<?php
if (!defined( 'ABSPATH' )) exit;

wp_register_style( 'woo2app_style', WOO2APP_CSS_URL.'woo2app_style.css'  );
wp_enqueue_style( 'woo2app_style'.WOO2APP_FILES_VER );
if(get_locale() == 'fa_IR'){
	wp_register_style('myfont', WOO2APP_CSS_URL . 'font.css');
	wp_enqueue_style( 'myfont'.WOO2APP_FILES_VER);
}

$current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


if(isset($_POST['submit_update'])){
	$update = array();
	$update = get_option('woo2app_inviter_setting');
	if(!is_array($update)){
		$update = array();
		$update['enable_after_register'] = false ;
		$update['inviter_title'] = '' ;
		$update['inviter_description'] = '' ;
		$update['display_score_in_menu'] = false ;
		$update['score_for_inviter_register'] = false ;
		$update['score_for_inviter_register_value'] = '' ;
		$update['score_for_inviter_first_order'] = false ;
		$update['score_for_inviter_first_order_value'] = '' ;
		$update['score_type'] = '0' ;
		$update['score_user_title'] = '' ;
		$update['display_marketer_code'] = false ;
		$update['marketer_title'] = '' ;
		$update['type_make_code'] = 'username' ;
		update_option('woo2app_inviter_setting' , $update);
	}

	$update['enable_after_register'] = (isset($_POST['enable_after_register']) && $_POST['enable_after_register'] == 'on' ) ? true : false;
	$update['inviter_title'] = $_POST['inviter_title'] ;
	$update['inviter_description'] = $_POST['inviter_description'] ;
	$update['display_score_in_menu'] = (isset($_POST['display_score_in_menu']) && $_POST['display_score_in_menu'] == 'on') ? true : false;
	$update['score_for_inviter_register'] = (isset($_POST['score_for_inviter_register']) && $_POST['score_for_inviter_register'] == 'on') ? true : false;
	$update['score_for_inviter_register_value'] = $_POST['score_for_inviter_register_value'] ;
	$update['score_for_inviter_first_order'] = (isset($_POST['score_for_inviter_first_order']) && $_POST['score_for_inviter_first_order'] == 'on') ? true : false;
	$update['score_for_inviter_first_order_value'] = $_POST['score_for_inviter_first_order_value'] ;
	$update['score_type'] = $_POST['score_type'] ;
	$update['score_user_title'] = $_POST['score_user_title'] ;
	$update['display_marketer_code'] = (isset($_POST['display_marketer_code']) && $_POST['display_marketer_code'] == 'on' ) ? true : false;
	$update['marketer_title'] = $_POST['marketer_title'] ;
	$update['type_make_code'] = $_POST['type_make_code'] ;
	update_option('woo2app_inviter_setting' , $update);

}
?>
<div class="wrap">

	<?php
	$update = array();
	$update = get_option('woo2app_inviter_setting');
	if(!is_array($update)){
		$update = array();
		$update['enable_after_register'] = false ;
		$update['inviter_title'] = '' ;
		$update['inviter_description'] = '' ;
		$update['display_score_in_menu'] = false ;
		$update['score_for_inviter_register'] = false ;
		$update['score_for_inviter_register_value'] = '' ;
		$update['score_for_inviter_first_order'] = false ;
		$update['score_for_inviter_first_order_value'] = '' ;
		$update['score_type'] = '0' ;
		$update['score_user_title'] = '' ;
		$update['display_marketer_code'] = false ;
		$update['marketer_title'] = '' ;
		$update['type_make_code'] = 'username' ;
		update_option('woo2app_inviter_setting' , $update);
	}
	?>
    <h1>
        <?php _e('User Invite', 'woo2app'); ?>
    </h1>
    <form method="post">
        <?php wp_nonce_field('woo2app-admin', 'woo2app-admin'); ?>
        <table class="form-table ">
            <tbody>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Enable', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="checkbox" name="enable_after_register" <?= checked( $update['enable_after_register']  );?> />
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Invite Code Title', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="text" class="regular-text" name="inviter_title" value="<?= $update['inviter_title']?>">
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label>  <?php _e('Invite Code description', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <textarea  type="text" class="regular-text" name="inviter_description" ><?= $update['inviter_description']?></textarea>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Score Type', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <select name="score_type" class="regular-text">
                        <option value="0" <?= selected($update['score_type'], '0'); ?> > <?php _e('None', 'woo2app'); ?> </option>
                        <option value="1" <?= selected($update['score_type'], '1'); ?> > <?php _e('Score', 'woo2app'); ?> </option>
                        <option value="2" <?= selected($update['score_type'], '2'); ?> > <?php _e('Wallet', 'woo2app'); ?> </option>
                    </select>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Credit In Registration', 'woo2app'); ?>  </label>
                </th>
                <td class="forminp">
                    <input type="checkbox" name="score_for_inviter_register" <?= checked( $update['score_for_inviter_register']  );?> />
                    <?php _e('The inviter receives credited for any user', 'woo2app'); ?>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Credit Amount', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="number" class="regular-text" name="score_for_inviter_register_value" value="<?= $update['score_for_inviter_register_value']?>">
                    <p>
		                <?php _e('Credit Amount For Any User ', 'woo2app'); ?>
                    </p>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Credit In First Completed Order.', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="checkbox" name="score_for_inviter_first_order" <?= checked( $update['score_for_inviter_first_order']  );?> />
                    <?php _e('The inviter receives credited for first', 'woo2app'); ?>
                    <mark class="order-status status-completed tips">
                        <span>
                            <?php _e('completed', 'woo2app'); ?>
                        </span>
                    </mark>
                    <?php _e('order.', 'woo2app'); ?>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Credit Amount', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="number" class="regular-text" name="score_for_inviter_first_order_value" value="<?= $update['score_for_inviter_first_order_value']?>">
                    <p>
                        <?php _e('Credit Amount For First ', 'woo2app'); ?>
                        <mark class="order-status status-completed tips">
                            <span>
                                <?php _e('completed', 'woo2app'); ?>
                            </span>
                        </mark>
                        <?php _e('order.', 'woo2app'); ?>
                    </p>
                </td>
            </tr>
            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Show User Credit', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="checkbox" name="display_score_in_menu" <?= checked( $update['display_score_in_menu']  );?> />
                    <?php _e('The user credit is displayed in application menu.', 'woo2app'); ?>
                </td>
            </tr>

            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('User Credit Title', 'woo2app'); ?></label>
                </th>
                <td class="forminp">
                    <input type="text" class="regular-text" name="score_user_title" value="<?= $update['score_user_title']?>">
                </td>
            </tr>

            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Marketing Code', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="checkbox" name="display_marketer_code" <?= checked( $update['display_marketer_code']  );?> />
                    <?php _e('The user\'s marketing code will be displayed in the menu.', 'woo2app'); ?>
                </td>
            </tr>

            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('Marketing Code Label', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <input type="text" class="regular-text" name="marketer_title" value="<?= $update['marketer_title']?>">
                </td>
            </tr>

            <tr valign="top" class="" >
                <th scope="row" class="titledesc">
                    <label> <?php _e('How to Generate marketing code ?', 'woo2app'); ?> </label>
                </th>
                <td class="forminp">
                    <select name="type_make_code" class="regular-text">
                        <option value="username" <?= selected($update['type_make_code'], 'username'); ?> > <?php _e('Username', 'woo2app'); ?> </option>
                        <option value="random_digit" <?= selected($update['type_make_code'], 'random_digit'); ?> > <?php _e('Random Number', 'woo2app'); ?> </option>
                        <option value="random_alphabet" <?= selected($update['type_make_code'], 'random_alphabet'); ?> > <?php _e('Random Letters', 'woo2app'); ?> </option>
                    </select>
                </td>
            </tr>


            </tbody>
        </table>
        <input name="submit_update" class="button button-primary" value="<?php _e('Save', 'woo2app'); ?>" type="submit">
    </form>
</div>
