Ejemplo n.º 1
0
 function add_new($stub = "")
 {
     $this->viewdata["function_title"] = '<a href="#">' . _("Add New") . '</a>';
     //$stub stands for $comic, but there's already a $comic here
     if ($stub != "") {
         if ($this->input->post()) {
             $chapter = new Chapter();
             if ($chapter->add($this->input->post())) {
                 $subchapter = is_int($chapter->subchapter) ? $chapter->subchapter : 0;
                 flash_notice('notice', sprintf(_('Chapter %s has been added to %s.'), $chapter->chapter . '.' . $subchapter, $chapter->comic->name));
                 redirect('/admin/series/series/' . $chapter->comic->stub . '/' . $chapter->id);
             }
         }
         $comic = new Comic();
         $comic->where('stub', $stub)->get();
         $this->viewdata["extra_title"][] = _("Chapter in") . ' ' . $comic->name;
         $chapter = new Chapter();
         $chapter->comic_id = $comic->id;
         $table = ormer($chapter);
         $table[] = array(_('Teams'), array('name' => 'team', 'type' => 'input', 'value' => array('value' => get_setting('fs_gen_default_team')), 'help' => _('Insert the names of the teams who worked on this chapter.')));
         $table = tabler($table, FALSE, TRUE);
         $data["form_title"] = _('Add New Chapter');
         $data["table"] = $table;
         $this->viewdata["main_content_view"] = $this->load->view("admin/form.php", $data, TRUE);
         $this->load->view("admin/default.php", $this->viewdata);
         return true;
     } else {
         $comic = new Comic();
         if ($this->input->post()) {
             if ($comic->add($this->input->post())) {
                 $config['upload_path'] = 'content/cache/';
                 $config['allowed_types'] = 'jpg|png|gif';
                 $this->load->library('upload', $config);
                 $field_name = "thumbnail";
                 if (count($_FILES) > 0 && $this->upload->do_upload($field_name)) {
                     $up_data = $this->upload->data();
                     if (!$this->files_model->comic_thumb($comic, $up_data)) {
                         log_message("error", "Controller: series.php/add_new: image failed being added to folder");
                     }
                     if (!unlink($up_data["full_path"])) {
                         log_message('error', 'series.php/add_new: couldn\'t remove cache file ' . $data["full_path"]);
                         return false;
                     }
                 }
                 flash_notice('notice', sprintf(_('The series %s has been added.'), $comic->name));
                 redirect('/admin/series/series/' . $comic->stub);
             }
         }
         $table = ormer($comic);
         $table[] = array(_('Licensed in'), array('name' => 'licensed', 'type' => 'nation', 'value' => array(), 'help' => _('Insert the nations where the series is licensed in order to limit the availability.')));
         $table = tabler($table, FALSE, TRUE);
         $data["form_title"] = _('Add New') . ' ' . _('Series');
         $data['table'] = $table;
         $this->viewdata["extra_title"][] = _("Series");
         $this->viewdata["main_content_view"] = $this->load->view("admin/form.php", $data, TRUE);
         $this->load->view("admin/default.php", $this->viewdata);
     }
 }