public function LoginParticulier() { $this->mLayout = "empty"; $this->mTheme = 'login-page'; $this->mViewFile = 'loginparticulier'; if (validate_form()) { $username = $this->input->post('username'); $password = $this->input->post('password'); $this->load->model('User_model', 'user_model'); $user = $this->user_model->get_by('email', $username); // only admin and staff can login /*if ( verify_role(['admin', 'staff'], $user) ) {*/ // password correct if (verify_pw($password, $user['password'])) { // limited fields to store in session $fields = array('id', 'role', 'email', 'first_name', 'last_name', 'created_at'); $user_data = elements($fields, $user); login_user($user); // success set_alert('success', 'Connexion réussie'); redirect('home'); exit; } //} // failed set_alert('danger', 'Nom d\'utilisateur ou Mot de passe incorrect'); redirect('/login/Loginparticulier'); } }
function update_product_table() { $action = $this->action; if ($action == 'visibility') { $this->update_product_table_visibility(); $type = 'success'; $msg = 'Changes successfully saved.'; } else { if ($action == 'delete') { $this->update_product_table_delete(); $type = 'success'; $msg = 'Item(s) successfully deleted.'; } else { if ($action == 'new') { $this->update_product_table_new(); } else { if ($action == 'status') { $this->update_product_active(); $type = 'success'; $msg = 'Changes successfully saved.'; } } } } $page = 'self'; set_alert($type, $msg); safe_redirect($page); }
public function form_basic() { $form = $this->form_builder->create_form('example/form_basic'); $form->add_text('name', 'Name', TRUE); $form->add_text('email', 'Email', TRUE); $form->add_text('subject', 'Subject'); $form->add_textarea('message', 'Message', TRUE); $form->add_recaptcha(); $form->add_submit(); if (!empty($this->input->post()) && $form->validate()) { // passed validation $email = $this->input->post('email'); $password = $this->input->post('password'); if (empty($user_id)) { // failed $form->add_custom_error('Failed to create user'); } else { // success set_alert('success', 'Thanks for registration. We have sent you a email and please follow the instruction to activate your account.'); redirect('account/login'); } } // display form when no POST data, or validation failed $this->mViewData['form'] = $form; $this->_render('example/form_basic'); }
/** * Login page and submission */ public function index() { // Login form $this->load->library('form_builder'); $form = $this->form_builder->create_form('admin/login'); $form->add_text('username', '', 'Username', 'admin'); $form->add_password('password', '', 'Password', 'admin'); $form->add_submit('Sign In', 'primary', TRUE); if (!empty($this->input->post()) && $form->validate()) { // passed validation $username = $this->input->post('username'); $password = $this->input->post('password'); $this->load->model('admin_user_model', 'users'); $user = $this->users->login($username, $password); if (empty($user)) { // login failed set_alert('danger', 'Invalid Login'); refresh(); } else { // login success $this->session->set_userdata('admin_user', $user); redirect('admin'); } } // display form when no POST data, or validation failed $this->mViewData['form'] = $form; $this->mBodyClass = 'login-page'; $this->render('login', 'empty'); }
public function index() { $this->mLayout = "empty"; $this->mTheme = 'login-page'; $this->mViewFile = 'login'; if (validate_form()) { $username = $this->input->post('username'); $password = $this->input->post('password'); $this->load->model('Backend_user_model', 'backend_users'); $user = $this->backend_users->get_by('username', $username); // only admin and staff can login if (verify_role(['admin', 'staff-1', 'staff-2', 'staff-3'], $user)) { // password correct if (verify_pw($password, $user['password'])) { // limited fields to store in session $fields = array('id', 'role', 'username', 'full_name', 'created_at'); $user_data = elements($fields, $user); login_user($user); // success set_alert('success', 'Login success'); redirect('home'); exit; } } // failed set_alert('danger', 'Invalid Login'); redirect('login'); } }
/** * Submission of Change Password form */ public function change_password() { $this->load->model('admin_user_model', 'admin_users'); $updated = $this->admin_users->change_password($this->mUser->id, $this->input->post('new_password')); if ($updated) { set_alert('success', 'Successfully changed password.'); } else { set_alert('danger', 'Failed to changed password.'); } redirect('admin/account'); }
/** * Submission of Change Password form */ public function change_password() { $form_url = 'account'; if (validate_form($form_url)) { // update db $password = $this->input->post('password'); $update_data = ['password' => hash_pw($password)]; $result = $this->backend_users->update($this->mUser['id'], $update_data); // success set_alert('success', 'Mot de passe changé.'); } // back to form redirect($form_url); }
/** * Reset password for backend users */ public function reset_password($user_id) { $this->mTitle = "Backend Users"; $this->mViewFile = 'admin/reset_password'; $this->mViewData['target'] = $this->backend_users->get($user_id); if (validate_form('', 'admin/reset_password')) { // update db $password = $this->input->post('password'); $result = $this->backend_users->update($user_id, ['password' => hash_pw($password)]); // success or failed if ($result) { set_alert('success', 'Successfully updated.'); } else { set_alert('danger', 'Database error.'); } // refresh page to show alert msg redirect(current_url()); } }
public function register() { if (post('register')) { $pengguna = ['username' => post('username'), 'email' => post('email'), 'level' => 0, 'aktif' => 1]; $pelanggan = ['nama_lengkap' => post('nama'), 'alamat' => post('alamat'), 'kota' => post('kota'), 'telp' => post('telp')]; if (post('password') == post('passconf')) { $pengguna['password'] = md5(post('password')); } if ($userId = User::add($pengguna)) { $pelanggan['id_pengguna'] = $userId; if (Customer::add($pelanggan)) { set_alert('success', 'Registrasi berhasil, silahkan login ke akun yang baru saja anda buat'); redirect('login'); } else { set_alert('error', 'Maaf registrasi gagal'); redirect('register'); } } } return $this->render('form-register', ['heading' => 'Silahkan register']); }
function validate_form($form_url = '', $rule_set = '') { $CI =& get_instance(); $CI->load->library('form_validation'); if ($CI->form_validation->run($rule_set) == FALSE) { if (validation_errors()) { // save error messages to flashdata set_alert('danger', validation_errors()); // save all fields to flashdata for repopulating // note: set_value() will not work upon redirection $CI->session->set_flashdata('form_fields', $CI->input->post()); // refresh or jump page to show error messagees $url = empty($form_url) ? current_url() : $form_url; redirect($url); exit; } // display form return FALSE; } else { // success return TRUE; } }
function insert_product() { //include("static/thumbnail.php"); /* --- DEFINED VARIABLE --- */ $date = date('Y-m-d H:i:s'); $date_only = date('d-m-y-H-i-s'); $product_category = filter_var($this->product_category, FILTER_SANITIZE_NUMBER_INT); $product_name = filter_var($this->product_name, FILTER_SANITIZE_STRING); $product_size_type_id = filter_var($this->size_type, FILTER_SANITIZE_NUMBER_INT); $product_id = filter_var($this->product_id, FILTER_SANITIZE_NUMBER_INT); $type_id = $this->type_id; //array $color_id = $this->color_id; //array $type_name = $this->type_name; //array $type_code = $this->type_code; //array $type_price = $this->type_price; //array $type_description = $this->type_description; //array $type_sizefit = $this->type_sizefit; //array $type_image = $this->color_image; //double_array $type_delete = $this->type_delete; //array $order = $this->order; //double_array $image_id = $this->image_id; $image_delete = $this->image_delete; $stock_quantity = $this->stock_quantity; //double_array $stock_name = $this->stock_name; //double_array $type_weight = $this->type_weight; $page_title = filter_var($this->page_title, FILTER_SANITIZE_STRING); $page_description = filter_var($this->page_description, FILTER_SANITIZE_STRING); $page_keywords = filter_var($this->page_keywords, FILTER_SANITIZE_STRING); $product_alias = cleanurl($this->product_name, FILTER_SANITIZE_STRING); /* --- EDIT PRODUCT --- */ $this->update_product($product_category, $product_name, $product_size_type_id, $product_alias, $page_title, $page_description, $page_keywords, $product_id); /* --- TYPE PRODUCT --- */ $i = 0; $max_order = $this->get_max_type_order(); foreach ($type_name as $key => $type_name) { $i = $key; $i = $i + $max_order->maximum_order; $temp_type_order = $this->get_type_data($this->type_id[$key]); /* --- DELETE PRODUCTS --- */ if ($this->type_delete[$key] == '1') { if ($this->type_id[$key] != '') { $type_id_ = $this->type_id[$key]; $this->update_delete_product('1', $type_id_); $this->delete_stocks($type_id); } } else { $type_code = filter_var($this->type_code[$key], FILTER_SANITIZE_STRING); $type_name = filter_var($type_name, FILTER_SANITIZE_STRING); $type_alias = cleanurl($type_name); $type_price = filter_var($this->type_price[$key], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $type_description = $this->type_description[$key]; $type_sizefit = $this->type_sizefit[$key]; $type_information = $this->type_information[$key]; $color_id = filter_var($this->color_id[$key], FILTER_SANITIZE_NUMBER_INT); $type_weight = filter_var($this->type_weight[$key], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $product_id = filter_var($this->product_id, FILTER_SANITIZE_NUMBER_INT); $type_id = filter_var($this->type_id[$key], FILTER_SANITIZE_NUMBER_INT); /* --- ADD --- */ if ($type_id == '') { $this->insert_type_id($type_code, $type_name, $type_price, $type_description, $type_sizefit, $type_information, $color_id, $type_weight, $product_id, $i, $page_title, $page_description, $type_alias); } else { $this->update_type_id($type_code, $type_name, $type_price, $type_description, $type_sizefit, $type_information, $color_id, $type_weight, $temp_type_order->type_order, $type_alias, $page_title, $page_description, $type_id); } if ($type_id == '') { $temp = $this->get_max_type_id(); $type_id = $temp->max_type_id; } else { $type_id = $type_id; } /* --- END: ADD --- */ /* --- TYPE COLOR IMAGE--- */ $i = $key; if ($this->color_image["tmp_name"][$i] != null) { $file_type = substr($this->color_image["name"][$i], -4); $file_name = substr($this->color_image["name"][$i], 0, -4); $tmp_name = $this->color_image["tmp_name"][$i]; $name = cleanurl($type_name) . "_" . $date_only . "_" . substr(cleanurl($file_name), 0, 20) . '-' . $k . $file_type; $error = $this->color_image["error"][$i]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/type_color_image/{$name}"); $img_src = "files/uploads/type_color_image/{$name}"; } else { $type = 'error'; $msg = 'Error: ' . $error; set_alert($type, $msg); safe_redirect('self'); } $this->insert_type_color($img_src, $type_id); } else { $color_id = $this->color_id[$i]; $img_src = $_POST["color_image_" . $i]; } //$this->insert_type_color($img_src, $type_id); /* --- TYPE IMAGE --- */ for ($j = 0; $j < 5; $j++) { $k = $order[$i][$j]; //initial order $image_id = $this->image_id[$i][$k]; if ($image_id == "") { if ($this->type_image["tmp_name"][$i][$k] != null) { $file_type = substr($this->type_image["name"][$i][$k], -4); $file_name = substr($this->type_image["name"][$i][$k], 0, -4); $tmp_name = $this->type_image["tmp_name"][$i][$k]; $name = cleanurl($product_name) . "_" . cleanurl($type_name) . "_" . $date_only . "_" . substr(cleanurl($file_name), 0, 20) . '-' . $k . $file_type; $error = $this->type_image["error"][$i][$k]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/product_image/{$name}"); $img_src = "files/uploads/product_image/{$name}"; } else { $type = 'error'; $msg = 'Error: ' . $error; set_alert($type, $msg); safe_redirect('self'); } /* --- GENERATE TYPE IMAGE --- */ //$tg = new thumbnailGenerator; //$tg->generate('../files/uploads/product_image/'.$name, 260, 195, '../files/uploads/product_image/thumb_260x195/'.$name); $this->insert_type_image($type_id, $img_src, $j); } } else { if ($this->type_image["tmp_name"][$i][$k] != null) { $file_type = substr($this->type_image["name"][$i][$k], -4); $file_name = substr($this->type_image["name"][$i][$k], 0, -4); $tmp_name = $this->type_image["tmp_name"][$i][$k]; $name = cleanurl($product_name) . "_" . cleanurl($type_name[$i]) . "_" . $date_only . "_" . cleanurl($file_name) . $file_type; $error = $this->type_image["error"][$i][$k]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/product_image/{$name}"); $img_src = "files/uploads/product_image/{$name}"; } else { $type = 'error'; $msg = 'Error: ' . $error; set_alert($type, $msg); safe_redirect('self'); } /* --- CREATE THUMBNAIL --- */ //$tg = new thumbnailGenerator; //$tg->generate('../files/uploads/product_image/'.$name, 240, 360, '../files/uploads/product_image/thumb_240x360/'.$name); $this->update_type_image($img_src, $image_id); } $image_delete = filter_var($this->image_delete[$i][$k], FILTER_SANITIZE_NUMBER_INT); if ($image_delete == '1') { $this->delete_type_image($image_id); } $this->update_type_image_order($j, $image_id); } } /* --- TYPE STOCK --- */ $this->delete_stock($type_id); $stock_name_ = current($stock_name[$i]); $product_size_type_id = filter_var($this->size_type, FILTER_SANITIZE_NUMBER_INT); foreach ($stock_quantity[$i] as $stock_quantity_) { if ($stock_quantity_ != 0) { $stock_sold_out = 0; } else { $stock_sold_out = 1; } //$this->insert_stock($type_id, $stock_name_, $stock_quantity_, $stock_sold_out); $this->insert_stock($type_id, $product_size_type_id, $stock_name_, $stock_quantity_, $stock_sold_out); $stock_name_ = next($stock_name[$i]); } } } $this->check_sold_out($product_id); $page = 'product-details-' . $product_alias; $type = 'success'; $msg = 'Changes successfully saved.'; set_alert($type, $msg); //safe_redirect($page); }
public function users($do = '', $id = '') { $data = ['heading' => 'Administrasi: Pengguna']; switch ($do) { case 'form': if (post('submit')) { $data = ['username' => post('username'), 'email' => post('email')]; if (User::is('admin')) { $data['level'] = post('level'); } if ($password = post('password') and $password == post('passconf')) { $data['password'] = $password; } if (User::save($data, $id)) { if ($id) { set_alert('success', 'Berhasil memperbarui data pengguna <b>' . $data['username'] . '</b>'); } else { set_alert('success', 'Berhasil menambahkan <b>' . $data['username'] . '</b> sebagai pengguna'); } return redirect('admin/users'); } set_alert('error', 'Terjadi kesalahan dalam penyimpanan pengguna <b>' . $data['username'] . '</b>'); return redirect($this->uri->path()); } if ($id) { $data['data'] = User::show([User::primary() => $id])->fetchOne(); } return $this->render('user-form', $data); break; case 'delete': if (User::del([User::primary() => $id])) { set_alert('success', 'Pengguna berhasil terhapus'); } else { set_alert('error', 'Terjadi kesalahan dalam penghapusan pengguna'); } return redirect('admin/users'); break; default: $data['data'] = User::show(); return $this->render('user-table', $data); break; } }
function upload_file($global_url, $type, $file, $prefix, $upload_dir, $ini_max_upload) { /* ---------------------------------------------------------------------- * TYPE: * string: images / files * ---------------------------------------------------------------------- */ $files_name = substr($file['name'], 0, -4); $file_type = $file['type']; if ($type === 'images') { if ($file_type === 'image/jpeg') { $file_type = '.jpg'; } else { if ($file_type === 'image/png') { $file_type = '.png'; } else { if ($file_type === 'image/gif') { $file_type = '.gif'; } } } } else { if ($type === 'files') { if ($file_type === 'application/zip') { $file_type = '.zip'; } else { if ($file_type === 'application/x-rar-compressed') { $file_type = '.rar'; } else { if ($file_type === 'application/pdf') { $file_type = '.pdf'; } } } } } $uploads_dir = __DIR__ . '/../../../' . $upload_dir; $userfile_name = cleanurl(str_replace(array('(', ')', ' '), '_', substr($files_name, 0, 20))) . $file_type; $userfile_tmp = $file['tmp_name']; $file_error = $file['error']; $file_type = $file['type']; $slideshow_size = $file['size']; $prefix = $prefix . '-' . date('d-m-y-H-i-s') . '-'; $prod_img = $uploads_dir . $prefix . $userfile_name; $filename = $upload_dir . $prefix . $userfile_name; if ($type === 'images') { $allowed_type = array('image/jpeg', 'image/png', 'image/gif'); } else { if ($type === 'files') { $allowed_type = array('application/zip', 'application/x-rar-compressed', 'application/pdf'); } } /* --- TOTAL SIZE SLIDESHOW --- */ if ($slideshow_size > $ini_max_upload) { $type = 'danger'; $msg = 'Maximum file size: ' . price(1, $ini_max_upload) . 'Byte(s)'; set_alert($type, $msg); safe_redirect('self'); /* --- FILE TYPE (IMAGE: JPG, PNG, GIF & FILES: PDF, ZIP) --- */ } else { if (!in_array($file_type, $allowed_type)) { $type = 'danger'; $msg = 'Only allowed images format: .jpg, .png, .gif & files format: .pdf, .zip, .rar'; set_alert($type, $msg); safe_redirect('self'); } else { if (!move_uploaded_file($userfile_tmp, $prod_img)) { $type = 'danger'; $msg = 'Error: Permission denied, check folder: ' . $uploads_dir . ' permission'; set_alert($type, $msg); safe_redirect('self'); } else { if (move_uploaded_file($userfile_tmp, $prod_img) && $file_error == 0) { } } } } return $filename; }
/** * Menghapus data pada $table * * @param string $table Nama Tabel * @param array $where Kondisi * @return bool */ public function delete($table, $where = []) { $wheres = $this->_parseWhere($where); try { return $this->query("DELETE FROM `%s` %s", $table, $wheres); } catch (Exception $e) { set_alert('error', $e->getMessage()); return false; } }
function delete_category($category_id) { $sql = "SELECT IFNULL(total_product_main,0)+IFNULL(total_product_child,0) AS total_product\n\t\t\t \n\t\t\t FROM tbl_category AS cat \n\t\t\t LEFT JOIN (SELECT product_category, COUNT(tbl_product.id) AS total_product_main FROM tbl_product\n\t\t\t WHERE product_delete!='1'\n\t\t\t GROUP BY product_category) AS prod\n\t\t\t ON cat.category_id = prod.product_category\n\t\t\t \n\t\t\t LEFT JOIN (SELECT COUNT(x.id) AS total_product_child, category_parent FROM tbl_product AS x LEFT JOIN tbl_category_relation AS y\n\t\t\t ON x.product_category = y.category_child\n\t\t\t \t WHERE product_delete!='1'\n\t\t\t \t GROUP BY category_parent) AS prod2\n\t\t\t \t ON cat.category_id = prod2.category_parent\n\t\t\t \n\t\t\t \t LEFT JOIN (SELECT * from tbl_category_relation WHERE relation_level = '1') AS relation\n\t\t\t \t ON cat.category_id = relation.category_child\n\t\t\t \t WHERE (category_id = '{$category_id}')"; $query = $this->conn->query($sql); $row = array(); while ($result = $query->fetch_object()) { array_push($row, $result); } $total_product = $row[0]->total_product; if ($total_product != 0) { $type = 'danger'; $msg = "Can't delete item(s) because it contains one or more item under it."; } else { $sql = "SELECT * from tbl_category WHERE category_id = '{$category_id}'"; $query = $this->conn->query($sql); $result = $query->fetch_object(); if ($query->num_rows != null) { $get_order_array = $query->fetch_object(); $category_order = $get_order_array->category_order; } $sql = "UPDATE tbl_category SET category_order = '(category_order - 1)' WHERE category_order > ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("s", $category_order); $stmt->execute(); } $stmt->close(); $sql = "DELETE FROM tbl_category WHERE category_id = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("s", $category_id); $stmt->execute(); } $stmt->close(); $sql = "SELECT * from tbl_category_relation WHERE category_parent = '{$category_id}'"; $query = $this->conn->query($sql); if ($query->num_rows != null) { for ($counter = 1; $counter <= $query->num_rows; $counter++) { $category_relation_array = $query->fetch_object(); $category_child = $category_relation_array->category_child; $sql = "DELETE FROM tbl_category_relation WHERE category_parent = ? OR category_child = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("ss", $category_child, $category_child); $stmt->execute(); } $stmt->close(); $sql = "DELETE FROM tbl_category WHERE category_id = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("s", $category_child); $stmt->execute(); } $stmt->close(); } } $sql = "DELETE FROM tbl_category_relation WHERE category_child = ? OR category_parent = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("ss", $category_id, $category_id); $stmt->execute(); } $stmt->close(); $type = 'success'; $msg = "Successfully deleted category"; } set_alert($type, $msg); }
function upload_image($files, $upload_dir, $prefix, $page) { /* --- FILE: NAME & TYPE --- */ $files_name = substr($files['name'], 0, -4); $file_type = substr($files['name'], -4); $uploads_dir = $upload_dir; $name = cleanurl(str_replace(array('(', ')', ' '), '_', $files_name)) . $file_type; $tmp = $files['tmp_name']; $prefix = $prefix; $prod_img = $uploads_dir . $prefix . $name; $error = $files['error']; if ($error == 0) { if (move_uploaded_file($tmp, $prod_img)) { $filename = $prod_img; } else { $type = 'danger'; $msg = "Image upload failed"; set_alert($type, $msg); safe_redirect($page); } } else { $type = 'danger'; $msg = 'Error: ' . upload_code_message($error); set_alert($type, $msg); safe_redirect($page); } return $filename; }
function update_product_table_delete() { $type_id = $this->type_id; $product_id = $this->product_id; $counter = 1; foreach ($type_id as $type_id) { $ordered = $this->count_ordered($type_id); if ($ordered->rows > 0) { $counter++; /* --- SET INACTIVE --- */ $delete = '0'; $this->update_active_status($delete, $type_id); } else { /* --- DELETE --- */ //$this->update_type_delete($delete, $type_id); $img = $this->get_product_img($type_id); foreach ($img as $img) { if (is_file('../' . $img->img_src)) { unlink('../' . $img->img_src); } } $this->update_type_delete($type_id); } } $type = 'success'; if ($counter > 1) { $msg = 'Item(s) successfully deleted. However ' . $counter . ' item(s) are set to be inactive because it related with order(s)'; } else { $msg = 'Item(s) successfully deleted.'; } foreach ($product_id as $product_id) { $type_delete = '0'; $result = $this->count_product_type($product_id, $type_delete); if ($result->rows == 0) { $result = $this->count_max_id($product_id); $delete = '1'; $product_id = $result->max_id; $this->update_delete($product_id); } } $page = 'self'; set_alert($type, $msg); safe_redirect($page); }
public function checkout() { if (!User::current('id')) { redirect('login'); } if ($items = session('cart-items')) { $userId = User::current('id'); $userKey = User::primary(); $custKey = Customer::primary(); $pelanggan = Customer::show([$userKey => $userId])->fetchOne(); $order = [$userKey => $userId, $custKey => $pelanggan->{$custKey}, 'tanggal' => date('Y-m-d'), 'produk' => $items, 'belanja' => post('belanja'), 'kurir' => post('kurir'), 'ongkir' => post('ongkir'), 'bayar' => 0, 'kembali' => 0]; if (!$order['ongkir'] && !$order['kurir']) { set_alert('error', 'Estimasi ongkos kirim belum ada, pastikan field kurir sudah diisi.'); return redirect('cart'); } $order['total'] = $order['belanja'] + $order['ongkir']; if ($return = Order::add($order)) { session('cart-items', ''); set_alert('success', ['Terima kasih telah berbelanja di ' . conf('app.title') . '.', 'Segeralah melakukan pembayaran agar pesanan anda dapat secepatnya kami proses.']); } else { set_alert('error', 'Terjadi kesalahan dalam penghapusan order'); return redirect('cart'); } } if (User::loggedin()) { return redirect('admin-shop/orders/form/' . $return); } return redirect('shop'); }
public function inscription_newsletter() { $recherche = $this->input->post('newsletter', TRUE); set_alert('success_newsletter', 'Inscription réussi.'); }
/** * Account - Reset Password */ public function reset_password() { // skip when code not found or invalid $code = $this->input->get_post('code'); if (!$this->users->verify_forgot_password_code($code)) { set_alert('danger', 'Invalid Code'); redirect('account/login'); } $this->load->library('form_builder'); $form = $this->form_builder->create_form('account/reset_password'); $form->add_password('password', 'Password'); $form->add_password('retype_password', 'Retype Password'); $form->add_hidden('code', $code); $form->add_submit(); $post_data = $this->input->post(); if (!empty($post_data) && $form->validate()) { // passed validation $email = $this->input->post('email'); $password = $this->input->post('password'); $result = $this->users->reset_password($code, $password); if ($result) { set_alert('success', 'Your password has been reset. Please login again.'); redirect('account/login'); } else { set_alert('danger', 'Reset password failed'); refresh(); } } // display form when no POST data, or validation failed $this->mViewData['form'] = $form; $this->render('_partials/form'); }
function insert_product() { //include("static/thumbnail.php"); /* --- DEFINED VARIABLE --- */ $date = date('Y-m-d H:i:s'); $date_only = date('d-m-y-H-i-s'); $product_category = filter_var($this->product_category, FILTER_SANITIZE_NUMBER_INT); $product_name = filter_var($this->product_name, FILTER_SANITIZE_STRING); $product_size_type_id = filter_var($this->size_type, FILTER_SANITIZE_NUMBER_INT); $product_id = filter_var($this->product_id, FILTER_SANITIZE_NUMBER_INT); //$type_id = $this->type_id; //array $color_id = $this->color_id; //array $type_name = $this->type_name; //array $type_code = $this->type_code; //array $type_price = $this->type_price; //array $type_description = $this->type_description; //array $type_sizefit = $this->type_sizefit; //array //$type_image = $_POST["type_image"]; //double_array $type_delete = $this->type_delete; //array $order = $this->order; //double_array $image_id = $this->image_id; $image_delete = $this->image_delete; $stock_quantity = $this->stock_quantity; //double_array $stock_name = $this->stock_name; //double_array $type_weight = $this->type_weight; $page_title = filter_var($this->page_title, FILTER_SANITIZE_STRING); $page_description = filter_var($this->page_description, FILTER_SANITIZE_STRING); $page_keywords = filter_var($this->page_keywords, FILTER_SANITIZE_STRING); $product_alias = filter_var($this->product_alias, FILTER_SANITIZE_STRING); /* --- PRODUCT --- */ if ($product_id == '') { $temp_order = $this->get_product_order(); $product_order = $temp_order->max_order * 1 + 1; $check_product_name = $this->check_product_name($product_alias); if ($check_product_name->rows > 0) { $product_alias = $product_alias . '-' . $check_product_name->rows; } else { $product_alias = $product_alias; } $this->insert_add_product($product_category, $product_name, $product_size_type_id, $date, $product_order, $product_alias, $page_title, $page_description, $page_keywords); } else { //$this->update_product($product_category, $product_name, $product_size_type_id, $product_alias, $page_title, $page_description, $page_keywords, $product_id); } /* --- PRODUCT TYPE --- */ $i = 0; $max_order = $this->get_max_type_order(); foreach ($type_name as $key => $type_name) { $i = $key; $i = $i + $max_order->maximum_order; /* --- DELETE PRODUCTS --- */ if ($type_delete[$key] == '1') { if ($type_id[$key] != '') { $type_id_ = $type_id[$key]; $this->update_delete_product('1', $type_id_); $this->delete_stocks($type_id); } } else { $type_code = filter_var($this->type_code[$key], FILTER_SANITIZE_STRING); $type_name = filter_var($type_name, FILTER_SANITIZE_STRING); $type_alias = cleanurl($type_name); $type_price = filter_var($this->type_price[$key], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $type_price = floor($type_price); $type_description = filter_var($this->type_description[$key], FILTER_SANITIZE_STRING); $type_sizefit = filter_var($this->type_sizefit[$key], FILTER_SANITIZE_STRING); $type_information = filter_var($this->type_information[$key], FILTER_SANITIZE_STRING); $color_id = filter_var($this->color_id[$key], FILTER_SANITIZE_NUMBER_INT); $type_weight = filter_var($this->type_weight[$key], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $product_id = $this->get_max_product_id(); $product_id = $product_id->maximum_id; $this->insert_type_id($type_code, $type_name, $type_price, $type_description, $type_sizefit, $type_information, $color_id, $type_weight, $product_id, $i, $page_title, $page_description, $type_alias, 1); //}else{ /* --- EDIT PRODUCT TYPE --- */ /* $type_code = filter_var($type_code[$i], FILTER_SANITIZE_STRING); $type_name = filter_var($type_code[$i], FILTER_SANITIZE_STRING); $type_alias = cleanurl($type_name); $type_price = filter_var($type_code[$i], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $type_description = filter_var($type_code[$i], FILTER_SANITIZE_STRING); $type_sizefit = filter_var($type_code[$i], FILTER_SANITIZE_STRING); $color_id = filter_var($type_code[$i], FILTER_SANITIZE_NUMBER_INT); $type_weight = filter_var($type_code[$i], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $type_id_ = $type_id[$i]; $this->update_type_id($type_code, $type_name, $type_price, $type_description, $type_sizefit, $color_id, $type_weight, $i, $type_alias, $page_title, $page_description, $type_id);*/ //} /* --- TYPE COLOR IMAGE--- */ $i = $key; if ($this->color_image["tmp_name"][$i] != null) { $file_type = substr($this->color_image["name"][$i], -4); $file_name = substr($this->color_image["name"][$i], 0, -4); $tmp_name = $this->color_image["tmp_name"][$i]; $name = cleanurl($type_name) . "_" . $date_only . "_" . substr(cleanurl($file_name), 0, 20) . $file_type; $error = $this->color_image["error"][$i]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/type_color_image/{$name}"); $img_src = "files/uploads/type_color_image/{$name}"; } /* --- GET TYPE ID --- */ $type_id = $this->get_max_type_id(); $type_id = $type_id->type_id; $this->insert_type_color($img_src, $type_id); } /* --- GET TYPE ID --- */ $type_id = $this->get_max_type_id(); $type_id = $type_id->type_id; /* --- TYPE IMAGE --- */ for ($j = 0; $j < 8; $j++) { $k = $order[$i][$j]; $image_id_ = $image_id[$i][$k]; if ($this->type_image["tmp_name"][$i][$k] != null) { $file_type = substr($this->type_image["name"][$i][$k], -4); $file_name = substr($this->type_image["name"][$i][$k], 0, -4); $tmp_name = $this->type_image["tmp_name"][$i][$k]; $name = cleanurl($product_name) . "_" . cleanurl($type_name) . "_" . $date_only . "_" . cleanurl($file_name) . $file_type; $error = $this->type_image["error"][$i][$k]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/product_image/{$name}"); $img_src = "files/uploads/product_image/{$name}"; } /* --- GENERATE TYPE IMAGE --- */ //$tg = new thumbnailGenerator; //$tg->generate('../files/uploads/product_image/'.$name, 260, 195, '../files/uploads/product_image/thumb_260x195/'.$name); $this->insert_type_image($type_id, $img_src, $j); } /*}else{ if($_FILES["product_image"]["tmp_name"][$i][$k] != null){ $file_type = substr($_FILES["product_image"]["name"][$i][$k],-4); $file_name = substr($_FILES["product_image"]["name"][$i][$k], 0, -4); $tmp_name = $_FILES["product_image"]["tmp_name"][$i][$k];; $name = cleanurl($product_name)."_".cleanurl($type_name[$i])."_".$date_only."_".cleanurl($file_name).$file_type; $error = $_FILES["product_image"]["error"][$i][$k]; if($error == 0){ move_uploaded_file($tmp_name,"../files/uploads/product_image/$name"); $img_src="files/uploads/product_image/$name"; } /* --- GENERATE TYPE IMAGE --- */ /* $tg = new thumbnailGenerator; $tg->generate('../files/uploads/product_image/'.$name, 240, 360, '../files/uploads/product_image/thumb_240x360/'.$name); $this->update_type_image($img_src, $image_id_); }*/ /* --- DELETE TYPE IMAGE --- */ //if($image_delete[$i][$k]=='1'){ //$this->delete_type_image($image_id); //} /* --- TYPE IMAGE ORDER --- */ //$this->update_type_image_order($j, $image_id); //} } /* --- TYPE STOCK --- */ $this->delete_stock($type_id); $stock_name_ = current($stock_name[$i]); $product_size_type_id = filter_var($this->size_type, FILTER_SANITIZE_NUMBER_INT); foreach ($stock_quantity[$i] as $stock_quantity_) { if ($stock_quantity_ != 0) { $stock_sold_out = 0; } else { $stock_sold_out = 1; } if ($stock_quantity_ < 0) { $stock_quantity_ = 0; } else { $stock_quantity_ = $stock_quantity_; } //$this->insert_stock($type_id, $stock_name_, $stock_quantity_, $stock_sold_out); $this->insert_stock($type_id, $product_size_type_id, $stock_name_, $stock_quantity_, $stock_sold_out); $stock_name_ = next($stock_name[$i]); } } //delete } //for $page = 'add-product'; $type = 'success'; $msg = 'Item successfully saved'; set_alert($type, $msg); $this->check_sold_out($product_id); }
public function logout() { logout_user(); set_alert('success', 'Successfully logout.'); redirect('account/login'); exit; }
function add_category($name, $description, $parent, $active, $visibility) { $sql = "SELECT * from tbl_category ORDER BY category_order DESC"; $query = $this->conn->query($sql); if ($query->num_rows != null) { $get_order_array = $query->fetch_object(); $order = $get_order_array->category_order * 1 + 1; } else { $order = 0; } $get_alias = $this->get_alias($parent); if ($parent == 'top') { $alias = cleanurl($name); } else { $alias = $get_alias->category_alias . '-' . cleanurl($name); } $count_alias = $this->count_alias($alias); if ($count_alias->rows > 0) { $type = 'danger'; $msg = ''; safe_redirect('add-category'); } else { $alias = $alias; } $sql = "INSERT INTO tbl_category (`category_name`,`category_alias`, `category_description`, `category_order`, `category_active_status`, `category_visibility_status`) \n\t\t\t\t VALUES(?, ?, ?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("ssssss", $name, $alias, $description, $order, $active, $visibility); $stmt->execute(); } $stmt->close(); $sql = "SELECT * from tbl_category WHERE category_name = '{$name}' ORDER BY category_id DESC"; $query = $this->conn->query($sql); if ($query->num_rows != null) { $get_id_array = $query->fetch_object(); $category_id = $get_id_array->category_id; } $parent_array = array(); $sql = "SELECT * from tbl_category_relation WHERE category_child = '{$parent}'"; $query = $this->conn->query($sql); if ($query->num_rows != null) { for ($counter = 1; $counter <= $query->num_rows; $counter++) { $get_parent_array = $query->fetch_object(); $tmp_level = $get_parent_array->relation_level; $tmp_parent = $get_parent_array->category_parent; $parent_array[$tmp_level] = $tmp_parent; } } $temp_relation = '1'; $sql = "INSERT INTO tbl_category_relation(category_child, category_parent, relation_level) VALUES(?, ?, ?)"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("sss", $category_id, $parent, $temp_relation); $stmt->execute(); } $stmt->close(); foreach ($parent_array as $level => $parent) { $new_level = $level * 1 + 1; $sql = "INSERT INTO tbl_category_relation(category_child, category_parent, relation_level)VALUES(?, ?, ?)"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("sss", $category_id, $parent, $new_level); $stmt->execute(); } $stmt->close(); if ($parent == 'top') { $category_level = $level; } } $sql = "UPDATE tbl_category SET category_level = ? WHERE category_id = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("ss", $category_level, $category_id); $stmt->execute(); } $stmt->close(); $type = 'success'; $msg = 'Item(s) has been successfully added.'; set_alert($type, $msg); }
public function inscription() { $data = array(); $data['menu'] = ''; if ($this->input->post()) { $nom = $this->input->post('nom', TRUE); $prenom = $this->input->post('prenom', TRUE); $tel = $this->input->post('telephone', TRUE); $mail = $this->input->post('mail', TRUE); $mdp = $this->input->post('password', TRUE); $mdp_re = $this->input->post('repassword', TRUE); $rcs = $this->input->post('rcs', TRUE); $role = $this->input->post('type', TRUE); if ($mdp == $mdp_re) { $user = $this->db->query("SELECT * FROM users WHERE email = " . $this->db->escape($mail))->row(); if (!$user) { $this->db->query(' INSERT INTO users(nom, prenom, telephone, email,rcs,role, password) VALUES( ' . $this->db->escape($nom) . ', ' . $this->db->escape($prenom) . ', ' . $this->db->escape($tel) . ', ' . $this->db->escape($mail) . ', ' . $this->db->escape($rcs) . ', ' . $this->db->escape($type) . ', ' . $this->db->escape(sha1($mdp)) . ' )'); $from = '*****@*****.**'; $to = $mail; $objet = '[Pays de la Drôme] Demande de nouveau mot de passe'; $contenu = ''; $contenu .= 'Bonjour,<br/>'; $contenu .= 'Vous avez effectué une demande de nouveau mot de passe sur le site <a href="#">www.paysdeladrome.com</a>.<br/><br/>'; $contenu .= 'Voici vos nouveaux identifiants de connexion:<br/>'; $contenu .= '- Email: <b>' . $mail . '</b><br/>'; $contenu .= '- Mot de passe: <b>' . $mdp . '</b><br/>'; $contenu .= '<br/>Vous pouvez modifier ce mot de passe via votre espace personnel sur le site <a href="#">www.paysdeladrome.com</a> : <u>Mon Compte</u>, rubrique <u>Mes Infos Personnelles</u>.'; //$this->mail_action($to, $from, $objet, $contenu); set_alert('success', 'Un email vous a été envoyé avec un récapitulatif de vos informations.'); } else { set_alert('danger', 'Le compte existe déjà.'); } } else { set_alert('danger', 'Les mots de passe ne sont pas identiques.'); } redirect(current_url()); } $this->load->view('inscription.php', $data); }
} } else { $image_delete = filter_var($_POST['delete_news_' . $i], FILTER_SANITIZE_NUMBER_INT); if ($image_delete == 1) { $image = ''; $_update->delete_news_img($news_id, $i); if (is_file('../' . $news_detail->news_image)) { unlink('../' . $news_detail->news_image); } } else { $oldImg = $_get->get_news_image($news_id, $i); /*$image = $oldImg->image;*/ } } } $image_null = ''; if ($_req_lang === 'ID') { $_update->updateNewsLangField($news_detail->news_category, $image_null, $date, $visibility, $news_id); $_update->updateNews($category, $title, $alias, $date, $image_null, $excerpt, $content, $description, $keywords, $visibility, $news_id); } else { if ($_req_lang === 'EN') { $_update->updateNewsLang($title, $alias, $excerpt, $content, $description, $keywords, $news_id); } } $page = 'news-detail/' . $_req_lang . '/' . $news_detail->news_id . '/' . cleanurl(preg_replace("/[^A-Za-z0-9]/", ' ', $alias)); $type = 'success'; $msg = 'Changes successfully saved'; set_alert($type, $msg); safe_redirect($page); } }
public function categories($do = '', $id = '') { $this->data['heading'] = 'Administrasi: Kategori'; switch ($do) { case 'form': if (post('submit')) { $data = ['nama' => post('nama'), 'alias' => post('alias'), 'keterangan' => post('keterangan')]; if (Category::save($data, $id)) { if ($id) { set_alert('success', 'Berhasil memperbarui data kategori <b>' . $data['nama'] . '</b>'); } else { set_alert('success', 'Berhasil menambahkan kategori <b>' . $data['nama'] . '</b>'); } return redirect('admin-shop/categories'); } set_alert('error', 'Terjadi kesalahan dalam penyimpanan kategori <b>' . $data['nama'] . '</b>'); return redirect($this->uri->path()); } else { if ($id) { $this->data['data'] = Category::show([Category::primary() => $id])->fetchOne(); } return $this->render('category-form', $this->data); } break; case 'delete': if (Category::del([Category::primary() => $id])) { set_alert('success', 'Kategori berhasil terhapus'); } else { set_alert('error', 'Terjadi kesalahan dalam penghapusan kategori'); } return redirect('admin-shop/categories'); break; default: $this->data['data'] = Category::show(); return $this->render('category-table', $this->data); break; } }