public function edit()
{
$banner_info = $this->Banners_model->getBanner((int) $this->input->get('id'));
if (!empty($banner_info)) {
$banner_id = $banner_info['banner_id'];
$data['_action'] = site_url('banners/edit?id=' . $banner_id);
} else {
$banner_id = 0;
$data['_action'] = site_url('banners/edit');
}
$title = isset($banner_info['name']) ? $banner_info['name'] : $this->lang->line('text_new');
$this->template->setTitle(sprintf($this->lang->line('text_edit_heading'), $title));
$this->template->setHeading(sprintf($this->lang->line('text_edit_heading'), $title));
$this->template->setButton($this->lang->line('button_save'), array('class' => 'btn btn-primary', 'onclick' => '$(\'#edit-form\').submit();'));
$this->template->setButton($this->lang->line('button_save_close'), array('class' => 'btn btn-default', 'onclick' => 'saveClose();'));
$this->template->setButton($this->lang->line('button_modules'), array('class' => 'btn btn-default', 'href' => site_url('extensions')));
$this->template->setButton($this->lang->line('button_icon_back'), array('class' => 'btn btn-default', 'href' => site_url('banners')));
if ($this->input->post() and $banner_id = $this->_saveBanner()) {
if ($this->input->post('save_close') === '1') {
redirect('banners');
}
redirect('banners/edit?id=' . $banner_id);
}
$data['banner_id'] = $banner_info['banner_id'];
$data['name'] = $banner_info['name'];
$data['type'] = $this->input->post('type') ? $this->input->post('type') : $banner_info['type'];
$data['click_url'] = $banner_info['click_url'];
$data['language_id'] = $banner_info['language_id'];
$data['alt_text'] = $banner_info['alt_text'];
$data['custom_code'] = $banner_info['custom_code'];
$data['status'] = $banner_info['status'];
$data['no_photo'] = $this->Image_tool_model->resize('data/no_photo.png');
$data['type'] = !empty($data['type']) ? $data['type'] : 'image';
$data['image'] = array('name' => 'no_photo.png', 'path' => 'data/no_photo.png', 'url' => $data['no_photo']);
$data['carousels'] = array();
if (!empty($banner_info['image_code'])) {
$image = unserialize($banner_info['image_code']);
if ($banner_info['type'] === 'image') {
if (!empty($image['path'])) {
$name = basename($image['path']);
$data['image'] = array('name' => $name, 'path' => $image['path'], 'url' => $this->Image_tool_model->resize($image['path'], 120, 120));
}
} else {
if ($banner_info['type'] === 'carousel') {
if (!empty($image['paths']) and is_array($image['paths'])) {
foreach ($image['paths'] as $path) {
$name = basename($path);
$data['carousels'][] = array('name' => $name, 'path' => $path, 'url' => $this->Image_tool_model->resize($path, 120, 120));
}
}
}
}
}
$data['types'] = array('image' => 'Image', 'carousel' => 'Carousel', 'custom' => 'Custom');
$this->load->model('Languages_model');
$data['languages'] = array();
$results = $this->Languages_model->getLanguages();
foreach ($results as $result) {
$data['languages'][] = array('language_id' => $result['language_id'], 'name' => $result['name']);
}
$this->template->render('banners_edit', $data);
}