source: extensions/ContestResults/admin/new.php

Last change on this file was 9975, checked in by mistic100, 13 years ago
  • many corrections
File size: 4.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// +-----------------------------------------------------------------------+
5//                              Ajout ou modification d'un concours
6// +-----------------------------------------------------------------------+
7if (isset($_POST['new_submit'])) {
8        if ($_POST['name'] != null) {
9                // Mise en forme des descriptions
10                if (isset($_POST['description'])) {                             
11                        for ($i=0; $i<=count($_POST['description']); $i++) {
12                                unset($_POST['description'][$i]['rank']);
13                        }
14                        // encoder le tableau sérialisé est le seul moyen que j'ai trouvé pour pas perdre les caractères spéciaux et planter unserialize
15                        $_POST['description'] = base64_encode(serialize($_POST['description']));
16                } else {
17                        $_POST['description'] = null;
18                }
19                       
20                // Modification d'un concours
21                if (isset($_GET['contest_id'])) {       
22                        pwg_query("UPDATE " . CR_TABLE_1 . " SET
23                                `name` = '" . $_POST['name'] ."',
24                                `visible` = '" . $_POST['visible'] ."',
25                                `date_begin` = '" . $_POST['date_begin'] ."',
26                                `date_end` = '" . $_POST['date_end'] ."',
27                                `logo` = '" . $_POST['logo'] ."',
28                                `banner` = '" . $_POST['banner'] ."',
29                                `summary` = '" . $_POST['summary'] ."',
30                                `description` = '" . $_POST['description'] ."'
31                        WHERE `id` = " . $_GET['contest_id'] .";");
32                       
33                        // redirige vers la page du concours si on en viens
34                        if (isset($_GET['redirect']) AND $_GET['redirect'] == 'page') {
35                                redirect(CR_PUBLIC . $_GET['contest_id'] . '-' . str2url(trigger_event('render_CR_content', $_POST['name'])));
36                        } else {
37                                redirect(CR_ADMIN .'-manage&amp;msg=infos.contest_saved');
38                        }
39                       
40                // Ajout d'un concours
41                } else {
42                        pwg_query("INSERT INTO " . CR_TABLE_1 . "
43                                (
44                                        name,
45                                        date_begin,
46                                        date_end,
47                                        visible,
48                                        logo,
49                                        banner,
50                                        summary,
51                                        description
52                                )
53                                VALUES(
54                                        '" . $_POST['name'] ."',
55                                        '" . $_POST['date_begin'] ."',
56                                        '" . $_POST['date_end'] ."',
57                                        '" . $_POST['visible'] ."',
58                                        '" . $_POST['logo'] ."',
59                                        '" . $_POST['banner'] ."',
60                                        '" . $_POST['summary'] ."',
61                                        '" . $_POST['description'] ."'
62                                );");
63                       
64                        redirect(CR_ADMIN .'-manage&amp;msg=infos.contest_added');
65                }
66               
67        } else {
68                $page['errors'][] = l10n('CR_name_empty');
69        }
70}
71
72
73// +-----------------------------------------------------------------------+
74//                              Définition des variables template
75// +-----------------------------------------------------------------------+   
76if (isset($_GET['contest_id']) AND !get_contest_name($_GET['contest_id'])) {
77        redirect(CR_ADMIN .'-new');
78}
79
80// Formulaire incomplet
81if ($page['errors']) {
82        $template->assign(array(
83                'NAME' => $_POST['name'],
84                'VISIBLE' => $_POST['visible'],
85                'DATE_BEGIN' => $_POST['date_begin'],
86                'DATE_END' => $_POST['date_end'],
87                'LOGO' => $_POST['logo'],
88                'BANNER' => $_POST['banner'],
89                'SUMMARY' => $_POST['summary'],
90        ));
91       
92        if (isset($_POST['description'])) {
93                $i=0;
94                foreach ($_POST['description'] as $data) {
95                        $template->append('description', array(
96                                        'NAME' => $data['name'],
97                                        'CONTENT' => $data['content'],
98                                        'RANK' => $i,
99                        ));
100                        $i++;
101                }
102        }
103
104// Edition d'un concours
105} else if (isset($_GET['contest_id'])) {
106        $query = "SELECT * FROM " . CR_TABLE_1 . " WHERE id = " . $_GET['contest_id'] . ";";
107        $contest = pwg_db_fetch_assoc(pwg_query($query));
108               
109        $template->assign(array(
110                'ID' => $contest['id'],
111                'NAME' => $contest['name'],
112                'VISIBLE' => $contest['visible'],
113                'DATE_BEGIN' => $contest['date_begin'],
114                'DATE_END' => $contest['date_end'],
115                'LOGO' => $contest['logo'],
116                'BANNER' => $contest['banner'],
117                'SUMMARY' => $contest['summary'],
118        ));
119       
120        if (!empty($contest['description'])) {
121                $contest['description'] = unserialize(base64_decode($contest['description']));
122                $i=0;
123                foreach ($contest['description'] AS $desc) {
124                        $template->append('description', array(
125                                'NAME' => stripslashes($desc['name']),
126                                'CONTENT' => stripslashes($desc['content']),
127                                'RANK' => $i,
128                        ));
129                        $i++;
130                }
131        }
132
133// Ajout d'un concours
134} else {
135        $template->assign(array(
136                'NAME' => null,
137                'VISIBLE' => 1,
138                'DATE_BEGIN' => date('Y-m-d'),
139                'DATE_END' => date('Y-m-d', time()+2592000),
140                'LOGO' => null,
141                'BANNER' => null,
142                'SUMMARY' => null,
143        ));
144}
145
146// +-----------------------------------------------------------------------+
147//                              Template
148// +-----------------------------------------------------------------------+
149$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/template/new.tpl'));
150$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
151
152?>
Note: See TracBrowser for help on using the repository browser.