X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fadmin%2Fadmin-inc.php;h=ae6191a043e05021fe8b47ddbc5d7d0f1266c32a;hb=c9b2e406d8e94ffcff8bac9d453e671f337552e4;hp=15c2715924b0dd5f2f9004e762f01dc032de24bb;hpb=64bd945ec270b9ed5e0a2490b5631e02d4dc62d8;p=mailer.git
diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php
index 15c2715924..ae6191a043 100644
--- a/inc/modules/admin/admin-inc.php
+++ b/inc/modules/admin/admin-inc.php
@@ -177,10 +177,10 @@ function doAdminAction () {
// Load header, footer, render menu
$content['header'] = loadTemplate('admin_header' , true, $content);
$content['footer'] = loadTemplate('admin_footer' , true, $content);
- $content['menu'] = addAdminMenu($action, $what, true);
+ $content['menu'] = addAdminMenu($action, $what);
- // Tableset header
- loadTemplate('admin_main_header', false, $content);
+ // Load main template
+ loadTemplate('admin_main', false, $content);
// Check if action/what pair is valid
$result_action = SQL_QUERY_ESC("SELECT
@@ -248,18 +248,20 @@ function isAdminAllowedAccessMenu ($action, $what = NULL) {
}
// Adds an admin menu
-function addAdminMenu ($action, $what, $return = false) {
+function addAdminMenu ($action, $what) {
// Init variables
$SUB = false;
$OUT = '';
// Menu descriptions
$GLOBALS['menu']['description'] = array();
- $GLOBALS['menu']['title'] = array();
+ $GLOBALS['menu']['title'] = array();
// Build main menu
$result_main = SQL_QUERY("SELECT
- `action`,`title`,`descr`
+ `action` AS `main_action`,
+ `title` AS `main_title`,
+ `descr` AS `main_descr`
FROM
`{?_MYSQL_PREFIX?}_admin_menu`
WHERE
@@ -271,52 +273,76 @@ ORDER BY
// Do we have entries?
if (!SQL_HASZERONUMS($result_main)) {
$OUT .= '
';
- // @TODO Rewrite this to $content = SQL_FETCHARRAY()
- while (list($menu, $title, $descr) = SQL_FETCHROW($result_main)) {
+
+ // Load all 'action' menus
+ while ($mainContent = SQL_FETCHARRAY($result_main)) {
// Filename
- $inc = sprintf("inc/modules/admin/action-%s.php", $menu);
+ $inc = sprintf("inc/modules/admin/action-%s.php", $mainContent['main_action']);
// Is the file readable?
$readable = isIncludeReadable($inc);
// Is the current admin allowed to access this 'action' menu?
- if (isAdminAllowedAccessMenu($menu)) {
+ if (isAdminAllowedAccessMenu($mainContent['main_action'])) {
if ($SUB === false) {
// Insert compiled menu title and description
- $GLOBALS['menu']['title'][$menu] = $title;
- $GLOBALS['menu']['description'][$menu] = $descr;
+ $GLOBALS['menu']['title'][$mainContent['main_action']] = $mainContent['main_title'];
+ $GLOBALS['menu']['description'][$mainContent['main_action']] = $mainContent['main_descr'];
} // END - if
- $OUT .= '';
- // Check for menu entries
- $result_what = SQL_QUERY_ESC("SELECT
- `what`,`title`,`descr`
+ // Add sub menu
+ $OUT .= addAdminSubMenu($mainContent, $action, $what);
+ } // END - if
+ } // END - while
+
+ // Close ul-tag
+ $OUT .= '
';
+
+ // Free memory
+ SQL_FREERESULT($result_main);
+ } // END - if
+
+ // Return content
+ return $OUT;
+}
+
+// Add admin sub menu
+function addAdminSubMenu ($mainContent, $action, $what) {
+ // Init content
+ $OUT = '';
+
+ // Check for menu entries
+ $result_what = SQL_QUERY_ESC("SELECT
+ `what` AS `sub_what`,
+ `title` AS `sub_title`,
+ `descr` AS `sub_descr`
FROM
`{?_MYSQL_PREFIX?}_admin_menu`
WHERE
@@ -326,78 +352,71 @@ WHERE
ORDER BY
`sort` ASC,
`id` DESC",
- array($menu), __FUNCTION__, __LINE__);
-
- // Remember the count for later checks
- setAdminMenuHasEntries($menu, ((!SQL_HASZERONUMS($result_what)) && ($action == $menu)));
-
- // Do we have entries?
- if ((ifAdminMenuHasEntries($menu)) && (!SQL_HASZERONUMS($result_what))) {
- $GLOBALS['menu']['description'] = array();
- $GLOBALS['menu']['title'] = array();
- $SUB = true;
- $OUT .= '';
+
+ // Return content
+ return $OUT;
}
// Create an admin selection box form
@@ -413,7 +432,9 @@ function addAdminSelectionBox ($adminId = NULL, $special = '') {
// Query all entries
$result = SQL_QUERY('SELECT
- `id`,`login`' . $ADD . '
+ `id`,
+ `login`
+ ' . $ADD . '
FROM
`{?_MYSQL_PREFIX?}_admins`
ORDER BY
@@ -675,7 +696,7 @@ function generateUserProfileLink ($userid, $title = '', $what = 'list_user') {
$title = $userid;
} elseif (!isValidUserId($userid)) {
// User id zero is invalid
- return '' . makeNullToZero($userid) . '';
+ return '' . convertNullToZero($userid) . '';
}
if (($title == '0') && ($what == 'list_refs')) {
@@ -889,7 +910,7 @@ function adminListBuilder ($listType, $tableName, $columns, $filterFunctions, $e
if ($key == $userIdColumn[0]) {
// Add it again as raw id
//* DEBUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'key=' . $key . ',userIdColumn=' . $userIdColumn[0]);
- $content[$userIdColumn[0]] = makeZeroToNull($value);
+ $content[$userIdColumn[0]] = convertZeroToNull($value);
$content[$userIdColumn[0] . '_raw'] = $content[$userIdColumn[0]];
} // END - if
@@ -1298,7 +1319,7 @@ function adminAddEntries ($tableName, $columns = array(), $filterFunctions = arr
$sqlValues = array();
// Add columns and values
- foreach ($columns as $key=>$columnName) {
+ foreach ($columns as $key => $columnName) {
// Copy entry to final arrays
$sqlColumns[$key] = $columnName;
$sqlValues[$key] = postRequestElement($columnName);
@@ -1312,7 +1333,7 @@ function adminAddEntries ($tableName, $columns = array(), $filterFunctions = arr
} // END - foreach
// Build the SQL query
- $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_' . $tableName[0] . '` (`' . implode('`, `', $sqlColumns) . "`) VALUES ('" . implode("','", $sqlValues) . "')";
+ $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_' . $tableName[0] . '` (`' . implode('`,`', $sqlColumns) . "`) VALUES ('" . implode("','", $sqlValues) . "')";
// Run the SQL query
SQL_QUERY($SQL, __FUNCTION__, __LINE__);
@@ -1372,7 +1393,7 @@ function adminListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tab
if (count($orderByColumns) > 0) {
// Add them as well
$SQL .= ' ORDER BY ';
- foreach ($orderByColumns as $orderByColumn=>$array) {
+ foreach ($orderByColumns as $orderByColumn => $array) {
// Get keys (table/alias) and values (sorting itself)
$table = trim(implode('', array_keys($array)));
$sorting = trim(implode('', array_keys($array)));
@@ -1406,7 +1427,7 @@ function doAdminListEntries ($SQL, $tableTemplate, $noEntryMessageId, $rowTempla
$OUT = '';
while ($content = SQL_FETCHARRAY($result)) {
// "Translate" content
- foreach ($callbackColumns as $columnName=>$callbackFunction) {
+ foreach ($callbackColumns as $columnName => $callbackFunction) {
// Fill the callback arguments
$args = array($content[$columnName]);
@@ -1611,7 +1632,7 @@ function adminCreateUserLink ($userid) {
// Generate a "link" for the given admin id (admin_id)
function generateAdminLink ($adminId) {
// No assigned admin is default
- $adminLink = '{--ADMIN_NO_ADMIN_ASSIGNED--}';
+ $adminLink = '{--ADMIN_NO_ADMIN_ASSIGNED--}';
// Zero? = Not assigned
if (bigintval($adminId) > 0) {
@@ -1630,7 +1651,7 @@ function generateAdminLink ($adminId) {
}
} else {
// Maybe deleted?
- $adminLink = '{%message,ADMIN_ID_404=' . $adminId . '%}
';
+ $adminLink = '{%message,ADMIN_ID_404=' . $adminId . '%}
';
}
} // END - if
@@ -1797,40 +1818,49 @@ function adminProcessMenuEditForm ($type, $subMenu) {
switch (postRequestElement('ok')) {
case 'edit': // Edit menu
- if (postRequestElement('sel_what', $sel) == '') {
+ // Shall we update a menu or sub menu?
+ if (!isGetRequestElementSet('sub')) {
// Update with 'what'=null
- SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s', `action`='%s', `what`=NULL WHERE ".$AND." AND `id`=%s LIMIT 1",
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`=NULL WHERE ".$AND." AND `id`=%s LIMIT 1",
array(
$type,
$menu,
postRequestElement('sel_action', $sel),
$sel
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
} else {
// Update with selected 'what'
- SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `title`='%s',`action`='%s',`what`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
array(
$type,
$menu,
postRequestElement('sel_action', $sel),
postRequestElement('sel_what', $sel),
$sel
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
}
break;
case 'delete': // Delete menu
SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE ".$AND." AND `id`=%s LIMIT 1",
- array($type, $sel), __FILE__, __LINE__);
+ array(
+ $type,
+ $sel
+ ), __FUNCTION__, __LINE__);
break;
case 'status': // Change status of menus
- SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
- array($type, postRequestElement('visible', $sel), postRequestElement('locked', $sel), $sel), __FILE__, __LINE__);
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `visible`='%s',`locked`='%s' WHERE ".$AND." AND `id`=%s LIMIT 1",
+ array(
+ $type,
+ postRequestElement('visible', $sel),
+ postRequestElement('locked', $sel),
+ $sel
+ ), __FUNCTION__, __LINE__);
break;
default: // Unexpected action
- logDebugMessage(__FILE__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestElement('ok') . '%}');
break;
} // END - switch
@@ -1855,7 +1885,7 @@ function doAdminProcessMenuWeightning ($type, $AND) {
$type,
getRequestElement('act'),
bigintval(getRequestElement('tid'))
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
list($tid) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
$result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `sort`=%s LIMIT 1",
@@ -1863,7 +1893,7 @@ function doAdminProcessMenuWeightning ($type, $AND) {
$type,
getRequestElement('act'),
bigintval(getRequestElement('fid'))
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
list($fid) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
} else {
@@ -1872,14 +1902,14 @@ function doAdminProcessMenuWeightning ($type, $AND) {
array(
$type,
bigintval(getRequestElement('tid'))
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
list($tid) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
$result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`=%s LIMIT 1",
array(
$type,
bigintval(getRequestElement('fid'))
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
list($fid) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
}
@@ -1891,13 +1921,13 @@ function doAdminProcessMenuWeightning ($type, $AND) {
$type,
bigintval(getRequestElement('tid')),
bigintval($fid)
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `sort`=%s WHERE ".$AND." AND `id`=%s LIMIT 1",
array(
$type,
bigintval(getRequestElement('fid')),
bigintval($tid)
- ), __FILE__, __LINE__);
+ ), __FUNCTION__, __LINE__);
} // END - if
} // END - if
}