public function get_user($search_string = null, $order = null, $order_type = 'DESC', $limit_start = null, $limit_end = null, $wherestatus = null, $user_id) { $get_parent_userids = model_load_model('user_role_extended_model')->get_user_role_extended_by_field_array(array("parent_user_id"), array(Access_level::session_user_id())); $this->db->select('*'); $this->db->from('order'); $this->db->where('user_id', $user_id); $query = $this->db->get(); return $query->result_array(); }
/** * Fetch user data from the database * possibility to mix search, filter and order * @param string $search_string * @param strong $order * @param string $order_type * @param int $limit_start * @param int $limit_end * @return array */ public function get_user($search_string = null, $order = null, $order_type = 'DESC', $limit_start = null, $limit_end = null, $wherestatus = null) { $get_parent_userids = model_load_model('user_role_extended_model')->get_user_role_extended_by_field_array(array("parent_user_id"), array(Access_level::session_user_id())); $this->db->select('*'); $this->db->from('user'); $this->db->where('user_type', 'operator'); $parent_ids[] = Access_level::session_user_id(); switch (Access_level::session_user_type()) { case 'super_admin': break; case 'admin': for ($i = 0; $i < count($get_parent_userids); $i++) { $parent_ids[] = $get_parent_userids[$i]['user_id']; } break; default: break; } $parent_string = implode(",", $parent_ids); if (Access_level::session_user_type() != 'super_admin') { $this->db->where("user_id IN ({$parent_string})"); } if ($wherestatus != null) { $this->db->where('status', $wherestatus); } //$this->db->order_by('status', 'Active'); if ($search_string) { if ($order == 'language_interface') { $this->load->model('site_language_model'); //$language_interface = $this->site_language_model->get_language_by_id(); //$lang = !empty($language_interface[0]['language_longform']) ? $language_interface[0]['language_longform'] : '--'; $this->db->join('site_language', 'user.language_interface = site_language.site_language_id'); $order = 'site_language.language_longform'; } $this->db->like($order, $search_string); } $this->db->group_by('user_id'); if ($order) { $this->db->order_by($order, $order_type); } else { $this->db->order_by('user_id', $order_type); } if ($limit_start && $limit_end) { $this->db->limit($limit_start, $limit_end); } if ($limit_start != null) { $this->db->limit($limit_start, $limit_end); } $query = $this->db->get(); return $query->result_array(); }
function addPosts() { $insertArr['uid '] = Access_level::session_user_id(); $insertArr['category_id'] = $_POST['category_id']; $insertArr['title'] = $_POST['title']; $insertArr['price'] = $_POST['price']; $insertArr['images'] = $_POST['images']; $insertArr['description'] = $_POST['description']; $insertArr['status'] = $_POST['status']; $insertArr['is_group'] = isset($_POST['is_group']) ? $_POST['is_group'] : ""; $insert = $this->db->insert('products', $insertArr); return $insert; }
/** * Update item by his id * @return void */ public function update() { $id = $this->uri->segment(4); $cat_id = $this->uri->segment(5); //if save button was clicked, get the data sent via post if ($this->input->server('REQUEST_METHOD') === 'POST') { $this->form_validation->set_rules('category_id', 'Category', 'required'); $this->form_validation->set_rules('title', 'Title', 'required|edit_unique[products.title.' . $id . ']'); $this->form_validation->set_rules('product_type', 'Product Type', 'required'); $this->form_validation->set_rules('uom', 'Unit of Measurement', 'required'); $this->form_validation->set_rules('qty', 'Quantity', 'required'); $this->form_validation->set_rules('price', 'Price', 'required'); $chckedImage = $_FILES['images']['name']; // if (empty($chckedImage)) { // $this->form_validation->set_rules('images', 'Product Image', 'required'); // } $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>'); if ($this->form_validation->run()) { $path = './uploads/product'; $this->load->library('upload'); $this->upload->initialize(array("upload_path" => $path, "allowed_types" => "*")); if (!empty($chckedImage)) { $data = $this->functions->do_upload_one('images', './uploads/product'); $file_name = $data['upload_data']['file_name']; $_POST['images'] = $file_name; @unlink("./uploads/product/" . $this->input->post('old_image')); } else { $file_name = $this->input->post('old_image'); $_POST['images'] = $file_name; } //if the insert has returned true then we show the flash message $redirect_url = $this->input->post('redirect_url'); foreach ($_POST as $k => $v) { if (in_array($k, array('redirect_url'))) { unset($_POST[$k]); } } $uid = Access_level::session_user_id(); $products_id = $this->input->post('products_id'); $category_id = $this->input->post('category_id'); $qty = $this->input->post('qty'); $title = $this->input->post('title'); $price = $this->input->post('price'); $images = $this->input->post('images'); $description = $this->input->post('description'); $status = $this->input->post('status'); $uom = $this->input->post('uom'); $product_type = $this->input->post('product_type'); $where = " AND uom_id={$uom}"; $uom_unit = $this->common_model->getFieldData('uom', 'uom', $where); if ($uom_unit == "KG" || $uom_unit == "LTR") { $convertedQty = Access_level::convertToMlOrGm($qty); } else { $convertedQty = $qty; } $is_group = $this->input->post('is_group'); if (!empty($is_group)) { $is_combo = $is_group; } else { $is_combo = "NO"; } $data_to_store = array("uid" => $uid, "category_id" => $category_id, "title" => $title, "images" => $images, "description" => $description, "price" => $price, "qty" => $convertedQty, "is_group" => $is_combo, "status" => $status, "product_type" => $product_type, "uom" => $uom); if ($this->products_model->update_products($data_to_store, $products_id) == TRUE) { $this->session->set_flashdata('flash_message', 'updated'); } else { $this->session->set_flashdata('flash_message', 'not_updated'); } $this->session->set_flashdata('flash_message', 'update'); redirect($redirect_url); } //validation run } $data['product_type_opt'] = $this->config->item('product_type_flag'); $data['uom_opt'] = $this->common_model->getDDArray('uom', 'uom_id', 'uom'); //if we are updating, and the data did not pass trough the validation //the code below wel reload the current data //product data $where = " AND parent_id= '0' "; $data['main_category_opt'] = $this->common_model->getDDArray('category', 'category_id', 'category_name', $where); //$data['country_opt'] = $this->common_model->getDDArray('country', 'country_id', 'country_name'); $data['products'] = $this->products_model->get_products_by_id($id); if ($data['products'][0]['category_id'] != "") { $where_subcategory = " AND parent_id!= '0' AND category_id='{$data['products'][0]['category_id']}'"; $data['subcategory_opt'] = $this->common_model->getDDArray('category', 'category_id', 'category_name', $where_subcategory); } //echo $id; die; $data['category'] = $this->category_model->get_category_by_id($cat_id); //echo "<pre>"; print_r($data['category']); die; $data['par_cat_array'] = $this->category_model->getParentCategoryList(0, $old_cat = "", 0, 1, 5); $data['main_content'] = 'admin/products/edit'; $this->load->view('admin/includes/template', $data); }
public function add() { //echo "<pre>"; print_r($_POST); die; //if save button was clicked, get the data sent via post if ($this->input->server('REQUEST_METHOD') === 'POST') { //form validation $this->form_validation->set_rules('firstname', 'First name', 'trim|required'); $this->form_validation->set_rules('username', 'User name', 'trim|required|min_length[4]|is_unique[user.username]'); $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]'); $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]'); $this->form_validation->set_rules('primary_email', 'primary E-mail', 'trim|required|valid_email|is_unique[user.primary_email]'); $this->form_validation->set_rules('company_id', 'Company name', 'trim|required'); $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>'); //if the form has passed through the validation if ($this->form_validation->run()) { $data = $this->functions->do_upload('avatar', './uploads/avatar/'); if (isset($data['upload_data'])) { $file_name = $data['upload_data']['file_name']; } else { $file_name = ""; } if (is_array($this->input->post('user_interests'))) { $user_interests = implode(",", $this->input->post('user_interests')); } else { $user_interests = ''; } if (is_array($this->input->post('language_id'))) { $language_ids = implode(",", $this->input->post('language_id')); } else { $language_ids = ''; } $user_rand_id = $this->functions->get_user_rand_id(); $data_to_store = array('firstname' => $this->input->post('firstname'), 'lastname' => $this->input->post('lastname'), 'username' => $this->input->post('username'), 'password' => $this->__encrip_password($this->input->post('password')), 'primary_email' => $this->input->post('primary_email'), 'company_id' => $this->input->post('company_id'), 'phone' => $this->input->post('phone'), 'user_type' => $this->input->post('user_type'), 'joining_date' => $this->input->post('joining_date'), 'end_date' => $this->input->post('end_date'), 'status' => $this->input->post('status')); //echo "<pre>"; print_r($data_to_store); die; //if the insert has returned true then we show the flash message if ($this->user_model->store_user($data_to_store)) { $user_id = $this->db->insert_id(); $ex_data = array('user_id' => $user_id, 'parent_user_id' => Access_level::session_user_id(), 'user_type' => $this->input->post('user_type')); $this->user_role_extended_model->store_user_role_extended($ex_data); $data['flash_message'] = TRUE; $this->session->set_flashdata('flash_message', 'add'); redirect('admin/user/'); //redirect('admin/user'.''); } else { $data['flash_message'] = FALSE; } } } $data['company'] = $this->company_model->get_company('', '', 'DESC', '', '', 'Active'); $data['main_content'] = 'admin/user/add'; $this->load->view('admin/includes/template', $data); }