2004-10-20 23:06:45 +02:00
|
|
|
|
<?php
|
2005-11-11 21:11:57 +01:00
|
|
|
|
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2006-05-01 01:59:46 +02:00
|
|
|
|
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
2002-12-17 20:40:02 +01:00
|
|
|
|
*
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*
|
|
|
|
|
|
* $Id$
|
|
|
|
|
|
* $Source$
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-08-11 22:01:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/don.class.php
|
2004-10-20 23:06:45 +02:00
|
|
|
|
\ingroup don
|
2004-09-04 17:58:21 +02:00
|
|
|
|
\brief Fichier de la classe des dons
|
|
|
|
|
|
\version $Revision$
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-11 22:01:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class Don
|
|
|
|
|
|
\brief Classe permettant la gestion des dons
|
2004-09-04 17:58:21 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2002-12-17 20:40:02 +01:00
|
|
|
|
class Don
|
|
|
|
|
|
{
|
2008-03-21 01:27:37 +01:00
|
|
|
|
var $db;
|
|
|
|
|
|
var $error;
|
|
|
|
|
|
var $element='don';
|
|
|
|
|
|
var $table_element='don';
|
2008-05-19 21:41:16 +02:00
|
|
|
|
|
|
|
|
|
|
var $id;
|
|
|
|
|
|
var $date;
|
|
|
|
|
|
var $amount;
|
|
|
|
|
|
var $prenom;
|
|
|
|
|
|
var $nom;
|
|
|
|
|
|
var $societe;
|
|
|
|
|
|
var $adresse;
|
|
|
|
|
|
var $cp;
|
|
|
|
|
|
var $ville;
|
|
|
|
|
|
var $pays;
|
|
|
|
|
|
var $email;
|
|
|
|
|
|
var $public;
|
|
|
|
|
|
var $projetid;
|
|
|
|
|
|
var $modepaiement;
|
|
|
|
|
|
var $modepaiementid;
|
|
|
|
|
|
var $note;
|
|
|
|
|
|
var $statut;
|
2005-11-11 21:11:57 +01:00
|
|
|
|
|
2008-05-19 21:41:16 +02:00
|
|
|
|
var $projet;
|
2005-11-11 21:11:57 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Constructeur
|
2006-06-19 22:35:22 +02:00
|
|
|
|
* \param DB Handler d'acc<EFBFBD>s base
|
2005-11-11 21:11:57 +01:00
|
|
|
|
*/
|
2006-07-13 18:23:35 +02:00
|
|
|
|
function Don($DB)
|
2002-12-17 20:40:02 +01:00
|
|
|
|
{
|
2005-11-11 21:11:57 +01:00
|
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
|
|
$this->db = $DB ;
|
|
|
|
|
|
$this->modepaiementid = 0;
|
|
|
|
|
|
|
|
|
|
|
|
$langs->load("donations");
|
2006-07-02 15:45:06 +02:00
|
|
|
|
$this->labelstatut[0]=$langs->trans("DonationStatusPromiseNotValidated");
|
|
|
|
|
|
$this->labelstatut[1]=$langs->trans("DonationStatusPromiseValidated");
|
2005-11-11 23:55:11 +01:00
|
|
|
|
$this->labelstatut[2]=$langs->trans("DonationStatusPayed");
|
2006-07-02 15:45:06 +02:00
|
|
|
|
$this->labelstatutshort[0]=$langs->trans("DonationStatusPromiseNotValidatedShort");
|
|
|
|
|
|
$this->labelstatutshort[1]=$langs->trans("DonationStatusPromiseValidatedShort");
|
|
|
|
|
|
$this->labelstatutshort[2]=$langs->trans("DonationStatusPayedShort");
|
2002-12-20 19:07:49 +01:00
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
|
2006-05-01 01:59:46 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retourne le libell<EFBFBD> du statut d'un don (brouillon, valid<EFBFBD>e, abandonn<EFBFBD>e, pay<EFBFBD>e)
|
|
|
|
|
|
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long
|
|
|
|
|
|
* \return string Libelle
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getLibStatut($mode=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->LibStatut($this->statut,$mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoi le libell<EFBFBD> d'un statut donn<EFBFBD>
|
|
|
|
|
|
* \param statut Id statut
|
|
|
|
|
|
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Picto
|
|
|
|
|
|
* \return string Libell<EFBFBD> du statut
|
|
|
|
|
|
*/
|
|
|
|
|
|
function LibStatut($statut,$mode=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
|
|
if ($mode == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->labelstatut[$statut];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 1)
|
|
|
|
|
|
{
|
2006-07-02 15:45:06 +02:00
|
|
|
|
return $this->labelstatutshort[$statut];
|
2006-05-01 01:59:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 2)
|
|
|
|
|
|
{
|
2006-07-02 15:45:06 +02:00
|
|
|
|
if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatutshort[$statut];
|
|
|
|
|
|
if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatutshort[$statut];
|
|
|
|
|
|
if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatutshort[$statut];
|
2006-05-01 01:59:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
$prefix='Short';
|
|
|
|
|
|
if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0');
|
|
|
|
|
|
if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1');
|
|
|
|
|
|
if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatut[$statut];
|
|
|
|
|
|
if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
|
|
|
|
|
|
if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($mode == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
$prefix='Short';
|
2006-07-02 15:45:06 +02:00
|
|
|
|
if ($statut == 0) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
|
|
|
|
|
|
if ($statut == 1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
|
|
|
|
|
|
if ($statut == 2) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
|
2006-05-01 01:59:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-21 01:04:24 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Initialise le don avec valeurs fictives al<EFBFBD>atoire
|
|
|
|
|
|
* Sert <EFBFBD> g<EFBFBD>n<EFBFBD>rer une recu de don pour l'aperu des mod<EFBFBD>les ou demo
|
|
|
|
|
|
*/
|
|
|
|
|
|
function initAsSpecimen()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $user,$langs;
|
|
|
|
|
|
|
|
|
|
|
|
// Charge tableau des id de soci<63>t<EFBFBD> socids
|
|
|
|
|
|
$socids = array();
|
2007-06-12 00:51:47 +02:00
|
|
|
|
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
|
2006-08-21 01:04:24 +02:00
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num_socs = $this->db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num_socs)
|
|
|
|
|
|
{
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
|
|
|
|
|
|
$row = $this->db->fetch_row($resql);
|
|
|
|
|
|
$socids[$i] = $row[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialise param<61>tres
|
|
|
|
|
|
$this->id=0;
|
|
|
|
|
|
$this->ref = 'SPECIMEN';
|
|
|
|
|
|
$this->specimen=1;
|
|
|
|
|
|
$this->nom = 'Doe';
|
|
|
|
|
|
$this->prenom = 'John';
|
2006-09-13 20:56:30 +02:00
|
|
|
|
$this->socid = $socids[$socid];
|
2006-08-21 01:04:24 +02:00
|
|
|
|
$this->date = time();
|
|
|
|
|
|
$this->amount = 100;
|
|
|
|
|
|
$this->public = 1;
|
|
|
|
|
|
$this->societe = 'The Company';
|
|
|
|
|
|
$this->adresse = 'Twist road';
|
|
|
|
|
|
$this->cp = '99999';
|
|
|
|
|
|
$this->ville = 'Town';
|
|
|
|
|
|
$this->note_public='SPECIMEN';
|
|
|
|
|
|
$this->email='email@email.com';
|
2008-03-21 01:27:37 +01:00
|
|
|
|
$this->note='';
|
2006-08-21 01:04:24 +02:00
|
|
|
|
$this->statut=1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-01 01:59:46 +02:00
|
|
|
|
/*
|
2005-11-11 21:11:57 +01:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
function print_error_list()
|
|
|
|
|
|
{
|
2006-11-20 02:13:13 +01:00
|
|
|
|
$num = sizeof($this->error);
|
2002-12-20 19:07:49 +01:00
|
|
|
|
for ($i = 0 ; $i < $num ; $i++)
|
|
|
|
|
|
{
|
2006-11-20 02:13:13 +01:00
|
|
|
|
print "<li>" . $this->error[$i];
|
2002-12-20 19:07:49 +01:00
|
|
|
|
}
|
2005-11-11 21:11:57 +01:00
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2002-12-22 21:04:24 +01:00
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function check($minimum=0)
|
2002-12-20 19:07:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
$err = 0;
|
2002-12-22 16:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
if (strlen(trim($this->societe)) == 0)
|
2002-12-20 19:07:49 +01:00
|
|
|
|
{
|
2002-12-22 16:11:07 +01:00
|
|
|
|
if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "Vous devez saisir vos nom et pr<70>nom ou le nom de votre soci<63>t<EFBFBD>.";
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
2002-12-20 19:07:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(trim($this->adresse)) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "L'adresse saisie est invalide";
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(trim($this->cp)) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "Le code postal saisi est invalide";
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(trim($this->ville)) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "La ville saisie est invalide";
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-22 16:11:07 +01:00
|
|
|
|
if (strlen(trim($this->email)) == 0)
|
2002-12-20 19:07:49 +01:00
|
|
|
|
{
|
2002-12-22 16:11:07 +01:00
|
|
|
|
$error_string[$err] = "L'email saisi est invalide";
|
2002-12-20 19:07:49 +01:00
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-22 16:11:07 +01:00
|
|
|
|
$this->amount = trim($this->amount);
|
|
|
|
|
|
|
|
|
|
|
|
$map = range(0,9);
|
|
|
|
|
|
for ($i = 0; $i < strlen($this->amount) ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!isset($map[substr($this->amount, $i, 1)] ))
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "Le montant du don contient un/des caract<63>re(s) invalide(s)";
|
|
|
|
|
|
$err++;
|
2002-12-22 19:46:40 +01:00
|
|
|
|
$amount_invalid = 1;
|
2002-12-22 16:11:07 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-22 19:46:40 +01:00
|
|
|
|
if (! $amount_invalid)
|
2002-12-22 16:11:07 +01:00
|
|
|
|
{
|
2002-12-22 19:46:40 +01:00
|
|
|
|
if ($this->amount == 0)
|
2002-12-22 19:37:53 +01:00
|
|
|
|
{
|
2002-12-22 19:46:40 +01:00
|
|
|
|
$error_string[$err] = "Le montant du don est null";
|
2002-12-22 19:37:53 +01:00
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
2002-12-22 19:46:40 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->amount < $minimum && $minimum > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$error_string[$err] = "Le montant minimum du don est de $minimum";
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-12-22 19:37:53 +01:00
|
|
|
|
}
|
2002-12-22 19:46:40 +01:00
|
|
|
|
|
2002-12-20 19:07:49 +01:00
|
|
|
|
if ($err)
|
|
|
|
|
|
{
|
2006-11-20 02:13:13 +01:00
|
|
|
|
$this->error = $error_string;
|
2002-12-20 19:07:49 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-17 20:40:02 +01:00
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2005-09-02 23:48:34 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Cr<EFBFBD>ation du don en base
|
|
|
|
|
|
* \param user Objet utilisateur qui cr<EFBFBD>e le don
|
|
|
|
|
|
* \return int Id don cr<EFBFBD>e si ok, <0 si ko
|
|
|
|
|
|
*/
|
2005-08-11 22:01:25 +02:00
|
|
|
|
function create($user)
|
2002-12-17 20:40:02 +01:00
|
|
|
|
{
|
2005-08-11 22:01:25 +02:00
|
|
|
|
$this->date = $this->db->idate($this->date);
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public,";
|
|
|
|
|
|
if ($this->projetid)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " fk_don_projet,";
|
|
|
|
|
|
}
|
|
|
|
|
|
$sql .= " note, fk_user_author, datedon, email)";
|
2008-08-27 20:53:27 +02:00
|
|
|
|
$sql .= " VALUES (".$this->db->idate(mktime()).",".price2num($this->amount).", $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, ";
|
2005-08-11 22:01:25 +02:00
|
|
|
|
if ($this->projetid)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " $this->projetid,";
|
|
|
|
|
|
}
|
2008-03-21 01:27:37 +01:00
|
|
|
|
$sql .= " '$this->note', ".$user->id.", '$this->date','$this->email')";
|
2005-08-11 22:01:25 +02:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->db->last_insert_id(MAIN_DB_PREFIX."don");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-12-17 20:40:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-11 22:01:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Mise <EFBFBD> jour du don
|
|
|
|
|
|
* \param user Objet utilisateur qui met <EFBFBD> jour le don
|
|
|
|
|
|
* \return int >0 si ok, <0 si ko
|
2002-12-27 22:54:03 +01:00
|
|
|
|
*/
|
2005-08-11 22:01:25 +02:00
|
|
|
|
function update($user)
|
2002-12-27 22:54:03 +01:00
|
|
|
|
{
|
2005-08-11 22:01:25 +02:00
|
|
|
|
|
|
|
|
|
|
$this->date = $this->db->idate($this->date);
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
|
|
|
|
|
|
$sql .= "amount = " . $this->amount;
|
|
|
|
|
|
$sql .= ",fk_paiement = ".$this->modepaiementid;
|
|
|
|
|
|
$sql .= ",prenom = '".$this->prenom ."'";
|
|
|
|
|
|
$sql .= ",nom='".$this->nom."'";
|
|
|
|
|
|
$sql .= ",societe='".$this->societe."'";
|
|
|
|
|
|
$sql .= ",adresse='".$this->adresse."'";
|
|
|
|
|
|
$sql .= ",cp='".$this->cp."'";
|
|
|
|
|
|
$sql .= ",ville='".$this->ville."'";
|
|
|
|
|
|
$sql .= ",pays='".$this->pays."'";
|
|
|
|
|
|
$sql .= ",public=".$this->public;
|
|
|
|
|
|
if ($this->projetid) { $sql .= ",fk_don_projet=".$this->projetid; }
|
2008-03-21 01:27:37 +01:00
|
|
|
|
$sql .= ",note='".$this->note."'";
|
2005-08-11 22:01:25 +02:00
|
|
|
|
$sql .= ",datedon='".$this->date."'";
|
|
|
|
|
|
$sql .= ",email='".$this->email."'";
|
|
|
|
|
|
$sql .= ",fk_statut=".$this->statut;
|
|
|
|
|
|
|
|
|
|
|
|
$sql .= " WHERE rowid = $this->id";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-12-27 22:54:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-19 19:55:38 +01:00
|
|
|
|
/*
|
2004-09-04 17:58:21 +02:00
|
|
|
|
* \brief Suppression du don de la base
|
|
|
|
|
|
* \param rowid id du don <EFBFBD> supprimer
|
2002-12-19 19:55:38 +01:00
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function delete($rowid)
|
2002-12-20 19:07:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;";
|
2002-12-19 19:55:38 +01:00
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query( $sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( $this->db->affected_rows() )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-08-11 22:01:25 +02:00
|
|
|
|
return -1;
|
2002-12-19 19:55:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-09-04 17:58:21 +02:00
|
|
|
|
dolibarr_print_error($this->db);
|
2005-08-11 22:01:25 +02:00
|
|
|
|
return -1;
|
2002-12-19 19:55:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* \brief Charge l'objet don en m<EFBFBD>moire depuis la base de donn<EFBFBD>e
|
|
|
|
|
|
* \param rowid Id du don <EFBFBD> charger
|
|
|
|
|
|
* \return int <0 si ko, >0 si ok
|
|
|
|
|
|
*/
|
|
|
|
|
|
function fetch($rowid)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "SELECT d.rowid, ".$this->db->pdate("d.datec")." as datec,";
|
|
|
|
|
|
$sql.= " ".$this->db->pdate("d.datedon")." as datedon,";
|
|
|
|
|
|
$sql.= " d.prenom, d.nom, d.societe, d.amount, p.libelle as projet, d.fk_statut, d.adresse, d.cp, d.ville, d.pays, d.public, d.amount, d.fk_paiement, d.note, cp.libelle, d.email, d.fk_don_projet";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as cp, ".MAIN_DB_PREFIX."don as d";
|
|
|
|
|
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."don_projet as p";
|
|
|
|
|
|
$sql.= " ON p.rowid = d.fk_don_projet";
|
|
|
|
|
|
$sql.= " WHERE cp.id = d.fk_paiement AND d.rowid = ".$rowid;
|
2002-12-19 19:55:38 +01:00
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
if ( $this->db->query( $sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$obj = $this->db->fetch_object();
|
|
|
|
|
|
|
|
|
|
|
|
$this->id = $obj->rowid;
|
2006-08-21 01:04:24 +02:00
|
|
|
|
$this->ref = $obj->rowid;
|
2005-11-11 21:11:57 +01:00
|
|
|
|
$this->datec = $obj->datec;
|
|
|
|
|
|
$this->date = $obj->datedon;
|
|
|
|
|
|
$this->prenom = stripslashes($obj->prenom);
|
|
|
|
|
|
$this->nom = stripslashes($obj->nom);
|
|
|
|
|
|
$this->societe = stripslashes($obj->societe);
|
|
|
|
|
|
$this->statut = $obj->fk_statut;
|
|
|
|
|
|
$this->adresse = stripslashes($obj->adresse);
|
|
|
|
|
|
$this->cp = stripslashes($obj->cp);
|
|
|
|
|
|
$this->ville = stripslashes($obj->ville);
|
|
|
|
|
|
$this->email = stripslashes($obj->email);
|
|
|
|
|
|
$this->pays = stripslashes($obj->pays);
|
|
|
|
|
|
$this->projet = $obj->projet;
|
|
|
|
|
|
$this->projetid = $obj->fk_don_projet;
|
|
|
|
|
|
$this->public = $obj->public;
|
|
|
|
|
|
$this->modepaiementid = $obj->fk_paiement;
|
|
|
|
|
|
$this->modepaiement = $obj->libelle;
|
|
|
|
|
|
$this->amount = $obj->amount;
|
|
|
|
|
|
$this->commentaire = stripslashes($obj->note);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2002-12-19 19:55:38 +01:00
|
|
|
|
/*
|
2004-09-04 17:58:21 +02:00
|
|
|
|
* \brief Valide une promesse de don
|
|
|
|
|
|
* \param rowid id du don <EFBFBD> modifier
|
|
|
|
|
|
* \param userid utilisateur qui valide la promesse
|
2002-12-19 19:55:38 +01:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function valid_promesse($rowid, $userid)
|
2002-12-19 19:55:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;";
|
2002-12-19 19:55:38 +01:00
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query( $sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( $this->db->affected_rows() )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-09-04 17:58:21 +02:00
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return 0;
|
2002-12-19 19:55:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
2005-11-11 23:55:11 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* \brief Classe le don comme pay<EFBFBD>, le don a <EFBFBD>t<EFBFBD> recu
|
|
|
|
|
|
* \param rowid id du don <EFBFBD> modifier
|
|
|
|
|
|
* \param modepaiementd mode de paiement
|
|
|
|
|
|
*/
|
|
|
|
|
|
function set_paye($rowid, $modepaiement='')
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
|
|
|
|
|
|
|
|
|
|
|
|
if ($modepaiement)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= ", fk_paiement=$modepaiement";
|
|
|
|
|
|
}
|
|
|
|
|
|
$sql .= " WHERE rowid = $rowid AND fk_statut = 1;";
|
|
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query( $sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( $this->db->affected_rows() )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-09-04 17:58:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
2006-08-06 01:55:10 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* \brief Classe le don comme encaiss<EFBFBD>
|
|
|
|
|
|
* \param rowid id du don <EFBFBD> modifier
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
function set_encaisse($rowid)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;";
|
|
|
|
|
|
|
|
|
|
|
|
if ( $this->db->query( $sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( $this->db->affected_rows() )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-12-21 19:39:38 +01:00
|
|
|
|
|
2006-08-06 01:55:10 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Somme des dons
|
|
|
|
|
|
* \param param 1=promesses de dons valid<EFBFBD>es , 2=xxx, 3=encaiss<EFBFBD>s
|
|
|
|
|
|
*/
|
|
|
|
|
|
function sum_donations($param)
|
|
|
|
|
|
{
|
|
|
|
|
|
$result=0;
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT sum(amount) as total";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."don";
|
|
|
|
|
|
$sql.= " WHERE fk_statut = ".$param;
|
|
|
|
|
|
|
|
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($resql);
|
|
|
|
|
|
$result=$obj->total;
|
|
|
|
|
|
}
|
2002-12-21 19:39:38 +01:00
|
|
|
|
|
2006-08-06 01:55:10 +02:00
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
2002-12-21 19:39:38 +01:00
|
|
|
|
|
2002-12-17 20:40:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
?>
|