source: extensions/ContestResults/admin/new.php @ 9745

Last change on this file since 9745 was 9745, checked in by mistic100, 13 years ago

[extensions] Contest Results

  • New bloc for PWG Stuffs
  • Use new admin links and javascript implementation
  • Distinguish pending and running contests (both pending before)
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']) AND get_contest_name($_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// +-----------------------------------------------------------------------+   
76// Formulaire incomplet
77if ($page['errors']) {
78        $template->assign(array(
79                'NAME' => $_POST['name'],
80                'VISIBLE' => $_POST['visible'],
81                'DATE_BEGIN' => $_POST['date_begin'],
82                'DATE_END' => $_POST['date_end'],
83                'LOGO' => $_POST['logo'],
84                'BANNER' => $_POST['banner'],
85                'SUMMARY' => $_POST['summary'],
86        ));
87       
88        if (isset($_POST['description'])) {
89                $i=0;
90                foreach ($_POST['description'] as $data) {
91                        $template->append('description', array(
92                                        'NAME' => $data['name'],
93                                        'CONTENT' => $data['content'],
94                                        'RANK' => $i,
95                        ));
96                        $i++;
97                }
98        }
99
100// Edition d'un concours
101} else if (isset($_GET['contest_id']) AND get_contest_name($_GET['contest_id'])) {
102        $query = "SELECT * FROM " . CR_TABLE_1 . " WHERE id = " . $_GET['contest_id'] . ";";
103        $contest = pwg_db_fetch_assoc(pwg_query($query));
104               
105        $template->assign(array(
106                'ID' => $contest['id'],
107                'NAME' => $contest['name'],
108                'VISIBLE' => $contest['visible'],
109                'DATE_BEGIN' => $contest['date_begin'],
110                'DATE_END' => $contest['date_end'],
111                'LOGO' => $contest['logo'],
112                'BANNER' => $contest['banner'],
113                'SUMMARY' => $contest['summary'],
114        ));
115       
116        if (!empty($contest['description'])) {
117                $contest['description'] = unserialize(base64_decode($contest['description']));
118                $i=0;
119                foreach ($contest['description'] AS $desc) {
120                        $template->append('description', array(
121                                'NAME' => stripslashes($desc['name']),
122                                'CONTENT' => stripslashes($desc['content']),
123                                'RANK' => $i,
124                        ));
125                        $i++;
126                }
127        }
128
129// Ajout d'un concours
130} else {
131        $template->assign(array(
132                'NAME' => null,
133                'VISIBLE' => 1,
134                'DATE_BEGIN' => date('Y-m-d'),
135                'DATE_END' => date('Y-m-d', time()+2592000),
136                'LOGO' => null,
137                'BANNER' => null,
138                'SUMMARY' => null,
139        ));
140}
141
142// +-----------------------------------------------------------------------+
143//                              Template
144// +-----------------------------------------------------------------------+
145$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/template/new.tpl'));
146$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
147
148?>
Note: See TracBrowser for help on using the repository browser.