dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
17  * or see https://www.gnu.org/
18  */
19 
25 include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
26 
27 
32 {
33  public $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  public $desc = 'Dolibarr users with emails'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
36  public $require_module = array(); // Module mailing actif si modules require_module actifs
37  public $require_admin = 1; // Module mailing actif pour user admin ou non
38 
42  public $picto = 'user';
43 
47  public $db;
48 
49 
55  public function __construct($db)
56  {
57  $this->db = $db;
58  }
59 
60 
69  public function getSqlArrayForStats()
70  {
71  global $conf, $langs;
72 
73  $langs->load("users");
74 
75  $statssql = array();
76  $sql = "SELECT '".$this->db->escape($langs->trans("DolibarrUsers"))."' as label,";
77  $sql .= " count(distinct(u.email)) as nb";
78  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
79  $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
80  $sql .= " AND u.entity IN (0,".$conf->entity.")";
81  $statssql[0] = $sql;
82 
83  return $statssql;
84  }
85 
86 
95  public function getNbOfRecipients($sql = '')
96  {
97  global $conf;
98 
99  $sql = "SELECT count(distinct(u.email)) as nb";
100  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
101  $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
102  $sql .= " AND u.entity IN (0,".$conf->entity.")";
103 
104  // La requete doit retourner un champ "nb" pour etre comprise
105  // par parent::getNbOfRecipients
106  return parent::getNbOfRecipients($sql);
107  }
108 
109 
115  public function formFilter()
116  {
117  global $langs;
118 
119  $langs->load("users");
120 
121  $s = '';
122  $s .= $langs->trans("Status").': ';
123  $s .= '<select name="filter" class="flat">';
124  $s .= '<option value="-1">&nbsp;</option>';
125  $s .= '<option value="1">'.$langs->trans("Enabled").'</option>';
126  $s .= '<option value="0">'.$langs->trans("Disabled").'</option>';
127  $s .= '</select>';
128 
129  $s .= ' ';
130  $s .= $langs->trans("Employee").': ';
131  $s .= '<select name="filteremployee" class="flat">';
132  $s .= '<option value="-1">&nbsp;</option>';
133  $s .= '<option value="1">'.$langs->trans("Yes").'</option>';
134  $s .= '<option value="0">'.$langs->trans("No").'</option>';
135  $s .= '</select>';
136 
137  return $s;
138  }
139 
140 
147  public function url($id)
148  {
149  return '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$id.'">'.img_object('', "user").'</a>';
150  }
151 
152 
153  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
160  public function add_to_target($mailing_id)
161  {
162  // phpcs:enable
163  global $conf, $langs;
164  $langs->load("companies");
165 
166  $cibles = array();
167 
168  // La requete doit retourner: id, email, fk_contact, lastname, firstname
169  $sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
170  $sql .= " u.lastname, u.firstname as firstname, u.civility as civility_id, u.login, u.office_phone";
171  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
172  $sql .= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicite dans ce test
173  $sql .= " AND u.entity IN (0,".$conf->entity.")";
174  $sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")";
175  if (GETPOSTISSET("filter") && GETPOST("filter") == '1') $sql .= " AND u.statut=1";
176  if (GETPOSTISSET("filter") && GETPOST("filter") == '0') $sql .= " AND u.statut=0";
177  if (GETPOSTISSET("filteremployee") && GETPOSt("filteremployee") == '1') $sql .= " AND u.employee=1";
178  if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') $sql .= " AND u.employee=0";
179  $sql .= " ORDER BY u.email";
180 
181  // Stocke destinataires dans cibles
182  $result = $this->db->query($sql);
183  if ($result)
184  {
185  $num = $this->db->num_rows($result);
186  $i = 0;
187  $j = 0;
188 
189  dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
190 
191  $old = '';
192  while ($i < $num)
193  {
194  $obj = $this->db->fetch_object($result);
195  if ($old <> $obj->email)
196  {
197  $cibles[$j] = array(
198  'email' => $obj->email,
199  'fk_contact' => $obj->fk_contact,
200  'lastname' => $obj->lastname,
201  'firstname' => $obj->firstname,
202  'other' =>
203  ($langs->transnoentities("Login").'='.$obj->login).';'.
204  ($langs->transnoentities("UserTitle").'='.$obj->civility_id).';'.
205  ($langs->transnoentities("PhonePro").'='.$obj->office_phone),
206  'source_url' => $this->url($obj->id),
207  'source_id' => $obj->id,
208  'source_type' => 'user'
209  );
210  $old = $obj->email;
211  $j++;
212  }
213 
214  $i++;
215  }
216  } else {
217  dol_syslog($this->db->error());
218  $this->error = $this->db->error();
219  return -1;
220  }
221 
222  return parent::addTargetsToDatabase($mailing_id, $cibles);
223  }
224 }
add_to_target($mailing_id)
Ajoute destinataires dans table des cibles.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to offer a selector of emailing targets with Rule &#39;Peche&#39;.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings...
$conf db
API class for accounts.
Definition: inc.php:54
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getNbOfRecipients($sql= '')
Return here number of distinct emails returned by your selector.
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.