2005-02-12 18:42:01 +01:00
|
|
|
|
<?php
|
2011-03-24 01:35:45 +01:00
|
|
|
|
/* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
2012-12-30 15:13:49 +01:00
|
|
|
|
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
|
2005-02-12 18:42:01 +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
|
2013-01-16 15:36:08 +01:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-02-12 18:42:01 +01:00
|
|
|
|
* (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
|
2011-08-01 01:24:38 +02:00
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-12 18:42:01 +01:00
|
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-04-07 01:23:48 +02:00
|
|
|
|
/**
|
2011-10-24 14:11:49 +02:00
|
|
|
|
* \file htdocs/core/modules/mailings/pomme.modules.php
|
2010-07-21 14:16:25 +02:00
|
|
|
|
* \ingroup mailing
|
|
|
|
|
|
* \brief File of class to offer a selector of emailing targets with Rule 'Pomme'.
|
2009-05-22 17:45:31 +02:00
|
|
|
|
*/
|
2011-10-24 14:11:49 +02:00
|
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
|
2005-02-12 18:42:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
2005-04-07 01:23:48 +02:00
|
|
|
|
/**
|
2010-07-21 14:16:25 +02:00
|
|
|
|
* \class mailing_pomme
|
|
|
|
|
|
* \brief Class to offer a selector of emailing targets with Rule 'Peche'.
|
2009-05-22 17:45:31 +02:00
|
|
|
|
*/
|
2005-02-12 18:42:01 +01:00
|
|
|
|
class mailing_pomme extends MailingTargets
|
|
|
|
|
|
{
|
2009-04-28 22:35:01 +02:00
|
|
|
|
var $name='DolibarrUsers'; // Identifiant du module mailing
|
2010-07-21 14:16:25 +02:00
|
|
|
|
var $desc='Dolibarr users with emails'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv<75>e
|
2009-05-22 17:45:31 +02:00
|
|
|
|
var $require_module=array(); // Module mailing actif si modules require_module actifs
|
|
|
|
|
|
var $require_admin=1; // Module mailing actif pour user admin ou non
|
|
|
|
|
|
var $picto='user';
|
2005-02-12 18:42:01 +01:00
|
|
|
|
|
2009-05-22 17:45:31 +02:00
|
|
|
|
var $db;
|
2005-02-12 18:42:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 11:45:25 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Constructor
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
|
*/
|
2012-03-14 11:49:11 +01:00
|
|
|
|
function __construct($db)
|
2009-05-22 17:45:31 +02:00
|
|
|
|
{
|
2011-11-13 11:45:25 +01:00
|
|
|
|
$this->db=$db;
|
2009-05-22 17:45:31 +02:00
|
|
|
|
}
|
2006-06-25 17:52:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 11:45:25 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* On the main mailing area, there is a box with statistics.
|
|
|
|
|
|
* If you want to add a line in this report you must provide an
|
|
|
|
|
|
* array of SQL request that returns two field:
|
|
|
|
|
|
* One called "label", One called "nb".
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return array Array with SQL requests
|
|
|
|
|
|
*/
|
2006-06-25 17:52:12 +02:00
|
|
|
|
function getSqlArrayForStats()
|
|
|
|
|
|
{
|
2009-04-28 22:35:01 +02:00
|
|
|
|
global $conf, $langs;
|
2009-05-22 17:45:31 +02:00
|
|
|
|
|
2009-04-28 22:35:01 +02:00
|
|
|
|
$langs->load("users");
|
2009-05-22 17:45:31 +02:00
|
|
|
|
|
2009-04-28 22:35:01 +02:00
|
|
|
|
$statssql=array();
|
2011-03-24 01:35:45 +01:00
|
|
|
|
$sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label,";
|
|
|
|
|
|
$sql.= " count(distinct(u.email)) as nb";
|
2009-05-22 17:45:31 +02:00
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
|
|
|
|
|
$sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
|
|
|
|
|
|
$sql.= " AND u.entity IN (0,".$conf->entity.")";
|
|
|
|
|
|
$statssql[0]=$sql;
|
2006-06-25 17:52:12 +02:00
|
|
|
|
|
|
|
|
|
|
return $statssql;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-01-25 23:04:55 +01:00
|
|
|
|
|
2013-04-05 09:23:31 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Return here number of distinct emails returned by your selector.
|
|
|
|
|
|
* For example if this selector is used to extract 500 different
|
|
|
|
|
|
* emails from a text file, this function must return 500.
|
|
|
|
|
|
*
|
2013-04-10 16:51:13 +02:00
|
|
|
|
* @param string $sql SQL request to use to count
|
2013-04-05 09:23:31 +02:00
|
|
|
|
* @return int Number of recipients
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getNbOfRecipients($sql='')
|
2009-05-22 17:45:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT count(distinct(u.email)) as nb";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
|
|
|
|
|
$sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
|
|
|
|
|
|
$sql.= " AND u.entity IN (0,".$conf->entity.")";
|
|
|
|
|
|
|
|
|
|
|
|
// La requete doit retourner un champ "nb" pour etre comprise
|
|
|
|
|
|
// par parent::getNbOfRecipients
|
|
|
|
|
|
return parent::getNbOfRecipients($sql);
|
|
|
|
|
|
}
|
2009-02-18 21:30:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-10 10:23:57 +01:00
|
|
|
|
* Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return string Retourne zone select
|
2009-05-22 17:45:31 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function formFilter()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
|
|
$langs->load("users");
|
|
|
|
|
|
|
|
|
|
|
|
$s='';
|
|
|
|
|
|
$s.='<select name="filter" class="flat">';
|
2011-03-24 01:35:45 +01:00
|
|
|
|
$s.='<option value="-1"></option>';
|
2009-05-22 17:45:31 +02:00
|
|
|
|
$s.='<option value="1">'.$langs->trans("Enabled").'</option>';
|
|
|
|
|
|
$s.='<option value="0">'.$langs->trans("Disabled").'</option>';
|
|
|
|
|
|
$s.='</select>';
|
|
|
|
|
|
return $s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-10 10:23:57 +01:00
|
|
|
|
* Renvoie url lien vers fiche de la source du destinataire du mailing
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param int $id ID
|
|
|
|
|
|
* @return string Url lien
|
2009-05-22 17:45:31 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function url($id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$id.'">'.img_object('',"user").'</a>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-10 10:23:57 +01:00
|
|
|
|
* Ajoute destinataires dans table des cibles
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param int $mailing_id Id of emailing
|
|
|
|
|
|
* @param array $filtersarray Requete sql de selection des destinataires
|
|
|
|
|
|
* @return int < 0 si erreur, nb ajout si ok
|
2009-05-22 17:45:31 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function add_to_target($mailing_id,$filtersarray=array())
|
|
|
|
|
|
{
|
|
|
|
|
|
global $conf, $langs;
|
|
|
|
|
|
|
|
|
|
|
|
$cibles = array();
|
|
|
|
|
|
|
|
|
|
|
|
// La requete doit retourner: id, email, fk_contact, name, firstname
|
|
|
|
|
|
$sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
|
2013-02-23 12:30:01 +01:00
|
|
|
|
$sql.= " u.lastname as name, u.firstname as firstname, u.login, u.office_phone";
|
2009-05-22 17:45:31 +02:00
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
2013-08-28 16:33:21 +02:00
|
|
|
|
$sql.= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicite dans ce test
|
2009-05-22 17:45:31 +02:00
|
|
|
|
$sql.= " AND u.entity IN (0,".$conf->entity.")";
|
2013-08-28 16:33:21 +02:00
|
|
|
|
$sql.= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
|
2009-05-22 17:45:31 +02:00
|
|
|
|
foreach($filtersarray as $key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($key == '1') $sql.= " AND u.statut=1";
|
|
|
|
|
|
if ($key == '0') $sql.= " AND u.statut=0";
|
|
|
|
|
|
}
|
|
|
|
|
|
$sql.= " ORDER BY u.email";
|
|
|
|
|
|
|
|
|
|
|
|
// Stocke destinataires dans cibles
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$j = 0;
|
|
|
|
|
|
|
|
|
|
|
|
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
|
|
|
|
|
|
|
|
|
|
|
|
$old = '';
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
if ($old <> $obj->email)
|
|
|
|
|
|
{
|
|
|
|
|
|
$cibles[$j] = array(
|
2006-06-25 17:52:12 +02:00
|
|
|
|
'email' => $obj->email,
|
|
|
|
|
|
'fk_contact' => $obj->fk_contact,
|
2013-03-09 20:34:38 +01:00
|
|
|
|
'lastname' => $obj->lastname,
|
2006-06-25 17:52:12 +02:00
|
|
|
|
'firstname' => $obj->firstname,
|
2010-12-13 19:52:19 +01:00
|
|
|
|
'other' =>
|
|
|
|
|
|
($langs->transnoentities("Login").'='.$obj->login).';'.
|
2012-08-15 18:55:32 +02:00
|
|
|
|
// ($langs->transnoentities("UserTitle").'='.$obj->civilite).';'.
|
2010-12-13 19:52:19 +01:00
|
|
|
|
($langs->transnoentities("PhonePro").'='.$obj->office_phone),
|
2010-12-01 22:51:13 +01:00
|
|
|
|
'source_url' => $this->url($obj->id),
|
|
|
|
|
|
'source_id' => $obj->id,
|
|
|
|
|
|
'source_type' => 'user'
|
2009-05-22 17:45:31 +02:00
|
|
|
|
);
|
|
|
|
|
|
$old = $obj->email;
|
|
|
|
|
|
$j++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dol_syslog($this->db->error());
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return parent::add_to_target($mailing_id, $cibles);
|
|
|
|
|
|
}
|
2005-02-12 18:42:01 +01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|