Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 function user_zoom_menubar($object)
 {
     $acl = HC_App::acl();
     if (!$acl->set_object($object)->can('loginlog::view')) {
         return;
     }
     return $this->render('loginlog/user_zoom_menubar', array('object' => $object));
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 5
0
 function filter_post($shifts)
 {
     $return = array();
     $acl = HC_App::acl();
     foreach ($shifts as $sh) {
         if (!$acl->set_object($sh)->can('pickup')) {
             continue;
         }
         $return[] = $sh;
     }
     return $return;
 }
 function add_form_inputs($parent_object = NULL)
 {
     $acl = HC_App::acl();
     if ($parent_object) {
         if (!$acl->set_object($parent_object)->can('notification_email::skip')) {
             return;
         }
     }
     $form = HC_Lib::form();
     $form->set_inputs(array('notifications_email_skip' => 'checkbox'));
     return $this->render('notifications_email/add_form_inputs', array('form' => $form));
 }
Ejemplo n.º 7
0
 function index($object)
 {
     if (!$this->_check_securuty($object)) {
         return;
     }
     $acl = HC_App::acl();
     if ($acl->set_object($object)->can('edit')) {
         $this->layout->set_partial('content', $this->render('release/index_edit', array('form' => $this->form_edit, 'object' => $object)));
     } else {
         $this->layout->set_partial('content', $this->render('release/index_view', array('object' => $object)));
     }
     $this->layout();
 }
Ejemplo n.º 8
0
 function __construct()
 {
     parent::__construct();
     // if we need to simulate user - in WP shortcut page */
     $app = HC_App::app();
     if (isset($GLOBALS['NTS_CONFIG'][$app]['SIMULATE_USER_ID'])) {
         $acl = HC_App::acl();
         $simulate_id = $GLOBALS['NTS_CONFIG'][$app]['SIMULATE_USER_ID'];
         $auth_user = $this->auth->user();
         $acl_user = $this->auth->user($simulate_id);
         if ($auth_user->level >= $auth_user->_const('LEVEL_MANAGER')) {
             $acl->set_user($acl_user);
         }
     }
 }
Ejemplo n.º 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'];
     $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();
 }
Ejemplo n.º 10
0
 protected function _check_securuty($object)
 {
     $return = FALSE;
     if ($object->status != $object->_const('STATUS_ACTIVE')) {
         return $return;
     }
     if ($object->type != $object->_const('TYPE_SHIFT')) {
         return $return;
     }
     if ($object->user_id) {
         return $return;
     }
     $acl = HC_App::acl();
     if (!$acl->set_object($object)->can('pickup')) {
         return $return;
     }
     $return = TRUE;
     return $return;
 }
