source: extensions/Flash_Gallery/admin/add_module.php @ 10758

Last change on this file since 10758 was 10758, checked in by Gotcha, 13 years ago

First revision for compatiblity with Piwigo v2.2
Not work !

File size: 9.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf;
6
7include_once(FLASHGAL_PATH . 'include/functions.inc.php');
8include_once(FLASHGAL_PATH . 'admin/functions.inc.php');
9
10load_language('plugin.lang', FLASHGAL_PATH);
11
12
13if (!isset($_GET['type']) or !is_dir(FLASHGAL_PATH . 'modules/' . $_GET['type']))
14{
15  die('Wrong parameters...');
16}
17else
18{
19  $type = $_GET['type'];
20}
21
22// Load module language
23get_flash_modules_language($type);
24
25include_once(FLASHGAL_PATH . 'modules/' . $type . '/module.inc.php');
26
27// restauration des parametres par defaut
28if (isset($_POST['restoredata']) and !is_adviser())
29{
30  $datas = array();
31        foreach ($module_data['datas'] as $key => $value)
32        {
33                if ($value)     // == true
34                        $datas[$key] = $value;
35        }
36        $datas =  (!empty($datas) ? '"'.addslashes(serialize($datas)).'"' : NULL);
37       
38        pwg_query('
39        UPDATE ' . FLASHGAL_TABLE . '
40        SET datas=' . $datas . '
41                WHERE id = ' . $_GET['edit'] . ';');
42
43    // Force le submit pour sauvegarder les données éventuellement modifiées lors du RAZ des paramètres. Pas de redirection dans ce cas
44    $_POST['submit'] = 'no_redirect';
45}
46
47
48
49// Enregistrement du module
50if (isset($_POST['submit']) and !is_adviser())
51{
52  include(FLASHGAL_PATH . 'modules/' . $type . '/admin/config.inc.php');
53  if (empty($page['errors']))
54  {
55    if (empty($_POST['module_name']))
56    {
57      array_push($page['errors'], l10n('flashgal_no_name'));
58    }
59    else
60    {
61      $module_name = $_POST['module_name'];
62      $desc = (!empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL');
63      $groups = (!empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL');
64      $users = (!empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL');
65      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
66      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
67          $on_home_global = $_POST['on_home_global'];
68      $on_cats = isset($_POST['on_cats'])  ? '"true"' : '"false"';
69        // Selected categories
70          $select_cats = isset($_POST['categories']) ? 
71                     array_map("mysql_escape_string", $_POST['categories']) :
72                     array(); 
73          $transparent = isset($_POST['flashgal_transparent']) ? '"true"' : '"false"';
74          $fullscreen = isset($_POST['flashgal_fullscreen']) ? '"true"' : '"false"';
75          $bgcolor = $_POST['flashgal_bgcolor'];
76          $recurs_cats = isset($_POST['flashgal_recurs_cats'])  ? '"true"' : '"false"';
77      $replace_thumb = isset($_POST['replace_thumb'])  ? '"true"' : '"false"';
78      $replace_cats = isset($_POST['replace_cats'])  ? '"true"' : '"false"';
79       
80          $height = (!empty($_POST['flashgal_height']) ? '"'.$_POST['flashgal_height'].'"' : "NULL");
81      $maxcomment = (!empty($_POST['flashgal_max_comment']) ? '"'.$_POST['flashgal_max_comment'].'"' : "0");;
82         
83          $sav_ext_datas = (!empty($ext_datas) ? '"' . addslashes(serialize($ext_datas)) . '"' : 'NULL');
84       
85        // Module parameters
86        include_once(FLASHGAL_PATH . 'modules/' . $type . '/module.inc.php');
87        foreach ($module_data['datas'] as $key => $value)
88        {
89                if ($value)     // == true
90                        $sav_datas[$key] = $_POST[$key];               
91        }
92       
93        $sav_datas =  (!empty($sav_datas) ? '"'.addslashes(serialize($sav_datas)).'"' : NULL);
94
95        $cats =  addslashes(serialize($select_cats));
96       
97        if (isset($_GET['edit']))
98      {         
99         
100        pwg_query('
101                UPDATE ' . FLASHGAL_TABLE . '
102                SET     name ="' . $module_name . '",
103                                descr=' . $desc . ',
104                                type="' . $type . '",
105                                datas=' . $sav_datas . ',
106                                ext_datas=' . $sav_ext_datas . ',
107                                users=' . $users . ',
108                                groups=' . $groups . ',
109                                show_title=' . $show_title .',
110                                on_home=' . $on_home .',
111                                on_home_global="' . $on_home_global .'",
112                                on_cats=' . $on_cats . ',
113                                cats="' . $cats . '",
114                                recurs_cats=' . $recurs_cats . ',
115                                replace_thumb=' . $replace_thumb . ',
116                                replace_cats=' . $replace_cats .',
117                                height=' . $height . ',
118                                transparent=' . $transparent .',
119                                fullscreen=' . $fullscreen .',
120                                bgcolor="' . $bgcolor .'",
121                maxcomment=' . $maxcomment . '
122
123                        WHERE id = ' . $_GET['edit'] . ';');
124      }
125      else
126      {
127        $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . FLASHGAL_TABLE . ' ;';
128        list($next_element_id) = mysql_fetch_array(pwg_query($query));
129
130        $query = 'SELECT MAX(pos)+1 AS next_pos  FROM ' . FLASHGAL_TABLE . ' ;';
131        list($pos) = mysql_fetch_array(pwg_query($query));
132                if (!isset($pos))       $pos = 1;
133               
134        $query = '
135INSERT INTO ' . FLASHGAL_TABLE . ' ( id, pos, name, descr, type, datas, ext_datas, users, groups, show_title, on_home, on_home_global, on_cats, cats, recurs_cats, replace_thumb, replace_cats, height, transparent, fullscreen, bgcolor, maxcomment)
136VALUES (' . $next_element_id . ' ,
137        ' . $pos . ',
138        "' . $module_name . '",
139        ' . $desc . ',
140        "' . $type . '",
141        ' . $sav_datas . ',
142        ' . $sav_ext_datas . ',
143        ' . $users . ',
144        ' . $groups . ',
145        ' . $show_title . ',
146        ' . $on_home . ',
147        "' . $on_home_global . '",
148        ' . $on_cats . ',
149        "' . $cats . '",
150        ' . $recurs_cats . ',
151        ' . $replace_thumb . ',
152        ' . $replace_cats .',
153        ' . $height . ',
154        ' . $transparent .',
155        ' . $fullscreen .',
156        "' . $bgcolor .'",
157    ' . $maxcomment . '
158  );';
159 
160       
161 
162        pwg_query($query);
163      }
164
165      if ($_POST['submit'] != 'no_redirect')
166        redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . FLASHGAL_DIR . '%2Fadmin%2Fadmin.php');
167    }
168  }
169}
170
171// Récupération des données du module
172if (isset($_GET['edit']))
173{
174  $q = ('SELECT * FROM ' . FLASHGAL_TABLE . ' WHERE id = ' . $_GET['edit'] . ';');
175  $module = mysql_fetch_array(pwg_query($q));
176
177  $module['users'] = explode(',', $module['users']);
178  $module['groups'] = explode(',', $module['groups']);
179
180  $cats = (!empty($module['cats']) ? unserialize($module['cats']) : false);
181  $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
182  $ext_datas = (!empty($module['ext_datas']) ? unserialize($module['ext_datas']) : false);
183
184  $template->assign(array(
185    'FLASHGAL_TITLE' => l10n('flashgal_edit_mod') . ' <i>' . trigger_event('render_flashgal_name', $module['name']) . '</i>',
186    'MODULE_NAME' => $module['name'],
187    'DESC_VALUE' => (isset($module['descr']) ? $module['descr'] : ''),
188    'show_title_CHECKED' => ($module['show_title'] == 'true' ? 'checked="checked"' : ''),
189    'on_home_CHECKED' => ($module['on_home'] == 'true' ? 'checked="checked"' : ''),
190    $module['on_home_global'].'_CHECKED' =>  'checked="checked"',
191    'on_cats_CHECKED' => ($module['on_cats'] == 'true' ? 'checked="checked"' : ''),
192    'FLASHGAL_HEIGHT' => (isset($module['height']) ? $module['height'] : ''),
193    'FLASHGAL_TRANSPARENT' => ($module['transparent'] == 'true' ? 'checked="checked"' : ''),
194    'FLASHGAL_FULLSCREEN' => ($module['fullscreen'] == 'true' ? 'checked="checked"' : ''),
195        'FLASHGAL_BGCOLOR' => $module['bgcolor'],       
196    'FLASHGAL_RECURS_CATS' => ($module['recurs_cats'] == 'true' ? 'checked="checked"' : ''),
197    'replace_thumb_CHECKED' => ($module['replace_thumb'] == 'true' ? 'checked="checked"' : ''),
198    'replace_cats_CHECKED' => ($module['replace_cats'] == 'true' ? 'checked="checked"' : ''),
199        'ENABLERESTORE' => true,
200    'FLASHGAL_MAX_COMMENT'  => (isset($module['maxcomment']) ? $module['maxcomment'] : '0')
201       
202        ));
203}
204else
205{
206  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
207  $module['groups'] = array();
208  $datas = array();
209        foreach ($module_data['datas'] as $key => $value)
210        {
211                if ($value)     // == true
212                        $datas[$key] = $value;
213        }
214  $template->assign(array(
215    'FLASHGAL_TITLE' => l10n('flashgal_add_mod'),
216    'MODULE_NAME' => l10n('module_name_' . $type),
217    'show_title_CHECKED' => 'checked="checked"',
218    'global_CHECKED' => 'checked="checked"',
219    'on_cats_CHECKED' => 'checked="checked"',
220    'FLASHGAL_HEIGHT' => '400',
221    'FLASHGAL_TRANSPARENT' => 'checked="checked"',
222    'FLASHGAL_FULLSCREEN' =>  'checked="checked"',
223        'FLASHGAL_BGCOLOR' => '#FFFFFF',       
224        'ENABLERESTORE' => false,
225        'FLASHGAL_MAX_COMMENT'  => '0'
226       
227        ));
228}
229
230// Selection des utilisateurs
231$template->assign('user_perm', array(
232  'GUEST' => (in_array('guest', $module['users']) ? 'checked="checked"' : ''),
233  'GENERIC' => (in_array('generic', $module['users']) ? 'checked="checked"' : ''),
234  'NORMAL' => (in_array('normal', $module['users']) ? 'checked="checked"' : ''),
235  'ADMIN' => (in_array('admin', $module['users']) ? 'checked="checked"' : ''),
236  'WEBMASTER' => (in_array('webmaster', $module['users']) ? 'checked="checked"' : '')));
237
238// Selection des groupes
239$groups = get_all_groups();
240if (!empty($groups))
241{
242  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', $module['groups'])));
243}
244
245
246// Recuperation des données pour les informations a parametrer dans le flux
247        foreach ($module_data['datas'] as $key => $value)
248        {
249                if ($value)     // == true
250                {
251                        $template->append( 'FlashGal_Param', array(
252                                        'name'  => $key,                                                // nom du parametre
253                                        'lib'           => l10n($key),          // libelle du parametre
254                                        'val'   => $datas[$key]                                 //  valeur du parametre
255                                ));
256                }
257               
258        }
259
260        // Affichage des categories
261        $query = '
262          SELECT id,name,uppercats,global_rank
263          FROM '.CATEGORIES_TABLE.';';
264
265
266        display_select_cat_wrapper($query,
267            (isset($module['cats']) ? unserialize($module['cats']) : ''),
268            'categories',
269            true);
270
271
272// Configuration supplémentaire du module (dans le cas ou il y a d'autres parametres)
273include_once(FLASHGAL_PATH . 'modules/' . $type . '/admin/config.inc.php');
274
275$template->assign(array('OTHERS_SCRIPT' =>
276                        '{combine_css path="'.FLASHGAL_PATH.'/farbtastic/farbtastic.css"}
277                         {combine_script id='jquery.farbtastic' require='jquery' path="'.FLASHGAL_PATH.'/farbtastic/farbtastic.js"}'));
278
279
280$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
281$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
282
283?>
Note: See TracBrowser for help on using the repository browser.