dolibarr  7.0.0-beta
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@capnetworks.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 
40  var $db;
41 
42 
48  function __construct($db)
49  {
50  $this->db=$db;
51  }
52 
53 
63  {
64  global $conf, $langs;
65 
66  $langs->load("users");
67 
68  $statssql=array();
69  $sql = "SELECT '".$langs->trans("DolibarrUsers")."' as label,";
70  $sql.= " count(distinct(u.email)) as nb";
71  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
72  $sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
73  $sql.= " AND u.entity IN (0,".$conf->entity.")";
74  $statssql[0]=$sql;
75 
76  return $statssql;
77  }
78 
79 
88  function getNbOfRecipients($sql='')
89  {
90  global $conf;
91 
92  $sql = "SELECT count(distinct(u.email)) as nb";
93  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
94  $sql.= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
95  $sql.= " AND u.entity IN (0,".$conf->entity.")";
96 
97  // La requete doit retourner un champ "nb" pour etre comprise
98  // par parent::getNbOfRecipients
99  return parent::getNbOfRecipients($sql);
100  }
101 
102 
108  function formFilter()
109  {
110  global $langs;
111 
112  $langs->load("users");
113 
114  $s='';
115  $s.=$langs->trans("Status").': ';
116  $s.='<select name="filter" class="flat">';
117  $s.='<option value="-1">&nbsp;</option>';
118  $s.='<option value="1">'.$langs->trans("Enabled").'</option>';
119  $s.='<option value="0">'.$langs->trans("Disabled").'</option>';
120  $s.='</select>';
121 
122  $s.=' ';
123  $s.=$langs->trans("Employee").': ';
124  $s.='<select name="filteremployee" class="flat">';
125  $s.='<option value="-1">&nbsp;</option>';
126  $s.='<option value="1">'.$langs->trans("Yes").'</option>';
127  $s.='<option value="0">'.$langs->trans("No").'</option>';
128  $s.='</select>';
129 
130  return $s;
131  }
132 
133 
140  function url($id)
141  {
142  return '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$id.'">'.img_object('',"user").'</a>';
143  }
144 
145 
153  function add_to_target($mailing_id,$filtersarray=array())
154  {
155  // Deprecation warning
156  if ($filtersarray) {
157  dol_syslog(__METHOD__ . ": filtersarray parameter is deprecated", LOG_WARNING);
158  }
159 
160  global $conf, $langs;
161  $langs->load("companies");
162 
163  $cibles = array();
164 
165  // La requete doit retourner: id, email, fk_contact, lastname, firstname
166  $sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
167  $sql.= " u.lastname, u.firstname as firstname, u.civility as civility_id, u.login, u.office_phone";
168  $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
169  $sql.= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicite dans ce test
170  $sql.= " AND u.entity IN (0,".$conf->entity.")";
171  $sql.= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
172  if (isset($_POST["filter"]) && $_POST["filter"] == '1') $sql.= " AND u.statut=1";
173  if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND u.statut=0";
174  if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '1') $sql.= " AND u.employee=1";
175  if (isset($_POST["filteremployee"]) && $_POST["filteremployee"] == '0') $sql.= " AND u.employee=0";
176  $sql.= " ORDER BY u.email";
177 
178  // Stocke destinataires dans cibles
179  $result=$this->db->query($sql);
180  if ($result)
181  {
182  $num = $this->db->num_rows($result);
183  $i = 0;
184  $j = 0;
185 
186  dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
187 
188  $old = '';
189  while ($i < $num)
190  {
191  $obj = $this->db->fetch_object($result);
192  if ($old <> $obj->email)
193  {
194  $cibles[$j] = array(
195  'email' => $obj->email,
196  'fk_contact' => $obj->fk_contact,
197  'lastname' => $obj->lastname,
198  'firstname' => $obj->firstname,
199  'other' =>
200  ($langs->transnoentities("Login").'='.$obj->login).';'.
201  ($langs->transnoentities("UserTitle").'='.$obj->civility_id).';'.
202  ($langs->transnoentities("PhonePro").'='.$obj->office_phone),
203  'source_url' => $this->url($obj->id),
204  'source_id' => $obj->id,
205  'source_type' => 'user'
206  );
207  $old = $obj->email;
208  $j++;
209  }
210 
211  $i++;
212  }
213  }
214  else
215  {
216  dol_syslog($this->db->error());
217  $this->error=$this->db->error();
218  return -1;
219  }
220 
221  return parent::add_to_target($mailing_id, $cibles);
222  }
223 
224 }
225 
Class to offer a selector of emailing targets with Rule 'Peche'.
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
Parent class of emailing target selectors modules.