A lot texts rewritten and exclamation signs removed
[mailer.git] / inc / modules / admin / what-config_admins.php
index c20a8c4..5d36456 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Admin-ACLs einstellen                            *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
 }
+
 // Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+addMenuDescription('admin', __FILE__);
 
 $SEL = 0;
-if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']);
+if (isPostRequestElementSet('sel')) $SEL = countPostSelection();
 
-if ((isset($_POST['edit'])) && ($SEL > 0))
-{
+if ((isPostRequestElementSet('edit')) && ($SEL > 0)) {
        // Edit ACLs
-       $SW = 2; $OUT = "";
-       foreach ($_POST['sel'] as $id=>$sel)
-       {
-               // Load data for the ID
-               $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM "._MYSQL_PREFIX."_admins_acls WHERE id=%d LIMIT 1",
-                array(bigintval($id)), __FILE__, __LINE__);
-               list($aid, $act, $wht, $mode) = SQL_FETCHROW($result);
+       $OUT = ''; $SW = 2;
+       foreach (postRequestElement('sel') as $id => $selected) {
+               // Load data for the id
+               $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)), __FILE__, __LINE__);
+               list($adminId, $action, $what, $mode) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
 
                // Prepare data for the row template
                $content = array(
                        'sw'               => $SW,
                        'id'               => $id,
-                       'admins_selection' => ADD_OPTION_LINES("admins", "id", "login", $aid, "default_acl"),
-                       'action_selection' => ADMIN_MENU_SELECTION("action", $act, $id),
-                       'what_selection'   => ADMIN_MENU_SELECTION("what", $wht, $id),
-                       'mode_options'     => ADD_OPTION_LINES(
-                               "/ARRAY/",
-                               array("allow", "deny"),
-                               array(ADMINS_ALLOW_MODE, ADMINS_DENY_MODE),
+                       'admins_selection' => generateOptionList('admins', 'id', 'login', $adminId, 'default_acl'),
+                       'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $action, $id),
+                       'what_selection'   => adminMenuSelectionBox_DEPRECATED('what', $what, $id),
+                       'mode_options'     => generateOptionList(
+                               '/ARRAY/',
+                               array('allow', 'deny'),
+                               array(
+                                       getMessage('ADMINS_ALLOW_MODE'),
+                                       getMessage('ADMINS_DENY_MODE')
+                               ),
                                $mode
                        ),
                );
 
                // Load row template
-               $OUT .= LOAD_TEMPLATE("admin_config_admins_edit_row", true, $content);
+               $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
                $SW = 3 - $SW;
        }
-       define('__ACL_ROWS', $OUT);
 
        // Load main template
