interface.inc.php 45.1 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3 4 5 6
<?php

/** @file
 *
 *
 */
7
/* Copyright 2005 - 2010
Ayolo's avatar
Ayolo committed
8
 * - Julien Etelain < julien at pmad dot net >
Ayolo's avatar
bleh  
Ayolo committed
9
 * - Simon lopez < simon dot lopez at ayolo dot org >
10
 * - Benjamin Collet < bcollet at oxynux dot org>
Ayolo's avatar
Ayolo committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
Lopar's avatar
Lopar committed
30

Feu's avatar
Feu committed
31
$timing["all"] -= microtime(true);
Ayolo's avatar
Ayolo committed
32

Colonel's avatar
Colonel committed
33
setlocale(LC_ALL, "fr_FR.UTF8");
Ayolo's avatar
Ayolo committed
34

Colonel's avatar
Colonel committed
35 36
if (!strncmp('/var/www/taiste', $_SERVER['SCRIPT_FILENAME'], 15))
    $GLOBALS["taiste"] = true;
Feu's avatar
Feu committed
37
else
Colonel's avatar
Colonel committed
38
    $GLOBALS["taiste"] = false;
Feu's avatar
Feu committed
39

Ayolo's avatar
Ayolo committed
40 41 42 43 44 45
require_once($topdir . "include/mysql.inc.php");
require_once($topdir . "include/mysqlae.inc.php");
require_once($topdir . "include/entities/std.inc.php");
require_once($topdir . "include/entities/utilisateur.inc.php");
require_once($topdir . "include/cts/standart.inc.php");

Bate's avatar
Bate committed
46 47
//if ( !isset($wwwtopdir) )
//{
Colonel's avatar
Colonel committed
48
if ($GLOBALS["taiste"]) {
Bate's avatar
Bate committed
49
    $wwwtopdir = "/taiste/";
Colonel's avatar
Colonel committed
50 51
    $fstopdir = $_SERVER['DOCUMENT_ROOT'] . "/../taiste/";
} else {
Bate's avatar
Bate committed
52
    $wwwtopdir = "/";
Colonel's avatar
Colonel committed
53 54
    $fstopdir = $_SERVER['DOCUMENT_ROOT'] . "/";
}
Bate's avatar
Bate committed
55
//}
Ayolo's avatar
Ayolo committed
56

Bate's avatar
Bate committed
57

Ayolo's avatar
Ayolo committed
58 59
/** Classe générant l'interface
 * @see site
Feu's avatar
Feu committed
60
 * @ingroup display
Ayolo's avatar
Ayolo committed
61 62 63
 */
class interfaceweb
{
Colonel's avatar
Colonel committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    var $db;
    var $dbrw;
    var $user;

    var $contents;
    var $sides;
    var $sides_ref;
    var $boxes;

    protected $buffer = "";

    var $section;
    var $title;

    var $extracss;
    var $rss;
    var $extrajs;

    var $compact;

    var $params; // cache des paramètres

    var $meta_keywords;
    var $meta_description;
    var $alternate;

    var $tab_array = array(
        array("accueil", "index.php", "Accueil",
            array(
                array("index.php", "Les nouvelles"),
                array("events.php", "Aujourd'hui"),
                array("weekmail.php", "Le weekmail"),
            )),
        array("presentation", "article.php?name=presentation", "L'AE",
            array(
                array("article.php?name=presentation", "Présentation"),
                array("article.php?name=presentation:services", "Services quotidiens"),
                array("article.php?name=presentation:carteae", "La carte AE"),
                array("article.php?name=presentation:siteae", "Le site AE"),
                array("article.php?name=presentation:activites", "Activités et clubs"),
                array("activites.php?view=trombino", "Responsables des clubs"),
            )),
        array("matmatronch", "matmatronch/", "Matmatronch"),
        array("wiki", "wiki2/", "Wiki"),
        array("sas", "sas2/", "SAS"),
        array("forum", "forum2/", "Forum",
            array(
                array("forum2/index.php", "Sommaire"),
                array("forum2/search.php?page=unread", "Messages non lus"),
                array("forum2/search.php", "Recherche"),
                array("forum2/search.php?page=starred", "Favoris"),
                array("forum2/admin/", "Administration"),
            )),
        array("services", "article.php?name=services", "Services"),
118 119 120
        //array ("pg", "pgae.php", "Petit géni"),
        //e-boutic -> services
        //array ("e-boutic", "e-boutic/", "E-boutic"),
Colonel's avatar
Colonel committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        array("fichiers", "d.php", "Fichiers",
            array(
                array("d.php", "Fichiers de l'AE"),
                array("asso.php", "Fichiers des associations et des clubs")
            )),
        array("liens", "article.php?name=liens", "Partenaires"),
        array("aide", "article.php?name=docs:index", "Aide"));

