public function qcreate($input)
 {
     $this->db->insert("questions", $input);
     $primary_key = $this->db->insert_id();
     if (gtzero_integer($primary_key)) {
         return to_int($primary_key);
     }
     return 0;
 }
Example #2
0
 public function show($pkey = '')
 {
     _has_user_access_permission(TRUE, array('admin', 'location_manager', 'location_user'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $note_id = isset($params[SYS_NOTE_ID]) && gtzero_integer($params[SYS_NOTE_ID]) ? (int) $params[SYS_NOTE_ID] : 0;
     $note_type_id = isset($params[SYS_NOTE_TYPE_ID]) && gtzero_integer($params[SYS_NOTE_TYPE_ID]) ? (int) $params[SYS_NOTE_TYPE_ID] : 0;
     $note_info = $this->notes_m->get_note_by_id($note_id);
     echo $note_info->note;
 }
 protected function _post_args($key, $type = ARGS_TYPE_STRING, $default = '', $params = array())
 {
     $value = '';
     $post_default = '';
     $key_exist = array_key_exists($key, $_POST);
     $override = array_key_exists('override', $params) ? $params['override'] : FALSE;
     $entities_to_ascii = array_key_exists('entities_to_ascii', $params) ? $params['entities_to_ascii'] : FALSE;
     $gtzero = array_key_exists('gtzero', $params) ? $params['gtzero'] : TRUE;
     switch ($type) {
         case ARGS_TYPE_STRING:
             $post_default = $override ? $default : '';
             $value = $key_exist ? $this->input->post($key, TRUE) ? $this->input->post($key, TRUE) : $post_default : $default;
             if ($entities_to_ascii) {
                 $value = entities_to_ascii($value);
             }
             break;
         case ARGS_TYPE_INT:
             $default = validate_integer($default) ? to_int($default) : 0;
             $post_default = $override ? $default : 0;
             $value = $key_exist ? ($value = $this->input->post($key)) && gtzero_integer($value) ? to_int($value) : $post_default : $default;
             break;
         case ARGS_TYPE_TRUE_FALSE:
             $default = validate_integer($default) ? gtzero_integer($default) ? TRUE : FALSE : FALSE;
             $post_default = $override ? $default : FALSE;
             $value = $key_exist ? ($value = $this->input->post($key)) && ($gtzero && gtzero_integer($value) || !$gtzero && validate_integer($value)) ? TRUE : $post_default : $default;
             break;
         case ARGS_TYPE_ARRAY:
             $value = $key_exist ? ($value = $this->input->post($key)) && is_array($value) ? $value : array() : (is_array($default) ? $default : array());
             break;
         case ARGS_TYPE_DECIMAL:
             $default = gtzero_decimal($default) ? to_float($default) : 0;
             $post_default = $override ? $default : 0;
             $value = $key_exist ? ($value = $this->input->post($key)) && gtzero_decimal($value) ? to_float($value) : $post_default : $default;
             break;
         case ARGS_TYPE_DATE:
             $default = validate_date($default) ? $default : '';
             $post_default = $override ? $default : '';
             $value = $key_exist ? ($value = $this->input->post($key)) && validate_date($value) ? $value : $post_default : $default;
             break;
         case ARGS_TYPE_DATETIME:
             $default = validate_datetime($default) ? $default : '';
             $post_default = $override ? $default : '';
             $value = $key_exist ? ($value = $this->input->post($key)) && validate_date($value) ? $value : $post_default : $default;
             break;
         default:
             $post_default = $override ? $default : '';
             $value = $key_exist ? $this->input->post($key, TRUE) ? $this->input->post($key, TRUE) : $post_default : $default;
             break;
     }
     unset($post_default);
     return $value;
 }
Example #4
0
 public function delete($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin', 'location_manager', 'user_company'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $type_id = isset($params[SYS_CONTACT_TYPE_ID]) && gtzero_integer($params[SYS_CONTACT_TYPE_ID]) ? to_int($params[SYS_CONTACT_TYPE_ID]) : 0;
     $ref_id = isset($params[SYS_REF_ID]) && gtzero_integer($params[SYS_REF_ID]) ? to_int($params[SYS_REF_ID]) : 0;
     $contact_id = isset($params[SYS_CONTACT_ID]) && gtzero_integer($params[SYS_CONTACT_ID]) ? to_int($params[SYS_CONTACT_ID]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $contact_info = $this->contact_m->details($contact_id, $ref_id, $type_id);
     if (!$contact_info) {
         $this->show_permission_denied_error($method);
     }
     $this->form_validation->set_rules('confirm', 'confirm', 'trim|required');
     $output = array('message' => "", 'status' => "");
     if ($this->form_validation->run() == TRUE) {
         $is_record_updated = $this->contact_m->delete($contact_id);
         if ($is_record_updated) {
             $output['message'] = sprintf('The contact "%s" has been deleted.', $contact_info->contact_name);
             $output['status'] = SUCCESS_MESSAGE;
             $output['contact_id'] = $contact_id;
         } else {
             $output['message'] = sprintf('Error occurred while trying to delete contact "%s".', $contact_info->contact_name);
             $output['status'] = ERROR_MESSAGE;
         }
         $this->_output_request($output, $redirect_url);
     } else {
         if (validation_errors()) {
             $output['message'] = validation_errors();
             $output['status'] = ERROR_MESSAGE;
         }
     }
     $doc_key = $this->_post_args('doc_key', ARGS_TYPE_STRING) ? $this->_post_args('doc_key', ARGS_TYPE_STRING) : keygen();
     $csrf = _get_csrf_nonce();
     $data = array('form_action' => site_url('contacts/delete/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'contacts/delete', 'title' => 'Contact "' . $contact_info->contact_name . '"', "display_message" => sprintf('Are you sure you want to delete contact "%s"?', $contact_info->contact_name), "display_heading" => sprintf('Delete contact', $contact_info->contact_name), "submit_btn_text" => "Save Changes", 'hiddenvars' => array_merge($csrf, array('redirect_url' => $redirect_url)), 'doc_key' => $doc_key);
     if ($this->input->is_ajax_request()) {
         $html = $this->template->raw_view('pages/contacts/delete_modal', $data, TRUE);
         if ($method == "ajax") {
             $output['html'] = $html;
             $this->_output_request($output, $redirect_url);
         } else {
             echo $html;
         }
     } else {
         if (!empty($output['status'])) {
             set_flash_data($output['status'], $output['message'], FALSE);
         }
         $this->template->load('default', $data);
     }
 }
Example #5
0
 public function download($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_STAFF, GROUP_ENGINEER)) ? $this->_post_args('company_id', ARGS_TYPE_INT, array_key_exists(SYS_COMPANY_ID, $params) && gtzero_integer($params[SYS_COMPANY_ID]) ? to_int($params[SYS_COMPANY_ID]) : 0) : $this->current_user->company_id;
     $site_id = isset($params[SYS_SITE_ID]) && gtzero_integer($params[SYS_SITE_ID]) ? to_int($params[SYS_SITE_ID]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $site_statuses = array('' => '', 1 => 'OPEN', 2 => 'SUBMITTED', 3 => 'COMPLETED');
     $site_info = $this->site_m->details($site_id, $company_id);
     if (!$site_info || _has_company_group_access($this->current_user->group_id) && $site_info->company_id != $this->current_user->company_id) {
         $this->show_permission_denied_error($method);
     }
     $company_id = in_array($this->current_user->group_id, array(GROUP_ADMIN, GROUP_STAFF, GROUP_ENGINEER)) ? $this->_post_args('company_id', ARGS_TYPE_INT, $site_info->company_id) : $this->current_user->company_id;
     $doc_key = $this->_post_args('doc_key', ARGS_TYPE_STRING) ? $this->_post_args('doc_key', ARGS_TYPE_STRING) : keygen();
     $csrf = _get_csrf_nonce();
     $headings = array("SITE", "FORM", "DATE ADDED", "ADDED BY", "STATUS", "DATE SUBMITTED", "SUBMITTED BY", "DATE COMPLETED", "COMPLETED BY");
     $this->load->library('PHPExcel');
     $this->load->library('PHPExcel/IOFactory');
     // Create a new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getActiveSheet()->setTitle('List of Site Forms');
     $rowNumber = 1;
     $col = 'A';
     foreach ($headings as $heading) {
         $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading);
         $col++;
     }
     // Loop through the result set
     $rowNumber = 2;
     foreach ($site_info->site_forms as $site_form) {
         $col = 'A';
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_info->site_code);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->form_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->added_on, 'Y-m-d H:i:s') ? local_time($site_form->added_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->added_by_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_statuses[$site_form->status]);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->submitted_on, 'Y-m-d H:i:s') ? local_time($site_form->submitted_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->submitted_by_name);
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, _validate_date($site_form->completed_on, 'Y-m-d H:i:s') ? local_time($site_form->completed_on, 'M d, Y @ h:ia') : '');
         $objPHPExcel->getActiveSheet()->setCellValue($col++ . $rowNumber, $site_form->completed_by_name);
         $rowNumber++;
     }
     $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
     // We'll be outputting an excel file
     header('Content-type: application/vnd.ms-excel');
     // It will be called file.xls
     header('Content-Disposition: attachment; filename="' . date('Ymd') . '.xls"');
     // Write file to the browser
     $objWriter->save('php://output');
 }
