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

327 lines
6.8 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 */
/* */
/*************************************************************************************/
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsTransports.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Message.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Messagedesc.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Variable.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Raisondesc.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Mail.class.php");
class Retraitenmagasin extends PluginsTransports{
public function __construct(){
parent::__construct("retraitenmagasin");
}
public function init() {
$lastid = new Cnx();
$recup_dernier_statut_id = "SELECT * FROM `statut` ORDER BY id DESC LIMIT 1";
$recup = mysql_query($recup_dernier_statut_id, $lastid->link);
$idrecup = $this->fetch_object($recup);
$newid = $idrecup->id+1;
$cnx = new Cnx();
$ajout_statut = "INSERT INTO `statut` VALUES('".$newid."','retraitcomptoir');";
mysql_query($ajout_statut, $cnx->link);
$cnx1 = new Cnx();
$ajout_statut_desc = "INSERT INTO `statutdesc` VALUES('','".$newid."','1','Retrait comptoir','','');";
mysql_query($ajout_statut_desc, $cnx1->link);
$this->ajout_desc("Retrait en magasin", "Retrait en magasin", "", 1);
$test = new Message();
if (! $test->charger("retraitenmagasin")) {
$message = new Message();
$message->nom = "retraitenmagasin";
$lastid = $message->add();
$messagedesc = new Messagedesc();
$messagedesc->message = $lastid;
$messagedesc->lang = 1;
$messagedesc->intitule = "Retrait en magasin";
$messagedesc->titre = "Votre commande __COMMANDE__ est prête";
$messagedesc->descriptiontext =
"__RAISON__ __NOM__ __PRENOM__,\n\n"
. "Nous vous remercions de votre commande sur notre site __URLSITE__.\n\n"
. "Votre commande __COMMANDE__ du __DATE__ __HEURE__ est disponible au magasin à partir de __DATEDJ__.\n\n"
. "Vous pouvez la retirer à n'importe quel moment pendant les heures d'ouverture de la boutique\n"
. "Vous devrez présenter la facture disponible dans votre espace client à notre comptoir.\n\n"
. "Nous restons à votre disposition pour toute information complémentaire.\n"
. "Cordialement,\n"
. "L'équipe __NOMSITE__.\n";
$messagedesc->description = nl2br($messagedesc->descriptiontext);
$messagedesc->add();
}
}
public function destroy() {
$message = new Message();
if ($message->charger("retraitenmagasin")) {
if (method_exists($message, 'supprimer'))
$message->supprimer();
else
$message->delete();
}
$supprim = new Cnx();
$supprim_statut = "DELETE FROM `statut` where nom='retraitcomptoir'";
mysql_query($supprim_statut, $supprim->link);
$supprim1 = new Cnx();
$supprim_statut_desc = "DELETE FROM `statutdesc` where titre='Retrait comptoir'";
mysql_query($supprim_statut_desc, $supprim1->link);
}
public function calcule(){
if($this->poids>0) return 0;
}
private function substitutions($texte, $client, $commande) {
$datecommande = strtotime($commande->date);
$raisondesc = new Raisondesc();
$raisondesc->charger($client->raison, $commande->lang);
$texte = str_replace("__RAISON__", $raisondesc->long, $texte);
$texte = str_replace("__NOM__", $client->nom, $texte);
$texte = str_replace("__PRENOM__", $client->prenom, $texte);
$texte = str_replace("__URLSITE__", Variable::lire('urlsite'), $texte);
$texte = str_replace("__NOMSITE__", Variable::lire('nomsite'), $texte);
$texte = str_replace("__COMMANDE__", $commande->ref, $texte);
$texte = str_replace("__DATE__", strftime("%d/%m/%Y", $datecommande), $texte);
$texte = str_replace("__HEURE__", strftime("%H:%M:%S", $datecommande), $texte);
$texte = str_replace("__DATEDJ__", strftime("%d/%m/%Y"), $texte);
$texte = str_replace("__COLIS__", $commande->colis, $texte);
return $texte;
}
public function statut($commande) {
if ($commande->statut == "4") {
if (! $commande->colis)
return;
$modTransport = new Modules();
$modTransport->charger('retraitenmagasin');
if($modTransport->id != $commande->transport)
return;
$message = new Message();
$message->charger("retraitenmagasin");
$messagedesc = new Messagedesc();
$messagedesc->charger($message->id, $commande->lang);
$client = new Client();
$client->charger_id($commande->client);
$sujet = $this->substitutions($messagedesc->titre, $client, $commande);
$texte = $this->substitutions($messagedesc->descriptiontext, $client, $commande);
$html = $this->substitutions($messagedesc->description, $client, $commande);
Mail::envoyer(
"$client->prenom $client->nom", $client->email,
Variable::lire('nomsite'), Variable::lire('emailcontact'),
$sujet,
$html, $texte);
}
}
}
?>