office = $office; $this->job_table = $job_table; add_shortcode( 'bts_jobv1_item', array($this, 'bts_jobv1_item')); add_shortcode( 'bb_timesheet_canvas_v1', array($this, 'bb_timesheet_canvas_v1')); add_shortcode( 'bts_jobv1_editor', array($this, 'bts_jobv1_editor')); add_action('wp_ajax_list_jobv1', array($this,'list_job' )); add_action('wp_ajax_delete_jobv1', array($this,'delete_jobv1' )); } public function bts_jobv1_item($attr){ $html =$this->template('jobv1_item', 'jobv1.html'); //$html = str_replace('[bts-tos-options]', $this->bts_tos_options([]), $html); $html = do_shortcode($html); return $html; } public function bts_jobv1_editor($attr){ $html =$this->template('jobv1_editor', 'jobv1_editor.html'); $html = do_shortcode($html); return $html; } public function bb_timesheet_canvas_v1($attr) { return file_get_contents(plugin_dir_path(__FILE__) . "/html/timesheet_canvas_v1.html"); } //generate template based on html file private function template($id, $file) { $text = ''; return $text; } //ajax browse job with different filters function list_job(){ global $wpdb; check_ajax_referer('acaresydney'); $start = $_POST['start'] . " 00:00:00"; $finish = $_POST['finish']. " 23:59:59"; $response = array( 'status'=>'success', 'jobs' => [], 'job_maps' =>[], ); $sql = "SELECT * FROM $this->job_table WHERE start>='%s' and start <='%s' order by start ASC ,staff ASC"; $sql = "SELECT * FROM $this->job_table order by start ASC ,staff ASC"; $query = $wpdb->prepare ($sql, array($start, $finish)); $response['sql'] = $query; $jobs = $wpdb->get_results($query); if (! empty($jobs)){ $response['status'] = 'success'; foreach( $jobs as $s){ $data = 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, ); $response['jobs'][] = $data; $response['jobs_maps'][$s->id] = $data; } } wp_send_json($response); } //ajax delete jobs function delete_jobv1(){ check_ajax_referer('acaresydney'); $id = $_POST['jobid']; $jobs = $_POST['jobs']; if ($id != ''){ $this->ajax_delete_single_job($id); }else if (!empty($jobs)) { $this->ajax_delete_multiple_jobs($jobs); } wp_die(); } private function ajax_delete_single_job($id) { global $wpdb; //delete single job; $result = $wpdb->delete($this->job_table, array('id'=> $id)); $response=array( 'status' => 'success', 'id' => $id, 'action'=> 'delete', 'error' => $wpdb->last_error, ); if ($result == 1){ wp_send_json($response); }else{ $response['status'] = 'error'; $response['error'] = $this->db->last_error; wp_send_json($response); } wp_die(); } private function ajax_delete_multiple_jobs($job_ids) { global $wpdb; $ids = implode( ',', array_map( 'absint', $job_ids ) ); $sql = "DELETE FROM $this->job_table WHERE ID IN($ids)" ; $result = $wpdb->query( "DELETE FROM $this->job_table WHERE ID IN($ids)" ); $response=array( 'status' => 'success', 'ids' => $job_ids, 'action'=> 'delete', 'deleted' => $result, 'error' => $wpdb->last_error, ); if ($this->db->last_error == "" ){ wp_send_json($response); }else{ $response['status'] = 'error'; $response['error'] = $this->db->last_error; wp_send_json($response); } wp_die(); } }