Example #1
0
 function insert()
 {
     $model = HC_App::model('user');
     /* supplied as parameters */
     $args = func_get_args();
     $values = hc_parse_args($args);
     /* if post supplied */
     $post = $this->input->post();
     if ($post) {
         $this->forms['add']->grab($post);
         $post = $this->forms['add']->values();
         $values = array_merge($values, $post);
     }
     if (!$values) {
         $redirect_to = 'admin/users/add';
         $this->redirect($redirect_to);
         return;
     }
     $related = $model->from_array($values);
     if ($model->save($related)) {
         /* save and redirect here */
         $msg = HCM::__('User added');
         $this->session->set_flashdata('message', $msg);
         $redirect_to = 'admin/users/index';
         $this->redirect($redirect_to);
     } else {
         /* final layout */
         $this->layout->set_partial('content', Modules::run('admin/users/add/index', $model));
         $this->layout();
     }
 }
Example #2
0
 function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['id'])) {
         echo 'PARAMS MISSING IN availability/delete<br>';
         return;
     }
     $id = $args['id'];
     $model = HC_App::model('availability');
     $model->where('id', $id)->get();
     $this->_check_model($model);
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('delete')) {
         return;
     }
     /* what to refresh on referring page */
     $parent_refresh = $model->present_calendar_refresh();
     $parent_refresh = array_keys($parent_refresh);
     if ($model->delete()) {
         $this->session->set_flashdata('message', HCM::__('Availability deleted'));
     } else {
         $this->session->set_flashdata('error', HCM::__('Error'));
     }
     $redirect_to = $this->my_parent();
     $this->redirect($redirect_to, $parent_refresh);
 }
Example #3
0
 private function _update($tab, $args)
 {
     $id = array_shift($args);
     $model = HC_App::model('user');
     $model->where('id', $id)->get();
     $this->_check_model($model);
     $original_model = clone $model;
     /* supplied as parameters */
     $values = hc_parse_args($args);
     /* if post supplied */
     $post = $this->input->post();
     if ($post) {
         $this->forms[$tab]->grab($post);
         $post = $this->forms[$tab]->values();
         $values = array_merge($values, $post);
     }
     if (!$values) {
         $redirect_to = 'admin/users/zoom/index/id/' . $id . '/tab/' . $tab;
         $this->redirect($redirect_to);
         return;
     }
     $related = $model->from_array($values);
     if ($model->save($related)) {
         /* save and redirect here */
         $msg = HCM::__('User updated');
         $this->session->set_flashdata('message', $msg);
         $redirect_to = 'admin/users/zoom/index/id/' . $id . '/tab/' . $tab;
         $this->redirect($redirect_to);
     } else {
         /* final layout */
         $this->layout->set_partial('content', Modules::run('admin/users/zoom/index', 'id', $model, 'tab', $tab));
         $this->layout();
     }
 }
Example #4
0
 public function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['id'])) {
         echo 'PARAMS MISSING IN availability/update/index<br>';
         return;
     }
     $id = $args['id'];
     if (is_object($id)) {
         $model = $id;
     } else {
         $model = HC_App::model('availability');
         $model->where('id', $id)->get();
         $this->_check_model($model);
     }
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('edit')) {
         return;
     }
     // $values = hc_parse_args( $args );
     $values = array();
     $form = $this->form_edit;
     $post = $this->input->post();
     if ($post) {
         $form->grab($post);
         $form_values = $form->values();
         $values = array_merge($values, $form_values);
     }
     $date_value = $form->input('date')->value(TRUE);
     if ($date_value['recurring'] == 'single') {
         $values['date_start'] = $date_value['datesingle'];
         $values['date_end'] = $date_value['datesingle'];
         $values['details'] = '';
     } else {
         $values['date_start'] = $date_value['datestart'];
         $values['date_end'] = $date_value['dateend'];
         $values['details'] = $form->input('date')->value(FALSE, TRUE);
     }
     unset($values['date']);
     $related = $model->from_array($values);
     // $action_result = $model->save( $related );
     $action_result = $model->save();
     if ($action_result) {
         $msg = HCM::__('Availability updated');
         $this->session->set_flashdata('message', $msg);
         $redirect_to = $this->my_parent();
         $redirect_to .= '/user/' . $model->user_id;
         /* what to refresh on referring page */
         $parent_refresh = $model->present_calendar_refresh();
         $parent_refresh = array_keys($parent_refresh);
         $this->redirect($redirect_to, $parent_refresh);
     } else {
         $form->set_errors($model->errors());
         $this->layout->set_partial('content', $this->render('availability/zoom/index', array('form' => $form, 'object' => $model)));
         $this->layout();
     }
 }