    /** Constructeur
     * @param $db instance de la base de donnée pour la lecture
     * @param $dbrw instance de la base de donéne pour l'écriture (+lecture)
     */
    function interfaceweb($db, $dbrw = false)
    {
        $this->db = $db;
        $this->dbrw = $dbrw;
Ayolo's avatar
bleh  
Ayolo committed
137

Colonel's avatar
Colonel committed
138 139
        $this->sides["left"] = array();
        $this->sides["right"] = array();
Lopar's avatar
Lopar committed
140

Colonel's avatar
Colonel committed
141 142 143 144 145 146
        $this->user = new utilisateur($db, $dbrw);
        $this->extracss = array();
        $this->extrajs = array();
        $this->rss = array();
        $this->contents = array();
        $this->alternate = array();
147

Colonel's avatar
Colonel committed
148
    }
149

Antoine Tenart's avatar
Antoine Tenart committed
150
    /**
Colonel's avatar
Colonel committed
151 152
     * Permet de choisir de générer une page pour version mobile
     * @param $bool  true|false
Antoine Tenart's avatar
Antoine Tenart committed
153
     */
Colonel's avatar
Colonel committed
154
    public function set_mobile($bool)
Ayolo's avatar
bleh  
Ayolo committed
155
    {
Colonel's avatar
Colonel committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        /**
         * Define whether we want a mobile rendering or not
         * Will be redefined by set_mobile().
         *
         * We use a constant so it can be used by any class.
         * Notice that interfaceweb:interfaceweb is called everytime
         * you create a page instance.
         */
        if ($bool) define("MOBILE", true);

        /* Reset tab menu in mobile mode */
        if (defined("MOBILE")) $this->tab_array = array();

        /* Check if user is connected */
        if (!$this->user->is_valid()) {
            if ($GLOBALS["taiste"])
                $frm = new form("connect", "/taiste/connect.php", true, "POST", "Connexion");
            else
                $frm = new form("connect", "/connect.php", true, "POST", "Connexion");
            $frm->add_select_field("domain",
                "Connexion",
                array("utbm" => "UTBM / Assidu",
                    "carteae" => "Carte AE",
                    "id" => "ID",
                    "autre" => "E-mail",
                    "alias" => "Alias"));
            $frm->add_text_field("username", "Utilisateur", "", "", 20, true, true, null, false, 35);
            $frm->add_password_field("password", "Mot de passe", "", "", 20);
            $frm->add_checkbox("personnal_computer", "Me connecter automatiquement la prochaine fois", true);
            $frm->add_submit("connect", "Se connecter");
            $frm->add_hidden("mobile");
            $this->add_contents($frm);

            /* Come back here after connexion completed */
            $_SESSION['session_redirect'] = "m/"; /* Oh, a diplodocus ! Shhh !! */

            $this->end_page();
            exit(0);
        }
Ayolo's avatar
bleh  
Ayolo committed
195
    }
Ayolo's avatar
Ayolo committed
196

Colonel's avatar
Colonel committed
197 198 199 200 201
    /** Défini les boites à afficher sur un coté
     * @param $side Coté (left ou right)
     * @param $boxes Array des nom des boites à afficher
     */
    function set_side_boxes($side, $boxes, $ref = null)
Ayolo's avatar
bleh  
Ayolo committed
202
    {
Colonel's avatar
Colonel committed
203 204 205 206 207 208 209 210
        if ($side != "left" && $side != "right") return;
        $this->sides[$side] = $boxes;

        if ($ref == null) {
            if (isset($this->sides_ref[$side]))
                unset($this->sides_ref[$side]);
        } else
            $this->sides_ref[$side] = $ref;
Ayolo's avatar
bleh  
Ayolo committed
211
    }
Ayolo's avatar
Ayolo committed
212

Colonel's avatar
Colonel committed
213 214 215 216 217
    /** Ajoute une boite affichable sur le coté
     * $name Nom de la boite
     * $contents Instance de stdcontents à afficher
     */
    function add_box($name, $contents)
Feu's avatar
Feu committed
218
    {
Colonel's avatar
Colonel committed
219 220 221
        if (is_null($contents))
            return;
        $this->boxes[$name] = $contents;
Feu's avatar
Feu committed
222
    }
Lopar's avatar
Lopar committed
223

Colonel's avatar
Colonel committed
224 225 226 227 228 229 230
    /** Ajoute une boite de contenu (dans le centre).
     * Si un titre est défini, alors il sera affiché.
     * @param $contents Instance de stdcontents à afficher.
     */
    function add_contents($contents)
    {
        $this->contents[] = $contents;
Antoine Tenart's avatar
plop  
Antoine Tenart committed
231 232
    }

Colonel's avatar
Colonel committed
233 234 235 236 237
    /** Initlialise la page
     * @param $section Nom de la section
     * @param $title Titre de la page
     */
    function start_page($section, $title, $compact = false) // <=> page
Ayolo's avatar
bleh  
Ayolo committed
238
    {
Colonel's avatar
Colonel committed
239 240 241
        $this->section = $section;
        $this->title = $title;
        $this->compact = $compact;
Antoine Tenart's avatar
Antoine Tenart committed
242
    }
Ayolo's avatar
bleh  
Ayolo committed
243

Colonel's avatar
Colonel committed
244 245 246 247
    /** Calcul de la survie des bars :P
     *
     */
    function get_comptoir()
Ayolo's avatar
bleh  
Ayolo committed
248
    {
Colonel's avatar
Colonel committed
249
        return '';
Ayolo's avatar
bleh  
Ayolo committed
250
    }
Ayolo's avatar
bleh  
Ayolo committed
251

Colonel's avatar
Colonel committed
252
    function add_css($url)
Ayolo's avatar
bleh  
Ayolo committed
253
    {
Colonel's avatar
Colonel committed
254
        $this->extracss[] = $url;
Ayolo's avatar
bleh  
Ayolo committed
255
    }
Colonel's avatar
Colonel committed
256 257

    function add_js($url)
Ayolo's avatar
bleh  
Ayolo committed
258
    {
Colonel's avatar
Colonel committed
259
        $this->extrajs[] = $url;
Ayolo's avatar
bleh  
Ayolo committed
260
    }
Colonel's avatar
Colonel committed
261 262

    function add_rss($title, $url)
Ayolo's avatar
bleh  
Ayolo committed
263
    {
Colonel's avatar
Colonel committed
264
        $this->add_alternate("application/rss+xml", $title, $url);
Ayolo's avatar
bleh  
Ayolo committed
265
    }
Colonel's avatar
Colonel committed
266 267 268 269

