<?php
/**
 * Cette classe représente une page
 */
require_once "DB.php";

class utils
{
    var $db;
    var $collectivite;
    var $droit;
    var $phptype;
    var $formatdate;
    
    function utils ()
    {
        $collectivite = array ();
        return $this -> connexion ();
    } // Constructeur
    
    function headerhtml ()
    {
         // * custom *
        include("../dyn/cg.css");
        if(file_exists("../dyn/custom/cg.css")) {
            include("../dyn/custom/cg.css");
        }
        echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
        echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" lang=\"fr\">\n";
        echo "\t<head>\n";
 /*       echo "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />\n";
        echo "\t\t<title>OpenParc</title>\n";
        //echo "\t\t<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"../img/favicon.ico\" />\n";
        echo "\t\t<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"../dyn/style.css\" />\n";
        echo "\t\t<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"../dyn/print.css\" />\n";
        echo "\t\t<script type=\"text/javascript\" src=\"../dyn/script.js\"></script>\n";
        echo "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../dyn/menu.css\" />\n";
        echo "\t\t<script type=\"text/javascript\" src=\"../dyn/menu.js\"></script>\n";*/
        include("../dyn/entete.inc");
        echo "\t</head>\n";
        echo "\t<body class='login'>\n";
    } // header ()
    
    function connexion ()
    {
        // grille de connexion
        if (file_exists ("../dyn/base.php"))
            include_once "../dyn/base.php";
        // $coll est fonction de la grille de connexion
        // chaque collectivite peut avoir une base differente suivant l'importance de la collectivite
        $coll = 1;
        if (!isset ($_SESSION ['coll']))
            $_SESSION ['coll'] = 1;
        else
            $coll = $_SESSION ['coll'];
        $titre = $conn [$coll][0];
        $dsn = array (
                'phptype' => $conn [$coll][1],
                'dbsyntax' => $conn [$coll][2],
                'username' => $conn [$coll][3],
                'password' => $conn [$coll][4],
                'protocol' => $conn [$coll][5],
                'hostspec' => $conn [$coll][6],
                'port' => $conn [$coll][7],
                'socket' => $conn [$coll][8],
                'database' => $conn [$coll][9]
        );
        $db_option = array (
                'debug' => 2,
                'portability' => DB_PORTABILITY_ALL
        );
        
        // Format de la date suivant la base utilisée
        $this -> formatdate = $conn [$coll][10];
        
        // Connexion à la BDD
        $this -> db =& DB :: connect ($dsn, $db_option);
        if (DB :: isError($this -> db))
                die ($this -> db ->getMessage ());
                
        $this -> phptype = $dsn ['phptype'];
    } //connexion ()
    
    function collectivite ()
    {
        $sql = "select * from collectivite";
        $res = $this -> db -> query ($sql);
        if (DB :: isError ($res))
                die ($res -> getMessage ()." erreur ".$sql);
        $row =& $res -> fetchRow (DB_FETCHMODE_ASSOC);
                $this -> collectivite = $row;
        $res -> free ();
    } // collectivite ()
    
    function droit ($obj)
    {
        $sql =  "select profil from droit where droit = '".$obj."'";
        $this -> droit = $this -> db -> getOne ($sql);
    } // droit ($obj)
    