Example #5
0
 function update($id)
 {
     $extensions = HC_App::extensions();
     $args = func_get_args();
     $id = array_shift($args);
     $model = HC_App::model('shift');
     $model->where('id', $id)->get();
     $this->_check_model($model);
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('edit')) {
         return;
     }
     $original_model = clone $model;
     /* supplied as parameters */
     $values = hc_parse_args($args);
     /* if post supplied */
     $form = $this->form_edit;
     $post = $this->input->post();
     if ($post) {
         $form->grab($post);
         $form_values = $form->values();
         $values = array_merge($values, $form_values);
     }
     if (!$values or !array_key_exists("action", $values)) {
         $redirect_to = 'shifts/zoom/index/id/' . $id;
         $this->redirect($redirect_to);
         return;
     }
     /* approve */
     if (!$model->release_request or $values['action']) {
         $current_user = $this->auth->user();
         $model->release_request = 0;
         $model->user_id = 0;
         $action_result = $model->save();
         // $action_result = $model->delete($current_user, 'user');
         $msg = HCM::__('Shift released');
     } else {
         $model->release_request = 0;
         $action_result = $model->save();
         $msg = HCM::__('Shift release rejected');
     }
     if ($action_result) {
         /* extensions */
         $extensions->run('shifts/update', $post, $model);
         /* save and redirect here */
         $this->session->set_flashdata('message', $msg);
         $redirect_to = 'shifts/zoom/index/id/' . $id;
         /* what to refresh on referring page */
         $parent_refresh = $model->present_calendar_refresh();
         $parent_refresh = array_keys($parent_refresh);
         $this->redirect($redirect_to, $parent_refresh);
     } else {
         /* final layout */
         $this->layout->set_partial('content', Modules::run('shifts/zoom/index', $model, 'release'));
         $this->layout();
     }
 }
Example #6
0
 function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['id'])) {
         echo 'PARAMS MISSING IN shifts/zoom/index<br>';
         return;
     }
     /* PARAMS */
     $id = $args['id'];
     $tab = isset($args['tab']) ? $args['tab'] : 'overview';
     $subtab = isset($args['subtab']) ? $args['subtab'] : '';
     if (is_object($id)) {
         $model = $id;
     } else {
         $model = HC_App::model('shift');
         $model->where('id', $id)->get();
         $this->_check_model($model);
     }
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('view')) {
         return;
     }
     /* display form */
     $this->form_edit->set_values($model->to_array());
     $this->form_edit->set_errors($model->errors());
     /* build content */
     $calling_parent = 'shifts/zoom/index/id/' . $id;
     $subheader = NULL;
     $content = '';
     $method = '_content_' . $tab;
     if (method_exists($this, $method)) {
         $content = $this->{$method}($model, $args);
     } else {
         $extensions = HC_App::extensions();
         if ($extensions->has(array('shifts/zoom', $tab))) {
             $calling_parent = 'shifts/zoom/index/id/' . $id . '/tab/' . $tab;
             $content = $extensions->run(array('shifts/zoom', $tab, $calling_parent), $model, $subtab);
             $subheader = $extensions->run(array('shifts/zoom/menubar', $tab), $model);
         }
     }
     /* CONTENT */
     $content = $this->render($this->views_path . '/index', array('subheader' => $subheader, 'content' => $content));
     $this->layout->set_partial('content', $content);
     if (!in_array($tab, array('assign'))) {
         /* HEADER */
         $this->layout->set_partial('header_ajax', $this->render($this->views_path . '/_header', array('object' => $model)));
         /* MENUBAR */
         $this->layout->set_partial('sidebar', $this->render($this->views_path . '/_menubar', array('tab' => $tab, 'object' => $model)));
     }
     $this->layout();
 }