    /** Termine et affiche la page
     */
    function end_page() // <=> html_render
Ayolo's avatar
bleh  
Ayolo committed
270
    {
Colonel's avatar
Colonel committed
271 272
        global $fstopdir, $wwwtopdir, $topdir, $timing;
        $timing["render"] -= microtime(true);
273

Colonel's avatar
Colonel committed
274
        header("Content-Type: text/html; charset=utf-8");
275

Colonel's avatar
Colonel committed
276 277 278 279 280 281 282
        $this->buffer .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\">\n";
        $this->buffer .= "<head>\n";

        $this->buffer .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"; // (IE6 Legacy support)
        if (!defined('NOTAE')) {
            $this->buffer .= "<title>" . htmlentities($this->title, ENT_COMPAT, "UTF-8") . " - association des etudiants de l'utbm</title>\n";
            if (!defined("MOBILE"))
Skia's avatar
Skia committed
283
                $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "themes/default3/css/site3.css?" . filemtime($fstopdir . "themes/default3/css/site3.css") . "\" title=\"AE2-DEFAULT\" />\n";
Colonel's avatar
Colonel committed
284 285 286 287 288 289 290 291
            else
                $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "themes/mobile/css/site.css?" . filemtime($fstopdir . "themes/mobile/css/site.css") . "\" title=\"AE2-MOBILE\" />\n";
        } else {
            $this->buffer .= "<title>" . htmlentities($this->title, ENT_COMPAT, "UTF-8") . "</title>\n";
            if (isset($this->css))
                $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . $this->css . "?" . filemtime($fstopdir . $this->css) . "\" title=\"AE2-NEW2\" />\n";
            else {
                if (!defined("MOBILE"))
Skia's avatar
Skia committed
292
                    $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "themes/default3/css/site3.css?" . filemtime($fstopdir . "themes/default3/css/site3.css") . "\" title=\"AE2-NEW3\" />\n";
Colonel's avatar
Colonel committed
293 294 295
                else
                    $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "themes/mobile/css/site.css?" . filemtime($fstopdir . "themes/mobile/css/site.css") . "\" title=\"AE2-MOBILE\" />\n";
            }
Ayolo's avatar
bleh  
Ayolo committed
296
        }
Colonel's avatar
Colonel committed
297 298 299 300 301 302 303 304 305 306 307
        foreach ($this->extracss as $url)
            if (file_exists(htmlentities($fstopdir . $url, ENT_COMPAT, "UTF-8")))
                $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
                    htmlentities($wwwtopdir . $url, ENT_COMPAT, "UTF-8") . "?" .
                    filemtime(htmlentities($fstopdir . $url, ENT_COMPAT, "UTF-8")) . "\" />\n";

        foreach ($this->alternate as $row) {
            $this->buffer .= "<link rel=\"alternate\" " .
                "type=\"" . htmlentities($row[0], ENT_COMPAT, "UTF-8") . "\" " .
                "title=\"" . htmlentities($row[1], ENT_COMPAT, "UTF-8") . "\" " .
                "href=\"" . htmlentities($row[2], ENT_COMPAT, "UTF-8") . "\" />\n";
Ayolo's avatar
bleh  
Ayolo committed
308
        }
309

Colonel's avatar
Colonel committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
        if (!empty($this->meta_keywords))
            $this->buffer .= "<meta name=\"keywords\" content=\"" . htmlentities($this->meta_keywords, ENT_COMPAT, "UTF-8") . "\" />\n";

        if (!empty($this->meta_description))
            $this->buffer .= "<meta name=\"description\" content=\"" . htmlentities($this->meta_description, ENT_COMPAT, "UTF-8") . "\" />\n";

        $this->buffer .= "<link rel=\"SHORTCUT ICON\" href=\"" . $wwwtopdir . "favicon.ico?" . filemtime($fstopdir . "favicon.ico") . "\" />\n";
        if (!defined("MOBILE")) {
            $this->buffer .= "<script type=\"text/javascript\">var site_topdir='" . $wwwtopdir . "';</script>\n";
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/site.js?" . filemtime($fstopdir . "js/site.js") . "\"></script>\n";
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/ajax.js?" . filemtime($fstopdir . "js/ajax.js") . "\"></script>\n";
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/dnds.js?" . filemtime($fstopdir . "js/dnds.js") . "\"></script>\n";
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/box_slideshow.js?" . filemtime($fstopdir . "js/box_slideshow.js") . "\"></script>\n";
        } else {
            /*  add manualy extra js scripts. Mobile version have to be light ! */
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/mobile.js?" . filemtime($fstopdir . "js/mobile.js") . "\"></script>\n";
        }
Ayolo's avatar
Ayolo committed
327

Colonel's avatar
Colonel committed
328 329 330 331 332 333 334 335 336 337
        foreach ($this->extrajs as $url)
            $this->buffer .= "<script type=\"text/javascript\" src=\"" . htmlentities($wwwtopdir . $url, ENT_QUOTES, "UTF-8") . "?" . filemtime(htmlentities($fstopdir . $url, ENT_QUOTES, "UTF-8")) . "\"></script>\n";

        $this->buffer .= "</head>\n";

        $this->buffer .= "<body>\n";
        /* Generate the logo */
        $this->buffer .= "<div id=\"site\">\n";
        if (!defined("MOBILE")) {
            $ovl = false;
Colonel's avatar
Colonel committed
338

Lopar's avatar
Lopar committed
339

Colonel's avatar
Colonel committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
            $this->buffer .= "<div id=\"dropmenudiv\" onmouseover=\"clearhidemenu()\" onmouseout=\"dynamichide(event)\"></div>\n";
            $this->buffer .= "<div id=\"overlay\" " . (!$ovl ? "onclick=\"hideConnexionBox()\"" : "") . " style=\"display:" . ($ovl ? 'block' : 'none') . "\"></div>\n";
            if (!$this->user->is_valid()) {
                /* Come back here after ! */
                $_SESSION['session_redirect'] = $_SERVER["REQUEST_URI"];

                $this->buffer .= '<div id="passwordbox" style="display:none">';
                $this->buffer .= '<img id="close" src="' . $topdir . 'images/actions/delete.png" onclick="hideConnexionBox()" alt="Fermer" ';
                $this->buffer .= 'title="Fermer" />';
                $frm = new form("connect", $topdir . "connect.php", true, "POST", "Connexion");
                $jsoch = "javascript:switchSelConnection(this);";
                $frm->add_select_field("domain",
                    "Connexion",
                    array("utbm" => "UTBM / Assidu",
                        "carteae" => "Carte AE",
                        "id" => "ID",
                        "autre" => "E-mail",
                        "alias" => "Alias"),
                    false,
                    "",
                    false,
                    true,
                    $jsoch);
                $frm->add_text_field("username", "Utilisateur", "prenom.nom", "", 20, true, true, null, false, 35);
                $frm->add_password_field("password", "Mot de passe", "", "", 20);
                $frm->add_checkbox("personnal_computer", "Me connecter automatiquement la prochaine fois", false);
                $frm->add_submit("connectbtn", "Se connecter");
                $this->buffer .= $frm->html_render();
                unset($frm);
                $this->buffer .= "</div>\n";
            }
        } /* ifndef MOBILE */ else {
            if ($this->user->is_valid()) {
                $this->buffer .= "<div id=\"overlay\" onclick=\"updateMenu()\" style=\"display:none\"></div>\n";
                $this->buffer .= "<div id=\"menuContent\" style=\"display:none;\">\n";

                $this->buffer .= "<a href=\"./\">Accueil</a>";
                $this->buffer .= "<a href=\"./edt.php\">Emploi du temps</a>";
                $this->buffer .= "<a href=\"./matmat.php\">Mat'Matronch</a>";
                if ($this->user->ae)
                    $this->buffer .= "<p>Compte AE : " . (sprintf("%.2f", $this->user->montant_compte / 100)) . "</p>";
                //$this->buffer .= "<a href=\"./forum2.php\">Forum</a>";

                $this->buffer .= "</div>";
            }
        }
Lopar's avatar
Lopar committed
386

Colonel's avatar
Colonel committed
387 388 389 390 391 392 393 394 395 396 397 398 399
        /* header */
        $this->buffer .= "<div id='header'>\n";
        if (!defined('NOTAE')) {
            if (!defined("MOBILE")) {
                $important = $this->get_param('box.Important');
                if (!empty($important) && $important != "<p />") {
                    $this->buffer .= "<div class=\"box\" id=\"important\">\n";
                    $this->buffer .= "<a class=\"logo\" href=\"http://ae.utbm.fr\"></a>";
                    $this->buffer .= "<div class=\"body\">\n";
                    $this->buffer .= $important . "\n";
                    $this->buffer .= "</div></div>\n";
                }
            }
Lopar's avatar
Lopar committed
400

Colonel's avatar
Colonel committed
401 402 403 404 405 406
            //if (isset($_SERVER['HTTPS']))
            $url = "https://ae.utbm.fr";
            //else
            //  $url = "http://ae.utbm.fr";
            if ($GLOBALS["taiste"])
                $url .= "/taiste/";
Lopar's avatar
Lopar committed
407

Colonel's avatar
Colonel committed
408 409
            if (defined("MOBILE"))
                $url .= 'm/';
gliss's avatar
gliss committed
410

Colonel's avatar
Colonel committed
411
            $this->buffer .= "<div id=\"logo\">";
Lopar's avatar
Lopar committed
412

Colonel's avatar
Colonel committed
413 414 415 416
            if (!defined("MOBILE"))
                $this->buffer .= "<a href=\"" . $url . "\"><img src=\"" . $wwwtopdir . "images/ae_header.png\" alt=\"Logo AE\"/></a>";
            else
                $this->buffer .= "<img src=\"" . $wwwtopdir . "images/ae_header.png\" alt=\"Logo AE\"/>";
Lopar's avatar
Lopar committed
417

Colonel's avatar
Colonel committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
            $this->buffer .= "</div>\n";
        }
        if (isset($this->logo))
            $this->buffer .= "<div id=\"logo\"><img src=\"" . $wwwtopdir . "images/" . $this->logo . "\" alt=\"Logo\"/></div>\n";

        $this->buffer .= "<div id='headermenu'>\n";
        if (!defined("MOBILE")) {
            if (!$this->user->is_valid()) {
                $this->buffer .= "<script type=\"text/javascript\">\n";
                $this->buffer .= "var menu_utilisateur=new Array();";
                $this->buffer .= "menu_utilisateur[0]='<a class=\"firstdropdown\" href=\"" . $topdir . "connect.php\" onclick=\"return showConnexionBox()\">Connexion</a>';";
                $this->buffer .= "menu_utilisateur[1]='<a href=\"" . $topdir . "password.php\">Mot de passe perdu</a>';";
                $this->buffer .= "menu_utilisateur[2]='<a href=\"" . $topdir . "newaccount.php\">Créer un compte</a>';";
                $this->buffer .= "</script>";
                $this->buffer .= "<div id='login' onmouseover=\"dropdownmenu(this, event, menu_utilisateur)\" onmouseout=\"delayhidemenu()\">\n";
                $this->buffer .= "<a href='" . $topdir . "connect.php'>Identification</a>\n";
            } elseif ($this->user->type == "srv") {
                $this->buffer .= "<script type=\"text/javascript\">\n";
                $this->buffer .= "var menu_utilisateur=new Array();";
                $i = 0;
                $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "disconnect.php\">Déconnexion</a>';";
                $this->buffer .= "</script>";
                $this->buffer .= "<div id='login' onmouseover=\"dropdownmenu(this, event, menu_utilisateur)\" onmouseout=\"delayhidemenu()\">\n";
                $this->buffer .= "<a href=\"" . $topdir . "boutique-utbm/suivi.php\">Suivi commandes</a>\n";
            } else {
                if (!defined('NOTAE') && $this->user->ae) {
                    $this->buffer .= $this->get_comptoir();
                }
                $this->buffer .= "<script type=\"text/javascript\">\n";
                $this->buffer .= "var menu_utilisateur=new Array();";
                $i = 0;
                if (!defined('NOTAE')) {
                    $this->buffer .= "menu_utilisateur[$i]='<a class=\"firstdropdown\" href=\"" . $topdir . "user.php?id_utilisateur=" . $this->user->id . "\">Mes informations</a>';";
                    $i++;
                    if ($this->user->ae) {
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "user/compteae.php\">Compte AE : " . (sprintf("%.2f", $this->user->montant_compte / 100)) . " €</a>';";
                        $i++;
                    }
                    $i++;
                    $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "user/outils.php\">Mes outils</a>';";
                    if ($this->user->is_in_group("root")) {
                        $i++;
                        $req = new requete ($this->db,
                            "SELECT COUNT(*) AS tot FROM `ae_info_todo` " .
                            "WHERE `id_utilisateur_assignee` = '0' " .
                            "AND `status` = '0'");

                        if ($req->lines > 0) {
                            $row = $req->get_row();

                            if (isset($row['tot']) && $row['tot'] > 0)
                                $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "ae/infotodo.php\">Tâches équipe info (" .
                                    $row['tot'] . ")</a>';";
                            else
                                $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "ae/infotodo.php\">Tâches équipe info</a>';";
                        } else {
                            $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "ae/infotodo.php\">Tâches équipe info</a>';";
                        }
                        $i++;
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"/taiste/\">/taiste</a>';";
                    }
                    $i++;
                    if ($this->user->utbm) {
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "trombi/index.php\">Trombinoscope</a>';";
                        $i++;
                    }
                    if ($this->user->is_in_group("jobetu_etu")) {
                        $jobuser = new jobuser_etu($this->db);
                        $jobuser->load_by_id($this->user->id);
                        $jobuser->load_annonces();
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"" .
                            $topdir . "jobetu/board_etu.php\">Mon compte JobEtu (" . count($jobuser->annonces) . ")</a>';";
                        unset($jobuser);
                    } elseif ($this->user->is_in_group("jobetu_client"))
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "jobetu/board_client.php\">AE JobEtu</a>';"; else
                        $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "jobetu/index.php\">AE JobEtu</a>';";
                    $i++;
                }
                $this->buffer .= "menu_utilisateur[$i]='<a href=\"" . $topdir . "disconnect.php\">Déconnexion</a>';";
                $this->buffer .= "</script>";
                $this->buffer .= "<div id='login' onmouseover=\"dropdownmenu(this, event, menu_utilisateur)\" onmouseout=\"delayhidemenu()\">\n";
                $this->buffer .= "<a href=\"" . $topdir . "user.php?id_utilisateur=" . $this->user->id . "\">" . $this->user->prenom . " " . $this->user->nom . "</a>";
Ayolo's avatar
bleh  
Ayolo committed
500
            }
Colonel's avatar
Colonel committed
501 502 503 504 505
        } else { /* ifndef MOBILE */
            if ($this->user->is_valid()) {
                $this->buffer .= $this->get_comptoir();
                $this->buffer .= "<a id=\"menu\" href=\"javascript:updateMenu();\">menu</a>";
                $this->buffer .= "<a href=\"disconnect.php\"><img id=\"deco\" src=\"../images/actions/stop.png\" alt=\"Déconnexion\" /></a>";
Ayolo's avatar
bleh  
Ayolo committed
506
            }
Colonel's avatar
Colonel committed
507 508
        } /* ifdef MOBILE */
        $this->buffer .= "</div>\n";
Lopar's avatar
Lopar committed
509

Colonel's avatar
Colonel committed
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
        if (!defined("MOBILE")) {
            if (!defined('NOTAE')) {
                $req = new requete($this->db,
                    "SELECT `asso`.`id_asso`, " .
                    "`asso`.`nom_asso` " .
                    "FROM `asso_membre` " .
                    "INNER JOIN `asso` ON `asso`.`id_asso`=`asso_membre`.`id_asso` " .
                    "WHERE `asso_membre`.`role` > 1 AND `asso_membre`.`date_fin` IS NULL " .
                    "AND `asso_membre`.`id_utilisateur`='" . $this->user->id . "' " .
                    "AND `asso`.`id_asso` != '1' " .
                    "ORDER BY asso.`nom_asso`");
                $req2 = new requete($this->db,
                    "SELECT id_comptoir,nom_cpt " .
                    "FROM cpt_comptoir " .
                    "WHERE id_groupe IN (" . $this->user->get_groups_csv() . ") AND nom_cpt != 'test' " .
                    "AND archive != '1' " .
                    "ORDER BY nom_cpt");

                if ($req->lines > 0
                    || $req2->lines > 0
                    || $this->user->is_in_group("root")
                    || $this->user->is_in_group("moderateur_site")
                    || $this->user->is_in_group("compta_admin")
                    || $this->user->is_in_group("gestion_ae")
                    || $this->user->is_in_group("gestion_syscarteae")
                ) {
                    $this->buffer .= "<script type=\"text/javascript\">\n";
                    $this->buffer .= "var menu_assos=new Array();";
                    $i = 0;
                    $class = "class=\"firstdropdown\"";

                    /* Droits spécifiques */
                    if ($this->user->is_in_group("root")) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "rootplace/index.php\">Équipe informatique</a>';";
                        $i++;
                        $class = "";
                    }
                    if ($this->user->is_in_group("moderateur_site")) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "ae/com.php\">Équipe com</a>';";
                        $i++;
                        $class = "";
                    }
                    if ($this->user->is_in_group("compta_admin")) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "ae/compta.php\">Équipe trésorerie</a>';";
                        $i++;
                        $class = "";
                    }
                    if ($this->user->is_in_group("gestion_ae")) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "ae/\">Équipe AE</a>';";
                        $i++;
                        $class = "";
                    }
                    if ($this->user->is_in_group("gestion_syscarteae")) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "ae/syscarteae.php\">Carte AE</a>';";
                        $i++;
                        $class = "";
                    }

                    /* Gestion assos */
                    while (list($id, $nom) = $req->get_row()) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "asso/index.php?id_asso=$id\">" . str_replace("'", "\'", $nom) . "</a>';";
                        $i++;
                        $class = "";
                    }

                    /* Admins comptoirs */
                    if ($req2->lines > 4) {
                        $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "comptoir/admin.php\">Admin : comptoirs</a>';";
                        $i++;
                        $class = "";
                    } else {
                        while (list($id, $nom) = $req2->get_row()) {
                            $this->buffer .= "menu_assos[" . $i . "]='<a $class href=\"" . $topdir . "comptoir/admin.php?id_comptoir=$id\">Admin : " . str_replace("'", "\'", $nom) . "</a>';";
                            $i++;
                            $class = "";
                        }
                    }

                    $this->buffer .= "</script>";
                    $this->buffer .= "<div id='assos' onmouseover=\"dropdownmenu(this, event, menu_assos, '150px')\" onmouseout='delayhidemenu()'>\n";
                    $this->buffer .= "Gestion assos/clubs";
                    $this->buffer .= "</div>\n";
                }

                $this->buffer .= "<div id=\"fsearchbox\">\n";
                $this->buffer .= "<form action=\"" . $wwwtopdir . "fsearch.php\" method=\"post\">";
                $this->buffer .= "<input type=\"text\" id=\"fsearchpattern\" name=\"pattern\" onblur=\"fsearch_stop_delayed();\" onkeyup=\"fsearch_keyup(event);\" value=\"\" />\n";
                $this->buffer .= "</form>";
                $this->buffer .= "<div class=\"fend\"></div></div>\n";
            }
            $this->buffer .= "</div>\n";
            if (!defined('NOTAE'))
                $this->buffer .= "<div id=\"fsearchres\"></div>\n";
        } /* ifndef MOBILE */
        $this->buffer .= "</div>\n";
        /* fin header */
