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

Revision 742, 14.8 KB (checked in by benoitg, 8 years ago)

2005-09-10 Benoit Gr�goire <bock@…>

  • Add UI to add a new Network
  • Improve UI to add a new Node and new Content
  • 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*/
30require_once BASEPATH.'include/schema_validate.php';
31validate_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                                }
109                                else
110                                {
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 class='admin_section_tools'>\n";
150                                                $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
151                                                $html .= "<input type='hidden' name='action' value='new_ui'>\n";
152                                                $html .= "<input type='hidden' name='object_class' value='Node'><br>\n";
153                                                $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n";
154                                                $html .= "</form>\n";
155                                                $html .= "</div>\n";
156                                                $html .= "</div>\n";
157                                        }
158
159                                        /* Network admin */
160                                        if ($current_user && $current_user->isSuperAdmin())
161                                        {
162                                                $html .= "<div class='admin_section_container'>\n";
163                                                $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
164                                                $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n";
165
166                                                $html .= "<div class='admin_section_data'>\n";
167                                                $html .= "<input type='hidden' name='action' value='edit'>\n";
168                                                $html .= "<input type='hidden' name='object_class' value='Network'><br>\n";
169                                                $html .= Network :: getSelectNetworkUI('object_id');
170                                                $html .= "</div>\n";
171                                                $html .= "<div class='admin_section_tools'>\n";
172
173                                                $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n";
174                                                $html .= "</div>\n";
175                                                $html .= "</form>\n";
176                                                $html .= "<div class='admin_section_tools'>\n";
177                                                $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
178                                                $html .= "<input type='hidden' name='action' value='new_ui'>\n";
179                                                $html .= "<input type='hidden' name='object_class' value='Network'><br>\n";
180                                                $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n";
181                                                $html .= "</form>\n";
182                                                $html .= "</div>\n";
183                                                $html .= "</div>\n";
184                                        }
185                                }
186                                break;
187                        default :
188                                $html .= "<p class='errormsg'>"._("Unknown section:")." $section</p>\n";
189
190                }
191                $this->tool_content = $html;
192        }
193
194        /** Set the content to be displayed in the tool pane */
195        public function setToolContent($html)
196        {
197                $this->tool_content = $html;
198        }
199
200        /** Get the content to be displayed in the tool pane
201         * @param section, one of:  START, LOGIN,
202         * @return HTML markup */
203        private function getToolContent($section = 'START')
204        {
205                global $session;
206                $html = '';
207                switch ($section)
208                {
209                        case "NONE" :
210                                break;
211                        case "LOGIN" :
212                                break;
213                        case "START" :
214                                $html .= '<div id="tool_section">'."\n";
215                                $html .= '<div class="tool_user_info">'."\n";
216                                $html .= '<span class="tool_user_info">'."\n";
217                                $user = User :: getCurrentUser();
218                                if ($user != null)
219                                {
220                                        $html .= '<p>'._("Logged in as:").' '.$user->getUsername().'</p>'."\n";
221                                        $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";
222
223                                        $gw_id = $session->get(SESS_GW_ID_VAR);
224                                        $gw_address = $session->get(SESS_GW_ADDRESS_VAR);
225                                        $gw_port = $session->get(SESS_GW_PORT_VAR);
226
227                                        if ($gw_id && $gw_address && $gw_port)
228                                                $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";
229                                        else
230                                                $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";
231
232                                }
233                                else
234                                {
235                                        $gw_id = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR);
236                                        $gw_address = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR);
237                                        $gw_port = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR);
238
239                                        // If the user connects physically ( through a gateway don't show the confusing login message )
240                                        if (empty ($gw_id) || empty ($gw_address) || empty ($gw_port))
241                                                $html .= '<p>'._("I'm NOT at a hotspot.").'<br><a href="'.BASE_SSL_PATH.'login/">'._("I would like to login virtually.").'</a></p>'."\n";
242                                        else
243                                                $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";
244                                        $html .= '<a class="administration" HREF="'.Network :: getCurrentNetwork()->getHomepageURL().'"><img class="administration" src="'.BASE_SSL_PATH.'images/lien_ext.gif"> '.Network :: getCurrentNetwork()->getName().'</a>'."\n";
245                                        $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";
246                                }
247
248                                $html .= "</span>"."\n"; //End tool_user_info
249                                $html .= "</div>"."\n"; //End tool_user_info
250
251                                $html .= '<div class="navigation">'."\n";
252                                /*
253                                $html .= '<a href="index.php" class="navigation">'._("Start").'</a>'."\n";
254                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
255                                $html .= '<a href="users.php" class="navigation">'._("Users Online").'</a>'."\n";
256                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
257                                $html .= '<a href="news.php" class="navigation">'._("News").'</a>'."\n";
258                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
259                                $html .= '<a href="hotspots.php" class="navigation">'._("Hotspots").'</a>'."\n";
260                                */
261                                $html .= '<span class="navigation">';
262                                $html .= Network :: getCurrentNetwork()->getName()." "._("Building your wireless community");
263                                $html .= '</span>';
264                                $html .= "</div>"."\n"; //End navigation
265
266                                $html .= '<div class="language">'."\n";
267                                $html .= '<form class="language" name="lang_form" method="post" action="'.$_SERVER['REQUEST_URI'].'">'."\n";
268                                $html .= _("Language:")."\n";
269                                $html .= "<select name='wifidog_language' onChange='javascript: document.lang_form.submit();'>"."\n";
270                                global $AVAIL_LOCALE_ARRAY; //From config file
271                                foreach ($AVAIL_LOCALE_ARRAY as $lang_ids => $lang_names)
272                                {
273                                        if (Locale :: getCurrentLocale()->getId() == $lang_ids)
274                                        {
275                                                $selected = "SELECTED";
276                                        }
277                                        else
278                                        {
279                                                $selected = '';
280                                        }
281                                        $html .= '<option label="'.$lang_names.'" value="'.$lang_ids.'" '.$selected.'>'.$lang_names.'</option>'."\n";
282                                }
283                                $html .= "</select>"."\n";
284                                $html .= "</form>"."\n";
285
286                                $html .= "</div>"."\n"; //End language
287
288                                $html .= "<div class='tool_content'>"."\n";
289                                /******************************/
290                                $html .= $this->tool_content;
291                                /******************************/
292                                $html .= "</div>"."\n"; //End tool_content
293                                $html .= '<div class="avis">'."\n";
294                                $html .= '<span class="avis">'."\n";
295                                $html .= sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName());
296                                $html .= _("Please inform us of any problem or service interruption at:");
297                                $tech_support_email = Network :: getCurrentNetwork()->getTechSupportEmail();
298                                $html .= '<a href="mailto:'.$tech_support_email.'">'.$tech_support_email.'</a>'."\n";
299                                $html .= "</span>"."\n"; //End avis
300                                $html .= "</div>"."\n"; //End avis
301                                $html .= "</div>"."\n"; //End tool_section
302                                break;
303                        default :
304                                $html .= '<p class="errmsg">MainUI::getToolContent(): Unknown section!</p>'."\n";
305                }
306                return $html;
307        }
308
309        /** Display the page
310         * @note:  Uses a few request parameters to displaty debug information
311         * if $_REQUEST['debug_request'] is present, it will print out the $_REQUEST array at the top of the page */
312        public function display()
313        {
314                $html = '';
315                //$this->smarty->display(DEFAULT_CONTENT_SMARTY_PATH."header.html");
316
317                /**** Headers ****/
318                $html .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'."\n";
319                $html .= '<html>'."\n";
320                $html .= '<head>'."\n";
321                $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
322                $html .= '<meta http-equiv="Pragma" CONTENT="no-cache">'."\n";
323                $html .= '<meta http-equiv="Expires" CONTENT="-1">'."\n";
324                // Add HTML headers
325                $html .= "{$this->html_headers}";
326                $html .= "<html>\n";
327                $html .= "<head>\n";
328                $html .= "<title>{$this->title}</title>\n";
329                $html .= "<style type='text/css'>\n";
330                if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.STYLESHEET_NAME))
331                {
332                        $stylesheet_file = NODE_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
333                }
334                else
335                {
336                        $stylesheet_file = DEFAULT_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
337                }
338                $html .= $this->smarty->fetch($stylesheet_file);
339                $html .= "</style>\n";
340                $html .= "</head>\n";
341
342                $html .= "<body>"."\n";
343                if (isset ($_REQUEST['debug_request']))
344                {
345                        $html .= '<pre>';
346                        $html .= print_r($_REQUEST, true);
347                        $html .= '</pre>';
348                }
349                $html .= '<div class="outer_container">'."\n";
350
351                if ($this->isToolSectionEnabled())
352                {
353                        /**** Tools ******/
354                        $html .= $this->getToolContent();
355
356                        /**** Main section ****/
357                        $html .= "<div id='main_section'>"."\n";
358                        $html .= $this->main_content;
359                        $html .= "</div>"."\n"; //End main_section     
360                }
361                else
362                {
363                        /**** Main section ****/
364                        $html .= $this->main_content;
365                }
366
367                $html .= '</div>'."\n"; //End outer_container
368
369                foreach ($this->footer_scripts as $script)
370                {
371                        $html .= "{$script}\n";
372                }
373                $html .= "</body>"."\n";
374                $html .= "</html>"."\n";
375                echo $html;
376
377        }
378
379        function displayError($errmsg)
380        {
381                $html = "<p>$errmsg</p>\n";
382                $email = Network :: getCurrentNetwork()->getTechSupportEmail();
383                if (!empty ($email))
384                {
385                        $html .= "<p>"._("Please get in touch with ")."<a href='{$email}'>{$email}</a></p>";
386                }
387                $this->setMainContent($html);
388                $this->display();
389        }
390
391} //End class
392?>
393
Note: See TracBrowser for help on using the browser.