root/trunk/wifidog-auth/wifidog/classes/MainUI.php @ 736

Revision 736, 15.0 KB (checked in by aprilp, 8 years ago)

Don't show the admin menu if user does not have access

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3
4/********************************************************************\
5 * This program is free software; you can redistribute it and/or    *
6 * modify it under the terms of the GNU General Public License as   *
7 * published by the Free Software Foundation; either version 2 of   *
8 * the License, or (at your option) any later version.              *
9 *                                                                  *
10 * This program is distributed in the hope that it will be useful,  *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
13 * GNU General Public License for more details.                     *
14 *                                                                  *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact:                        *
17 *                                                                  *
18 * Free Software Foundation           Voice:  +1-617-542-5942       *
19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
21 *                                                                  *
22 \********************************************************************/
23/**@file MainUI.php
24 * @author Copyright (C) 2005 Technologies Coeus inc.
25 */
26require_once BASEPATH.'include/common.php';
27        /** @note We put a call to validate_schema() here so it systematically called
28 * from any UI page, but not from any machine readable pages
29 */ 
30                require_once BASEPATH.'include/schema_validate.php';
31                validate_schema();
32               
33if (CONF_USE_CRON_FOR_DB_CLEANUP == false)
34{
35        garbage_collect();
36}
37
38require_once BASEPATH.'include/common_interface.php';
39
40/** Style contains functions managing headers, footers, stylesheet, etc.
41 */
42class MainUI
43{
44        private $main_content; /**<Content to be displayed in the main pane */
45        private $tool_content; /**<Content to be displayed in the tool pane */
46        private $smarty;
47        private $title;
48        private $html_headers;
49        private $tool_section_enabled = true;
50        private $footer_scripts = array ();
51
52        function __construct()
53        {
54                $this->smarty = new SmartyWifidog();
55                $this->title = Network :: getCurrentNetwork()->getName().' '._("authentication server"); //Default title
56        }
57       
58        /** Check if the tool section is enabled
59         *
60         */
61        public function isToolSectionEnabled()
62        {
63                return $this->tool_section_enabled;
64        }
65       
66        public function setToolSectionEnabled($status)
67        {
68                $this->tool_section_enabled = $status;
69        }
70
71        /** Set the content to be displayed in the main pane */
72        public function setMainContent($html)
73        {
74                $this->main_content = $html;
75        }
76
77        /** Set the title of the page */
78        public function setTitle($title_string)
79        {
80                $this->title = $title_string;
81        }
82
83        /** Add content at the very end of the <body>.  This is NOT meant to add footers or other display content, it is meant to add <script></script> tag pairs that have to be executed only once the page is loaded.
84         * @param $script A piece of script surrounded by <script></script> tags. */
85        public function addFooterScript($script)
86        {
87                $this->footer_scripts[] = $script;
88        }
89
90        /** Set the HTML page headers */
91        public function setHtmlHeader($headers_string)
92        {
93                $this->html_headers = $headers_string;
94        }
95
96        /** Set the section to be displayed in the tool pane */
97        public function setToolSection($section)
98        {
99                switch ($section)
100                {
101                        case "ADMIN" :
102                                $current_user = User :: getCurrentUser();
103                                $html = '';
104
105                if ($current_user && $current_user->isNobody())
106                {
107                    $html .= _("You do not have permissions to access any administration functions.");
108                } else {
109
110                    $html .= "<ul class='admin_menu_list'>\n";
111
112                    if ($current_user && $current_user->isSuperAdmin())
113                    {
114                        $html .= "<li><a href='user_log.php'>"._("User logs")."</a></li>\n";
115                        $html .= "<li><a href='online_users.php'>"._("Online Users")."</a></li>\n";
116                        $html .= "<li><a href='stats.php'>"._("Statistics")."</a></li>\n";
117                        $html .= "<li><a href='import_user_database.php'>"._("Import NoCat user database")."</a></li>\n";
118                        $html .= "<li><a href='content_admin.php'>"._("Content manager")."</a></li>\n";
119                    }
120
121                    $html .= "</ul>\n";
122
123                    // If the user is super admin OR owner of at least one hotspot show the menu
124                    if ($current_user && ($current_user->isSuperAdmin() || $current_user->isOwner()))
125                    {
126                        /* Node admin */
127                        $html .= "<div class='admin_section_container'>\n";
128                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
129                        $html .= "<div class='admin_section_title'>"._("Node administration:")." </div>\n";
130
131                        $html .= "<div class='admin_section_data'>\n";
132
133                        if ($current_user->isSuperAdmin())
134                            $sql_additional_where = '';
135                        else
136                            $sql_additional_where = "AND node_id IN (SELECT node_id from node_stakeholders WHERE is_owner = true AND user_id='".$current_user->getId()."')";
137                        $html .= "<div id='NodeSelector'>\n";
138                        $html .= Node :: getSelectNodeUI('object_id', $sql_additional_where);
139                        $html .= "</div>\n";
140                        $html .= "</div>\n";
141                        $html .= "<div class='admin_section_tools'>\n";
142
143                        $html .= "<input type='hidden' name='object_class' value='Node'>\n";
144                        $html .= "<input type='hidden' name='action' value='edit'>\n";
145                        $html .= "<input type='submit' name='edit_submit' value='"._("Edit")."'>\n";
146
147                        $html .= "</div>\n";
148                        $html .= '</form>';
149                        $html .= "</div>\n";
150                    }
151
152                    /* Network admin */
153                    if ($current_user && $current_user->isSuperAdmin())
154                    {
155                        $html .= "<div class='admin_section_container'>\n";
156                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
157                        $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n";
158
159                        $html .= "<div class='admin_section_data'>\n";
160                        $html .= "<input type='hidden' name='action' value='edit'>\n";
161                        $html .= "<input type='hidden' name='object_class' value='Network'><br>\n";
162                        $html .= Network :: getSelectNetworkUI('object_id');
163                        $html .= "</div>\n";
164                        $html .= "<div class='admin_section_tools'>\n";
165
166                        $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n";
167                        $html .= "</div>\n";
168                        $html .= '</form>';
169                        $html .= "</div>\n";
170                    }
171                }
172                                break;
173                        default :
174                                $html .= "<p class='errormsg'>"._("Unknown section:")." $section</p>\n";
175
176                }
177                $this->tool_content = $html;
178        }
179
180        /** Set the content to be displayed in the tool pane */
181        public function setToolContent($html)
182        {
183                $this->tool_content = $html;
184        }
185
186        /** Get the content to be displayed in the tool pane
187         * @param section, one of:  START, LOGIN,
188         * @return HTML markup */
189        private function getToolContent($section = 'START')
190        {
191                global $session;
192                $html = '';
193                switch ($section)
194                {
195                        case "NONE" :
196                                break;
197                        case "LOGIN" :
198                                break;
199                        case "START" :
200                                $html .= '<div id="tool_section">'."\n";
201                                $html .= '<div class="tool_user_info">'."\n";
202                                $html .= '<span class="tool_user_info">'."\n";
203                                $user = User :: getCurrentUser();
204                                if ($user != null)
205                                {
206                                        $html .= '<p>'._("Logged in as:").' '.$user->getUsername().'</p>'."\n";
207                                        $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'user_profile.php"><img class="administration" src="'.BASE_SSL_PATH.'images/profile.gif" border="0"> '._("My Profile").'</a>'."\n";
208
209                                        $gw_id = $session->get(SESS_GW_ID_VAR);
210                                        $gw_address = $session->get(SESS_GW_ADDRESS_VAR);
211                                        $gw_port = $session->get(SESS_GW_PORT_VAR);
212
213                                        if ($gw_id && $gw_address && $gw_port)
214                                                $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'login/?logout=true&gw_id='.$gw_id.'&gw_address='.$gw_address.'&gw_port='.$gw_port.'"><img class="administration" src="'.BASE_SSL_PATH.'images/logout.gif" border="0"> '._("Logout").'</a>'."\n";
215                                        else
216                                                $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'login/?logout=true"><img class="administration" src="'.BASE_SSL_PATH.'images/logout.gif" border="0"> '._("Logout").'</a>'."\n";
217
218                                }
219                                else
220                                {
221                                        $gw_id = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR);
222                                        $gw_address = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR);
223                                        $gw_port = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR);
224
225                                        // If the user connects physically ( through a gateway don't show the confusing login message )
226                                        if (empty ($gw_id) || empty ($gw_address) || empty ($gw_port))
227                                                $html .= '<p>'._("I'm NOT at a hotspot.").'<br><a href="'.BASE_SSL_PATH.'login/">'._("I would like to login virtually.").'</a></p>'."\n";
228                                        else
229                                                $html .= '<p>'._("NOT logged in.").'<br><a href="'.BASE_SSL_PATH.'login/?gw_id='.$gw_id.'&gw_address='.$gw_address.'&gw_port='.$gw_port.'">'._("Login to this hotspot.").'</a></p>'."\n";
230                                        $html .= '<a class="administration" HREF="'.Network :: getCurrentNetwork()->getHomepageURL().'"><img class="administration" src="'.BASE_SSL_PATH.'images/lien_ext.gif"> '.Network :: getCurrentNetwork()->getName().'</a>'."\n";
231                                        $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'faq.php"><img class="administration" src="'.BASE_SSL_PATH.'images/where.gif"> '._("Where am I?").'</a>'."\n";
232                                }
233
234                                $html .= "</span>"."\n"; //End tool_user_info
235                                $html .= "</div>"."\n"; //End tool_user_info
236
237                                $html .= '<div class="navigation">'."\n";
238                                /*
239                                $html .= '<a href="index.php" class="navigation">'._("Start").'</a>'."\n";
240                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
241                                $html .= '<a href="users.php" class="navigation">'._("Users Online").'</a>'."\n";
242                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
243                                $html .= '<a href="news.php" class="navigation">'._("News").'</a>'."\n";
244                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
245                                $html .= '<a href="hotspots.php" class="navigation">'._("Hotspots").'</a>'."\n";
246                                */
247                                $html .= '<span class="navigation">';
248                                $html .= Network :: getCurrentNetwork()->getName()." "._("Building your wireless community");
249                                $html .= '</span>';
250                                $html .= "</div>"."\n"; //End navigation
251
252                                $html .= '<div class="language">'."\n";
253                                $html .= '<form class="language" name="lang_form" method="post" action="'.$_SERVER['REQUEST_URI'].'">'."\n";
254                                $html .= _("Language:")."\n";
255                                $html .= "<select name='wifidog_language' onChange='javascript: document.lang_form.submit();'>"."\n";
256                                global $AVAIL_LOCALE_ARRAY; //From config file
257                                foreach ($AVAIL_LOCALE_ARRAY as $lang_ids => $lang_names)
258                                {
259                                        if (Locale :: getCurrentLocale()->getId() == $lang_ids)
260                                        {
261                                                $selected = "SELECTED";
262                                        }
263                                        else
264                                        {
265                                                $selected = '';
266                                        }
267                                        $html .= '<option label="'.$lang_names.'" value="'.$lang_ids.'" '.$selected.'>'.$lang_names.'</option>'."\n";
268                                }
269                                $html .= "</select>"."\n";
270                                $html .= "</form>"."\n";
271
272                                $html .= "</div>"."\n"; //End language
273
274                                $html .= "<div class='tool_content'>"."\n";
275                                /******************************/
276                                $html .= $this->tool_content;
277                                /******************************/
278                                $html .= "</div>"."\n"; //End tool_content
279                                $html .= '<div class="avis">'."\n";
280                                $html .= '<span class="avis">'."\n";
281                                $html .= sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName());
282                                $html .= _("Please inform us of any problem or service interruption at:");
283                                $tech_support_email = Network :: getCurrentNetwork()->getTechSupportEmail();
284                                $html .= '<a href="mailto:'.$tech_support_email.'">'.$tech_support_email.'</a>'."\n";
285                                $html .= "</span>"."\n"; //End avis
286                                $html .= "</div>"."\n"; //End avis
287                                $html .= "</div>"."\n"; //End tool_section
288                                break;
289                        default :
290                                $html .= '<p class="errmsg">MainUI::getToolContent(): Unknown section!</p>'."\n";
291                }
292                return $html;
293        }
294
295        /** Display the page
296         * @note:  Uses a few request parameters to displaty debug information
297         * if $_REQUEST['debug_request'] is present, it will print out the $_REQUEST array at the top of the page */
298        public function display()
299        {
300                $html = '';
301                //$this->smarty->display(DEFAULT_CONTENT_SMARTY_PATH."header.html");
302
303                /**** Headers ****/
304                $html .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'."\n";
305                $html .= '<html>'."\n";
306                $html .= '<head>'."\n";
307                $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
308                $html .= '<meta http-equiv="Pragma" CONTENT="no-cache">'."\n";
309                $html .= '<meta http-equiv="Expires" CONTENT="-1">'."\n";
310                // Add HTML headers
311                $html .= "{$this->html_headers}";
312                $html .= "<html>\n";
313                $html .= "<head>\n";
314                $html .= "<title>{$this->title}</title>\n";
315                $html .= "<style type='text/css'>\n";
316                if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.STYLESHEET_NAME))
317                {
318                        $stylesheet_file = NODE_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
319                }
320                else
321                {
322                        $stylesheet_file = DEFAULT_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
323                }
324                $html .= $this->smarty->fetch($stylesheet_file);
325                $html .= "</style>\n";
326                $html .= "</head>\n";
327
328                $html .= "<body>"."\n";
329                if(isset($_REQUEST['debug_request']))
330                {
331                        $html .= '<pre>';
332                        $html .= print_r($_REQUEST,true);
333                        $html .= '</pre>';
334                }
335                $html .= '<div class="outer_container">'."\n";
336
337               
338                if($this->isToolSectionEnabled())
339                {
340                        /**** Tools ******/
341                        $html .= $this->getToolContent();
342                       
343                        /**** Main section ****/
344                        $html .= "<div id='main_section'>"."\n";
345                        $html .= $this->main_content;
346                        $html .= "</div>"."\n"; //End main_section     
347                }
348                else
349                {
350                        /**** Main section ****/
351                        $html .= $this->main_content;
352                }
353
354                $html .= '</div>'."\n"; //End outer_container
355
356                foreach ($this->footer_scripts as $script)
357                {
358                        $html .= "{$script}\n";
359                }
360                $html .= "</body>"."\n";
361                $html .= "</html>"."\n";
362                echo $html;
363
364        }
365
366        function displayError($errmsg)
367        {
368                $html = "<p>$errmsg</p>\n";
369                $email = Network::getCurrentNetwork()->getTechSupportEmail();
370                if(!empty($email))
371                {
372                $html .= "<p>"._("Please get in touch with ")."<a href='{$email}'>{$email}</a></p>";
373                }
374                $this->setMainContent($html);
375                $this->display();
376        }
377
378} //End class
379?>
Note: See TracBrowser for help on using the browser.