[3609] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
[9369] | 5 | if ($page['tab'] == 'add_module') |
---|
[3609] | 6 | { |
---|
[9369] | 7 | if (!isset($_GET['path']) or !isset($modules[$_GET['path']])) |
---|
| 8 | { |
---|
| 9 | die('Wrong module path.'); |
---|
| 10 | } |
---|
| 11 | else |
---|
| 12 | { |
---|
| 13 | $module_path = $_GET['path']; |
---|
| 14 | } |
---|
[3609] | 15 | } |
---|
| 16 | |
---|
[9369] | 17 | // Save module |
---|
[3609] | 18 | if (isset($_POST['submit']) and !is_adviser()) |
---|
| 19 | { |
---|
[9369] | 20 | include($module_path.'config.inc.php'); |
---|
[3609] | 21 | if (empty($page['errors'])) |
---|
| 22 | { |
---|
| 23 | if (empty($_POST['module_name'])) |
---|
| 24 | { |
---|
| 25 | array_push($page['errors'], l10n('stuffs_no_name')); |
---|
| 26 | } |
---|
| 27 | else |
---|
| 28 | { |
---|
| 29 | $module_name = $_POST['module_name']; |
---|
[9369] | 30 | $desc = !empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL'; |
---|
| 31 | $groups = !empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL'; |
---|
[9383] | 32 | $users = 'NULL'; |
---|
| 33 | if ($conf['Stuffs']['user_perm']) |
---|
| 34 | { |
---|
| 35 | $users = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : '""'; |
---|
| 36 | } |
---|
[3609] | 37 | $show_title = isset($_POST['show_title']) ? '"true"' : '"false"'; |
---|
| 38 | $on_home = isset($_POST['on_home']) ? '"true"' : '"false"'; |
---|
[9383] | 39 | $on_root = isset($_POST['on_root']) ? '"true"' : '"false"'; |
---|
[3609] | 40 | $on_cats = isset($_POST['on_cats']) ? '"true"' : '"false"'; |
---|
| 41 | $on_picture = isset($_POST['on_picture']) ? '"true"' : '"false"'; |
---|
| 42 | |
---|
[9369] | 43 | $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL'); |
---|
[3609] | 44 | |
---|
| 45 | if (isset($_GET['edit'])) |
---|
[9369] | 46 | { |
---|
[3609] | 47 | pwg_query(' |
---|
| 48 | UPDATE ' . STUFFS_TABLE . ' |
---|
| 49 | SET name ="' . $module_name . '", |
---|
[9369] | 50 | descr=' . $desc . ', |
---|
| 51 | datas=' . $sav_datas . ', |
---|
| 52 | users=' . $users . ', |
---|
| 53 | groups=' . $groups . ', |
---|
[3609] | 54 | show_title=' . $show_title .', |
---|
| 55 | on_home=' . $on_home .', |
---|
[9383] | 56 | on_root=' . $on_root .', |
---|
[3609] | 57 | on_cats=' . $on_cats . ', |
---|
| 58 | on_picture='. $on_picture . ' |
---|
| 59 | WHERE id = ' . $_GET['edit'] . ';'); |
---|
[9369] | 60 | if (isset($_GET['redirect'])) |
---|
| 61 | { |
---|
| 62 | redirect(urldecode($_GET['redirect'])); |
---|
| 63 | } |
---|
[3609] | 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . STUFFS_TABLE . ' ;'; |
---|
| 68 | list($next_element_id) = mysql_fetch_array(pwg_query($query)); |
---|
| 69 | |
---|
| 70 | $query = 'SELECT MAX(pos)+1 AS next_pos FROM ' . STUFFS_TABLE . ' ;'; |
---|
| 71 | list($pos) = mysql_fetch_array(pwg_query($query)); |
---|
| 72 | |
---|
| 73 | $query = ' |
---|
[9383] | 74 | INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, parent, datas, users, groups, show_title, on_home, on_root, on_cats, on_picture, id_line, width ) |
---|
[3609] | 75 | VALUES (' . $next_element_id . ' , |
---|
[9369] | 76 | ' . $pos . ', |
---|
| 77 | "' . $module_name . '", |
---|
| 78 | ' . $desc . ', |
---|
| 79 | "' . $module_path . '", |
---|
| 80 | ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .', |
---|
| 81 | ' . $sav_datas . ', |
---|
| 82 | ' . $users . ', |
---|
| 83 | ' . $groups . ', |
---|
[3609] | 84 | ' . $show_title . ', |
---|
| 85 | ' . $on_home . ', |
---|
[9383] | 86 | ' . $on_root . ', |
---|
[3609] | 87 | ' . $on_cats . ', |
---|
| 88 | ' . $on_picture . ', |
---|
| 89 | NULL, |
---|
| 90 | NULL);'; |
---|
| 91 | pwg_query($query); |
---|
| 92 | } |
---|
| 93 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[9369] | 98 | // Default module data |
---|
| 99 | if ($page['tab'] == 'add_module') |
---|
[3609] | 100 | { |
---|
| 101 | $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster'); |
---|
| 102 | $module['groups'] = array(); |
---|
[9383] | 103 | |
---|
[3609] | 104 | $template->assign(array( |
---|
| 105 | 'STUFFS_TITLE' => l10n('stuffs_add_mod'), |
---|
[9369] | 106 | 'MODULE_NAME' => $modules[$module_path]['name'], |
---|
[9383] | 107 | 'show_title_CHECKED' => true, |
---|
| 108 | ) |
---|
| 109 | ); |
---|
| 110 | |
---|
| 111 | $template->assign('selected_options', array( |
---|
| 112 | 'on_home' => true, |
---|
| 113 | 'on_root' => true, |
---|
| 114 | 'on_cats' => false, |
---|
| 115 | 'on_picture' => false, |
---|
| 116 | ) |
---|
| 117 | ); |
---|
[3609] | 118 | } |
---|
| 119 | |
---|
[9369] | 120 | // Users perm |
---|
[9383] | 121 | if ($conf['Stuffs']['user_perm']) |
---|
| 122 | { |
---|
| 123 | $users_id = array('guest', 'generic', 'normal', 'admin', 'webmaster'); |
---|
| 124 | $users = array(); |
---|
| 125 | foreach ($users_id as $id) |
---|
| 126 | { |
---|
| 127 | $users[$id] = l10n('user_status_'.$id); |
---|
| 128 | } |
---|
| 129 | $template->assign(array( |
---|
| 130 | 'users' => $users, |
---|
| 131 | 'selected_users' => isset($module['users']) ? $module['users'] : $users_id, |
---|
| 132 | ) |
---|
| 133 | ); |
---|
| 134 | } |
---|
[3609] | 135 | |
---|
[9369] | 136 | // Groups perm |
---|
[9383] | 137 | if ($conf['Stuffs']['group_perm']) |
---|
[3609] | 138 | { |
---|
[9383] | 139 | $query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;'; |
---|
| 140 | $result = pwg_query($query); |
---|
| 141 | $groups = array(); |
---|
| 142 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 143 | { |
---|
| 144 | $groups[$row['id']] = $row['name']; |
---|
| 145 | } |
---|
| 146 | $template->assign(array( |
---|
| 147 | 'groups' => $groups, |
---|
| 148 | 'selected_groups' => isset($module['groups']) ? $module['groups'] : array(), |
---|
| 149 | ) |
---|
| 150 | ); |
---|
[3609] | 151 | } |
---|
| 152 | |
---|
[9383] | 153 | // Level perm |
---|
| 154 | if ($conf['Stuffs']['level_perm']) |
---|
| 155 | { |
---|
| 156 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 157 | { |
---|
| 158 | $level_options[$level] = l10n(sprintf('Level %d', $level)); |
---|
| 159 | } |
---|
| 160 | $template->assign(array( |
---|
| 161 | 'level_perm' => $level_options, |
---|
| 162 | 'level_selected' => isset($module['level']) ? $module['level'] : 0, |
---|
| 163 | ) |
---|
| 164 | ); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | // Display options |
---|
| 168 | $template->assign('display_options', array( |
---|
| 169 | 'on_home' => true, |
---|
| 170 | 'on_root' => true, |
---|
| 171 | 'on_cats' => true, |
---|
| 172 | 'on_picture' => true, |
---|
| 173 | ) |
---|
| 174 | ); |
---|
| 175 | |
---|
[9369] | 176 | // Module configuration |
---|
| 177 | include_once($module_path.'config.inc.php'); |
---|
[3609] | 178 | |
---|
| 179 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl')); |
---|
| 180 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 181 | |
---|
[3300] | 182 | ?> |
---|