// Model function editProduct() { // Delete current image if box was checked if ($this->input->post('deleteimage') && $this->input->post('currentimage')) { $this->image->deleteImage('products',$this->input->post('currentimage')); } // Set our validation rules and custom delimiters (for display) for the form $this->validation->set_rules(array('pid' => 'trim|required', 'cid' => 'trim|required', 'name' => 'trim|required|min_length[5]|max_length[128]', 'description' => 'trim')); $this->validation->set_error_delimiters('
  • ', '
  • '); // If form fails validation, reload data for view if ($this->validation->run() == FALSE) { $pid = (int) $this->input->post('pid'); ($pid) ? $data['pid'] = $pid : $data['pid'] = (int) $this->uri->segment(3); $data['product'] = $this->product->getProduct($data['pid']); // Check if product exists and load edit form or bounce to admin home if ($data['product']) { // Load category names and cids for select list $data['categories'] = $this->category->getallCategory(); $this->load->view('editproduct', $data); } else { $this->session->set_userdata('warningMessage', 'Product does not exist.'); redirect('/admin/'); } } else { // Load data with the information from our form $data = array('pid' => (int) $this->input->post('pid'), 'cid' => $this->input->post('cid'), 'name' => $this->input->post('name'), 'description' => $this->input->post('description'), 'image' => $this->image->addImage('products')); // If image upload failed, set back to current image, otherwise, delete old images $data['image'] === false ? $data['image'] = $this->input->post('currentimage') : $this->image->deleteImage('products',$this->input->post('currentimage')); // Surpress "no file selected for upload message" for edits if (empty($_FILES['userfile']['name'])) $this->session->set_userdata('warningMessage', ''); // Update product with data, set flash message and return to main admin page $this->product->updateProduct($data['pid'], $data); $this->session->set_userdata('statusMessage', 'Product '.$data['name'].' has been updated.'); redirect('/admin/listproducts/'.$data['cid']); } } // Model Administration :: Edit Product: <?= $product->name ?> load->view('header'); ?>

    Edit Product: name ?>

    validation->error_string ? '
    There were problems updating the product:
    ' : ''; ?>
    Product Info

    Product Image image) : ?>
    validation->set_checkbox('deleteimage', '1'); ?> /> Check to delete current image. No need to check if uploading a new image.

    image ? makeThumbnailPopup($product->image, '/assets/images/products/', $product->name) : 'No image is associated with this product.'?>

    load->view('footer'); ?>