Lopar's avatar
Lopar committed
606

Colonel's avatar
Colonel committed
607 608
        $this->buffer .= "<div class=\"tabsv2\">\n";
        $links = null;
Lopar's avatar
Lopar committed
609

Colonel's avatar
Colonel committed
610
        foreach ($this->tab_array as $entry) {
Lopar's avatar
Lopar committed
611

Colonel's avatar
Colonel committed
612 613 614 615 616 617
            $this->buffer .= "<span";
            if ($this->section == $entry[0]) {
                $this->buffer .= " class=\"selected tab" . $entry[0] . "\"";
                $links = $entry[3];
            } else
                $this->buffer .= " class=\"tab" . $entry[0] . "\"";
Lopar's avatar
Lopar committed
618

Colonel's avatar
Colonel committed
619 620
            $this->buffer .= "><a id=\"tab_" . $entry[0] . "\" href=\"" . $wwwtopdir . $entry[1] . "\"";
            $this->buffer .= " title=\"" . $entry[2] . "\">" . $entry[2] . "</a></span>";
Ayolo's avatar
bleh  
Ayolo committed
621
        }
Lopar's avatar
Lopar committed
622

Colonel's avatar
Colonel committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
        $this->buffer .= "</div>\n"; // /tabs

        if (!defined("MOBILE")) { /* this is too elaborate for a mobile website */
            if ($links) {
                $this->buffer .= "<div class=\"sectionlinks\">";

                foreach ($links as $entry) {
                    if (($entry[0] == "forum2/admin/") && (!$this->user->is_in_group('root') && !$this->user->is_in_group('moderateur_forum')))
                        continue;

                    if (!strncmp("http://", $entry[0], 7))
                        $this->buffer .= "<a href=\"" . $entry[0] . "\">" . $entry[1] . "</a>";
                    elseif (!empty($entry[0]))
                        $this->buffer .= "<a href=\"" . $wwwtopdir . $entry[0] . "\">" . $entry[1] . "</a>"; else
                        $this->buffer .= "<span>" . $entry[1] . "</span>";
                }

                $this->buffer .= "</div>\n";
            } else
                $this->buffer .= "<div class=\"emptysectionlinks\"></div>\n";
        } /* ifndef MOBILE */

        $this->buffer .= "<div class=\"contents\">\n";
        $idpage = "";

        $mode = $this->user->id > 0 ? "c" : "nc";

        if (!defined("MOBILE")) { /* ths is too elaborate for a mobile version */
            foreach ($this->sides as $side => $names) {
                if (count($names)) {
                    $pattern = "auto_$side";
                    foreach ($this->boxes as $name => $cts) {
                        if (!strncmp($name, $pattern, strlen($pattern))) {
                            $names = array_merge(array($name), $names);
                        }

                    }

                    $idpage .= substr($side, 0, 1);

                    if (isset($this->sides_ref[$side])) {
                        $ref = "dnds_" . $this->sides_ref[$side];
                        if (isset($_SESSION["usersession"][$ref])) {
                            $n_names = array();
                            $elts = explode(",", $_SESSION["usersession"][$ref]);
                            foreach ($elts as $elt) {
                                $name = substr($elt, 5);
                                if (in_array($name, $names))
                                    $n_names[] = $name;
                            }
                            foreach ($names as $name) {
                                if (!in_array($name, $n_names))
                                    $n_names = array_merge(array($name), $n_names);
                            }
                            $names = $n_names;
                        }
                    } else
                        $ref = null;

                    $this->buffer .= "<div id=\"" . $side . "\" class=\"clearfix\">\n";
                    foreach ($names as $name) {

                        if ($cts = $this->boxes[$name]) {
                            $this->buffer .= "<div class=\"box\" id=\"sbox_" . $name . "\">\n";
                            if ($cts->title && ($ref != null))
                                $this->buffer .= "<h1><a onmousedown=\"dnds_startdrag(event,'sbox_" . $name . "','" . $ref . "');\" class=\"dragstartzone\">" . $cts->title . "</a></h1>\n";
                            elseif ($cts->title)
                                $this->buffer .= "<h1>" . $cts->title . "</h1>\n";

                            $this->buffer .= "<div class=\"body\" id=\"sbox_body_" . $name . "\">\n";

                            $this->buffer .= $cts->html_render();

                            $this->buffer .= "</div>\n";
                            $this->buffer .= "</div>\n";
                        }

                    }
                    $this->buffer .= "</div>\n";
                }
            }
        } /* ifndef MOBILE */
