Test Failed
Push — master ( 3a07f6...f0ddc3 )
by Stefan
06:45
created

PageDecoration::defaultPagePrelude()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
/*
3
 * *****************************************************************************
4
 * Contributions to this work were made on behalf of the GÉANT project, a 
5
 * project that has received funding from the European Union’s Framework 
6
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
7
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
8
 * 691567 (GN4-1) and No. 731122 (GN4-2).
9
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
10
 * of the copyright in all material which was developed by a member of the GÉANT
11
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
12
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
13
 * UK as a branch of GÉANT Vereniging.
14
 * 
15
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
16
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
17
 *
18
 * License: see the web/copyright.inc.php file in the file structure or
19
 *          <base_url>/copyright.php after deploying the software
20
 */
21
22
namespace web\lib\admin;
23
24
class PageDecoration extends \core\common\Entity {
25
26
    private $validator;
27
    private $ui;
28
    private $langObject;
29
    
30
    /**
31
     * construct the PageDecoration object
32
     */
33
    public function __construct() {
34
        parent::__construct();
35
        $this->langObject = new \core\common\Language();
36
        $this->langObject->setTextDomain("web_admin");
37
        $this->validator = new \web\lib\common\InputValidation();
38
        $this->ui = new UIElements();
39
    }
40
41
    /**
42
     * Our (very modest and light) sidebar. authenticated admins get more options, like logout
43
     * 
44
     * @param boolean $advancedControls display the admin-side advanced controls?
45
     * @return string
46
     */
47
    private function sidebar($advancedControls) {
48
        \core\common\Entity::intoThePotatoes();
49
        $retval = "<div class='sidebar'><p>";
50
51
        if ($advancedControls) {
52
            $retval .= "<strong>" . _("You are:") . "</strong> ".$_SESSION['name']
53
            ."<br/>
54
              <br/>
55
              <a href='" . \core\CAT::getRootUrlPath() . "/admin/overview_user.php'>" . _("Go to your Profile page") . "</a> 
56
              <a href='" . \core\CAT::getRootUrlPath() . "/admin/inc/logout.php'>" . _("Logout") . "</a> ";
57
        }
58
        $retval .= "<a href='" . \core\CAT::getRootUrlPath() . "/'>" . _("Start page") . "</a>
59
            </p>
60
        </div> <!-- sidebar -->";
61
        \core\common\Entity::outOfThePotatoes();
62
        return $retval;
63
    }
64
65
    /**
66
     * constructs a <div> called 'header' for use on the top of the page
67
     * 
68
     * @param string $cap1     caption to display in this div
69
     * @param string $language current language (this one gets pre-set in the lang selector drop-down
70
     * @return string
71
     */
72
    private function headerDiv($cap1, $language) {
73
        \core\common\Entity::intoThePotatoes();
74
        $place = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
75
76
        $retval = "<div class='header'>
77
            <div id='header_toprow'>
78
                <div id='header_captions' style='display:inline-block; float:left; min-width:400px;'>
79
                    <h1>$cap1</h1>
80
                </div><!--header_captions-->
81
                <div id='langselection' style='padding-top:20px; padding-left:10px;'>
82
                    <form action='$place' method='GET' accept-charset='UTF-8'>" . _("View this page in") . "&nbsp;
83
                        <select id='lang' name='lang' onchange='this.form.submit()'>";
84
85
        foreach (CONFIG['LANGUAGES'] as $lang => $value) {
86
            $retval .= "<option value='$lang' " . (strtoupper($language) == strtoupper($lang) ? "selected" : "" ) . " >" . $value['display'] . "</option> ";
87
        }
88
        $retval .= "</select>";
89
90
        foreach ($_GET as $var => $value) {
91
            if ($var != "lang" && $value != "") {
92
                $retval .= "<input type='hidden' name='" . htmlspecialchars($var) . "' value='" . htmlspecialchars($value) . "'>";
93
            }
94
        }
95
        $retval .= "</form>
96
                </div><!--langselection-->";
97
        $logoUrl = \core\CAT::getRootUrlPath() . "/resources/images/consortium_logo.png";
98
        $retval .= "<div class='consortium_logo'>
99
                    <img id='test_locate' src='$logoUrl' alt='Consortium Logo'>
100
                </div> <!-- consortium_logo -->
101
            </div><!--header_toprow-->
102
        </div> <!-- header -->";
103
        \core\common\Entity::outOfThePotatoes();
104
        return $retval;
105
    }
106
107
    /**
108
     * This starts HTML in a default way. Most pages would call this.
109
     * Exception: if you need to add extra code in <head> or modify the <body> tag
110
     * (e.g. onload) then you should call defaultPagePrelude, close head, open body,
111
     * and then call productheader.
112
     * 
113
     * @param string  $pagetitle    Title of the page to display
114
     * @param string  $area         the area in which this page is (displays some matching <h1>s)
115
     * @param boolean $authRequired is authentication required on this page?
116
     * @return string
117
     */
118
    public function pageheader($pagetitle, $area, $authRequired = TRUE) {
119
        $retval = "";
120
        $retval .= $this->defaultPagePrelude($pagetitle, $authRequired);
121
        $retval .= "</head></body>";
122
        $retval .= $this->productheader($area);
123
        return $retval;
124
    }
125
126
    /**
127
     * the entire top of the page (<body> part)
128
     * 
129
     * @param string $area the area we are in
130
     * @return string
131
     */
132
    public function productheader($area) {
133
        \core\common\Entity::intoThePotatoes();
134
        $language = $this->languageInstance->getLang();
135
        // this <div is closing in footer, keep it in PHP for Netbeans syntax
136
        // highlighting to work
137
        $retval = "<div class='maincontent'>";
138
        // default values which match almost every case; override where needed
139
        $cap1 = CONFIG['APPEARANCE']['productname_long'];
140
        $advancedControls = TRUE;
141
        switch ($area) {
142
            case "ADMIN-PARTICIPANT":
143
                $cap2 = sprintf(_("Administrator Interface - %s"), $this->ui->nomenclatureParticipant);
144
                break;
145
            case "ADMIN-IDP":
146
                $cap2 = sprintf(_("Administrator Interface - %s"), $this->ui->nomenclatureInst);
147
                break;
148
            case "ADMIN-SP":
149
                $cap2 = sprintf(_("Administrator Interface - %s"), $this->ui->nomenclatureHotspot);
150
                break;
151
            case "ADMIN-IDP-USERS":
152
                $cap2 = sprintf(_("Administrator Interface - %s User Management"), \core\ProfileSilverbullet::PRODUCTNAME);
153
                break;
154
            case "ADMIN":
155
                $cap2 = _("Administrator Interface");
156
                break;
157
            case "USERMGMT":
158
                $cap2 = _("Management of User Details");
159
                break;
160
            case "FEDERATION":
161
                $cap2 = sprintf(_("Administrator Interface - %s Management"), $this->ui->nomenclatureFed);
162
                break;
163
            case "USER":
164
                $cap1 = sprintf(_("Welcome to %s"), CONFIG['APPEARANCE']['productname']);
165
                $cap2 = CONFIG['APPEARANCE']['productname_long'];
166
                $advancedControls = FALSE;
167
                break;
168
            case "SUPERADMIN":
169
                $cap2 = _("CIC");
170
                break;
171
            case "DIAG":
172
                $cap2 = _("Diagnostics");
173
                break;
174
            default:
175
                $cap2 = "It is an error if you ever see this string.";
176
                $advancedControls = FALSE;
177
        }
178
179
        $retval .= $this->headerDiv($cap1, $language);
180
        // content from here on will SCROLL instead of being fixed at the top
181
        $retval .= "<div class='pagecontent'>"; // closes in footer again
182
        $retval .= "<div class='trick'>"; // closes in footer again
183
        $retval .= "<div id='secondrow'>
184
            <div id='secondarycaptions' style='display:inline-block; float:left'>
185
                <h2 style='padding-left:10px;'>$cap2</h2>
186
            </div><!--secondarycaptions-->";
187
188
        if (isset(CONFIG['APPEARANCE']['MOTD']) && CONFIG['APPEARANCE']['MOTD'] != "") {
189
            $retval .= "<div id='header_MOTD' style='display:inline-block; padding-left:20px;vertical-align:top;'>
190
              <p class='MOTD'>" . CONFIG['APPEARANCE']['MOTD'] . "</p>
191
              </div><!--header_MOTD-->";
192
        }
193
        $retval .= $this->sidebar($advancedControls);
194
        $retval .= "</div><!--secondrow--><div id='thirdrow'>";
195
        \core\common\Entity::outOfThePotatoes();
196
        return $retval;
197
    }
198
199
    /**
200
     * 
201
     * @param string  $pagetitle    Title of the page to display
202
     * @param boolean $authRequired does the user need to be autenticated to access this page?
203
     * @return string
204
     */
205
    public function defaultPagePrelude($pagetitle, $authRequired = TRUE) {
206
        if ($authRequired === TRUE) {
207
            $auth = new \web\lib\admin\Authentication();
208
            $auth->authenticate();
209
        }
210
        $ourlocale = $this->langObject->getLang();
211
        header("Content-Type:text/html;charset=utf-8");
212
        $retval = "<!DOCTYPE html>
213
          <html xmlns='http://www.w3.org/1999/xhtml' lang='$ourlocale'>
214
          <head lang='$ourlocale'>
215
          <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
216
        $cssUrl = \core\CAT::getRootUrlPath() . "/resources/css/cat.css.php";
217
        $retval .= "<link rel='stylesheet' type='text/css' href='$cssUrl' />";
218
        $retval .= "<title>" . htmlspecialchars($pagetitle) . "</title>";
219
        return $retval;
220
    }
221
222
    /**
223
     * HTML code for the EU attribution
224
     * 
225
     * @return string HTML code with GEANT Org and EU attribution as required for FP7 / H2020 projects
226
     */
227
    public function attributionEurope() {
228
        if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") {// SW: APPROVED
229
            // we may need to jump up one dir if we are either in admin/ or accountstatus/
230
            // (accountstatus courtesy of my good mood. It's userspace not admin space so
231
            // it shouldn't be using this function any more.)
232
            $logoBase = \core\CAT::getRootUrlPath() . "/resources/images";
233
            return "<span id='logos' style='position:fixed; left:50%;'><img src='$logoBase/dante.png' alt='DANTE' style='height:23px;width:47px'/>
234
              <img src='$logoBase/eu.png' alt='EU' style='height:23px;width:27px;border-width:0px;'/></span>
235
              <span id='eu_text' style='text-align:right;'><a href='http://ec.europa.eu/dgs/connect/index_en.htm' style='text-decoration:none; vertical-align:top;'>European Commission Communications Networks, Content and Technology</a></span>";
236
        }
237
        return "&nbsp";
238
    }
