Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-memedit.php
index e47bea61681ba0a5efbb8c9a00b2d854777ae181..dc9b102b557ff25d3dc1c353b7ec28ba414e8c16 100644 (file)
  * $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 - 2009 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -42,261 +41,200 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 } // END - if
 
 // Add description as navigation point
-addMenuDescription('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
 // Do we edit/delete/change main menus or sub menus?
-$AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
+$AND = "(`what` = '' OR `what` IS NULL)"; $subMenu = '';
 
 if (isGetRequestElementSet('sub')) {
        $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", getRequestElement('sub'));
-       $SUB = getRequestElement('sub');
+       $subMenu = getRequestElement('sub');
 } // END - if
 
 // List all menu points and make them editable
-if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
+if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
        // Edit menu entries
-       $content['sub'] = $SUB;
+       $content['sub'] = $subMenu;
        $content['chk'] = countPostSelection();
-       $SW = 2; $cnt = '0'; $OUT = '';
+       $count = '0'; $OUT = '';
        foreach (postRequestElement('sel') as $sel => $confirm) {
                if ($confirm == 1) {
-                       $cnt++;
-                       $result = SQL_QUERY_ESC("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
+                       $count++;
+                       $result = sqlQueryEscaped("SELECT `title`, `action`, `what` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
                                array(bigintval($sel)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1) {
+                       if (sqlNumRows($result) == 1) {
                                // Entry found so we load the stuff...
-                               $data = SQL_FETCHARRAY($result);
-                               $data = array(
-                                       'cnt'    => $cnt,
+                               $content = sqlFetchArray($result);
+                               $content = array(
+                                       'count'  => $count,
                                        'sel'    => $sel,
-                                       'menu'   => $data['title'],
-                                       'sw'     => $SW,
-                                       'act'    => adminAddMenuSelectionBox('member', 'act' , 'sel_act['  . $sel . ']', $data['action']),
-                                       'what'   => adminAddMenuSelectionBox('member', 'what', 'sel_what[' . $sel . ']', $data['what']),
+                                       'menu'   => $content['title'],
+                                       'action' => adminAddMenuSelectionBox('member', 'action', 'sel_action[' . $sel . ']', $content['action']),
+                                       'what'   => adminAddMenuSelectionBox('member', 'what'  , 'sel_what[' . $sel . ']', $content['what']),
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_mmenu_edit_row', true, $data);
+                               $OUT .= loadTemplate('admin_edit_member_menu_row', TRUE, $content);
                        } else {
                                // Entry not found?
-                               $data = array(
-                                       'sw'  => $SW,
+                               $content = array(
                                        'sel' => $sel
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_menu_404_row', true, $data);
+                               $OUT .= loadTemplate('admin_menu_404_row', TRUE, $content);
                        }
-                       SQL_FREERESULT($result);
-                       $SW = 3 - $SW;
-               }
-       }
-       $content['rows'] = $OUT;
-       $content['cnt'] = $cnt;
+                       sqlFreeResult($result);
+               } // END - if
+       } // END - foreach
+
+       // Add row content and current counter
+       $content['rows']  = $OUT;
+       $content['chk']   = countPostSelection();
+       $content['sub']   = $subMenu;
+       $content['count'] = $count;
 
        // Load template
-       loadTemplate('admin_mmenu_edit', false, $content);
-} elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
+       loadTemplate('admin_edit_member_menu', FALSE, $content);
+} elseif ((isFormSent('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
        // Del menu entries with or without confirmation
-       $content['sub'] = $SUB;
+       $content['sub'] = $subMenu;
        $content['chk'] = countPostSelection();
-       $SW = 2; $cnt = '0'; $OUT = '';
+       $count = '0'; $OUT = '';
        foreach (postRequestElement('sel') as $sel => $confirm) {
                if ($confirm == 1) {
-                       $cnt++;
-                       $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
+                       $count++;
+                       $result = sqlQueryEscaped("SELECT `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
                                array(bigintval($sel)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1) {
+                       if (sqlNumRows($result) == 1) {
                                // Entry found so we load the stuff...
-                               list($title) = SQL_FETCHROW($result);
+                               list($title) = sqlFetchRow($result);
                                $content = array(
-                                       'cnt'   => $cnt,
+                                       'count' => $count,
                                        'sel'   => $sel,
                                        'title' => $title
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_mmenu_delete_row', true, $content);
+                               $OUT .= loadTemplate('admin_delete_member_menu_row', TRUE, $content);
                        } else {
                                // Entry not found?
                                $content = array(
-                                       'sw'  => $SW,
                                        'sel' => $sel
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_menu_404_row', true, $content);
+                               $OUT .= loadTemplate('admin_menu_404_row', TRUE, $content);
                        }
-                       SQL_FREERESULT($result);
+                       sqlFreeResult($result);
                } // END - if
        } // END - foreach
-       $content['rows'] = $OUT;
-       $content['cnt'] = $cnt;
+
+       $content['rows']  = $OUT;
+       $content['chk']   = countPostSelection();
+       $content['sub']   = $subMenu;
+       $content['count'] = $count;
 
        // Load template
-       loadTemplate('admin_mmenu_delete', false, $content);
-} elseif ((isPostRequestElementSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
+       loadTemplate('admin_delete_member_menu', FALSE, $content);
+} elseif ((isPostRequestElementSet('status')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
        // Change status (visible / locked)
-       $content['sub'] = $SUB;
+       $content['sub'] = $subMenu;
        $content['chk'] = countPostSelection();
-       $SW = 2; $cnt = '0'; $OUT = '';
+       $count = '0'; $OUT = '';
        foreach (postRequestElement('sel') as $sel => $confirm) {
                if ($confirm == 1) {
-                       $cnt++;
-                       $result = SQL_QUERY_ESC("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
+                       $count++;
+                       $result = sqlQueryEscaped("SELECT `title`, `visible`, `locked` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
                                array(bigintval($sel)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1) {
+                       if (sqlNumRows($result) == 1) {
                                // Entry found so we load the stuff...
-                               $data = SQL_FETCHARRAY($result);
-                               $data = array(
-                                       'cnt'     => $cnt,
-                                       'menu'    => $data['title'],
+                               $content = sqlFetchArray($result);
+                               $content = array(
+                                       'count'   => $count,
+                                       'menu'    => $content['title'],
                                        'sel'     => $sel,
-                                       'sw'      => $SW,
-                                       'visible' => addSelectionBox('yn', $data['visible'], 'visible', $sel),
-                                       'locked'  => addSelectionBox('yn', $data['locked'] , 'locked' , $sel),
+                                       'visible' => addSelectionBox('yn', $content['visible'], 'visible', $sel),
+                                       'locked'  => addSelectionBox('yn', $content['locked'] , 'locked' , $sel),
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_menu_status_row', true, $data);
+                               $OUT .= loadTemplate('admin_menu_status_row', TRUE, $content);
                        } else {
                                // Entry not found?
-                               $data = array(
-                                       'sw'  => $SW,
+                               $content = array(
                                        'sel' => $sel
                                );
 
                                // Load template
-                               $OUT .= loadTemplate('admin_menu_404_row', true, $data);
+                               $OUT .= loadTemplate('admin_menu_404_row', TRUE, $content);
                        }
-                       SQL_FREERESULT($result);
-                       $SW = 3 - $SW;
+                       sqlFreeResult($result);
                } // END - if
        } // END - foreach
-       $content['rows'] = $OUT;
-       $content['cnt'] = $cnt;
 
-       // Load template
-       loadTemplate('admin_mmenu_status', false, $content);
-} elseif ((isFormSent()) && (!isDemoModeActive())) {
-       // An act is done...
-       foreach (postRequestElement('sel') as $sel => $menu) {
-               $AND = "(`what` = '' OR `what` IS NULL)";
-               $sel = bigintval($sel);
-               if (!empty($SUB)) $AND = "`action`='".$SUB."'";
-               switch (postRequestElement('ok')) {
-                       case 'edit': // Edit menu
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
-                                       array($menu, postRequestElement('sel_act', $sel), postRequestElement('sel_what', $sel), $sel), __FILE__, __LINE__);
-                               break;
-
-                       case 'del': // Delete menu
-                               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
-                                       array($sel), __FILE__, __LINE__);
-                               break;
-
-                       case 'status': // Change status of menus
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
-                                       array(postRequestElement('visible', $sel), postRequestElement('locked', $sel), $sel), __FILE__, __LINE__);
-                               break;
-               } // END - switch
-               break;
-       } // END - foreach
+       $content['rows']  = $OUT;
+       $content['chk']   = countPostSelection();
+       $content['sub']   = $subMenu;
+       $content['count'] = $count;
 
        // Load template
-       loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
+       loadTemplate('admin_member_menu_status', FALSE, $content);
+} elseif ((isFormSent()) && (!isDemoModeActive())) {
+       // Process menu editing form
+       adminProcessMenuEditForm('member', $subMenu);
 } else {
-       if ((isGetRequestElementSet('act')) && (isGetRequestElementSet('tid')) && (isGetRequestElementSet('fid'))) {
-               // Init
-               $tid = ''; $fid = '';
+       // Handle weightning
+       doAdminProcessMenuWeightning('member', $AND);
 
-               // Get ids
-               if (isGetRequestElementSet('w')) {
-                       // Sub menus selected
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
-                               array(bigintval(getRequestElement('act')), bigintval(getRequestElement('tid'))), __FILE__, __LINE__);
-                       list($tid) = SQL_FETCHROW($result);
-                       SQL_FREERESULT($result);
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
-                               array(bigintval(getRequestElement('act')), bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
-                       list($fid) = SQL_FETCHROW($result);
-                       SQL_FREERESULT($result);
-               } else {
-                       // Main menu selected
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
-                               array(bigintval(getRequestElement('tid'))), __FILE__, __LINE__);
-                       list($tid) = SQL_FETCHROW($result);
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
-                               array(bigintval(getRequestElement('fid'))), __FILE__, __LINE__);
-                       list($fid) = SQL_FETCHROW($result);
-               }
-
-               if ((!empty($tid)) && (!empty($fid))) {
-                       // Sort menu
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
-                               array(bigintval(getRequestElement('tid')), bigintval($fid)), __FILE__, __LINE__);
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `sort`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
-                               array(bigintval(getRequestElement('fid')), bigintval($tid)), __FILE__, __LINE__);
-               } // END - -fi
-       } // END - if
-
-       if (!empty($SUB)) {
+       if (!empty($subMenu)) {
                // Edit sub menus
-               $result = SQL_QUERY("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC", __FILE__, __LINE__);
+               $result = sqlQuery("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE ".$AND." AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC", __FILE__, __LINE__);
        } else {
                // Edit main menus
-               $result = SQL_QUERY("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
+               $result = sqlQuery("SELECT `id`, `action`, `what`, `title`, `sort` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
        }
 
-       // Get total menu entries
-       $max = SQL_NUMROWS($result);
-
        // Some are there?
-       if ($max > 0) {
-               // Set sub value
-               $content['sub'] = $SUB;
+       if (!ifSqlHasZeroNumRows($result)) {
+               $count = '0'; $OUT = '';
+               while ($content = sqlFetchArray($result)) {
+                       // Set sub value
+                       $content['sub'] = $subMenu;
 
-               $SW = 2; $cnt = '0'; $OUT = '';
-               while ($data = SQL_FETCHARRAY($result)) {
                        // Init navigation
-                       $data['navi'] = '';
-                       $cnt++;
-                       if (($data['sort'] == '0') || (($data['sort'] == 1) && (!empty($SUB)))) {
+                       $content['navi'] = '';
+                       $count++;
+                       if (($content['sort'] == '0') || (($content['sort'] == 1) && (!empty($subMenu)))) {
                                // Is highest position
-                               $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
-                       } elseif ($cnt == $max) {
+                               $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
+                       } elseif ($count == sqlNumRows($result)) {
                                // Is lowest position
-                               $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>';
-                       } elseif ($data['sort'] > 0) {
+                               $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']-1) . '&amp;fid=' . $content['sort'] . '%}">{--HIGHER--}</a>';
+                       } elseif ($content['sort'] > 0) {
                                // Anything else between highest and lowest
-                               $data['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=adminedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']-1) . '&amp;fid=' . $data['sort'] . '%}">{--HIGHER--}</a>/<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $data['action'] . '&amp;w=' . $data['what'] . '&amp;tid=' . ($data['sort']+1) . '&amp;fid=' . $data['sort'] . '%}">{--LOWER--}</a>';
+                               $content['navi'] = '<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']-1) . '&amp;fid=' . $content['sort'] . '%}">{--HIGHER--}</a>|<a href="{%url=modules.php?module=admin&amp;what=memedit&amp;sub=' . $content['sub'] . '&amp;act=' . $content['action'] . '&amp;w=' . $content['what'] . '&amp;tid=' . ($content['sort']+1) . '&amp;fid=' . $content['sort'] . '%}">{--LOWER--}</a>';
                        }
 
-                       // Fix empty values for Firefox
-                       if (empty($data['action'])) $data['action'] = '&nbsp;';
-                       if (empty($data['what']))   $data['what']   = '&nbsp;';
-                       if (empty($data['title']))  $data['title']  = '&nbsp;';
-
                        // Add more entries
-                       $data['sw']   = $SW;
-                       $data['mode'] = 'mem';
+                       $content['do'] = 'mem';
 
                        // Load row template and switch color
-                       $OUT .= loadTemplate('admin_menu_overview_row', true, $data);
-                       $SW = 3 - $SW;
+                       $OUT .= loadTemplate('admin_menu_overview_row', TRUE, $content);
                } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
-               // Remember rows in array
+               // Remember rows/sub in array
                $content['rows'] = $OUT;
+               $content['sub']  = $subMenu;
 
                // Load main template
-               loadTemplate('admin_mmenu_overview', false, $content);
+               loadTemplate('admin_member_menu_overview', FALSE, $content);
        } else {
                // Menu entries are missing... (???)
-               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));
+               displayMessage('{--ADMIN_NO_MENUS_FOUND--}');
        }
 }