| @@ -1,6 +1,6 @@ | |||
| <?php | |||
| namespace Biukop; | |||
| require_once(ABSPATH . "wp-config.php"); | |||
| require_once(ABSPATH . "wp-config.php"); | |||
| require_once(ABSPATH . "wp-includes/wp-db.php"); | |||
| class AddrMap{ | |||
| @@ -5,14 +5,17 @@ namespace Biukop; | |||
| class NdisPrice{ | |||
| private $html = ''; | |||
| private $ndis_table; | |||
| private $tos =[]; | |||
| public function __construct(int $year=2019) { | |||
| global $wpdb; | |||
| $this->ndis_table = $wpdb->prefix . 'acare_ndis_price'; | |||
| $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year | |||
| $results = $wpdb->get_results($sql); | |||
| $this->tos =[]; | |||
| $html = ' <select>'; | |||
| foreach($results as $r){ | |||
| $this->tos[] = $r; | |||
| $html .= sprintf('<option value="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>', | |||
| $r->code, | |||
| $r->level, | |||
| @@ -49,4 +52,13 @@ class NdisPrice{ | |||
| { | |||
| return $this->html; | |||
| } | |||
| public function get_tos_str($ndis_code) | |||
| { | |||
| foreach ($this->tos as $r){ | |||
| if ($ndis_code == $r->code) | |||
| return $r->name; | |||
| } | |||
| return ""; | |||
| } | |||
| } | |||
| @@ -0,0 +1,105 @@ | |||
| <?php | |||
| namespace Biukop; | |||
| class UserJob{ | |||
| private $user; | |||
| private $db; | |||
| private $table_name; | |||
| private $jobs; | |||
| private $options; | |||
| public function __construct($login){ | |||
| if ($login == null || $login == "") | |||
| $this->user = wp_get_current_user(); | |||
| else{ | |||
| $this->user = get_user_by('login', $login); | |||
| } | |||
| global $wpdb; | |||
| $this->db = $wpdb; | |||
| $this->table_name = $wpdb->prefix . 'acare_ts'; | |||
| $this->jobs = $this->list_jobs("2019-07-01", "2019-07-14"); | |||
| } | |||
| private function is_staff() | |||
| { | |||
| $roles = get_userdata($this->user->ID)->roles; | |||
| return $roles == 'staff'; | |||
| } | |||
| public function list_jobs($start, $finish){ | |||
| $response = array( | |||
| 'status'=>'success', | |||
| 'jobs' => [], | |||
| 'staff_name'=>$this->user->display_name, | |||
| 'job_count' => 0. | |||
| ); | |||
| $sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s' and staff='%s' order by start ASC"; | |||
| $query = $this->db->prepare ($sql, array($start, $finish, $this->user->user_login)); | |||
| $jobs = $this->db->get_results($query); | |||
| $response['job_count'] = count($jobs); | |||
| //$response['sql'] = $query; | |||
| if ($this->db->last_error == ""){ | |||
| $response['status'] = 'success'; | |||
| foreach( $jobs as $s){ | |||
| $response['jobs'][] = array( | |||
| 'id' => $s->id, | |||
| 'tos' => $s->tos, | |||
| 'start'=> $s->start, | |||
| 'finish'=> $s->finish, | |||
| 'rate'=> $s->rate, | |||
| 'staff'=> $s->staff, | |||
| 'client'=> $s->client, | |||
| 'ack' => $s->ack, | |||
| 'rating' =>$s->rating, | |||
| //descriptions | |||
| 'rate_str'=> $this->get_rate_str($s->rate), | |||
| 'tos_str'=> $this->get_tos_str($s->tos), | |||
| 'client_name' => $this->get_display_name($s->client), | |||
| 'client_addr' => $this->get_client_addr($s->client), | |||
| ); | |||
| } | |||
| }else{ | |||
| $response['status'] = 'error'; | |||
| $response['err'] = $this->db->last_error; | |||
| } | |||
| return $response; | |||
| } | |||
| private function get_rate_str($earnings_rate_id) | |||
| { | |||
| if ($this->options == NULL){ | |||
| $this->options = get_option('bts_payitem_earnings_rate'); | |||
| } | |||
| foreach($this->options as $o){ | |||
| if ($o['EarningsRateID'] == $earnings_rate_id) | |||
| return $o['Name']; | |||
| } | |||
| return ""; | |||
| } | |||
| private function get_tos_str($ndis_code) | |||
| { | |||
| if ($this->ndis == null){ | |||
| $this->ndis = new NdisPrice(2019); | |||
| } | |||
| return $this->ndis->get_tos_str($ndis_code); | |||
| } | |||
| private function get_client_addr($login) | |||
| { | |||
| $user = get_user_by('login', $login); | |||
| return get_user_meta($user->ID, 'address', true); | |||
| } | |||
| private function get_display_name($login) | |||
| { | |||
| $user = get_user_by('login', $login); | |||
| return $user->display_name; | |||
| } | |||
| } | |||
| ?> | |||
| @@ -110,6 +110,8 @@ class Xero { | |||
| foreach ( $employees as $e){ | |||
| $msg = sprintf("SYNC employee name=[%s %s] {%s} \n", $e->getFirstName(), $e->getLastName(), $e->getEmployeeID()); | |||
| $this->logConsole($msg); | |||
| if ($e->getEmployeeID() != '3e8c2e62-8e28-4b68-ae98-9ef1d76188c4') | |||
| continue; | |||
| $this->ensure_staff_exists($e); | |||
| } | |||
| } | |||
| @@ -199,6 +201,7 @@ class Xero { | |||
| $login = $employee->getEmployeeID(); | |||
| $user = get_user_by('login', $login); | |||
| if ($user === false){ | |||
| echo "add new \n"; | |||
| $xero_employee = $this->getEmployee($login); | |||
| $args = $this->xero_employee_profile($xero_employee); | |||
| $id = wp_insert_user($args); | |||
| @@ -209,10 +212,12 @@ class Xero { | |||
| if ($this->is_too_close_to_sync($user)){ | |||
| return; | |||
| } | |||
| echo "i update existing $user->user_login $user->display_name\n"; | |||
| $xero_employee = $this->getEmployee($login); | |||
| $args = $this->xero_employee_profile($xero_employee); | |||
| $args['ID'] = $user->ID; | |||
| unset($args['user_pass']); | |||
| var_dump($args); | |||
| wp_update_user($args); | |||
| update_user_meta($user->ID, 'mobile', $args['mobile']); | |||
| update_user_meta($user->ID, 'address', $args['address']); | |||
| @@ -0,0 +1,47 @@ | |||
| @CHARSET "UTF-8"; | |||
| .jobsummary section{ | |||
| margin-bottom:0px; | |||
| } | |||
| .jobfield{ | |||
| width: 100%; | |||
| margin: 0 0 0px; | |||
| padding: 0.5em 0.5em 0.5em 4em; | |||
| } | |||
| .confirmfield{ | |||
| padding-top:auto; | |||
| padding-bottom:auto; | |||
| padding-left: 20px; | |||
| background-color: #f7be68; | |||
| font-weight:bolder; | |||
| font-size: 1.5em; | |||
| } | |||
| .confirmfield label{ | |||
| width: 100%; | |||
| } | |||
| .fullinner > .vc_column-inner {padding:0px;} | |||
| .jobcard { | |||
| margin-top: 10px !important; | |||
| margin-bottom: 20px !important; | |||
| border-top-width: 0px !important; | |||
| border-right-width: 0px !important; | |||
| border-bottom-width: 0px !important; | |||
| border-left-width: 0px !important; | |||
| padding-top: 0px !important; | |||
| padding-right: 0px !important; | |||
| padding-bottom: 0px !important; | |||
| padding-left: 0px !important; | |||
| background-color: #f7be68 !important; | |||
| box-shadow: 0px 0px 10px black; | |||
| width: 96% !important; | |||
| margin-left: 2% !important; | |||
| margin-right: 2% !important; | |||
| left: 0px !important; | |||
| } | |||
| .jobcard .vc_message_box{ | |||
| border-color:transparent; | |||
| } | |||
| #jobtemplate{ | |||
| display:none; | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| Dear {{display_name}}, | |||
| Below is your job arrangement for the current week, please click the link to view your jobs | |||
| https://acaresydney.com.au/task/{{user_login}}/ | |||
| If you have any questions, please call Helen directly or email | |||
| helen@acaresydney.com.au | |||
| Kind Regards | |||
| Team of | |||
| AcareSydney WebOffice | |||
| @@ -0,0 +1,256 @@ | |||
| function on_confirm_all(){} | |||
| (function ($) { | |||
| $(function () { | |||
| /*_____________________________________________*/ | |||
| function test_jobs(){ | |||
| for(var i =0; i<12; i++) | |||
| { | |||
| var h = $('#jobtemplate').wrap('<p/>').parent().html(); | |||
| $('#jobtemplate').unwrap(); | |||
| var el = $(h); | |||
| el.attr('id', 'job_' + i); | |||
| $('#jobtemplate').after(el); | |||
| } | |||
| } | |||
| function set_user_name_at_summary(name){ | |||
| var title = ''; | |||
| if ( typeof name != 'undefined' && name != "") | |||
| title = name + "'s Job"; | |||
| else | |||
| title = "Job Arrangement"; | |||
| $('.jobsummary h2').html(title); | |||
| } | |||
| function get_my_jobs(){ | |||
| $.post(bts().ajax_url, { // POST request | |||
| _ajax_nonce: bts().nonce, // nonce | |||
| action: "list_job_by_staff", // action | |||
| start: get_this_week_start(), | |||
| finish: get_this_week_end(), | |||
| login: get_staff_login(), | |||
| }, function(response, status, xhr){ | |||
| if (response.status == "success"){ | |||
| pre_process(response); | |||
| //console.log("%o", response); | |||
| load_staff_jobs(response); | |||
| }else{ | |||
| display_error(response); | |||
| } | |||
| }); | |||
| } | |||
| function get_staff_login() | |||
| { | |||
| //pathname: "/task/a6536a3b-ef22-4a28-8d55-e2a26d4ae227/" | |||
| var path = window.location.pathname; | |||
| var p = path.substr(6);//remove /task/ | |||
| var s = p.substring(0, p.length - 1); //remove last / | |||
| //console.log(s); | |||
| return s; | |||
| } | |||
| //add extra info to response.jobs | |||
| function pre_process(response) | |||
| { | |||
| var newjobs = []; | |||
| $.each(response.jobs, function(idx, val){ | |||
| if (val.ack != 0){ | |||
| val.readonly = "checked disabled"; | |||
| val.confirm = "Already Confirmed"; | |||
| }else{ | |||
| val.confirm = "Confirm"; | |||
| val.readonly = ""; | |||
| } | |||
| val.start_day = get_weekday_name(val.start); | |||
| val.finish_day = get_weekday_name(val.finish); | |||
| newjobs.push(val); | |||
| }); | |||
| response.jobs = newjobs; | |||
| //console.log("%o", response); | |||
| } | |||
| function get_weekday_name(dateString) | |||
| { | |||
| var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; | |||
| var d = new Date(dateString); | |||
| var dayName = days[d.getDay()]; | |||
| return dayName; | |||
| } | |||
| function load_staff_jobs(response) | |||
| { | |||
| set_user_name_at_summary(response.staff_name); | |||
| var template = get_staff_job_template(); | |||
| var html = Mustache.render(template, response); | |||
| $('#jobtemplate').after(html); | |||
| } | |||
| function get_staff_job_template() | |||
| { | |||
| var h = get_html_include_tag($('#jobtemplate')); | |||
| var h = get_html_include_tag($(h).removeAttr('id')); | |||
| return " {{#jobs}}" + h + " {{/jobs}} "; | |||
| } | |||
| function get_html_include_tag(el) | |||
| { | |||
| var h = el.wrap('<p/>').parent().html(); | |||
| el.unwrap(); | |||
| return h; | |||
| } | |||
| function display_error() | |||
| { | |||
| err_message_box("Network Error", "Your Jobs for this week cannot be loaded, please try again later. For urgent job arrangement please contact <strong>Helen</strong> directly."); | |||
| } | |||
| function format_date(date){ | |||
| var dd = date.getDate(); | |||
| var mm = date.getMonth() + 1; //January is 0! | |||
| var hh = date.getHours(); | |||
| var ii = date.getMinutes(); | |||
| var ss = date.getSeconds(); | |||
| var yyyy = date.getFullYear(); | |||
| if (dd < 10) { | |||
| dd = '0' + dd; | |||
| } | |||
| if (mm < 10) { | |||
| mm = '0' + mm; | |||
| } | |||
| if (hh< 10){ | |||
| hh = '0' + hh; | |||
| } | |||
| if (ii < 10){ | |||
| ii = '0' + ii; | |||
| } | |||
| if (ss <10 ){ | |||
| ss = '0' + ss; | |||
| } | |||
| return yyyy + '-' + mm + '-' +dd + " " +hh +":" + ii + ":" + ss; | |||
| } | |||
| function get_this_week_start(){ | |||
| var curr = new Date; // get current date | |||
| // First day is the day of the month - the day of the week | |||
| var first = curr.getDate() - curr.getDay() + 1; //+1 we want Mon as first | |||
| var last = first + 6; // last day is the first day + 6 | |||
| var firstday = new Date(curr.setDate(first)); //Mon | |||
| firstday.setHours(0,0,0); | |||
| return format_date(firstday); | |||
| } | |||
| function get_this_week_end(){ | |||
| var curr = new Date; // get current date | |||
| // First day is the day of the month - the day of the week | |||
| var first = curr.getDate() - curr.getDay() + 1; //+1 we want Mon as first | |||
| var last = first + 6; // last day is the first day + 6 | |||
| var lastday = new Date(curr.setDate(last)); //Sat | |||
| lastday.setHours(23,59,59); | |||
| return format_date(lastday); | |||
| } | |||
| function do_on_confirm_all() | |||
| { | |||
| var job_ids=[]; | |||
| $('.jobcard input[type="checkbox"]').prop('checked', true); | |||
| if ( $('.jobcard input[type="checkbox"]:checked').length ==0 ) | |||
| { | |||
| err_message_box("Warning", "You have no job to Confirm"); | |||
| return; | |||
| } | |||
| $('.jobcard input[type="checkbox"]:checked').each(function(e){ | |||
| var ack = $(this).is(':checked'); | |||
| var lb = $(this).closest('label[name="recordinfo"]'); | |||
| var id = lb.attr('data-record-id'); | |||
| if ( id != '{{id}}' ) //the template | |||
| job_ids.push({id:id, ack:ack}); | |||
| }); | |||
| do_update_ack(job_ids); | |||
| info_message_box("Congratulations", "All Your Jobs has been confirmed. Your payment will be calculated based on them. For urgent job changes please contact <strong>Helen</strong> directly."); | |||
| } | |||
| function info_message_box(title, message) | |||
| { | |||
| message_box('.job_ok_box', title, message); | |||
| } | |||
| function err_message_box(title, message) | |||
| { | |||
| message_box('.job_error_box', title, message); | |||
| } | |||
| function message_box(selector, title,message) | |||
| { | |||
| set_modal_title(selector, title); | |||
| set_modal_message(selector, message); | |||
| $(selector + '_trigger').trigger('click'); | |||
| } | |||
| function set_modal_title(selector, title) | |||
| { | |||
| var el = selector + ' .ult_modal-title '; | |||
| $(el).html(title); | |||
| } | |||
| function set_modal_message(selector, msg) | |||
| { | |||
| var el = selector + ' .ult_modal-body '; | |||
| $(el).html(msg); | |||
| } | |||
| function do_update_ack(job_ids) | |||
| { | |||
| $.post(bts().ajax_url, { // POST request | |||
| _ajax_nonce: bts().nonce, // nonce | |||
| action: "staff_ack_job", // action | |||
| jobs: job_ids, | |||
| }, function(response, status, xhr){ | |||
| if (response.status == "success"){ | |||
| var txt = response.ack? 'Confirmed':'Click to Confirm'; | |||
| span.html(txt); | |||
| }else{ | |||
| err_message_box("Network Error", "Try again later"); | |||
| } | |||
| }); | |||
| } | |||
| //register events | |||
| $(document).on('change', 'div.confirmfield input', function(){ | |||
| var ack = $(this).is(':checked'); | |||
| var lb = $(this).closest('label[name="recordinfo"]'); | |||
| var id = lb.attr('data-record-id'); | |||
| var span = lb.find('span'); | |||
| span.html('reporting ...'); | |||
| $.post(bts().ajax_url, { // POST request | |||
| _ajax_nonce: bts().nonce, // nonce | |||
| action: "staff_ack_job", // action | |||
| jobs: [{id:id, ack:ack}], | |||
| }, function(response, status, xhr){ | |||
| if (response.status == "success"){ | |||
| var txt = ack? 'Confirmed':'Click to Confirm'; | |||
| span.html(txt); | |||
| }else{ | |||
| err_message_box("Network Error", "Try again later"); | |||
| } | |||
| }); | |||
| }); | |||
| //init | |||
| set_user_name_at_summary(); | |||
| get_my_jobs(); | |||
| //get_staff_login(); | |||
| on_confirm_all = do_on_confirm_all; | |||
| /*_____________________________________________*/ | |||
| }); | |||
| })(jQuery); | |||
| @@ -630,25 +630,25 @@ | |||
| this.mark_rate_invalid(); | |||
| return false; | |||
| } | |||
| if (this.get_rate() != this.data.rate){ | |||
| this.set_err_msg_rate('rate@Xero inactive ' + this.data.rate); | |||
| this.mark_rate_invalid(); | |||
| this.mark_dirty(); | |||
| return false; | |||
| } | |||
| // if (this.get_rate() != this.data.rate){ | |||
| // this.set_err_msg_rate('rate@Xero inactive ' + this.data.rate); | |||
| // this.mark_rate_invalid(); | |||
| // this.mark_dirty(); | |||
| // return false; | |||
| // } | |||
| this.set_err_msg_rate(''); | |||
| this.mark_rate_valid(); | |||
| return true; | |||
| } | |||
| validate_tos(){ | |||
| if (this.get_tos() != this.data.tos){ | |||
| this.set_err_msg_tos('require NDIS ' + this.data.tos); | |||
| this.mark_tos_invalid(); | |||
| this.mark_dirty(); | |||
| console.log('tos mark dirty'); | |||
| return false; | |||
| } | |||
| // if (this.get_tos() != this.data.tos){ | |||
| // this.set_err_msg_tos('require NDIS ' + this.data.tos); | |||
| // this.mark_tos_invalid(); | |||
| // this.mark_dirty(); | |||
| // console.log('tos mark dirty'); | |||
| // return false; | |||
| // } | |||
| this.set_err_msg_tos(''); | |||
| this.mark_tos_valid(); | |||
| return true; | |||
| @@ -721,6 +721,7 @@ | |||
| var w1_end = new Date($('span[name="w1d7"]').data().date); | |||
| w1_begin.setHours(0,0,0,0); | |||
| w1_end.setHours(23,59,59); | |||
| //console.log("week1 begin %o, end %o", w1_begin, w1_end); | |||
| //w1_end = new Date (w1_end.setDate(w1_end.getDate()+1)); //from 00:00 to 23:59; | |||
| var me = new Date(this.data.start); | |||
| return (w1_begin <= me && me <= w1_end ); | |||
| @@ -732,6 +733,7 @@ | |||
| var w2_end = new Date($('span[name="w2d7"]').data().date); | |||
| w2_begin.setHours(0,0,0,0); | |||
| w2_end.setHours(23,59,59); | |||
| console.log("week2 begin %o, end %o", w2_begin, w2_end); | |||
| var me = new Date(this.data.start); | |||
| return (w2_begin <= me && me <= w2_end ); | |||
| } | |||
| @@ -865,8 +867,9 @@ | |||
| var pos = 1; //first lot | |||
| for (var i=first; i<=last; i++) | |||
| { | |||
| var d1 = new Date(curr.setDate(i)); | |||
| var d2 = new Date(curr.setDate(i+7)); | |||
| var now = new Date; | |||
| var d1 = new Date(now.setDate(i)); | |||
| var d2 = new Date(now.setDate(i+7)); | |||
| set_day_number(1,pos, d1); //week 1 | |||
| set_day_number(2,pos, d2); //week 2 | |||
| pos +=1; | |||
| @@ -1044,11 +1047,13 @@ | |||
| var els=[]; | |||
| unblink_all_date(); | |||
| $('div.bstart input').each(function(i,e){ | |||
| var value = $(e).attr('value'); | |||
| if( -1 != value.indexOf(strDate) ) //found | |||
| { | |||
| els.push(e); | |||
| $(e).addClass('blink_me'); | |||
| if ( $(e).is(":visible") ){ | |||
| var value = $(e).attr('value'); | |||
| if( -1 != value.indexOf(strDate) ) //found | |||
| { | |||
| els.push(e); | |||
| $(e).addClass('blink_me'); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| @@ -1187,19 +1192,65 @@ | |||
| return; | |||
| } | |||
| //if staffs is empty, we only filter by client | |||
| if (staffs === undefined || staffs.length ==0){ | |||
| filter_workspace_by_client(clients); | |||
| return; | |||
| } | |||
| //if clients is empty, we only filter by staff | |||
| if (clients===undefined || clients.length ==0){ | |||
| filter_workspace_by_staff(staffs); | |||
| return; | |||
| } | |||
| //filter by both | |||
| filter_workspace_by_both(staffs, clients); | |||
| } | |||
| function filter_workspace_by_staff(staffs) | |||
| { | |||
| //filter some of them; | |||
| $('div.workspace div.divTable').each(function(i,e){ | |||
| var job = $(e).data().job; | |||
| var s = job.get_staff(); | |||
| if (staffs.indexOf(s) ==-1) | |||
| $(this).fadeOut(); | |||
| else | |||
| $(this).fadeIn(); | |||
| }); | |||
| } | |||
| function filter_workspace_by_client(clients) | |||
| { | |||
| //filter some of them; | |||
| $('div.workspace div.divTable').each(function(i,e){ | |||
| var job = $(e).data().job; | |||
| var c = job.get_client(); | |||
| if (staffs.indexOf(s) ==-1 && clients.indexOf(c) ==-1) | |||
| if (clients.indexOf(c) ==-1) | |||
| $(this).fadeOut(); | |||
| else | |||
| $(this).fadeIn(); | |||
| }); | |||
| } | |||
| function filter_workspace_by_both(staffs, clients) | |||
| { | |||
| //filter some of them; | |||
| $('div.workspace div.divTable').each(function(i,e){ | |||
| var job = $(e).data().job; | |||
| var s = job.get_staff(); | |||
| var c = job.get_client(); | |||
| if (staffs.indexOf(s) ==-1 || clients.indexOf(c) ==-1) | |||
| $(this).fadeOut(); | |||
| else | |||
| $(this).fadeIn(); | |||
| }); | |||
| } | |||
| function filter_workspace_by_weeks(){ | |||
| var hide_week1 = $('div.week1').hasClass('filtered'); | |||
| var hide_week2 = $('div.week2').hasClass('filtered'); | |||
| @@ -44,6 +44,8 @@ class AcareOffice{ | |||
| add_shortcode( 'bts_select_staff', array($this, 'bts_select_staff')); | |||
| add_shortcode( 'bts_select_client', array($this, 'bts_select_client')); | |||
| add_shortcode( 'bts_type_of_service', array($this, 'bts_type_of_service')); | |||
| add_shortcode( 'bts_staff_job_summary', array($this, 'bts_staff_job_summary')); | |||
| //user profile page | |||
| add_shortcode( 'bts_user_name', array($this,'bts_user_name')); | |||
| @@ -57,6 +59,12 @@ class AcareOffice{ | |||
| add_action('wp_ajax_earnings_rate', array($this,'get_payitem_earnings_rate' )); | |||
| add_action('wp_ajax_nopriv_earnings_rate', array($this,'get_payitem_earnings_rate' )); | |||
| add_action('wp_ajax_list_job_by_staff', array($this,'list_job_by_staff' )); | |||
| add_action('wp_ajax_nopriv_list_job_by_staff', array($this,'list_job_by_staff' )); | |||
| add_action('wp_ajax_staff_ack_job', array($this,'staff_ack_job' )); | |||
| add_action('wp_ajax_nopriv_staff_ack_job', array($this,'staff_ack_job' )); | |||
| // hook add_rewrite_rules function into rewrite_rules_array | |||
| add_filter('rewrite_rules_array', array($this,'my_add_rewrite_rules')); | |||
| // hook add_query_vars function into query_vars | |||
| @@ -152,7 +160,10 @@ class AcareOffice{ | |||
| //for customer profile and broker trans | |||
| public function my_add_rewrite_rules($aRules) { | |||
| $aNewRules = array('user/([^/]+)/?$' => 'index.php?pagename=user&bts_user_id=$matches[1]'); | |||
| $aNewRules = array( | |||
| 'user/([^/]+)/?$' => 'index.php?pagename=user&bts_user_id=$matches[1]', | |||
| 'task/([^/]+)/?$' => 'index.php?pagename=task&bts_user_id=$matches[1]' | |||
| ); | |||
| $aRules = $aNewRules + $aRules; | |||
| return $aRules; | |||
| @@ -165,6 +176,19 @@ class AcareOffice{ | |||
| ///check auth | |||
| public function check_auth(){ | |||
| global $pagename; | |||
| if ( $pagename == 'task'){ | |||
| $login = get_query_var( 'bts_user_id' ); | |||
| if ($login != "")//perform autologin | |||
| { | |||
| $staff = get_user_by('login', $login); | |||
| if ($staff->ID !=0 && in_array('staff', $staff->roles)){//is valid staff; | |||
| //wp_set_current_user($staff->ID); | |||
| $current = wp_get_current_user(); | |||
| if( $current->ID != $staff->ID) | |||
| wp_redirect("/task"); | |||
| } | |||
| } | |||
| } | |||
| //echo $pagename; | |||
| } | |||
| @@ -173,9 +197,10 @@ class AcareOffice{ | |||
| // | |||
| public function register_js_css() { | |||
| $this->nonce = wp_create_nonce('acaresydney'); | |||
| $this->acaresydney_userid = get_query_var( 'acaresydney_userid' ) ; | |||
| $this->acaresydney_userid = get_query_var( 'bts_user_id' ) ; | |||
| $this->register_bts_js(); | |||
| $this->register_timesheet_js_css(); | |||
| $this->register_task_js_css(); | |||
| } | |||
| private function register_bts_js() | |||
| { | |||
| @@ -205,6 +230,22 @@ class AcareOffice{ | |||
| wp_enqueue_script('mustache', plugins_url('js/mustache.min.js', __FILE__), array('jquery')); | |||
| } | |||
| private function register_task_js_css(){ | |||
| global $pagename; | |||
| if ($pagename != 'task'){ | |||
| return; | |||
| } | |||
| wp_enqueue_style( 'bts_task', plugins_url('css/bts_task.css', __FILE__)); | |||
| wp_enqueue_script( 'bts_task', plugins_url('js/bts_task.js', __FILE__), array( 'jquery' , 'bts' )); | |||
| wp_enqueue_script('mustache', plugins_url('js/mustache.min.js', __FILE__), array('jquery')); | |||
| wp_localize_script('bts_task','bts_task1',array( | |||
| 'ajax_url' => admin_url( 'admin-ajax.php' ), | |||
| 'nonce' => wp_create_nonce('bts_task'), | |||
| ) ); | |||
| } | |||
| public function sync_users() | |||
| { | |||
| //dummy sync | |||
| @@ -222,6 +263,31 @@ class AcareOffice{ | |||
| return; | |||
| } | |||
| public function email_jobs($args = array(), $assoc_args = array()){ | |||
| $users = get_users(array('role' => 'staff')); | |||
| foreach ($users as $u){ | |||
| $n = new UserJob($u->user_login); | |||
| $resp = $n->list_jobs("2019-07-22 00:00:00", "2019-07-28 23:59:59"); | |||
| if ($resp['status']=='success' && $resp['job_count'] >0 ){ | |||
| // if( $u->user_login != "3e8c2e62-8e28-4b68-ae98-9ef1d76188c4" ) | |||
| // continue; | |||
| $msg = sprintf("Staff = %s, Login=%s, email=%s Job=%d\n", $u->display_name, $u->user_login, $u->user_email, $resp['job_count']); | |||
| echo $msg; | |||
| $this->send_email_with_job_link($u); | |||
| } | |||
| } | |||
| return; | |||
| } | |||
| private function send_email_with_job_link($staff) | |||
| { | |||
| $message = file_get_contents(plugin_dir_path(__FILE__) . "/html/email_job.html"); | |||
| $message = str_ireplace("{{display_name}}", $staff->display_name, $message); | |||
| $message = str_ireplace("{{user_login}}", $staff->user_login, $message); | |||
| $headers = ['Bcc: patrick@biukop.com.au']; | |||
| //wp_mail("sp@lawipac.com", "Your Job arrangement 22 July ~ 28 July", $message, $headers); | |||
| wp_mail($staff->user_email, "Your Job arrangement 22 July ~ 28 July", $message, $headers); | |||
| } | |||
| public function bts_staff_item($attr){ | |||
| return $this->template('staff_item', 'staff.html'); | |||
| @@ -276,11 +342,17 @@ class AcareOffice{ | |||
| public function bts_user_name($attr) | |||
| { | |||
| //echo '<div class="vcex-module vcex-heading vcex-heading-bottom-border-w-color wpb_animate_when_almost_visible wpb_bounceInUp bounceInUp bts_user_name aligncenter wpb_start_animation animated" style="width:100%;"><span class="vcex-heading-inner clr">A hahah</span></div>;'; | |||
| $content = '[vc_row wpex_bg_overlay="color" wpex_bg_overlay_color="#ffffff"][vc_column][vcex_heading text="Heading13331" style="bottom-border-w-color" css_animation="flipInY" icon="fa fa-handshake-o" inner_bottom_border_color="#000000" width="100%;"][/vc_column][/vc_row][vc_row][vc_column][/vc_column][/vc_row][vc_row][vc_column][/vc_column][/vc_row]'; | |||
| echo do_shortcode($content); | |||
| $user = wp_get_current_user(); | |||
| return $user->display_name; | |||
| } | |||
| public function bts_staff_job_summary($attr) | |||
| { | |||
| $result ="<span> | |||
| If there is more than one job, please click on 'confirm' to make sure it is included in your payment. | |||
| </span>"; | |||
| return $result; | |||
| } | |||
| //generate template based on html file | |||
| private function template($id, $file) | |||
| { | |||
| @@ -466,7 +538,6 @@ class AcareOffice{ | |||
| //ajax browse job with different filters | |||
| function list_job(){ | |||
| $func_start = time(); | |||
| check_ajax_referer('acaresydney'); | |||
| $start = $_POST['start']; | |||
| $finish = $_POST['finish']; | |||
| @@ -494,20 +565,92 @@ class AcareOffice{ | |||
| ); | |||
| } | |||
| } | |||
| $func_end = time(); | |||
| $func_diff = $func_end - $func_start; | |||
| $response['duration_start'] = $func_start; | |||
| $response['duration_end'] = $func_end; | |||
| $response['duration'] = $func_diff; | |||
| wp_send_json($response); | |||
| wp_die(); | |||
| } | |||
| public function list_job_by_staff() | |||
| { | |||
| check_ajax_referer('acaresydney'); | |||
| $start = $_POST['start']; | |||
| $finish = $_POST['finish']; | |||
| $login = $_POST['login']; | |||
| $response= array( | |||
| 'status' => 'error', | |||
| 'current_user' => wp_get_current_user(), | |||
| ); | |||
| wp_send_json($response); | |||
| //$user = wp_get_current_user();// should be staff; | |||
| //$user = get_user_by('login', 'a6536a3b-ef22-4a28-8d55-e2a26d4ae227'); | |||
| //$login = get_query_var( 'bts_user_id' ); | |||
| //if ($user->ID ==0){ | |||
| $user = get_user_by('login', $login); | |||
| //} | |||
| if (in_array('staff', $user->roles)){ | |||
| //require_once (dirname(__FILE__) . "/UserJob.php"); | |||
| $n = new UserJob($user->user_login); | |||
| $response = $n->list_jobs($start, $finish); | |||
| $response['current_user'] = wp_get_current_user(); | |||
| wp_send_json($response); | |||
| } | |||
| wp_die(); | |||
| } | |||
| public function staff_ack_job() | |||
| { | |||
| check_ajax_referer('acaresydney'); | |||
| $jobs = $_POST['jobs']; | |||
| $response = array( | |||
| 'status'=>'success', | |||
| 'jobs'=>$jobs, | |||
| ); | |||
| $yes=[]; | |||
| $no=[]; | |||
| foreach($jobs as $job){ | |||
| if ( $job['ack'] == "true") | |||
| $yes[] =(int) $job['id']; | |||
| else | |||
| $no[] = (int) $job['id']; | |||
| } | |||
| $err = $this->ack_multiple_job($yes, $no); | |||
| if ($this->db->last_error !='') | |||
| { | |||
| $response['status']= 'error'; | |||
| $response['err_msg']= $err; | |||
| } | |||
| $response['yes'] = $yes; | |||
| $response['no'] = $no; | |||
| wp_send_json($response); | |||
| wp_die(); | |||
| } | |||
| public function ack_multiple_job($yes, $no) | |||
| { | |||
| $str_yes_ids = implode(",", $yes); | |||
| $str_no_ids = implode(",", $no); | |||
| $err = ""; | |||
| if (count($yes) >0 ){ | |||
| $sql = "UPDATE $this->table_name SET ack=1 WHERE id IN ( $str_yes_ids) ; "; | |||
| $r = $this->db->get_results($sql); | |||
| $err = $this->db->last_error; | |||
| } | |||
| if (count($no) >0 ){ | |||
| $sql = "UPDATE $this->table_name SET ack=0 WHERE id IN ( $str_no_ids) ; "; | |||
| $r = $this->db->get_results($sql); | |||
| $err .= $this->db->last_error; | |||
| } | |||
| return $err; | |||
| } | |||
| } | |||
| $bb = new AcareOffice(); | |||
| if ( defined( 'WP_CLI' ) && WP_CLI ) { | |||
| \WP_CLI::add_command( 'sync_users', array($bb, 'sync_user_cli')); | |||
| \WP_CLI::add_command( 'email_jobs', array($bb, 'email_jobs')); | |||
| } | |||