dolibarr  19.0.0-dev
html.formadvtargetemailing.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
3  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
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  */
18 
29 {
33  public $db;
34 
38  public $error = '';
39 
45  public function __construct($db)
46  {
47  global $langs;
48 
49  $this->db = $db;
50  }
51 
59  public function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status')
60  {
61  global $conf, $langs;
62  $options_array = array();
63 
64  $sql = "SELECT code, label";
65  $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
66  $sql .= " WHERE active > 0";
67  $sql .= " ORDER BY sortorder";
68 
69  $resql = $this->db->query($sql);
70  if ($resql) {
71  $num = $this->db->num_rows($resql);
72  $i = 0;
73  while ($i < $num) {
74  $obj = $this->db->fetch_object($resql);
75 
76  $level = $langs->trans($obj->code);
77  if ($level == $obj->code) {
78  $level = $langs->trans($obj->label);
79  }
80  $options_array[$obj->code] = $level;
81 
82  $i++;
83  }
84  } else {
85  dol_print_error($this->db);
86  }
87  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
88  }
89 
97  public function multiselectCountry($htmlname = 'country_id', $selected_array = array())
98  {
99  global $conf, $langs;
100 
101  $langs->load("dict");
102  $maxlength = 0;
103 
104  $out = '';
105  $countryArray = array();
106  $label = array();
107 
108  $options_array = array();
109 
110  $sql = "SELECT rowid, code as code_iso, label";
111  $sql .= " FROM ".MAIN_DB_PREFIX."c_country";
112  $sql .= " WHERE active = 1 AND code<>''";
113  $sql .= " ORDER BY code ASC";
114 
115  $resql = $this->db->query($sql);
116  if ($resql) {
117  $num = $this->db->num_rows($resql);
118  $i = 0;
119  if ($num) {
120  $foundselected = false;
121 
122  while ($i < $num) {
123  $obj = $this->db->fetch_object($resql);
124  $countryArray [$i] ['rowid'] = $obj->rowid;
125  $countryArray [$i] ['code_iso'] = $obj->code_iso;
126  $countryArray [$i] ['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
127  $label[$i] = $countryArray[$i]['label'];
128  $i++;
129  }
130 
131  $array1_sort_order = SORT_ASC;
132  array_multisort($label, $array1_sort_order, $countryArray);
133 
134  foreach ($countryArray as $row) {
135  $label = dol_trunc($row['label'], $maxlength, 'middle');
136  if ($row['code_iso']) {
137  $label .= ' ('.$row['code_iso'].')';
138  }
139 
140  $options_array[$row['rowid']] = $label;
141  }
142  }
143  } else {
144  dol_print_error($this->db);
145  }
146 
147  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
148  }
149 
158  public function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
159  {
160 
161  global $conf;
162 
163  $options_array = array();
164 
165  $sql_usr = '';
166  $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
167  $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
168  $sql_usr .= " WHERE u2.entity IN (0,".$conf->entity.")";
169  $sql_usr .= " AND u2.rowid = sc.fk_user ";
170 
171  if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) {
172  $sql_usr .= " AND u2.statut<>0 ";
173  }
174  $sql_usr .= " ORDER BY name ASC";
175  // print $sql_usr;exit;
176 
177  $resql_usr = $this->db->query($sql_usr);
178  if ($resql_usr) {
179  while ($obj_usr = $this->db->fetch_object($resql_usr)) {
180  $label = $obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
181 
182  $options_array [$obj_usr->rowid] = $label;
183  }
184  $this->db->free($resql_usr);
185  } else {
186  dol_print_error($this->db);
187  }
188 
189  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
190  }
191 
199  public function multiselectselectLanguage($htmlname = '', $selected_array = array())
200  {
201 
202  global $conf, $langs;
203 
204  $options_array = array();
205 
206  $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
207 
208  foreach ($langs_available as $key => $value) {
209  $label = $value;
210  $options_array[$key] = $label;
211  }
212  asort($options_array);
213  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
214  }
215 
225  public function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
226  {
227  $options_array = array();
228 
229  if (is_array($sqlqueryparam)) {
230  $param_list = array_keys($sqlqueryparam);
231  $InfoFieldList = explode(":", $param_list [0]);
232 
233  // 0 1 : tableName
234  // 1 2 : label field name Name of field that contains the label
235  // 2 3 : key fields name (if differ of rowid)
236  // 3 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
237 
238  $keyList = 'rowid';
239 
240  if (count($InfoFieldList) >= 3) {
241  if (strpos($InfoFieldList[3], 'extra.') !== false) {
242  $keyList = 'main.'.$InfoFieldList[2].' as rowid';
243  } else {
244  $keyList = $InfoFieldList[2].' as rowid';
245  }
246  }
247 
248  $sql = "SELECT ".$keyList.", ".$InfoFieldList[1];
249  $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0];
250  if (!empty($InfoFieldList[3])) {
251  // We have to join on extrafield table
252  if (strpos($InfoFieldList[3], 'extra') !== false) {
253  $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra';
254  $sql .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[3];
255  } else {
256  $sql .= " WHERE ".$InfoFieldList[3];
257  }
258  }
259  if (!empty($InfoFieldList[1])) {
260  $sql .= " ORDER BY nom";
261  }
262  // $sql.= ' WHERE entity = '.$conf->entity;
263 
264  $resql = $this->db->query($sql);
265  if ($resql) {
266  $num = $this->db->num_rows($resql);
267  $i = 0;
268  if ($num) {
269  while ($i < $num) {
270  $obj = $this->db->fetch_object($resql);
271  $labeltoshow = dol_trunc($obj->$InfoFieldList[1], 90);
272  $options_array[$obj->rowid] = $labeltoshow;
273  $i++;
274  }
275  }
276  $this->db->free($resql);
277  }
278  }
279 
280  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
281  }
282 
290  public function multiselectCivility($htmlname = 'civilite_id', $selected_array = array())
291  {
292  global $conf, $langs, $user;
293  $langs->load("dict");
294 
295  $options_array = array();
296 
297  $sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
298  $sql .= " WHERE active = 1";
299 
300  dol_syslog(__METHOD__, LOG_DEBUG);
301  $resql = $this->db->query($sql);
302  if ($resql) {
303  $num = $this->db->num_rows($resql);
304  $i = 0;
305  if ($num) {
306  while ($i < $num) {
307  $obj = $this->db->fetch_object($resql);
308  // If a translation exists, we use it, else we use the default label
309  $label = ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite != '-' ? $obj->civilite : ''));
310 
311  $options_array[$obj->code] = $label;
312 
313  $i++;
314  }
315  }
316  } else {
317  dol_print_error($this->db);
318  }
319 
320  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
321  }
322 
332  public function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0)
333  {
334  global $conf, $langs;
335 
336  $form = new Form($this->db);
337  $return = $form->multiselectarray($htmlname, $options_array, $selected_array, 0, 0, '', 0, 295);
338  return $return;
339  }
340 
351  public function selectAdvtargetemailingTemplate($htmlname = 'template_id', $selected = 0, $showempty = 0, $type_element = 'mailing', $morecss = '')
352  {
353  global $conf, $user, $langs;
354 
355  $out = '';
356 
357  $sql = "SELECT c.rowid, c.name, c.fk_element";
358  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_advtarget as c";
359  $sql .= " WHERE type_element = '".$this->db->escape($type_element)."'";
360  $sql .= " ORDER BY c.name";
361 
362  dol_syslog(__METHOD__, LOG_DEBUG);
363  $resql = $this->db->query($sql);
364  if ($resql) {
365  $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
366  if ($showempty) {
367  $out .= '<option value=""></option>';
368  }
369  $num = $this->db->num_rows($resql);
370  $i = 0;
371  if ($num) {
372  while ($i < $num) {
373  $obj = $this->db->fetch_object($resql);
374  $label = $obj->name;
375  if (empty($label)) {
376  $label = $obj->fk_element;
377  }
378 
379  if ($selected > 0 && $selected == $obj->rowid) {
380  $out .= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
381  } else {
382  $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>';
383  }
384  $i++;
385  }
386  }
387  $out .= '</select>';
388  } else {
389  dol_print_error($this->db);
390  }
391  $this->db->free($resql);
392  return $out;
393  }
394 }
Class to manage building of HTML components.
multiselectCivility($htmlname='civilite_id', $selected_array=array())
Return combo list with people title.
advMultiselectarraySelllist($htmlname, $sqlqueryparam=array(), $selected_array=array())
Return multiselect list of entities for extrafeild type sellist.
multiselectCountry($htmlname='country_id', $selected_array=array())
Return combo list of activated countries, into language of user.
advMultiselectarray($htmlname, $options_array=array(), $selected_array=array(), $showempty=0)
Return multiselect list of entities.
multiselectselectLanguage($htmlname='', $selected_array=array())
Return select list for categories (to use in form search selectors)
selectAdvtargetemailingTemplate($htmlname='template_id', $selected=0, $showempty=0, $type_element='mailing', $morecss='')
Return a combo list to select emailing target selector.
multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
Return select list for categories (to use in form search selectors)
multiselectProspectionStatus($selected_array=array(), $htmlname='cust_prospect_status')
Affiche un champs select contenant une liste.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))