source: extensions/PWG_Stuffs/admin/add_module.inc.php @ 9600

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

Module configuration is now optional.

File size: 4.9 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5if ($page['tab'] == 'add_module')
6{
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  }
15}
16
17// Save module
18if (isset($_POST['submit']) and !is_adviser())
19{
20  @include($module_path.'config.inc.php');
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'];
30      $desc = !empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL';
31      $groups = !empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL';
32      $users = 'NULL';
33      if ($conf['Stuffs']['user_perm'])
34      {
35        $users = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : '""';
36      }
37      $level = !empty($_POST['level']) ? $_POST['level'] : 0;
38      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
39      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
40      $on_root = isset($_POST['on_root'])  ? '"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('
49UPDATE ' . STUFFS_TABLE . '
50SET name ="' . $module_name . '",
51    descr=' . $desc . ',
52    datas=' . $sav_datas . ',
53    users=' . $users . ',
54    groups=' . $groups . ',
55    level=' . $level . ',
56    show_title=' . $show_title .',
57    on_home=' . $on_home .',
58    on_root=' . $on_root .',
59    on_cats=' . $on_cats . ',
60    on_picture='. $on_picture . '
61WHERE id = ' . $_GET['edit'] . ';');
62        if (isset($_GET['redirect']))
63        {
64          redirect(urldecode($_GET['redirect']));
65        }
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 = '
76INSERT 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 )
77VALUES (' . $next_element_id . ' ,
78  ' . $pos . ',
79  "' . $module_name . '",
80  ' . $desc . ',
81  "' . $module_path . '",
82  ' . $sav_datas . ',
83  ' . $users . ',
84  ' . $groups . ',
85  ' . $level . ',
86  ' . $show_title . ',
87  ' . $on_home . ',
88  ' . $on_root . ',
89  ' . $on_cats . ',
90  ' . $on_picture . ',
91  NULL,
92  NULL);';
93        pwg_query($query);
94      }
95      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
96    }
97  }
98}
99
100// Default module data
101if ($page['tab'] == 'add_module')
102{
103  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
104  $module['groups'] = array();
105
106  $template->assign(array(
107    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
108    'MODULE_NAME' => $modules[$module_path]['name'],
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  );
120}
121
122// Users perm
123if ($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}
137
138// Groups perm
139if ($conf['Stuffs']['group_perm'])
140{
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  );
153}
154
155// Level perm
156if ($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
178// Module configuration
179@include_once($module_path.'config.inc.php');
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
184?>
Note: See TracBrowser for help on using the repository browser.