function check_login($access = array()) { $CI =& get_instance(); $access = (array) $access; if ($CI->session->userdata('logged_in') === '1') { $data = $CI->session->userdata('loggedData'); if (in_array($data['group_id'], $access)) { $CI->db->where(array('email' => $data['email'], 'password' => $data['password'], 'group_id' => $data['group_id'])); $CI->db->where('active', '1'); $CI->db->from('user'); $query = $CI->db->count_all_results(); if ($query < 1) { $CI->session->set_userdata('login_error', '1'); $msg = array('login' => '<p>Some problem caused accessing this page. Please contact us regarding this issue.</p>'); set_global_messages($msg, 'error'); redirect('registration/login'); } } else { $CI->session->set_userdata('login_error', '1'); $msg = array('login' => '<p>You must have appropriate rights to access secure page.</p>'); set_global_messages($msg, 'error'); redirect('registration/login'); } } else { $CI->session->set_userdata('login_error', '1'); $msg = array('login' => '<p>You must be logged in to access secure area.</p>'); set_global_messages($msg, 'error'); redirect('registration/login'); } //just in case $CI->session->set_userdata('redirect', '1'); }
public function __construct($params = '') { $this->CI = get_instance(); if (!self::_check_access()) { //display access error and exit $msg = array('error' => '<p>You are not allowed to access this page.</p>'); set_global_messages($msg, 'error'); redirect($this->redirect); exit; } }
function index() { $data = ''; $banner_extension = $this->_tep_banner_image_extension(); // check if the graphs directory exists $dir_ok = false; if (function_exists('imagecreate') && !empty($banner_extension)) { if (is_dir(FCPATH . 'media' . DS . 'graph')) { if (is_writeable(FCPATH . 'media' . DS . 'graph')) { $dir_ok = true; } else { // display login error //$data['error_message'][] = 'Folder "' . dirname(FCPATH) . '/media/graph" must be writeable.'; $msg = array('error' => '<p>Folder ' . FCPATH . 'media' . DS . 'graph must be writeable.</p>'); set_global_messages($msg, 'error'); } } else { // display login error //$data['error_message'][] = 'Folder "' . dirname(FCPATH) . '/media/graph" does not exists.'; $msg = array('error' => "<p>Folder " . FCPATH . 'media' . DS . 'graph does not exists.</p>'); set_global_messages($msg, 'error'); } } $this->db->order_by('banner_title', 'asc'); $banner_query = $this->db->get('banner'); $data['banner'] = $banner_query->result_array(); foreach ($data['banner'] as $k => $v) { $info_query = $this->db->query("select sum(banner_shown) as banner_shown, sum(banner_clicked) as banner_clicked from cf_banner_history where banner_id = '" . (int) $v['banner_id'] . "'"); $data['banner'][$k]['info'] = $info_query->result_array(); } $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('screen' => array('admin', 'swiff', 'box', 'upload'), 'print' => array('admin')); //load all required js //$assets['js'] = array('mootools-1.2.1-core','Swiff.Uploader','Fx.ProgressBar','FancyUpload2'); $this->cf_asset_lib->load($assets); $this->load->view('admin/banner/banner_view', $data); }
function set_setting_keys($val) { if (isset($val['submit'])) { unset($val['submit']); } foreach ($val as $k => $v) { $this->db->where('setting_key', $k); $this->db->update('setting', array('setting_info' => $v)); } $msg = array('success' => "<p>Setting Updated Successfully.</p>"); set_global_messages($msg, 'success'); }
/** * Forgotten Password * * @access public * @return void */ public function forgotten_password() { $data = ''; //Define Validation Rules $val = array(array('field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|xss_clean')); $this->form_validation->set_rules($val); //Run Validation if ($this->form_validation->run()) { $email = set_value('email'); $query = $this->db->get_where('user', array('email' => $email)); $query = $query->result(); //If User Found With Such Email, Reset Password And Notify if (count($query) >= 1) { $userData = $query[0]; //Create A Random Password $newPass = $this->_createRandomPassword(); $newPassMD5 = md5($newPass); //update database with new password $this->db->where('email', $email); $this->db->update('user', array('password' => $newPassMD5)); //send new password $this->load->library('email'); $this->email->initialize(); $this->email->subject('| ' . $this->setting->site_name . ' | Password Reset'); $this->email->from($this->setting->email_sender, $this->setting->site_name); $this->email->to($email); //Prepare Email Body $emailBody = "\r\n\t\t\t\t\r\nHi " . $userData->firstname . " " . $userData->lastname . ",\r\n\r\nYou or someone requested for a new password through forgotten password link at " . $this->setting->site_name . " and we have reset your password.\r\n\r\nYour New Password is:\r\n\r\n" . $newPass . "\r\n\r\n"; $this->email->message($emailBody); if ($this->email->send()) { //Set Success Message $msg = array('login' => '<p>New Password Sent Successfully.</p>'); set_global_messages($msg, 'success'); $_POST = array(); } else { //Set Error Message //echo $this->email->print_debugger(); $msg = array('login' => '<p>System could not send password at this time, please try again later.</p>'); set_global_messages($msg, 'error'); } } else { //Set Error Message $msg = array('login' => '<p>Invalid Email.</p>'); set_global_messages($msg, 'error'); } } if (validation_errors()) { //Set Error Message $msg = array('login' => validation_errors()); set_global_messages($msg, 'error'); } //load all required css $assets['css'] = array('page', 'login'); //load all required js //$assets['js'] = array(); $this->cf_asset_lib->load($assets); //main content block [content view] $data['content_block'] = 'registration/forgotten_password_view'; /* | @process_view('data', 'master page') | @see app/core/MY_Controller.php */ $this->process_view($data); }
function _edit() { $data = ''; $id_array = array(); if (!isset($_POST['page'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => "<p>You must select atleast one page to edit</p>"); set_global_messages($msg, 'error'); unset($_POST); $this->index(); exit; } } !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('page_id', $id); $query = $this->db->get('page'); foreach ($query->result() as $row) { $_POST['page'][$row->page_id]['id'] = $row->page_id; $_POST['page'][$row->page_id]['page_active'] = $row->page_active; $_POST['page'][$row->page_id]['page_title'] = $row->page_title; //$_POST['page'][$row->page_id]['page_blurb'] = $row->page_blurb; //$_POST['page'][$row->page_id]['page_blurb_length'] = $row->page_blurb_length; $_POST['page'][$row->page_id]['page_body'] = $row->page_body; $_POST['page'][$row->page_id]['menu_id'] = $row->menu_id; $_POST['page'][$row->page_id]['websites_id'] = $row->websites_id; $_POST['page'][$row->page_id]['page_author'] = $row->page_author; $_POST['page'][$row->page_id]['page_tag'] = $row->page_tag; $_POST['page'][$row->page_id]['page_date'] = $row->page_date; $_POST['page'][$row->page_id]['show_date'] = $row->show_date; $_POST['page'][$row->page_id]['show_author'] = $row->show_author; $_POST['page'][$row->page_id]['allow_comment'] = $row->allow_comment; $_POST['page'][$row->page_id]['page_meta_title'] = $row->page_meta_title; $_POST['page'][$row->page_id]['page_meta_keywords'] = $row->page_meta_keywords; $_POST['page'][$row->page_id]['page_meta_description'] = $row->page_meta_description; $_POST['page'][$row->page_id]['page_sort'] = $row->page_sort; $_POST['page'][$row->page_id]['group_id'] = array('1', '2', '3'); } $this->db->where('page_id', $id); $query = $this->db->get('page_access'); //$test = $query->result_array(); foreach ($query->result() as $row) { $_POST['page'][$row->page_id]['group_id'] = explode('_', $row->group_id); } //To make it multiple selected, we need more than two elements in array. if (count($_POST['page'][$row->page_id]['group_id']) == 1) { $_POST['page'][$row->page_id]['group_id'][] = '0'; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['page']) && is_array($_POST['page'])) { foreach ($_POST['page'] as $v) { if (empty($v['menu_id'])) { $v['menu_id'][0] = 0; } if (empty($v['websites_id'])) { $v['websites_id'][0] = 0; } //print_r($v); //cleaning $id = xss_clean($v['id']); $page_active = xss_clean($v['page_active']); $page_title = $v['page_title']; $page_blurb = ''; //$page_blurb_length = xss_clean($v['page_blurb_length']); $page_body = $v['page_body']; $page_author = $v['page_author']; $page_tag = $v['page_tag']; $page_date = date('Y-m-d H:i:s', strtotime($v['page_date'])); $show_date = isset($v['show_date']) ? $v['show_date'] : '0'; $show_author = isset($v['show_author']) ? $v['show_author'] : '0'; $allow_comment = isset($v['allow_comment']) ? $v['allow_comment'] : '0'; $page_body = $v['page_body']; //$menu_id = $v['menu_id']; $page_meta_title = xss_clean($v['page_meta_title']); $page_meta_keywords = xss_clean($v['page_meta_keywords']); $page_meta_description = xss_clean($v['page_meta_description']); $page_sort = xss_clean($v['page_sort']); $page_break = explode('<!-- pagebreak -->', $page_body); if (isset($page_break[0])) { $page_blurb = trim($page_break[0]); if (substr($page_blurb, -1, 3) == '<p>') { $page_blurb = substr($page_blurb, 0, -3); } } //clean up menu ids $menu_id = array(); foreach ($v['menu_id'] as $w) { $w = xss_clean($w); $menu_id[$w] = $w; } $websites_id = array(); foreach ($v['websites_id'] as $w) { $w = xss_clean($w); $websites_id[$w] = $w; } //clean up group id, selected from multi select $group_id = array(); foreach ($v['group_id'] as $w) { $group_id[] = xss_clean($w); } //clean the data to autofill in form $_POST['page'][$id]['id'] = $id; $_POST['page'][$id]['page_active'] = $page_active; $_POST['page'][$id]['page_title'] = $page_title; //$_POST['page'][$id]['page_blurb'] = $page_blurb; //$_POST['page'][$id]['page_blurb_length'] = $page_blurb_length; $_POST['page'][$id]['page_body'] = $page_body; $_POST['page'][$id]['page_author'] = $page_author; $_POST['page'][$id]['page_tag'] = $page_tag; $_POST['page'][$id]['page_date'] = $page_date; $_POST['page'][$id]['show_date'] = $show_date; $_POST['page'][$id]['show_author'] = $show_author; $_POST['page'][$id]['allow_comment'] = $allow_comment; $_POST['page'][$id]['menu_id'] = $menu_id; $_POST['page'][$id]['websites_id'] = $websites_id; $_POST['page'][$id]['page_meta_title'] = $page_meta_title; $_POST['page'][$id]['page_meta_keywords'] = $page_meta_keywords; $_POST['page'][$id]['page_meta_description'] = $page_meta_description; $_POST['page'][$id]['page_sort'] = $page_sort; $_POST['page'][$id]['group_id'] = $group_id; //update database if set if (!empty($page_title) && !empty($page_body) && !empty($id)) { //delete previous tag //$this->db->delete('page_tag', array('page_id' => $id)); //delete|decrement previous tag count $this->db->where('page_id', $id); $query = $this->db->get('page'); $page_data = $query->result_array(); if ($page_data[0]['websites_id']) { $websites_ids = explode(',', trim($page_data[0]['websites_id'], ',')); $this->cf_data_model->tag_cloud_delete($id, $this->uri->segment(3, 'page'), $websites_ids); } //$this->cf_data_model->tag_cloud_delete($id, $this->uri->segment(3, 'page'), $websites_id); //update page $this->db->where('page_id', $id); $this->db->update('page', array('page_active' => $page_active, 'page_title' => $page_title, 'page_blurb' => $page_blurb, 'page_body' => $page_body, 'page_author' => $page_author, 'page_tag' => $page_tag, 'page_date' => $page_date, 'show_date' => $show_date, 'show_author' => $show_author, 'allow_comment' => $allow_comment, 'menu_id' => ',' . implode(',', $menu_id) . ',', 'websites_id' => ',' . implode(',', $websites_id) . ',', 'page_meta_title' => $page_meta_title, 'page_meta_keywords' => $page_meta_keywords, 'page_meta_description' => $page_meta_description, 'page_sort' => $page_sort)); //update page access $this->db->where('page_id', $id); $this->db->delete('page_access'); $this->db->insert('page_access', array('page_id' => $id, 'group_id' => implode('_', $group_id))); //update page tags if (isset($page_tag)) { $page_tag = explode(',', $page_tag); if (is_array($page_tag) && count($page_tag) > 0) { foreach ($page_tag as $v) { //clean tag $tag = url_title($v); //add|increment tag count $this->cf_data_model->tag_cloud_add($tag, $this->uri->segment(3, 'page'), $v, $websites_id); //insert tag to tag table $this->db->insert('page_tag', array('page_id' => $id, 'tag' => $tag)); } } } } $msg = array('success' => "<p>Updated successfully.</p>"); set_global_messages($msg, 'success'); } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'page', 'box')); //load all required js $assets['js'] = array('tiny_mce/tiny_mce'); $this->cf_asset_lib->load($assets); //$data['page'] = $this->cf_blog_model->get_page(); //--- $html_string = $this->load->view('admin/' . $this->uri->segment(3, 'page') . '/page_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function delete_ids($id) { $error = 0; $success = 0; $ids = (array) $id; foreach ($ids as $id) { $this->db->where('websites_id', $id); $this->db->delete('websites'); if ($this->db->affected_rows()) { $success++; } else { $error++; } } if ($error) { $msg = array('error' => "<p>{$error} websites could not be deleted.</p>"); set_global_messages($msg, 'error'); } if ($success) { $msg = array('success' => "<p>{$success} Websites Deleted Successfully.</p>"); set_global_messages($msg, 'success'); } return; }
function _upload($data = array()) { $data = (array) $data; if (empty($data)) { return FALSE; } $config = array(); $config['upload_path'] = FCPATH . 'media/upload/'; $config['allowed_types'] = 'gif|jpg|png|pdf|doc|zip|csv|xls'; $config['max_size'] = '1073741824'; //default: 1GB max //$config['max_width'] = '1024'; //$config['max_height'] = '768'; $config['file_field'] = 'file'; //overwrite default config values with supplied (if any) $config = array_merge($config, $data); //print_r($config); $this->load->library('upload', $config); if (!$this->upload->do_upload($config['file_field'])) { $msg = array('error' => $this->upload->display_errors()); set_global_messages($msg, 'error'); return FALSE; } else { return $this->upload->data(); } }
function index() { $url_to_trim = $this->input->post('longurl', TRUE); //Remove the last slash while (substr($url_to_trim, -1) == '/') { $url_to_trim = substr($url_to_trim, 0, -1); } //$url_to_trim = prep_url($url_to_trim); $error = FALSE; $data = array(); if (!empty($url_to_trim) && preg_match('|^https?://|', $url_to_trim)) { $this->config->load('trim.php'); $this->base = $this->config->item('allowed_chars'); //check if the client's IP is allowed to trim if ($_SERVER['REMOTE_ADDR'] != $this->config->item('limit_to_ip')) { $msg = array('error' => '<p>You are not allowed to trim URLs with this service.</p>'); set_global_messages($msg, 'error'); $error = TRUE; } // check if the URL is valid $pos = strpos($url_to_trim, base_url()); if ($this->config->item('verify_url') && !$error || $pos === FALSE) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_to_trim); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '404') { $msg = array('error' => '<p>That is not a valid URL.</p>'); set_global_messages($msg, 'error'); $error = TRUE; } curl_close($ch); } if (!$error) { // check if the URL has already been trimed $this->db->where('long_url', $url_to_trim); $query = $this->db->get('trim'); $already_trimed = $query->result_array(); if (!empty($already_trimed)) { // URL has already been trimed $integer = $already_trimed[0]['trim_id']; $trimed_url = $this->_getShortUrl($integer); } else { // URL not in database, insert $sql = array('long_url' => $url_to_trim, 'created' => time(), 'creator' => $_SERVER['REMOTE_ADDR']); $this->db->insert('trim', $sql); $trimed_url = $this->_getShortUrl($this->db->insert_id()); } $data['trim'] = site_url('trim/' . $trimed_url); $data['url'] = $url_to_trim; $msg = array('success' => '<p>URL successfully Trimed.</p>'); set_global_messages($msg, 'success'); } } elseif (isset($_POST['longurl'])) { $msg = array('error' => '<p>Not a valid URL.</p>'); set_global_messages($msg, 'error'); } $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'group', 'box')); //load all required js $assets['js'] = array('jquery', 'interface'); $this->cf_asset_lib->load($assets); $html_string = $this->load->view('admin/trim/trim_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function _edit() { $data = ''; $id_array = array(); if (!isset($_POST['menu'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { //$data['error_message']['select'] = "You must select atleast one menu to edit"; $msg = array('error' => '<p>You must select atleast one menu to edit.</p>'); set_global_messages($msg, 'error'); unset($_POST); $this->index(); exit; } } !is_array($id_array) ? $id_array = array() : ''; $menu_type = $this->uri->segment(3, 'page'); //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('menu_id', $id); $query = $this->db->get('menu'); foreach ($query->result() as $row) { $_POST['menu'][$row->menu_id]['id'] = $row->menu_id; $_POST['menu'][$row->menu_id]['menu_active'] = $row->menu_active; $_POST['menu'][$row->menu_id]['menu_parent_id'] = $row->menu_parent_id; $_POST['menu'][$row->menu_id]['menu_title'] = $row->menu_title; $_POST['menu'][$row->menu_id]['menu_link'] = $row->menu_link; $_POST['menu'][$row->menu_id]['menu_params'] = $row->menu_params; $_POST['menu'][$row->menu_id]['websites_id'] = $row->websites_id; $_POST['menu'][$row->menu_id]['menu_sort'] = $row->menu_sort; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['menu']) && is_array($_POST['menu'])) { foreach ($_POST['menu'] as $v) { //cleaning $id = xss_clean($v['id']); $menu_active = xss_clean($v['menu_active']); $menu_parent_id = xss_clean($v['menu_parent_id']); $menu_title = $v['menu_title']; $menu_link = $v['menu_link']; $menu_params = $v['menu_params']; $menu_sort = xss_clean($v['menu_sort']); $menu_type = $this->uri->segment(3, 'page'); if (!isset($v['websites_id'])) { $v['websites_id'] = 0; } $websites_id = xss_clean($v['websites_id']); //If menu link is not defined, create one. if (empty($menu_link)) { $menu_link = preg_replace('/[^a-z0-9]+/i', '-', strtolower($menu_title)); } //remove last dashes if any while (substr($menu_link, -1) == '-') { $menu_link = substr($menu_link, 0, -1); } //clean the data to autofill in form $_POST['menu'][$id]['id'] = $id; $_POST['menu'][$id]['menu_active'] = $menu_active; $_POST['menu'][$id]['menu_parent_id'] = $menu_parent_id; $_POST['menu'][$id]['menu_title'] = $menu_title; $_POST['menu'][$id]['menu_link'] = $menu_link; $_POST['menu'][$id]['menu_params'] = $menu_params; $_POST['menu'][$id]['menu_sort'] = $menu_sort; $_POST['menu'][$id]['websites_id'] = $websites_id; //update database if set if (!empty($menu_title) && !empty($menu_link) && !empty($id)) { /* $this->db->where('menu_id', $id); $this->db->update('menu', array( 'menu_active' => $menu_active, 'menu_parent_id' => $menu_parent_id, 'menu_title' => $menu_title, 'menu_link' => $menu_link, 'menu_type' => $menu_type, 'menu_sort' => $menu_sort)); */ $_menu_data = array('menu_id' => $id, 'menu_active' => $menu_active, 'menu_parent_id' => $menu_parent_id, 'menu_link' => $menu_link, 'menu_params' => $menu_params, 'menu_title' => $menu_title, 'menu_type' => $menu_type, 'menu_meta_title' => '', 'menu_meta_keywords' => '', 'menu_meta_description' => '', 'websites_id' => ',' . implode(',', (array) $websites_id) . ',', 'menu_sort' => $menu_sort); //insert new menu to database $insert = $this->cf_menu_model->update($_menu_data); } //['update']: to avoid repeated success_message /* $msg = array('success' => '<p>Updated successfully.</p>'); set_global_messages($msg, 'success'); */ } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'menu', 'box')); //load all required js $assets['js'] = array(); $this->cf_asset_lib->load($assets); //--- $data['websites'] = $this->cf_websites_model->get_websites(); $html_string = $this->load->view('admin/menu/menu_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function _approve() { $data = ''; if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $id_array = array(); $msg = array('error' => "<p>You must select atleast one comment to approve.</p>"); set_global_messages($msg, 'error'); } !is_array($id_array) ? $id_array = array() : ''; $msg = false; foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('page_comment_id', $id); if ($this->db->update('page_comment', array('page_comment_status' => '1'))) { $msg = array('error' => "<p>Selected comment(s) approved successfully.</p>"); $type = 'success'; } else { $msg = array('error' => "<p>Error! couldn't approve.</p>"); $type = 'error'; } } if ($msg) { set_global_messages($msg, $type); } return $data; }
function _edit() { $data = ''; $id_array = array(); if (!isset($_POST['group'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => '<p>You must select atleast one group to edit.</p>'); set_global_messages($msg, 'error'); unset($_POST); $this->index(); exit; } } !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('group_id', $id); $query = $this->db->get('group'); foreach ($query->result() as $row) { $_POST['group'][$row->group_id]['id'] = $row->group_id; $_POST['group'][$row->group_id]['title'] = $row->group_title; $_POST['group'][$row->group_id]['description'] = $row->group_description; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['group']) && is_array($_POST['group'])) { $msg = false; foreach ($_POST['group'] as $v) { //cleaning $id = xss_clean($v['id']); $title = xss_clean($v['title']); $description = xss_clean($v['description']); //clean the data to autofill in form $_POST['group'][$id]['id'] = $id; $_POST['group'][$id]['title'] = xss_clean($v['title']); $_POST['group'][$id]['description'] = xss_clean($v['description']); //update database if set if (!empty($title) && !empty($description) && !empty($id)) { $this->db->where('group_id', $id); $this->db->update('group', array('group_title' => $title, 'group_description' => $description)); if (!$msg) { $msg = array('success' => '<p>Updated successfully.</p>'); set_global_messages($msg, 'success'); } } } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'group', 'box')); //load all required js $assets['js'] = array(); $this->cf_asset_lib->load($assets); //--- $html_string = $this->load->view('admin/group/group_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function _manage_group_item() { $data = ''; $id_array = array(); //if its not submitting edit page (form_item_edit_view.php) if (!isset($_POST['group'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => '<p>You must select atleast one item to edit.</p>'); set_global_messages($msg, 'error'); unset($_POST); $this->group(); exit; } } !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('form_group_id', $id); $query = $this->db->get('form_group'); foreach ($query->result() as $row) { $_POST['group'][$row->form_group_id]['form_group_id'] = $row->form_group_id; $_POST['group'][$row->form_group_id]['form_group_name'] = $row->form_group_name; $_POST['group'][$row->form_group_id]['form_group_identifier'] = $row->form_group_identifier; $_POST['group'][$row->form_group_id]['form_group_send_to'] = $row->form_group_send_to; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['group']) && is_array($_POST['group'])) { foreach ($_POST['group'] as $v) { //cleaning $form_group_id = $v['form_group_id']; //clean the data to autofill in form $_POST['group'][$form_group_id]['form_group_id'] = $form_group_id; $_POST['group'][$form_group_id]['form_group_name'] = $v['form_group_name']; $_POST['group'][$form_group_id]['form_group_identifier'] = $v['form_group_identifier']; $_POST['group'][$form_group_id]['form_group_send_to'] = $v['form_group_send_to']; //update database if set if (!empty($v['form_group_name']) && !empty($v['form_group_identifier']) && !empty($v['form_group_id'])) { $this->db->where('form_group_id', $v['form_group_id']); $this->db->update('form_group', array('form_group_name' => $v['form_group_name'], 'form_group_identifier' => $v['form_group_identifier'], 'form_group_send_to' => $v['form_group_send_to'])); } //['update']: to avoid repeated success_message $msg = array('success' => '<p>Updated successfully.</p>'); set_global_messages($msg, 'success'); } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'group', 'box')); //load all required js $assets['js'] = array('jquery'); $this->cf_asset_lib->load($assets); //--- $html_string = $this->load->view('admin/form/form_group_item_manage_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function insert($_menu_data, $action = 'insert') { $_menu_data = (array) $_menu_data; if (empty($_menu_data)) { return FALSE; } if (!in_array($action, array('insert', 'update'))) { return FALSE; } if ($action == 'update') { $this->db->where('menu_id !=', $_menu_data['menu_id']); } $this->db->where('menu_title', $_menu_data['menu_title']); $this->db->where('menu_parent_id', $_menu_data['menu_parent_id']); $this->db->where('menu_type', $_menu_data['menu_type']); $count = $this->db->count_all_results('menu'); if ($count >= 1) { $msg = array('error' => '<p>Menu <strong>' . $_menu_data['menu_title'] . '</strong> already exists!</p>'); set_global_messages($msg, 'error'); return FALSE; } else { /* if($_menu_data['menu_type'] == 'blog') { $_menu_data['menu_link'] = 'blog/c/' . $_menu_data['menu_link']; } */ if ($action == 'update') { $this->db->where('menu_id !=', $_menu_data['menu_id']); } $this->db->where('menu_link', $_menu_data['menu_link']); $this->db->where('menu_type', $_menu_data['menu_type']); $this->db->where('menu_parent_id', $_menu_data['menu_parent_id']); $count = $this->db->count_all_results('menu'); if ($count >= 1 && !preg_match('/javascript::void\\(0\\);/', $_menu_data['menu_link'])) { $msg = array('error' => '<p>Menu Link <strong>' . $_menu_data['menu_link'] . '</strong> already exists!</p>'); set_global_messages($msg, 'error'); return FALSE; } else { $msg = array('success' => '<p>New Menu <strong>' . $_menu_data['menu_title'] . '</strong> Successfully Added.</p>'); if ($action == 'update') { $msg = array('success' => '<p>Menu <strong>' . $_menu_data['menu_title'] . '</strong> Updated Successfully.</p>'); } set_global_messages($msg, 'success'); /* $sql = array( 'menu_active' => $menu_active, 'menu_parent_id' => $menu_parent_id, 'menu_title' => $menu_title, 'menu_link' => $menu_link, 'menu_type' => $menu_type, 'menu_sort' => $menu_sort ); */ if ($action == 'update') { $this->db->where('menu_id', $_menu_data['menu_id']); } $this->db->{$action}('menu', $_menu_data); return TRUE; } } }
function _key_edit() { $data = ''; $id_array = array(); if (!isset($_POST['setting'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => "<p>You must select atleast one setting key to edit.</p>"); set_global_messages($msg, 'error'); unset($_POST); $this->keys(); exit; } } !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('setting_id', $id); $query = $this->db->get('setting_keys'); foreach ($query->result() as $row) { $_POST['setting'][$row->setting_id]['setting_id'] = $row->setting_id; $_POST['setting'][$row->setting_id]['setting_key'] = $row->setting_key; $_POST['setting'][$row->setting_id]['setting_info'] = $row->setting_info; $_POST['setting'][$row->setting_id]['setting_form'] = $row->setting_form; $_POST['setting'][$row->setting_id]['setting_option'] = $row->setting_option; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['setting']) && is_array($_POST['setting'])) { foreach ($_POST['setting'] as $v) { //cleaning $setting_id = $v['setting_id']; //clean the data to autofill in form $_POST['setting'][$setting_id]['setting_id'] = $setting_id; $_POST['setting'][$setting_id]['setting_key'] = $v['setting_key']; $_POST['setting'][$setting_id]['setting_info'] = $v['setting_info']; $_POST['setting'][$setting_id]['setting_form'] = $v['setting_form']; $_POST['setting'][$setting_id]['setting_option'] = $v['setting_option']; //update database if set if (!empty($v['setting_key']) && !empty($v['setting_info']) && !empty($v['setting_id'])) { $query = $this->db->get_where('setting_keys', array('setting_id' => $v['setting_id'])); $row = $query->result_array(); $this->db->where('setting_id', $v['setting_id']); $sql = array('setting_key' => $v['setting_key'], 'setting_option' => $v['setting_option'], 'setting_form' => $v['setting_form'], 'setting_info' => $v['setting_info']); $this->db->update('setting_keys', $sql); if (count($row) && isset($row[0]['setting_key'])) { $this->db->where('setting_key', $row[0]['setting_key']); $this->db->update('setting', $sql); } } $msg = array('success' => "<p>Updated successfully.</p>"); set_global_messages($msg, 'success'); } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'group', 'box')); //load all required js $assets['js'] = array(); $this->cf_asset_lib->load($assets); //--- $html_string = $this->load->view('admin/setting/key_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function edit_file() { $data = ''; $success_count = 1; $id_array = array(); //$_POST['file'] || see edit view file if (!isset($_POST['file'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => '<p>You must select atleast one file to edit.</p>'); set_global_messages($msg, 'error'); unset($_POST); $this->index(); exit; } } $this->load->library('form_validation'); $this->load->model('cf_group_model'); $this->load->model('cf_user_model'); $data['folder'] = $this->cf_file_model->get_active_folder(); $data['group'] = $this->cf_group_model->get_group(FALSE); $data['user'] = $this->cf_user_model->get_active_user(); !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('file_id', $id); $query = $this->db->get('file'); foreach ($query->result() as $row) { $_POST['file'][$row->file_id]['id'] = $row->file_id; $_POST['file'][$row->file_id]['active'] = $row->file_status; $_POST['file'][$row->file_id]['access'] = $row->file_access; $_POST['file'][$row->file_id]['parent'] = $row->folder_id; $_POST['file'][$row->file_id]['name'] = $row->file_title; $_POST['file'][$row->file_id]['description'] = $row->file_description; $file_access_members = explode(',', trim($row->file_access_members, ',')); $_POST['file'][$row->file_id]['group'] = $file_access_members; $_POST['file'][$row->file_id]['user'] = $file_access_members; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['file']) && is_array($_POST['file'])) { foreach ($_POST['file'] as $k => $v) { //cleaning $id = xss_clean($v['id']); //set_value('id'); $active = xss_clean($v['active']); //set_value('active'); $name = xss_clean($v['name']); //set_value('name'); $description = xss_clean($v['description']); //set_value('description'); $access = xss_clean($v['access']); $group = ''; if (isset($v['group'])) { $group = xss_clean($v['group']); } $user = ''; if (isset($v['user'])) { $user = xss_clean($v['user']); } //clean the data to autofill in form $_POST['file'][$id]['id'] = $id; $_POST['file'][$id]['active'] = $active; $_POST['file'][$id]['name'] = $name; $_POST['file'][$id]['description'] = $description; $_POST['file'][$id]['access'] = $access; $_POST['file'][$id]['group'] = $group; $_POST['file'][$id]['user'] = $user; //update database if set if (!empty($access) && !empty($name) && !empty($id)) { $val = array(array('field' => 'file[' . $k . '][active]', 'label' => 'STATUS[id: ' . $id . ']', 'rules' => 'trim|required|xss_clean'), array('field' => 'file[' . $k . '][name]', 'label' => 'FILE NAME[id: ' . $id . ']', 'rules' => 'trim|required|xss_clean'), array('field' => 'file[' . $k . '][description]', 'label' => 'FILE DESCRIPTION[id: ' . $id . ']', 'rules' => 'trim|xss_clean'), array('field' => 'file[' . $k . '][access]', 'label' => 'ASSIGN TO', 'rules' => 'trim|required|xss_clean')); if (isset($_POST['file'][$k]['access'])) { //--- switch ($_POST['file'][$k]['access']) { case 'group': $val[] = array('field' => 'file[' . $k . '][group][]', 'label' => 'User Group', 'rules' => 'trim|required|xss_clean'); $val[] = array('field' => 'file[' . $k . '][user][]', 'label' => 'User', 'rules' => 'trim|xss_clean'); break; case 'user': $val[] = array('field' => 'file[' . $k . '][group][]', 'label' => 'User Group', 'rules' => 'trim|xss_clean'); $val[] = array('field' => 'file[' . $k . '][user][]', 'label' => 'User', 'rules' => 'trim|required|xss_clean'); break; default: $val[] = array('field' => 'file[' . $k . '][group][]', 'label' => 'User Group', 'rules' => 'trim|xss_clean'); $val[] = array('field' => 'file[' . $k . '][user][]', 'label' => 'User', 'rules' => 'trim|xss_clean'); } } $this->form_validation->set_rules($val); if ($this->form_validation->run() == FALSE) { if (!validation_errors() == '' && $this->input->post('edit') == 'Update') { $msg = array('error' => validation_errors()); set_global_messages($msg, 'error'); } } else { $file = array('id' => $id, 'active' => $active, 'name' => $name, 'description' => $description, 'access' => $access, 'group' => $group, 'user' => $user); //FCPATH $update = $this->cf_file_model->update_file($file); if ($update) { $msg = array('success' => '<p>' . $success_count++ . ' Records Updated successfully.</p>'); set_global_messages($msg, 'success', false); } else { $msg = array('error' => '<p>Could not update files specified.</p>'); set_global_messages($msg, 'error'); } } } else { $msg = array('error' => '<p>Required fields can not be empty!</p>'); set_global_messages($msg, 'error'); } } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'file', 'box')); //load all required js $assets['js'] = array(); $this->cf_asset_lib->load($assets); //--- $html_string = $this->load->view('admin/file/file_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }
function _edit() { $this->load->library('form_validation'); $data = ''; $success_count = 1; $id_array = array(); if (!isset($_POST['user'])) { if (isset($_POST['select'])) { $id_array = $_POST['select']; } else { $msg = array('error' => '<p>You must select atleast one user to edit.</p>'); set_global_messages($msg, 'error'); unset($_POST); $this->index(); exit; } } !is_array($id_array) ? $id_array = array() : ''; //START: for the first page load, get data from database foreach ($id_array as $id) { $id = preg_replace('/[^0-9]+/', '', $id); $this->db->where('user_id', $id); $query = $this->db->get('user'); foreach ($query->result() as $row) { $_POST['user'][$row->user_id]['id'] = $row->user_id; $_POST['user'][$row->user_id]['active'] = $row->active; $_POST['user'][$row->user_id]['email'] = $row->email; $_POST['user'][$row->user_id]['firstname'] = $row->firstname; $_POST['user'][$row->user_id]['lastname'] = $row->lastname; $_POST['user'][$row->user_id]['group_id'] = $row->group_id; //$_POST['user'][$row->user_id]['password'] = $row->password; } } //END: for the first page load, get data from database //START: clean data and update in database if ($this->input->post('edit') == 'Update' && isset($_POST['user']) && is_array($_POST['user'])) { foreach ($_POST['user'] as $v) { //cleaning $id = (int) preg_replace('/[^0-9]+/', '', $v['id']); //only intergers $active = (int) preg_replace('/[^0-9]+/', '', $v['active']); $email = xss_clean($v['email']); $firstname = xss_clean($v['firstname']); $lastname = xss_clean($v['lastname']); $group_id = (int) preg_replace('/[^0-9]+/', '', $v['group_id']); $password = xss_clean($v['password']); //clean the data to autofill in form $_POST['user'][$id]['id'] = $id; $_POST['user'][$id]['active'] = $active; $_POST['user'][$id]['email'] = $email; $_POST['user'][$id]['firstname'] = $firstname; $_POST['user'][$id]['lastname'] = $lastname; $_POST['user'][$id]['group_id'] = $group_id; $_POST['user'][$id]['password'] = $password; //update database if set if (!empty($email) && !empty($group_id) && !empty($id)) { $_POST['email'] = $email; $_POST['group_id'] = $group_id; $_POST['firstname'] = $firstname; $_POST['lastname'] = $lastname; $_POST['password'] = $password; $val = array(array('field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|xss_clean|valid_email'), array('field' => 'group_id', 'label' => 'Group', 'rules' => 'trim|required|xss_clean'), array('field' => 'password', 'label' => 'Password', 'rules' => 'trim|xss_clean|md5'), array('field' => 'firstname', 'label' => 'First Name', 'rules' => 'trim|required|xss_clean'), array('field' => 'lastname', 'label' => 'Last Name', 'rules' => 'trim|required|xss_clean')); $this->form_validation->set_rules($val); if ($this->form_validation->run() == FALSE) { if (!validation_errors() == '' && $this->input->post('edit') == 'Update') { $msg = array('error' => validation_errors()); set_global_messages($msg, 'error'); } } else { $this->db->where('user_id', $id); $sql_update = array('active' => $active, 'email' => set_value('email'), 'firstname' => set_value('firstname'), 'lastname' => set_value('lastname'), 'group_id' => set_value('group_id')); if (!empty($password)) { $sql_update['password'] = set_value('password'); } //$password; $this->db->update('user', $sql_update); $msg = array('success' => '<p>' . $success_count++ . ' Records Updated successfully.</p>'); set_global_messages($msg, 'success', false); } } else { $msg = array('error' => '<p>Required fields can not be empty!</p>'); set_global_messages($msg, 'error'); } } } //END: validate data and update in database $assets = array(); //load all required css //if media type not defined, screen is default. //$assets['css'] = array('admin','swiff','box','upload'); $assets['css'] = array('all' => array('admin', 'user', 'box')); //load all required js $assets['js'] = array(); $this->cf_asset_lib->load($assets); //--- $html_string = $this->load->view('admin/user/user_edit_view', $data, true); //Get view data in place of sending to browser. $this->cf_process_lib->view($html_string); }