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