function banner_form($banner_collection_id, $id = false) { $config['upload_path'] = 'uploads'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = $this->config->item('size_limit'); $config['encrypt_name'] = true; $this->load->library('upload', $config); $this->load->helper(array('form', 'date')); $this->load->library('form_validation'); //set the default values $data = array('banner_id' => $id, 'banner_collection_id' => $banner_collection_id, 'name' => '', 'enable_date' => '', 'disable_date' => '', 'image' => '', 'link' => '', 'new_window' => false); if ($id) { $data = array_merge($data, (array) $this->banner_model->banner($id)); $data['enable_date'] = format_mdy($data['enable_date']); $data['disable_date'] = format_mdy($data['disable_date']); $data['new_window'] = (bool) $data['new_window']; } $data['page_title'] = lang('banner_form'); $this->form_validation->set_rules('name', 'lang:name', 'trim|required|full_decode'); $this->form_validation->set_rules('enable_date', 'lang:enable_date', 'trim'); $this->form_validation->set_rules('disable_date', 'lang:disable_date', 'trim|callback_date_check'); $this->form_validation->set_rules('image', 'lang:image', 'trim'); $this->form_validation->set_rules('link', 'lang:link', 'trim'); $this->form_validation->set_rules('new_window', 'lang:new_window', 'trim'); if ($this->form_validation->run() == false) { $data['error'] = validation_errors(); $this->view(config_item('admin_folder') . '/banner_form', $data); } else { $uploaded = $this->upload->do_upload('image'); $save['banner_collection_id'] = $banner_collection_id; $save['name'] = $this->input->post('name'); $save['enable_date'] = format_ymd($this->input->post('enable_date')); $save['disable_date'] = format_ymd($this->input->post('disable_date')); $save['link'] = $this->input->post('link'); $save['new_window'] = $this->input->post('new_window'); if ($id) { $save['banner_id'] = $id; //delete the original file if another is uploaded if ($uploaded) { if ($data['image'] != '') { $file = 'uploads/' . $data['image']; //delete the existing file if needed if (file_exists($file)) { unlink($file); } } } } else { if (!$uploaded) { $data['error'] = $this->upload->display_errors(); $this->view(config_item('admin_folder') . '/banner_form', $data); return; //end script here if there is an error } } if ($uploaded) { $image = $this->upload->data(); $save['image'] = $image['file_name']; } $this->banner_model->save_banner($save); $this->session->set_flashdata('message', lang('message_banner_saved')); redirect(config_item('admin_folder') . '/banners/banner_collection/' . $banner_collection_id); } }
function form($id = false) { $config['upload_path'] = 'uploads'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = intval(ini_get('upload_max_filesize')) * 1024; //$this->config->item('size_limit'); $config['encrypt_name'] = true; $this->load->library('upload', $config); $this->load->helper('form'); $this->load->library('form_validation'); //set the default values $data = array('id' => $id, 'title' => '', 'enable_on' => '', 'disable_on' => '', 'image' => '', 'link' => '', 'new_window' => false); if ($id) { $data = (array) $this->banner_model->get_banner($id); $data['enable_on'] = format_mdy($data['enable_on']); $data['disable_on'] = format_mdy($data['disable_on']); $data['new_window'] = (bool) $data['new_window']; } //$data['page_title'] = lang('banner_form'); $this->template->set('title', 'Banners'); $this->form_validation->set_rules('title', 'Title', 'trim|required|full_decode'); $this->form_validation->set_rules('enable_on', 'Enable', 'trim'); $this->form_validation->set_rules('disable_on', 'Disable', 'trim|callback_date_check'); $this->form_validation->set_rules('image', 'Image', 'trim'); $this->form_validation->set_rules('link', 'Link', 'trim'); $this->form_validation->set_rules('new_window', 'Window', 'trim'); if ($this->form_validation->run() == false) { $data['errors'][] = validation_errors(); $this->template->load('templates/admin/brainlight', 'admin/banners/banner_form', $data); } else { $uploaded = $this->upload->do_upload('image'); $save['title'] = $this->input->post('title'); $save['enable_on'] = format_ymd($this->input->post('enable_on')); $save['disable_on'] = format_ymd($this->input->post('disable_on')); $save['link'] = $this->input->post('link'); $save['new_window'] = $this->input->post('new_window'); if ($id) { $save['id'] = $id; //delete the original file if another is uploaded if ($uploaded) { if ($data['image'] != '') { $file = 'uploads/' . $data['image']; //delete the existing file if needed if (file_exists($file)) { unlink($file); } } } } else { if (!$uploaded) { $data['error'] = $this->upload->display_errors(); $this->template->load('templates/admin/brainlight', 'admin/banner_form', $data); return; //end script here if there is an error } } if ($uploaded) { $image = $this->upload->data(); $save['image'] = $image['file_name']; } $this->banner_model->save_banner($save); $this->session->set_flashdata('message', lang('message_banner_saved')); redirect('admin/banners'); } }