public function check($source, $items = array()) { foreach ($items as $item => $rules) { foreach ($rules as $rule => $rule_value) { $value = trim(@$source[$item]); $item = escape($item); $disp_text = $rules['disp_text']; if ($rule === 'required' && empty($value)) { $this->addError("{$disp_text} " . lang('CAN_NOT_BE_EMPTY')); } else { if (!empty($value)) { switch ($rule) { case 'min': if (strlen($value) < $rule_value) { $this->addError("{$disp_text} " . lang('MUST_BE_MINIMUM_OF') . " {$rule_value} " . lang('CHARACTERS') . "."); } break; case 'max': if (strlen($value) > $rule_value) { $this->addError("{$disp_text} " . lang('MUST_BE_MAXIMUM_OF') . " {$rule_value} " . lang('CHARACTERS') . "."); } break; case 'valid_email': if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $this->addError("{$value} " . lang('IS_NOT_VALID_EMAIL')); } break; case 'matches': if ($value != $source[$rule_value]) { $this->addError("{$disp_text} " . lang('YOU_ENTERED_DID_NOT_MATCH')); } break; case 'unique': $check = $this->_db->get($rule_value, array($item, '=', $value)); if ($check->count()) { $this->addError("{$disp_text} " . lang('HAS_BEEN_TOKEN')); } break; case 'exists': $check = $this->_db->get($rule_value, array($item, '=', $value)); if (!$check->count()) { $this->addError("{$disp_text} " . lang('NOT_EXISTS')); } break; case 'inArray': if (in_array($source[$item], $rules['inArray']) === false) { $this->addError("{$disp_text} " . lagn('NOT_DEFINED')); } break; case 'regex': if (!preg_match($rules['regex'], $value)) { $this->addError("{$disp_text} must contain only alphanumeric characters and lower case letters."); } break; } } } } } return $this; }
function save_room() { //load language $this->lang->load('reservation/hotels', $this->language); $code = $this->session->userdata('code'); $hotel_id = $this->session->userdata('hotel_id'); $arr = array('name' => $this->input->post('name'), 'capacity' => $this->input->post('capacity'), 'min_capacity' => $this->input->post('min_capacity'), 'max_capacity' => $this->input->post('max_capacity'), 'min_adult' => $this->input->post('min_adult'), 'max_adult' => $this->input->post('max_adult'), 'max_child' => $this->input->post('max_child'), 'default_policy' => $this->input->post('default_policy'), 'room_units' => null !== $this->input->post('room_units') ? implode(',', $this->input->post('room_units')) : '0', 'included' => null !== $this->input->post('room_included') ? implode(',', $this->input->post('room_included')) : '0', 'preferences' => empty($this->input->post('forms')) ? '[]' : $this->input->post('forms'), 'hotel_id' => $hotel_id, 'code' => $code); //update mi yeni mi? if ($this->input->post('update') == 1) { $room_id = $this->input->post('room_id'); $update = $this->db->update('rooms', $arr, array('id' => $room_id)); //diğer dillerdeki açıklamalar $this->db->delete('room_contents', array('room_id' => $room_id)); $description = $this->input->post('description'); foreach ($description as $key => $value) { $this->db->insert('room_contents', array('lang' => $value['lang'], 'content' => $value['desc'], 'title' => $value['title'], 'room_id' => $room_id, 'hotel_id' => $hotel_id)); } //children yaşlarını ekle if ($arr['max_child'] != '0') { $this->db->delete('room_children', array('room_id' => $room_id)); $children = $this->input->post('child_age'); foreach ($children as $key => $child) { $this->db->insert('room_children', array('room_id' => $room_id, 'child_id' => $key, 'child_min' => $child['min'], 'child_max' => $child['max'])); } } if ($update) { $this->session->set_flashdata('success', lang('update_success')); redirect('reservation/rooms/edit/' . $room_id); } else { $this->session->set_flashdata('error', lang('update_error')); redirect('reservation/rooms/edit/' . $room_id); //echo json_encode(array('status' => 'danger','message' => 'Otel Eklenemedi, Lütfen Tekrar Deneyin.')); } //update değilse yeni ekle } else { $insert = $this->db->insert('rooms', $arr); $room_id = $this->db->insert_id(); //diğer dillerdeki açıklamalar $this->db->delete('room_contents', array('room_id' => $room_id)); $description = $this->input->post('description'); foreach ($description as $key => $value) { $this->db->insert('room_contents', array('lang' => $value['lang'], 'content' => $value['desc'], 'title' => $value['title'], 'room_id' => $room_id, 'hotel_id' => $hotel_id)); } //children yaşlarını ekle if ($arr['max_child'] != '0') { $this->db->delete('room_children', array('room_id' => $room_id)); $children = $this->input->post('child_age'); foreach ($children as $key => $child) { $this->db->insert('room_children', array('room_id' => $room_id, 'child_id' => $key, 'child_min' => $child['min'], 'child_max' => $child['max'])); } } if ($insert) { $this->session->set_flashdata('success', lang('added_success')); redirect('reservation/rooms/edit/' . $room_id); } else { $this->session->set_flashdata('error', lagn('added_error')); redirect('reservation/rooms/add_new'); //echo json_encode(array('status' => 'danger','message' => 'Otel Eklenemedi, Lütfen Tekrar Deneyin.')); } } }