View difference between Paste ID: zZjFCGap and 96LT86Pi
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
if (!defined('BASEPATH'))
4
    exit('No direct script access allowed');
5
6
class Admin extends CI_Controller {
7
    public function chapters($action="", $id="") {
8
        if (!$this->users->can_access(USERS_ADMIN)) {
9
            die($this->load->view("errors/users_cant_access", '', true));
10
        }
11
12
        $data = array(
13
            "title" => "Gestion des Chapitres",
14
            "output" => "",
15
        );
16
17
        if ($action == "add") {
18
		// Irelevant !
19
        } elseif ($action == "edit" && is_numeric($id)) {
20
            echo var_dump($_FILES); // Empty when I submit a .zip !
21
            echo var_dump($_POST); // Empty when I submit a .zip !
22
23
            $query = "SELECT *
24
                      FROM webcopedia_chapters
25
                      LEFT OUTER JOIN webcopedia_projects ON chapter_project = project_id
26
                      LEFT OUTER JOIN webcopedia_teams ON chapter_team = team_id
27
                      WHERE chapter_id = {$id}";
28
29
            $query = $this->db->query($query);
30
            if ($query->num_rows() == 1) {
31
32
                $data["chapter_data"] = $query->row_array();
33
                $data["title"] = "Edition de " . $data["chapter_data"]["project_name"];
34
35
                $this->form_validation->set_rules('chapter-edit-title', 'Titre', 'required');
36
                $this->form_validation->set_rules('chapter-edit-team', 'Team', 'required');
37
                $this->form_validation->set_rules('chapter-edit-project', 'Webcomic', 'required');
38
                $this->form_validation->set_rules('chapter-edit-sort', 'Numéro', 'required');
39
40
                if ($this->form_validation->run()) {
41
42
                    $update = array(
43
                        'chapter_title' => $this->input->post("chapter-edit-title"),
44
                        'chapter_sort' => $this->input->post("chapter-edit-sort"),
45
                        'chapter_team' => $this->input->post("chapter-edit-team"),
46
                        'chapter_project' => $this->input->post("chapter-edit-project"),
47
                    );
48
49
                    $this->db->where('chapter_id', $id);
50
                    $query = $this->db->update('webcopedia_chapters', $update);
51
52
                    if ($query) {
53
                        $data["output"] = "<div class='success'>Webcomic édité avec succés !</div>";
54
55
                        $config['upload_path'] = './uploads/temps';
56
                        $config['file_name'] = $id;
57
                        $config['overwrite'] = TRUE;
58
                        $this->load->library('upload', $config);
59
60
                        if (!$this->upload->do_upload("chapter-edit-files")) {
61
                            $data["output"] .= $this->upload->display_errors("<div class='error'>Chapitre : ", "</div>");
62
                        } else {
63
                            echo $data["chapter_data"]["chapter_project"] . "/" . $data["chapter_data"]["chapter_team"] . "/" . $data["chapter_data"]["chapter_sort"];
64
                        }
65
                    } else {
66
                        $data["output"] = "<div class='error'>Une erreur est survenue !</div>";
67
                    }
68
                } else {
69
                    echo var_dump($this->input->post());
70
                    echo var_dump($_POST);
71
                }
72
                $this->load->view('admin_chapter_edit', $data);
73
            } else {
74
                echo "Aucun résultat";
75
            }
76
        } else {
77
            // Irelevant !
78
        }
79
    }
80
81
}