Example #7
0
 function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['id'])) {
         echo 'PARAMS MISSING IN admin/users/zoom/index<br>';
         return;
     }
     /* PARAMS */
     $id = $args['id'];
     $tab = isset($args['tab']) ? $args['tab'] : 'edit';
     $subtab = isset($args['subtab']) ? $args['subtab'] : '';
     if (is_object($id)) {
         $model = $id;
     } else {
         $model = HC_App::model('user');
         $model->where('id', $id)->get();
         $this->_check_model($model);
     }
     /* build content */
     $subheader = NULL;
     $content = '';
     $method = '_content_' . $tab;
     if (method_exists($this, $method)) {
         $content = $this->{$method}($model);
     } else {
         $extensions = HC_App::extensions();
         if ($extensions->has(array('admin/users/zoom', $tab))) {
             $calling_parent = 'admin/users/zoom/index/id/' . $id . '/tab/' . $tab;
             $pass_arg = isset($args['_pass']) ? $args['_pass'] : array();
             array_unshift($pass_arg, array('admin/users/zoom', $tab, $calling_parent));
             $pass_arg[] = 'user';
             $pass_arg[] = $model->id;
             $content = call_user_func_array(array($extensions, 'run'), $pass_arg);
             $subheader = $extensions->run(array('admin/users/zoom/menubar', $tab), $model);
         }
     }
     /* CONTENT */
     $content = $this->render($this->views_path . '/index', array('subheader' => $subheader, 'content' => $content));
     $this->layout->set_partial('content', $content);
     /* HEADER */
     $this->layout->set_partial('header_ajax', $this->render($this->views_path . '/_header', array('object' => $model)));
     /* MENUBAR */
     $this->layout->set_partial('sidebar', $this->render($this->views_path . '/_menubar', array('tab' => $tab, 'object' => $model)));
     $this->layout();
 }
Example #8
0
 public function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['user'])) {
         echo 'PARAMS MISSING IN availability/index<br>';
         return;
     }
     $user_id = is_object($args['user']) ? $args['user']->id : $args['user'];
     $model = HC_App::model('availability');
     $model->include_related('user', array('id', 'email', 'first_name', 'last_name', 'active'), TRUE, TRUE);
     $model->where_related('user', 'id', $user_id);
     $model->get();
     $user = HC_App::model('user')->where('id', $user_id)->get();
     $acl = HC_App::acl();
     $entries = $acl->filter($model, 'view');
     $this->layout->set_partial('content', $this->render('availability/index', array('entries' => $entries, 'user' => $user)));
     $this->layout();
 }
Example #9
0
 public function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['user'])) {
         echo 'PARAMS MISSING IN availability/index<br>';
         return;
     }
     $user_id = is_object($args['user']) ? $args['user']->id : $args['user'];
     $t = HC_Lib::time();
     $t->setNow();
     $date_start = $t->formatDate_Db();
     $t->setEndMonth();
     // $t->modify('+1 month');
     $date_end = $t->formatDate_Db();
     $form_values = array('user' => $user_id, 'date' => array('recurring' => 'single', 'datesingle' => $date_start, 'datestart' => $date_start, 'dateend' => $date_end, 'repeat' => 'daily'));
     $this->form_add->set_values($form_values);
     $this->layout->set_partial('content', $this->render('availability/add', array('form' => $this->form_add)));
     $this->layout();
 }
