function parseFind($csvFile, $afm, $surname) { // init vars $empOffset = 5; $anadrData = []; // parse csv & find employee $csv = new parseCSV(); $csv->encoding('iso8859-7', 'UTF-8'); $csv->delimiter = ";"; $csv->heading = false; // find employee T.M. $csv->offset = $empOffset; $condition = '8 is ' . $afm . ' AND 1 contains ' . grstrtoupper($surname); $csv->conditions = $condition; $csv->parse($csvFile); $parsed = $csv->data; // enhanced check of surname (instead of 'contains' in fullname) if ($parsed) { $tmp = explode(' ', $parsed[0][1]); $fileSurname = $tmp[0]; if (strcmp(grstrtoupper($surname), $fileSurname) != 0) { return ['parsed' => [], 'month' => []]; } } // find month $csv->offset = 1; $csv->conditions = '19 contains ΜΙΣΘΟΔΟΣΙΑ'; $csv->parse($csvFile); //$csv->fields =[19]; $data = $csv->data; $tmp = explode(' ', $data[0][19]); $month = $tmp[2] . '_' . $tmp[3]; // find anadromika (if any) $csv->offset = $empOffset; $csv->conditions = ''; $csv->parse($csvFile); $data = $csv->data; $i = $foundFrom = $foundTo = 0; foreach ($data as $row) { if (array_key_exists('8', $row) && $afm == $row[8] && !$foundFrom) { $foundFrom = $i; } if ($foundFrom && !$foundTo && array_key_exists('8', $row)) { if ($row[8] != '' && $row[8] != $afm) { $foundTo = $i - 1; } } $i++; } $tempData = array_slice($data, $foundFrom, $foundTo - $foundFrom + 1); foreach ($tempData as $line) { if ($line[10] == 'ΑΝΑΔΡΟΜΙΚΑ') { $anadrData = $line; } } if (count($anadrData) > 0) { array_push($parsed, $anadrData); } return ['parsed' => $parsed, 'month' => $month]; }
function add_post() { $appointment_data = empty($this->post('service') || $this->post('provider') || $this->post('start_datetime') || $this->post('end_datetime') || $this->post('user_id')) ? FALSE : TRUE; if ($appointment_data) { $this->load->model('appointments_model'); $this->load->model('providers_model'); $this->load->model('services_model'); $this->load->model('customers_model'); $this->load->helper('greek_string'); $appointment = array('id_services' => $this->post('service'), 'id_users_provider' => $this->post('provider'), 'start_datetime' => $this->post('start_datetime'), 'end_datetime' => $this->post('end_datetime'), 'notes' => grstrtoupper(strip_tags($this->post('notes'))), 'id_users_customer' => $this->post('user_id')); $manage_mode = isset($appointment['id']); $appointment['id'] = $this->appointments_model->add($appointment); //Send mail notification if (MAIL_NOTIFICATIONS) { $this->sendMailNotification($appointment, $manage_mode); } if (!empty($appointment['id'])) { $this->response(array('success' => 'Appointment saved successfully!'), 200); // 200 being the HTTP response code } else { $this->response(array('error' => 'There was a problem while adding an appointment!'), 500); } } }