Files
le-matelot/client/plugins/magasin/Magasin.class.php
2020-01-27 08:56:08 +01:00

218 lines
7.2 KiB
PHP

<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) Octolys Development */
/* email : thelia@octolys.fr */
/* web : http://www.octolys.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 */
/* */
/*************************************************************************************/
?>
<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Variable.class.php");
class Magasin extends PluginsClassiques{
var $id;
var $nom;
var $adresse;
var $cp;
var $ville;
var $tel;
var $fax;
var $lat;
var $lon;
var $table = "magasin";
var $bddvars=array("id", "nom", "adresse", "cp", "ville", "tel", "fax", "lat", "lon");
function init(){
$cnx = new Cnx();
$query_magasin = "CREATE TABLE `magasin` (
`id` int(11) NOT NULL auto_increment,
`nom` text NOT NULL,
`adresse` text NOT NULL,
`cp` text NOT NULL,
`ville` text NOT NULL,
`tel` text NOT NULL,
`fax` text NOT NULL,
`lat` text NOT NULL,
`lon` text NOT NULL,
PRIMARY KEY (`id`)
) ;";
$resul_magasin = mysql_query($query_magasin, $cnx->link);
@mkdir("../client/gfx/magasin",0755);
@mkdir("../client/cache/magasin",0755);
$variable = new Variable();
if(!$variable->charger("cle_google_map")){
$variable->nom = "cle_google_map";
$variable->add();
}
}
function Magasin(){
$this->PluginsClassiques();
}
function charger($id){
return $this->getVars("select * from $this->table where id=\"$id\"");
}
function charger_ville($ville){
return $this->getVars("select * from $this->table where ville=\"$ville\"");
}
function boucle($texte, $args){
// r?cup?ration des arguments
$boucle = lireTag($args, "boucle");
if($boucle == "codepostal")
return $this->boucle_codepostal($texte, $args);
if($boucle == "ville")
return $this->boucle_ville($texte, $args);
else if($boucle == "magasin")
return $this->boucle_magasin($texte, $args);
}
function boucle_codepostal($texte, $args){
$search="";
$res="";
$order = "order by cp";
$query = "select distinct(cp) from $this->table $order";
$resul = mysql_query($query);
$nbres = mysql_num_rows($resul);
if(!$nbres) return "";
while( $row = mysql_fetch_object($resul)){
$temp = str_replace("#CP", "$row->cp", $texte);
if(isset($_GET['cp']) && $_GET['cp'] == $row->cp)
$temp = str_replace("#SELECTED", "selected=\"selected\"", $temp);
else
$temp = str_replace("#SELECTED", "", $temp);
$res .= $temp;
}
return $res;
}
function boucle_ville($texte, $args){
$search="";
$res="";
$order = "order by ville";
$query = "select distinct(ville) from $this->table $order";
$resul = mysql_query($query);
$nbres = mysql_num_rows($resul);
if(!$nbres) return "";
while( $row = mysql_fetch_object($resul)){
$temp = str_replace("#VILLE", "$row->ville", $texte);
$this->charger_ville($row->ville);
$temp = str_replace("#CP", "$this->cp", $temp);
if(isset($_GET['cp']) && $_GET['cp'] == $this->cp)
$temp = str_replace("#SELECTED", "selected=\"selected\"", $temp);
else
$temp = str_replace("#SELECTED", "", $temp);
$res .= $temp;
}
return $res;
}
function boucle_magasin($texte, $args){
$cp = lireTag($args, "cp");
$largeur_image = lireTag($args, "largeur_image");
$search="";
$res="";
if($cp != "")
$search .= " and cp=\"$cp\"";
if($ville != "")
$search .= " and ville=\"$ville\"";
$order = "order by cp";
$query = "select * from $this->table where 1 $search $order";
$resul = mysql_query($query);
$nbres = mysql_num_rows($resul);
if(!$nbres) return "";
while( $row = mysql_fetch_object($resul)){
$temp = str_replace("#CP", "$row->cp", $texte);
$temp = str_replace("#NOM", "$row->nom", $temp);
$temp = str_replace("#ADRESSE", "$row->adresse", $temp);
$temp = str_replace("#CP", "$row->cp", $temp);
$temp = str_replace("#VILLE", "$row->ville", $temp);
$temp = str_replace("#TEL", "$row->tel", $temp);
$temp = str_replace("#FAX", "$row->fax", $temp);
$temp = str_replace("#LAT", "$row->lat", $temp);
$temp = str_replace("#LON", "$row->lon", $temp);
if(file_exists("client/gfx/magasin/" . $row->id . ".jpg"))
$temp = str_replace("#IMAGE", "client/plugins/magasin/redimlive.php?nomorig=../../gfx/magasin/" . $row->id . ".jpg&width=$largeur_image", $temp);
else
$temp = str_replace("#IMAGE", "", $temp);
$res .= $temp;
}
return $res;
}
function action(){
global $res;
if($_GET['cp'])
$res = str_replace("#MAGASIN_CP", $_GET['cp'], $res);
else
$res = str_replace("#MAGASIN_CP", "75020", $res);
}
}
?>