Exemple #1
0
 public function ajax_appointments()
 {
     $data = $this->parse_input_data();
     $response = array();
     if ($this->type === 'GET') {
         $response = $this->models->get_all_appointments($data);
     }
     die(json_encode($response));
 }
 public function ajax_export()
 {
     $data = $this->parse_input_data();
     $workersTmp = $response = $this->models->get_all_rows('ea_staff');
     $locationsTmp = $response = $this->models->get_all_rows('ea_locations');
     $servicesTmp = $response = $this->models->get_all_rows('ea_services');
     $workers = array();
     $locations = array();
     $services = array();
     foreach ($workersTmp as $w) {
         $workers[$w->id] = $w->name;
     }
     foreach ($locationsTmp as $l) {
         $locations[$l->id] = $l->name;
     }
     foreach ($servicesTmp as $s) {
         $services[$s->id] = $s->name;
     }
     // print_r($workersTmp);die;
     header('Content-Encoding: UTF-8');
     header('Content-type: text/csv; charset=UTF-8');
     header('Content-Disposition: attachment; filename=Customers_Export.csv');
     echo "";
     // UTF-8 BOM
     // set_time_limit(0);
     $params = array('from' => $data['ea-export-from'], 'to' => $data['ea-export-to']);
     $rows = $this->models->get_all_appointments($params);
     $out = fopen('php://output', 'w');
     if (count($rows) > 0) {
         $arr = get_object_vars($rows[0]);
         $keys = array_keys($arr);
         fputcsv($out, $keys);
     }
     foreach ($rows as $row) {
         $arr = get_object_vars($row);
         $arr['worker'] = $workers[$arr['worker']];
         $arr['location'] = $locations[$arr['location']];
         $arr['service'] = $services[$arr['service']];
         fputcsv($out, $arr);
     }
     fclose($out);
     die;
 }