    function header ($menu = 0, $ent = "", $ico = "", $obj = "")
    {
        //if ($menu == 1){
                $this -> menu ();
        //}
        echo "<div id=\"header\">\n";
        //if ($menu == 1)
        //{
//            echo "\t<div id=\"menu_fond\"></div>\n";
//            echo "\t<div id=\"logo\"><a href=\"../scr/login.php\"><img class=\"logo\" src=\"../img/logo.png\" alt=\"Accueil\" title=\"Accueil\" /></a></div>\n";
//            echo "\t<div id=\"ville\">".htmlentities ($this -> collectivite ['ville'])."</div>\n";
//            echo "\t<div id=\"date\">Date : ".date("d / m / Y")."</div>\n";
        //}
        echo "\t<div id=\"top\">";
        /*if (isset($_SESSION ['login']))
        {
          if ($_SESSION ['login']!="") {
            echo $_SESSION ['login'];
            echo " | ";
            // mode demo
            include ("../dyn/var.inc");
            if($demo==1){
                echo "<a class=\"MotdePasse\" href=\"#\" title=\"non accessible en demo\">Mot de Passe</a>";
            }else{
                echo "<a class=\"MotdePasse\" href=\"../spg/loginchangepwd.php\" title=\"Changer votre mot de passe\">Mot de Passe</a>";
            }
            echo " | ";
            echo "<a class=\"Deconnexion\" href=\"../spg/login.php?dec=1\" title=\"Quitter\">D&eacute;connexion</a>";
            echo " | ";
            echo "<a class=\"lientable\" href=\"../index.php\" title=\"Autre Base\">";
            echo "Autre Base</a>";
            echo " | ";
            echo "<a class=\"lientdb\" href=\"../scr/tdb.php\" title=\"Tableau de bord\">";
            echo "Tableau de bord</a>";
          }else{
            echo "Vous n'&ecirc;tes pas connect&eacute;";
            echo " | ";
            echo "<a class=\"Identification\" href=\"../spg/login.php\" title=\"Connexion\">Identifiez-vous</a>";
          }
        }
        else
        {
            echo "Vous n'&ecirc;tes pas connect&eacute;";
            echo " | ";
            echo "<a class=\"Identification\" href=\"../spg/login.php\" title=\"Connexion\">Identifiez-vous</a>";
        }*/
        echo "</div>\n";
        
        echo "</div>\n";
        $this -> entete ($ent, $ico, $obj);
    } // header ($menu = 0, $ent = "", $ico = "", $obj = "")
    
    function titre ($ent)
    {
        $ent = ucwords($ent);
        $ent = str_replace ("->", "<img class=\"fleche_droite\" src=\"../img/fleche_droite.png\" style=\"vertical-align:middle\" alt=\"->\" title=\"->\" />", $ent);
        echo "\t<div id=\"titre\">";
        echo $ent;
        echo "</div>\n";
    } // titre ($ent)
    
    function aide ($ico, $obj)
    {
        echo "\t<div id=\"aide\">";
        echo "<a href=\"javascript:aide('".$obj."')\">";
        echo "<img class=\"aide\" src=\"../img/".$ico."\" alt=\"Aide\" title=\"Aide\" /><img class=\"aide\" src=\"../img/ico_aide.png\" alt=\"Aide\" title=\"Aide\" />";
        echo "</a>";
        echo "</div>\n";
    } // aide ($ico, $obj)
    
    function entete ($ent = "", $ico = "", $obj = "")
    {
        echo "<div id=\"entete\">\n";
        $this -> titre ($ent);
        if ($ico != "" && $obj != "")
                $this -> aide ($ico, $obj);
        echo "</div>\n";
    } // entete ($ent = "", $ico = "", $obj = "")
    
    function menu ()
    {
        if (file_exists ("../dyn/menu.inc"))
            include_once "../dyn/menu.inc";
    } // menu ()
    
    function footer ()
    {
        $version = "0.00";
        if (file_exists ("../version.inc"))
            include_once ("../version.inc");
        echo "<div id=\"footer\">\n";
        echo "\t<span id=\"footerName\">".$version."";
        echo "&nbsp;|&nbsp;<a href=\"../spg/doc.php\" title=\"Documentation\">Documentation</a>";
        echo "&nbsp;|&nbsp;<a href=\"http://www.openmairie.org/\" target=\"_blank\" title=\"OpenMairie.org\">OpenMairie.org</a>&nbsp;|&nbsp;</span>\n";
        echo "</div>\n";
    } // footer ()
    
    function deconnexion ()
    {
        $this -> db -> disconnect ();
    } // deconnexion ()
    
    function footerhtml ()
    {
        echo "\t</body>\n";
        echo "</html>";
    } // footerhtml ()
    

    function tmp ($fichier, $msg)
    {   
        $inf = fopen ($fichier, "w");
        
        $ent .= date("d/m/Y G:i:s")."<br />";
        $ent .= "Collectivité : ".$_SESSION ['coll']." - ".$this -> collectivite ['ville']."<br />";
        $ent .= "Utilisateur : ".$_SESSION ['login']."<br />";
        $ent .= "==================================================<br />";
        
        $msg = $ent."<br />".$msg ;
        
        fwrite ($inf, $msg);
        
        fclose ($inf);
    } // tmp ($fichier, $msg)
}
?>