public function delete($id) { $article = Product::find_by_id($id); if ($article->delete()) { return true; } }
function test_create_product() { $form_data = array('name' => 'Product test 1', 'description' => 'Test Description, Test Description', 'active' => '1', 'option' => '1', 'category_id' => $this->m_category->id, 'image' => "srv/www/dfjdsf.jpg"); $product = Product::create($form_data); $this->m_product = Product::find_by_id(Product::last()->id); if ($product->is_valid()) { $this->_assert_true(TRUE); } if ($product->is_invalid()) { $this->_assert_true(FALSE); } }
public function getProductByID($id) { $product = Product::find_by_id($id); return in_array("id", $product) ? $product->id : 0; // $myaccount = Accounts::find_by_phone($phone); }
<?php require_once $libpath = substr(str_replace('\\', '/', __DIR__), 0, -28) . 'library/initialize.php'; if (!$session->is_logged_in()) { redirect_to(HOME . "login"); } //must have an ID if (empty($_GET['id'])) { $session->message("No product ID was provided."); redirect_to(HOME . "all-products"); } $product = Product::find_by_id($_GET['id']); if ($product && $product->destroy()) { $session->message("The AD for " . $product->name . " was removed."); redirect_to(HOME . "dashboard"); } else { $session->message("The AD could not be removed."); redirect_to(HOME . "dashboard"); } ?> <?php if (isset($database)) { $database->close_connections(); }
} elseif (isset($_GET["mbntab"])) { $back = HOME . "mobiles-and-tablets"; $id = $_GET["mbntab"]; } elseif (isset($_GET["clothing"])) { $back = HOME . "clothing-and-accessories"; $id = $_GET["clothing"]; } elseif (isset($_GET["booksncd"])) { $back = HOME . "books-and-cds"; $id = $_GET["booksncd"]; } elseif (isset($_GET["homenfur"])) { $back = HOME . "home-and-furniture"; $id = $_GET["homenfur"]; } elseif (isset($_GET["other"])) { $back = HOME . "other"; $id = $_GET["other"]; } elseif (isset($_GET["id"]) && !isset($_SESSION["user_id"])) { $back = HOME; $id = $_GET["id"]; } elseif (isset($_GET["id"]) && isset($_SESSION["user_id"])) { $back = HOME . "all-products"; $id = $_GET["id"]; } else { redirect_to(HOME); } $product = Product::find_by_id($id); if (!$product) { $session->message("The Photo could not be located"); redirect_to(HOME); } $user = User::find_by_id($product->user_id); include $dir_public . 'view-product.php';
public function create() { if (!empty($_POST['clientid']) && !empty($_POST['prodname']) && !empty($_POST["address"]) && !empty($_POST["country"]) && !empty($_POST["state"])) { /*if(Client::find_by_id($_POST['clientid'])){ return 4; //Ensures that user creates the clients before proceeding exit; } if(Client::find_by_id($_POST['prodid'])){ return 5; //Cannot enter ensures that users enter an existing product in the category exit; }*/ $newProduct = new Cproduct(); if (isset($_FILES['fupload']) && $_FILES['fupload']['error'] == 0) { //if file upload is set move_uploaded_file($_FILES['fupload']['tmp_name'], "public/uploads/" . basename($_FILES['fupload']['name'])); $image = new Imageresize(); // an instance of image resize object $image->load("public/uploads/" . basename($_FILES['fupload']['name'])); //$image->image =; $image->resize(400, 400); $image->save("public/uploads/" . basename($_FILES['fupload']['name'])); //this section is needed to get the extension for image type in renaming the image if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/png") { $ext = ".png"; } if ($_FILES['fupload']['type'] == "image/jpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/pjpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/jpg") { $ext = ".jpg"; } $new_name = uniqid() . "_" . time() . $ext; //new name for the image rename("public/uploads/" . basename($_FILES['fupload']['name']), "public/uploads/" . $new_name); $photo = $new_name; $newProduct->img_url = $photo; } else { //$applicant->img_url = $_POST['imgvalue']; } $areadata = explode(",", $_POST['area']); $cid = explode(",", $_POST["country"]); $newProduct->client_id = $_POST["clientid"]; $newProduct->client_name = $_POST["clientname"]; $newProduct->prod_id = $_POST["prodid"]; $newProduct->terminal_id = $_POST['terminal_id']; $newProduct->prod_name = $_POST["prodname"]; //." ". $_POST["clientname"]." ".$_POST["sregion"]." ".$_POST['site']; $newProduct->prod_serial = $_POST["serial"]; $newProduct->install_address = $_POST["address"]; $newProduct->install_country = $cid[1]; $newProduct->install_state = $_POST["state"]; $newProduct->install_area_id = $areadata[0]; $newProduct->install_area = $areadata[1]; $newProduct->install_city = $_POST['sregion'] == "Other" || !empty($_POST['sregion']) ? $_POST["city"] : $_POST['sregion']; $newProduct->install_status = 0; $newProduct->status = 0; $newProduct->branch = $_POST['site']; $newProduct->atm_type = $_POST["mmode"]; $newProduct->os = $_POST["os"]; $newProduct->selling_price = $_POST["amount"]; $newProduct->datecreated = date("Y-m-d H:i:s"); $prod = Product::find_by_id($_POST['prodid']); $Tlog2 = new Transaction(); $Tlog2->com_id = $prod->main_id; $Tlog2->trans_type = "CLIENT PRODUCT CREATION"; $Tlog2->trans_description = $prod->prod_name . " assigned to" . $_POST["clientname"] . " Role"; $Tlog2->datecreated = date("Y-m-d H:i:s"); $Tlog2->user_id = $_SESSION['emp_ident']; $client = Client::find_by_id($_POST["clientid"]); $Tlog = new Transaction(); $Tlog->com_id = $client->main_id; $Tlog->trans_type = "CLIENT ASSIGNED PRODUCT"; $Tlog->trans_description = $prod->prod_name . " assigned to" . $_POST["clientname"] . " Role"; $Tlog->datecreated = date("Y-m-d H:i:s"); $Tlog->user_id = $_SESSION['emp_ident']; global $session; if ($newProduct->create()) { $Tlog->create(); $Tlog2->create(); $_SESSION["message"] = "<div data-alert class='alert-box success'>Record Saved <a href='#' class='close'>×</a></div>"; return 1; //returns 1 on success } else { $_SESSION["message"] = "<div data-alert class='alert-box alert'>Unexpected Error! Record not Saved <a href='#' class='close'>×</a></div>"; return 2; // returns 2 on insert error } } else { $_SESSION["message"] = "<div data-alert class='alert-box alert'>Unexpected Error! Record not Saved <a href='#' class='close'>×</a></div>"; return 3; //returns 3 if requiered input field is not supplied } }
function edit($id = FALSE) { //load block submit helper and append in the head $this->template->append_metadata(block_submit_button()); //get the $id and sanitize $id = $this->uri->segment(4) ? $this->uri->segment(4) : $this->input->post('id', TRUE); $id = $id != 0 ? filter_var($id, FILTER_VALIDATE_INT) : NULL; //search the categories and send to the view $this->load->model('category'); //create control variables $this->template->title('web_edit_product'); $this->template->set('updType', 'edit'); $this->template->set('page', $this->uri->segment(6) ? $this->uri->segment(6) : $this->input->post('page', TRUE)); $this->template->set('parent_id', $this->uri->segment(5) ? $this->uri->segment(5) : $this->input->post('parent_id', TRUE)); $this->template->set('categories', Category::get_formatted_combo()); //variables for check the upload $form_data_aux = array(); $files_to_delete = array(); //redirect if it´s no correct if (!$id) { $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exist'))); redirect('products/'); } //Rules for validation $this->set_rules(); if ($this->form_validation->run() == FALSE) { //search the item to show in edit form $this->template->set('product', Product::find_by_id($id)); //load the view and the layout $this->template->build('products/create'); } else { $data['product'] = Product::find($this->input->post('id', TRUE)); $this->template->set('product', $data['product']); foreach ($_FILES as $index => $value) { if ($value['name'] != '') { //initializing the upload library $this->load->library('upload'); $this->upload->initialize($this->set_upload_options('products')); //upload the image if (!$this->upload->do_upload($index)) { $this->template->set('upload_error', $this->upload->display_errors("<span class='error'>", "</span>")); //load the view and the layout $this->template->build('products/create'); return FALSE; } else { //create an array to send to image_lib library to create the thumbnail $info_upload = $this->upload->data(); //Save the name an array to save on BD before $form_data_aux[$index] = $info_upload["file_name"]; //Save the name of old files to delete array_push($files_to_delete, $data['product']->{$index}); //Load and initializing the imagelib library to create the thumbnail $this->load->library('image_lib'); $this->image_lib->initialize($this->set_thumbnail_options($info_upload, 'products')); //create the thumbnail if (!$this->image_lib->resize()) { $this->template->set('upload_error', $this->image_lib->display_errors("<span class='error'>", "</span>")); //load the view and the layout $this->template->build('products/create'); return FALSE; } } } } // build array for the model $form_data = array('name' => $this->input->post('name', TRUE), 'description' => $this->input->post('description', TRUE), 'active' => $this->input->post('active', TRUE), 'option' => $this->input->post('option', TRUE), 'category_id' => $this->input->post('category_id', TRUE), 'id' => $this->input->post('id', TRUE)); //add the aux form data to the form data array to save $form_data = array_merge($form_data_aux, $form_data); //find the item to update $product = Product::find($this->input->post('id', TRUE)); //save the old image to delete $old_image = $product->image; // run insert model to write data to db $product->update_attributes($form_data); if ($product->is_valid()) { $this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_edit_success'))); //delete the old images foreach ($files_to_delete as $index) { if (is_file(FCPATH . 'public/uploads/products/img/' . $index)) { unlink(FCPATH . 'public/uploads/products/img/' . $index); } if (is_file(FCPATH . 'public/uploads/products/img/thumbs/' . $index)) { unlink(FCPATH . 'public/uploads/products/img/thumbs/' . $index); } } } if ($product->is_invalid()) { $this->session->set_flashdata('message', array('type' => 'error', 'text' => $product->errors->full_messages())); } if ($this->input->post('parent_id')) { redirect('admin/products/product_list/' . $this->input->post('category_id', TRUE) . '/' . $this->input->post('page', TRUE)); } else { redirect('admin/products/' . $this->input->post('page', TRUE)); } } }
function getProductWeb() { if (isset($_POST['prod_id'])) { $product = Product::find_by_id($_POST['prod_id']); return $product; } }
public function updateProduct() { if (isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['editor2']) && !empty($_POST['editor2']) && isset($_POST['prod_id'])) { $error = ""; $product = Product::find_by_id($_POST['prod_id']); $val = new Val(); if ($val->minlength($_POST['name'], 3) && $val->maxlength($_POST['name'], 255)) { $product->prod_name = strip_tags($_POST['name']); } else { $error .= "Name, "; } $product->prod_web_content = htmlspecialchars($_POST['editor2']); $product->prod_visible = $_POST['display']; if (isset($_POST['desc']) && !empty($_POST['desc'])) { $product->prod_desc = $_POST['desc']; } if (isset($_POST['series']) && !empty($_POST['series'])) { $product->prod_series = $_POST['series']; } if (isset($_POST['company']) && !empty($_POST['company'])) { $product->prod_company = $_POST['company']; } if (!empty($_FILES['image']['name'])) { $filepath = $this->upload_pix(); if ($filepath) { $product->prod_image = $filepath; } else { $error .= "Image, "; } } if (!empty($_FILES['pdf']['name'])) { $filepath = $this->upload_document(); if ($filepath) { $product->prod_pdf = $filepath; } else { $error .= "File, "; } } $product->prod_cat_id = $this->getCatID(); if ($error == "") { if ($product->update()) { $_SESSION['adminmessage'] = "Product updated successfully"; } else { $error = "An error occured please try again"; } } } else { $error = "Please fill all the required spaces"; } if ($error == "") { return true; } else { $_SESSION['adminmessage'] = $error; return false; } }