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;
     }
 }
 /**
  * Push notification for mobile when Admin change access point
  *
  * @return      bool
  */
 function push_notification_change_access_point()
 {
     // Get all access point have selected
     $access_point = $this->get_all_access_point(SELECTED);
     if ($access_point != NULL) {
         $this->load->model('users_model');
         $users = Users_model::get_all_users();
         $registation_ids = array();
         if ($users != NULL) {
             foreach ($users as $user) {
                 if ($user->gcm_regid != NULL) {
                     $registation_ids[] = $user->gcm_regid;
                 }
             }
         }
         if ($registation_ids != NULL) {
             $send_notification['data'] = array('type' => 'config_access_point', 'access_point' => $access_point);
             $this->common->send_notification($registation_ids, $send_notification);
             return TRUE;
         } else {
             return FALSE;
         }
     } else {
         return FALSE;
     }
 }
 public function load_users_view($search)
 {
     $message = array('title', 'search', 'search_name', 'email', 'first_name', 'last_name', 'what_taste', 'want_vegan_meal', 'floor', 'role', 'user', 'admin', 'create_user', 'edit', 'delete', 'are_you_sure', 'yes', 'cancel');
     $data = $this->common->set_language_and_data('users', $message);
     $this->load->library('pagination');
     $config['base_url'] = $search == NULL ? base_url() . '/admin/users' : base_url() . '/admin/users/search';
     $config['total_rows'] = Users_model::get_num_of_users($search);
     $config['per_page'] = 10;
     $config['use_page_numbers'] = TRUE;
     $config['uri_segment'] = $search == NULL ? 3 : 4;
     $config['num_links'] = 3;
     $config['full_tag_open'] = "<ul class='pagination'>";
     $config['full_tag_close'] = "</ul>";
     $config['first_link'] = FALSE;
     $config['last_link'] = FALSE;
     $config['num_tag_open'] = '<li>';
     $config['num_tag_close'] = '</li>';
     $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
     $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
     $config['next_tag_open'] = "<li>";
     $config['next_tagl_close'] = "</li>";
     $config['prev_tag_open'] = "<li>";
     $config['prev_tagl_close'] = "</li>";
     $config['first_tag_open'] = "<li>";
     $config['first_tagl_close'] = "</li>";
     $config['last_tag_open'] = "<li>";
     $config['last_tagl_close'] = "</li>";
     $this->pagination->initialize($config);
     $data['pagination'] = $this->pagination->create_links();
     $data['page'] = $search == NULL ? $this->uri->segment(3) ? $this->uri->segment(3) : 0 : ($this->uri->segment(4) ? $this->uri->segment(4) : 0);
     $users = Users_model::get_all_users($config['per_page'], ($data['page'] == 0 ? $data['page'] : $data['page'] - 1) * $config['per_page'], $search);
     $data['users'] = $users;
     $this->common->load_view('admin/users/users', $data);
 }