Example #10
0
 public function index()
 {
     $args = hc_parse_args(func_get_args(), TRUE);
     if (!isset($args['id'])) {
         echo 'PARAMS MISSING IN availability/zoom/index<br>';
         return;
     }
     $id = $args['id'];
     if (is_object($id)) {
         $model = $id;
     } else {
         $model = HC_App::model('availability');
         $model->where('id', $id)->get();
         $this->_check_model($model);
     }
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('view')) {
         return;
     }
     $form_values = $model->to_array();
     $date_input = clone $this->form_edit->input('date');
     $date_value = $date_input->unserialize($model->details, 'no-dates');
     $date_value['datestart'] = $model->date_start;
     $date_value['dateend'] = $model->date_end;
     $form_values['date'] = $date_value;
     $this->form_edit->set_values($form_values);
     /* HEADER */
     /*
     		$this->layout->set_partial(
     			'header_ajax',
     			$this->render(
     				$this->views_path . '/_header',
     				array(
     					'object'	=> $model,
     					)
     				)
     			);
     */
     $this->layout->set_partial('content', $this->render($this->views_path . '/index', array('form' => $this->form_edit, 'object' => $model)));
     $this->layout();
 }
Example #11
0
 function index()
 {
     if (!$this->auth->check()) {
         $this->redirect('auth/login');
     }
     $args = hc_parse_args(func_get_args(), TRUE);
     // if( ! (isset($args['id'])) ){
     // echo 'PARAMS MISSING IN admin/users/zoom/index<br>';
     // return;
     // }
     /* PARAMS */
     $tab = isset($args['tab']) ? $args['tab'] : 'edit';
     $model = isset($args['id']) ? $args['id'] : clone $this->auth->user();
     /* build content */
     $subheader = NULL;
     $content = '';
     $method = '_content_' . $tab;
     if (method_exists($this, $method)) {
         $content = $this->{$method}($model);
     } else {
         $extensions = HC_App::extensions();
         if ($extensions->has(array('auth/profile', $tab))) {
             $calling_parent = 'auth/profile/index/tab/' . $tab;
             $pass_arg = isset($args['_pass']) ? $args['_pass'] : array();
             array_unshift($pass_arg, array('auth/profile', $tab, $calling_parent));
             $pass_arg[] = 'user';
             $pass_arg[] = $model->id;
             $content = call_user_func_array(array($extensions, 'run'), $pass_arg);
             $subheader = $extensions->run(array('auth/profile/menubar', $tab), $model);
         }
     }
     /* CONTENT */
     $content = $this->render($this->views_path . '/index', array('subheader' => $subheader, 'content' => $content));
     $this->layout->set_partial('content', $content);
     /* HEADER */
     $this->layout->set_partial('header_ajax', $this->render($this->views_path . '/_header', array('object' => $model)));
     /* MENUBAR */
     $this->layout->set_partial('sidebar', $this->render($this->views_path . '/_menubar', array('tab' => $tab, 'object' => $model)));
     $this->layout();
 }