239
240
    /**
241
     * displays the admin area footer
242
     * 
243
     * @return string
244
     */
245
    public function footer() {
246
        $cat = new \core\CAT();
247
        \core\common\Entity::intoThePotatoes();
248
        $retval = "</div><!-- thirdrow --></div><!-- trick -->
249
          </div><!-- pagecontent -->
250
        <div class='footer'>
251
            <table style='width:100%'>
252
                <tr>
253
                    <td style='padding-left:20px; padding-right:20px; text-align:left; vertical-align:top;'>
254
                        " . $cat->CAT_COPYRIGHT . "</td>";
255
        if (!empty(CONFIG['APPEARANCE']['privacy_notice_url'])) {
256
            $retval .= "<td><a href='".CONFIG['APPEARANCE']['privacy_notice_url']."'>" . sprintf(_("%s Privacy Notice"),CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']) . "</a></td>";
257
        }
258
        $retval .= "            <td style='padding-left:80px; padding-right:20px; text-align:right; vertical-align:top;'>";
259
260
        if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
261
            $retval .= $this->attributionEurope();
262
        } else {
263
            $retval .= "&nbsp;";
264
        }
265
        $retval .= "
266
                    </td>
267
                </tr>
268
            </table>
269
        </div><!-- footer -->
270
        </div><!-- maincontent -->
271
        </body>
272
        </html>";
273
        \core\common\Entity::outOfThePotatoes();
274
        return $retval;
275
    }
276
277
}
278