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

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

Some optimizations.

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