Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: settings-x.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/pages/settings-x.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
 */
18

    
19
// Create new admin object
20
    if (!defined('WB_PATH')) { require dirname(dirname((__DIR__))).'/config.php'; }
21
    if (!class_exists('admin', false)) { require WB_PATH.'/framework/class.admin.php'; }
22
    $admin = new admin('Pages', 'pages_settings');
23
// Include the WB functions file
24
    include __DIR__.'/settings_helper.php';
25
// Get page id from  HTML request and sanitize it
26
    if (!($page_id = intval(@$_GET['page_id']?:0))) {
27
        $admin->print_header();
28
        $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
29
    }
30
// load requested page
31
    $aPage = null;
32
    $sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
33
    if (($oResult = $database->query($sql))) {
34
        $aPage = $oResult->fetchRow(MSQL_ASSOC);
35
    }
36
    if (!$aPage) {
37
// throw error if no valid page received
38
        $admin->print_header();
39
        $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
40
    }
41
// check if current user has admin rights to that page
42
    if (!($admin->ami_group_member($aPage['admin_groups']) ||
43
         $admin->is_group_match($aPage['admin_users'], $admin->get_user_id()))
44
    ) {
45
        $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
46
    }
47
// check if user has owner rights for this page
48
    $bHasOwnerRight = ($admin->get_user_id() == $aPage['page_owner'] || $admin->get_user_id() == 1);
49
// restore SEO title from page-link
50
    $aPage['seo_title'] = basename($aPage['link']);
51
// add user data array to page
52
    $aPage['modified_by'] = $admin->get_user_details($aPage['modified_by']);
53

    
54
// prepare template data -------------------------------------------------------
55
    $aTmplDataGlobal = array();
56
    $aTmplData = array();
57
    $aTmplDataGlobal['page'] = $aPage;
58
    $aTmplDataGlobal['user'] = $admin->get_user_details($admin->get_user_id());
59
    $aTmplDataGlobal['user']['owner'] = $bHasOwnerRight;
60

    
61
// get sorted group lists ------------------------------------------------------
62
    $aAdmins = explode(',', $aPage['admin_groups']);
63
    $aViewers = explode(',', $aPage['viewing_groups']);
64
    $aList = array();
65
    $sql = 'SELECT `group_id` `id`, `name` '
66
         . 'FROM `'.TABLE_PREFIX.'groups` '
67
         . 'ORDER BY `name`';
68
    $oRecords = $database->query($sql);
69
    while ($aRecord = $oRecords->fetchRow(MYSQLI_ASSOC)) {
70
    // if group is set as admin to this page
71
        $aRecord['admin'] = in_array($aRecord['id'], $aAdmins);
72
    // if group ist set as viewer to this page
73
        $aRecord['viewer'] = in_array($aRecord['id'], $aViewers);
74
        $aList[] = $aRecord;
75
    }
76
// sort groups by admins
77
    $aTmplData['GroupListAdmin'] = SettingsHelper::doMultiSort($aList, 'admin', 'name');
78
// sort groups by viewers
79
    $aTmplData['GroupListViewer'] = SettingsHelper::doMultiSort($aList, 'viewer', 'name');
80
// get sorted user lists -------------------------------------------------------
81
    $aAdmins = explode(',', $aPage['admin_users']);
82
    $aViewers = explode(',', $aPage['viewing_users']);
83
    $aList = array();
84
    $sql = 'SELECT `user_id` `id`, `display_name` `name` '
85
         . 'FROM `'.TABLE_PREFIX.'users` '
86
         . 'ORDER BY `name`';
87
    $oRecords = $database->query($sql);
88
    while ($aRecord = $oRecords->fetchRow(MYSQLI_ASSOC)) {
89
    // if user is set as admin to this page
90
        $aRecord['admin'] = in_array($aRecord['id'], $aAdmins);
91
    // if user is set as viewer to this page
92
        $aRecord['viewer'] = in_array($aRecord['id'], $aViewers);
93
        $aList[] = $aRecord;
94
    }
95
// sort groups by admins
96
    $aTmplData['UserListAdmin'] = SettingsHelper::doMultiSort($aList, 'admin', 'name');
97
// sort groups by viewers
98
    $aTmplData['UserListViewer'] = SettingsHelper::doMultiSort($aList, 'viewer', 'name');
99
// clean up memory
100
    unset($aAdmins, $aViewers, $oRecords, $aRecord, $aList, $doMultiSort);
101
// add list of possible parent pages -------------------------------------------
102
    $aParentPages = SettingsHelper::getParentPagesList($aTmplDataGlobal['page']['page_id'], $iCurrentPage, $admin, $database);
103
// check for permission to add a level-0 page
104
    if ($admin->get_permission('pages_add_l0') || $results_array['level'] == 0) {
105
// add the option to choose level-0
106
        $aPage['id']       = 0;
107
        $aPage['title']    = $aLang['TEXT_NONE'];
108
        $aPage['language'] = '';
109
        $aPage['active']   = !$results_array['parent'];
110
        array_unshift($aParentPages, $aPage);
111
    }
112
    $aTmplData['ParentPages'] = $aParentPages;
113
// add list of linking targets -------------------------------------------------
114
    $aTmplData['LinkTargets'] = array(
115
        array('target' => '_top', 'caption' => $TEXT['TOP_FRAME']),
116
        array('target' => '_self', 'caption' => $TEXT['SAME_WINDOW']),
117
        array('target' => '_blank', 'caption' => $TEXT['NEW_WINDOW'])
118
    );
119
// build list of available templates -------------------------------------------
120
    $aTemplatesList = array();
121
    $sql = 'SELECT `directory`, `name`, `version` FROM `'.TABLE_PREFIX.'addons` '
122
         . 'WHERE `function` = \'template\' '
123
         . 'ORDER BY `name`';
124
    if (($oAddons = $database->query($sql))) {
125
        while (($aAddon = $oAddon->fetchRow(MYSQLI_ASSOC))) {
126
            $aTemplatesList[] = $aAddon;
127
        }
128
    }
129
    if (!$aTemplatesList) {
130
        $aTemplatesList[] = array('directory'=>'', 'name'=>'System Default', 'version'=>'');
131
    }
132
    $aTmplData['Templates'] = $aTemplatesList;
133
// get available menues from active template -----------------------------------
134
    $sTpl = WB_PATH.'/templates/'
135
          .($aPage['template'] ?: DEFAULT_TEMPLATE)
136
          .'/info.php';
137
    $aTemplateInfo = getContentFromInfoPhp(
138
        WB_PATH.'/templates/'.($aPage['template'] ?: DEFAULT_TEMPLATE).'/info.php'
139
    );
140
    if (!isset($aTemplateInfo['menu'])) {
141
        $aTemplateInfo['menu'] = array(1 => 'Main');
142
    }
143
    $aTmplData['Menues'] = $aTemplateInfo['menu'];
144
// get list of available languages ---------------------------------------------
145
    $sql = 'SELECT `directory`, `name`, `version` FROM `'.TABLE_PREFIX.'addons` '
146
         . 'WHERE `type` = \'language\' '
147
         . 'ORDER BY `name`';
148
    if (($oAddons = $database->query($sql))) {
149
        while (($aAddon = $oAddon->fetchRow(MYSQLI_ASSOC))) {
150
            $aLanguageList[] = $aAddon;
151
        }
152
    }
153
    $aTmplData['Languages'] = $aLanguageList;
154

    
155
// Print admin footer
156
$admin->print_footer();
(21-21/25)