Lopar's avatar
Lopar committed
705

Colonel's avatar
Colonel committed
706
        if ($idpage == "") $idpage = "n";
Lopar's avatar
Lopar committed
707

Colonel's avatar
Colonel committed
708 709
        $this->buffer .= "\n<!-- page -->\n";
        $this->buffer .= "<div class=\"page\" id=\"" . $idpage . "\">\n";
Lopar's avatar
Lopar committed
710

Colonel's avatar
Colonel committed
711 712 713
        $i = 0;
        foreach ($this->contents as $cts) {
            $cssclass = "article";
Lopar's avatar
Lopar committed
714

Colonel's avatar
Colonel committed
715 716
            if (!is_null($cts->cssclass))
                $cssclass = $cts->cssclass;
Lopar's avatar
Lopar committed
717

Colonel's avatar
Colonel committed
718
            $i++;
Lopar's avatar
Lopar committed
719 720


Colonel's avatar
Colonel committed
721 722 723 724 725 726
            $this->buffer .= "<div class=\"" . $cssclass . "\"";
            if ($cts->divid)
                $this->buffer .= " id=\"" . $cts->divid . "\"";
            else
                $this->buffer .= " id=\"cts" . $i . "\"";
            $this->buffer .= ">\n";
Lopar's avatar
Lopar committed
727

Colonel's avatar
Colonel committed
728 729 730 731 732
            if ($cts->toolbox) {
                $this->buffer .= "<div class=\"toolbox\">\n";
                $this->buffer .= $cts->toolbox->html_render() . "\n";
                $this->buffer .= "</div>\n";
            }
Feu's avatar
Feu committed
733

Colonel's avatar
Colonel committed
734 735
            if ($cts->title)
                $this->buffer .= "<h1>" . $cts->title . "</h1>\n";
Lopar's avatar
Lopar committed
736

Colonel's avatar
Colonel committed
737
            $this->buffer .= $cts->html_render();
Lopar's avatar
Lopar committed
738

Colonel's avatar
Colonel committed
739 740
            $this->buffer .= "</div>\n";
        }
