Index: /extensions/PWG_Stuffs/admin/add_module.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/add_module.inc.php	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/add_module.inc.php	(revision 9383)
@@ -0,0 +1,182 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+if ($page['tab'] == 'add_module')
+{
+  if (!isset($_GET['path']) or !isset($modules[$_GET['path']]))
+  {
+    die('Wrong module path.');
+  }
+  else
+  {
+    $module_path = $_GET['path'];
+  }
+}
+
+// Save module
+if (isset($_POST['submit']) and !is_adviser())
+{
+  include($module_path.'config.inc.php');
+  if (empty($page['errors']))
+  {
+    if (empty($_POST['module_name']))
+    {
+      array_push($page['errors'], l10n('stuffs_no_name'));
+    }
+    else
+    {
+      $module_name = $_POST['module_name'];
+      $desc = !empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL';
+      $groups = !empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL';
+      $users = 'NULL';
+      if ($conf['Stuffs']['user_perm'])
+      {
+        $users = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : '""';
+      }
+      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
+      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
+      $on_root = isset($_POST['on_root'])  ? '"true"' : '"false"';
+      $on_cats = isset($_POST['on_cats'])  ? '"true"' : '"false"';
+      $on_picture = isset($_POST['on_picture'])  ? '"true"' : '"false"';
+
+      $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
+
+      if (isset($_GET['edit']))
+      {      
+        pwg_query('
+UPDATE ' . STUFFS_TABLE . '
+SET name ="' . $module_name . '",
+    descr=' . $desc . ',
+    datas=' . $sav_datas . ',
+    users=' . $users . ',
+    groups=' . $groups . ',
+    show_title=' . $show_title .',
+    on_home=' . $on_home .',
+    on_root=' . $on_root .',
+    on_cats=' . $on_cats . ',
+    on_picture='. $on_picture . '
+WHERE id = ' . $_GET['edit'] . ';');
+        if (isset($_GET['redirect']))
+        {
+          redirect(urldecode($_GET['redirect']));
+        }
+      }
+      else
+      {
+        $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . STUFFS_TABLE . ' ;';
+        list($next_element_id) = mysql_fetch_array(pwg_query($query));
+
+        $query = 'SELECT MAX(pos)+1 AS next_pos  FROM ' . STUFFS_TABLE . ' ;';
+        list($pos) = mysql_fetch_array(pwg_query($query));
+
+        $query = '
+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 )
+VALUES (' . $next_element_id . ' ,
+  ' . $pos . ',
+  "' . $module_name . '",
+  ' . $desc . ',
+  "' . $module_path . '",
+  ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .',
+  ' . $sav_datas . ',
+  ' . $users . ',
+  ' . $groups . ',
+  ' . $show_title . ',
+  ' . $on_home . ',
+  ' . $on_root . ',
+  ' . $on_cats . ',
+  ' . $on_picture . ',
+  NULL,
+  NULL);';
+        pwg_query($query);
+      }
+      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
+    }
+  }
+}
+
+// Default module data
+if ($page['tab'] == 'add_module')
+{
+  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
+  $module['groups'] = array();
+
+  $template->assign(array(
+    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
+    'MODULE_NAME' => $modules[$module_path]['name'],
+    'show_title_CHECKED' => true,
+    )
+  );
+
+  $template->assign('selected_options', array(
+    'on_home' => true,
+    'on_root' => true,
+    'on_cats' => false,
+    'on_picture' => false,
+    )
+  );
+}
+
+// Users perm
+if ($conf['Stuffs']['user_perm'])
+{
+  $users_id = array('guest', 'generic', 'normal', 'admin', 'webmaster');
+  $users = array();
+  foreach ($users_id as $id)
+  {
+    $users[$id] = l10n('user_status_'.$id);
+  }
+  $template->assign(array(
+    'users' => $users,
+    'selected_users' => isset($module['users']) ? $module['users'] : $users_id,
+    )
+  );
+}
+
+// Groups perm
+if ($conf['Stuffs']['group_perm'])
+{
+	$query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;';
+  $result = pwg_query($query);
+  $groups = array();
+  while ($row = pwg_db_fetch_assoc($result))
+  {
+    $groups[$row['id']] = $row['name'];
+  }
+  $template->assign(array(
+    'groups' => $groups,
+    'selected_groups' => isset($module['groups']) ? $module['groups'] : array(),
+    )
+  );
+}
+
+// Level perm
+if ($conf['Stuffs']['level_perm'])
+{
+  foreach ($conf['available_permission_levels'] as $level)
+  {
+    $level_options[$level] = l10n(sprintf('Level %d', $level));
+  }
+  $template->assign(array(
+    'level_perm' => $level_options,
+    'level_selected' => isset($module['level']) ? $module['level'] : 0,
+    )
+  );
+}
+
+// Display options
+$template->assign('display_options', array(
+  'on_home' => true,
+  'on_root' => true,
+  'on_cats' => true,
+  'on_picture' => true,
+  )
+);
+
+// Module configuration
+include_once($module_path.'config.inc.php');
+
+$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: tensions/PWG_Stuffs/admin/add_module.php
===================================================================
--- /extensions/PWG_Stuffs/admin/add_module.php	(revision 9382)
+++ 	(revision )
@@ -1,124 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-if ($page['tab'] == 'add_module')
-{
-  if (!isset($_GET['path']) or !isset($modules[$_GET['path']]))
-  {
-    die('Wrong module path.');
-  }
-  else
-  {
-    $module_path = $_GET['path'];
-  }
-}
-
-// Save module
-if (isset($_POST['submit']) and !is_adviser())
-{
-  include($module_path.'config.inc.php');
-  if (empty($page['errors']))
-  {
-    if (empty($_POST['module_name']))
-    {
-      array_push($page['errors'], l10n('stuffs_no_name'));
-    }
-    else
-    {
-      $module_name = $_POST['module_name'];
-      $desc = !empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL';
-      $groups = !empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL';
-      $users = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL';
-      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
-      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
-      $on_cats = isset($_POST['on_cats'])  ? '"true"' : '"false"';
-      $on_picture = isset($_POST['on_picture'])  ? '"true"' : '"false"';
-
-      $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
-
-      if (isset($_GET['edit']))
-      {      
-        pwg_query('
-UPDATE ' . STUFFS_TABLE . '
-SET name ="' . $module_name . '",
-    descr=' . $desc . ',
-    datas=' . $sav_datas . ',
-    users=' . $users . ',
-    groups=' . $groups . ',
-    show_title=' . $show_title .',
-    on_home=' . $on_home .',
-    on_cats=' . $on_cats . ',
-    on_picture='. $on_picture . '
-WHERE id = ' . $_GET['edit'] . ';');
-        if (isset($_GET['redirect']))
-        {
-          redirect(urldecode($_GET['redirect']));
-        }
-      }
-      else
-      {
-        $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . STUFFS_TABLE . ' ;';
-        list($next_element_id) = mysql_fetch_array(pwg_query($query));
-
-        $query = 'SELECT MAX(pos)+1 AS next_pos  FROM ' . STUFFS_TABLE . ' ;';
-        list($pos) = mysql_fetch_array(pwg_query($query));
-
-        $query = '
-INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, parent, datas, users, groups, show_title, on_home, on_cats, on_picture, id_line, width )
-VALUES (' . $next_element_id . ' ,
-  ' . $pos . ',
-  "' . $module_name . '",
-  ' . $desc . ',
-  "' . $module_path . '",
-  ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .',
-  ' . $sav_datas . ',
-  ' . $users . ',
-  ' . $groups . ',
-  ' . $show_title . ',
-  ' . $on_home . ',
-  ' . $on_cats . ',
-  ' . $on_picture . ',
-  NULL,
-  NULL);';
-        pwg_query($query);
-      }
-      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
-    }
-  }
-}
-
-// Default module data
-if ($page['tab'] == 'add_module')
-{
-  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
-  $module['groups'] = array();
-  $template->assign(array(
-    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
-    'MODULE_NAME' => $modules[$module_path]['name'],
-    'show_title_CHECKED' => 'checked="checked"',
-    'on_home_CHECKED' => 'checked="checked"'));
-}
-
-// Users perm
-$template->assign('user_perm', array(
-  'GUEST' => (in_array('guest', $module['users']) ? 'checked="checked"' : ''),
-  'GENERIC' => (in_array('generic', $module['users']) ? 'checked="checked"' : ''),
-  'NORMAL' => (in_array('normal', $module['users']) ? 'checked="checked"' : ''),
-  'ADMIN' => (in_array('admin', $module['users']) ? 'checked="checked"' : ''),
-  'WEBMASTER' => (in_array('webmaster', $module['users']) ? 'checked="checked"' : '')));
-
-// Groups perm
-$groups = get_all_groups();
-if (!empty($groups))
-{
-  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', $module['groups'])));
-}
-
-// Module configuration
-include_once($module_path.'config.inc.php');
-
-$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
-$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
-
-?>
Index: /extensions/PWG_Stuffs/admin/admin.php
===================================================================
--- /extensions/PWG_Stuffs/admin/admin.php	(revision 9382)
+++ /extensions/PWG_Stuffs/admin/admin.php	(revision 9383)
@@ -8,5 +8,4 @@
 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
 include_once(STUFFS_PATH . 'include/functions.inc.php');
