function edit($id = FALSE, $page = 1) { //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; //get the $page and sanitize $page = $this->uri->segment(5) ? $this->uri->segment(5) : $this->input->post('page', TRUE); $page = $page != 0 ? filter_var($page, FILTER_VALIDATE_INT) : NULL; //redirect if it´s no correct if (!$id) { $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exist'))); redirect('admin/groups/'); } //variables for check the upload $form_data_aux = array(); $files_to_delete = array(); //Rules for validation $this->set_rules($id); //create control variables $this->template->title(lang('web_edit_group')); $this->template->set('updType', 'edit'); $this->template->set('page', $page); if ($this->form_validation->run() == FALSE) { //search the item to show in edit form $this->template->set('group', Group::find_by_id($id)); //load the view and the layout $this->template->build('groups/create'); } else { // build array for the model $form_data = array('id' => $this->input->post('id', TRUE), 'name' => set_value('name'), 'description' => set_value('description')); //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 $group = Group::find($this->input->post('id', TRUE)); $group->update_attributes($form_data); // run insert model to write data to db if ($group->is_valid()) { $this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_edit_success'))); redirect("/admin/groups/" . $page); } if ($group->is_invalid()) { $this->session->set_flashdata('message', array('type' => 'error', 'text' => $group->errors->full_messages())); redirect("/admin/groups/" . $page); } } }
function edit($id = FALSE, $parent_id = FALSE) { //load block submit helper and append in the head $this->template->append_metadata(block_submit_button()); //Rules for validation $this->_set_rules('edit'); //get the parent id and sanitize $parent_id = $this->uri->segment(5) ? $this->uri->segment(5) : $this->input->post('parent_id', TRUE); $parent_id = $parent_id != 0 ? filter_var($parent_id, FILTER_VALIDATE_INT) : NULL; //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; //redirect if it´s no correct if (!$id) { $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exit'))); redirect('admin/categories/'); } //create control variables $this->template->title(lang("web_category_edit")); $this->template->set('category', Category::find_by_id($id)); $this->template->set('updType', 'edit'); $this->template->set('parent_id', $parent_id); if ($this->form_validation->run() == FALSE) { //load the view and the layout $this->template->build('categories/create'); } else { // build array for the model $form_data = array('name' => $this->input->post('name', TRUE), 'id' => $this->input->post('id', TRUE)); //find the item to update $category = Category::find($this->input->post('id', TRUE)); $category->update_attributes($form_data); // run insert model to write data to db if ($category->is_valid()) { $this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_edit_success'))); redirect('admin/categories/' . $parent_id); } if ($category->is_invalid()) { $this->session->set_flashdata('message', array('type' => 'error', 'text' => $category->errors->full_messages())); redirect('admin/categories/' . $parent_id); } } }
function edit($id = FALSE) { //load block submit helper and append in the head $this->template->append_metadata(block_submit_button()); //get the $id $id = $this->uri->segment(4) ? $this->uri->segment(4) : $this->input->post('id', TRUE); //Filter & Sanitize $id $id = $id != 0 ? filter_var($id, FILTER_VALIDATE_INT) : NULL; //redirect if it´s no correct if (!$id) { $this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exist'))); redirect('/admin/users/'); } //Rules for validation $this->_set_rules('edit', $id); if ($this->form_validation->run() == FALSE) { $this->template->title(lang("web_edit_user")); $this->template->set('updType', 'edit'); $this->template->set('user', User::find_by_id($id)); $this->template->build('users/create_user'); } else { $data = array('username' => $this->input->post('email'), 'email' => $this->input->post('email'), 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name')); if ($this->input->post('password') != '') { $data['password'] = User::new_password($this->input->post('password')); } //find the item to update $user = User::find($this->input->post('id', TRUE)); $user->update_attributes($data); // run insert model to write data to db if ($user->is_valid()) { $this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_edit_success'))); redirect('/admin/users/'); } if ($user->is_invalid()) { $this->session->set_flashdata('message', array('type' => 'error', 'text' => lang('web_edit_failed'))); redirect('/admin/users/'); } } }
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)); } } }