|
%s is loading .... please wait...
|
ZOT;
foreach ($users as $u)
{
$payment = get_user_meta($u->ID, 'payment', true);
if ( $attr['preferred'] == 'true' ){
if( $payment == 'invoice' ){
$invoice_preferred = "invoice_preferred";
$result .= sprintf($row,
$u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name,
$u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name);
}
}else{
$invoice_preferred = "";
if( $payment != 'invoice' ){
$result .= sprintf($row,
$u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name,
$u->user_login, $u->user_login, $invoice_preferred, $u->user_login, $u->display_name);
}
}
}
return $result;
}
//generate template based on html file
private function template($id, $file)
{
$text = '';
return $text;
}
function list_staff(){
check_ajax_referer('acaresydney');
// Handle the ajax request
$response = array(
'status' =>'error',
'users' => [],
);
//search all users that are staff
$staffq = new \WP_User_Query(array('role'=>'staff','meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC'));
$staff = $staffq->get_results();
if (! empty($staff)){
$response['status'] = 'success';
foreach( $staff as $s){
$response['users'][] = array(
'login' => $s->user_login,
'firstname'=> $s->first_name,
'lastname'=> $s->last_name,
'display_name' => $s->display_name,
'mobile'=> get_user_meta($s->ID, 'mobile', true),
'email'=> $s->user_email,
'wages'=> 0,
'hour' => 0 ,
'OT' => 0 ,
'petrol'=> 0 ,
'rating'=> 0,
'unconfirmedjob'=> 0,
);
}
}
wp_send_json($response);
wp_die();
}
function list_client(){
check_ajax_referer('acaresydney');
$user = wp_get_current_user();
// Handle the ajax request
$response = array(
'status' =>'error',
'users' => [],
'role' => $user,
);
//search all users that are staff
$clientq = new \WP_User_Query(array('role'=>'client', 'meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC'));
$client = $clientq->get_results();
if (! empty($client)){
$response['status'] = 'success';
foreach( $client as $s){
$data_item = array(
'login' => $s->user_login,
'firstname'=> $s->first_name,
'lastname'=> $s->last_name,
'display_name'=> $s->display_name,
'mobile'=> get_user_meta($s->ID, 'mobile', true),
'email'=> $s->user_email,
'account'=> get_user_meta($s->ID, 'account', true),
'address' => get_user_meta($s->ID, 'address', true),
'payment'=>get_user_meta($s->ID, 'payment', true),
'rating'=> 0,
'unconfirmedjob'=> 0,
);
$response['users'][] = $data_item;
}
}
wp_send_json($response);
wp_die();
}
//ajax
function list_tos() {
check_ajax_referer('acaresydney');
// Handle the ajax request
$response = array(
'status' =>'success',
'tos' => [],
);
$price = $this->get_ndis_price();
$response['tos']= $price->get_tos_array();
wp_send_json($response);
}
private function get_people_by_role($role){
//search all users that are staff
$staffq = new \WP_User_Query(array('role'=>$role, 'meta_key'=>'first_name', 'orderby'=>'meta_value', 'order'=>'ASC'));
$staff = $staffq->get_results();
return $staff;
}
//ajax get earnings rates
function earnings_rate()
{
$response= array(
'status' => 'success',
'options'=> get_option('bts_payitem_earnings_rate'),
);
wp_send_json($response);
}
//ajax job CRUD
function save_job()
{
check_ajax_referer('acaresydney');
$r = $_POST['record'];
$response = array();
$d = array(
'tos' => $r['tos'],
'start' => $r['start'],
'finish' => $r['finish'],
'rate' => $r['rate'],
'staff' => $r['staff'],
'client' => $r['client'],
'ack' => $r['ack']=='true'?1:0,
'rating'=>$r['rating'],
);
//this is an update
if ( isset($r['id']) && trim($r['id']) !='' && is_numeric($r['id'])){
$response['isNew'] = false; //add or update?
$result = $this->db->update($this->table_name, $d, array('id' =>$r['id']));
if ($result !== false && $this->db->last_error == ''){
$d['id'] = $r['id'];
$response['status'] = 'success';
//do data type conversion, string to int
$response['newdata'] = $this->get_ts_record($r['id']);
$response['errors'] = array(); //empty array
}else{
$response['status'] = 'error';
$repsonse['errors'] = array(
'db' => "network database error" . $this->db->last_error,
);
}
}else{
$response['isNew'] = true;
$result = $this->db->insert($this->table_name, $d);
$lastid = $this->db->insert_id;
if ($result != false && $this->db->last_error == ''){
$response['status'] = 'success';
$response['newdata'] = $this->get_ts_record($lastid);
}else{
$response['status'] = 'error';
$response['errors'] = array(
'db' => 'network database error ' . $this->db->last_error,
);
}
}
wp_send_json($response);
wp_die();
}
private function get_ts_record($id){
$sql = "SELECT * FROM $this->table_name WHERE id=%d";
$row = $this->db->get_row($this->db->prepare ($sql, array($id)));
$response = [];
if ($row != null){
$response = array(
'id' => (int)$row->id,
'tos' => $row->tos,
'start' => $row->start,
'finish' => $row->finish,
'rate' => $row->rate,
'staff' => $row->staff,
'client' => $row->client,
'ack' => (int)$row->ack,
'rating' =>(int) $row->rating,
);
}
return $response;
}
//ajax delete job
function delete_job(){
check_ajax_referer('acaresydney');
$id = $_POST['jobid'];
$result = $this->db->delete($this->table_name, array('id'=> $id));
$response=array(
'status' => 'success',
'id' => $id,
'action'=> 'delete',
'error' => '',
);
if ($result == 1){
wp_send_json($response);
}else{
$response['status'] = 'error';
$response['error'] = $this->db->last_error;
wp_send_json($response);
}
wp_die();
}
//ajax email staff their job arrangement
function email_job()
{
check_ajax_referer('acaresydney');
$staff = $_POST['staff'];
$start = $_POST['start'];
$finish = $_POST['finish'];
$response=array(
'status' => 'success',
'staff' => $staff,
'start' => $start,
'finish' => $finish,
'error' => '',
'sent' => false,
'emailstatus'=>"Bypass (no job)",
);
$u = get_user_by('login', $staff);
if ($this->is_staff($u)){
$n = new UserJob($staff);
$resp = $n->list_jobs_by_staff("$start 00:00:00", "$finish 23:59:59");
if ($resp['status']=='success' && $resp['job_count'] >0 ){
$msg = sprintf("Email to