function get_tables_from_shift()
 {
     $this->common->authenticate();
     $shift_id = $this->input->post('shift_id');
     $day = $this->input->post('day');
     $for_vegans = $day == NORMAL_DAY ? 0 : NULL;
     $this->load->model('tables_model');
     $this->load->model('shifts_model');
     $tables = Tables_model::get_tables_by_shift($shift_id, $for_vegans, $day);
     $data['tables'] = $tables;
     $data['shift'] = Shifts_model::get_shift_by_id($shift_id);
     echo json_encode($data);
 }
 public function load_edit_table_view($table_id)
 {
     $message = array('title', 'description', 'manage_tables', 'table', 'for_vegans', 'list_of_users', 'shift', 'seats', 'image', 'name', 'delete', 'are_you_sure', 'yes', 'cancel', 'floor', 'edit');
     $data = $this->common->set_language_and_data('edit_table', $message);
     $this->load->model('shifts_model');
     $data['shifts'] = Shifts_model::get_all_shifts();
     $data['table'] = Tables_model::get_table_by($table_id);
     $data['users'] = Tables_model::get_users_in_table($table_id);
     $this->common->load_view('admin/tables/edit_table', $data);
 }
 public function store_or_edit_shift($request, $shift_id = NULL)
 {
     $shift = $this->input->post('shift');
     $description = $this->input->post('description');
     $start_time = date("H:i", strtotime($this->input->post('start_time')));
     $end_time = date("H:i", strtotime($this->input->post('end_time')));
     $data = array('name' => $shift, 'description' => $description, 'start_time' => $start_time, 'end_time' => $end_time);
     if ($request == 'add') {
         return Shifts_model::insert_shift($data);
     } else {
         return Shifts_model::update_shift($shift_id, $data);
     }
 }
 public function store_announcement()
 {
     $this->load->model('users_model');
     $data['user_id'] = (int) $this->session->userdata('logged_in')['user_id'];
     $data['title'] = $this->input->post('subject');
     $data['content'] = $this->input->post('content');
     $data['meal_date'] = $this->input->post('lunch_date');
     $announcement_for = $this->input->post('announcement_for');
     $users = array();
     switch ($announcement_for) {
         case ANNOUNCEMENT_USER:
             $data['user'] = $this->input->post('user');
             $users[] = Users_model::get_user_by('id', $data['user']);
             break;
         case ANNOUNCEMENT_TABLE:
             $data['table'] = $this->input->post('table');
             $this->load->model('tables_model');
             $users = Tables_model::get_users_in_table($data['table']);
             break;
         case ANNOUNCEMENT_SHIFT:
             $data['shift'] = $this->input->post('shift');
             $this->load->model('shifts_model');
             $users = Shifts_model::get_users_by_shift($data['shift']);
             break;
         default:
             $data['user'] = '******';
             $users = Users_model::get_all_users();
             break;
     }
     list($result, $announcement_id) = Announcements_model::insert_announcement($data);
     if ($result) {
         $registation_ids = array();
         if ($users != NULL) {
             foreach ($users as $user) {
                 if ($user->gcm_regid != NULL) {
                     $registation_ids[] = $user->gcm_regid;
                 }
             }
         }
         $user = array();
         $user['avatar_content_file'] = $this->session->userdata('logged_in')['avatar_content_file'];
         $user['email'] = $this->session->userdata('logged_in')['email'];
         $user['id'] = (int) $this->session->userdata('logged_in')['user_id'];
         if ($registation_ids != NULL) {
             $send_notification['data'] = array('type' => 'announcement', 'announcement' => array('id' => (int) $announcement_id, 'title' => $data['title'], 'content' => $data['content'], 'meal_date' => $data['meal_date'], 'read_flag' => FALSE, 'number_of_replies' => 0, 'number_of_have_read_replies' => 0, 'created_at' => date('Y-m-d H:i:s'), 'email' => $user['email'], 'avatar_content_file' => $user['avatar_content_file'], 'user_id' => $user['id']));
             $this->common->send_notification($registation_ids, $send_notification);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 public function load_edit_user_view($user_id)
 {
     $user = Users_model::get_user_by('id', $user_id);
     $image_data['file_name'] = $user->avatar_file_name;
     $this->session->set_userdata('upload', $image_data);
     $message = array('title', 'manage_users', 'email', 'password', 'confirm_password', 'what_taste', 'edit', 'want_vegan_meal', 'first_name', 'last_name', 'floor', 'shift', 'admin', 'user', 'role', 'image_upload', 'avatar', 'change_password', 'change_shift', 'yes', 'cancel');
     $data = $this->common->set_language_and_data('edit_user', $message);
     $this->load->model('floors_model');
     $data['floors'] = Floors_model::get_all_floors();
     $this->load->model('shifts_model');
     $data['shifts'] = Shifts_model::get_all_shifts();
     $data['user'] = $user;
     $this->common->load_view('admin/users/edit_user', $data);
 }