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

136 lines
5.4 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");
class Messagecmd extends PluginsClassiques{
var $id;
var $commande;
var $expediteur;
var $destinataire;
var $message;
var $table = "messagecmd";
var $bddvars=array("id", "commande", "expediteur", "destinataire", "message");
function init(){
$cnx = new Cnx();
$query_messagecmd = "CREATE TABLE `messagecmd` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`commande` INT NOT NULL ,
`expediteur` TEXT NOT NULL ,
`destinataire` TEXT NOT NULL ,
`message` TEXT NOT NULL
)";
$resul_messagecmd = mysql_query($query_messagecmd, $cnx->link);
}
function Messagecmd(){
$this->PluginsClassiques("Messagecmd");
}
function charger($commande){
return $this->getVars("select * from $this->table where commande=\"$commande\"");
}
function action(){
global $res;
if($_REQUEST['texte_messagecmd'] != ""){
$_SESSION['texte_messagecmd_client_id'] = $_SESSION['navig']->client->id; // XXX pour autoriser partage d'un même ordi par plusieurs clients ~ yoann@VLT, 20111012_1613
$_SESSION['texte_messagecmd'] = $_REQUEST['texte_messagecmd'];
$_SESSION['texte_destinatairecmd'] = $_REQUEST['texte_destinatairecmd'];
$_SESSION['texte_expediteurcmd'] = $_REQUEST['texte_expediteurcmd'];
}
// XXX pour autoriser partage d'un même ordi par plusieurs clients ~ yoann@VLT, 20111012_1613
if ( $_SESSION['texte_messagecmd_client_id'] == $_SESSION['navig']->client->id ) {
if (get_magic_quotes_gpc()) { // XXX support magic quotes ... ~ yoann@VLT, 20111012_1617
$res = str_replace("#MESSAGECMD", stripcslashes( $_SESSION['texte_messagecmd']), $res);
$res = str_replace("#DESTINATAIRECMD", stripcslashes($_SESSION['texte_destinatairecmd']), $res);
$res = str_replace("#EXPEDITEURCMD", stripcslashes($_SESSION['texte_expediteurcmd']), $res);
} else {
$res = str_replace("#MESSAGECMD", $_SESSION['texte_messagecmd'], $res);
$res = str_replace("#DESTINATAIRECMD", $_SESSION['texte_destinatairecmd'], $res);
$res = str_replace("#EXPEDITEURCMD", $_SESSION['texte_expediteurcmd'], $res);
}
} else {
$res = str_replace("#MESSAGECMD", "", $res);
$res = str_replace("#DESTINATAIRECMD", "", $res);
$res = str_replace("#EXPEDITEURCMD", "", $res);
}
}
function aprescommande($commande){
// XXX test id client pour autoriser partage d'un même ordi par plusieurs clients ~ yoann@VLT, 20111012_1631
if($_SESSION['texte_messagecmd'] && ($_SESSION['texte_messagecmd_client_id'] == $_SESSION['navig']->client->id) ){
$msg = new Messagecmd();
$msg->commande = $commande->id;
$msg->message = $_SESSION['texte_messagecmd'];
$msg->destinataire = $_SESSION['texte_destinatairecmd'];
$msg->expediteur = $_SESSION['texte_expediteurcmd'];
$msg->add();
// XXX vider les variables de session ~ yoann@VLT, 20111012_1639
$_SESSION['texte_messagecmd_client_id'] = "";
$_SESSION['texte_messagecmd'] = "";
$_SESSION['texte_destinatairecmd'] = "";
$_SESSION['texte_expediteurcmd'] = "";
}
}
public function charger_id($id) {
return $this->getVars("select * from $this->table where id=".intval($id));
}
public function boucle($texte, $args) {
$res = '';
$commande = lireTag($args, 'commande');
if ($this->charger($commande)) {
$res = str_replace('#MESSAGE', $this->message, $texte);
}
return $res;
}
}
?>