Ejemplo n.º 11
0
 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();
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
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();
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
 function add_form_inputs($parent_object = NULL)
 {
     $acl = HC_App::acl();
     if ($parent_object) {
         if (!$acl->set_object($parent_object)->can('notification_email::skip')) {
             return;
         }
     }
     $form = HC_Lib::form();
     $form->set_inputs(array('notifications_email_skip' => 'checkbox'));
     $default_values = array('notifications_email_skip' => 0);
     /* extensions */
     $extensions = HC_App::extensions();
     $change_values = $extensions->run('notifications_email/insert/defaults');
     foreach ($change_values as $change_array) {
         foreach ($change_array as $k => $v) {
             $default_values[$k] = $v;
         }
     }
     $form->set_values($default_values);
     return $this->render('notifications_email/add_form_inputs', array('form' => $form));
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 private function _content_overview($model, $args = array())
 {
     $acl = HC_App::acl();
     if ($acl->set_object($model)->can('edit')) {
         /* check if we have anything changed */
         $changed = array();
         foreach ($args as $k => $v) {
             switch ($k) {
                 case 'c_location':
                     $changed['location'] = $v;
                     break;
                 case 'c_user':
                     $changed['user'] = $v;
                     break;
             }
         }
         $form_values = $model->to_array();
         $form_values['location'] = $model->location_id;
         $form_values['user'] = $model->user_id;
         if ($changed) {
             foreach ($changed as $k => $v) {
                 $form_values[$k] = $v;
             }
             $model->from_array($form_values);
         }
         $form_values = $model->to_array();
         $form_values['location'] = $model->location_id;
         $form_values['user'] = $model->user_id;
         $this->form_edit->set_values($form_values);
         $this->form_edit->set_errors($model->errors());
         return $this->render($this->views_path . '/overview_edit', array('form' => $this->form_edit, 'object' => $model));
     } else {
         return $this->render($this->views_path . '/overview_view', array('object' => $model));
     }
 }
Ejemplo n.º 19
0
 function layout($template_file = NULL)
 {
     $template_dir = '_layout_new';
     $ri = HC_Lib::ri();
     $is_module = $this->is_module();
     $is_ajax = $this->input->is_ajax_request();
     if ($is_module or $is_ajax) {
         $template_file = 'index_module';
     } else {
         if (!$template_file) {
             $template_file = 'index';
         }
         /* theme */
         $theme_dir = $GLOBALS['NTS_APPPATH'] . '/../theme';
         if (file_exists($theme_dir)) {
             $theme_head = $theme_dir . '/head.php';
             if (file_exists($theme_head)) {
                 $this->layout->set_partial('theme_head', $this->render('../../theme/head', array()));
             }
             $theme_header = $theme_dir . '/header.php';
             if (file_exists($theme_header)) {
                 $this->layout->set_partial('theme_header', $this->render('../../theme/header', array()));
             }
             $theme_footer = $theme_dir . '/footer.php';
             if (file_exists($theme_footer)) {
                 $this->layout->set_partial('theme_footer', $this->render('../../theme/footer', array()));
             }
         }
         $this->layout->set_param('ri', $ri);
         /* head */
         // if( ! $ri ){
         $page_title = $this->config->item('nts_app_title');
         $this->layout->set_partial('head', $this->render($template_dir . '/head', array('layout' => $this->layout, 'page_title' => $page_title)));
         // }
         /* menu & profile */
         $user = NULL;
         if ($this->auth && $this->auth->check() && $this->auth->user() && $this->auth->user()->active) {
             $user = $this->auth->user();
         }
         $user = $this->auth->user();
         /* menu */
         if ((1 or $user) && !$this->is_setup) {
             $menu_conf = $this->config->item('menu');
             $disabled_panels = $this->config->item('disabled_panels');
             $this_uri = $this->uri->uri_string();
             $user_level = $user ? $user->level : 0;
             $acl = HC_App::acl();
             $auth_user = $acl->user();
             $this->layout->set_partial('menu', $this->render($template_dir . '/menu', array('menu_conf' => $menu_conf, 'disabled_panels' => $disabled_panels, 'this_uri' => $this_uri, 'user' => $auth_user)));
         }
         /* profile */
         $app_conf = HC_App::app_conf();
         if ((1 or !$ri) && !$this->is_setup) {
             $this_method = $this->router->fetch_method();
             $login_with = $app_conf->get('login_with');
             $this->layout->set_partial('profile', $this->render($template_dir . '/profile', array('this_method' => $this_method, 'login_with' => $login_with, 'user' => $user)));
         }
         /* brand */
         $brand_title = $this->config->item('nts_app_title');
         $brand_url = $this->config->item('nts_app_url');
         $hc_app_version = $this->config->item('hc_app_version');
         if (!$ri && strlen($brand_title)) {
             $this->layout->set_partial('brand', $this->render($template_dir . '/brand', array('brand_title' => $brand_title, 'brand_url' => $brand_url, 'ri' => $ri, 'app_version' => $hc_app_version)));
         }
         /* js footer code */
         $this->layout->set_partial('js_footer', $this->render($template_dir . '/js_footer', array()));
     }
     /* flashdata */
     if (!$is_module) {
         $this->layout->set_partial('flashdata', $this->render($template_dir . '/flashdata', array('message' => $this->session->flashdata('message_ajax') ? $this->session->flashdata('message_ajax') : $this->session->flashdata('message'), 'debug_message' => $this->session->flashdata('debug_message'), 'error' => $this->session->flashdata('error_ajax') ? $this->session->flashdata('error_ajax') : $this->session->flashdata('error'))));
         $this->layout->set_partial('flashdata_ajax', $this->render($template_dir . '/flashdata', array('message' => $this->session->flashdata('message_ajax'), 'debug_message' => NULL, 'error' => $this->session->flashdata('error_ajax'))));
     }
     /* final output */
     $this->layout->set_template($template_dir . '/' . $template_file);
     /* return */
     $this->load->view($this->layout->template(), array('layout' => $this->layout));
     /*
     		return $this->render(
     			$this->layout->template(),
     			array(
     				'layout'	=> $this->layout
     				)
     			);
     */
 }
Ejemplo n.º 20
0
 function quickstats($objects, $wrap = NULL)
 {
     $cmm = HC_App::model('conflict_manager');
     $acl = HC_App::acl();
     $show_this = FALSE;
     $count_ok = 0;
     $count_fail = 0;
     $conflict_ids = array();
     foreach ($objects as $obj) {
         if ($obj->start === NULL) {
             continue;
         }
         if (!$acl->set_object($obj)->can('conflicts::view')) {
             continue;
         }
         $entries = $cmm->get($obj, TRUE);
         if ($entries) {
             foreach ($entries as $e) {
                 $conflict_ids[$e->id] = 1;
             }
             $count_fail++;
         } else {
             $count_ok++;
         }
     }
     /* render view */
     if (count($conflict_ids)) {
         $this->layout->set_partial('content', $this->render('conflicts/quickstats', array('count_fail' => count($conflict_ids), 'count_ok' => $count_ok, 'wrap' => $wrap)));
         $this->layout();
     }
 }
Ejemplo n.º 21
0
 private function _init_shifts($state)
 {
     $t = HC_Lib::time();
     $shifts = HC_App::model('shift');
     switch ($state['range']) {
         case 'custom':
             if (strpos($state['date'], '_') !== FALSE) {
                 list($start_date, $end_date) = explode('_', $state['date']);
             } else {
                 $start_date = $end_date = $state['date'];
             }
             break;
         case 'day':
             $start_date = $state['date'];
             $end_date = 0;
             break;
         case 'all':
             $start_date = $end_date = 0;
             break;
         case 'upcoming':
             $t->setNow();
             $start_date = $t->formatDate_Db();
             $end_date = NULL;
             break;
         default:
             $t->setDateDb($state['date']);
             list($start_date, $end_date) = $t->getDates($state['range'], TRUE);
             break;
     }
     if ($start_date && $end_date) {
         // $shifts->where('date_end >=', $start_date);
         // $shifts->where('date <=', $end_date);
         $shifts->where('date_end >=', $start_date);
         $shifts->where('date <=', $end_date);
         $shifts->where('date >=', $start_date);
     } elseif ($start_date && $end_date === 0) {
         $shifts->where('date =', $start_date);
     } elseif ($start_date && $end_date === NULL) {
         $shifts->where('date_end >=', $start_date);
     }
     /* location */
     $where_location = array();
     if ($this->fix['location']) {
         if (is_array($this->fix['location']) && count($this->fix['location']) == 1 && $this->fix['location'][0] == 0) {
             /* all locations */
         } else {
             $where_location = $this->fix['location'];
         }
     }
     if (isset($state['location'])) {
         if (!is_array($state['location'])) {
             $state['location'] = array($state['location']);
         }
         $where_location = $state['location'];
     }
     if ($where_location) {
         $shifts->group_start();
         $shifts->or_where('type', $shifts->_const('TYPE_TIMEOFF'));
         $shifts->or_where_in_related('location', 'id', $where_location);
         $shifts->group_end();
     }
     /* staff */
     $where_staff = array();
     if ($this->fix['staff']) {
         $where_staff = $this->fix['staff'];
     }
     if (isset($state['staff'])) {
         if (!is_array($state['staff'])) {
             $state['staff'] = array($state['staff']);
         }
         $where_staff = $state['staff'];
     }
     if (count($where_staff)) {
         if (in_array(0, $where_staff)) {
             $shifts->group_start();
             $shifts->or_where_related('user', 'id', NULL, TRUE);
             $shifts->or_where_related('user', 'id', 0);
             $shifts->or_where_in_related('user', 'id', $where_staff);
             $shifts->group_end();
         } else {
             $shifts->where_related('user', 'id', $where_staff);
         }
     }
     /* type */
     if (isset($this->fix['type'])) {
         $state['type'] = $this->fix['type'];
     }
     if (isset($state['by']) && $state['by'] == 'location') {
         $shifts->where('type', $shifts->_const('TYPE_SHIFT'));
     }
     if (isset($state['type']) && $state['type'] !== NULL) {
         $this_types = array();
         $this_statuses = array();
         foreach ($state['type'] as $stype) {
             if (strpos($stype, '_') === FALSE) {
                 $this_type = $stype;
                 $this_types[$this_type] = 1;
             } else {
                 list($this_type, $this_status) = explode('_', $stype);
                 $this_types[$this_type] = 1;
                 $this_statuses[$this_status] = 1;
             }
         }
         if ($this_types) {
             $shifts->where_in('type', array_keys($this_types));
         }
         if ($this_statuses) {
             $shifts->where_in('status', array_keys($this_statuses));
         }
     }
     /* status */
     if (isset($state['status'])) {
         $shifts->where('status', $state['status']);
     }
     /* extensions */
     $extensions = HC_App::extensions();
     $current_filter = '';
     if (isset($this->fix['filter'])) {
         $current_filter = $this->fix['filter'];
     } elseif (isset($state['filter'])) {
         $current_filter = $state['filter'];
     }
     /* preprocess */
     if ($current_filter) {
         if ($extensions->has(array('list/filter', $current_filter))) {
             $shifts = $extensions->run(array('list/filter', $current_filter), 'pre', $shifts);
         }
     }
     /* NOW GET */
     $shifts->get();
     // $shifts->get_iterated();
     // $shifts->check_last_query();
     $acl = HC_App::acl();
     $return = $acl->filter($shifts, 'view');
     /* extensions with postprocess */
     if ($current_filter) {
         if ($extensions->has(array('list/filter', $current_filter))) {
             $return = $extensions->run(array('list/filter', $current_filter), 'post', $return);
         }
     }
     return $return;
     // return $shifts;
 }
Ejemplo n.º 22
0
 function add_form_inputs($parent_object = NULL)
 {
     $acl = HC_App::acl();
     if ($parent_object) {
         if (!$acl->set_object($parent_object)->can('notes::add')) {
             return;
         }
     }
     $form = HC_Lib::form();
     $form->set_inputs(array('notes' => 'textarea', 'access_level' => 'select'));
     $note = HC_App::model('note');
     $default_access_level = $note->_const('LEVEL_OWNER');
     $default_values = array('access_level' => $default_access_level);
     /* extensions */
     $extensions = HC_App::extensions();
     $change_values = $extensions->run('notes/insert/defaults');
     foreach ($change_values as $change_array) {
         foreach ($change_array as $k => $v) {
             $default_values[$k] = $v;
         }
     }
     $form->set_values($default_values);
     return $this->render('notes/add_form_inputs', array('access_levels' => $this->access_levels, 'form' => $form));
 }
Ejemplo n.º 23
0
<?php

$t = HC_Lib::time();
$acl = HC_App::acl();
$current_user_id = $acl->user() ? $acl->user()->id : 0;
$test_shift = HC_App::model('shift');
$is_print = isset($state['print']) && $state['print'] ? 1 : 0;
$can_add = TRUE;
if ($is_print or !$current_user_id) {
    $can_add = FALSE;
}
if ($can_add) {
    if (!$acl->set_object($test_shift->set('type', $test_shift->_const('TYPE_SHIFT')))->can('add')) {
        $can_add = FALSE;
    }
}
$t->setDateDb($state['date']);
$t->setStartMonth();
$month_matrix = $t->getMonthMatrix();
$t->setDateDb($state['date']);
$dates = $t->getDates($state['range']);
$DATE_LABELS = array();
reset($dates);
foreach ($dates as $date) {
    $t->setDateDb($date);
    $date_label = HC_Html_Factory::element('h4')->add_attr('class', 'text-center')->add_child(HC_Html_Factory::widget('list')->add_attr('class', 'squeeze-in')->add_attr('class', 'list-unstyled')->add_item($t->formatWeekdayShort())->add_item(HC_Html_Factory::element('small')->add_child($t->formatDate())));
    $DATE_LABELS[$date] = $date_label;
}
/* compile the cells content */
$CELLS = array();
$LINKS = array();
Ejemplo n.º 24
0
 function bulk()
 {
     $acl = HC_App::acl();
     $extensions = HC_App::extensions();
     /* if post supplied */
     $post = $this->input->post();
     if (isset($post['id'])) {
         $ids = $post['id'];
     } elseif (isset($post['ids'])) {
         $ids = explode('|', $post['ids']);
     } else {
         $ids = array();
     }
     // $action = isset($post['action']) ? $post['action'] : '';
     // if( $ids && $action ){
     if ($ids) {
         $model = HC_App::model('shift');
         $model->where_in('id', $ids)->get();
         $success_count = 0;
         $action = 'update';
         /* delete */
         if (isset($post['delete'])) {
             $action = 'delete';
             foreach ($model as $o) {
                 if (!$acl->set_object($o)->can('delete')) {
                     continue;
                 }
                 if ($o->delete()) {
                     $success_count++;
                 }
             }
         } else {
             $this->form->grab($post);
             $form_values = $this->form->values();
             foreach ($model as $o) {
                 if (!$acl->set_object($o)->can('edit')) {
                     continue;
                 }
                 reset($form_values);
                 foreach ($form_values as $k => $v) {
                     if ($v === NULL) {
                         continue;
                     }
                     $o->{$k} = $v;
                 }
                 if ($o->save()) {
                     $success_count++;
                 } else {
                     $errors = $o->errors();
                 }
             }
         }
         switch ($action) {
             case 'delete':
                 $msg = sprintf(HCM::_n('%d shift deleted', '%d shifts deleted', $success_count), $success_count);
                 break;
             default:
                 $msg = sprintf(HCM::_n('%d shift updated', '%d shifts updated', $success_count), $success_count);
                 break;
         }
         if ($msg) {
             $this->session->set_flashdata('message', $msg);
         }
         foreach ($model as $o) {
             $extensions->run('shifts/update', $post, $o);
         }
     }
     $redirect_to = '-referrer-';
     $parent_refresh = array();
     foreach ($model as $o) {
         $this_parent_refresh = $o->present_calendar_refresh();
         $parent_refresh = array_merge($parent_refresh, $this_parent_refresh);
     }
     $parent_refresh = array_keys($parent_refresh);
     $this->redirect($redirect_to, $parent_refresh);
 }
Ejemplo n.º 25
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();
     }
 }
