function __construct() { parent::__construct(); $this->load->library('migration'); if (!$this->migration->current()) { show_error($this->migration->error_string()); return false; } $this->load->library('app_conf'); $app = $this->config->item('nts_app'); if (!$this->auth->logged_in()) { if (isset($GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID']) && isset($GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_NAME'])) { $id = $GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID']; $email = $GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_NAME']; $this->auth->do_login($id, $email); } else { ci_redirect('auth/login'); } } elseif (!$this->auth->is_admin()) { $this->session->set_flashdata('message', 'You must be an admin to view this page'); ci_redirect('auth/login'); } // validation error $this->form_validation->set_message('is_unique', lang('common_err_already_registered')); // template $this->template = $this->input->is_ajax_request() ? 'admin/template_ajax' : 'admin/template'; }
function index($status = 0) { $model = $this->{$this->model}; if (!$status) { $status = TIMEOFF_MODEL::STATUS_PENDING; } /* all statuses counts */ $statuses = array(); $res = $this->{$this->model}->select('status')->select_func('COUNT', '@id', 'count')->group_by('status')->order_by('status', 'ASC')->get(); foreach ($res as $r) { if ($r->count > 0) { $statuses[$r->status] = $r->count; } } if (isset($statuses[TIMEOFF_MODEL::STATUS_ACTIVE]) && $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] > 0) { $this->hc_time->setNow(); /* if this week then not yet expired */ $this->hc_time->setStartWeek(); $check_with = $this->hc_time->formatDate_Db(); // count archive $archived_count = $this->{$this->model}->where('status', TIMEOFF_MODEL::STATUS_ACTIVE)->where('date_end <', $check_with)->count(); if ($archived_count > 0) { $statuses[TIMEOFF_MODEL::STATUS_ARCHIVE] = $archived_count; $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] = $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] - $archived_count; if ($statuses[TIMEOFF_MODEL::STATUS_ACTIVE] <= 0) { unset($statuses[TIMEOFF_MODEL::STATUS_ACTIVE]); } } } /* no timeoffs so far */ if (!$statuses) { ci_redirect($this->conf['path'] . '/add'); return; } $this->data['statuses'] = $statuses; /* load */ if (!isset($statuses[$status])) { $all_statuses = array_keys($statuses); $status = $all_statuses[0]; } switch ($status) { case TIMEOFF_MODEL::STATUS_ARCHIVE: $this->{$this->model}->where('status', TIMEOFF_MODEL::STATUS_ACTIVE); $this->{$this->model}->where('date <', $check_with); break; case TIMEOFF_MODEL::STATUS_ACTIVE: $this->{$this->model}->where('status', $status); $this->{$this->model}->where('date >=', $check_with); break; default: $this->{$this->model}->where('status', $status); break; } $this->data['entries'] = $this->{$this->model}->get()->all; $this->data['status'] = $status; $this->set_include('index'); $this->data['index_child'] = $this->get_view('index_child'); $this->load->view($this->template, $this->data); }
function force_ssl($change_url = FALSE) { if ($change_url) { $CI =& get_instance(); $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); } if ($_SERVER['SERVER_PORT'] != 80) { ci_redirect($CI->uri->uri_string()); } }
function __construct($user_level = 0, $default_path = '') { parent::__construct(); $this->load->library('migration'); if (!$this->migration->current()) { // show_error($this->migration->error_string()); return false; } $this->load->library('conf/app_conf'); $this->load->library('hc_time'); $this->load->library('hc_form'); $app = $this->config->item('nts_app'); if (isset($GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID'])) { $id = $GLOBALS['NTS_CONFIG'][$app]['FORCE_LOGIN_ID']; $this->auth->login($id); } if (!$this->auth->check()) { ci_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'; ci_redirect($to); exit; } /* check user level */ if ($user_level) { $this->check_level($user_level); if ($default_path) { $this->conf['path'] = $default_path; } } /* check license code */ if ($this->hc_modules->exists('license')) { $license_model = new Hitcode_license_model(); $code = $license_model->get(); if (!$code) { $to = 'license/admin'; $current_slug = $this->get_current_slug(); if ($current_slug != $to) { $this->session->set_flashdata('error', lang('license_code_required')); ci_redirect($to); exit; } } } }
function __construct() { parent::__construct(); if ($this->input->server('SERVER_NAME') == 'localhost') { // $this->output->enable_profiler(TRUE); } $detect = new lprMobileDetect(); $this->is_mobile = $detect->isMobile(); $this->load->database(); $this->load->helper(array('url')); $skip_setup = array('setup', 'demo'); if (!in_array($this->router->fetch_class(), $skip_setup) and !$this->is_setup()) { ci_redirect('setup'); } $this->load->helper(array('language', 'form')); $this->load->helper(array('hitcode')); $this->load->library(array('form_validation', 'session')); $this->form_validation->set_error_delimiters('<div class="hc-form-error">', '</div>'); // table $this->load->library('table'); $table_tmpl = array('table_open' => '<table class="table table-striped">'); $this->table->set_template($table_tmpl); // pagination $this->load->library('pagination'); // conf $this->load->library('simple_auth', NULL, 'auth'); $app_core = $this->config->item('nts_app_core') ? $this->config->item('nts_app_core') : $this->config->item('nts_app'); $this->load->library('app_conf'); $my_language = $this->app_conf->get('language'); if (!file_exists(APPPATH . '/language/' . $my_language)) { $my_language = 'english'; } $this->lang->load($app_core, $my_language); $this->data = array(); $this->data['page_title'] = $this->config->item('nts_app_title'); $this->data['message'] = $this->session->flashdata('message'); $this->data['error'] = $this->session->flashdata('error'); if (isset($GLOBALS['NTS_IS_PLUGIN']) && $GLOBALS['NTS_IS_PLUGIN'] == 'wordpress') { wp_localize_script('lctrScript1', 'url_prefix', ci_site_url('front/get')); wp_localize_script('lctrScript_front', 'lpr_vars', array('conf_trigger_autodetect' => $this->app_conf->get('trigger_autodetect') ? $this->app_conf->get('trigger_autodetect') : 0, 'conf_append_search' => $this->app_conf->get('append_search'), 'start_listing' => $this->app_conf->get('start_listing') ? 1 : 0, 'map_scrollwheel' => $this->app_conf->get('map_no_scrollwheel') ? FALSE : TRUE, 'show_print_link' => $this->app_conf->get('show_print_link'), 'show_matched_locations' => $this->app_conf->get('show_matched_locations'))); } }
function index() { ci_redirect(''); return; $target1 = ci_site_url('load'); $html = <<<EOT <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> <script type="text/javascript" src="{$target1}"></script> </body> </html> EOT; echo $html; }
function index($what = 'settings') { if ($what == 'resetproducts') { return $this->resetproducts(); } if ($this->form_validation->run('conf-' . $what) == false) { // display the form $this->data['include'] = 'admin/conf/' . $what; $this->load->view($this->template, $this->data); } else { // update reset($this->params[$what]); foreach ($this->params[$what] as $p) { $v = $this->input->post($p); $this->app_conf->set($p, $v); } // redirect back $msg = lang('common_update') . ': ' . lang('common_ok'); $this->session->set_flashdata('message', $msg); ci_redirect('admin/conf/' . $what); } }
function index() { $this->form_validation->set_rules('submit', 'submit', 'required'); $fields = $this->config->items('settings'); $ri = $this->remote_integration(); if ($ri) { unset($fields['login_with']); } reset($fields); foreach ($fields as $fn => $f) { if (isset($f['rules'])) { $this->form_validation->set_rules($fn, $f['label'], $f['rules']); } } $this->data['fields'] = $fields; if ($this->form_validation->run() == false) { $post = $this->input->post(); if ($post) { $this->hc_form->set_defaults($post); } $this->hc_form->set_errors($this->form_validation->error_array()); // display the form $this->set_include('index'); $this->load->view($this->template, $this->data); } else { // update reset($fields); foreach ($fields as $fn => $f) { $v = $this->input->post($fn); $this->app_conf->set($fn, $v); } // redirect back $msg = lang('common_update') . ': ' . lang('common_ok'); $this->session->set_flashdata('message', $msg); $to = 'conf/admin'; ci_redirect($to); } }
function __construct() { parent::__construct(); $app = $this->config->item('nts_app'); if (!$this->auth->check()) { 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_Model'; $um = new $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 (isset($GLOBALS['NTS_CONFIG'][$app]['FORCE_USER_LEVEL'])) { $user_level = $GLOBALS['NTS_CONFIG'][$app]['FORCE_USER_LEVEL']; } $remote_integration = $this->remote_integration(); if ($remote_integration) { $wall_schedule_display = 0; } else { $wall_schedule_display = $this->app_conf->get('wall_schedule_display'); } $allowed = FALSE; switch ($user_level) { case 0: if ($wall_schedule_display <= $user_level) { $to = 'wall'; } else { if ($user_id) { $to = 'auth/notallowed'; } else { $to = 'auth/login'; } } break; case USER_MODEL::LEVEL_ADMIN: $to = 'admin/schedules'; break; case USER_MODEL::LEVEL_MANAGER: $to = 'admin/schedules'; break; case USER_MODEL::LEVEL_STAFF: $to = 'staff/shifts'; break; } ci_redirect($to); exit; }
function ci_secure_redirect($uri = '', $method = 'location', $http_response_code = 302) { ci_redirect($uri, $method, $http_response_code, TRUE); }
function savepassword($id) { if (!$this->{$this->model}->id) { $this->{$this->model}->get_by_id($id); } if (!$this->{$this->model}->exists()) { $this->session->set_flashdata('message', sprintf(lang('common_not_found'), get_class($this->{$this->model}), $id)); ci_redirect($this->conf['path']); return; } $post = array(); foreach (array('password', 'confirm_password') as $fname) { $supplied = $this->input->post($fname); if ($supplied !== FALSE) { $post[$fname] = $supplied; $this->{$this->model}->{$fname} = $supplied; } } if ($this->{$this->model}->save()) { // redirect to list $msg = lang('common_change_password'); $this->session->set_flashdata('message', $msg . ': ' . lang('common_ok')); $redirect_to = array($this->conf['path']); ci_redirect($redirect_to); return; } else { $this->hc_form->set_errors($this->{$this->model}->error->all); $this->hc_form->set_defaults($post); return $this->password($id); } }
function redirect($to) { if ($this->input->is_ajax_request()) { // if( $this->input->post() ) // { // clear flash $this->session->set_flashdata('message', NULL); $this->session->set_flashdata('error', NULL); // } $to = ci_site_url($to); $out = array('redirect' => $to); $this->output->set_content_type('application/json'); $this->output->enable_profiler(FALSE); echo json_encode($out); hc_ci_before_exit(); exit; // return; } else { ci_redirect($to); return; } return; }
protected function _load($id) { // $related_fields = array_merge( $this->{$this->model}->has_one, $this->{$this->model}->has_many ); $related_fields = array_merge($this->{$this->model}->has_one); if (!$this->{$this->model}->id) { reset($related_fields); foreach ($related_fields as $fname => $rel_props) { $this->{$this->model}->include_related($fname, 'id'); } $this->{$this->model}->get_by_id($id); } if (!$this->{$this->model}->exists()) { $this->session->set_flashdata('message', sprintf(lang('common_not_found'), get_class($this->{$this->model}), $id)); ci_redirect($this->conf['path']); return FALSE; } if ($this->{$this->model}->id) { if (!$this->_permission()) { $this->session->set_flashdata('message', 'You are not allowed to access this page'); ci_redirect($this->conf['path']); return FALSE; } } return TRUE; }
function run($predefined_admin = NULL) { $validation = array(array('field' => 'email', 'label' => 'lang:email', 'rules' => 'trim|required|valid_email'), array('field' => 'password', 'label' => 'lang:password', 'rules' => 'trim|required|matches[password2]'), array('field' => 'password2', 'label' => 'lang:password2', 'rules' => 'trim|required')); $this->form_validation->set_rules($validation); if (!$predefined_admin && $this->form_validation->run() == FALSE) { $this->data['include'] = 'setup'; $this->load->view('template', $this->data); } else { if (!$predefined_admin) { $admin_email = $this->input->post('email'); $admin_password = $this->input->post('password'); } else { $admin_email = $predefined_admin; $admin_password = mt_rand(1000000, 9999999); } $tables = array(); $sth = $this->db->query("SHOW TABLES LIKE '" . NTS_DB_TABLES_PREFIX . "%'"); foreach ($sth->result_array() as $r) { reset($r); foreach ($r as $k => $v) { $tables[] = $v; } } reset($tables); foreach ($tables as $t) { $this->db->query("DROP TABLE " . $t . ""); } $this->load->library('migration'); if (!$this->migration->current()) { show_error($this->migration->error_string()); return false; } $this->load->library('app_conf'); // create admin $this->app_conf->set('admin_email', $admin_email); $hash_password = $this->auth->hash_password($admin_password); $this->app_conf->set('admin_password', $hash_password); $setup_ok = TRUE; if ($setup_ok) { /* default settings */ $this->app_conf->set('email_from', $admin_email); $this->app_conf->set('email_from_name', $admin_email); $this->session->set_flashdata('message', lang('ok')); ci_redirect('setup/ok'); return; } ci_redirect(''); } }
function run() { $app = $this->config->item('nts_app'); $validation = array(array('field' => 'first_name', 'label' => 'lang:user_first_name', 'rules' => 'trim|required'), array('field' => 'last_name', 'label' => 'lang:user_last_name', 'rules' => 'trim|required'), array('field' => 'email', 'label' => 'lang:common_email', 'rules' => 'trim|required|valid_email'), array('field' => 'password', 'label' => 'lang:common_password', 'rules' => 'trim|required|matches[confirm_password]'), array('field' => 'confirm_password', 'label' => 'lang:common_password_confirm', 'rules' => 'trim|required')); $fields = array('first_name', 'last_name', 'email', 'password', 'confirm_password'); $this->form_validation->set_rules($validation); if ($this->input->post()) { $post = array(); reset($fields); foreach ($fields as $f) { $post[$f] = $this->input->post($f); } $this->hc_form->set_defaults($post); if ($this->form_validation->run() == FALSE) { $errors = array(); reset($fields); foreach ($fields as $f) { $errors[$f] = form_error($f); } $this->hc_form->set_errors($errors); } else { /* run setup */ /* reset tables */ $this->_drop_tables(); /* setup tables */ $this->load->library('migration'); if (!$this->migration->current()) { show_error($this->migration->error_string()); return false; } $this->load->library('conf/app_conf'); $setup_ok = TRUE; /* admin user */ $this->load->model('User_model'); $this->User_model->from_array($post); $this->User_model->level = USER_MODEL::LEVEL_ADMIN; if ($this->User_model->save()) { $email_from = $post['email']; $email_from_name = $post['first_name'] . ' ' . $post['last_name']; } else { $this->hc_form->set_errors($this->User_model->error->all); $this->hc_form->set_defaults($post); $setup_ok = FALSE; } if ($setup_ok) { /* default settings */ $this->app_conf->set('email_from', $email_from); $this->app_conf->set('email_from_name', $email_from_name); $this->session->set_flashdata('message', lang('ok')); ci_redirect('setup/ok'); return; } } } $this->data['include'] = 'setup'; $this->load->view('_layout/index_no_menu', $this->data); return; }
function forgot_password() { $this->form_validation->set_rules('email', 'Email Address', 'required'); if ($this->form_validation->run() == false) { //setup the input $this->data['email'] = array('name' => 'email', 'id' => 'email'); //set any errors and display the form $this->data['auth_message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); $this->data['include'] = 'auth/forgot_password'; $this->load->view($this->template, $this->data); } else { $supplied_email = $this->input->post('email'); //run the forgotten password method to email new one to the user $forgotten = $this->auth->forgotten_password($supplied_email); if ($forgotten) { //if there were no errors $this->session->set_flashdata('message', lang('auth_forgot_password_successful')); ci_redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page } else { $this->session->set_flashdata('message', $this->auth->error); ci_redirect("auth/forgot_password", 'refresh'); } } }
function edit($id) { $object = $this->model->get($id); if (!$object) { $this->session->set_flashdata('message', sprintf(lang('not_found'), $id)); ci_redirect($this->conf['path']); exit; } if ($this->form_validation->run($this->conf['validation']) == false) { // display the form $this->data['object'] = $object; $this->data['include'] = $this->conf['path'] . '/edit'; } else { // update $adata = array(); reset($this->fields); foreach ($this->fields as $f) { $adata[$f['name']] = $this->input->post($f['name']); } $object = array_merge($object, $adata); $this->model->save($object); // redirect to list $this->session->set_flashdata('message', lang('common_update') . ': ' . lang('common_ok')); ci_redirect(array($this->conf['path'], 'edit', $id)); exit; } $this->load->view($this->template, $this->data); }