Example #12
0
 function index($id)
 {
     $extensions = HC_App::extensions();
     $args = func_get_args();
     $id = array_shift($args);
     $model = HC_App::model('shift');
     $model->where('id', $id)->get();
     $this->_check_model($model);
     $acl = HC_App::acl();
     if (!$acl->set_object($model)->can('edit')) {
         return;
     }
     $original_model = clone $model;
     /* supplied as parameters */
     $values = hc_parse_args($args);
     /* if post supplied */
     $form = $this->form_edit;
     $post = $this->input->post();
     if ($post) {
         $form->grab($post);
         $form_values = $form->values();
         $values = array_merge($values, $form_values);
     }
     $relname = 'user';
     $unassign = FALSE;
     if ($values[$relname] === '0' or $values[$relname] === 0 or $values[$relname] == '' or $values[$relname] === NULL) {
         // delete user relation
         unset($values[$relname]);
         if ($model->user_id) {
             $unassign = TRUE;
         }
     }
     if (!$values) {
         return $this->_zoom($model, 'time');
     }
     if ($values['location'] === NULL) {
         unset($values['location']);
     }
     $related = $model->from_array($values);
     $action_result1 = $model->save($related);
     $action_result2 = TRUE;
     if ($unassign) {
         $rel = $model->{$relname}->get();
         $action_result2 = $model->delete($rel, $relname);
     }
     if ($action_result1 && $action_result2) {
         /* extensions */
         $extensions->run('shifts/update', $post, $model);
         /* save and redirect here */
         if ($id) {
             $msg = sprintf(HCM::_n('%d shift updated', '%d shifts updated', 1), 1);
         } else {
             $msg = sprintf(HCM::_n('%d shift added', '%d shifts added', 1), 1);
         }
         $this->session->set_flashdata('message', $msg);
         $redirect_to = 'shifts/zoom/index/id/' . $id;
         //			$redirect_to = '-referrer-';
         /* what to refresh on referring page */
         $parent_refresh = $model->present_calendar_refresh();
         $parent_refresh = array_keys($parent_refresh);
         $this->redirect($redirect_to, $parent_refresh);
     } else {
         /* final layout */
         $this->layout->set_partial('content', Modules::run('shifts/zoom/index', 'id', $model));
         $this->layout();
     }
 }
Example #13
0
 function add()
 {
     $values = array('time' => array(0, 15 * 60));
     $func_args = func_get_args();
     $values = array_merge($values, hc_parse_args($func_args));
     $errors = array();
     /* display form */
     $this->form->set_values($values);
     $this->form->set_errors($errors);
     $this->layout->set_partial('content', $this->render('admin/shift_templates/add', array('form' => $this->form)));
     $this->layout();
 }
Example #14
0
 function formall()
 {
     $args = hc_parse_args(func_get_args());
     $shifts = isset($args['shifts']) ? $args['shifts'] : array();
     $ids = array_map(create_function('$o', 'return $o->id;'), $shifts);
     /* render view */
     $this->layout->set_partial('content', $this->render('shift_groups/form', array('form' => $this->form, 'act_on_all' => 1, 'ids' => $ids, 'count' => count($ids))));
     $this->layout();
 }
