public function write($user_id) { if (!empty($this->posts)) { $this->fields = array('title'); $this->errors = array('required'); $this->runValidator($this->fields, $this->errors); //Check for errors if ($this->form_validation->run() == FALSE) { //show the form and send the parameters of the failed fields echo json_encode($this->form_validation->error_array()); return false; } else { //Add the time and date when the user registers with cleansure $date_id = $this->Registration_Model->insert_return(array('date' => insert_date($this->time)), 'date'); $message_id = $this->messages_model->insert_return(array_merge(array_slice($this->posts, 1, 2), array('sent' => true, 'inbox' => true, 'status' => true, 'note' => false, 'user_id' => $this->data['data']->user_id, 'date_id' => $date_id)), 'messages'); $recipitent = array('recipitent_id' => $this->posts['reciptent_id'], 'message_id' => $message_id, 'status' => true); $this->messages_model->insert($recipitent, 'recipitent'); echo json_encode(array('message' => 'Message Sent')); return false; } } else { $levels = array(1, 2, 3, 5); $args = array('users.master_id' => $this->data['data']->master_id, 'users.company_id' => $this->data['data']->company_id); $accounts = $this->auth_model->get_accounts($args, $levels); $this->data['members'] = array(); foreach ($accounts as $user) { if ($user['u_id'] != $this->data['data']->user_id) { $this->data['members'][$user['u_id']] = $user['title'] . ' ' . $user['first_name'] . ' ' . $user['last_name']; } } $this->load->view($this->data['modules'] . 'clientarea_messages_write', $this->data); } }
public function add() { if (!empty($this->posts)) { //all the fields that want validation $this->fields = array('identifier', 'log_num', 'type', 'age', 'date[]'); //Correspoding errors $this->errors = array('required', 'required', 'required', 'required', 'required'); /* * Created a function to return the loop */ $this->runValidator($this->fields, $this->errors); //Check for errors if ($this->form_validation->run() == FALSE) { echo json_encode($this->form_validation->error_array()); } else { /* * Insert the dates array into the dbn and retrieve the appropriate keys * * format the data, rebuild the array ready for batch insert... * */ foreach ($this->posts['date'] as $d) { $dates['date'][] = insert_date($d); } $keys = $this->machinery_model->batch_insert($dates, 'date', NULL); /* * Unset the date value to we can create a clean insert... * * */ unset($this->posts['date']); $machineArray = array('aq_date' => (int) $keys[0], 'pat_date' => $this->posts['pat_tested'] == true ? (int) $keys[1] : false, 'master_id' => $this->data['data']->master_id); $this->machinery_model->insert(array_merge($this->posts, $machineArray), 'machinery'); echo json_encode(array('message' => 'Machinery Has Been added successfuly....')); return false; } return false; } $this->view($this->master, $this->prefix, $this->file_ext); }
function pars_data($url, $config, $lang, $name, $roster, $pars = 'all') { //print_r($url); $html = str_get_html($url); $newr = $html->find('div[class=b-data-create]', 0); $newu = $html->find('div[class=b-data-date]', 0); $veh = ''; //if(VEH == 'alter'){ // $veh = $html->find('table[class=t-statistic]',1); //} $array['date'] = pars_date($newr->outertext, $newu->outertext, $config); if (count($array['date']) < 1) { $new = array(); } else { $new['date'] = $array['date']; if (LAST_PLAYED == 'on' && MYSQL == 'on' && MYSQL_ERROR != 'on' && $pars != 'all') { insert_date($array, $name, SERVER, $config); } } if ($pars == 'all') { $array['stats'] = parseTable($html, $config, $veh); if (MYSQL == 'on' && MYSQL_ERROR != 'on') { insert_rating_old($array, $lang, $name, SERVER, $config, $roster); } if (count($array['stats']) < 1) { $array['stats'] = array(); $new = array(); } $html->clear(); unset($html, $newr, $newu, $array['date']); unset($array['stats'][0]); if (count($array['stats']) > 0) { foreach ($array['stats'][1] as $val) { $tmp = str_replace(':', '', trim($val[$lang['overall_title']])); $num = explode('(', trim($val[0])); $new['overall'][$tmp] = str_replace(' ', '', $num[0]); } unset($array['stats'][1]); foreach ($array['stats'][2] as $val) { $tmp = str_replace(':', '', trim($val[$lang['perform_title']])); $num = explode('(', trim($val[0])); $new['perform'][$tmp] = str_replace(' ', '', $num[0]); } unset($array['stats'][2]); foreach ($array['stats'][3] as $val) { $tmp = str_replace(':', '', trim($val[$lang['battel_title']])); $num = explode('(', trim($val[0])); $new['exp'][$tmp] = str_replace(' ', '', $num[0]); } unset($array['stats'][3]); foreach ($array['stats'][4] as $val) { $tmp = trim($val[$lang['place']]); $new['rating'][$tmp]['type'] = $val[$lang['rating_title']]; $new['rating'][$tmp]['link'] = $val[$lang['value']]; $new['rating'][$tmp]['name'] = $val[$lang['place']]; $new['rating'][$tmp]['value'] = str_replace(' ', '', $val[0]); $new['rating'][$tmp]['place'] = str_replace(' ', '', $val[1]); } unset($array['stats'][4]); if (isset($array['stats'][5])) { foreach ($array['stats'][5] as $val) { $tmp = trim($val[$lang['battle']]); $new['tank'][number_transform($val[0])][$tmp]['type'] = $val[$lang['battle']]; $new['tank'][number_transform($val[0])][$tmp]['total'] = str_replace(' ', '', $val[$lang['win']]); $new['tank'][number_transform($val[0])][$tmp]['link'] = $val[$lang['tank']]; $new['tank'][number_transform($val[0])][$tmp]['win'] = str_replace(' ', '', $val[1]); $new['tank'][number_transform($val[0])][$tmp]['nation'] = str_replace(' ', '', $val[2]); $new['tank'][number_transform($val[0])][$tmp]['lvl'] = number_transform($val[0]); } unset($array['stats'][5]); } } } return $new; }
/** * Clean the post vars for the search area * * we are sending different keys so we need to change them * * accordingly.. * * We already trimmed of any empty vars.. * * @param array */ private function post_filter($post_vars) { //if customers dropdown is left at 'select' option.. if ($post_vars['customers'] == 'Select One...') { //Get rid if it is.. unset($post_vars['customers']); } //Create an array for keys and replacement keys $find_replace = array('customers' => 'orders.company_id', 'date_from' => 'date.date >', 'date_to' => 'date.date <'); //Loop them to find any that need replacing foreach ($find_replace as $find => $replace) { //Does the key exist that needs replacing if (array_key_exists($find, $post_vars)) { //Create the new var.. $post_vars[$replace] = strpos($find, 'date') !== false ? insert_date($post_vars[$find]) : $post_vars[$find]; //Unset the old var.. unset($post_vars[$find]); } } //return function output.. return $post_vars; }
public function updateDate($id) { if (!empty($this->posts)) { $this->worders_model->update_row($id, 'id', 'date', array('date' => insert_date($this->posts['date'][0]))); echo json_encode(array('message' => 'Date Updated')); return false; } $this->data['row_data'] = $this->worders_model->get_row('date', 'id', $id); $this->load->view('modules/datepicker', $this->data); }
public function products($company_id, $product_id = NULL, $measurement_id = false, $date_id = false) { if ($product_id != NULL) { $this->data['row_data'] = $this->supplier_model->get_product($product_id); } if (!empty($this->posts)) { //Fields to be validated $this->fields = array('name', 'type', 'cost', 'price'); //Corresponding errors $this->errors = array('required', 'required', 'required|decimal', 'required|decimal'); //Run them through the validator $this->runValidator($this->fields, $this->errors); //Check for errors if ($this->form_validation->run() == FALSE) { //show the form and send the parameters of the failed fields echo json_encode($this->form_validation->error_array()); return false; } else { if ($measurement_id != false && $date_id != false) { $keys = array(array('products', $product_id, 0, 7), array('measurments', $measurement_id, 8, 4)); for ($i = 0; $i < 2; $i++) { $this->supplier_model->update_row($keys[$i][1], 'id', $keys[$i][0], array_slice($this->posts, $keys[$i][2], $keys[$i][3])); } $this->supplier_model->update_row($date_id, 'id', 'date', array('date' => insert_date($this->posts['date'][0]))); //Return json success message echo json_encode(array('message' => 'Successfully Updated Product')); return false; } else { $measurement_id = $this->supplier_model->insert_return(array_slice($this->posts, 8, 4), 'measurments'); $date_id = $this->supplier_model->insert_return(array('date' => insert_date($this->posts['date'][0])), 'date'); $vars = array_merge(array('measurement_id' => $measurement_id, 'date_id' => $date_id, 'company_id' => $company_id, 'master_id' => $this->data['data']->master_id), array_slice($this->posts, 0, 7)); $this->supplier_model->insert($vars, 'products'); //Return json success message echo json_encode(array('message' => 'Successfully Added Product')); return false; } } } if ($product_id != NULl && $measurement_id == false) { $this->load->view($this->data['modules'] . 'product_overview', $this->data); } else { $this->data['type'] = array('1' => 'Product', '2' => 'consumable', '3' => 'Both'); $this->load->view($this->data['modules'] . 'products', $this->data); } }
public function holidays($view, $staff_id) { /* * Get Staff Members Name * */ $staff_name = $this->staff_model->staff_name($staff_id); /* * We need to check if we are posting data * */ if (!empty($this->posts)) { //all the fields that want validation $this->fields = array('date[]'); //Correspoding errors $this->errors = array('required'); //Run them through the validator $this->runValidator($this->fields, $this->errors); //Check for errors if ($this->form_validation->run() == FALSE) { //Check we are dealing with ajax if ($this->input->is_ajax_request()) { //Run the warning function $this->warning('staff_warning'); } else { //show the form and send the parameters of the failed fields $this->form_validation->error_array(); } } else { /* * Loop through the posts and rebuild array to format dates * * ready to be inserted into the database... * */ foreach ($this->posts['date'] as $p) { $dates[] = insert_date($p); } /* * Unset the post array so don't duplicate bad data * */ unset($this->posts['date']); /* * Move the new array back into post array ready for insertion * */ $this->posts['date'] = $dates; /* * Batch insert of the dates into the * * dates table and return both the last inserted keys.. * */ /* * We need to run some checks here, are we posting or editing... * * Using the below switch, we can alternate the functions accordingly... * */ switch ($view) { /* * We are dealing with inserting a holiday first.. * */ case 'holiday_request': $date_ids = $this->staff_model->my_array($this->posts, 'date', NULL, NULL); /* * We now take the keys from inserting the dates and use the array to insert into holidays table... * * We then need to add further keys to the array as its a new holiday request * * Request = if the holiday is still in request mode, Approval = has it been approved by a manager? * * Type = 0 = start date | 1 = end date, we can the calculate the duration * */ $this->customer_model->insert(array('staff_id' => $staff_id, 'request' => false, 'approval' => false, 'year' => date('Y'), 'start_id' => $date_ids[0], 'end_id' => $date_ids[1]), 'holidays'); /** * Private Alert function * * @param $staff_id * * @param $event * */ $this->addAlert($staff_id, sprintf($this->lang->line('holdiday_request_event'), $staff_name->first_name . ' ' . $staff_name->last_name)); break; /* * If we are updating holiday data we use the below statement * * */ /* * If we are updating holiday data we use the below statement * * */ case 'staff_holidays': if (!isset($this->posts['ids'])) { $this->holidays('holiday_request', $staff_id); return false; } /* * We create some ids with jquery and append them with hidden input * * explode the value to get the correct keys * */ $ids = explode('#', $this->posts['ids']); /* * Start the counter * */ $n = 0; /* * Loop the ids and update each row accordingly * */ foreach ($ids as $id) { $this->staff_model->update_row($id, 'id', 'date', array('date' => $dates[$n])); $n++; } /** * Private Alert function * * @param $staff_id * * @param $event * */ $this->addAlert($staff_id, $this->data['data']->first_name . ' ' . $this->data['data']->last_name . sprintf($this->lang->line('holdiday_edit_event'), $staff_name->first_name . ' ' . $staff_name->last_name)); break; } //Return json success message echo json_encode(array('message' => 'Successfully updated')); return false; } } else { /* * Run a check on which view we are dealing with * * */ if ($view == 'staff_holidays') { /* * We got the right view * */ $data = $this->staff_model->get_holiday_dates($staff_id); /* * Check $arr length, is it greater than 0, if yes we have some dates * */ if (is_array($data) && count($data) > 0) { /* * Which staff member are we applying the holidays to */ $this->data['header'] = $data[0]->first_name . " " . $data[0]->last_name . " - " . $data[0]->reference; /* * Loop the data * */ foreach ($data as $d) { /* * Upcoming holiday, it has been authorized by admin and the date is greater then the current date * */ if ($d->request == true && $d->approval == true && strtotime($d->finish_date) > time()) { /* * Create a an array for the dates */ $this->data['row_data_1'][] = $d; } elseif ($d->request == true && $d->approval == true && strtotime($d->finish_date) < time()) { /* * Create a an array for the dates */ $this->data['row_data_2'][] = $d; } elseif ($d->request == false) { /* * Create a an array for the dates */ $this->data['row_data_3'][] = $d; } } } } $this->load->view($this->modules . $view, $this->data); } }