| } | } | ||||
| div.error { | div.error { | ||||
| color:red | |||||
| text-align: center; | |||||
| color:red; | |||||
| font-weight: bold; | font-weight: bold; | ||||
| } | } | ||||
| margin-top:10px; | margin-top:10px; | ||||
| margin-bottom:10px; | margin-bottom:10px; | ||||
| color: black; | color: black; | ||||
| //display:none; | |||||
| display:none; | |||||
| } | } | ||||
| input.fullwidth{ | input.fullwidth{ | ||||
| width:100%; | width:100%; | ||||
| } | } | ||||
| select.fullwidth{ | |||||
| width: 100%; | |||||
| height: 50px; | |||||
| padding:10px; | |||||
| } | |||||
| table.details { | table.details { | ||||
| border: 1px solid #FFFFFF; | border: 1px solid #FFFFFF; |
| <div id="search"> | <div id="search"> | ||||
| <div> | <div> | ||||
| <input id="username" class="typeahead" type=text name="user" placeholder="input name"> | |||||
| <div class='error' id="errUserName"> abcdefg </div> | |||||
| <input autocomplete=off id="username" class="typeahead" type=text name="user" placeholder="Your name"> | |||||
| <div class='error' id="errUserName"> </div> | |||||
| </div> | </div> | ||||
| <div> | <div> | ||||
| <button id="step1" class=disabled> Search </button> | |||||
| <button id="step1" class=disabled> Next <i class="ticon ticon-arrow-down"></i> </button> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class= 'clear'></div> | <div class= 'clear'></div> | ||||
| <div class="verification" id="userpass"> | <div class="verification" id="userpass"> | ||||
| <div> Mobile Phone last 4 digits: </div> | |||||
| <div> <input class='fullwidth' id="phone" type=text> </div> | |||||
| <div> Postal Code: </div> | |||||
| <div><input class='fullwidth' id="zipcode" type=text></div> | |||||
| <button id="step2"> Verify</button> | |||||
| <p> Please provide missing information: </p> | |||||
| <select name="verify_method" class=fullwidth id="verify_method"> | |||||
| <option value="mobile" id="vmobile">Your Phone: </option> | |||||
| <option value="email" id="vemail">Your Email: </option> | |||||
| </select> | |||||
| <div> Your Answer:</div> | |||||
| <div> <input class='fullwidth' id="verifycode" type=text> </div> | |||||
| <div class='error' id="errVerify"> </div> | |||||
| <button id="step2"> Verify <i class="ticon ticon-arrow-down"></i></button> | |||||
| </div> | </div> | ||||
| <div class= 'clear'></div> | <div class= 'clear'></div> | ||||
| <button id=changeaddr>Change Address</button> | <button id=changeaddr>Change Address</button> | ||||
| </td></tr> | </td></tr> | ||||
| <tr> | |||||
| <td>State in Australia</td> | |||||
| <td class="left"> | |||||
| <select name="states" class=fullwidth id="states"> | |||||
| <option value="NSW">NSW</option> | |||||
| <option value="ACT">ACT</option> | |||||
| <option value="WA">WA</option> | |||||
| <option value="SA">SA</option> | |||||
| <option value="NT">NT</option> | |||||
| <option value="TAS">TAS</option> | |||||
| <option value="VIC">VIC</option> | |||||
| </select> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td>Delivery:</td> | <td>Delivery:</td> | ||||
| <td class="left"> | <td class="left"> | ||||
| <input type=radio name="delivery"> Direct Post <br> | |||||
| <input type=radio name="delivery" checked> Pickup from <span id=collector> Patrick Sun </span> | |||||
| <input type=radio name="delivery" > N/A <br> | |||||
| <input type=radio name="delivery" > Direct Post <br> | |||||
| <input type=radio name="delivery" checked> Pick up from <span id=collector> Patrick Sun </span> | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td style="vertical-align:middle"> | <td style="vertical-align:middle"> | ||||
| <input id="medal" type=checkbox checked><br> | |||||
| <label for="medal"> uncheck = 放弃</label> | |||||
| <input id="medal" type=checkbox checked onclick="return false;"><br> | |||||
| <label for="medal" id='medalstatus'>Received in AU</labe> | |||||
| </td> | </td> | ||||
| <td > | <td > | ||||
| <img src="https://via.placeholder.com/150" > | <img src="https://via.placeholder.com/150" > | ||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td style="vertical-align:middle"> | |||||
| <button id=cardbtn> Apply </button> | |||||
| <img id=cardloading style="display:none;"> | |||||
| <input id="card" type=checkbox checked style="display:none;""> | |||||
| <div class='error' id=errCard></div> | |||||
| <tr id=tracking1> | |||||
| <td id=date1 style="vertical-align:middle"> | |||||
| 2020-12-10 | |||||
| </td> | </td> | ||||
| <td> | <td> | ||||
| <img src="https://via.placeholder.com/150" > | |||||
| Send out from Sydney | |||||
| </td> | |||||
| </tr> | |||||
| <tr id=tracking2> | |||||
| <td id=date1 style="vertical-align:middle"> | |||||
| 2020-12-10 | |||||
| </td> | |||||
| <td> | |||||
| Send out from Sydney | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td style="vertical-align:middle"> | |||||
| <button id=btn90> Apply </button> | |||||
| <img id=loading90 style="display:none;"> | |||||
| <input id="medal90" type=checkbox checked style="display:none;"> | |||||
| <div class='error' id=errCard></div> | |||||
| <tr id=tracking3> | |||||
| <td id=date1 style="vertical-align:middle"> | |||||
| 2020-12-10 | |||||
| </td> | </td> | ||||
| <td> | <td> | ||||
| <img src="https://via.placeholder.com/150" > | |||||
| Send out from Sydney | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <div class="success"> | <div class="success"> | ||||
| <table style="min-height:150px;"> | <table style="min-height:150px;"> | ||||
| <tr><td style="text-align:center; vertical-align:middle;"> | <tr><td style="text-align:center; vertical-align:middle;"> | ||||
| <button id='confirm' > Confirm Everything </button> | |||||
| <button id='confirm' > Card received </button> | |||||
| <img id=done style="display:none;" > | <img id=done style="display:none;" > | ||||
| </td></tr> | </td></tr> | ||||
| </table> | </table> |
| /*______________________________________________________*/ | /*______________________________________________________*/ | ||||
| $(function () { | $(function () { | ||||
| $('#test').html(mm.display_name); | |||||
| //$('#test').html(mm.display_name); | |||||
| console.log(mm); | console.log(mm); | ||||
| $("#cardloading").attr('src', mm.loading); | $("#cardloading").attr('src', mm.loading); | ||||
| $("#loading90").attr('src', mm.loading); | $("#loading90").attr('src', mm.loading); | ||||
| $("#done").attr('src', mm.done); | $("#done").attr('src', mm.done); | ||||
| $(':radio:not(:checked)').attr('disabled', true); | |||||
| init_clientname_input("#username"); | init_clientname_input("#username"); | ||||
| }); | }); | ||||
| function clientname_suggestions(){ | function clientname_suggestions(){ | ||||
| function onUpdateClientID (e, suggestion) | function onUpdateClientID (e, suggestion) | ||||
| { | { | ||||
| console.log(suggestion); | |||||
| console.log(e); | |||||
| mm.current_user = suggestion.userid; | |||||
| $.post(mm.ajax_url, { // POST request | |||||
| _ajax_nonce: mm.nonce, // nonce | |||||
| action: "list_users", // action | |||||
| client : suggestion.userid, | |||||
| name : '' | |||||
| }, function(response, status, xhr){ | |||||
| step2_verify_user(response); | |||||
| }).fail(function(){ | |||||
| errUserName("Network Error, Please try again later"); | |||||
| }); | |||||
| } | } | ||||
| function init_clientname_input(selector){ | function init_clientname_input(selector){ | ||||
| //console.log('selector = ' + selector); | //console.log('selector = ' + selector); | ||||
| }, 2000); | }, 2000); | ||||
| } | } | ||||
| //step1 | //step1 | ||||
| $(document).on("click", "#step1", function(){ | $(document).on("click", "#step1", function(){ | ||||
| var input = $("#username").val(); | var input = $("#username").val(); | ||||
| $.post(mm.ajax_url, { // POST request | $.post(mm.ajax_url, { // POST request | ||||
| _ajax_nonce: mm.nonce, // nonce | _ajax_nonce: mm.nonce, // nonce | ||||
| action: "list_users", // action | action: "list_users", // action | ||||
| client : input, | |||||
| client : mm.current_user, | |||||
| name : input, | |||||
| }, function(response, status, xhr){ | }, function(response, status, xhr){ | ||||
| step2_verify_user(response); | step2_verify_user(response); | ||||
| }).fail(function(){ | }).fail(function(){ | ||||
| //step2 | //step2 | ||||
| function step2_verify_user(response) | function step2_verify_user(response) | ||||
| { | { | ||||
| console.log(response); | |||||
| var el = $("#userpass"); | var el = $("#userpass"); | ||||
| el.slideUp(); | |||||
| el.slideDown(); | |||||
| $("#vmobile").text(response.phone); | |||||
| $("#vemail").text(response.email); | |||||
| el.slideToggle(); | |||||
| } | } | ||||
| //verify | //verify | ||||
| $(document).on("click", "#step2", function(){ | $(document).on("click", "#step2", function(){ | ||||
| var input = $("#verifycode").val(); | |||||
| var method = $("#verify_method").val(); | |||||
| $.post(mm.ajax_url, { // POST request | |||||
| _ajax_nonce: mm.nonce, // nonce | |||||
| action: "verify_user", // action | |||||
| client : mm.current_user, | |||||
| method: method, | |||||
| verifycode : input, | |||||
| }, function(response, status, xhr){ | |||||
| step3_show_details(response); | |||||
| }).fail(function(){ | |||||
| errUserName("Network Error, Please try again later"); | |||||
| }); | |||||
| }); | |||||
| function step3_show_details(response) | |||||
| { | |||||
| var el = $('#details'); | var el = $('#details'); | ||||
| el.slideDown(); | el.slideDown(); | ||||
| }); | |||||
| if ( response.pass ){ | |||||
| el.slideDown(); | |||||
| $("#errVerify").text(""); | |||||
| }else { | |||||
| el.hide(); | |||||
| $("#errVerify").text("Incorrect, please try again"); | |||||
| } | |||||
| } | |||||
| //apply card | //apply card | ||||
| $(document).on("click", "#cardbtn", function(){ | $(document).on("click", "#cardbtn", function(){ |
| class Member{ | class Member{ | ||||
| private $token = ""; | private $token = ""; | ||||
| private $nonce = ""; | private $nonce = ""; | ||||
| private $db; | |||||
| public function __construct() { | public function __construct() { | ||||
| add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); | add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); | ||||
| // | // | ||||
| $this->ajax_hook('list_users'); | $this->ajax_hook('list_users'); | ||||
| $this->ajax_hook('search_users'); | $this->ajax_hook('search_users'); | ||||
| $this->ajax_hook('verify_user'); | |||||
| global $wpdb; | |||||
| $this->db = $wpdb; | |||||
| } | } | ||||
| private function ajax_hook($code, $admin_only = false) | private function ajax_hook($code, $admin_only = false) | ||||
| } | } | ||||
| public function shortcode_token($attrs) { | public function shortcode_token($attrs) { | ||||
| $login = get_query_var( 'token' ); | |||||
| return "<h1 id='test'> $login </h1>"; | |||||
| $token = get_query_var( 'token' ); | |||||
| $user = $this->getUserByToken($token); | |||||
| return "<h1 id='test'> ok ok " . $user[0]->display_name . " </h1>"; | |||||
| } | } | ||||
| public function register_js_css() { | public function register_js_css() { | ||||
| $this->nonce = wp_create_nonce('medal'); | $this->nonce = wp_create_nonce('medal'); | ||||
| $this->token = get_query_var( 'token' ); | $this->token = get_query_var( 'token' ); | ||||
| if ($this->token == "edit") | |||||
| $this->house_keeping(); | |||||
| if ($this->token == "test") | |||||
| $this->test(); | |||||
| $this->register_medal_js(); | $this->register_medal_js(); | ||||
| } | } | ||||
| 'done' => plugins_url('img/done.gif', __FILE__), | 'done' => plugins_url('img/done.gif', __FILE__), | ||||
| 'search_user' => plugins_url('img/loading_user.gif', __FILE__), | 'search_user' => plugins_url('img/loading_user.gif', __FILE__), | ||||
| 'anonymous' => !is_user_logged_in(), | 'anonymous' => !is_user_logged_in(), | ||||
| 'user' => $this->getUserByToken($this->token), | |||||
| ) ); | ) ); | ||||
| } | } | ||||
| { | { | ||||
| //check_ajax_referer('medal'); | //check_ajax_referer('medal'); | ||||
| $client = $_POST['client']; | $client = $_POST['client']; | ||||
| $url = $_POST["action"]; | |||||
| $name = $_POST['name']; | |||||
| $user = false; | |||||
| if ($name != ""){ | |||||
| $user =$this->getUserByDisplayName($name); | |||||
| }else{ | |||||
| $user = get_user_by("ID", $client); | |||||
| } | |||||
| if ($user == false){ | |||||
| $response = array( | |||||
| 'status' => 'error', | |||||
| 'errMsg' => "User not found", | |||||
| ); | |||||
| wp_send_json($response); | |||||
| } | |||||
| $phone = get_user_meta($user->ID, "tel-mobile", true); | |||||
| $response = array( | $response = array( | ||||
| 'status' => 'success', | 'status' => 'success', | ||||
| 'users' => [ | |||||
| 1,2,3,4,5,6,7 | |||||
| ], | |||||
| 'id' => $client, | |||||
| 'url' => $url, | |||||
| 'userID' => $user->ID, | |||||
| 'email' => $this->mask_email($user->user_email), | |||||
| 'phone' => $this->mask_phone($phone), | |||||
| ); | ); | ||||
| wp_send_json($response); | wp_send_json($response); | ||||
| } | } | ||||
| public function ajax_search_users(){ | |||||
| private function mask_phone($phone) | |||||
| { | |||||
| if ($phone != "" && strlen($phone) > 4){ | |||||
| return substr($phone, 0, -4) . "####"; | |||||
| }else | |||||
| return "no valid phone"; | |||||
| } | |||||
| private function mask_email($email) | |||||
| { | |||||
| $pos = stripos($email,"@"); | |||||
| return substr($email,0,1) . "*****" . substr($email, $pos); | |||||
| } | |||||
| public function ajax_search_users() | |||||
| { | |||||
| //check_ajax_referer('medal'); | //check_ajax_referer('medal'); | ||||
| $pattern = $_GET['pattern']; | $pattern = $_GET['pattern']; | ||||
| $args= array( | $args= array( | ||||
| 'search' => "*$pattern*", // or login or nicename in this example | 'search' => "*$pattern*", // or login or nicename in this example | ||||
| 'search_fields' => array('display_name'), | 'search_fields' => array('display_name'), | ||||
| wp_send_json($response['users']); | wp_send_json($response['users']); | ||||
| } | } | ||||
| public function ajax_verify_user() | |||||
| { | |||||
| //check_ajax_referer('medal'); | |||||
| $client = $_POST['client']; | |||||
| $verifycode = $_POST['verifycode']; | |||||
| $method = $_POST['method']; | |||||
| $user = get_user_by("ID", $client); | |||||
| if ($user == false){ | |||||
| $response = array( | |||||
| 'status' => 'error', | |||||
| 'errMsg' => "User not found", | |||||
| ); | |||||
| wp_send_json($response); | |||||
| } | |||||
| $response = array( | |||||
| 'status' => 'success', | |||||
| 'userID' => $user->ID, | |||||
| 'pass' => $this->verify_code($method, $verifycode, $user), | |||||
| ); | |||||
| wp_send_json($response); | |||||
| } | |||||
| private function verify_code($method, $verifycode, $user) | |||||
| { | |||||
| $phone = get_user_meta($user->ID, "tel-mobile", true); | |||||
| if ($method=="mobile" && stripos($phone, $verifycode) != false && strlen($verifycode) ==4 ) | |||||
| return true; | |||||
| if ($method=="email"){ | |||||
| $mas = $this->mask_email($user->user_email); | |||||
| $newEmail = str_replace("*****", $verifycode, $mas ); | |||||
| return $newEmail == $user->user_email; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| private function getUserByDisplayName($pattern) | |||||
| { | |||||
| $args= array( | |||||
| 'search' => "*$pattern*", // or login or nicename in this example | |||||
| 'search_fields' => array('display_name'), | |||||
| ); | |||||
| $users = new \WP_User_Query($args); | |||||
| if ($users->get_total() >=1){ | |||||
| return $users->results[0]; | |||||
| }else | |||||
| return false; | |||||
| } | |||||
| public function getUserByToken($token) | |||||
| { | |||||
| $user = get_users(array( | |||||
| 'meta_key' => 'token', | |||||
| 'meta_value' => "$token" | |||||
| )); | |||||
| return $user; | |||||
| } | |||||
| //for development purpose only | |||||
| public function test() | |||||
| { | |||||
| $this->ajax_list_users(); | |||||
| } | |||||
| public function house_keeping() | |||||
| { | |||||
| $args= array( | |||||
| 'search' => "**", // or login or nicename in this example | |||||
| 'search_fields' => array('display_name'), | |||||
| 'role__in' => array("subscriber"), | |||||
| ); | |||||
| $users = new \WP_User_Query($args); | |||||
| $count = $users->get_total(); | |||||
| foreach ( $users->results as $u ) { | |||||
| $card = 0; | |||||
| $post_addr = get_user_meta($u->ID, 'postal-address', true); | |||||
| $card = trim($post_addr) == ""? -1: 0; | |||||
| $medal = 1; | |||||
| $country = get_user_meta($u->ID, 'country', true); | |||||
| if ($country != "Australia") | |||||
| $medal = 0; | |||||
| $this->db->update('sp_medal_100', array( | |||||
| 'medal' => $medal, | |||||
| 'card' => $card, | |||||
| 'card_posted' =>0, | |||||
| 'card_delivered' => 0, | |||||
| 'medal_delivered' => 0, | |||||
| ),array( | |||||
| 'uid' => $u->ID, | |||||
| )); | |||||
| } | |||||
| } | |||||
| private function update_medal($u) | |||||
| { | |||||
| $this->db->update('sp_medal_100', array( | |||||
| 'medal' => 1, | |||||
| 'card' => 0, | |||||
| 'card_posted' =>0, | |||||
| 'card_delivered' => 0, | |||||
| 'medal_delivered' => 0, | |||||
| ),array( | |||||
| 'uid' => $u->ID, | |||||
| )); | |||||
| } | |||||
| } | } | ||||
| $mm = new Member(); | |||||
| $mm = new Member(); |