public function addOption() { if ($this->request->isAjax()) { $songname = Convert::raw2sql($_POST['song']); $roomID = Convert::raw2sql($_POST['roomid']); $errors = array(); if (empty($songname)) { $errors[] = "You must enter a song name"; } if (empty($roomID)) { $errors[] = "No Room ID sent. Try refreshing the page."; } $room = Room::get_by_id("Room", is_numeric($roomID) ? $roomID : null); if (!$room) { $errors[] = "No room found. Try refreshing."; } if ($errors) { $returnArray = array(); $returnArray["success"] = false; $returnArray["errorstring"] = "<div class=\"alert alert-info\">" . implode(", ", $errors) . "</div>"; return json_encode($returnArray); } else { $jsonResponse = json_decode($_POST['lastFMResponse'], true); // Register a new option $songOption = new SongOption(); $songOption->Song = $jsonResponse["title"]; $songOption->Artist = $jsonResponse["artist"]; $songOption->Image = $jsonResponse["img"]; $songOption->ParentID = $room->ID; $songOption->write(); $returnArray = array(); $returnArray["success"] = true; $returnArray["nextstep"] = "/room/" . $room->Segment; return json_encode($returnArray); } } }
public function update($group_id) { $this->load->library('form_validation'); $this->form_validation->set_rules('room[name]', 'lang:admin_rooms_form_field_name', 'required'); $this->form_validation->set_rules('room[time_begin]', 'lang:admin_rooms_form_field_time_begin', 'required|callback__is_time'); $this->form_validation->set_rules('room[time_end]', 'lang:admin_rooms_form_field_time_end', 'required|callback__is_time|callback__is_later_time'); $this->form_validation->set_rules('room[time_day]', 'lang:admin_rooms_form_field_time_day', 'required|callback__is_day'); $this->form_validation->set_rules('room[capacity]', 'lang:admin_rooms_form_field_capacity', 'required|integer|greater_than[0]'); $this->form_validation->set_rules('room_id', 'room_id', 'required'); $this->form_validation->set_message('_is_time', $this->lang->line('admin_rooms_form_error_message_is_time')); $this->form_validation->set_message('_is_day', $this->lang->line('admin_rooms_form_error_message_is_day')); $this->form_validation->set_message('_is_later_time', $this->lang->line('admin_rooms_form_error_message_is_later_time')); if ($this->form_validation->run()) { $room_id = intval($this->input->post('room_id')); $room = new Room(); $room->get_by_id($room_id); if ($room->exists()) { $room_data = $this->input->post('room'); $room->from_array($room_data, array('name', 'time_day')); $room->time_begin = $this->time_to_int($room_data['time_begin']); $room->time_end = $this->time_to_int($room_data['time_end']); $room->capacity = intval($room_data['capacity']); $this->_transaction_isolation(); $this->db->trans_begin(); if (trim($room_data['teachers_plain']) != '') { $room->teachers_plain = trim($room_data['teachers_plain']); } else { $room->teachers_plain = NULL; } $current_teachers = $room->teacher->get(); $room->delete($current_teachers->all); $teachers = new Teacher(); if (is_array($room_data['teachers']) && count($room_data['teachers'])) { foreach ($room_data['teachers'] as $teacher_id) { $teachers->or_where('id', $teacher_id); } $teachers->get(); } if ($room->save(array($teachers->all)) && $this->db->trans_status()) { $this->db->trans_commit(); $this->messages->add_message('lang:admin_rooms_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); $room->group->get(); $this->output->set_internal_value('course_id', $room->group->course_id); } else { $this->db->trans_rollback(); $this->messages->add_message('lang:admin_rooms_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR); } } else { $this->messages->add_message('lang:admin_rooms_error_room_not_found', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('admin_rooms/index/' . $group_id)); } else { $this->edit($group_id); } }