source: extensions/PWG_Stuffs/admin/add_module.php @ 7690

Last change on this file since 7690 was 7540, checked in by patdenice, 13 years ago

Main block can be hidden according to user status or user group.

File size: 5.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf;
6
7include_once(STUFFS_PATH . 'include/functions.inc.php');
8include_once(STUFFS_PATH . 'admin/functions.inc.php');
9load_language('plugin.lang', STUFFS_PATH);
10
11if (!isset($_GET['type']) or ($_GET['type'] != 'MainBlock' and !is_dir(STUFFS_PATH . 'modules/' . $_GET['type'])))
12{
13  die('Wrong parameters...');
14}
15else
16{
17  $type = $_GET['type'];
18}
19
20// Cas particulier des News
21if ($type == 'News') include(STUFFS_PATH . 'modules/News/config.inc.php');
22
23// Enregistrement du module
24if (isset($_POST['submit']) and !is_adviser())
25{
26  @include(STUFFS_PATH . 'modules/' . $type . '/config.inc.php');
27  if (empty($page['errors']))
28  {
29    if ($type == 'MainBlock')
30    {
31      $_POST['module_name'] = 'MainBlock';
32      $_POST['show_title'] = true;
33      $_POST['on_home'] = true;
34      $_POST['on_cats'] = true;
35      $_POST['on_picture'] = true;
36    }
37    if (empty($_POST['module_name']))
38    {
39      array_push($page['errors'], l10n('stuffs_no_name'));
40    }
41    else
42    {
43      $module_name = $_POST['module_name'];
44      $desc = (!empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL');
45      $groups = (!empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL');
46      $users = (!empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL');
47      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
48      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
49      $on_cats = isset($_POST['on_cats'])  ? '"true"' : '"false"';
50      $on_picture = isset($_POST['on_picture'])  ? '"true"' : '"false"';
51
52                        $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
53
54      if (isset($_GET['edit']))
55      {                 
56        pwg_query('
57UPDATE ' . STUFFS_TABLE . '
58SET name ="' . $module_name . '",
59                descr=' . $desc . ',
60                type="' . $type . '",
61                datas=' . $sav_datas . ',
62                users=' . $users . ',
63                groups=' . $groups . ',
64    show_title=' . $show_title .',
65    on_home=' . $on_home .',
66    on_cats=' . $on_cats . ',
67    on_picture='. $on_picture . '
68WHERE id = ' . $_GET['edit'] . ';');
69      }
70      else
71      {
72        $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . STUFFS_TABLE . ' ;';
73        list($next_element_id) = mysql_fetch_array(pwg_query($query));
74
75        $query = 'SELECT MAX(pos)+1 AS next_pos  FROM ' . STUFFS_TABLE . ' ;';
76        list($pos) = mysql_fetch_array(pwg_query($query));
77
78        $query = '
79INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, type, datas, users, groups, show_title, on_home, on_cats, on_picture, id_line, width )
80VALUES (' . $next_element_id . ' ,
81        ' . $pos . ',
82        "' . $module_name . '",
83        ' . $desc . ',
84        "' . $type . '",
85        ' . $sav_datas . ',
86        ' . $users . ',
87        ' . $groups . ',
88  ' . $show_title . ',
89  ' . $on_home . ',
90  ' . $on_cats . ',
91  ' . $on_picture . ',
92  NULL,
93  NULL);';
94        pwg_query($query);
95      }
96
97      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
98    }
99  }
100}
101
102// Récupération des données du module
103if (isset($_GET['edit']))
104{
105  $q = ('SELECT * FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['edit'] . ';');
106  $module = mysql_fetch_array(pwg_query($q));
107
108  $module['users'] = explode(',', $module['users']);
109  $module['groups'] = explode(',', $module['groups']);
110
111  $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
112
113  $template->assign(array(
114    'STUFFS_TITLE' => l10n('stuffs_edit_mod') . ' <i>' . trigger_event('render_stuffs_name', $module['name']) . '</i>',
115    'MODULE_ID' => $_GET['edit'],
116    'MODULE_NAME' => $module['name'],
117    'DESC_VALUE' => (isset($module['descr']) ? $module['descr'] : ''),
118    'show_title_CHECKED' => ($module['show_title'] == 'true' ? 'checked="checked"' : ''),
119    'on_home_CHECKED' => ($module['on_home'] == 'true' ? 'checked="checked"' : ''),
120    'on_cats_CHECKED' => ($module['on_cats'] == 'true' ? 'checked="checked"' : ''),
121    'on_picture_CHECKED' => ($module['on_picture'] == 'true' ? 'checked="checked"' : '')));
122}
123else
124{
125  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
126  $module['groups'] = array();
127  $template->assign(array(
128    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
129    'MODULE_NAME' => l10n('module_name_' . strtolower($type)),
130    'show_title_CHECKED' => 'checked="checked"',
131    'on_home_CHECKED' => 'checked="checked"'));
132}
133
134// Selection des utilisateurs
135$template->assign('user_perm', array(
136  'GUEST' => (in_array('guest', $module['users']) ? 'checked="checked"' : ''),
137  'GENERIC' => (in_array('generic', $module['users']) ? 'checked="checked"' : ''),
138  'NORMAL' => (in_array('normal', $module['users']) ? 'checked="checked"' : ''),
139  'ADMIN' => (in_array('admin', $module['users']) ? 'checked="checked"' : ''),
140  'WEBMASTER' => (in_array('webmaster', $module['users']) ? 'checked="checked"' : '')));
141
142// Selection des groupes
143$groups = get_all_groups();
144if (!empty($groups))
145{
146  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', $module['groups'])));
147}
148
149// Configuration du module
150@include_once(STUFFS_PATH . 'modules/' . $type . '/config.inc.php');
151
152$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
153$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
154
155?>
Note: See TracBrowser for help on using the repository browser.