Ejemplo n.º 26
0
 private function _add_more_user($layout, $params)
 {
     $model = HC_App::model('shift');
     $shift_array = $params->to_array();
     $already_users = isset($shift_array['user']) ? $shift_array['user'] : array();
     $date_input = $this->form_add_time->input('date');
     $date_input->set_value($shift_array['date']);
     $dates = $date_input->dates();
     unset($shift_array['user']);
     unset($shift_array['date']);
     $shift_array['location_id'] = $shift_array['location'];
     unset($shift_array['location']);
     $model->from_array($shift_array);
     /* choose only those that I can add shifts for */
     $acl = HC_App::acl();
     $all_staff = HC_App::model('user')->where_not_in('id', $already_users)->get_staff();
     $free_staff = array();
     foreach ($all_staff as $this_staff) {
         $shift = HC_App::model('shift');
         $shift->user_id = $this_staff->id;
         if ($acl->set_object($shift)->can('add')) {
             $free_staff[] = $this_staff;
         }
     }
     if (0 && !$free_staff) {
         $link = HC_Lib::link('shifts/add/index');
         $params_array = $params->to_array();
         $redirect_to = $link->url($params_array);
         $this->redirect($redirect_to);
         return;
     }
     /* models */
     $models = array();
     foreach ($dates as $date) {
         $model = HC_App::model('shift');
         $shift_array['date'] = $date;
         $model->from_array($shift_array);
         $models[] = $model;
     }
     $layout->set_partial('content', $this->render('shifts/add/user', array('free_staff' => $free_staff, 'models' => $models, 'params' => $params, 'dates' => $dates, 'form' => $this->form_add_user, 'form_open' => $this->form_add_open_shift)));
     return $layout;
 }