Example #6
0
 public function deactivate($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin', 'management_company'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = $this->current_user->group_id == GROUP_ADMIN ? 0 : $this->current_user->company_id;
     $user_id = isset($params[SYS_USER_ID]) && gtzero_integer($params[SYS_USER_ID]) ? to_int($params[SYS_USER_ID]) : 0;
     $code = isset($params['code']) && !empty($params['code']) ? $params['code'] : FALSE;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $user_info = $this->user_m->details($user_id);
     if (!$user_info || _has_company_group_access($this->current_user->group_id) && $user_info->company_id != $this->current_user->company_id || $this->current_user->user_id == $user_id) {
         $this->show_permission_denied_error($method);
     }
     $company_id = $user_info->company_id;
     $this->form_validation->set_rules('confirm', 'confirm', 'trim|required');
     $output = array('message' => "", 'status' => "");
     if ($this->form_validation->run() == TRUE) {
         /*if ($this->_valid_csrf_nonce() === FALSE || $user_id != $this->input->post('id'))
         		{
         			show_error('This form post did not pass our security checks.');
         		}*/
         $is_record_updated = $this->ion_auth->deactivate($user_id);
         if ($is_record_updated) {
             $output['message'] = sprintf('The user "%s" has been deactivated.', $user_info->full_name);
             $output['status'] = SUCCESS_MESSAGE;
             $output['user_id'] = $user_id;
             /*trigger_trip("user_activated", $user_info->company_id, array('user_id' => $user_id, 'updated_by' => $this->current_user->user_id));*/
         } else {
             $output['message'] = sprintf('Error occurred while trying to deactivated user "%s".', $user_info->full_name);
             $output['status'] = ERROR_MESSAGE;
         }
         $this->_output_request($output, $redirect_url);
     } else {
         if (validation_errors()) {
             $output['message'] = validation_errors();
             $output['status'] = ERROR_MESSAGE;
         }
     }
     $csrf = _get_csrf_nonce();
     $data = array('form_action' => site_url('users/deactivate/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'user/confirm', 'title' => 'Deactivate User', 'display_message' => sprintf('Are you sure you want to deactivate user "%s"?', $user_info->full_name), 'display_heading' => sprintf('Deactivate User', $user_info->full_name), 'submit_btn_text' => "Save Changes", 'hiddenvars' => array_merge($csrf, array('redirect_url' => $redirect_url)));
     if ($this->input->is_ajax_request()) {
         $html = $this->template->raw_view('pages/user/confirm_modal', $data, TRUE);
         if ($method == "ajax") {
             $output['html'] = $html;
             $this->_output_request($output, $redirect_url);
         } else {
             echo $html;
         }
     } else {
         if (!empty($output['status'])) {
             set_flash_data($output['status'], $output['message'], FALSE);
         }
         $this->template->load('default', $data);
     }
 }
 public function add_client_note($client_id, $note_id)
 {
     if (!gtzero_integer($client_id) || !gtzero_integer($note_id)) {
         return 0;
     }
     $input = array('client_id' => $client_id, 'note_id' => $note_id);
     return $this->db->insert('client_notes', $input);
 }
Example #8
0
 public function synctimezone()
 {
     $front_gmt_offset = $this->input->post("front_gmt_offset");
     $recheck = ($recheck = $this->input->post("recheck")) && gtzero_integer($recheck) ? TRUE : FALSE;
     $user_info = $this->user_m->get_user_info($this->current_user->user_id);
     $gmt_options = $this->session->userdata('gmt_options');
     if (!empty($gmt_options)) {
         $this->session->unset_userdata('gmt_options');
     }
     $gmt_options = array('recheck' => $recheck);
     $this->session->set_userdata('gmt_options', serialize_object($gmt_options));
     header('Content-Type: application/json');
     echo json_encode(array('gmt_options' => $gmt_options));
     die;
 }
 public function add_product($input)
 {
     $input['created_on'] = curr_timestamp();
     $this->db->insert("products", $input);
     $primary_key = $this->db->insert_id();
     if (gtzero_integer($primary_key)) {
         return to_int($primary_key);
     }
     return 0;
 }
Example #10
0
 public function qdelete($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $form_type_id = isset($params[SYS_FORM_TYPE_ID]) && gtzero_integer($params[SYS_FORM_TYPE_ID]) ? to_int($params[SYS_FORM_TYPE_ID]) : 0;
     $question_id = isset($params[SYS_QUESTION_ID]) && gtzero_integer($params[SYS_QUESTION_ID]) ? to_int($params[SYS_QUESTION_ID]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $form_info = $this->survey_m->form_type_details($form_type_id);
     $question_info = $this->survey_m->get_question_detail($question_id, $form_type_id);
     if (!$form_info) {
         $this->show_permission_denied_error($method);
     }
     $this->form_validation->set_rules('confirm', 'confirm', 'trim|required');
     $output = array('message' => "", 'status' => "");
     if ($this->form_validation->run() == TRUE) {
         $is_record_updated = $this->survey_m->delete_question($question_id);
         if ($is_record_updated) {
             $output['message'] = sprintf('The question "%s" has been deleted.', $question_info->description);
             $output['status'] = SUCCESS_MESSAGE;
             $output['question_id'] = $question_id;
         } else {
             $output['message'] = sprintf('Unable to delete question "%s". Please report the issue to %s', $question_info->description, $this->cfg->contact_email);
             $output['status'] = ERROR_MESSAGE;
         }
         $this->_output_request($output, $redirect_url);
     } else {
         if (validation_errors()) {
             $output['message'] = validation_errors();
             $output['status'] = ERROR_MESSAGE;
         }
     }
     $csrf = _get_csrf_nonce();
     $data = array('form_action' => site_url('survey/qdelete/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'survey/delete', 'title' => 'Delete Question', "display_message" => sprintf('Are you sure you want to delete question "%s"?', $question_info->description), "display_heading" => sprintf('Delete Question', $question_info->description), "submit_btn_text" => "Save Changes", 'hiddenvars' => array_merge($csrf, array('redirect_url' => $redirect_url, 'confirm' => 1)));
     if ($this->input->is_ajax_request()) {
         $html = $this->template->raw_view('pages/survey/delete_modal', $data, TRUE);
         if ($method == "ajax") {
             $output['html'] = $html;
             $this->_output_request($output, $redirect_url);
         } else {
             echo $html;
         }
     } else {
         if (!empty($output['status'])) {
             set_flash_data($output['status'], $output['message'], FALSE);
         }
         $this->template->load('default', $data);
     }
 }
 public function update_site_contact($site_id, $contact_id, $is_default)
 {
     if (!gtzero_integer($site_id) || !gtzero_integer($contact_id)) {
         return 0;
     }
     $this->db->from('site_contacts')->where("site_id", to_int($site_id))->where("contact_id", to_int($contact_id));
     $is_record_exist = $this->db->count_all_results() > 0;
     if (!$is_record_exist) {
         $input = array('site_id' => $site_id, 'contact_id' => $contact_id, 'is_default' => $is_default);
         $this->db->insert('site_contacts', $input);
     } else {
         $this->db->where('contact_id', to_int($contact_id));
         $this->db->where("site_id", to_int($site_id));
         $this->db->update('site_contacts', array('is_default' => $is_default));
     }
     if (gtzero_integer($is_default)) {
         $this->db->where('contact_id !=', to_int($contact_id));
         $this->db->where("site_id", to_int($site_id));
         $return = $this->db->update('site_contacts', array('is_default' => 0));
     }
 }
 /**
  * Callback method for updating company record
  *
  * @param array 
  * @param int    $id    The company id
  *
  * @return true/false
  * CALLED FROM
  * 	- profile/set_timezone
  */
 public function delete_company_settings($company_id)
 {
     if (gtzero_integer($company_id)) {
         $this->db->where('company_id', $company_id);
         $this->db->delete('company_settings');
         return TRUE;
     }
     return FALSE;
 }
Example #13
0
 public function show_files($pkey = '')
 {
     $document_type_id = 9;
     $ref_id = 0;
     $doc_ref = FALSE;
     $params = ($params = wdp_arr_decode($pkey)) && is_array($params) ? $params : array();
     if ($params) {
         $ref_id = array_key_exists(WDP_REF_ID, $params) && gtzero_integer($params[WDP_REF_ID]) ? to_int($params[WDP_REF_ID]) : 0;
         $document_type_id = array_key_exists(WDP_TYPE_ID, $params) && gtzero_integer($params[WDP_TYPE_ID]) ? to_int($params[WDP_TYPE_ID]) : 0;
     } else {
         $doc_secret_key = wdp_arr_decode($this->input->post('doc_secret_key'));
         if ($doc_secret_key) {
             $ref_id = isset($doc_secret_key[WDP_REF_ID]) ? $doc_secret_key[WDP_REF_ID] : FALSE;
             $doc_ref = isset($doc_secret_key[WDP_DOC_REF]) ? $doc_secret_key[WDP_DOC_REF] : FALSE;
             $document_type_id = isset($doc_secret_key[WDP_TYPE_ID]) ? $doc_secret_key[WDP_TYPE_ID] : 0;
         } else {
             $ref_id = $this->input->post('ref_id');
             $doc_ref = $this->input->post('doc_ref');
             $document_type_id = $this->input->post('document_type_id') ? $this->input->post('document_type_id') : 0;
         }
     }
     $files = $this->document_model->get_files(array('ref_id' => $ref_id, 'doc_ref' => $doc_ref, 'document_type_id' => $document_type_id));
     $this->template->raw_view('pages/docs/files', array('files' => $files, 'ref_id' => $ref_id));
 }
Example #14
0
 public function index($pkey = '', $method = 'echo')
 {
     ensure_user_access(TRUE, array('admin', 'management_company'));
     $params = ($params = wdp_arr_decode($pkey)) && is_array($params) ? $params : array();
     $company_id = $this->current_user->group_id == 1 ? 0 : $this->current_user->company_id;
     $grid_column_type_id = isset($params[GRID_CTYPE]) && gtzero_integer($params[GRID_CTYPE]) ? to_int($params[GRID_CTYPE]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $params = array('user_id' => $this->current_user->user_id, 'grid_column_type_id' => $grid_column_type_id);
     if (_check_company_user_access()) {
         $params['company_id'] = $company_id;
     }
     $grid_columns = $this->setting_m->grid_columns_by_many($params);
     if (!$grid_columns) {
         $this->show_permission_denied_error($method);
     }
     $this->form_validation->set_rules('grid_column_rows', '', '');
     $output = array('message' => "", 'status' => "");
     if ($this->form_validation->run() == TRUE) {
         $grid_column_rows = $this->_post_args('grid_column_rows', ARGS_TYPE_ARRAY);
         if ($this->current_user->group_id == 2) {
             $this->setting_m->delete_company_grid_columns($company_id, $grid_column_type_id);
             foreach ($grid_column_rows as $grid_column_id => $is_visible) {
                 $this->setting_m->add_company_grid_columns(array('company_id' => $company_id, 'grid_column_id' => $grid_column_id, 'grid_column_type_id' => $grid_column_type_id, 'visible' => to_int($is_visible)));
             }
             $this->setting_m->user_grid_columns_by_many($company_id, array('company_id' => $company_id, 'grid_column_type_id' => $grid_column_type_id), TRUE);
         } else {
             $this->setting_m->delete_user_grid_columns($this->current_user->user_id, $grid_column_type_id);
             foreach ($grid_column_rows as $grid_column_id => $is_visible) {
                 $this->setting_m->add_user_grid_columns(array('user_id' => $this->current_user->user_id, 'grid_column_id' => $grid_column_id, 'grid_column_type_id' => $grid_column_type_id, 'visible' => to_int($is_visible)));
             }
             $this->setting_m->user_grid_columns_by_many($company_id, array('user_id' => $this->current_user->user_id, 'grid_column_type_id' => $grid_column_type_id), TRUE);
         }
         $gparams = array('grid_column_type_id' => $grid_column_type_id, 'user_id' => $this->current_user->user_id);
         if (_check_company_user_access()) {
             $gparams['company_id'] = $this->current_user->company_id;
         }
         $grid_columns = $this->setting_m->user_grid_columns_by_many($this->current_user->company_id, $gparams);
         $output['message'] = 'Setting Saved';
         $output['status'] = SUCCESS_MESSAGE;
         $output['grid_columns'] = $grid_columns;
         //$output['redirect'] 	= $redirect_url;
         $this->_output_request($output, $redirect_url);
     } else {
         if (validation_errors()) {
             $output['message'] = validation_errors();
             $output['status'] = ERROR_MESSAGE;
         }
     }
     $details = $this->company_m->company_settings($company_id);
     $data = array('form_action' => site_url('settings/gcolumns/index/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'settings/my_grid_permission', 'title' => 'Grid Setting', 'submit_btn_text' => 'Save Changes', 'company_id' => $company_id, 'grid_columns' => $grid_columns->columns, 'js_files' => array('settings/gcolumns.js'), 'hiddenvars' => array('redirect_url' => $redirect_url));
     if ($this->input->is_ajax_request()) {
         $html = $this->template->raw_view('pages/settings/my_grid_permission_modal', $data, TRUE);
         if ($method == "ajax") {
             $output['html'] = $html;
             $this->_output_request($output, $redirect_url);
         } else {
             echo $html;
         }
     } else {
         $this->template->load('default', $data);
     }
 }
Example #15
0
 public function ajax_gets_count($params)
 {
     $uc = "(SELECT user_id, company_id FROM user_company UNION SELECT clu.user_id, cu.company_id FROM user_clients clu INNER JOIN clients cu ON clu.client_id = cu.id) uc";
     $this->db->from('users u')->join('users_groups ug', 'u.id = ug.user_id', 'INNER')->join('groups g', 'ug.group_id = g.id', 'INNER')->join($uc, 'u.id=uc.user_id', 'LEFT')->join('companies com', 'uc.company_id=com.id', 'LEFT')->where('u.is_deleted', 0);
     if (array_key_exists('company_id', $params) && gtzero_integer($params['company_id'])) {
         $this->db->where("uc.company_id", to_int($params['company_id']));
     }
     if (array_key_exists('group_id', $params) && gtzero_integer($params['group_id'])) {
         $this->db->where("g.id", to_int($params['group_id']));
     }
     return $this->db->count_all_results();
 }
Example #16
0
 public function add_site_form($input)
 {
     $this->db->insert("site_forms", $input);
     $primary_key = $this->db->insert_id();
     if (gtzero_integer($primary_key)) {
         return to_int($primary_key);
     }
     return 0;
 }
Example #17
0
 public function _validate_client_name($client_name, $pkey)
 {
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = isset($params['company_id']) && gtzero_integer($params['company_id']) ? (int) $params['company_id'] : 0;
     $client_id = isset($params['client_id']) && gtzero_integer($params['client_id']) ? (int) $params['client_id'] : 0;
     $count = $this->client_m->get_by_many(array('name' => $client_name, 'client_id_not' => $client_id), $company_id, 'COUNT');
     if ($count > 0) {
         $this->form_validation->set_message('_validate_client_name', 'The %s field must contain a unique value. Client name "' . $site_name . '" is already in use');
         return FALSE;
     }
     return TRUE;
 }
Example #18
0
 public function delete($pkey, $method = "echo")
 {
     _has_user_access_permission(TRUE, array('admin'));
     $params = ($params = unserialize_object($pkey)) && is_array($params) ? $params : array();
     $company_id = isset($params[SYS_COMPANY_ID]) && gtzero_integer($params[SYS_COMPANY_ID]) ? to_int($params[SYS_COMPANY_ID]) : 0;
     $redirect_url = $this->_post_args('redirect_url', ARGS_TYPE_STRING, $this->agent->referrer());
     $company_info = $this->company_m->details($company_id);
     if (!$company_info) {
         $this->show_permission_denied_error($method);
     }
     $this->form_validation->set_rules('confirm', 'confirm', 'trim|required');
     $output = array('message' => "", 'status' => "");
     if ($this->form_validation->run() == TRUE) {
         $is_record_updated = $this->company_m->delete($company_id);
         if ($is_record_updated) {
             $output['message'] = sprintf('The Agency "%s" has been deleted.', $company_info->name);
             $output['status'] = SUCCESS_MESSAGE;
             $output['company_id'] = $company_id;
             /*trigger_trip("company_deleted", 0, array('company_id' => $company_id, 'deleted_by' => $this->current_user->user_id));*/
         } else {
             $output['message'] = sprintf('Unable to Delete Agency "%s" record. Please report the issue to %s', $company_info->name, $this->cfg->contact_email);
             $output['status'] = ERROR_MESSAGE;
         }
         $this->_output_request($output, $redirect_url);
     } else {
         if (validation_errors()) {
             $output['message'] = validation_errors();
             $output['status'] = ERROR_MESSAGE;
         }
     }
     $csrf = _get_csrf_nonce();
     $data = array('form_action' => site_url('agencies/delete/' . $pkey), 'cancel_url' => $redirect_url, 'page' => 'companies/delete', 'title' => 'Delete Agency', 'display_message' => sprintf('Are you sure you want to delete Agency "%s"?', $company_info->name), 'display_heading' => sprintf('Delete Agency', $company_info->name), 'submit_btn_text' => 'Save Changes', 'hiddenvars' => array_merge($csrf, array('redirect_url' => $redirect_url)));
     if ($this->input->is_ajax_request()) {
         $html = $this->template->raw_view('pages/companies/delete_modal', $data, TRUE);
         if ($method == 'ajax') {
             $output['html'] = $html;
             $this->_output_request($output, $redirect_url);
         } else {
             echo $html;
         }
     } else {
         if (!empty($output['status'])) {
             set_flash_data($output['status'], $output['message'], FALSE);
         }
         $this->template->load('default', $data);
     }
 }
Example #19
0
" class="btn btn-primary  btn-xs" data-ajax="wdpajax" data-options='{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Agency Detail", "modal" : {"buttons" : true, "modal_success_callback" : "gl.user.form._init_companies(response);", "override" : true}, "params" : "echo"}'>
											<i class="fa fa-level-up"></i>
										</a>
									</div>
								</div>
								<?php 
    echo form_error('company_id', '<label class="error">', '</label>');
    ?>
							</div>
						</div>
						<?php 
}
?>

						<div class="form-group client_option" <?php 
echo _has_company_non_resources($group_id) && gtzero_integer($company_id) ? '' : 'style="display:none;"';
?>
>
							<label class="col-sm-4 control-label no-padding-right" for="client_ids">Client:</label>
							<div class="col-sm-8">
								<div class="row">
									<div class="col-sm-10">
										<?php 
echo form_dropdown('client_ids[]', clients_dropdown('return', array('company_id' => $company_id, 'first_row' => TRUE)), $client_ids, 'id="client_ids" class="form-control input-sm" data-placeholder="Select a Client" multiple="multiple"');
?>
									</div>
									<div class="col-sm-2">
										<a href="<?php 
echo site_url('clients/create/' . serialize_object());
?>
" class="btn btn-primary btn-xs" data-ajax="wdpajax" data-options='{"form_method" : "GET", "data_type" : "HTML", "role" : "modal", "created_new" : true, "title" : "Client detail", "modal" : {"buttons" : true, "modal_success_callback" : "gl.user.form._init_clients(response);", "override" : true}, "params" : "echo"}'>
 function _check_company_user_access()
 {
     $ci =& get_instance();
     $groups = array(GROUP_MANAGEMENT_COMPANY);
     $company_id = in_array($ci->current_user->group_id, array(GROUP_ADMIN, GROUP_STAFF, GROUP_ENGINEER)) ? 0 : $ci->current_user->company_id;
     if (gtzero_integer($company_id) && in_array(to_int($ci->current_user->group_id), $groups, TRUE)) {
         return TRUE;
     }
     return FALSE;
 }