dolibarr  9.0.0
pomme.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * or see http://www.gnu.org/
18  */
19 
25 include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
26 
27 
32 {
33  var $name='DolibarrUsers'; // Identifiant du module mailing
34  // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
35  var $desc='Dolibarr users with emails'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
36  var $require_module=array(); // Module mailing actif si modules require_module actifs
37  var $require_admin=1; // Module mailing actif pour user admin ou non
38  var $picto='user';
39 
43  public $db;
44 
45 
51  function __construct($db)
52  {
53  $this->db=$db;
54  }
55 
56 
66  {
67  global $conf, $langs;
68 
69  $langs->load("users");
70 
71  $statssql=array();
72  $sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label,";
73  $sql.= " count(distinct(u.email)) as nb";
74  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
75  $sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
76  $sql.= " AND u.entity IN (0,".$conf->entity.")";
77  $statssql[0]=$sql;
78 
79  return $statssql;
80  }
81 
82 
91  function getNbOfRecipients($sql='')
92  {
93  global $conf;
94 
95  $sql = "SELECT count(distinct(u.email)) as nb";
96  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
97  $sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
98  $sql.= " AND u.entity IN (0,".$conf->entity.")";
99 
100  // La requete doit retourner un champ "nb" pour etre comprise
101  // par parent::getNbOfRecipients
102  return parent::getNbOfRecipients($sql);
103  }
104 
105 
111  function formFilter()
112  {
113  global $langs;
114 
115  $langs->load("users");
116 
117  $s='';
118  $s.=$langs->trans("Status").': ';
119  $s.='<select name="filter" class="flat">';
120  $s.='<option value="-1">&nbsp;</option>';
121  $s.='<option value="1">'.$langs->trans("Enabled").'</option>';
122  $s.='<option value="0">'.$langs->trans("Disabled").'</option>';
123  $s.='</select>';
124 
125  $s.=' ';
126  $s.=$langs->trans("Employee").': ';
127  $s.='<select name="filteremployee" class="flat">';
128  $s.='<option value="-1">&nbsp;</option>';
129  $s.='<option value="1">'.$langs->trans("Yes").'</option>';
130  $s.='<option value="0">'.$langs->trans("No").'</option>';
131  $s.='</select>';
132 
133  return $s;
134  }
135 
136 
143  function url($id)
144  {
145  return '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$id.'">'.img_object('',"user").'</a>';
146  }
147 
148 
149  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
157  function add_to_target($mailing_id, $filtersarray=array())
158  {
159  // phpcs:enable
160  // Deprecation warning
161  if ($filtersarray) {
162  dol_syslog(__METHOD__ . ": filtersarray parameter is deprecated", LOG_WARNING);
163  }
164 
165  global $conf, $langs;
166  $langs->load("companies");
167 
168  $cibles = array();
169 
170  // La requete doit retourner: id, email, fk_contact, lastname, firstname
171  $sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
172  $sql.= " u.lastname, u.firstname as firstname, u.civility as civility_id, u.login, u.office_phone";
173  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
174  $sql.= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicite dans ce test
175  $sql.= " AND u.entity IN (0,".$conf->entity.")";
176  $sql.= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
177  if (isset($_POST["filter"]) && $_POST["filter"] == '1') $sql.= " AND u.statut=1";
178  if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND u.statut=0";
179  if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '1') $sql.= " AND u.employee=1";
180  if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '0') $sql.= " AND u.employee=0";
181  $sql.= " ORDER BY u.email";
182 
183  // Stocke destinataires dans cibles
184  $result=$this->db->query($sql);
185  if ($result)
186  {
187  $num = $this->db->num_rows($result);
188  $i = 0;
189  $j = 0;
190 
191  dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
192 
193  $old = '';
194  while ($i < $num)
195  {
196  $obj = $this->db->fetch_object($result);
197  if ($old <> $obj->email)
198  {
199  $cibles[$j] = array(
200  'email' => $obj->email,
201  'fk_contact' => $obj->fk_contact,
202  'lastname' => $obj->lastname,
203  'firstname' => $obj->firstname,
204  'other' =>
205  ($langs->transnoentities("Login").'='.$obj->login).';'.
206  ($langs->transnoentities("UserTitle").'='.$obj->civility_id).';'.
207  ($langs->transnoentities("PhonePro").'='.$obj->office_phone),
208  'source_url' => $this->url($obj->id),
209  'source_id' => $obj->id,
210  'source_type' => 'user'
211  );
212  $old = $obj->email;
213  $j++;
214  }
215 
216  $i++;
217  }
218  }
219  else
220  {
221  dol_syslog($this->db->error());
222  $this->error=$this->db->error();
223  return -1;
224  }
225 
226  return parent::add_to_target($mailing_id, $cibles);
227  }
228 }
Class to offer a selector of emailing targets with Rule &#39;Peche&#39;.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
add_to_target($mailing_id, $filtersarray=array())
Ajoute destinataires dans table des cibles.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
url($id)
Renvoie url lien vers fiche de la source du destinataire du mailing.
__construct($db)
Constructor.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Parent class of emailing target selectors modules.