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

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

[extensions] ContestResults 1.3

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