<?
#########################################################################################
# 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."accesbd.php");
class CSchema
{
var $m_VarFormulaire = array();
var $m_oAccesBD = null;
var $m_ListeObjet = array();
var $m_ListeObjetIndex = array();
var $m_ListeFond = array();
var $m_ListeFondIndex = array();
var $m_ListeCatObjet = array();
var $m_ListeFondChoisi = array();
var $m_MenuAffiche = 1;
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_MenuAffiche = isset($this->m_VarFormulaire["menu"])?$this->m_VarFormulaire["menu"]:$this->m_MenuAffiche;
@$this->m_oAccesBD = new AccesBD();
@$this->m_oAccesBD->Connect();
}
function Main()
{
session_name("pnyx");
session_start();
if (isset($_SESSION['SESSION']['niveau']) && $_SESSION['SESSION']['niveau'] == "admin")
{
$oCSchema = new CSchema();
$oCSchema->construct();
$oCSchema->Demarrer();
}
else
{
include(REP_ROOT.REP_TEMPLATES."secure.template");
exit;
}
}
function Demarrer()
{
if(isset($this->m_VarFormulaire['effacefichier']))
{
$this->EffacerFichier($this->m_VarFormulaire['nomfichier']);
}
if ($_FILES['fichierimage']['tmp_name'] != "")
{
if($this->m_VarFormulaire['typeimage'] == "fond")
$this->UploadFond();
else
$this->UploadObjet();
}
$this->ChargerListeImages();
$this->ChargerListeFonds();
$this->RecupererListeCatObjets();
$this->RecupererListeCatFonds();
if($this->m_VarFormulaire['sauvegarde'] == "vrai")
{
$this->Sauvegarder();
echo "<script language='javascript'>\ndocument.location='".$_SERVER['PHP_SELF']."?b=1;charger=true';\n</script>";
}
else if(isset($this->m_VarFormulaire['charger']))
{
$this->Charger();
}
$this->Afficher();
}
function EffacerFichier($NomFichier)
{
$NoObjetGx = 0;
$RequeteSql = "select noobjet from pancarte_objetgx where nomfichier='".$NomFichier."'";
$this->m_oAccesBD->Requete($RequeteSql);
if ($this->m_oAccesBD->GetMsgErreur() == "" && $this->m_oAccesBD->GetNbRows() > 0)
{
$this->m_oAccesBD->NextRow();
$NoObjetGx = $this->m_oAccesBD->GetFromRow("noobjet");
}
$RequeteSql = "delete from pancarte_categoriesobjet where noobjet=".$NoObjetGx;
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "delete from pancarte_objets where typeobjet=".$NoObjetGx;
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "delete from pancarte_objetgx where noobjet=".$NoObjetGx;
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "delete from pancarte_themefond where noobjet=".$NoObjetGx;
$this->m_oAccesBD->Requete($RequeteSql);
$Destination = REP_ROOT.REP_IMAGES.$NomFichier;
@unlink($Destination);
}
function Charger()
{
$oBDTmp = new AccesBD();
$oBDTmp->Connect();
$RequeteSql = "SELECT nocategorie, description, ordre FROM pancarte_categorie order by ordre ASC" ;
$this->m_oAccesBD->Requete($RequeteSql);
for ($i = 0; $i < $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$this->m_ListeCatObjet[$i]['titre'] = $this->m_oAccesBD->GetFromRow("description");
$RequeteSql = "SELECT pancarte_categoriesobjet.nocategorie, pancarte_categoriesobjet.noobjet, pancarte_objetgx.description, pancarte_categoriesobjet.ordre FROM pancarte_categoriesobjet, pancarte_objetgx where pancarte_categoriesobjet.noobjet=pancarte_objetgx.noobjet and pancarte_categoriesobjet.nocategorie=".$this->m_oAccesBD->GetFromRow("nocategorie")." order by pancarte_categoriesobjet.ordre ASC";
$oBDTmp->Requete($RequeteSql);
for ($j = 0; $j < $oBDTmp->GetNbRows(); $j++)
{
$oBDTmp->NextRow();
$this->m_ListeCatObjet[$i]['objets'][$j]['id'] = $oBDTmp->GetFromRow('noobjet');
$this->m_ListeCatObjet[$i]['objets'][$j]['description'] = $oBDTmp->GetFromRow('description');
}
$this->m_VarFormulaire['cat'.$i] = $this->m_oAccesBD->GetFromRow("description");
}
$RequeteSql = "SELECT pancarte_themefond.noobjet, pancarte_objetgx.description, ordre FROM pancarte_themefond, pancarte_objetgx WHERE pancarte_themefond.noobjet = pancarte_objetgx.noobjet order by ordre ASC" ;
$this->m_oAccesBD->Requete($RequeteSql);
for ($i = 0; $i < $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$this->m_ListeFondChoisi[$i]['id'] = $this->m_oAccesBD->GetFromRow('noobjet');
$this->m_ListeFondChoisi[$i]['description'] = $this->m_oAccesBD->GetFromRow("description");
}
}
function Sauvegarder()
{
$NoCategorie = 0;
$RequeteSql = "delete from pancarte_themefond";
$this->m_oAccesBD->Requete($RequeteSql);
$RequeteSql = "select nocategorie from pancarte_categorie";
$this->m_oAccesBD->Requete($RequeteSql);
$TmpCat = array();
for ($i = 0; $i < $this->m_oAccesBD->GetNbRows(); $i++)
{
$this->m_oAccesBD->NextRow();
$TmpCat[$i] = $this->m_oAccesBD->GetFromRow("nocategorie");
}
for ($i = 0; $i < count($TmpCat); $i++)
{
$RequeteSql = "delete from pancarte_categoriesobjet where nocategorie=".$TmpCat[$i];
$this->m_oAccesBD->Requete($RequeteSql);
}
$RequeteSql = "delete from pancarte_categorie";
$this->m_oAccesBD->Requete($RequeteSql);
for ($i = 0; $i < $this->m_VarFormulaire['nbfond']; $i++)
{
$RequeteSql = "insert into pancarte_themefond values(".$this->m_VarFormulaire['fond'.$i].", ".$i.")";
$this->m_oAccesBD->Requete($RequeteSql);
}
for ($i = 0; $i < $this->m_VarFormulaire['nbcat']; $i++)
{
$NoCategorie = $this->m_oAccesBD->ProchaineClef("pancarte_categorie", "nocategorie");
$RequeteSql = "insert into pancarte_categorie values(".$NoCategorie.", '".$this->m_VarFormulaire['cat'.$i]."', ".$i.")";
$this->m_oAccesBD->Requete($RequeteSql);
for ($j = 0; $j < $this->m_VarFormulaire['nbcat'.$i]; $j++)
{
$RequeteSql = "insert into pancarte_categoriesobjet values(".$NoCategorie.", ".$this->m_VarFormulaire['cat'.$i.'_obj'.$j].", ".$j.")";
$this->m_oAccesBD->Requete($RequeteSql);
}
}
}
function UploadFond()
{
$Source = $_FILES['fichierimage']['tmp_name'];
$NomFichier = "F".time().".".substr($_FILES['fichierimage']['name'], -3, 3);
$Destination = REP_ROOT.REP_IMAGES.$NomFichier;
copy($Source,$Destination);
list($width, $height, $type, $attr) = getimagesize($Destination);
if ($width == 400 && $height == 300)
{
$RequeteSql = "insert into pancarte_objetgx(noobjet, hauteur, largeur, nomfichier, description, typeobjet) values(".$this->m_oAccesBD->ProchaineClef("pancarte_objetgx", "noobjet").", 0, 0, \"".$NomFichier."\", \"".$this->m_VarFormulaire['descriptionimage']."\", ".$width.")";
$this->m_oAccesBD->Requete($RequeteSql);
}
else
@unlink($Destination);
}
function UploadObjet()
{
$Source = $_FILES['fichierimage']['tmp_name'];
$NomFichier = "F".time().".".substr($_FILES['fichierimage']['name'], -3, 3);;
$Destination = REP_ROOT.REP_IMAGES.$NomFichier;
if ($_FILES['fichierimage']['type'] == "image/gif" || $_FILES['fichierimage']['type'] == "image/png")
{
copy($Source,$Destination);
list($height, $width, $type, $attr) = getimagesize($Destination);
$RequeteSql = "insert into pancarte_objetgx(noobjet, hauteur, largeur, nomfichier, description) values(".$this->m_oAccesBD->ProchaineClef("pancarte_objetgx", "noobjet").", ".$width.", ".$height.", \"".$NomFichier."\", \"".$this->m_VarFormulaire['descriptionimage']."\")";
$this->m_oAccesBD->Requete($RequeteSql);
}
else
@unlink($Destination);
}
function RecupererListeCatObjets()
{
$NbCat = isset($this->m_VarFormulaire['nbcat']) ? $this->m_VarFormulaire['nbcat'] : 0;
for ($i = 0; $i < $NbCat; $i++)
{
$NbItemTmp = isset($this->m_VarFormulaire['nbcat'.$i]) ? $this->m_VarFormulaire['nbcat'.$i] : 0;
$this->m_ListeCatObjet[$i]['titre'] = $this->m_VarFormulaire['cat'.$i];
for ($j = 0; $j < $NbItemTmp; $j++)
{
$this->m_ListeCatObjet[$i]['objets'][$j]['id'] = $this->m_VarFormulaire['cat'.$i.'_obj'.$j];
$this->m_ListeCatObjet[$i]['objets'][$j]['description'] = $this->m_ListeObjet[$this->m_ListeObjetIndex[$this->m_VarFormulaire['cat'.$i.'_obj'.$j]]["id"]]["description"];
}
}
}
function RecupererListeCatFonds()
{
$NbFond = isset($this->m_VarFormulaire['nbfond']) ? $this->m_VarFormulaire['nbfond'] : 0;
for ($i = 0; $i < $NbFond; $i++)
{
$this->m_ListeFondChoisi[$i]['id'] = $this->m_VarFormulaire["fond".$i];
$this->m_ListeFondChoisi[$i]['description'] = $this->m_ListeFond[$this->m_ListeFondIndex[$this->m_VarFormulaire["fond".$i]]["id"]]["description"];
}
}
function ChargerListeImages()
{
$RequeteSql = "select noobjet, hauteur, largeur, nomfichier ,description from pancarte_objetgx where hauteur!=0";
$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_ListeObjetIndex[$this->m_oAccesBD->GetFromRow("noobjet")]["id"] = $i;
$this->m_ListeObjet[$i]["noobjet"] = $this->m_oAccesBD->GetFromRow("noobjet");
$this->m_ListeObjet[$i]["nomfichier"] = $this->m_oAccesBD->GetFromRow("nomfichier");
$this->m_ListeObjet[$i]["description"] = $this->m_oAccesBD->GetFromRow("description");
$this->m_ListeObjet[$i]["hauteur"] = $this->m_oAccesBD->GetFromRow("hauteur");
$this->m_ListeObjet[$i]["largeur"] = $this->m_oAccesBD->GetFromRow("largeur");
}
}
}
function ChargerListeFonds()
{
$RequeteSql = "select noobjet, nomfichier ,description, typeobjet from pancarte_objetgx where hauteur=0";
$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_ListeFondIndex[$this->m_oAccesBD->GetFromRow("noobjet")]["id"] = $i;
$this->m_ListeFond[$i]["noobjet"] = $this->m_oAccesBD->GetFromRow("noobjet");
$this->m_ListeFond[$i]["nomfichier"] = $this->m_oAccesBD->GetFromRow("nomfichier");
$this->m_ListeFond[$i]["description"] = $this->m_oAccesBD->GetFromRow("description");
$this->m_ListeFond[$i]["typeobjet"] = $this->m_oAccesBD->GetFromRow("typeobjet");
}
}
}
function Afficher()
{
include(REP_ROOT.REP_TEMPLATES."admin.template");
}
}
CSchema::Main();
?>