<?php
/**
 * Created by mr2app.
 * User: hani
 * Date: 11/13/18
 * Time: 16:16
 */

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);
}

if (!defined( 'ABSPATH' )) exit;
$current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if(isset($_REQUEST["submit_edit"])){
    $array = array(
        'replace_phone' => $_POST['replace_phone'],
        'registered_role' => $_POST['registered_role'],
    );
    if(update_option( 'mr2app_register_form',$array )){
        ?>
        <div class="notice notice-success is-dismissible">
            <p><?php _e('Settings saved successfully', 'woo2app'); ?></p>
        </div>
        <?php
    }
    else {
        ?>
        <div class="notice notice-danger is-dismissible">
            <p><?php _e('Sorry, we encountered a problem. Please try again.', 'woo2app'); ?></p>
        </div>
        <?php
    }
}
$setting = get_option('mr2app_register_form');
?>
<div class="wrap" >
    <div id="col-container" class="">
        <div class="col-wrap" style="width: 50%;">
            <div class="form-wrap">
                <form id="addtag" method="post" action="" class="validate">
                    <?php wp_nonce_field('woo2app-admin', 'woo2app-admin'); ?>

                    <div class="form-field ">
                        <label> <?php _e('Field replaces mobile number', 'woo2app'); ?> </label>
                        <?php
                        $args      = array(
                            'post_type'   => 'woo2app_register',
                            'post_status' => 'draft',
                            'posts_per_page' => -1,
                            'orderby' => 'menu_order',
                            'order' => 'ASC'
                        );
                        $the_query = get_posts( $args );
                        ?>
                        <select name="replace_phone" style="width: 90%">
                            <option value="0">
                                <?php _e('Please Select ...', 'woo2app'); ?>
                            </option>
                            <?php
                            foreach ($the_query as $f){
                                ?>
                                <option <?= ($setting['replace_phone'] == $f->post_content)? 'selected' : '' ;?> value="<?= $f->post_content; ?>">
                                    <?= $f->post_title;?>
                                </option>
                                <?php
                            }
                            ?>
                        </select>
                    </div>
                    <div class="form-field ">
                        <label> نقش کاربر هنگام ثبت نام </label>
                        <select  class="regular-text" name="registered_role" required="required">
		                    <?php
		                    $roles = wp_roles();
		                    foreach ($roles->roles as $r => $rr){
		                        if($r == 'administrator') continue;
			                    ?>
                                <option <?= selected($setting['registered_role'], $r)?> value="<?= $r; ?>"> <?= $rr['name'];?></option>
			                    <?php
		                    }
		                    ?>
                        </select>
                    </div>
                    <div class="form-field " >
                        <p class="submit">
                            <input type="submit" name="submit_edit" class="button button-primary"
                                   value="<?php _e('Edit', 'woo2app'); ?>"/>
                        </p>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>