Exemplo n.º 1
0
 public function edit($id, $id_campaign = null)
 {
     //$this->output->enable_profiler(true);
     $id = (int) $id;
     $this->load->model('Card');
     $this->form_validation->set_rules('num', 'Number', 'required|integer');
     $this->form_validation->set_rules('word_english', 'English', 'required');
     $this->form_validation->set_rules('word_french', 'French', 'required');
     $this->layout->add_basic_assets()->menu();
     if ($this->form_validation->run() === false) {
         $card = Card::find($id);
         $data = array('id' => $id, 'num' => $card->get_num(), 'word_english' => str_replace('<br />', "\n", $card->get_card_content()->get_word_english()), 'word_french' => str_replace('<br />', "\n", $card->get_card_content()->get_word_french()), 'is_active_english' => $card->get_card_content()->get_is_active_english(), 'is_active_french' => $card->get_card_content()->get_is_active_french(), 'id_campaign' => $id_campaign);
         $create_edit = $this->layout->views('controllers/Card/actions/create_edit', $data, array('css', 'js'), true);
         $this->layout->action_view(array('create_edit' => $create_edit));
     } else {
         $data = array('num' => (int) $this->input->post('num'), 'word_english' => $this->input->post('word_english'), 'word_french' => $this->input->post('word_french'), 'is_active_english' => $this->input->post('is_active_english'), 'is_active_french' => $this->input->post('is_active_french'));
         $result = Card::update($id, $data, $id_campaign);
         if ($result === true) {
             if ($id_campaign === null) {
                 $this->layout->view('others/form_success');
             } else {
                 $this->load->model('Campaign');
                 $campaign = Campaign::find($id_campaign);
                 $campaign->with_next_id_card();
                 if ($campaign->next_id_card === null) {
                     $this->layout->view('controllers/Campaign/actions/completed');
                 } else {
                     redirect('/Card/edit/' . $campaign->next_id_card . '/' . $id_campaign);
                 }
             }
         } elseif ($result instanceof Standard_error) {
             $this->layout->views('others/form_failure', array('message' => $result->message));
             $data = array('id' => $id, 'num' => $this->input->post('num'), 'word_english' => $this->input->post('word_english'), 'word_french' => $this->input->post('word_french'), 'is_active_english' => $this->input->post('is_active_english'), 'is_active_french' => $this->input->post('is_active_french'), 'id_campaign' => $id_campaign);
             $create_edit = $this->layout->views('controllers/Card/actions/create_edit', $data, array('css', 'js'), true);
             $this->layout->action_view(array('create_edit' => $create_edit));
         }
     }
 }