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

Revision 694, 13.8 KB (checked in by benoitg, 8 years ago)

2005-08-19 Benoit Gr�goire <bock@…>

  • New schema version
  • install.php, tmp/magpie_cache/: Move all magpie caches to a central location, adjust install script to match.
  • classes/MainUI.php: Add $_REQUEST array output if debug_request is set as a parameter to the page
  • classes/Network.php, classes/Node.php: Change content ordering to be most recently subscribed first, this is a stopgap measure while waiting for Content ordering to be explicitely settable.
  • classes/Content/RssAggregator.php: Full admin UI, some bug fixes
  • lib/RssPressReview/RssPressReview.php: New version, adds isFeedAvailable() and getFeedTitle() methods. Fixes minor bugs
  • 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';
27require_once BASEPATH.'include/common_interface.php';
28
29/** Style contains functions managing headers, footers, stylesheet, etc.
30 */
31class MainUI
32{
33        private $main_content; /**<Content to be displayed in the main pane */
34        private $tool_content; /**<Content to be displayed in the tool pane */
35        private $smarty;
36        private $title;
37        private $html_headers;
38        private $tool_section_enabled = true;
39        private $footer_scripts = array ();
40
41       
42        /** @note We put a call to validate_schema() here so it systematically called
43 * from any UI page, but not from any machine readable pages
44 */ 
45        function __construct()
46        {
47                require_once BASEPATH.'include/schema_validate.php';
48                validate_schema();
49
50                $this->smarty = new SmartyWifidog();
51                $this->title = Network :: getCurrentNetwork()->getName().' '._("authentication server"); //Default title
52        }
53       
54        /** Check if the tool section is enabled
55         *
56         */
57        public function isToolSectionEnabled()
58        {
59                return $this->tool_section_enabled;
60        }
61       
62        public function setToolSectionEnabled($status)
63        {
64                $this->tool_section_enabled = $status;
65        }
66
67        /** Set the content to be displayed in the main pane */
68        public function setMainContent($html)
69        {
70                $this->main_content = $html;
71        }
72
73        /** Set the title of the page */
74        public function setTitle($title_string)
75        {
76                $this->title = $title_string;
77        }
78
79        /** 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.
80         * @param $script A piece of script surrounded by <script></script> tags. */
81        public function addFooterScript($script)
82        {
83                $this->footer_scripts[] = $script;
84        }
85
86        /** Set the HTML page headers */
87        public function setHtmlHeader($headers_string)
88        {
89                $this->html_headers = $headers_string;
90        }
91
92        /** Set the section to be displayed in the tool pane */
93        public function setToolSection($section)
94        {
95                switch ($section)
96                {
97                        case "ADMIN" :
98                                $current_user = User :: getCurrentUser();
99                                $html = '';
100                                $html .= "<ul class='admin_menu_list'>\n";
101
102                                if ($current_user && $current_user->isSuperAdmin())
103                                {
104                                        $html .= "<li><a href='user_log.php'>"._("User logs")."</a></li>\n";
105                                        $html .= "<li><a href='online_users.php'>"._("Online Users")."</a></li>\n";
106                                        $html .= "<li><a href='user_stats.php'>"._("Cumulative user statistics")."</a></li>\n";
107                                        $html .= "<li><a href='hotspot_log.php'>"._("Hotspot logs")."</a></li>\n";
108                                        $html .= "<li><a href='import_user_database.php'>"._("Import NoCat user database")."</a></li>\n";
109                                        $html .= "<li><a href='content_admin.php'>"._("Content manager")."</a></li>\n";
110                                }
111
112                                $html .= "</ul>\n";
113
114                                // If the user is super admin OR owner of at least one hotspot show the menu
115                                if ($current_user && ($current_user->isSuperAdmin() || $current_user->isOwner()))
116                                {
117                                        /* Node admin */
118                                        $html .= "<div class='admin_section_container'>\n";
119                                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
120                                        $html .= "<div class='admin_section_title'>"._("Node administration:")." </div>\n";
121
122                                        $html .= "<div class='admin_section_data'>\n";
123
124                                        if ($current_user->isSuperAdmin())
125                                                $sql_additional_where = '';
126                                        else
127                                                $sql_additional_where = "AND node_id IN (SELECT node_id from node_owners WHERE user_id='".$current_user->getId()."')";
128                                        $html .= "<div id='NodeSelector'>\n";
129                                        $html .= Node :: getSelectNodeUI('object_id', $sql_additional_where);
130                                        $html .= "</div>\n";
131                                        $html .= "</div>\n";
132                                        $html .= "<div class='admin_section_tools'>\n";
133
134                                        $html .= "<input type='hidden' name='object_class' value='Node'>\n";
135                                        $html .= "<input type='hidden' name='action' value='edit'>\n";
136                                        $html .= "<input type='submit' name='edit_submit' value='"._("Edit")."'>\n";
137
138                                        $html .= "</div>\n";
139                                        $html .= '</form>';
140                                        $html .= "</div>\n";
141                                }
142
143                                /* Network admin */
144                                if ($current_user && $current_user->isSuperAdmin())
145                                {
146                                        $html .= "<div class='admin_section_container'>\n";
147                                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
148                                        $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n";
149
150                                        $html .= "<div class='admin_section_data'>\n";
151                                        $html .= "<input type='hidden' name='action' value='edit'>\n";
152                                        $html .= "<input type='hidden' name='object_class' value='Network'><br>\n";
153                                        $html .= Network :: getSelectNetworkUI('object_id');
154                                        $html .= "</div>\n";
155                                        $html .= "<div class='admin_section_tools'>\n";
156
157                                        $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n";
158                                        $html .= "</div>\n";
159                                        $html .= '</form>';
160                                        $html .= "</div>\n";
161                                }
162                                break;
163                        default :
164                                $html .= "<p class='errormsg'>"._("Unknown section:")." $section</p>\n";
165
166                }
167                $this->tool_content = $html;
168        }
169
170        /** Set the content to be displayed in the tool pane */
171        public function setToolContent($html)
172        {
173                $this->tool_content = $html;
174        }
175
176        /** Get the content to be displayed in the tool pane
177         * @param section, one of:  START, LOGIN,
178         * @return HTML markup */
179        private function getToolContent($section = 'START')
180        {
181                global $session;
182                $html = '';
183                switch ($section)
184                {
185                        case "NONE" :
186                                break;
187                        case "LOGIN" :
188                                break;
189                        case "START" :
190                                $html .= '<div id="tool_section">'."\n";
191                                $html .= '<div class="tool_user_info">'."\n";
192                                $html .= '<span class="tool_user_info">'."\n";
193                                $user = User :: getCurrentUser();
194                                if ($user != null)
195                                {
196                                        $html .= '<p>'._("Logged in as:").' '.$user->getUsername().'</p>'."\n";
197                                        $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";
198
199                                        $gw_id = $session->get(SESS_GW_ID_VAR);
200                                        $gw_address = $session->get(SESS_GW_ADDRESS_VAR);
201                                        $gw_port = $session->get(SESS_GW_PORT_VAR);
202
203                                        if ($gw_id && $gw_address && $gw_port)
204                                                $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";
205                                        else
206                                                $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";
207
208                                }
209                                else
210                                {
211                                        $gw_id = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR);
212                                        $gw_address = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR);
213                                        $gw_port = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR);
214
215                                        // If the user connects physically ( through a gateway don't show the confusing login message )
216                                        if (empty ($gw_id) || empty ($gw_address) || empty ($gw_port))
217                                                $html .= '<p>'._("I'm NOT at a hotspot.").'<br><a href="'.BASE_SSL_PATH.'login/">'._("I would like to login virtually.").'</a></p>'."\n";
218                                        else
219                                                $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";
220                                        $html .= '<a class="administration" HREF="'.Network :: getCurrentNetwork()->getHomepageURL().'"><img class="administration" src="'.BASE_SSL_PATH.'images/lien_ext.gif"> '.Network :: getCurrentNetwork()->getName().'</a>'."\n";
221                                        $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";
222                                }
223
224                                $html .= "</span>"."\n"; //End tool_user_info
225                                $html .= "</div>"."\n"; //End tool_user_info
226
227                                $html .= '<div class="navigation">'."\n";
228                                /*
229                                $html .= '<a href="index.php" class="navigation">'._("Start").'</a>'."\n";
230                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
231                                $html .= '<a href="users.php" class="navigation">'._("Users Online").'</a>'."\n";
232                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
233                                $html .= '<a href="news.php" class="navigation">'._("News").'</a>'."\n";
234                                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
235                                $html .= '<a href="hotspots.php" class="navigation">'._("Hotspots").'</a>'."\n";
236                                */
237                                $html .= '<span class="navigation">';
238                                $html .= Network :: getCurrentNetwork()->getName()." "._("Building your wireless community");
239                                $html .= '</span>';
240                                $html .= "</div>"."\n"; //End navigation
241
242                                $html .= '<div class="language">'."\n";
243                                $html .= '<form class="language" name="lang_form" method="post" action="'.$_SERVER['REQUEST_URI'].'">'."\n";
244                                $html .= _("Language:")."\n";
245                                $html .= "<select name='wifidog_language' onChange='javascript: document.lang_form.submit();'>"."\n";
246                                global $AVAIL_LOCALE_ARRAY; //From config file
247                                foreach ($AVAIL_LOCALE_ARRAY as $lang_ids => $lang_names)
248                                {
249                                        if (Locale :: getCurrentLocale()->getId() == $lang_ids)
250                                        {
251                                                $selected = "SELECTED";
252                                        }
253                                        else
254                                        {
255                                                $selected = '';
256                                        }
257                                        $html .= '<option label="'.$lang_names.'" value="'.$lang_ids.'" '.$selected.'>'.$lang_names.'</option>'."\n";
258                                }
259                                $html .= "</select>"."\n";
260                                $html .= "</form>"."\n";
261
262                                $html .= "</div>"."\n"; //End language
263
264                                $html .= "<div class='tool_content'>"."\n";
265                                /******************************/
266                                $html .= $this->tool_content;
267                                /******************************/
268                                $html .= "</div>"."\n"; //End tool_content
269                                $html .= '<div class="avis">'."\n";
270                                $html .= '<span class="avis">'."\n";
271                                $html .= sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName());
272                                $html .= _("Please inform us of any problem or service interruption at:");
273                                $tech_support_email = Network :: getCurrentNetwork()->getTechSupportEmail();
274                                $html .= '<a href="mailto:'.$tech_support_email.'">'.$tech_support_email.'</a>'."\n";
275                                $html .= "</span>"."\n"; //End avis
276                                $html .= "</div>"."\n"; //End avis
277                                $html .= "</div>"."\n"; //End tool_section
278                                break;
279                        default :
280                                $html .= '<p class="errmsg">MainUI::getToolContent(): Unknown section!</p>'."\n";
281                }
282                return $html;
283        }
284
285        /** Display the page
286         * @note:  Uses a few request parameters to displaty debug information
287         * if $_REQUEST['debug_request'] is present, it will print out the $_REQUEST array at the top of the page */
288        public function display()
289        {
290                $html = '';
291                //$this->smarty->display(DEFAULT_CONTENT_SMARTY_PATH."header.html");
292
293                /**** Headers ****/
294                $html .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'."\n";
295                $html .= '<html>'."\n";
296                $html .= '<head>'."\n";
297                $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
298                $html .= '<meta http-equiv="Pragma" CONTENT="no-cache">'."\n";
299                $html .= '<meta http-equiv="Expires" CONTENT="-1">'."\n";
300                // Add HTML headers
301                $html .= "{$this->html_headers}";
302                $html .= "<html>\n";
303                $html .= "<head>\n";
304                $html .= "<title>{$this->title}</title>\n";
305                $html .= "<style type='text/css'>\n";
306                if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.STYLESHEET_NAME))
307                {
308                        $stylesheet_file = NODE_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
309                }
310                else
311                {
312                        $stylesheet_file = DEFAULT_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
313                }
314                $html .= $this->smarty->fetch($stylesheet_file);
315                $html .= "</style>\n";
316                $html .= "</head>\n";
317
318                $html .= "<body>"."\n";
319                if(isset($_REQUEST['debug_request']))
320                {
321                        $html .= '<pre>';
322                        $html .= print_r($_REQUEST,true);
323                        $html .= '</pre>';
324                }
325                $html .= '<div class="outer_container">'."\n";
326
327               
328                if($this->isToolSectionEnabled())
329                {
330                        /**** Tools ******/
331                        $html .= $this->getToolContent();
332                       
333                        /**** Main section ****/
334                        $html .= "<div id='main_section'>"."\n";
335                        $html .= $this->main_content;
336                        $html .= "</div>"."\n"; //End main_section     
337                }
338                else
339                {
340                        /**** Main section ****/
341                        $html .= $this->main_content;
342                }
343
344                $html .= '</div>'."\n"; //End outer_container
345
346                foreach ($this->footer_scripts as $script)
347                {
348                        $html .= "{$script}\n";
349                }
350                $html .= "</body>"."\n";
351                $html .= "</html>"."\n";
352                echo $html;
353
354        }
355
356        function displayError($errmsg)
357        {
358                $html = "<p>$errmsg</p>\n";
359                $html .= "<p>"._("Please get in touch with ")."<a href='{TECH_SUPPORT_EMAIL}'>{TECH_SUPPORT_EMAIL}</a></p>";
360                $this->setMainContent($html);
361                $this->display();
362        }
363
364} //End class
365?>
Note: See TracBrowser for help on using the browser.