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