| 1 |
2
|
Manuela
|
<?php
|
| 2 |
|
|
|
| 3 |
|
|
/*
|
| 4 |
|
|
* To change this license header, choose License Headers in Project Properties.
|
| 5 |
|
|
* To change this template file, choose Tools | Templates
|
| 6 |
|
|
* and open the template in the editor.
|
| 7 |
|
|
*/
|
| 8 |
|
|
|
| 9 |
|
|
/**
|
| 10 |
|
|
* Description of settings_helper
|
| 11 |
|
|
*
|
| 12 |
|
|
* @category Core
|
| 13 |
|
|
* @package Core package
|
| 14 |
|
|
* @subpackage Name of subpackage if needed
|
| 15 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
| 16 |
|
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
| 17 |
|
|
* @license GNU General Public License 3.0
|
| 18 |
|
|
* @version 0.0.0
|
| 19 |
|
|
* @revision $Revision$
|
| 20 |
|
|
* @lastmodified $Date$
|
| 21 |
|
|
* @since File available since 18.05.2016
|
| 22 |
|
|
* @deprecated no / since 0000/00/00
|
| 23 |
|
|
* @description xxx
|
| 24 |
|
|
*/
|
| 25 |
|
|
|
| 26 |
|
|
class SettingsHelper
|
| 27 |
|
|
{
|
| 28 |
|
|
|
| 29 |
|
|
/**
|
| 30 |
|
|
* get a list of possible allowed parent pages
|
| 31 |
|
|
* @param integer $iParent
|
| 32 |
|
|
* @param integer $iCurrentPage
|
| 33 |
|
|
* @param object $admin
|
| 34 |
|
|
* @param object $database
|
| 35 |
|
|
* @return array
|
| 36 |
|
|
*/
|
| 37 |
|
|
static public function getParentPagesList($iParent, $iCurrentPage, $admin, $database)
|
| 38 |
|
|
{
|
| 39 |
|
|
$aRetval = array();
|
| 40 |
|
|
$aNeededFields = array('id', 'title', 'language', 'active');
|
| 41 |
|
|
$sql = 'SELECT *, `page_id` `id`, `menu_title` `title` '
|
| 42 |
|
|
. 'FROM `'.TABLE_PREFIX.'pages` '
|
| 43 |
|
|
. 'WHERE `parent`='.$iParent.' AND '
|
| 44 |
|
|
. '`level`<'.(PAGE_LEVEL_LIMIT - 1).', AND '
|
| 45 |
|
|
. '(SELECT FIND_IN_SET('.$iCurrentPage.', `page_trail`))<(`level`+1) '
|
| 46 |
|
|
. 'ORDER BY `position` ASC';
|
| 47 |
|
|
if (($oPages = $database->query($sql))) {
|
| 48 |
|
|
while (($aPage = $oPages->fetchRow(MYSQLI_ASSOC))) {
|
| 49 |
|
|
// skip this page and its children if page is not visible for current user
|
| 50 |
|
|
if (!$admin->page_is_visible($aPage)) { continue; }
|
| 51 |
|
|
// check if current user has admin or owner permissions for this page
|
| 52 |
|
|
$aPage['active'] = (bool)(
|
| 53 |
|
|
$admin->ami_group_member($aPage['admin_groups'])
|
| 54 |
|
|
|| $admin->is_group_match($admin->get_user_id(), $aPage['admin_users'])
|
| 55 |
|
|
|| $aPage['page_owner'] == $admin->get_user_id()
|
| 56 |
|
|
);
|
| 57 |
|
|
// Title -'s prefix
|
| 58 |
|
|
$aPage['title'] = str_repeat('- ', $aPage['level']).$aPage['title'];
|
| 59 |
|
|
// if parent = 0 set flag_icon
|
| 60 |
|
|
$aPage['language'] = $aPage['parent'] ? '' : $aPage['language'];
|
| 61 |
|
|
// remove unneeded fields from record and add record to retval
|
| 62 |
|
|
$aRetval[] = array_intersect_key($aPage, $aNeededFields);
|
| 63 |
|
|
// check for children
|
| 64 |
|
|
$aRetval = array_merge(
|
| 65 |
|
|
$aRetval,
|
| 66 |
|
|
self::getParentPagesList($aPage['id'], $iCurrentPage, $admin, $database)
|
| 67 |
|
|
);
|
| 68 |
|
|
}
|
| 69 |
|
|
}
|
| 70 |
|
|
return $aRetval;
|
| 71 |
|
|
} // end of method getParentPagesList()
|
| 72 |
|
|
/**
|
| 73 |
|
|
* get a list of possible language reference pages
|
| 74 |
|
|
* @param integer $iParent
|
| 75 |
|
|
* @param string $sCurrentPageLanguage
|
| 76 |
|
|
* @param object $admin
|
| 77 |
|
|
* @param object $database
|
| 78 |
|
|
* @return array
|
| 79 |
|
|
*/
|
| 80 |
|
|
static public function getPageCodeList($iParent, $sCurrentPageLanguage, $admin, $database)
|
| 81 |
|
|
{
|
| 82 |
|
|
$aRetval = array();
|
| 83 |
|
|
// there is no intlRef to choose if current page is set to DEFAULT_LANGUAGE
|
| 84 |
|
|
if (DEFAULT_LANGUAGE != $sCurrentPageLanguage) {
|
| 85 |
|
|
$aNeededFields = array('id', 'title', 'language', 'active', 'intlRef');
|
| 86 |
|
|
$sql = 'SELECT *, `page_id` `id`, `menu_title` `title`, `page_code` `intlRef` '
|
| 87 |
|
|
. 'FROM `'.TABLE_PREFIX.'pages` '
|
| 88 |
|
|
. 'WHERE `parent`='.$iParent.' AND '
|
| 89 |
|
|
. '`level`<'.(PAGE_LEVEL_LIMIT - 1).', AND '
|
| 90 |
|
|
. '`language`=\''.DEFAULT_LANGUAGE.'\' '
|
| 91 |
|
|
. 'ORDER BY `position` ASC';
|
| 92 |
|
|
if (($oPages = $database->query($sql))) {
|
| 93 |
|
|
while (($aPage = $oPages->fetchRow(MYSQLI_ASSOC))) {
|
| 94 |
|
|
// skip this page and its children if page is not visible for current user
|
| 95 |
|
|
if (!$admin->page_is_visible($aPage)) { continue; }
|
| 96 |
|
|
// check if current user has admin or owner permissions for this page
|
| 97 |
|
|
$aPage['active'] = (bool)(
|
| 98 |
|
|
$admin->ami_group_member($aPage['admin_groups'])
|
| 99 |
|
|
|| $admin->is_group_match($admin->get_user_id(), $aPage['admin_users'])
|
| 100 |
|
|
|| $aPage['page_owner'] == $admin->get_user_id()
|
| 101 |
|
|
);
|
| 102 |
|
|
// Title -'s prefix
|
| 103 |
|
|
$aPage['title'] = str_repeat('- ', $aPage['level']).$aPage['title'];
|
| 104 |
|
|
// if parent = 0 set flag_icon
|
| 105 |
|
|
$aPage['language'] = $aPage['parent'] ? '' : $aPage['language'];
|
| 106 |
|
|
// remove unneeded fields from record and add record to retval
|
| 107 |
|
|
$aRetval[] = array_intersect_key($aPage, $aNeededFields);
|
| 108 |
|
|
// check for children
|
| 109 |
|
|
$aRetval = array_merge(
|
| 110 |
|
|
$aRetval,
|
| 111 |
|
|
self::getPageCodeList($aPage['id'], $sCurrentPageLanguage, $admin, $database)
|
| 112 |
|
|
);
|
| 113 |
|
|
}
|
| 114 |
|
|
}
|
| 115 |
|
|
}
|
| 116 |
|
|
return $aRetval;
|
| 117 |
|
|
} // end of method getPageCodeList()
|
| 118 |
|
|
/**
|
| 119 |
|
|
*
|
| 120 |
|
|
* @param array $aList
|
| 121 |
|
|
* @param string $sSortBy1
|
| 122 |
|
|
* @param string $sSortBy2
|
| 123 |
|
|
* @return array the sorted array
|
| 124 |
|
|
*/
|
| 125 |
|
|
|
| 126 |
|
|
static function orderByColumn($aList)
|
| 127 |
|
|
{
|
| 128 |
|
|
$args = func_get_args();
|
| 129 |
|
|
array_shift($args);
|
| 130 |
|
|
|
| 131 |
|
|
}
|
| 132 |
|
|
|
| 133 |
|
|
|
| 134 |
|
|
static function doMultiSort($aList, $sSortBy1, $sSortBy2)
|
| 135 |
|
|
{
|
| 136 |
|
|
foreach ($aList as $key => $row) {
|
| 137 |
|
|
${$sSortBy1}[$key] = $row[$sSortBy1];
|
| 138 |
|
|
${$sSortBy2}[$key] = $row[$sSortBy2];
|
| 139 |
|
|
}
|
| 140 |
|
|
$iSortFlags = ((version_compare(PHP_VERSION, '5.4.0', '<'))?SORT_REGULAR:SORT_NATURAL|SORT_FLAG_CASE);
|
| 141 |
|
|
array_multisort(${$sSortBy1}, SORT_DESC, ${$sSortBy2}, SORT_ASC, $iSortFlags, $aList);
|
| 142 |
|
|
return $aList;
|
| 143 |
|
|
} // end of method doMultiSort()
|
| 144 |
|
|
|
| 145 |
|
|
} // end of class SettingsHelper
|