dolibarr  9.0.0
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  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
28 {
32  public $db;
33 
37  public $error='';
38 
44  function __construct($db)
45  {
46  global $langs;
47 
48  $this->db = $db;
49  }
50 
58  function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status')
59  {
60  global $conf, $langs;
61  $options_array = array();
62 
63  $sql = "SELECT code, label";
64  $sql .= " FROM " . MAIN_DB_PREFIX . "c_prospectlevel";
65  $sql .= " WHERE active > 0";
66  $sql .= " ORDER BY sortorder";
67  dol_syslog ( get_class( $this ) . '::multiselectProspectionStatus sql=' . $sql, LOG_DEBUG );
68  $resql = $this->db->query( $sql );
69  if ($resql) {
70  $num = $this->db->num_rows( $resql );
71  $i = 0;
72  while ( $i < $num ) {
73  $obj = $this->db->fetch_object( $resql );
74 
75  $level = $langs->trans( $obj->code );
76  if ($level == $obj->code)
77  $level = $langs->trans( $obj->label );
78  $options_array[$obj->code] = $level;
79 
80  $i ++;
81  }
82  } else {
83  dol_print_error($this->db);
84  }
85  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
86  }
87 
95  function multiselectCountry($htmlname = 'country_id', $selected_array=array())
96  {
97  global $conf, $langs;
98 
99  $langs->load("dict");
100  $maxlength = 0;
101 
102  $out = '';
103  $countryArray = array();
104  $label = array ();
105 
106  $options_array = array();
107 
108  $sql = "SELECT rowid, code as code_iso, label";
109  $sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
110  $sql .= " WHERE active = 1 AND code<>''";
111  $sql .= " ORDER BY code ASC";
112 
113  dol_syslog(get_class($this) . "::select_country sql=" . $sql);
114  $resql = $this->db->query($sql);
115  if ($resql) {
116 
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  array_multisort($label, SORT_ASC, $countryArray);
132 
133  foreach ($countryArray as $row) {
134  $label = dol_trunc($row['label'], $maxlength, 'middle');
135  if ($row['code_iso'])
136  $label .= ' (' . $row['code_iso'] . ')';
137 
138  $options_array[$row['rowid']] = $label;
139  }
140  }
141  } else {
142  dol_print_error($this->db);
143  }
144 
145  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
146  }
147 
156  function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user)
157  {
158 
159  global $conf;
160 
161  $options_array = array ();
162 
163  $sql_usr = '';
164  $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
165  $sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
166  $sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")";
167  $sql_usr .= " AND u2.rowid = sc.fk_user ";
168 
169  if (! empty ( $conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX ))
170  $sql_usr .= " AND u2.statut<>0 ";
171  $sql_usr .= " ORDER BY name ASC";
172  // print $sql_usr;exit;
173 
174  $resql_usr = $this->db->query ( $sql_usr );
175  if ($resql_usr) {
176  while ( $obj_usr = $this->db->fetch_object ( $resql_usr ) ) {
177 
178  $label = $obj_usr->firstname . " " . $obj_usr->name . " (" . $obj_usr->login . ')';
179 
180  $options_array [$obj_usr->rowid] = $label;
181  }
182  $this->db->free ( $resql_usr );
183  } else {
184  dol_print_error ( $this->db );
185  }
186 
187  return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
188  }
189 
197  function multiselectselectLanguage($htmlname='', $selected_array=array())
198  {
199 
200  global $conf,$langs;
201 
202  $options_array = array ();
203 
204  $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
205 
206  foreach ($langs_available as $key => $value)
207  {
208  $label = $value;
209  $options_array[$key] = $label;
210  }
211  asort($options_array);
212  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
213  }
214 
224  function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
225  {
226  $options_array=array();
227 
228  if (is_array($sqlqueryparam))
229  {
230  $param_list = array_keys ( $sqlqueryparam );
231  $InfoFieldList = explode ( ":", $param_list [0] );
232 
233  // 0 1 : tableName
234  // 1 2 : label field name Nom du champ contenant le libelle
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 
252  // We have to join on extrafield table
253  if (strpos ( $InfoFieldList [3], 'extra' ) !== false) {
254  $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList [0] . '_extrafields as extra';
255  $sql .= ' WHERE extra.fk_object=main.' . $InfoFieldList [2] . ' AND ' . $InfoFieldList [3];
256  } else {
257  $sql .= ' WHERE ' . $InfoFieldList [3];
258  }
259  }
260  if (! empty($InfoFieldList[1])) {
261  $sql .= " ORDER BY nom";
262  }
263  // $sql.= ' WHERE entity = '.$conf->entity;
264 
265  dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG);
266  $resql = $this->db->query($sql);
267  if ($resql) {
268 
269  $num = $this->db->num_rows($resql);
270  $i = 0;
271  if ($num) {
272  while ( $i < $num ) {
273  $obj = $this->db->fetch_object ( $resql );
274  $labeltoshow = dol_trunc ( $obj->$InfoFieldList [1], 90 );
275  $options_array[$obj->rowid]=$labeltoshow;
276  $i ++;
277  }
278  }
279  $this->db->free ( $resql );
280  }
281  }
282 
283  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
284  }
285 
293  function multiselectCivility($htmlname='civilite_id',$selected_array = array())
294  {
295  global $conf,$langs,$user;
296  $langs->load("dict");
297 
298  $options_array=array();
299 
300 
301  $sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
302  $sql.= " WHERE active = 1";
303 
304  dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG);
305  $resql=$this->db->query($sql);
306  if ($resql)
307  {
308 
309  $num = $this->db->num_rows($resql);
310  $i = 0;
311  if ($num)
312  {
313  while ($i < $num)
314  {
315  $obj = $this->db->fetch_object($resql);
316  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
317  $label= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:''));
318 
319 
320  $options_array[$obj->code]=$label;
321 
322  $i++;
323  }
324  }
325  }
326  else
327  {
328  dol_print_error($this->db);
329  }
330 
331  return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
332  }
333 
343  function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0)
344  {
345  global $conf, $langs;
346 
347  $form=new Form($this->db);
348  $return = $form->multiselectarray($htmlname, $options_array, $selected_array,0,0,'',0,295);
349  return $return;
350  }
351 
359  function multiselectCustomerCategories($htmlname='cust_cat',$selected_array = array())
360  {
361  return $this->multiselectCategories($htmlname,$selected_array,2);
362  }
363 
371  function multiselectContactCategories($htmlname='contact_cat',$selected_array = array())
372  {
373  return $this->multiselectCategories($htmlname,$selected_array,4);
374  }
375 
384  public function multiselectCategories($htmlname='',$selected_array = array(), $type=0)
385  {
386  global $conf,$langs,$user;
387  $langs->load("dict");
388 
389  $options_array=array();
390 
391  $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."categorie";
392  $sql.= " WHERE type=".$type;
393 
394  dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG);
395  $resql=$this->db->query($sql);
396  if ($resql)
397  {
398 
399  $num = $this->db->num_rows($resql);
400  $i = 0;
401  if ($num)
402  {
403  while ($i < $num)
404  {
405  $obj = $this->db->fetch_object($resql);
406 
407  $options_array[$obj->rowid]=$obj->label;
408 
409  $i++;
410  }
411  }
412  }
413  else
414  {
415  dol_print_error($this->db);
416  }
417 
418  return $this->advMultiselectarray( $htmlname, $options_array, $selected_array );
419  }
420 
430  public function selectAdvtargetemailingTemplate($htmlname='template_id', $selected=0, $showempty=0, $type_element='mailing')
431  {
432  global $conf, $user, $langs;
433 
434  $out = '';
435 
436  $sql = "SELECT c.rowid, c.name, c.fk_element";
437  $sql .= " FROM " . MAIN_DB_PREFIX . "advtargetemailing as c";
438  $sql .= " WHERE type_element='$type_element'";
439  $sql .= " ORDER BY c.name";
440 
441  dol_syslog ( get_class ( $this ) . "::".__METHOD__, LOG_DEBUG );
442  $resql = $this->db->query ( $sql );
443  if ($resql) {
444 
445 
446  $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
447  if ($showempty)
448  $out .= '<option value=""></option>';
449  $num = $this->db->num_rows ( $resql );
450  $i = 0;
451  if ($num) {
452  while ( $i < $num ) {
453  $obj = $this->db->fetch_object ( $resql );
454  $label = $obj->name;
455  if (empty($label)) {
456  $label=$obj->fk_element;
457  }
458 
459  if ($selected > 0 && $selected == $obj->rowid) {
460  $out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>';
461  } else {
462  $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>';
463  }
464  $i ++;
465  }
466  }
467  $out .= '</select>';
468  } else {
469  dol_print_error ( $this->db );
470  }
471  $this->db->free ( $resql );
472  return $out;
473  }
474 }
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.
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:1053
Class to manage building of HTML components.
multiselectCategories($htmlname='', $selected_array=array(), $type=0)
Return combo list of categories.
advMultiselectarray($htmlname, $options_array=array(), $selected_array=array(), $showempty=0)
Return multiselect list of entities.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
multiselectCountry($htmlname='country_id', $selected_array=array())
Return combo list of activated countries, into language of user.
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.
advMultiselectarraySelllist($htmlname, $sqlqueryparam=array(), $selected_array=array())
Return multiselect list of entities for extrafeild type sellist.
multiselectCivility($htmlname='civilite_id', $selected_array=array())
Return combo list with people title.
multiselectCustomerCategories($htmlname='cust_cat', $selected_array=array())
Return combo list with customer categories.
multiselectContactCategories($htmlname='contact_cat', $selected_array=array())
Return combo list with customer contact.
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.
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')
Return a combo list to select emailing target selector.