Lopar's avatar
Lopar committed
741

Colonel's avatar
Colonel committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
        $this->buffer .= "</div>\n"; // /page
        $this->buffer .= "<!-- end of page -->\n\n";
        $this->buffer .= "</div>\n"; // /contents
        $this->buffer .= "<div id=\"contentsend\">&nbsp;</div>\n";
        $this->buffer .= "<div id=\"endsite\">";
        $this->buffer .= "<div id=\"endsitelinks\">";
        if (!defined('NOTAE')) {
            if (!defined("MOBILE")) {
                $this->buffer .= "<a href=\"" . $wwwtopdir . "article.php?name=contacts\">CONTACTS</a> ";
                $this->buffer .= "<a href=\"" . $wwwtopdir . "article.php?name=legals\">MENTIONS LÉGALES</a> ";
                $this->buffer .= "<a href=\"" . $wwwtopdir . "copyright_agent.php\">PROPRIÉTÉ INTELLECTUELLE</a>";
                $this->buffer .= "<a href=\"" . $wwwtopdir . "article.php?name=docs:index\">AIDE ET DOCUMENTATION</a> ";
                $this->buffer .= "<a href=\"" . $wwwtopdir . "article.php?name=rd\">R&amp;D</a> ";
            } else { /* TODO */
            }
        } elseif (isset($this->footer))
            $this->buffer = $this->footer;
        $this->buffer .= "</div>"; // /endsitelinks
        $this->buffer .= "</div>"; // /endsite
        $this->buffer .= "</div>\n"; // /site

        if ($this->get_param("backup_server", true)) {
            $this->buffer .= "<div id=\"topalert\">";
            $this->buffer .= "<img width=\"16\" height=\"16\" src=\"" . $wwwtopdir . "themes/default/images/exclamation.png\" />";
            $this->buffer .= "Le système fonctionne actuellement sur le serveur de secours, " .
                "veuillez limiter vos actions au strict minimum.";
            $this->buffer .= "</div>";
        } elseif ($this->get_param("warning_enabled", true)) {
            $this->buffer .= "<div id=\"topalert\">";
            $this->buffer .= "<img width=\"16\" height=\"16\" src=\"" . $wwwtopdir . "themes/default/images/exclamation.png\" />";
            $this->buffer .= $this->get_param("warning_message");
            $this->buffer .= "</div>";
        }
        $this->buffer .= "</body>\n";
        $this->buffer .= "</html>\n";

        /**
         * Reduce page's weight for mobile version
         * May we can always do it ?
         *
         * For taiste version, do not apply !
         *
         * TODO : include css files in buffer and reduce weight too for mobile version
         */
        if (defined("MOBILE") && !$GLOBALS["taiste"]) $this->buffer = strtr($this->buffer, array("\n" => "", "\r" => ""));

        echo $this->buffer;
        $timing["render"] += microtime(true);
        $timing["all"] += microtime(true);
        echo "<!-- ";
        if ($GLOBALS["taiste"]) {
            print_r($timing);
            echo "\non est en taiste\n";
        }
        echo " -->";
BenC's avatar
BenC committed
797
    }
Colonel's avatar
Colonel committed
798 799 800 801 802

    /**
     * Rendu de la page en mode popup (sans header, sans boites laterales)
     */
    function popup_end_page()
