source: extensions/PWG_Stuffs/admin/add_module.php @ 9369

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

Plugins can add their own modules.

File size: 4.0 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 = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL';
33      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
34      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
35      $on_cats = isset($_POST['on_cats'])  ? '"true"' : '"false"';
36      $on_picture = isset($_POST['on_picture'])  ? '"true"' : '"false"';
37
38      $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
39
40      if (isset($_GET['edit']))
41      {     
42        pwg_query('
43UPDATE ' . STUFFS_TABLE . '
44SET name ="' . $module_name . '",
45    descr=' . $desc . ',
46    datas=' . $sav_datas . ',
47    users=' . $users . ',
48    groups=' . $groups . ',
49    show_title=' . $show_title .',
50    on_home=' . $on_home .',
51    on_cats=' . $on_cats . ',
52    on_picture='. $on_picture . '
53WHERE id = ' . $_GET['edit'] . ';');
54        if (isset($_GET['redirect']))
55        {
56          redirect(urldecode($_GET['redirect']));
57        }
58      }
59      else
60      {
61        $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . STUFFS_TABLE . ' ;';
62        list($next_element_id) = mysql_fetch_array(pwg_query($query));
63
64        $query = 'SELECT MAX(pos)+1 AS next_pos  FROM ' . STUFFS_TABLE . ' ;';
65        list($pos) = mysql_fetch_array(pwg_query($query));
66
67        $query = '
68INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, parent, datas, users, groups, show_title, on_home, on_cats, on_picture, id_line, width )
69VALUES (' . $next_element_id . ' ,
70  ' . $pos . ',
71  "' . $module_name . '",
72  ' . $desc . ',
73  "' . $module_path . '",
74  ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .',
75  ' . $sav_datas . ',
76  ' . $users . ',
77  ' . $groups . ',
78  ' . $show_title . ',
79  ' . $on_home . ',
80  ' . $on_cats . ',
81  ' . $on_picture . ',
82  NULL,
83  NULL);';
84        pwg_query($query);
85      }
86      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
87    }
88  }
89}
90
91// Default module data
92if ($page['tab'] == 'add_module')
93{
94  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
95  $module['groups'] = array();
96  $template->assign(array(
97    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
98    'MODULE_NAME' => $modules[$module_path]['name'],
99    'show_title_CHECKED' => 'checked="checked"',
100    'on_home_CHECKED' => 'checked="checked"'));
101}
102
103// Users perm
104$template->assign('user_perm', array(
105  'GUEST' => (in_array('guest', $module['users']) ? 'checked="checked"' : ''),
106  'GENERIC' => (in_array('generic', $module['users']) ? 'checked="checked"' : ''),
107  'NORMAL' => (in_array('normal', $module['users']) ? 'checked="checked"' : ''),
108  'ADMIN' => (in_array('admin', $module['users']) ? 'checked="checked"' : ''),
109  'WEBMASTER' => (in_array('webmaster', $module['users']) ? 'checked="checked"' : '')));
110
111// Groups perm
112$groups = get_all_groups();
113if (!empty($groups))
114{
115  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', $module['groups'])));
116}
117
118// Module configuration
119include_once($module_path.'config.inc.php');
120
121$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
122$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
123
124?>
Note: See TracBrowser for help on using the repository browser.