Example #15
0
 private function _grab_state($args, $tab = 'browse')
 {
     $t = HC_Lib::time();
     $state = array('range' => 'week', 'date' => $t->formatDate_Db(), 'by' => NULL, 'location' => array(), 'staff' => array(), 'type' => NULL, 'wide' => NULL, 'filter' => NULL);
     $default_params = $this->default_params;
     $supplied = hc_parse_args($args);
     $supplied = array_merge($default_params, $supplied);
     foreach ($supplied as $k => $v) {
         if (in_array($k, array('staff', 'location', 'type'))) {
             if (strpos($v, '.') !== FALSE) {
                 $v = explode('.', $v);
             } elseif (strpos($v, ',') !== FALSE) {
                 $v = explode(',', $v);
             } else {
                 $v = array($v);
             }
         }
         $state[$k] = $v;
     }
     /* check _current_user_id_ */
     if (isset($state['staff'])) {
         $check_current_user = array('_current_user_id_', '_current_user_id', 'current_user_id', 'current_user', '_current_user_');
         $current_user_key = '';
         foreach ($check_current_user as $cuk) {
             if (in_array($cuk, $state['staff'])) {
                 $current_user_key = $cuk;
                 break;
             }
         }
         if ($current_user_key) {
             $current_user_id = 0;
             if ($test_user = $this->auth->user()) {
                 $current_user_id = $test_user->id;
             }
             $state['staff'] = HC_Lib::replace_in_array($state['staff'], $current_user_key, $current_user_id);
         }
     }
     /* fixed ? */
     $force_fixed = array('location', 'staff');
     foreach ($default_params as $k => $v) {
         if (in_array($k, $force_fixed)) {
             $this->fix[$k] = $state[$k];
         }
     }
     switch ($state['range']) {
         case 'all':
             $t = HC_Lib::time();
             $shifts = HC_App::model('shift');
             $min_date = $shifts->select_min('date')->get()->date;
             $max_date = $shifts->select_max('date_end')->get()->date_end;
             if ($min_date && $max_date) {
                 $state['date'] = $min_date . '_' . $max_date;
             }
             break;
         case 'upcoming':
             $t = HC_Lib::time();
             $shifts = HC_App::model('shift');
             $min_date = $t->setNow()->formatDate_Db();
             $max_date = $shifts->select_max('date_end')->get()->date_end;
             if ($min_date && $max_date) {
                 $state['date'] = $min_date . '_' . $max_date;
             }
             break;
         case 'day':
         case 'week':
         case 'month':
             if (!$state['date']) {
                 $t->setNow();
                 $state['date'] = $t->formatDate_Db();
             }
             break;
         case 'custom':
             if (strpos($state['date'], '_') !== FALSE) {
                 list($start_date, $end_date) = explode('_', $state['date']);
             } else {
                 $start_date = $end_date = $state['date'];
             }
             $t->setNow();
             if (!$start_date) {
                 $start_date = $t->formatDate_Db();
             }
             if (!$end_date) {
                 $end_date = $t->formatDate_Db();
             }
             $state['date'] = join('_', array($start_date, $end_date));
             break;
         default:
             // attempt to parse the range text in time
             $start_date = $state['date'];
             if (!$start_date) {
                 $t->setNow();
                 $start_date = $t->formatDate_Db();
             }
             $t->setDateDb($start_date);
             $t->modify('+' . $state['range']);
             $end_date = $t->formatDate_Db();
             $state['date'] = join('_', array($start_date, $end_date));
             $state['range'] = 'custom';
             break;
     }
     /* if custom dates supplied */
     if (isset($supplied['customdates']) && $supplied['customdates']) {
         $post = $this->input->post();
         if (isset($post['start_date']) && isset($post['end_date'])) {
             if ($post['end_date'] <= $post['start_date']) {
                 $post['end_date'] = $post['start_date'];
             }
             $state['date'] = $post['start_date'] . '_' . $post['end_date'];
             $state['range'] = 'custom';
             unset($state['customdates']);
             $link = HC_Lib::link($this->views_path . '/' . $tab, $state);
             $redirect_to = $link->url();
             $this->redirect($redirect_to);
             return;
         }
     }
     /* something fixed ? */
     foreach ($this->fix as $fk => $fv) {
         if ($fv) {
             unset($state[$fk]);
         }
     }
     return $state;
 }