BenC's avatar
BenC committed
803
    {
Colonel's avatar
Colonel committed
804
        global $fstopdir, $wwwtopdir;
805

Colonel's avatar
Colonel committed
806
        header("Content-Type: text/html; charset=utf-8");
Lopar's avatar
Lopar committed
807

Colonel's avatar
Colonel committed
808
        //$this->buffer .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
Lopar's avatar
Lopar committed
809

Colonel's avatar
Colonel committed
810 811 812 813 814 815 816 817
        $this->buffer .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\">\n";
        $this->buffer .= "<head>\n";
        $this->buffer .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
        $this->buffer .= "<title>" . htmlentities($this->title, ENT_COMPAT, "UTF-8") . " - association des etudiants de l'utbm</title>\n";
        $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "themes/default/css/site.css?" . filemtime($fstopdir . "themes/default/css/site.css") . "\" title=\"AE2-NEW2\" />\n";
        $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $wwwtopdir . "css/popup.css?" . filemtime($fstopdir . "css/popup.css") . "\" />\n";
        foreach ($this->extracss as $url)
            $this->buffer .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlentities($wwwtopdir . $url, ENT_COMPAT, "UTF-8") . "\" />\n";
Lopar's avatar
Lopar committed
818

Colonel's avatar
Colonel committed
819 820
        foreach ($this->rss as $title => $url)
            $this->buffer .= "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"" . htmlentities($title, ENT_COMPAT, "UTF-8") . "\" href=\"" . htmlentities($url, ENT_COMPAT, "UTF-8") . "\" />";
Lopar's avatar
Lopar committed
821

Colonel's avatar
Colonel committed
822 823
        $this->buffer .= "<link rel=\"SHORTCUT ICON\" href=\"" . $wwwtopdir . "favicon.ico\" />\n";
        $this->buffer .= "<script type=\"text/javascript\">var site_topdir='" . $wwwtopdir . "';</script>\n";
824 825 826
        $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/site.js\" async></script>\n";
        $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/ajax.js\" async></script>\n";
        $this->buffer .= "<script type=\"text/javascript\" src=\"" . $wwwtopdir . "js/dnds.js\" async></script>\n";
Lopar's avatar
Lopar committed
827

Colonel's avatar
Colonel committed
828
        foreach ($this->extrajs as $url)
Dustri's avatar
Dustri committed
829
            $this->buffer .= "<script defer async type=\"text/javascript\" src=\"" . htmlentities($wwwtopdir . $url, ENT_QUOTES, "UTF-8") . "\"></script>\n";
Lopar's avatar
Lopar committed
830

Colonel's avatar
Colonel committed
831
        $this->buffer .= "</head>\n";
Lopar's avatar
Lopar committed
832

Colonel's avatar
Colonel committed
833 834
        $this->buffer .= "<body>\n";
        /* Generate the logo */
Lopar's avatar
Lopar committed
835

Colonel's avatar
Colonel committed
836
        $this->buffer .= "<div id=\"popup\">";
Lopar's avatar
Lopar committed
837

Colonel's avatar
Colonel committed
838 839 840
        $i = 0;
        foreach ($this->contents as $cts) {
            $cssclass = "article";
Lopar's avatar
Lopar committed
841

Colonel's avatar
Colonel committed
842 843
            if (!is_null($cts->cssclass))
                $cssclass = $cts->cssclass;
Lopar's avatar
Lopar committed
844

Colonel's avatar
Colonel committed
845 846 847 848 849 850 851
            $i++;
            $this->buffer .= "<div class=\"" . $cssclass . "\"";
            if ($cts->divid)
                $this->buffer .= " id=\"" . $cts->divid . "\"";
            else
                $this->buffer .= " id=\"cts" . $i . "\"";
            $this->buffer .= ">\n";
Lopar's avatar
Lopar committed
852

Colonel's avatar
Colonel committed
853 854 855 856 857
            if ($cts->toolbox) {
                $this->buffer .= "<div class=\"toolbox\">\n";
                $this->buffer .= $cts->toolbox->html_render() . "\n";
                $this->buffer .= "</div>\n";
            }
Feu's avatar
Feu committed
858

Colonel's avatar
Colonel committed
859 860
            if ($cts->title)
                $this->buffer .= "<h1>" . $cts->title . "</h1>\n";
Lopar's avatar
Lopar committed
861

Colonel's avatar
Colonel committed
862 863 864
            $this->buffer .= $cts->html_render();
            $this->buffer .= "</div>\n";
        }
Lopar's avatar
Lopar committed
865

Colonel's avatar
Colonel committed
866 867 868 869 870
        $this->buffer .= "</div>\n";
        $this->buffer .= "</body>\n";
        $this->buffer .= "</html>\n";
        echo $this->buffer;
    }
Lopar's avatar
Lopar committed
871

Colonel's avatar
Colonel committed
872 873 874 875 876 877 878
    /** Charge tous les paramètres du site.
     * ATTENTION: ceci est UNIQUEMENT concu pour stocker des paramètres.
     * @private
     */
    function load_params()
    {
        $this->params = array();
Lopar's avatar
Lopar committed
879

Colonel's avatar
Colonel committed
880 881
        $req = new requete($this->db, "SELECT `nom_param`,`valeur_param` " .
            "FROM `site_parametres`");
Lopar's avatar
Lopar committed
882

Colonel's avatar
Colonel committed
883 884
        while (list($id, $name) = $req->get_row())
            $this->params[$id] = $name;
Lopar's avatar
Lopar committed
885

Colonel's avatar
Colonel committed
886 887
        $this->params["backup_server"] = serialize($_SERVER["BACKUP_AE_SERVER"]);
    }
Lopar's avatar
Lopar committed
888

Colonel's avatar
Colonel committed
889 890 891 892 893 894 895 896 897
    /**
     * Obtient un paramètre du site.
     * @param $name Nom du paramètre
     * @param $value $default par défaut retrouné si il n'est pas définit
     */
    function get_param($name, $default = null)
    {
        if (!$this->params)
            $this->load_params();
Ayolo's avatar
Ayolo committed
898

Colonel's avatar
Colonel committed
899 900
        if (!isset($this->params[$name]))
            return $default;
gliss's avatar
gliss committed
901

Colonel's avatar
Colonel committed
902 903
        return unserialize($this->params[$name]);
    }
Lopar's avatar
Lopar committed
904 905


Colonel's avatar
Colonel committed
906 907 908 909 910 911
    /**
     * Définit un paramètre du site.
     * @param $name Nom du paramètre
     * @param $value Valeur du paramètre.
     */
    function set_param($name, $value)
