dolibarr  13.0.2
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  $options_array[$obj->code] = $level;
80 
81  $i++;
82  }
83  } else {
84  dol_print_error($this->db);
85  }
86  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
87  }
88 
96  public function multiselectCountry($htmlname = 'country_id', $selected_array = array())
97  {
98  global $conf, $langs;
99 
100  $langs->load("dict");
101  $maxlength = 0;
102 
103  $out = '';
104  $countryArray = array();
105  $label = array();
106 
107  $options_array = array();
108 
109  $sql = "SELECT rowid, code as code_iso, label";
110  $sql .= " FROM ".MAIN_DB_PREFIX."c_country";
111  $sql .= " WHERE active = 1 AND code<>''";
112  $sql .= " ORDER BY code ASC";
113 
114  $resql = $this->db->query($sql);
115  if ($resql) {
116  $num = $this->db->num_rows($resql);
117  $i = 0;
118  if ($num) {
119  $foundselected = false;
120 
121  while ($i < $num) {
122  $obj = $this->db->fetch_object($resql);
123  $countryArray [$i] ['rowid'] = $obj->rowid;
124  $countryArray [$i] ['code_iso'] = $obj->code_iso;
125  $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 : ''));
126  $label[$i] = $countryArray[$i]['label'];
127  $i++;
128  }
129 
130  array_multisort($label, SORT_ASC, $countryArray);
131 
132  foreach ($countryArray as $row) {
133  $label = dol_trunc($row['label'], $maxlength, 'middle');
134  if ($row['code_iso'])
135  $label .= ' ('.$row['code_iso'].')';
136 
137  $options_array[$row['rowid']] = $label;
138  }
139  }
140  } else {
141  dol_print_error($this->db);
142  }
143 
144  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
145  }
146 
155  public function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
156  {
157 
158  global $conf;
159 
160  $options_array = array();
161 
162  $sql_usr = '';
163  $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
164  $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
165  $sql_usr .= " WHERE u2.entity IN (0,".$conf->entity.")";
166  $sql_usr .= " AND u2.rowid = sc.fk_user ";
167 
168  if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX))
169  $sql_usr .= " AND u2.statut<>0 ";
170  $sql_usr .= " ORDER BY name ASC";
171  // print $sql_usr;exit;
172 
173  $resql_usr = $this->db->query($sql_usr);
174  if ($resql_usr) {
175  while ($obj_usr = $this->db->fetch_object($resql_usr)) {
176  $label = $obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
177 
178  $options_array [$obj_usr->rowid] = $label;
179  }
180  $this->db->free($resql_usr);
181  } else {
182  dol_print_error($this->db);
183  }
184 
185  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
186  }
187 
195  public function multiselectselectLanguage($htmlname = '', $selected_array = array())
196  {
197 
198  global $conf, $langs;
199 
200  $options_array = array();
201 
202  $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
203 
204  foreach ($langs_available as $key => $value)
205  {
206  $label = $value;
207  $options_array[$key] = $label;
208  }
209  asort($options_array);
210  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
211  }
212 
222  public function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
223  {
224  $options_array = array();
225 
226  if (is_array($sqlqueryparam))
227  {
228  $param_list = array_keys($sqlqueryparam);
229  $InfoFieldList = explode(":", $param_list [0]);
230 
231  // 0 1 : tableName
232  // 1 2 : label field name Nom du champ contenant le libelle
233  // 2 3 : key fields name (if differ of rowid)
234  // 3 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
235 
236  $keyList = 'rowid';
237 
238  if (count($InfoFieldList) >= 3) {
239  if (strpos($InfoFieldList [3], 'extra.') !== false) {
240  $keyList = 'main.'.$InfoFieldList [2].' as rowid';
241  } else {
242  $keyList = $InfoFieldList [2].' as rowid';
243  }
244  }
245 
246  $sql = 'SELECT '.$keyList.', '.$InfoFieldList [1];
247  $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList [0];
248  if (!empty($InfoFieldList [3])) {
249  // We have to join on extrafield table
250  if (strpos($InfoFieldList [3], 'extra') !== false) {
251  $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList [0].'_extrafields as extra';
252  $sql .= ' WHERE extra.fk_object=main.'.$InfoFieldList [2].' AND '.$InfoFieldList [3];
253  } else {
254  $sql .= ' WHERE '.$InfoFieldList [3];
255  }
256  }
257  if (!empty($InfoFieldList[1])) {
258  $sql .= " ORDER BY nom";
259  }
260  // $sql.= ' WHERE entity = '.$conf->entity;
261 
262  $resql = $this->db->query($sql);
263  if ($resql) {
264  $num = $this->db->num_rows($resql);
265  $i = 0;
266  if ($num) {
267  while ($i < $num) {
268  $obj = $this->db->fetch_object($resql);
269  $labeltoshow = dol_trunc($obj->$InfoFieldList [1], 90);
270  $options_array[$obj->rowid] = $labeltoshow;
271  $i++;
272  }
273  }
274  $this->db->free($resql);
275  }
276  }
277 
278  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
279  }
280 
288  public function multiselectCivility($htmlname = 'civilite_id', $selected_array = array())
289  {
290  global $conf, $langs, $user;
291  $langs->load("dict");
292 
293  $options_array = array();
294 
295  $sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
296  $sql .= " WHERE active = 1";
297 
298  dol_syslog(__METHOD__, LOG_DEBUG);
299  $resql = $this->db->query($sql);
300  if ($resql)
301  {
302  $num = $this->db->num_rows($resql);
303  $i = 0;
304  if ($num)
305  {
306  while ($i < $num)
307  {
308  $obj = $this->db->fetch_object($resql);
309  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
310  $label = ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite != '-' ? $obj->civilite : ''));
311 
312  $options_array[$obj->code] = $label;
313 
314  $i++;
315  }
316  }
317  } else {
318  dol_print_error($this->db);
319  }
320 
321  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
322  }
323 
333  public function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0)
334  {
335  global $conf, $langs;
336 
337  $form = new Form($this->db);
338  $return = $form->multiselectarray($htmlname, $options_array, $selected_array, 0, 0, '', 0, 295);
339  return $return;
340  }
341 
352  public function selectAdvtargetemailingTemplate($htmlname = 'template_id', $selected = 0, $showempty = 0, $type_element = 'mailing', $morecss = '')
353  {
354  global $conf, $user, $langs;
355 
356  $out = '';
357 
358  $sql = "SELECT c.rowid, c.name, c.fk_element";
359  $sql .= " FROM ".MAIN_DB_PREFIX."advtargetemailing as c";
360  $sql .= " WHERE type_element='$type_element'";
361  $sql .= " ORDER BY c.name";
362 
363  dol_syslog(__METHOD__, LOG_DEBUG);
364  $resql = $this->db->query($sql);
365  if ($resql) {
366  $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
367  if ($showempty)
368  $out .= '<option value=""></option>';
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 }
multiselectselectLanguage($htmlname= '', $selected_array=array())
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 building of HTML components.
multiselectCivility($htmlname= 'civilite_id', $selected_array=array())
Return combo list with people title.
advMultiselectarray($htmlname, $options_array=array(), $selected_array=array(), $showempty=0)
Return multiselect list of entities.
$conf db
API class for accounts.
Definition: inc.php:54
selectAdvtargetemailingTemplate($htmlname= 'template_id', $selected=0, $showempty=0, $type_element= 'mailing', $morecss= '')
Return a combo list to select emailing target selector.
Class to manage generation of HTML components Only common components must be here.
advMultiselectarraySelllist($htmlname, $sqlqueryparam=array(), $selected_array=array())
Return multiselect list of entities for extrafeild type sellist.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
Return select list for categories (to use in form search selectors)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
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 &#39;...&#39; if string larger than length.
multiselectCountry($htmlname= 'country_id', $selected_array=array())
Return combo list of activated countries, into language of user.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.