Example #16
0
 private function _init_add_params($args)
 {
     $params = new HC_Page_Params();
     $args = hc_parse_args($args, TRUE);
     foreach ($args as $k => $v) {
         $params->set($k, $v);
     }
     /* possible options */
     $acl = HC_App::acl();
     $shift = HC_App::model('shift');
     $all = array('type' => array($shift->_const('TYPE_SHIFT'), $shift->_const('TYPE_TIMEOFF')), 'location' => HC_App::model('location')->get(), 'user' => HC_App::model('user')->get_staff(), 'status' => array($shift->_const('STATUS_DRAFT'), $shift->_const('STATUS_ACTIVE')));
     $can = array('type' => array(), 'location' => array(), 'user' => array(), 'status' => array());
     foreach ($all['type'] as $type) {
         foreach ($all['location'] as $location) {
             foreach ($all['user'] as $user) {
                 foreach ($all['status'] as $status) {
                     $shift = HC_App::model('shift');
                     $shift->type = $type;
                     $shift->location_id = $location->id;
                     $shift->user_id = $user->id;
                     $shift->status = $status;
                     if ($acl->set_object($shift)->can('validate')) {
                         $can['type'][$type] = $type;
                         $can['location'][$location->id] = $location;
                         $can['user'][$user->id] = $user;
                         $can['status'][$status] = $status;
                     }
                 }
             }
         }
     }
     if (count($can['type']) == 1) {
         reset($can['type']);
         $params->set('type', key($can['type']));
     }
     if (count($can['location']) == 1) {
         reset($can['location']);
         $params->set('location', key($can['location']));
     }
     $shift = HC_App::model('shift');
     if (count($can['user']) == 1) {
         if ($params->get('type') == $shift->_const('TYPE_TIMEOFF')) {
             reset($can['user']);
             $params->set('user', key($can['user']));
         }
     }
     if (count($can['status']) == 1) {
         reset($can['status']);
         $params->set('status', key($can['status']));
     }
     /* set location for timeoff */
     if ($params->get('type') == $shift->_const('TYPE_TIMEOFF')) {
         $params->set('location', 0);
     }
     /* user params as array */
     if ($params->get('user') !== NULL) {
         $param_users = $params->get('user');
         if (!is_array($param_users)) {
             $param_users = array($param_users);
         }
         $params->set('user', $param_users);
     }
     $params->set_options('type', $can['type']);
     $params->set_options('user', $can['user']);
     $params->set_options('location', $can['location']);
     $params->set_options('status', $can['status']);
     return $params;
 }
 function add()
 {
     $values = array();
     $values = array_merge($values, hc_parse_args(func_get_args()));
     $errors = array();
     /* display form */
     $this->form->set_values($values);
     $this->form->set_errors($errors);
     $this->layout->set_partial('content', $this->render('admin/locations/add', array('form' => $this->form)));
     $this->layout();
 }
Example #18
0
 function status()
 {
     $args = hc_parse_args(func_get_args());
     $count = array();
     $this->data['location_id'] = 0;
     $this->data['staff_id'] = 0;
     if (isset($args['staff']) && $args['staff']) {
         $um = new User_Model();
         $um->get_by_id($args['staff']);
         $sm = $um->shift;
         $this->data['staff_id'] = $args['staff'];
     } elseif (isset($args['location']) && $args['location']) {
         $lm = new Location_Model();
         $lm->get_by_id($args['location']);
         $sm = $lm->shift;
         $this->data['location_id'] = $args['location'];
     } else {
         $sm = new Shift_Model();
     }
     /* duration */
     $sm->clear();
     $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->select_sum('end')->select_sum('start')->get();
     $count['duration'] = $sm->end - $sm->start;
     /* ACTIVE	- published with staff */
     $sm->clear();
     $sm->include_related('user', 'id');
     $count['active'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS NOT ', 'NULL', FALSE)->count();
     /* OPEN		- published with no staff */
     $sm->clear();
     $sm->include_related('user', 'id');
     $count['open'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS ', 'NULL', FALSE)->count();
     /* PENDING	- not published with staff */
     $sm->clear();
     $count['pending'] = $sm->include_related('user', 'id')->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status <>', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS NOT ', 'NULL', FALSE)->count();
     /* DRAFT	- not published with no staff */
     $sm->clear();
     $sm->include_related('user', 'id');
     $count['draft'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status <>', SHIFT_MODEL::STATUS_ACTIVE)->group_start()->or_where('user_id IS ', 'NULL', FALSE)->or_where('user_id', 0)->group_end()->count();
     /* total */
     $sm->clear();
     $count['total'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->count();
     $this->data['count'] = $count;
     $this->data['start_date'] = $args['start'];
     $this->data['end_date'] = $args['end'];
     $this->set_include('status');
     $this->load->view($this->template, $this->data);
 }