dolibarr  7.0.0-beta
fraise.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 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 
26 include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
27 include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
28 
29 
34 {
35  var $name='FundationMembers'; // Identifiant du module mailing
36  // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
37  var $desc='Foundation members with emails';
38  // Set to 1 if selector is available for admin users only
39  var $require_admin=0;
40 
41  var $require_module=array('adherent');
42  var $picto='user';
43 
44  var $db;
45 
51  function __construct($db)
52  {
53  $this->db=$db;
54  }
55 
56 
66  {
67  global $langs;
68 
69  $langs->load("members");
70 
71  // Array for requests for statistics board
72  $statssql=array();
73 
74  $statssql[0] ="SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb";
75  $statssql[0].=" FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")";
76 
77  return $statssql;
78  }
79 
80 
89  function getNbOfRecipients($sql='')
90  {
91  $sql = "SELECT count(distinct(a.email)) as nb";
92  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
93  $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")";
94 
95  // La requete doit retourner un champ "nb" pour etre comprise
96  // par parent::getNbOfRecipients
97  return parent::getNbOfRecipients($sql);
98  }
99 
100 
106  function formFilter()
107  {
108  global $conf, $langs;
109  $langs->load("members");
110  $langs->load("categories");
111  $langs->load("companies");
112 
113  $form=new Form($this->db);
114 
115  $s='';
116 
117  // Status
118  $s.=$langs->trans("Status").': ';
119  $s.='<select name="filter" class="flat">';
120  $s.='<option value="none">&nbsp;</option>';
121  $s.='<option value="-1">'.$langs->trans("MemberStatusDraft").'</option>';
122  $s.='<option value="1a">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusPaidShort").')</option>';
123  $s.='<option value="1b">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusActiveLateShort").')</option>';
124  $s.='<option value="0">'.$langs->trans("MemberStatusResiliatedShort").'</option>';
125  $s.='</select> ';
126  $s.=$langs->trans("Type").': ';
127  $s.='<select name="filter_type" class="flat">';
128  $sql = "SELECT rowid, libelle, statut";
129  $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
130  $sql.= " WHERE entity = ".$conf->entity;
131  $sql.= " ORDER BY rowid";
132  $resql = $this->db->query($sql);
133  if ($resql)
134  {
135  $num = $this->db->num_rows($resql);
136 
137  $s.='<option value="0">&nbsp;</option>';
138  if (! $num) $s.='<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>';
139 
140  $i = 0;
141  while ($i < $num)
142  {
143  $obj = $this->db->fetch_object($resql);
144 
145  $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->libelle,38,'middle');
146  $s.='</option>';
147  $i++;
148  }
149  }
150  else
151  {
152  dol_print_error($this->db);
153  }
154 
155  $s.='</select>';
156 
157  $s.=' ';
158 
159  $s.=$langs->trans("Category").': ';
160  $s.='<select name="filter_category" class="flat">';
161 
162  // Show categories
163  $sql = "SELECT rowid, label, type, visible";
164  $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
165  $sql.= " WHERE type = 3"; // We keep only categories for members
166  // $sql.= " AND visible > 0"; // We ignore the property visible because member's categories does not use this property (only products categories use it).
167  $sql.= " AND entity = ".$conf->entity;
168  $sql.= " ORDER BY label";
169 
170  //print $sql;
171  $resql = $this->db->query($sql);
172  if ($resql)
173  {
174  $num = $this->db->num_rows($resql);
175 
176  $s.='<option value="0">&nbsp;</option>';
177  if (! $num) $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
178 
179  $i = 0;
180  while ($i < $num)
181  {
182  $obj = $this->db->fetch_object($resql);
183 
184  $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle');
185  $s.='</option>';
186  $i++;
187  }
188  }
189  else
190  {
191  dol_print_error($this->db);
192  }
193 
194  $s.='</select>';
195 
196 
197  $s.='<br>';
198  $s.=$langs->trans("DateEndSubscription").': &nbsp;';
199  $s.=$langs->trans("After").' > '.$form->select_date(-1,'subscriptionafter',0,0,1,'fraise',1,0,1,0);
200  $s.=' &nbsp; ';
201  $s.=$langs->trans("Before").' < '.$form->select_date(-1,'subscriptionbefore',0,0,1,'fraise',1,0,1,0);
202 
203  return $s;
204  }
205 
206 
213  function url($id)
214  {
215  return '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$id.'">'.img_object('',"user").'</a>';
216  }
217 
218 
226  function add_to_target($mailing_id,$filtersarray=array())
227  {
228  // Deprecation warning
229  if ($filtersarray) {
230  dol_syslog(__METHOD__ . ": filtersarray parameter is deprecated", LOG_WARNING);
231  }
232 
233  global $langs,$_POST;
234  $langs->load("members");
235  $langs->load("companies");
236 
237  $cibles = array();
238  $now=dol_now();
239 
240  $dateendsubscriptionafter=dol_mktime($_POST['subscriptionafterhour'],$_POST['subscriptionaftermin'],$_POST['subscriptionaftersec'],$_POST['subscriptionaftermonth'],$_POST['subscriptionafterday'],$_POST['subscriptionafteryear']);
241  $dateendsubscriptionbefore=dol_mktime($_POST['subscriptionbeforehour'],$_POST['subscriptionbeforemin'],$_POST['subscriptionbeforesec'],$_POST['subscriptionbeforemonth'],$_POST['subscriptionbeforeday'],$_POST['subscriptionbeforeyear']);
242 
243  // La requete doit retourner: id, email, fk_contact, name, firstname
244  $sql = "SELECT a.rowid as id, a.email as email, null as fk_contact, ";
245  $sql.= " a.lastname, a.firstname,";
246  $sql.= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields
247  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
248  if ($_POST['filter_category'])
249  {
250  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid";
251  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie";
252  }
253  $sql.= " , ".MAIN_DB_PREFIX."adherent_type as ta";
254  $sql.= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false
255  $sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($mailing_id).")";
256  // Filter on status
257  if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1";
258  if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'";
259  if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql.= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')";
260  if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND a.statut=0";
261  // Filter on date
262  if ($dateendsubscriptionafter > 0) $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'";
263  if ($dateendsubscriptionbefore > 0) $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'";
264  $sql.= " AND a.fk_adherent_type = ta.rowid";
265  // Filter on type
266  if ($_POST['filter_type']) $sql.= " AND ta.rowid='".$_POST['filter_type']."'";
267  // Filter on category
268  if ($_POST['filter_category']) $sql.= " AND c.rowid='".$_POST['filter_category']."'";
269  $sql.= " ORDER BY a.email";
270  //print $sql;
271 
272  // Add targets into table
273  dol_syslog(get_class($this)."::add_to_target", LOG_DEBUG);
274  $result=$this->db->query($sql);
275  if ($result)
276  {
277  $num = $this->db->num_rows($result);
278  $i = 0;
279  $j = 0;
280 
281  dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
282 
283  $old = '';
284  while ($i < $num)
285  {
286  $obj = $this->db->fetch_object($result);
287  if ($old <> $obj->email)
288  {
289  $cibles[$j] = array(
290  'email' => $obj->email,
291  'fk_contact' => $obj->fk_contact,
292  'lastname' => $obj->lastname,
293  'firstname' => $obj->firstname,
294  'other' =>
295  ($langs->transnoentities("Login").'='.$obj->login).';'.
296  ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'.
297  ($langs->transnoentities("DateEnd").'='.dol_print_date($this->db->jdate($obj->datefin),'day')).';'.
298  ($langs->transnoentities("Company").'='.$obj->societe),
299  'source_url' => $this->url($obj->id),
300  'source_id' => $obj->id,
301  'source_type' => 'member'
302  );
303  $old = $obj->email;
304  $j++;
305  }
306 
307  $i++;
308  }
309  }
310  else
311  {
312  dol_syslog($this->db->error());
313  $this->error=$this->db->error();
314  return -1;
315  }
316 
317  return parent::add_to_target($mailing_id, $cibles);
318  }
319 
320 }
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings...
add_to_target($mailing_id, $filtersarray=array())
Ajoute destinataires dans table des cibles.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to generate target according to rule Fraise.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
__construct($db)
Constructor.
url($id)
Renvoie url lien vers fiche de la source du destinataire du mailing.
Parent class of emailing target selectors modules.