-       LOAD_TEMPLATE("admin_config_admins_edit");
-}
- elseif ((isset($_POST['change'])) && ($SEL > 0))
-{
+       loadTemplate('admin_config_admins_edit', false, $OUT);
+} elseif ((isPostRequestElementSet('change')) && ($SEL > 0)) {
        // Change entries
-       foreach ($_POST['sel'] as $id=>$sel)
-       {
-               // Secure ID
+       foreach (postRequestElement('sel') as $id => $selected) {
+               // Secure id
                $id = bigintval($id);
 
                // Update entries
-               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins_acls SET admin_id=%d, action_menu='%s', what_menu='%s', access_mode='%s' WHERE id=%d LIMIT 1",
-                array($_POST['admin'][$id], $_POST['action_menu'][$id], $_POST['what_menu'][$id], $_POST['mode'][$id], $id),__FILE__, __LINE__);
-       }
+               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_acls` SET admin_id=%s, action_menu='%s', what_menu='%s', access_mode='%s' WHERE `id`=%s LIMIT 1",
+               array(
+                       postRequestElement('admin', $id),
+                       postRequestElement('action_menu', $id),
+                       postRequestElement('what_menu', $id),
+                       postRequestElement('mode', $id),
+                       $id
+               ),__FILE__, __LINE__);
+       } // END - foreach
 
        // Update cache when installed
-       if (EXT_IS_ACTIVE("cache"))
-       {
-               if ($cacheInstance->cache_file("admins_acls", true) == true) $cacheInstance->cache_destroy();
-       }
+       if (isExtensionActive('cache')) {
+               if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
+       } // END - if
 
        // Entries changed
-       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ADMINS_ENTRIES_CHANGED);
-}
- elseif ((isset($_POST['del'])) && ($SEL > 0))
-{
+       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
+} elseif ((isPostRequestElementSet('del')) && ($SEL > 0)) {
        // Delete ACLs
-       $SW = 2; $OUT = "";
-       foreach ($_POST['sel'] as $id=>$sel)
-       {
-               // Load data for the ID
-               $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM "._MYSQL_PREFIX."_admins_acls WHERE id=%d LIMIT 1",
-                array(bigintval($id)), __FILE__, __LINE__);
-               list($admin, $act, $wht, $mode) = SQL_FETCHROW($result);
+       $OUT = ''; $SW = 2;
+       foreach (postRequestElement('sel') as $id => $selected) {
+               // Load data for the id
+               $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)), __FILE__, __LINE__);
+               list($admin, $action, $what, $mode) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
 
                // Prepare variables
-               if (empty($act)) $act = "---";
-               if (empty($wht))   $wht   = "---";
-               $eval = "\$mode = ADMINS_".strtoupper($mode)."_MODE;";
-               eval($eval);
-
-               // Load admin's data
-               $login = GET_ADMIN_LOGIN($admin);
-               if ($login != "***")
-               {
-                       // Admin found
-                       $admin = "<A href=\"".URL."/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</A>";
-               }
-                else
-               {
-                       // Maybe deleted?
-                       $admin = "<FONT class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</FONT>";
-               }
+               if (empty($action)) $action = '---';
+               if (empty($what)) $what = '---';
+
+               // Get admin mode
+               $mode = getMessage('ADMINS_'.strtoupper($mode).'_MODE');
+
+               // Generate link
+               $admin = generateAdminLink($admin);
 
                // Prepare data for the row template
                $content = array(
                        'sw'     => $SW,
                        'id'     => $id,
                        'admin'  => $admin,
-                       'action' => $act,
-                       'what'   => $wht,
+                       'action' => $action,
+                       'what'   => $what,
                        'mode'   => $mode,
                );
 
                // Load row template and switch colors
-               $OUT .= LOAD_TEMPLATE("admin_config_admins_del_row", true, $content);
+               $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
                $SW = 3 - $SW;
-       }
-       define('__ACL_ROWS', $OUT);
+       } // END - foreach
 
        // Load main template
-       LOAD_TEMPLATE("admin_config_admins_del");
-}
- elseif ((isset($_POST['remove'])) && ($SEL > 0))
-{
+       loadTemplate('admin_config_admins_del', false, $OUT);
+} elseif ((isPostRequestElementSet('remove')) && ($SEL > 0)) {
        // Remove entries
-       foreach ($_POST['sel'] as $id=>$sel)
-       {
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admins_acls WHERE id=%d LIMIT 1",
-                array(bigintval($id)),__FILE__, __LINE__);
-       }
+       // @TODO Rewrite this to filter 'run_sqls'
+       foreach (postRequestElement('sel') as $id => $selected) {
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)),__FILE__, __LINE__);
+       } // END - foreach
 
        // Update cache when installed
-       if (EXT_IS_ACTIVE("cache"))
-       {
-               if ($cacheInstance->cache_file("admins_acls", true) == true) $cacheInstance->cache_destroy();
-       }
+       if (isExtensionActive('cache')) {
+               if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
+       } // END - if
 
        // Entries deleted
-       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ADMINS_ENTRIES_DELETED);
-}
- elseif (isset($_POST['add']))
-{
+       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_DELETED'));
+} elseif (isPostRequestElementSet('add')) {
        // Check if everything is fine...
-       $result = SQL_QUERY_ESC("SELECT default_acl FROM "._MYSQL_PREFIX."_admins WHERE id=%d LIMIT 1",
-        array(bigintval($_POST['admin_id'])), __FILE__, __LINE__);
-       list($mode) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
+       $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
 
        // Default ACL is false
        $ACL = false;
-       if (!empty($_POST['what_menu']))
-       {
+       if (isPostRequestElementSet('what_menu')) {
                // Check parent ACL
-               $ACL = ADMINS_CHECK_ACL(GET_ACTION("admin", $_POST['what_menu']), "");
-       }
+               $ACL = adminsCheckAdminAcl(getModeAction('admin', postRequestElement('what_menu')), '');
+       } // END - if
 
-       if ($mode != $_POST['mode'] || ($ACL))
-       {
+       if (($mode != postRequestElement('mode')) || ($ACL)) {
                // Mode is fine
-               $BOTH = ((!empty($_POST['action_menu'])) && (!empty($_POST['what_menu'])));
-               if (((!empty($_POST['action_menu'])) || (!empty($_POST['what_menu']))) && (!$BOTH))
-               {
+               $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')));
+               if (((isPostRequestElementSet('action_menu')) || (isPostRequestElementSet('what_menu'))) && ($BOTH === false)) {
                        // Main or sub menu selected
-                       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_admins_acls WHERE admin_id=%d AND action_menu='%s' AND what_menu='%s' LIMIT 1",
-                        array(bigintval($_POST['admin_id']), $_POST['action_menu'], $_POST['what_menu']), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 0)
-                       {
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE admin_id=%s AND action_menu='%s' AND what_menu='%s' LIMIT 1",
+                               array(bigintval(postRequestElement('admin_id')), postRequestElement('action_menu'), postRequestElement('what_menu')), __FILE__, __LINE__);
+                       if (SQL_NUMROWS($result) == 0) {
                                // Finally add the new ACL
-                               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admins_acls (admin_id, action_menu, what_menu, access_mode)
-VALUES ('%s', '%s', '%s', '%s')",
- array(
-       $_POST['admin_id'],
-       $_POST['action_menu'],
-       $_POST['what_menu'],
-       $_POST['mode']
-), __FILE__, __LINE__);
-                               $content = ADMIN_ADMINS_ACL_SAVED;
+                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
+VALUES ('%s','%s','%s','%s')",
                              array(
+                                       bigintval(postRequestElement('admin_id')),
+                                       postRequestElement('action_menu'),
+                                       postRequestElement('what_menu'),
+                                       postRequestElement('mode')
+                               ), __FILE__, __LINE__);
+                               $content = getMessage('ADMIN_ADMINS_ACL_SAVED');
 
                                // Update cache when installed
-                               if (EXT_IS_ACTIVE("cache"))
-                               {
-                                       if ($cacheInstance->cache_file("admins_acls", true) == true) $cacheInstance->cache_destroy();
-                               }
-                       }
-                        else
-                       {
+                               if (isExtensionActive('cache')) {
+                                       if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
+                               } // END - if
+                       } else {
                                // ACL does already exist!
-                               $content = ADMIN_ADMINS_ACL_ALREADY_ADDED;
+                               $content = getMessage('ADMIN_ADMINS_ACL_ALREADY_ADDED');
                        }
 
                        // Free memory
                        SQL_FREERESULT($result);
-               }
-                else
-               {
+               } else {
                        // No menu selected makes also no sence...
-                       $content = ADMIN_ADMINS_SELECT_ACTION_WHAT;
+                       $content = getMessage('ADMIN_ADMINS_SELECT_ACTION_WHAT');
                }
-       }
-        else
-       {
+       } else {
                // Same mode makes no sence...
-               $content = ADMIN_ADMINS_SAME_MODE_SELECTED;
+               $content = getMessage('ADMIN_ADMINS_SAME_MODE_SELECTED');
        }
 
        // Display message
-       LOAD_TEMPLATE("admin_settings_saved", false, $content);
-}
- else
-{
+       loadTemplate('admin_settings_saved', false, $content);
+} else {
        // List all ACLs
-       $result_acls = SQL_QUERY("SELECT id, admin_id, action_menu, what_menu, access_mode FROM "._MYSQL_PREFIX."_admins_acls ORDER BY admin_id, id", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result_acls) > 0)
-       {
+       $result_acls = SQL_QUERY('SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC, `id` ASC', __FILE__, __LINE__);
+
+       // Entries found?
+       if (SQL_NUMROWS($result_acls) > 0) {
                // List ACLs
-               $SW = 2; $OUT = "";
-               while(list($id, $admin, $act, $wht, $mode) = SQL_FETCHROW($result_acls))
-               {
+               $OUT = ''; $SW = 2;
+               while ($content = SQL_FETCHARRAY($result_acls)) {
                        // Prepare variables
-                       if (empty($act)) $act = "---";
-                       if (empty($wht))   $wht   = "---";
-                       $eval = "\$mode = ADMINS_".strtoupper($mode)."_MODE;";
-                       eval($eval);
-
-                       // Load admin's data
-                       $login = GET_ADMIN_LOGIN($admin);
-                       if ($login != "***")
-                       {
-                               // Admin found
-                               $admin = "<A href=\"".URL."/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</A>";
-                       }
-                        else
-                       {
-                               // Maybe deleted?
-                               $admin = "<FONT class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</FONT>";
-                       }
+                       if (empty($content['action_menu'])) $content['action_menu'] = '---';
+                       if (empty($content['what_menu']))   $content['what_menu']   = '---';
+
+                       // Get mode
+                       $content['access_mode'] = getMessage('ADMINS_'.strtoupper($content['access_mode']).'_MODE');
 
                        // Prepare data for the row template
                        $content = array(
                                'sw'     => $SW,
-                               'id'     => $id,
-                               'admin'  => $admin,
-                               'action' => $act,
-                               'what'   => $wht,
-                               'mode'   => $mode,
+                               'id'     => $content['id'],
+                               'admin'  => generateAdminLink($content['admin_id']),
+                               'action' => $content['action_menu'],
+                               'what'   => $content['what_menu'],
+                               'mode'   => $content['access_mode'],
                        );
 
                        // Load row template and switch colors
-                       $OUT .= LOAD_TEMPLATE("admin_config_admins_row", true, $content);
+                       $OUT .= loadTemplate('admin_config_admins_row', true, $content);
                        $SW = 3 - $SW;
-               }
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
-               define('__ACL_ROWS', $OUT);
 
                // Load main template
-               LOAD_TEMPLATE("admin_config_admins");
-       }
+               loadTemplate('admin_config_admins', false, $OUT);
+       } // END - if
 
        // Prepare some constants for the template
-       define('_ADMINS_SELECTION', ADD_OPTION_LINES("admins", "id", "login", "", "default_acl"));
-       define('_ACTION_SELECTION', ADMIN_MENU_SELECTION("action"));
-       define('_WHAT_SELECTION'  , ADMIN_MENU_SELECTION("what"));
-       define('_MODE_OPTIONS'    , ADD_OPTION_LINES("/ARRAY/", array("allow", "deny"), array(ADMINS_ALLOW_MODE, ADMINS_DENY_MODE)));
+       $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
+       $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
+       $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
+       $content['mode_options']     = generateOptionList(
+               '/ARRAY/',
+               array('allow', 'deny'),
+               array(
+                       getMessage('ADMINS_ALLOW_MODE'),
+                       getMessage('ADMINS_DENY_MODE')
+               )
+       );
 
        // Load template for adding new ACL
-       LOAD_TEMPLATE("admin_admins_add_acl");
+       loadTemplate('admin_admins_add_acl', false, $content);
 }
+
 //
 ?>