public function index() { /* if post supplied */ $post = $this->input->post(); $values = array(); if ($post) { $this->form_add->grab($post); $form_values = $this->form_add->values(); $values = array_merge($values, $form_values); } $date_value = $this->form_add->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'] = $this->form_add->input('date')->value(FALSE, TRUE); } unset($values['date']); $model = HC_App::model('availability'); $related = $model->from_array($values); $action_result = $model->save($related); if ($action_result) { $msg = HCM::__('Availability added'); $this->session->set_flashdata('message', $msg); $redirect_to = $this->my_parent(); $this->redirect($redirect_to); } else { $this->form_add->set_errors($model->errors()); $this->layout->set_partial('content', $this->render('availability/add', array('form' => $this->form_add))); $this->layout(); } }
function index($object, $object_id = NULL) { if (is_object($object)) { $object_class = $object->my_class(); $object_id = $object->id; } else { $object_class = $object; $object = HC_App::model($object_class)->where('id', $object_id)->get(); } /* load */ $model = HC_App::model('logaudit'); $acl = HC_App::acl(); if (!$acl->set_object($object)->can('history::view')) { return; } $entries = $model->changes_by_time($object); $objects = array(); foreach ($entries as $action_time => $obj_changes) { foreach (array_keys($obj_changes) as $object_full_id) { if (array_key_exists($object_full_id, $objects)) { continue; } list($obj_class, $obj_id) = explode('.', $object_full_id); $child_object = HC_App::model($obj_class)->get_by_id($obj_id); if (!$acl->set_object($child_object)->can('view')) { unset($entries[$action_time][$object_full_id]); continue; } $objects[$object_full_id] = $child_object; } } /* render view */ $this->layout->set_partial('content', $this->render('logaudit/index', array('object' => $object, 'objects' => $objects, 'entries' => $entries))); $this->layout(); }
public function can($what, $params = array()) { $return = FALSE; $object = $this->object(); $user = $this->user(); if (!$user) { $user = HC_App::model('user'); } $check = array(); if ($object) { $check[] = $object->my_class() . '::' . $object->id . '::' . $what; $check[] = $object->my_class() . '::' . '*' . '::' . $what; $check[] = $object->my_class() . '::' . $what; $check[] = $object->my_class() . '::' . '*'; } $check[] = $what; $check[] = '*'; reset($check); foreach ($check as $ch) { if (isset($this->rules[$ch])) { $rule = $this->rules[$ch]; if (is_callable($rule)) { $return = $rule($user, $object, $params); } else { $return = $rule; } if ($return !== NULL) { break; } } } return $return; }
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(); } }
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); }
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(); } }
public function index() { $app = $this->config->item('nts_app'); $app_conf = HC_App::app_conf(); if (isset($GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID'])) { $id = $GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID']; $this->auth->login($id); } // sync user account $ri = $this->remote_integration(); if ($ri) { $id = $this->auth->check(); if ($id) { $model_name = $ri . '_User'; $um = HC_App::model($model_name); $um->sync($id); $this->auth->reset_user(); } } // check user level $user_level = 0; $user_id = 0; if ($this->auth->check()) { if ($test_user = $this->auth->user()) { $user_id = $test_user->id; $user_level = $test_user->level; } } if ($ri) { $wall_schedule_display = 0; } else { $wall_schedule_display = $app_conf->get('wall:schedule_display'); } $default_params = $this->default_params; $allowed = FALSE; switch ($user_level) { case 0: if ($wall_schedule_display <= $user_level) { $to = 'list'; } else { if ($user_id) { $to = 'auth/notallowed'; } else { $to = 'auth/login'; } } break; case USER_HC_MODEL::LEVEL_ADMIN: case USER_HC_MODEL::LEVEL_MANAGER: $to = isset($default_params['route']) ? $default_params['route'] : 'list'; break; case USER_HC_MODEL::LEVEL_STAFF: $to = isset($default_params['route']) ? $default_params['route'] : 'listme'; break; } $this->redirect($to); exit; }
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(); } }
function get($model) { /* if the shift within the preferred availability */ $myclass = get_class(); $return = array(); if ($model->type == $model->_const('TYPE_TIMEOFF')) { return $return; } if (!(strlen($model->start) && strlen($model->end))) { return $return; } if (!($model->date && $model->date_end)) { return $return; } if (!$model->user_id) { return $return; } $am = HC_App::model('availability'); $am->where_related('user', 'id', $model->user_id)->where('type', $am->_const('TYPE_PREFERRED'))->where('date_end >=', $model->date)->where('date_start <=', $model->date_end); $am->get_iterated_slim(); $found_availability = FALSE; foreach ($am as $availability) { /* get dates of this availability */ $this_dates = $availability->get_dates(); foreach ($this_dates as $this_date) { $test = HC_App::model('shift'); $test->date = $this_date; $test->start = $availability->start; $test->end = $availability->end; $test->validate(); if ($test->date_end < $model->date) { continue; } if ($test->date > $model->date_end) { break; } if ($test->covers($model)) { $found_availability = TRUE; break; } } if ($found_availability) { break; } } if (!$found_availability) { $conflict = new $myclass(); $conflict_id = array($model->id); sort($conflict_id); $conflict_id = $this->type . '_' . join('_', $conflict_id); $conflict->id = $conflict_id; $conflict->shift_id = $model->id; // $conflict->details = $availability->id; $return[] = $conflict; } return $return; }
function api_insert($post) { $notifications_email_skip = isset($post['notifications_email_skip']) ? $post['notifications_email_skip'] : FALSE; if ($notifications_email_skip) { $messages = HC_App::model('messages'); $messages->remove_engine('email'); } $return = TRUE; return $return; }
function render() { $model = HC_App::model('location'); $model->get(); $options = array(); foreach ($model as $obj) { $options[$obj->id] = $obj->present_title(); } $this->set_options($options); return parent::render(); }
function __construct() { parent::__construct(); $this->rootlink = 'list_toff'; $temp_shift = HC_App::model('shift'); // $this->fix['staff'] = array( $this->auth->user()->id ); // $this->fix['location'] = array( 0 ); // $this->fix['filter'] = NULL; $this->fix['type'] = array($temp_shift->_const('TYPE_TIMEOFF')); $this->fix['tab'] = 'browse'; $this->default_params['range'] = 'upcoming'; }
public function run($msgs) { reset($msgs); foreach ($msgs as $uid => $user_msgs) { $user = HC_App::model('user')->where('id', $uid)->get(); /* group messages */ reset($user_msgs); foreach ($user_msgs as $key => $payloads) { $this->send($key, $user, $payloads); } } }
function todo() { $shifts = HC_App::model('shift')->where('release_request', 1); $shifts->get(); $count = $shifts->result_count(); if (!$count) { return; } /* render view */ $this->layout->set_partial('content', $this->render('release/todo', array('count' => $count))); $this->layout(); }
function api_insert($post) { $extensions = HC_App::extensions(); $notifications_email_skip = isset($post['notifications_email_skip']) ? $post['notifications_email_skip'] : FALSE; if ($notifications_email_skip) { $messages = HC_App::model('messages'); $messages->remove_engine('email'); } /* extensions */ $extensions->run('notifications_email/insert', $post); $return = TRUE; return $return; }
function save($prefix, $watch, $post) { $model = HC_App::model('user_preferences'); foreach ($watch as $k) { $key = strlen($prefix) ? $prefix . '/' . $k : $k; $value = NULL; if (array_key_exists($k, $post)) { $value = $post[$k]; } $model->set($key, $value); } $return = TRUE; return $return; }
function details($model, $vlevel = HC_PRESENTER::VIEW_HTML) { $conflicting_one = HC_App::model('availability'); $conflicting_one->where('id', $model->details)->get(); switch ($vlevel) { case HC_PRESENTER::VIEW_HTML: $return = HC_Html_Factory::widget('availability_view')->set_new_window(TRUE)->set_wide(TRUE); $return->set_model($conflicting_one); break; case HC_PRESENTER::VIEW_TEXT: case HC_PRESENTER::VIEW_RAW: $return = $conflicting_one->present_details($vlevel); break; } return $return; }
function delete($id) { $model = HC_App::model('user'); $model->where('id', $id)->get(); $this->_check_model($model); if ($model->delete()) { $msg = 'User deleted'; $this->session->set_flashdata('message', $msg); } else { $errors = $model->errors(); $msg = HCM::__('Error') . ': ' . join(' ', $errors); $this->session->set_flashdata('error', $msg); } $redirect_to = 'admin/users'; $this->redirect($redirect_to); return; }
function __construct($user_level = 0) { parent::__construct(); $this->load->library('migration'); if (!$this->migration->current()) { // show_error($this->migration->error_string()); return false; } $nts_config = HC_Lib::nts_config(); if (isset($nts_config['FORCE_LOGIN_ID'])) { $id = $nts_config['FORCE_LOGIN_ID']; $this->auth->login($id); } if (!$this->auth->check()) { $this->redirect('auth/login'); exit; } /* check user active */ $user_active = 0; if ($test_user = $this->auth->user()) { $user_active = $test_user->active; } if (!$user_active) { $to = 'auth/notallowed'; $this->redirect($to); exit; } /* check user level */ if ($user_level) { $this->check_level($user_level); } /* check license code */ if ($this->hc_modules->exists('license')) { $license_model = HC_App::model('hitcode_license'); $code = $license_model->get(); if (!$code) { $to = 'license/admin'; $current_slug = $this->get_current_slug(); if ($current_slug != $to) { $this->session->set_flashdata('error', 'license_code_required'); $this->redirect($to); exit; } } } }
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(); }
function index($user_id = 0) { $model = HC_App::model('loginlog'); $model->include_related('user', array('id', 'email', 'first_name', 'last_name', 'active'), TRUE, TRUE); if ($user_id) { if (is_object($user_id)) { $user_id = $user_id->id; } $model->where_related('user', 'id', $user_id); $user = HC_App::model('user'); $user->where('id', $user_id)->get(); } $model->get(); /* render view */ $this->layout->set_partial('header', $this->render('loginlog/_header', array())); $this->layout->set_partial('content', $this->render('loginlog/index', array('user_id' => $user_id, 'entries' => $model))); $this->layout(); }
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(); }
function get($model) { $limit_qty = 2; $limit_duration = 4 * 60 * 60; $this->shift_id = $model->id; $return = array(); /* find if the employee has more shifts that allowed per week */ if (!(strlen($model->start) && strlen($model->end))) { return $return; } if (!($model->date && $model->date_end)) { return $return; } if (!$model->user_id) { return $return; } if ($model->type != $model->_const('TYPE_SHIFT')) { return $return; } $t = HC_Lib::time(); $t->setDateDb($model->date); list($start_week, $end_week) = $t->getDates('week', TRUE); $my_qty = 0; $my_duration = 0; $sm = HC_App::model('shift'); $sm->select('id, date, date_end, start, end')->where_related('user', 'id', $model->user_id)->where('date_end >=', $start_week)->where('date <=', $end_week); $sm->get_iterated_slim(); foreach ($sm as $test) { $my_qty += 1; $my_duration += $test->get_duration(); } if ($my_qty > $limit_qty) { $conflict = clone $this; $conflict->details = 'qty:' . $my_qty; $return[] = $conflict; } if ($my_duration > $limit_duration) { $conflict = clone $this; $conflict->details = 'duration:' . $my_duration; $return[] = $conflict; } return $return; }
function open() { $t = HC_Lib::time(); $today = $t->setNow()->formatDate_Db(); $shifts = HC_App::model('shift'); $shifts->where('date_end >=', $today)->where('status', $shifts->_const('STATUS_ACTIVE'))->where_related('user', 'id', NULL, TRUE); $shifts->get(); $acl = HC_App::acl(); $count = 0; foreach ($shifts as $obj) { if (!$acl->set_object($obj)->can('view')) { continue; } $count++; } /* view */ $this->layout->set_partial('content', $this->render('admin/todo/open', array('count' => $count))); $this->layout(); }
function quickstats($objects, $wrap = NULL) { $cmm = HC_App::model('conflict_manager'); $acl = HC_App::acl(); $count = 0; foreach ($objects as $obj) { if (!$this->_check_securuty($obj)) { continue; } if ($obj->release_request) { $count++; } } /* render view */ if ($count) { $this->layout->set_partial('content', $this->render('release/quickstats', array('count' => $count, 'wrap' => $wrap))); $this->layout(); } }
function deleterel($id, $relname, $relid) { $model = HC_App::model('shift'); $model->get_by_id($id); $this->_check_model($model); $acl = HC_App::acl(); if (!$acl->set_object($model)->can($relname . '::delete')) { return; } $rel = $model->{$relname}->get_by_id($relid); if ($model->delete($rel, $relname)) { $this->session->set_flashdata('message', sprintf(HCM::_n('%d shift updated', '%d shifts updated', 1), 1)); } else { $this->session->set_flashdata('error', HCM::__('Error')); } $redirect_to = 'shifts/zoom/' . $id; // $redirect_to = '-referrer-'; $this->redirect($redirect_to); return; }
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(); }
function insert() { $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('release')) { return; } $current_user = $this->auth->user(); $app_conf = HC_App::app_conf(); $approval_required = $app_conf->get("release:approval_required"); if ($approval_required) { $model->release_request = 1; $action_result = $model->save(); } else { $action_result = $model->delete($current_user, 'user'); } if ($action_result) { /* extensions */ // $extensions->run('shifts/update', $post, $model); if ($approval_required) { $msg = HCM::__('Shift release request received'); } else { $msg = HCM::__('Shift released'); } /* save and redirect here */ $this->session->set_flashdata('message', $msg); } else { /* save and redirect here */ $this->session->set_flashdata('error', HCM::__('Error')); } $redirect_to = 'shifts/zoom/index/id/' . $id . '/tab/release'; /* what to refresh on referring page */ $parent_refresh = $model->present_calendar_refresh(); $parent_refresh = array_keys($parent_refresh); $this->redirect($redirect_to, $parent_refresh); }
function insert() { $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('pickup')) { return; } $current_user = $this->auth->user(); $related = array('user' => $current_user); $model->user = $current_user; $app_conf = HC_App::app_conf(); $approval_required = $app_conf->get('pickup:approval_required'); if ($approval_required) { $model->status = $model->_const('STATUS_DRAFT'); } $action_result = $model->save($related); if ($action_result) { if ($approval_required) { $msg = HCM::__('Shift pickup request received'); } else { $msg = HCM::__('Shift picked up'); } /* save and redirect here */ $this->session->set_flashdata('message', $msg); } else { /* save and redirect here */ $this->session->set_flashdata('error', HCM::__('Error')); } $redirect_to = 'shifts/zoom/index/' . $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); }
function filter_post($shifts) { $return = array(); $cmm = HC_App::model('conflict_manager'); $acl = HC_App::acl(); $show_this = FALSE; $count_ok = 0; $count_fail = 0; foreach ($shifts as $obj) { if ($obj->start === NULL) { continue; } if (!$acl->set_object($obj)->can('conflicts::view')) { continue; } $entries = $cmm->get($obj, TRUE); if ($entries) { $return[] = $obj; } } return $return; }