-include_once(STUFFS_PATH . 'admin/functions.inc.php');
 $my_base_url = get_admin_plugin_menu_link(__FILE__);
 
@@ -28,6 +27,7 @@
 if ($page['tab'] == 'edit_module')
 {
-  $tabsheet->add('edit_module', l10n('stuffs_edit_mod'), $my_base_url.'&amp;tab=edit_module');
+  $tabsheet->add('edit_module', l10n('stuffs_edit_mod'), $my_base_url.'&amp;tab=edit_module&amp;edit='.$_GET['edit']);
 }
+$tabsheet->add('config', l10n('Configuration'), $my_base_url.'&amp;tab=config');
 $tabsheet->select($page['tab']);
 $tabsheet->assign();
@@ -51,5 +51,5 @@
 
 // Include file
-include(STUFFS_PATH.'admin/'.$page['tab'].'.php');
+include(STUFFS_PATH.'admin/'.$page['tab'].'.inc.php');
 
 ?>
Index: /extensions/PWG_Stuffs/admin/config.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/config.inc.php	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/config.inc.php	(revision 9383)
@@ -0,0 +1,44 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+// Save config
+if (isset($_POST['submit']))
+{
+  if (!$conf['Stuffs']['user_perm'] and isset($_POST['user_perm']))
+  {
+    pwg_query('UPDATE '.STUFFS_TABLE.' SET users = "guest,generic,normal,admin,webmaster";');
+  }
+  if ($conf['Stuffs']['user_perm'] and !isset($_POST['user_perm']))
+  {
+    pwg_query('UPDATE '.STUFFS_TABLE.' SET users = NULL;');
+  }
+  if ($conf['Stuffs']['level_perm'] and !isset($_POST['level_perm']))
+  {
+    $default_user = get_default_user_info(true);
+    pwg_query('UPDATE '.STUFFS_TABLE.' SET level = '.$default_user['level'].';');
+  }
+  if ($conf['Stuffs']['group_perm'] and !isset($_POST['group_perm']))
+  {
+    pwg_query('UPDATE '.STUFFS_TABLE.' SET groups = NULL;');
+  }
+
+  $params = array('group_perm', 'user_perm', 'level_perm');
+
+  foreach ($params as $param)
+  {
+    $conf['Stuffs'][$param] = isset($_POST[$param]);
+  }
+
+  conf_update_param('PWG_Stuffs', pwg_db_real_escape_string(serialize($conf['Stuffs'])));
+
+  array_push($page['infos'], l10n('Information data registered in database'));
+}
+
+// Parametrage du template
+$template->assign('stuffs_conf', $conf['Stuffs']);
+
+$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/config.tpl'));
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/PWG_Stuffs/admin/edit_module.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/edit_module.inc.php	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/edit_module.inc.php	(revision 9383)
@@ -0,0 +1,34 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+// Retrieve module data
+$q = ('SELECT * FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['edit'] . ';');
+$module = mysql_fetch_array(pwg_query($q));
+
+$module['users'] = explode(',', $module['users']);
+$module['groups'] = explode(',', $module['groups']);
+
+$datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
+
+$template->assign(array(
+  'STUFFS_TITLE' => l10n('stuffs_edit_mod') . ' <i>' . trigger_event('render_stuffs_name', $module['name']) . '</i>',
+  'MODULE_NAME' => $module['name'],
+  'DESC_VALUE' => (isset($module['descr']) ? $module['descr'] : ''),
+  'show_title_CHECKED' => ($module['show_title'] == 'true'),
+  )
+);
+
+$template->assign('selected_options', array(
+  'on_home' => ($module['on_home'] == 'true'),
+  'on_root' => ($module['on_root'] == 'true'),
+  'on_cats' => ($module['on_cats'] == 'true'),
+  'on_picture' => ($module['on_picture'] == 'true'),
+  )
+);
+
+$module_path = $module['path'];
+
+include('add_module.inc.php');
+
+?>
Index: tensions/PWG_Stuffs/admin/edit_module.php
===================================================================
--- /extensions/PWG_Stuffs/admin/edit_module.php	(revision 9382)
+++ 	(revision )
@@ -1,29 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-// Retrieve module data
-$q = ('SELECT * FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['edit'] . ';');
-$module = mysql_fetch_array(pwg_query($q));
-
-$module['users'] = explode(',', $module['users']);
-$module['groups'] = explode(',', $module['groups']);
-
-$datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
-
-$template->assign(array(
-  'STUFFS_TITLE' => l10n('stuffs_edit_mod') . ' <i>' . trigger_event('render_stuffs_name', $module['name']) . '</i>',
-  'MODULE_NAME' => $module['name'],
-  'DESC_VALUE' => (isset($module['descr']) ? $module['descr'] : ''),
-  'show_title_CHECKED' => ($module['show_title'] == 'true' ? 'checked="checked"' : ''),
-  'on_home_CHECKED' => ($module['on_home'] == 'true' ? 'checked="checked"' : ''),
-  'on_cats_CHECKED' => ($module['on_cats'] == 'true' ? 'checked="checked"' : ''),
-  'on_picture_CHECKED' => ($module['on_picture'] == 'true' ? 'checked="checked"' : ''),
-  )
-);
-
-$module_path = $module['path'];
-
-include('add_module.php');
-
-?>
Index: tensions/PWG_Stuffs/admin/functions.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/functions.inc.php	(revision 9382)
+++ 	(revision )
@@ -1,85 +1,0 @@
-<?php
-
-function get_default_stuffs_modules($modules)
-{
-  $dir = opendir(STUFFS_PATH . 'modules/');
-  while ($file = readdir($dir))
-  {
-    if ($file != '.' and $file != '..' and $file != '.svn')
-    {
-      $path = STUFFS_PATH . 'modules/' . $file;
-      if (is_dir($path) and !is_link($path))
-      {
-        array_push($modules, array(
-          'path' => $path,
-          'name' => l10n('module_name_' . strtolower($file)),
-          'description' => l10n('module_desc_' . strtolower($file)),
-          )
-        );
-      }
-    }
-  }
-  closedir($dir);
-  return $modules;
-}
-
-function get_html_groups_selection(
-  $groups,
-  $fieldname,
-  $selecteds = array()
-  )
-{
-  global $conf;
-  if (count ($groups) == 0 )
-  {
-    return '';
-  }
-  $output = '<div id="'.$fieldname.'">';
-  $id = 1;
-  foreach ($groups as $group)
-  {
-    $output.=
-
-      '<input type="checkbox" name="'.$fieldname.'[]"'
-      .' id="group_'.$id++.'"'
-      .' value="'.$group['id'].'"'
-      ;
-
-    if (in_array($group['id'], $selecteds))
-    {
-      $output.= ' checked="checked"';
-    }
-
-    $output.=
-      '><label>'
-      .'&nbsp;'. $group['name']
-      .'</label>'
-      ."\n"
-      ;
-  }
-  $output.= '</div>';
-
-  return $output;
-}
-
-
-function get_all_groups()
-{
-$query = '
-SELECT id, name
-  FROM '.GROUPS_TABLE.'
-  ORDER BY name ASC
-;';
-$result = pwg_query($query);
-
-$groups = array();
-  while ($row = mysql_fetch_assoc($result))
-  {
-    array_push($groups, $row);
-  }
-
-  uasort($groups, 'name_compare');
-  return $groups;
-}
-
-?>
Index: /extensions/PWG_Stuffs/admin/manage.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/manage.inc.php	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/manage.inc.php	(revision 9383)
@@ -0,0 +1,89 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $pwg_loaded_plugins;
+
+// Delete module
+if (isset($_GET['del']) and !is_adviser())
+{
+  pwg_query('DELETE FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['del'] . ' LIMIT 1;');
+  redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
+}
+
+// Save order
+if (isset($_POST['submitOrder']) and !is_adviser())
+{
+  asort($_POST['position'], SORT_NUMERIC);
+  $pos = 1;
+  foreach($_POST['position'] as $id => $old_pos)
+  {
+    $id_line = !empty($_POST['id_line'][$id]) ? '"'.$_POST['id_line'][$id].'"' : 'NULL';
+    $width = (!empty($_POST['width'][$id]) and is_numeric($_POST['width'][$id])) ? '"'.$_POST['width'][$id].'"' : 'NULL';
+
+    pwg_query('
+UPDATE ' . STUFFS_TABLE . '
+SET pos=' . $pos++ . ' , id_line='.$id_line.', width='.$width.'
+WHERE id=' . $id . ' LIMIT 1');
+  }
+
+    pwg_query('
+UPDATE ' . STUFFS_TABLE . '
+SET datas = "'.addslashes(serialize(array('hide' => isset($_POST['hidemb'])))).'"
+WHERE id=0;');
+
+  array_push($page['infos'], l10n('stuffs_order_saved'));
+}
+
+// Display
+$q = 'SELECT id, name, descr, path, parent, id_line, width, datas
+FROM ' . STUFFS_TABLE . '
+ORDER BY pos ASC;';
+$result = pwg_query($q);
+$num = 0;
+$pos = 1;
+$id_line_options = array(
+    '' => '-',
+    'A' => 'A',
+    'B' => 'B',
+    'C' => 'C',
+    'D' => 'D',
+    'E' => 'E',
+    'F' => 'F',
+    'G' => 'G',
+    'H' => 'H',
+    'I' => 'I',
+    'J' => 'J');
+
+while ($module = mysql_fetch_assoc($result))
+{
+  $module['name'] = !empty($module['path']) ? $module['name'] : l10n('stuffs_main_block');
+
+  $template->append('modules', array(
+    'ID' => $module['id'],
+    'NAME' => trigger_event('render_stuffs_name', $module['name']),
+    'DESC' => $module['descr'],
+    'PATH' => $module['path'],
+    'TYPE_NAME' => (isset($modules[$module['path']]['name']) ? $modules[$module['path']]['name'] : ''),
+    'POS' => 10 * $pos++,
+    'ID_LINE_OPTIONS' => $id_line_options,
+    'ID_LINE_SELECTED' => $module['id_line'],
+    'WIDTH' => $module['width'],
+    'ID' => $module['id'],
+    'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=edit_module&amp;edit='.$module['id'],
+    'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&amp;del=' . $module['id'] : '',
+    'MISSING' => (isset($module['parent']) and !isset($pwg_loaded_plugins[$module['parent']])),
+    )
+  );
+
+  if (empty($module['path']) and !empty($module['datas']))
+  {
+    $datas = unserialize($module['datas']);
+    $template->assign('HIDEMB', $datas['hide']); 
+  }
+}
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/manage.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: tensions/PWG_Stuffs/admin/manage.php
===================================================================
--- /extensions/PWG_Stuffs/admin/manage.php	(revision 9382)
+++ 	(revision )
@@ -1,89 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-global $pwg_loaded_plugins;
-
-// Delete module
-if (isset($_GET['del']) and !is_adviser())
-{
-  pwg_query('DELETE FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['del'] . ' LIMIT 1;');
-  redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
-}
-
-// Save order
-if (isset($_POST['submitOrder']) and !is_adviser())
-{
-  asort($_POST['position'], SORT_NUMERIC);
-  $pos = 1;
-  foreach($_POST['position'] as $id => $old_pos)
-  {
-    $id_line = !empty($_POST['id_line'][$id]) ? '"'.$_POST['id_line'][$id].'"' : 'NULL';
-    $width = (!empty($_POST['width'][$id]) and is_numeric($_POST['width'][$id])) ? '"'.$_POST['width'][$id].'"' : 'NULL';
-
-    pwg_query('
-UPDATE ' . STUFFS_TABLE . '
-SET pos=' . $pos++ . ' , id_line='.$id_line.', width='.$width.'
-WHERE id=' . $id . ' LIMIT 1');
-  }
-
-    pwg_query('
-UPDATE ' . STUFFS_TABLE . '
-SET datas = "'.addslashes(serialize(array('hide' => isset($_POST['hidemb'])))).'"
-WHERE id=0;');
-
-  array_push($page['infos'], l10n('stuffs_order_saved'));
-}
-
-// Display
-$q = 'SELECT id, name, descr, path, parent, id_line, width, datas
-FROM ' . STUFFS_TABLE . '
-ORDER BY pos ASC;';
-$result = pwg_query($q);
-$num = 0;
-$pos = 1;
-$id_line_options = array(
-    '' => '-',
-    'A' => 'A',
-    'B' => 'B',
-    'C' => 'C',
-    'D' => 'D',
-    'E' => 'E',
-    'F' => 'F',
-    'G' => 'G',
-    'H' => 'H',
-    'I' => 'I',
-    'J' => 'J');
-
-while ($module = mysql_fetch_assoc($result))
-{
-  $module['name'] = !empty($module['path']) ? $module['name'] : l10n('stuffs_main_block');
-
-  $template->append('modules', array(
-    'ID' => $module['id'],
-    'NAME' => trigger_event('render_stuffs_name', $module['name']),
-    'DESC' => $module['descr'],
-    'PATH' => $module['path'],
-    'TYPE_NAME' => (isset($modules[$module['path']]['name']) ? $modules[$module['path']]['name'] : ''),
-    'POS' => 10 * $pos++,
-    'ID_LINE_OPTIONS' => $id_line_options,
-    'ID_LINE_SELECTED' => $module['id_line'],
-    'WIDTH' => $module['width'],
-    'ID' => $module['id'],
-    'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=edit_module&amp;edit='.$module['id'],
-    'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&amp;del=' . $module['id'] : '',
-    'MISSING' => (isset($module['parent']) and !isset($pwg_loaded_plugins[$module['parent']])),
-    )
-  );
-
-  if (empty($module['path']) and !empty($module['datas']))
-  {
-    $datas = unserialize($module['datas']);
-    $template->assign('HIDEMB', $datas['hide']); 
-  }
-}
-
-$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/manage.tpl');
-$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
-
-?>
Index: /extensions/PWG_Stuffs/admin/new.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/new.inc.php	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/new.inc.php	(revision 9383)
@@ -0,0 +1,31 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+//Ajout d'un module
+if (isset($_POST['addModule']) and !is_adviser())
+{
+  if (!isset($_POST['module']))
+  {
+    array_push($page['errors'], l10n('stuffs_error_no_mod_selected'));
+  }
+  else
+  {
+    redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&tab=add_module&path=' . urlencode($_POST['module']));
+  }
+}
+
+// Affichages des modules à ajouter
+foreach($modules as $module)
+{
+  $template->append('add_module', array(
+    'MODULE_PATH' => $module['path'],
+    'NAME' => $module['name'],
+    'DESC' => $module['description'],
+    )
+  );
+}
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/new.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+?>
Index: tensions/PWG_Stuffs/admin/new.php
===================================================================
--- /extensions/PWG_Stuffs/admin/new.php	(revision 9382)
+++ 	(revision )
@@ -1,31 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-//Ajout d'un module
-if (isset($_POST['addModule']) and !is_adviser())
-{
-  if (!isset($_POST['module']))
-  {
-    array_push($page['errors'], l10n('stuffs_error_no_mod_selected'));
-  }
-  else
-  {
-    redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&tab=add_module&path=' . urlencode($_POST['module']));
-  }
-}
-
-// Affichages des modules à ajouter
-foreach($modules as $module)
-{
-  $template->append('add_module', array(
-    'MODULE_PATH' => $module['path'],
-    'NAME' => $module['name'],
-    'DESC' => $module['description'],
-    )
-  );
-}
-
-$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/new.tpl');
-$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
-?>
Index: /extensions/PWG_Stuffs/admin/template/add_module.tpl
===================================================================
--- /extensions/PWG_Stuffs/admin/template/add_module.tpl	(revision 9382)
+++ /extensions/PWG_Stuffs/admin/template/add_module.tpl	(revision 9383)
@@ -1,5 +1,12 @@
+{known_script id="jquery" src=$ROOT_URL|@cat:"themes/default/js/jquery.packed.js"}
 {include file='include/autosize.inc.tpl'}
-
-{$TINYMCE_SCRIPT}
+{html_head}{literal}
+<style type="text/css">
+.groups { margin-top:15px; }
+.groups input { margin-right:5px; }
+.groups label { margin-right:10px; display: inline-block; overflow: hidden; white-space: nowrap; line-height:1.3em;}
+.groups div { float:right; width:74%; line-height:1.3em;}
+</style>
+{/literal}{/html_head}
 
 <div class="titrePage">
@@ -7,80 +14,78 @@
 </div>
 
-<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+<form method="post" action="" class="properties" ENCTYPE="multipart/form-data">
+<fieldset id="mainConf" >
+  <legend>{'stuffs_module_config'|@translate}</legend>
+	<ul>
+    <li>
+      <span class="property">
+        <label for="module_name">{'stuffs_module_title'|@translate}</label>
+      </span>
+      <textarea rows="2" name="module_name" id="module_name" class="description" style="height:2em; width:500px;">{$MODULE_NAME}</textarea>
+    </li>
+    <li>
+      <span class="property">
+        <label for="module_desc">{'stuffs_desc'|@translate}<br>&nbsp;</label>
+      </span>
+      <input type="text" maxlength="255" value="{$DESC_VALUE}" name="module_desc" id="module_desc" style="width:500px;"/><br><i>{'stuffs_only_for_admin'|@translate}</i>
+    </li>
+    <li>
+      <span class="property">
+        <label for="show_title">{'stuffs_show_title'|@translate}</label>
+      </span>
+      <input type="checkbox" name="show_title" id="show_title" value="1" {if $show_title_CHECKED}checked="checked"{/if}>
+    </li>
 
-<fieldset>
-	<legend>{'stuffs_module_config'|@translate}</legend>
-	<table>
-
-		<tr><td colspan="3"><br></td></tr>
-
-		<tr>
-			<td><b>{'stuffs_module_title'|@translate}&nbsp;&nbsp;</b></td>
-			<td colspan="2"><textarea cols="50" rows="2" name="module_name" id="module_name" class="description" style="height: 2em">{$MODULE_NAME}</textarea></td>
-		</tr>
-
-		<tr><td colspan="3"><br></td></tr>
-
-		<tr>
-			<td><b>{'stuffs_desc'|@translate}&nbsp;&nbsp;</b></td>
-			<td colspan="2"><input type="text" size="65" maxlength="255" value="{$DESC_VALUE}" name="module_desc"/></td>
-		</tr>
-		<tr>
-			<td></td>
-			<td colspan="2">{'stuffs_only_for_admin'|@translate}</td>
-		</tr>
-
-		<tr><td colspan="3"><br></td></tr>
-		<tr>
-			<td><b>{'stuffs_authorized_users'|@translate} &nbsp;&nbsp;</b></td>
-			<td colspan="2">
-				<div id="users">
-				<input type="checkbox" name="users[]" id="guest" value="guest" {$user_perm.GUEST}><label>&nbsp;{'user_status_guest'|@translate}</label>
-				<input type="checkbox" name="users[]" id="generic" value="generic" {$user_perm.GENERIC}><label>&nbsp;{'user_status_generic'|@translate}</label>
-				<input type="checkbox" name="users[]" id="normal" value="normal" {$user_perm.NORMAL}><label>&nbsp;{'user_status_normal'|@translate}</label>
-				<input type="checkbox" name="users[]" id="admin" value="admin" {$user_perm.ADMIN}><label>&nbsp;{'user_status_admin'|@translate}</label>
-				<input type="checkbox" name="users[]" id="webmaster" value="webmaster" {$user_perm.WEBMASTER}><label>&nbsp;{'user_status_webmaster'|@translate}</label>
-				</div>
-			</td>
-        </tr>
-
-		{if isset($group_perm)}
-		<tr><td colspan="3"><br></td></tr>
-		<tr>
-			<td><b>{'stuffs_authorized_group'|@translate} &nbsp;&nbsp;</b></td>
-			<td colspan="2">{$group_perm.GROUPSELECTION}</td>
-        </tr>
-        <tr>
-        	<td></td>
-			<td colspan="2"><i>{'stuffs_public_module'|@translate}</i></td>
-        </tr>
+    {if isset($level_perm)}
+    <li style="margin-top:15px;">
+      <span class="property">
+        <label for="level">{'Privacy level'|@translate}</label>
+      </span>
+      <select name="level" id="level" size="1">{html_options options=$level_perm selected=$level_selected id=privacy}</select>
+    </li>
     {/if}
 
-        <tr><td colspan="3"><br></td></tr>
-	</table>
+    
+    {if isset($users)}
+    <li class="groups" style="margin-top:15px;">
+      <span class="property">
+        <label for="users">{'stuffs_authorized_users'|@translate}</label>
+      </span>
+      {html_checkboxes options=$users selected=$selected_users name=users}
+    </li>
+    {/if}
+
+    {if isset($groups)}
+    <li class="groups" style="margin-top:15px;">
+      <span class="property">
+        <label for="groups">{'stuffs_authorized_group'|@translate}</label>
+      </span>
+      <div>{html_checkboxes options=$groups selected=$selected_groups name=groups}</div>
+    </li>
+    <li class="groups">
+      <div>
+        <a href="#" onClick="jQuery('input[name^=\'groups\']').attr('checked', 'checked');return false;">{'stuffs_select_all'|@translate}</a> /
+        <a href="#" onClick="jQuery('input[name^=\'groups\']').attr('checked', '');return false;">{'stuffs_unselect_all'|@translate}</a> &nbsp; 
+        <i>{'stuffs_guest'|@translate}</i>
+      </div>
+    </li>
+    {/if}
+  </ul>
 </fieldset>
 
-<fieldset>
-	<legend>{'stuffs_visual_config'|@translate}</legend>
-	<table>
-		<tr><td colspan="2"><br></td></tr>
-		<tr>
-			<td colspan="2"><input type="checkbox" name="show_title" value="1" {$show_title_CHECKED}>&nbsp;&nbsp;{'stuffs_show_title'|@translate}</td>
-		</tr>
-		<tr><td><br></td></tr>
-		<tr>
-			<td>{'stuffs_show_module_on'|@translate}</td>
-			<td>&nbsp;&nbsp;<input type="checkbox" name="on_home" value="1" {$on_home_CHECKED}>&nbsp;&nbsp;<i>{'stuffs_show_on_home'|@translate}</i></td>
-		</tr>
-		<tr><td></td>
-			<td>&nbsp;&nbsp;<input type="checkbox" name="on_cats" value="1" {$on_cats_CHECKED}>&nbsp;&nbsp;<i>{'stuffs_show_on_cats'|@translate}</i></td>
-		</tr>
-		<tr><td></td>
-			<td>&nbsp;&nbsp;<input type="checkbox" name="on_picture" value="1" {$on_picture_CHECKED}>&nbsp;&nbsp;<i>{'stuffs_show_on_pictures'|@translate}</i></td>
-		</tr>
-		<tr><td colspan="2"><br></td></tr>
-	</table>
-
-
+<fieldset id="indexDisplayConf">
+	<legend>{'stuffs_show_module_on'|@translate}</legend>
+  <ul>
+    {foreach from=$display_options key=option item=value}
+    {if $value}
+    <li>
+      <label>
+        <span class="property">{'stuffs_show_'|@cat:$option|@translate}</span>
+        <input type="checkbox" name="{$option}" value="1" {if $selected_options[$option]}checked="checked"{/if}>
+      </label>
+    </li>
+    {/if}
+    {/foreach}
+  </ul>
 </fieldset>
 
Index: /extensions/PWG_Stuffs/admin/template/config.tpl
===================================================================
--- /extensions/PWG_Stuffs/admin/template/config.tpl	(revision 9383)
+++ /extensions/PWG_Stuffs/admin/template/config.tpl	(revision 9383)
@@ -0,0 +1,33 @@
+<div class="titrePage">
+	<h2>PWG Stuffs - {'Configuration'|@translate}</h2>
+</div>
+
+<form name="stuffsform" method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+<fieldset id="indexDisplayConf">
+  <legend>{'stuffs_perm'|@translate}</legend>
+  <ul>
+      <li>
+      <label>
+        <span class="property">{'stuffs_level_perm'|@translate}</span>
+        <input type="checkbox" name="level_perm" id="level_perm" value="on" {if $stuffs_conf.level_perm}checked="checked"{/if}/>
+      </label>
+    </li>
+
+    <li>
+      <label>
+        <span class="property">{'stuffs_user_perm'|@translate}</span>
+        <input type="checkbox" name="user_perm" id="user_perm" value="on" {if $stuffs_conf.user_perm}checked="checked"{/if}/>
+      </label>
+    </li>
+
+    <li>
+      <label>
+        <span class="property">{'stuffs_group_perm'|@translate}</span>
+        <input type="checkbox" name="group_perm" id="group_perm" value="on" {if $stuffs_conf.group_perm}checked="checked"{/if}/>
+      </label>
+    </li>
+  </ul>
+</fieldset>
+
+<p><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit"/></p>
+</form>
Index: /extensions/PWG_Stuffs/admin/upgrade.inc.php
===================================================================
--- /extensions/PWG_Stuffs/admin/upgrade.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/admin/upgrade.inc.php	(revision 9383)
@@ -92,5 +92,13 @@
   $query = 'ALTER TABLE ' . $prefixeTable . 'stuffs
 CHANGE `type` `path` VARCHAR( 255 ) NULL DEFAULT NULL,
-ADD `parent` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `path`
+ADD `parent` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `path`,
+ADD `level` TINYINT( 3 ) NOT NULL default "0" AFTER `groups`,
+ADD `on_root` enum(\'true\',\'false\') NOT NULL AFTER `on_home`
+;';
+  pwg_query($query);
+
+  $query = 'UPDATE ' . $prefixeTable . 'stuffs
+SET on_root = "false"
+WHERE on_cats = "false"
 ;';
   pwg_query($query);
@@ -107,11 +115,25 @@
 ;';
   pwg_query($query);
+
+  $conf['Stuffs'] = array('level_perm' => false);
+
+  $query = 'SELECT id
+FROM '.$prefixeTable.'stuffs
+WHERE users <> "guest,generic,normal,admin,webmaster"
+;';
+  $ids = array_from_query($query, 'id');
+  $conf['Stuffs']['user_perm'] = !empty($ids);
+
+  $query = 'SELECT id
+FROM '.$prefixeTable.'stuffs
+WHERE groups IS NOT NULL
+;';
+  $ids = array_from_query($query, 'id');
+  $conf['Stuffs']['group_perm'] = !empty($ids);
+
+  $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
+VALUES ("PWG_Stuffs" , "'.pwg_db_real_escape_string(serialize($conf['Stuffs'])).'" , "PWG Stuffs configuration");';
+  pwg_query($query);  
 }
 
-$query = '
-UPDATE ' . PLUGINS_TABLE . '
-SET version=\''.STUFFS_VERSION.'\'
-WHERE id=\'PWG_Stuffs\'';
-pwg_query($query);
-
 ?>
Index: /extensions/PWG_Stuffs/include/class.inc.php
===================================================================
--- /extensions/PWG_Stuffs/include/class.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/include/class.inc.php	(revision 9383)
@@ -9,7 +9,24 @@
   var $blocks = array();
   var $pos = 'begin';
+  var $template_var = array();
 
   function stuffs()
   {
+    global $page, $template;
+
+    if ($page['stuffs_section'] == 'on_picture')
+    {
+      $this->template_var['begin'] = 'PLUGIN_PICTURE_BEFORE';
+      $this->template_var['end'] = 'PLUGIN_PICTURE_AFTER';
+      $template->set_prefilter('header', array('stuffs', 'prefilter_picture_css'));
+      pwgs_picture_special_sections();
+    }
+    else
+    {
+      $this->template_var['begin'] = 'PLUGIN_INDEX_CONTENT_BEFORE';
+      $this->template_var['end'] = 'PLUGIN_INDEX_CONTENT_AFTER';
+      $template->set_prefilter( 'header', array('stuffs', 'prefilter_index_css') );
+    }
+
     $this->get_user_groups();
     $this->get_modules();
@@ -35,25 +52,17 @@
     global $page, $user;
 
+    if (!isset($page['stuffs_section'])) return;
+
     $query = '
-SELECT id, name, path, parent, datas, groups, show_title, id_line, width
+SELECT DISTINCT id, name, path, parent, datas, groups, show_title, id_line, width
 FROM ' . STUFFS_TABLE . '
-WHERE users LIKE "%' . $user['status'] . '%"
-';
-
-    $script = script_basename();
-    if ($script == 'index')
-    {
-      $query .= !$page['is_homepage'] ?
-        'AND on_cats = "true"' :
-        'AND on_home = "true"' ;
-    }
-    elseif ($script == 'picture')
-    {
-      $query .= 'AND on_picture = "true"';
-    }
-    else return;
-
-    $query .= '
-ORDER BY pos ASC;';
+LEFT JOIN ' . USER_GROUP_TABLE . '
+  ON user_id = '.$user['id'].'
+WHERE (users IS NULL OR users LIKE "%' . $user['status'] . '%")
+  AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)"))
+  AND level <= '.$user['level'].'
+  AND '.$page['stuffs_section'].' = "true"
+ORDER BY pos ASC
+;';
 
     $result = pwg_query($query);
@@ -86,9 +95,4 @@
       {
         continue;
-      }
-      if (!empty($module['groups']))
-      {
-        $authorized_groups = explode(',', $module['groups']);
-        if (array_intersect($this->user_groups, $authorized_groups) == array()) continue;
       }
 
Index: /extensions/PWG_Stuffs/include/functions.inc.php
===================================================================
--- /extensions/PWG_Stuffs/include/functions.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/include/functions.inc.php	(revision 9383)
@@ -37,4 +37,27 @@
 }
 
+function get_default_stuffs_modules($modules)
+{
+  $dir = opendir(STUFFS_PATH . 'modules/');
+  while ($file = readdir($dir))
+  {
+    if ($file != '.' and $file != '..' and $file != '.svn')
+    {
+      $path = STUFFS_PATH . 'modules/' . $file;
+      if (is_dir($path) and !is_link($path))
+      {
+        array_push($modules, array(
+          'path' => $path,
+          'name' => l10n('module_name_' . strtolower($file)),
+          'description' => l10n('module_desc_' . strtolower($file)),
+          )
+        );
+      }
+    }
+  }
+  closedir($dir);
+  return $modules;
+}
+
 function pwgs_picture_special_sections()
 {
@@ -61,7 +84,7 @@
       {
         case 'pwgs_mv': $title = l10n('Most visited'); break;
-        case 'pwgs_br': $title = l10n('Best rated');   break;
-        case 'pwgs_re': $title = l10n('Recent pictures');  break;
-        case 'pwgs_ra': $title = l10n('Random pictures');       break;
+        case 'pwgs_br': $title = l10n('Best rated'); break;
+        case 'pwgs_re': $title = l10n('Recent pictures'); break;
+        case 'pwgs_ra': $title = l10n('Random pictures'); break;
       }
       $page['title'] .= $conf['level_separator'] . $title;
@@ -117,5 +140,5 @@
   global $page, $template;
 
-  if ($page['is_homepage'])
+  if ($page['stuffs_section'] == 'on_home')
   {
     $template->set_prefilter('index', 'hide_main_block_prefilter');
Index: tensions/PWG_Stuffs/include/stuffs.inc.php
===================================================================
--- /extensions/PWG_Stuffs/include/stuffs.inc.php	(revision 9382)
+++ 	(revision )
@@ -1,40 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-global $template;
-
-include_once(STUFFS_PATH . 'include/class.inc.php');
-include(STUFFS_PATH . 'include/functions.inc.php');
-
-$stuffs = new stuffs();
-
-$template->set_template_dir(STUFFS_PATH.'theme/template/');
-$template->set_filename('stuffs', 'stuffs_blocks.tpl');
-
-if (script_basename() == 'index')
-{
-  $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
-  $end = 'PLUGIN_INDEX_CONTENT_AFTER';
-  $template->set_prefilter( 'header', array('stuffs', 'prefilter_index_css') );
-}
-else
-{
-  $begin = 'PLUGIN_PICTURE_BEFORE';
-  $end = 'PLUGIN_PICTURE_AFTER';
-  $template->set_prefilter('header', array('stuffs', 'prefilter_picture_css'));
-  pwgs_picture_special_sections();
-}
-
-if (!empty($stuffs->blocks['begin']))
-{
-  $template->assign('blocks', $stuffs->blocks['begin']);
-  $template->concat($begin,  $template->parse('stuffs', true));
-}
-if (!empty($stuffs->blocks['end']))
-{
-  $template->assign('blocks', $stuffs->blocks['end']);
-  $template->concat($end,  $template->parse('stuffs', true));
-}
-
-?>
Index: /extensions/PWG_Stuffs/language/ar_SA/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/ar_SA/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/ar_SA/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'في الصفحة الرئيسية';
 $lang['stuffs_show_on_cats'] = 'في كل صفحات التصنيفات';
-$lang['stuffs_show_on_pictures'] = 'في صفحات الصورة';
+$lang['stuffs_show_on_picture'] = 'في صفحات الصورة';
 $lang['stuffs_no_options'] = 'لا خيارات لهذه الموديول';
 $lang['Hide on home page'] = 'اخفاء في الصفحة الاولى';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/cs_CZ/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/cs_CZ/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/cs_CZ/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Na hlavní stránce';
 $lang['stuffs_show_on_cats'] = 'Ve všech kategoriích';
-$lang['stuffs_show_on_pictures'] = 'Na stránkách fotek';
+$lang['stuffs_show_on_picture'] = 'Na stránkách fotek';
 $lang['stuffs_no_options'] = 'Žádné hodnoty k nastavení pro tento modul';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/de_DE/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/de_DE/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/de_DE/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Nur auf der Indexseite (also die Hauptseite)';
 $lang['stuffs_show_on_cats'] = 'Auf allen Seiten der verschiedenen Kategorien';
-$lang['stuffs_show_on_pictures'] = 'Auf den Seiten der Bilder und Fotos';
+$lang['stuffs_show_on_picture'] = 'Auf den Seiten der Bilder und Fotos';
 $lang['stuffs_no_options'] = 'Für dieses Modul steht keine Option zur Verfügung';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/en_UK/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/en_UK/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'On main page';
 $lang['stuffs_show_on_cats'] = 'On all categories pages';
-$lang['stuffs_show_on_pictures'] = 'On picture pages';
+$lang['stuffs_show_on_picture'] = 'On picture pages';
 $lang['stuffs_no_options'] = 'No options for this module';
 $lang['Hide on home page'] = 'Hide on home page';
+
+$lang['stuffs_perm'] = 'Activate authorization management:';
+$lang['stuffs_group_perm'] = 'by groups';
+$lang['stuffs_user_perm'] = 'by user type';
+$lang['stuffs_level_perm'] = 'by privacy level';
+$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/es_ES/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/es_ES/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/es_ES/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'En la página inicial del sitio';
 $lang['stuffs_show_on_cats'] = 'En todas las páginas de las categorías';
-$lang['stuffs_show_on_pictures'] = 'En las páginas de las imágenes';
+$lang['stuffs_show_on_picture'] = 'En las páginas de las imágenes';
 $lang['stuffs_no_options'] = 'Ninguna opcion disponibles para este módulo';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/fr_FR/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/fr_FR/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Sur la page d\'accueil du site';
 $lang['stuffs_show_on_cats'] = 'Sur toutes les pages des catégories';
-$lang['stuffs_show_on_pictures'] = 'Sur les pages des images';
+$lang['stuffs_show_on_picture'] = 'Sur les pages des images';
 $lang['stuffs_no_options'] = 'Pas d\'options disponibles pour ce module';
+
+$lang['stuffs_perm'] = 'Activer la gestion des droits d\'accès aux modules:';
+$lang['stuffs_group_perm'] = 'par groupes';
+$lang['stuffs_user_perm'] = 'par type d\'utilisateurs';
+$lang['stuffs_level_perm'] = 'par niveau de confidentialité';
+$lang['stuffs_show_on_root'] = 'A la racine des catégories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/hr_HR/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/hr_HR/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/hr_HR/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Na glavnoj stranici';
 $lang['stuffs_show_on_cats'] = 'Na stranicama kategorija';
-$lang['stuffs_show_on_pictures'] = 'Na stranicama slika';
+$lang['stuffs_show_on_picture'] = 'Na stranicama slika';
 $lang['stuffs_no_options'] = 'Bez opcija za ovaj modul';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/hu_HU/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/hu_HU/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/hu_HU/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Fő oldalon';
 $lang['stuffs_show_on_cats'] = 'Minden kategória oldalon';
-$lang['stuffs_show_on_pictures'] = 'Kép oldalakon';
+$lang['stuffs_show_on_picture'] = 'Kép oldalakon';
 $lang['stuffs_no_options'] = 'A modulhoz nincs egyéb beállítási lehetőség';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/it_IT/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/it_IT/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/it_IT/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Sulla home page del sito';
 $lang['stuffs_show_on_cats'] = 'Su tutte le pagine delle categorie';
-$lang['stuffs_show_on_pictures'] = 'Sulle pagine delle immagini';
+$lang['stuffs_show_on_picture'] = 'Sulle pagine delle immagini';
 $lang['stuffs_no_options'] = 'Nessuna opzione per questo modulo';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/ja_JP/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/ja_JP/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/ja_JP/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'メインメニュー';
 $lang['stuffs_show_on_cats'] = 'すべてのカテゴリページ';
-$lang['stuffs_show_on_pictures'] = '写真ページ';
+$lang['stuffs_show_on_picture'] = '写真ページ';
 $lang['stuffs_no_options'] = 'このモジュールにオプションはありません。';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/lv_LV/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/lv_LV/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/lv_LV/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Galvenajā lapā';
 $lang['stuffs_show_on_cats'] = 'Visu kategoriju lapās';
-$lang['stuffs_show_on_pictures'] = 'Attēlu lapās';
+$lang['stuffs_show_on_picture'] = 'Attēlu lapās';
 $lang['stuffs_no_options'] = 'Šim modulim nav citu iespēju';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Informatīvie paziņojumi
Index: /extensions/PWG_Stuffs/language/no_NO/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/no_NO/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/no_NO/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'På hoved side';
 $lang['stuffs_show_on_cats'] = 'På alle kategori sider';
-$lang['stuffs_show_on_pictures'] = 'På bilde sider';
+$lang['stuffs_show_on_picture'] = 'På bilde sider';
 $lang['stuffs_no_options'] = 'Ingen alternativer for denne modulen';
 $lang['Hide on home page'] = 'Gjem på hjemme side';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/pl_PL/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/pl_PL/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/pl_PL/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'Na głównej stronie';
 $lang['stuffs_show_on_cats'] = 'Na stronach ze wszystkimi kategoriami';
-$lang['stuffs_show_on_pictures'] = 'Na stronach z obrazami';
+$lang['stuffs_show_on_picture'] = 'Na stronach z obrazami';
 $lang['stuffs_no_options'] = 'Nie ma opcji dla tego modułu';
 /*translate*/$lang['Hide on home page'] = 'Hide on home page';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/pt_PT/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/pt_PT/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/pt_PT/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'Na Página Principal';
 $lang['stuffs_show_on_cats'] = 'Em todas as páginas de categoria';
-$lang['stuffs_show_on_pictures'] = 'Nas páginas de Imagem';
+$lang['stuffs_show_on_picture'] = 'Nas páginas de Imagem';
 $lang['stuffs_no_options'] = 'Este módulo não tem opções';
 $lang['Hide on home page'] = 'Esconder na página principal';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/ru_RU/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/ru_RU/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/ru_RU/plugin.lang.php	(revision 9383)
@@ -31,6 +31,12 @@
 $lang['stuffs_show_on_home'] = 'На главную страницу';
 $lang['stuffs_show_on_cats'] = 'На всех страницах этой категории';
-$lang['stuffs_show_on_pictures'] = 'На страницах изображения';
+$lang['stuffs_show_on_picture'] = 'На страницах изображения';
 $lang['stuffs_no_options'] = 'Нет вариантов для этого модуля';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Информация о сообщениях
Index: /extensions/PWG_Stuffs/language/sk_SK/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/sk_SK/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/sk_SK/plugin.lang.php	(revision 9383)
@@ -30,6 +30,12 @@
 $lang['stuffs_show_on_home'] = 'Na hlavnej stránke';
 $lang['stuffs_show_on_cats'] = 'Na všetkých stránkach kategórií';
-$lang['stuffs_show_on_pictures'] = 'Na stránkach fotografií';
+$lang['stuffs_show_on_picture'] = 'Na stránkach fotografií';
 $lang['stuffs_no_options'] = 'Žiadne možnosti pre tento modul';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/sv_SE/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/sv_SE/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/sv_SE/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'På huvudsidan';
 $lang['stuffs_show_on_cats'] = 'På alla kategoriers sidor';
-$lang['stuffs_show_on_pictures'] = 'På bild sidor';
+$lang['stuffs_show_on_picture'] = 'På bild sidor';
 $lang['stuffs_no_options'] = 'Inga alternativ för denna enhet';
 $lang['Hide on home page'] = 'Göm på huvudsidan';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Messages d'infos
Index: /extensions/PWG_Stuffs/language/tr_TR/plugin.lang.php
===================================================================
--- /extensions/PWG_Stuffs/language/tr_TR/plugin.lang.php	(revision 9382)
+++ /extensions/PWG_Stuffs/language/tr_TR/plugin.lang.php	(revision 9383)
@@ -29,7 +29,13 @@
 $lang['stuffs_show_on_home'] = 'Ana sayfada';
 $lang['stuffs_show_on_cats'] = 'Tüm kategorilerdeki sayfalarda';
-$lang['stuffs_show_on_pictures'] = 'Resim sayfalarında';
+$lang['stuffs_show_on_picture'] = 'Resim sayfalarında';
 $lang['stuffs_no_options'] = 'Bu modül için seçenekler yok';
 $lang['Hide on home page'] = 'Ana sayfada gizle';
+
+/*TODO*/$lang['stuffs_perm'] = 'Activate authorization management:';
+/*TODO*/$lang['stuffs_group_perm'] = 'by groups';
+/*TODO*/$lang['stuffs_user_perm'] = 'by user type';
+/*TODO*/$lang['stuffs_level_perm'] = 'by privacy level';
+/*TODO*/$lang['stuffs_show_on_root'] = 'On root categories';
 
 //Bilgi mesajları
Index: /extensions/PWG_Stuffs/main.inc.php
===================================================================
--- /extensions/PWG_Stuffs/main.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/main.inc.php	(revision 9383)
@@ -9,9 +9,7 @@
 */
 
-define('STUFFS_VERSION', '2.1.m');
-
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-global $prefixeTable;
+global $prefixeTable, $conf;
 
 define('STUFFS_DIR' , basename(dirname(__FILE__)));
@@ -19,50 +17,74 @@
 define('STUFFS_TABLE' , $prefixeTable . 'stuffs');
 
+$conf['Stuffs'] = @unserialize($conf['PWG_Stuffs']);
+
 // Need upgrade?
-if ($plugin['version'] != STUFFS_VERSION)
+if ($conf['Stuffs'] === false)
   include('admin/upgrade.inc.php');
 
 function stuffs_admin_menu($menu)
 {
-    array_push($menu, array(
-      'NAME' => 'PWG Stuffs',
-      'URL' => get_admin_plugin_menu_link(STUFFS_PATH . 'admin/admin.php')));
-    return $menu;
+  array_push($menu, array(
+    'NAME' => 'PWG Stuffs',
+    'URL' => get_admin_plugin_menu_link(STUFFS_PATH . 'admin/admin.php')
+    )
+  );
+  return $menu;
 }
 
-function set_stuffs_on_index()
+function load_stuffs()
 {
-  global $page;
+  global $template;
 
-  if (isset($page['section']) and $page['section'] == 'categories')
+  include(STUFFS_PATH . 'include/class.inc.php');
+  include(STUFFS_PATH . 'include/functions.inc.php');
+
+  $template->set_template_dir(STUFFS_PATH.'theme/template/');
+  $template->set_filename('stuffs', 'stuffs_blocks.tpl');
+
+  $stuffs = new stuffs();
+
+  if (!empty($stuffs->blocks['begin']))
   {
-    include_once(STUFFS_PATH . 'include/stuffs.inc.php');
+    $template->assign('blocks', $stuffs->blocks['begin']);
+    $template->concat($stuffs->template_var['begin'],  $template->parse('stuffs', true));
+  }
+  if (!empty($stuffs->blocks['end']))
+  {
+    $template->assign('blocks', $stuffs->blocks['end']);
+    $template->concat($stuffs->template_var['end'],  $template->parse('stuffs', true));
   }
 }
 
-function set_stuffs_on_picture()
+function stuffs_section_init()
 {
-  include_once(STUFFS_PATH . 'include/stuffs.inc.php');
+  global $tokens, $page;
+
+  switch (script_basename())
+  {
+    case 'picture':
+      $page['stuffs_section'] = 'on_picture';
+      break;
+
+    case 'index':
+      if (count($tokens) == 1 and empty($tokens[0]))
+      {
+        $page['stuffs_section'] = 'on_home';
+        break;
+      }
+      elseif (isset($page['section']) and $page['section'] == 'categories')
+      {
+        $page['stuffs_section'] = isset($page['category']) ? 'on_cats' : 'on_root';
+        break;
+      }
+
+      default: return;
+  }
+
+  add_event_handler('loc_begin_page_header', 'load_stuffs');
 }
 
 add_event_handler('get_admin_plugin_menu_links', 'stuffs_admin_menu');
-add_event_handler('loc_begin_index', 'set_stuffs_on_index');
-add_event_handler('loc_begin_picture', 'set_stuffs_on_picture');
+add_event_handler('loc_end_section_init', 'stuffs_section_init', 60);
 
-function set_is_homepage()
-{
-  global $tokens, $page;
-
-  $next_token = 0;
-  $parsed_url = parse_section_url($tokens, $next_token);
-  if (!isset($parsed_url['section']) and !isset($page['chronology_field']))
-  {
-    $page['is_homepage'] = true;
-  }
-  else
-  {
-    $page['is_homepage'] = false;
-  }
-}
-add_event_handler('loc_end_section_init', 'set_is_homepage');
 ?>
Index: /extensions/PWG_Stuffs/maintain.inc.php
===================================================================
--- /extensions/PWG_Stuffs/maintain.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/maintain.inc.php	(revision 9383)
@@ -16,11 +16,13 @@
 `name` text NOT NULL,
 `descr` varchar(255) default NULL,
-`type` varchar(255) NOT NULL,
 `path` varchar(255) default NULL,
+`parent` varchar(255) default NULL,
 `datas` longtext default NULL,
 `users` varchar(255) default NULL,
 `groups` varchar(255) default NULL,
+`level` TINYINT( 3 ) NOT NULL default "0",
 `show_title` enum(\'true\',\'false\') NOT NULL,
 `on_home` enum(\'true\',\'false\') NOT NULL,
+`on_root` enum(\'true\',\'false\') NOT NULL,
 `on_cats` enum(\'true\',\'false\') NOT NULL,
 `on_picture` enum(\'true\',\'false\') NOT NULL,
@@ -34,19 +36,20 @@
     pwg_query($q);
   
-    $q = "INSERT INTO `" . $prefixeTable . "stuffs` (`id`, `pos`, `name`, `descr`, `type`, `path`, `datas`, `users`, `groups`, `show_title`, `on_home`, `on_cats`, `on_picture`, `id_line`, `width`) 
-VALUES (0, 1, 'MainBlock', NULL, 'MainBlock', NULL, NULL, 'guest,generic,normal,admin,webmaster', NULL, 'true', 'true', 'true', 'true', NULL, NULL);";
+    $q = "INSERT INTO `" . $prefixeTable . "stuffs` (`id`, `pos`, `name`, `users`, `show_title`, `on_home`, `on_cats`, `on_picture`) 
+VALUES (0, 1, 'MainBlock', 'guest,generic,normal,admin,webmaster', 'true', 'true', 'true', 'true');";
     pwg_query($q);
   }
-}
 
-function plugin_activate($id, $version)
-{
-  global $plugins, $prefixeTable;
+  if (!isset($conf['PWG_Stuffs']))
+  {
+    $config = array(
+      'level_perm' => false,
+      'group_perm' => false,
+      'user_perm' => false,
+    );
 
-  // Check if upgrade is needed
-  if ($version != $plugins->fs_plugins[$id]['version'])
-  {
-    define('STUFFS_VERSION', $plugins->fs_plugins[$id]['version']);
-    include('admin/upgrade.inc.php');
+    $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
+VALUES ("PWG_Stuffs" , "'.pwg_db_real_escape_string(serialize($config)).'" , "PWG Stuffs configuration");';
+    pwg_query($query);
   }
 }
@@ -54,8 +57,11 @@
 function plugin_uninstall()
 {
-    global $prefixeTable;
+  global $prefixeTable;
 
   $q = 'DROP TABLE ' . $prefixeTable . 'stuffs;';
-    pwg_query($q);
+  pwg_query($q);
+
+	$q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="PWG_Stuffs";';
+  pwg_query($q);
 }
 
Index: /extensions/PWG_Stuffs/modules/BestRated/config.inc.php
===================================================================
--- /extensions/PWG_Stuffs/modules/BestRated/config.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/BestRated/config.inc.php	(revision 9383)
@@ -29,5 +29,6 @@
   'NB_IMAGES' => $datas['nb_images'],
   'cat_display' => $datas['cat_display'],
-  'category_selected' => $datas['cat_selection']
+  'category_selected' => $datas['cat_selection'],
+  'on_picture_option' => false,
 ));
 
Index: /extensions/PWG_Stuffs/modules/BestRated/config.tpl
===================================================================
--- /extensions/PWG_Stuffs/modules/BestRated/config.tpl	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/BestRated/config.tpl	(revision 9383)
@@ -82,6 +82,4 @@
   }
 }
-
-jQuery("table:eq(1) tr:eq(5)").hide();
 </script>
 {/literal}
Index: /extensions/PWG_Stuffs/modules/MostVisited/config.inc.php
===================================================================
--- /extensions/PWG_Stuffs/modules/MostVisited/config.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/MostVisited/config.inc.php	(revision 9383)
@@ -29,5 +29,6 @@
   'NB_IMAGES' => $datas['nb_images'],
   'cat_display' => $datas['cat_display'],
-  'category_selected' => $datas['cat_selection']
+  'category_selected' => $datas['cat_selection'],
+  'on_picture_option' => false,
 ));
 
Index: /extensions/PWG_Stuffs/modules/MostVisited/config.tpl
===================================================================
--- /extensions/PWG_Stuffs/modules/MostVisited/config.tpl	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/MostVisited/config.tpl	(revision 9383)
@@ -82,6 +82,4 @@
   }
 }
-
-jQuery("table:eq(1) tr:eq(5)").hide();
 </script>
 {/literal}
Index: /extensions/PWG_Stuffs/modules/Random/config.inc.php
===================================================================
--- /extensions/PWG_Stuffs/modules/Random/config.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/Random/config.inc.php	(revision 9383)
@@ -29,5 +29,6 @@
   'NB_IMAGES' => $datas['nb_images'],
   'cat_display' => $datas['cat_display'],
-  'category_selected' => $datas['cat_selection']
+  'category_selected' => $datas['cat_selection'],
+  'on_picture_option' => false,
 ));
 
Index: /extensions/PWG_Stuffs/modules/Random/config.tpl
===================================================================
--- /extensions/PWG_Stuffs/modules/Random/config.tpl	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/Random/config.tpl	(revision 9383)
@@ -82,6 +82,4 @@
   }
 }
-
-jQuery("table:eq(1) tr:eq(5)").hide();
 </script>
 {/literal}
Index: /extensions/PWG_Stuffs/modules/Recent/config.inc.php
===================================================================
--- /extensions/PWG_Stuffs/modules/Recent/config.inc.php	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/Recent/config.inc.php	(revision 9383)
@@ -29,5 +29,6 @@
   'NB_IMAGES' => $datas['nb_images'],
   'cat_display' => $datas['cat_display'],
-  'category_selected' => $datas['cat_selection']
+  'category_selected' => $datas['cat_selection'],
+  'on_picture_option' => false,
 ));
 
Index: /extensions/PWG_Stuffs/modules/Recent/config.tpl
===================================================================
--- /extensions/PWG_Stuffs/modules/Recent/config.tpl	(revision 9382)
+++ /extensions/PWG_Stuffs/modules/Recent/config.tpl	(revision 9383)
@@ -82,6 +82,4 @@
   }
 }
-
-jQuery("table:eq(1) tr:eq(5)").hide();
 </script>
 {/literal}
