<?php
#########################################################################################
# Croquis en ligne, pour réaliser la pancarte dans Pnyx #
# Auteur : Sébastien Tremblay, hide@address.com #
# #
# Pnyx - une application Web (PHP/MySQL) d'élections virtuelles conçue pour des élèves #
# du primaire et du secondaire, dans lequel ils sont amenés à faire des propositions #
# en ligne et voter pour leur favorite, sous la supervision d'un enseignant. #
# #
# Copyright (C) <2008 - 2009> #
# <Service national du RÉCIT de l'univers social de la Commission scolaire de la #
# Pointe-de-l'Île> #
# #
# 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. #
# 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 as the file LICENSE.txt; if not, please see #
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. #
# #
# Service national du RÉCIT de l'univers social #
# http://www.recitus.qc.ca #
# Contact e-mail : steve-hide@address.com #
#########################################################################################
include_once(file_exists("constante.php")? "constante.php" : "../constante.php");
include_once(REP_ROOT.REP_CLASSES."csecure.php");
include_once(REP_ROOT.REP_CLASSES."cgraphique2.php");
include_once(REP_ROOT.REP_CLASSES."accesbd.php");
class CSchema
{
var $m_VarFormulaire = array();
var $m_oAccesBD = null;
var $m_BackGround = "";
var $m_ListeObjets = array(array());
var $m_ListeCategories = array(array());
var $m_ListeItemCatSel = array(array());
var $m_ListeItemCatIndex = array();
var $m_Sauvegarde = false;
var $m_Chargement = false;
var $m_FlagMessageSauver = false;
var $m_oCGraphique = null;
var $m_DimensionThemeX = 400;
var $m_DimensionThemeY = 300;
function construct()
{
$this->Init();
}
function Init()
{
$TabTemp1 = array();
$TabTemp2 = array();
$TabTemp3 = array();
if ((isset($_POST)) && (isset($_GET)))
$this->m_VarFormulaire = array_merge ($_POST, $_GET);
elseif ((isset($HTTP_POST_VARS)) && (isset($HTTP_GET_VARS)))
$this->m_VarFormulaire = array_merge ($HTTP_POST_VARS, $HTTP_GET_VARS);
$TabTemp1 = explode(";", $this->m_VarFormulaire["b"]);
for ($i = 0; $i < count($TabTemp1); $i++)
{
$TabTemp2 = explode("=", $TabTemp1[$i]);
$TabTemp3[$TabTemp2[0]] = $TabTemp2[1];
$this->m_VarFormulaire = array_merge ($TabTemp3, $this->m_VarFormulaire);
}
$this->m_Sauvegarde = isset($this->m_VarFormulaire["save"]) ? true : false;
$this->m_Chargement = isset($this->m_VarFormulaire["load"]) ? true : false;
$this->m_BackGround = isset($this->m_VarFormulaire["fond"]) ? $this->m_VarFormulaire["fond"] : 0;
$this->m_FlagMessageSauver = isset($this->m_VarFormulaire["flag"]) ? $this->m_VarFormulaire["flag"] : $this->m_FlagMessageSauver;
@$this->m_oAccesBD = new AccesBD();
@$this->m_oAccesBD->Connect();
}
function Main()
{
$oCSchema = new CSchema();
$oCSchema->construct();
$oCSchema->Demarrer();
}
function Demarrer()
{
$this->m_Chargement = (isset($this->m_VarFormulaire['bienvenue']) ? true : $this->m_Chargement);
$this->TelechargerCategories();
$this->TelechargerItemCategorie();
if ($this->m_Sauvegarde)
{
$this->m_FlagMessageSauver = false;
$this->ObtenirObjetGet();
$this->EnregistrerObjets();
}
elseif ($this->m_Chargement)
{
$this->m_FlagMessageSauver = false;
$this->TelechargerObjets();
}
else
$this->ObtenirObjetGet();
$this->Afficher();
}
function TelechargerObjets()
{
session_name("pnyx");
session_start();
$Titre = (isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']);
$CptObjet = 0;
$RequeteSql = "select noesquisse, imagefond from pancarte where titreesquisse = '".$Titre."'";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
$this->m_oAccesBD->NextRow();
$NoSchema = $this->m_oAccesBD->GetFromRow("noesquisse");
$this->m_BackGround = $this->m_oAccesBD->GetFromRow("imagefond");
$RequeteSql = "select * from pancarte_labels where noesquisse=".$NoSchema;
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
for ($i = 0; $i < $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$NoSchema = $this->m_oAccesBD->GetFromRow("noesquisse");
$CptObjet++;
$this->m_ListeObjets[$CptObjet]["id"] = $CptObjet;
$this->m_ListeObjets[$CptObjet]["type"] = "t";
$this->m_ListeObjets[$CptObjet]["posx"] = $this->m_oAccesBD->GetFromRow("coordx");
$this->m_ListeObjets[$CptObjet]["posy"] = $this->m_oAccesBD->GetFromRow("coordy");
$this->m_ListeObjets[$CptObjet]["dimx"] = 400;
$this->m_ListeObjets[$CptObjet]["dimy"] = 40;
$this->m_ListeObjets[$CptObjet]["zindex"] = $this->m_oAccesBD->GetFromRow("zindex");
$this->m_ListeObjets[$CptObjet]["texte"] = urldecode($this->m_oAccesBD->GetFromRow("label"));
$this->m_ListeObjets[$CptObjet]["police"] = $this->m_oAccesBD->GetFromRow("police");
$this->m_ListeObjets[$CptObjet]["taille"] = $this->m_oAccesBD->GetFromRow("taille");
$this->m_ListeObjets[$CptObjet]["gras"] = $this->m_oAccesBD->GetFromRow("gras");
$this->m_ListeObjets[$CptObjet]["italique"] = $this->m_oAccesBD->GetFromRow("italique");
$this->m_ListeObjets[$CptObjet]["souligne"] = $this->m_oAccesBD->GetFromRow("souligne");
$this->m_ListeObjets[$CptObjet]["couleur"] = $this->m_oAccesBD->GetFromRow("couleur");
}
}
$RequeteSql = "select pancarte_objets.*, pancarte_objetgx.largeur as largeuro, pancarte_objetgx.hauteur as hauteuro from pancarte_objets, pancarte_objetgx where noesquisse=".$NoSchema." and pancarte_objets.typeobjet=pancarte_objetgx.noobjet";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
for ($i = 0; $i < $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$NoSchema = $this->m_oAccesBD->GetFromRow("noesquisse");
$CptObjet++;
$this->m_ListeObjets[$CptObjet]["id"] = $CptObjet;
$this->m_ListeObjets[$CptObjet]["type"] = $this->m_oAccesBD->GetFromRow("typeobjet");
$this->m_ListeObjets[$CptObjet]["posx"] = $this->m_oAccesBD->GetFromRow("coordx");
$this->m_ListeObjets[$CptObjet]["posy"] = $this->m_oAccesBD->GetFromRow("coordy");
$this->m_ListeObjets[$CptObjet]["dimx"] = $this->m_oAccesBD->GetFromRow("largeur");
$this->m_ListeObjets[$CptObjet]["dimy"] = $this->m_oAccesBD->GetFromRow("hauteur");
$this->m_ListeObjets[$CptObjet]["largeuro"] = $this->m_oAccesBD->GetFromRow("largeuro");
$this->m_ListeObjets[$CptObjet]["hauteuro"] = $this->m_oAccesBD->GetFromRow("hauteuro");
$this->m_ListeObjets[$CptObjet]["zindex"] = $this->m_oAccesBD->GetFromRow("zindex");
}
}
}
}
function EnregistrerObjets()
{
$NoSchema = 0;
session_name("pnyx");
session_start();
$Titre = (isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']);
$RequeteSql = "select noesquisse from pancarte where titreesquisse ='".$Titre."'";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetNbRows() != 0)
{
$this->m_oAccesBD->NextRow();
$NoSchema = $this->m_oAccesBD->GetFromRow("noesquisse");
$RequeteSql = "delete from pancarte_objets where noesquisse =".$NoSchema;
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "delete from pancarte_labels where noesquisse =".$NoSchema;
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "update pancarte set imagefond=".$this->m_BackGround." where noesquisse=".$NoSchema;
$this->m_oAccesBD->Requete($RequeteSql);
}
else
{
$NoSchema = $this->m_oAccesBD->ProchaineClef("pancarte", "noesquisse");
$RequeteSql = "insert into pancarte(noesquisse, titreesquisse, imagefond) values(".$NoSchema.", '".$Titre."', '".$this->m_BackGround."')";
$this->m_oAccesBD->Requete($RequeteSql);
}
for ($i = 1; $i < count($this->m_ListeObjets); $i++)
{
if ($this->m_ListeObjets[$i]["type"] != 0)
{
$RequeteSql = "insert into pancarte_objets values(".$NoSchema.", '".$this->m_ListeObjets[$i]["type"]."', ".$this->m_ListeObjets[$i]["zindex"].", ".$this->m_ListeObjets[$i]["posx"].", ".$this->m_ListeObjets[$i]["posy"].", ".$this->m_ListeObjets[$i]["dimx"].", ".$this->m_ListeObjets[$i]["dimy"].")";
$this->m_oAccesBD->Requete($RequeteSql);
}
else
{
$RequeteSql = "insert into pancarte_labels values(".$NoSchema.", ".$this->m_ListeObjets[$i]["posx"].", ".$this->m_ListeObjets[$i]["posy"].", '".$this->m_ListeObjets[$i]["police"]."', '".$this->m_ListeObjets[$i]["taille"]."', '".$this->m_ListeObjets[$i]["gras"]."', '".$this->m_ListeObjets[$i]["italique"]."', '".$this->m_ListeObjets[$i]["souligne"]."', '".$this->m_ListeObjets[$i]["couleur"]."',".$this->m_ListeObjets[$i]["zindex"].", '".urlencode($this->m_ListeObjets[$i]["texte"])."')";
$this->m_oAccesBD->Requete($RequeteSql);
}
}
$this->m_oCGraphique = new CGraphique((isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']), $_SESSION['SESSION']['projet']);
$this->m_oCGraphique->EnregistrerImage();
$RequeteSql = "update fiche set affiche = 'pancartes/projet_".$_SESSION['SESSION']['projet']."/".(isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']).".jpg' where projet_id=".$_SESSION['SESSION']['projet']." and eleve_id=".(isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']);
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "select * from fiche where affiche = 'pancartes/projet_".$_SESSION['SESSION']['projet']."/".(isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']).".jpg'";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetNbRows() == 0)
{
$RequeteSql = "insert fiche (affiche, projet_id, eleve_id) values ('pancartes/projet_".$_SESSION['SESSION']['projet']."/".(isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']).".jpg', ".$_SESSION['SESSION']['projet'].",".(isset($_SESSION['SESSION']['usager_id_mod']) ? $_SESSION['SESSION']['usager_id_mod'] : $_SESSION['SESSION']['usager_id']).")";
$this->m_oAccesBD->Requete($RequeteSql);
}
}
function ObtenirObjetGet()
{
$CptObjet = 0;
$CptArret = 0;
$NbObjet = isset($this->m_VarFormulaire["nbobjet"]) ? $this->m_VarFormulaire["nbobjet"] : "0";
while (++$CptArret <= $NbObjet)
{
if ((isset($this->m_VarFormulaire["t".$CptArret])) && (isset($this->m_VarFormulaire["x".$CptArret])) && (isset($this->m_VarFormulaire["y".$CptArret])) && (isset($this->m_VarFormulaire["z".$CptArret])))
{
$CptObjet++;
$this->m_ListeObjets[$CptObjet]["id"] = $CptObjet;
$this->m_ListeObjets[$CptObjet]["type"] = $this->m_VarFormulaire["t".$CptArret];
if ($this->m_ListeObjets[$CptObjet]["type"] == "t")
{
$this->m_ListeObjets[$CptObjet]["texte"] = $this->m_VarFormulaire["te".$CptArret];
$this->m_ListeObjets[$CptObjet]["police"] = $this->m_VarFormulaire["po".$CptArret];
$this->m_ListeObjets[$CptObjet]["taille"] = $this->m_VarFormulaire["ta".$CptArret];
$this->m_ListeObjets[$CptObjet]["gras"] = $this->m_VarFormulaire["gr".$CptArret];
$this->m_ListeObjets[$CptObjet]["italique"] = $this->m_VarFormulaire["it".$CptArret];
$this->m_ListeObjets[$CptObjet]["souligne"] = $this->m_VarFormulaire["so".$CptArret];
$this->m_ListeObjets[$CptObjet]["couleur"] = $this->m_VarFormulaire["co".$CptArret];
$this->m_ListeObjets[$CptObjet]["dimx"] = 400;
$this->m_ListeObjets[$CptObjet]["dimy"] = 40;
}
else
{
$this->m_ListeObjets[$CptObjet]["dimx"] = isset($this->m_VarFormulaire["w".$CptArret]) ? $this->m_VarFormulaire["w".$CptArret] : $this->m_ListeItemCatSel[$this->m_ListeObjets[$CptObjet]["type"]]["largeur"];
$this->m_ListeObjets[$CptObjet]["dimy"] = isset($this->m_VarFormulaire["h".$CptArret]) ? $this->m_VarFormulaire["h".$CptArret] : $this->m_ListeItemCatSel[$this->m_ListeObjets[$CptObjet]["type"]]["hauteur"];
$this->m_ListeObjets[$CptObjet]["largeuro"] = $this->m_ListeItemCatSel[$this->m_ListeObjets[$CptObjet]["type"]]["largeur"];
$this->m_ListeObjets[$CptObjet]["hauteuro"] = $this->m_ListeItemCatSel[$this->m_ListeObjets[$CptObjet]["type"]]["hauteur"];
}
$this->m_ListeObjets[$CptObjet]["posx"] = $this->m_VarFormulaire["x".$CptArret];
$this->m_ListeObjets[$CptObjet]["posy"] = $this->m_VarFormulaire["y".$CptArret];
$this->m_ListeObjets[$CptObjet]["zindex"] = $this->m_VarFormulaire["z".$CptArret];
}
}
}
function TelechargerItemCategorie()
{
$NbCatTmp = 0;
$RequeteSql = "select pancarte_categorie.nocategorie, pancarte_objetgx.noobjet, pancarte_objetgx.hauteur, pancarte_objetgx.largeur, pancarte_objetgx.nomfichier, pancarte_objetgx.description, pancarte_categoriesobjet.ordre from pancarte_objetgx, pancarte_categoriesobjet, pancarte_categorie where pancarte_objetgx.noobjet = pancarte_categoriesobjet.noobjet and pancarte_categoriesobjet.nocategorie = pancarte_categorie.nocategorie order by pancarte_categoriesobjet.nocategorie, pancarte_categoriesobjet.ordre ASC";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
for ($i = 1; $i <= $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["nomfichier"] = $this->m_oAccesBD->GetFromRow("nomfichier");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["description"] = $this->m_oAccesBD->GetFromRow("description");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["categorie"] = $this->m_oAccesBD->GetFromRow("nocategorie");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["hauteur"] = $this->m_oAccesBD->GetFromRow("hauteur");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["largeur"] = $this->m_oAccesBD->GetFromRow("largeur");
}
}
$RequeteSql = "select pancarte_objetgx.noobjet, pancarte_objetgx.nomfichier, pancarte_objetgx.description, pancarte_themefond.ordre from pancarte_objetgx, pancarte_themefond where pancarte_objetgx.noobjet = pancarte_themefond.noobjet order by pancarte_themefond.ordre ASC";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
$NbCatTmp = count($this->m_ListeItemCatSel);
for ($i = $NbCatTmp; $i < ($this->m_oAccesBD->GetNbRows()+$NbCatTmp); $i++)
{
$this->m_oAccesBD->NextRow();
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["nomfichier"] = $this->m_oAccesBD->GetFromRow("nomfichier");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["description"] = $this->m_oAccesBD->GetFromRow("description");
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["categorie"] = 0;
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["hauteur"] = 0;
$this->m_ListeItemCatSel[$this->m_oAccesBD->GetFromRow("noobjet")]["largeur"] = 0;
}
}
}
function TelechargerCategories()
{
$RequeteSql = "select nocategorie, description, ordre from pancarte_categorie order by ordre";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
for ($i = 1; $i <= $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$this->m_ListeCategories[$i]["nocategorie"] = $this->m_oAccesBD->GetFromRow("nocategorie");
$this->m_ListeCategories[$i]["description"] = $this->m_oAccesBD->GetFromRow("description");
}
}
}
function Afficher()
{
include(REP_ROOT.REP_TEMPLATES."schema.template");
}
}
CSchema::Main();
?>