<?
#########################################################################################
# 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");
include_once(REP_ROOT.REP_CLASSES."ctextimageexport.php");
class CGraphique
{
var $m_oAccesBD = null;
var $m_TitreDessin = "";
var $m_ImageFinale;
var $m_ListeObjets = array(array());
var $m_ListeItemCatSel = array(array());
var $m_ListeImages = array();
var $m_CptImages = 0;
var $m_BackGround = "";
var $m_IndexTriZindex = array();
var $m_oTextImage = null;
var $m_NomProjet = "";
function __construct($TitreUser, $NomProjet)
{
$this->m_oAccesBD = new AccesBD();
$this->m_oAccesBD->Connect();
$this->m_TitreDessin = $TitreUser;
$this->m_NomProjet = $NomProjet;
$this->Proceder();
}
function Proceder()
{
$this->TelechargerItemCategorie();
$this->ObtenirObjets();
if ($this->m_BackGround != 0)
{
if (substr($this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"], -3, 3) == "jpg" || substr($this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"], -4, 4) == "jpeg")
$this->m_ImageFinale = imagecreatefromjpeg(REP_ROOT.REP_IMAGES.$this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"]);
elseif (substr($this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"], -3, 3) == "gif")
$this->m_ImageFinale = imagecreatefromgif(REP_ROOT.REP_IMAGES.$this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"]);
elseif (substr($this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"], -3, 3) == "png")
$this->m_ImageFinale = imagecreatefrompng(REP_ROOT.REP_IMAGES.$this->m_ListeItemCatSel[$this->m_BackGround]["nomfichier"]);
else
$this->m_ImageFinale = imagecreatefromjpeg(REP_ROOT.REP_IMAGES."bg400.jpg");
}
else
$this->m_ImageFinale = imagecreatefromjpeg(REP_ROOT.REP_IMAGES."bg400.jpg");
$this->TrierZindex();
$this->PlacerObjet();
}
function TrierZindex()
{
for ($i=1; $i < count($this->m_ListeObjets); $i++)
$this->m_IndexTriZindex[$i] = $this->m_ListeObjets[$i]["zindex"];
asort($this->m_IndexTriZindex);
$TabTmp = $this->m_IndexTriZindex;
$CptElement = 1;
while (list($key, $val) = each($TabTmp))
{
$this->m_IndexTriZindex[$CptElement++] = $key;
}
}
function PlacerObjet()
{
for ($i = 1; $i < count($this->m_ListeObjets); $i++)
{
if ($this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"] != "t")
{
$CoeficientX = $this->m_ListeItemCatSel[$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"]]["largeur"]/$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["dimx"];
$CoeficientY = $this->m_ListeItemCatSel[$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"]]["hauteur"]/$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["dimy"];
$width = $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["dimx"];
$height = $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["dimy"];
if (substr($this->m_ListeItemCatSel[$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"]]["nomfichier"], -3, 3) == "gif")
$this->m_ListeImages[++$this->m_CptImages] = imagecreatefromgif(REP_ROOT.REP_IMAGES.$this->m_ListeItemCatSel[$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"]]["nomfichier"]);
else
$this->m_ListeImages[++$this->m_CptImages] = imagecreatefrompng(REP_ROOT.REP_IMAGES.$this->m_ListeItemCatSel[$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["type"]]["nomfichier"]);
imagecopyresized ( $this->m_ImageFinale, $this->m_ListeImages[$this->m_CptImages], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["posx"], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["posy"], 0, 0, $width, $height,$width*$CoeficientX ,$height*$CoeficientY );
}
else
{
$this->m_oTextImage = new CTextImage((($this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["texte"] != "") ? $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["texte"] : ""), $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["couleur"], (($this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["police"] != "") ? $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["police"] : "Arial"), $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["gras"], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["italique"], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["taille"]);
$width = ((strlen($this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["texte"]) * (6*$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["taille"]/6)) < 50) ? 50 : (strlen($this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["texte"]) * (6*$this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["taille"]/6));
$height = $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["taille"]*2+10;
$this->m_ListeImages[++$this->m_CptImages] = imagecreatefromgif($this->m_oTextImage->ObtenirImage());
imagecopymerge ( $this->m_ImageFinale, $this->m_ListeImages[$this->m_CptImages], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["posx"], $this->m_ListeObjets[$this->m_IndexTriZindex[$i]]["posy"], 0, 0, $width, $height, 100);
}
}
}
function TelechargerItemCategorie()
{
$CptObjet = 0;
$RequeteSql = "select noesquisse, imagefond from pancarte where titreesquisse = '".$this->m_TitreDessin."'";
$this->m_oAccesBD->Requete($RequeteSql);
$this->m_oAccesBD->NextRow();
$NoSchema = $this->m_oAccesBD->GetFromRow("noesquisse");
$this->m_BackGround = $this->m_oAccesBD->GetFromRow("imagefond");
$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.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 ObtenirObjets()
{
$CptObjet = 0;
$RequeteSql = "select noesquisse, imagefond from pancarte where titreesquisse = '".$this->m_TitreDessin."'";
$this->m_oAccesBD->Requete($RequeteSql);
$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 * from pancarte_objets 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"] = $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]["zindex"] = $this->m_oAccesBD->GetFromRow("zindex");
}
}
}
function EnregistrerImage()
{
if (!@is_dir(REP_PANCARTES."projet_".$this->m_NomProjet))
{
@mkdir (REP_PANCARTES."projet_".$this->m_NomProjet);
}
// if (touch(REP_PANCARTES."projet_".$this->m_NomProjet."/".$this->m_TitreDessin.".jpg"))
// {
if (imagejpeg($this->m_ImageFinale, REP_PANCARTES."projet_".$this->m_NomProjet."/".$this->m_TitreDessin.".jpg",100))
{
$a = "fait rien"; //bug de imagejpeg;
}
// }
}
}
?>