Ayolo's avatar
bleh  
Ayolo committed
912
    {
Colonel's avatar
Colonel committed
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
        if (!$this->params)
            $this->load_params();

        $value = serialize($value);

        if (!isset($this->params[$name])) {
            $sql = new insert($this->dbrw, "site_parametres",
                array(
                    "nom_param" => $name,
                    "valeur_param" => $value
                ));
            $this->params[$name] = $value;
        } elseif ($this->params[$name] !== $value) {
            $sql = new update($this->dbrw, "site_parametres",
                array("valeur_param" => $value),
                array("nom_param" => $name)); //$this->buffer .= " onmouseover=\"tabsection('".$entry[0]."', 'hoversectionlinks');\"";
            $this->params[$name] = $value;
        }
Ayolo's avatar
bleh  
Ayolo committed
931
    }
Ayolo's avatar
Ayolo committed
932

gliss's avatar
gliss committed
933

Colonel's avatar
Colonel committed
934 935 936 937 938 939 940 941 942 943
    /**
     * Vérifie que l'utilisateur est vraiment sûre de procéder à une opération.
     * Certifié "boulet proof(tm)".
     * Remarque: ne fonctionne pas dans le cas de passage de tableaux en GET/POST
     * @param $section Section de la page de confirmation
     * @param $message Message à afficher
     * @param $uid identifiant unique de la question
     * @param $level niveau d'incidence (0:pas grave, 1:peu risqué, 2:très risqué, 3:risque la colère des administrateurs)
     */
    function is_sure($section, $message, $uid = null, $level = 0)
Ayolo's avatar
bleh  
Ayolo committed
944
    {
Colonel's avatar
Colonel committed
945 946 947 948 949 950
        if (isset($_POST["___i_am_really_sure"])) {
            if ($GLOBALS["svalid_call"])
                return true;
            return false;
        } elseif (isset($_POST["___finally_i_want_to_cancel"]))
            return false;
Lopar's avatar
Lopar committed
951

Colonel's avatar
Colonel committed
952
        if (!$uid) $uid = $section . md5($message);
Lopar's avatar
Lopar committed
953

Colonel's avatar
Colonel committed
954
        $this->start_page($section, "Êtes vous sûr ?");
Lopar's avatar
Lopar committed
955

Colonel's avatar
Colonel committed
956
        $cts = new contents("Confirmation");
Lopar's avatar
Lopar committed
957

Colonel's avatar
Colonel committed
958 959
        if ($level == 2)
            $cts->add_paragraph("ATTENTION", "huge");
Lopar's avatar
Lopar committed
960

Colonel's avatar
Colonel committed
961
        $cts->add_paragraph($message);
Lopar's avatar
Lopar committed
962

Colonel's avatar
Colonel committed
963 964
        if ($level == 2)
            $cts->add_paragraph("Cette opération <b>pourrait avoir de lourdes conséquences</b> sur le <b>bon fonctionnement des services</b> si elle été appliquée sur un élément critique. <b>Contactez un administrateur en cas de doute</b>.");
Lopar's avatar
Lopar committed
965

Colonel's avatar
Colonel committed
966 967 968 969
        $cts->add_paragraph("Êtes vous sûr ?");
        if ($level == 3) {
            $phrase_magique = 'oui je suis sur de vouloir faire ça';
            $cts->add_paragraph('Tapez dans le champ correspondant et en toutes lettres la phrase "' . str_replace(' ', '&nbsp;', $phrase_magique) . '"');
mbriand's avatar
bleh  
mbriand committed
970
        }
Lopar's avatar
Lopar committed
971

Colonel's avatar
Colonel committed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
        $frm = new form("suretobesurefor" . $uid, "?");
        $frm->allow_only_one_usage();

        foreach ($_POST as $key => $val)
            if ($key != "magicform") {
                if ($key == "__script__")
                    $frm->add_hidden($key, htmlspecialchars($val));
                else if (is_array($val)) {
                    foreach ($val as $k => $v)
                        $frm->add_hidden($key . '[' . $k . ']', $v);
                } else
                    $frm->add_hidden($key, $val);
            }
        foreach ($_GET as $key => $val)
            if ($key != "magicform") {
                if (is_array($val)) {
                    foreach ($val as $k => $v)
                        $frm->add_hidden($key . '[' . $k . ']', $v);
                } else
                    $frm->add_hidden($key, $val);
            }

        if ($level == 3) {
            $_uid = gen_uid();
            $frm->add_text_field('____really_sure__' . $_uid, 'Tapez la phrase magique :', '', true, 50);
        }
jlaval's avatar
jlaval committed
998

Colonel's avatar
Colonel committed
999 1000
        $frm->add_submit("___i_am_really_sure", "OUI");
        $frm->add_submit("___finally_i_want_to_cancel", "NON");
Lopar's avatar
Lopar committed
1001

Colonel's avatar
Colonel committed
1002 1003 1004 1005
        $cts->add($frm);
        if ($level == 3)
            $cts->puts('<script type="text/javascript">
var txt = document.getElementsByName("____really_sure__' . $_uid . '")[0];
slopez's avatar
slopez committed
1006 1007
var sub = document.getElementById("___i_am_really_sure");
sub.disabled = true;
slopez's avatar
fix?  
slopez committed
1008 1009 1010 1011
txt.onkeyup = function (event){
  if ( event != null )
  {
    var sub = document.getElementById("___i_am_really_sure");
Colonel's avatar
Colonel committed
1012 1013
    var txt = document.getElementsByName("____really_sure__' . $_uid . '")[0];
    if (txt.value == "' . $phrase_magique . '")
slopez's avatar
fix?  
slopez committed
1014 1015 1016 1017
      sub.disabled = false;
    else
      sub.disabled = true;
  }
slopez's avatar
slopez committed
1018 1019
}
</script>');
Lopar's avatar
Lopar committed
1020

Colonel's avatar
Colonel committed
1021
        $this->add_contents($cts);
Lopar's avatar
Lopar committed
1022

Colonel's avatar
Colonel committed
1023 1024 1025
        $this->end_page();
        exit();
    }
Lopar's avatar
Lopar committed
1026

Colonel's avatar
Colonel committed
1027 1028 1029 1030 1031
    function set_meta_information($keywords, $description)
    {
        $this->meta_keywords = $keywords;
        $this->meta_description = $description;
    }
Lopar's avatar
Lopar committed
1032

Colonel's avatar
Colonel committed
1033 1034 1035 1036
    function add_alternate($type, $title, $href)
    {
        $this->alternate[] = array($type, $title, $href);
    }
Lopar's avatar
Lopar committed
1037

Colonel's avatar
Colonel committed
1038 1039 1040 1041 1042
    function add_alternate_geopoint(&$geopoint)
    {
        global $wwwtopdir;
        $this->add_alternate("application/vnd.google-earth.kml+xml", "KML", $wwwtopdir . "loc.php?id_geopoint=" . $geopoint->id . "&action=kml");
    }
Feu's avatar
Feu committed
1043

Lopar's avatar
Lopar committed
1044

Ayolo's avatar
Ayolo committed
1045 1046 1047
}

?>