dolibarr  7.0.0-beta
html.formadvtargetemailing.class.php
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 {
29  var $db;
30  var $error;
31 
37  function __construct($db) {
38  global $langs;
39 
40  $this->db = $db;
41  }
42 
50  function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status') {
51  global $conf, $langs;
52  $options_array = array();
53 
54  $sql = "SELECT code, label";
55  $sql .= " FROM " . MAIN_DB_PREFIX . "c_prospectlevel";
56  $sql .= " WHERE active > 0";
57  $sql .= " ORDER BY sortorder";
58  dol_syslog ( get_class( $this ) . '::multiselectProspectionStatus sql=' . $sql, LOG_DEBUG );
59  $resql = $this->db->query( $sql );
60  if ($resql) {
61  $num = $this->db->num_rows( $resql );
62  $i = 0;
63  while ( $i < $num ) {
64  $obj = $this->db->fetch_object( $resql );
65 
66  $level = $langs->trans( $obj->code );
67  if ($level == $obj->code)
68  $level = $langs->trans( $obj->label );
69  $options_array[$obj->code] = $level;
70 
71  $i ++;
72  }
73  } else {
74  dol_print_error($this->db);
75  }
76  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
77  }
78 
86  function multiselectCountry($htmlname = 'country_id', $selected_array=array()) {
87  global $conf, $langs;
88 
89  $langs->load("dict");
90  $maxlength = 0;
91 
92  $out = '';
93  $countryArray = array();
94  $label = array ();
95 
96  $options_array = array();
97 
98  $sql = "SELECT rowid, code as code_iso, label";
99  $sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
100  $sql .= " WHERE active = 1 AND code<>''";
101  $sql .= " ORDER BY code ASC";
102 
103  dol_syslog(get_class($this) . "::select_country sql=" . $sql);
104  $resql = $this->db->query($sql);
105  if ($resql) {
106 
107  $num = $this->db->num_rows($resql);
108  $i = 0;
109  if ($num) {
110  $foundselected = false;
111 
112  while ($i < $num) {
113  $obj = $this->db->fetch_object ( $resql );
114  $countryArray [$i] ['rowid'] = $obj->rowid;
115  $countryArray [$i] ['code_iso'] = $obj->code_iso;
116  $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 : ''));
117  $label[$i] = $countryArray[$i]['label'];
118  $i ++;
119  }
120 
121  array_multisort($label, SORT_ASC, $countryArray);
122 
123  foreach ($countryArray as $row) {
124  $label = dol_trunc($row['label'], $maxlength, 'middle');
125  if ($row['code_iso'])
126  $label .= ' (' . $row['code_iso'] . ')';
127 
128  $options_array[$row['rowid']] = $label;
129  }
130  }
131  } else {
132  dol_print_error($this->db);
133  }
134 
135  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
136  }
137 
146  function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user) {
147 
148  global $conf;
149 
150  $options_array = array ();
151 
152  $sql_usr = '';
153  $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
154  $sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
155  $sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")";
156  $sql_usr .= " AND u2.rowid = sc.fk_user ";
157 
158  if (! empty ( $conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX ))
159  $sql_usr .= " AND u2.statut<>0 ";
160  $sql_usr .= " ORDER BY name ASC";
161  // print $sql_usr;exit;
162 
163  $resql_usr = $this->db->query ( $sql_usr );
164  if ($resql_usr) {
165  while ( $obj_usr = $this->db->fetch_object ( $resql_usr ) ) {
166 
167  $label = $obj_usr->firstname . " " . $obj_usr->name . " (" . $obj_usr->login . ')';
168 
169  $options_array [$obj_usr->rowid] = $label;
170 
171  }
172  $this->db->free ( $resql_usr );
173  } else {
174  dol_print_error ( $this->db );
175  }
176 
177  return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
178  }
179 
187  function multiselectselectLanguage($htmlname='', $selected_array=array()) {
188 
189  global $conf,$langs;
190 
191  $options_array = array ();
192 
193  $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
194 
195  foreach ($langs_available as $key => $value)
196  {
197  $label = $value;
198  $options_array[$key] = $label;
199  }
200  asort($options_array);
201  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
202  }
203 
213  function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
214  {
215  $options_array=array();
216 
217  if (is_array($sqlqueryparam))
218  {
219  $param_list = array_keys ( $sqlqueryparam );
220  $InfoFieldList = explode ( ":", $param_list [0] );
221 
222  // 0 1 : tableName
223  // 1 2 : label field name Nom du champ contenant le libelle
224  // 2 3 : key fields name (if differ of rowid)
225  // 3 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
226 
227  $keyList = 'rowid';
228 
229  if (count ( $InfoFieldList ) >= 3) {
230  if (strpos ( $InfoFieldList [3], 'extra.' ) !== false) {
231  $keyList = 'main.' . $InfoFieldList [2] . ' as rowid';
232  } else {
233  $keyList = $InfoFieldList [2] . ' as rowid';
234  }
235  }
236 
237  $sql = 'SELECT ' . $keyList . ', ' . $InfoFieldList [1];
238  $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList [0];
239  if (! empty ( $InfoFieldList [3] )) {
240 
241  // We have to join on extrafield table
242  if (strpos ( $InfoFieldList [3], 'extra' ) !== false) {
243  $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList [0] . '_extrafields as extra';
244  $sql .= ' WHERE extra.fk_object=main.' . $InfoFieldList [2] . ' AND ' . $InfoFieldList [3];
245  } else {
246  $sql .= ' WHERE ' . $InfoFieldList [3];
247  }
248  }
249  if (! empty($InfoFieldList[1])) {
250  $sql .= " ORDER BY nom";
251  }
252  // $sql.= ' WHERE entity = '.$conf->entity;
253 
254  dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG);
255  $resql = $this->db->query($sql);
256  if ($resql) {
257 
258  $num = $this->db->num_rows($resql);
259  $i = 0;
260  if ($num) {
261  while ( $i < $num ) {
262  $obj = $this->db->fetch_object ( $resql );
263  $labeltoshow = dol_trunc ( $obj->$InfoFieldList [1], 90 );
264  $options_array[$obj->rowid]=$labeltoshow;
265  $i ++;
266  }
267  }
268  $this->db->free ( $resql );
269  }
270  }
271 
272  return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
273  }
274 
282  function multiselectCivility($htmlname='civilite_id',$selected_array = array())
283  {
284  global $conf,$langs,$user;
285  $langs->load("dict");
286 
287  $options_array=array();
288 
289 
290  $sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
291  $sql.= " WHERE active = 1";
292 
293  dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG);
294  $resql=$this->db->query($sql);
295  if ($resql)
296  {
297 
298  $num = $this->db->num_rows($resql);
299  $i = 0;
300  if ($num)
301  {
302  while ($i < $num)
303  {
304  $obj = $this->db->fetch_object($resql);
305  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
306  $label= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:''));
307 
308 
309  $options_array[$obj->code]=$label;
310 
311  $i++;
312  }
313  }
314 
315  }
316  else
317  {
318  dol_print_error($this->db);
319  }
320 
321  return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
322  }
323 
333  function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0) {
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 
348  function multiselectCustomerCategories($htmlname='cust_cat',$selected_array = array())
349  {
350  return $this->multiselectCategories($htmlname,$selected_array,2);
351  }
352 
360  function multiselectContactCategories($htmlname='contact_cat',$selected_array = array())
361  {
362  return $this->multiselectCategories($htmlname,$selected_array,4);
363  }
364 
373  public function multiselectCategories($htmlname='',$selected_array = array(), $type=0)
374  {
375  global $conf,$langs,$user;
376  $langs->load("dict");
377 
378  $options_array=array();
379 
380  $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."categorie";
381  $sql.= " WHERE type=".$type;
382 
383  dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG);
384  $resql=$this->db->query($sql);
385  if ($resql)
386  {
387 
388  $num = $this->db->num_rows($resql);
389  $i = 0;
390  if ($num)
391  {
392  while ($i < $num)
393  {
394  $obj = $this->db->fetch_object($resql);
395 
396  $options_array[$obj->rowid]=$obj->label;
397 
398  $i++;
399  }
400  }
401 
402  }
403  else
404  {
405  dol_print_error($this->db);
406  }
407 
408  return $this->advMultiselectarray( $htmlname, $options_array, $selected_array );
409  }
410 
420  public function selectAdvtargetemailingTemplate($htmlname='template_id',$selected=0,$showempty=0) {
421  global $conf, $user, $langs;
422 
423  $out = '';
424 
425  $sql = "SELECT c.rowid, c.name, c.fk_mailing";
426  $sql .= " FROM " . MAIN_DB_PREFIX . "advtargetemailing as c";
427  $sql .= " ORDER BY c.name";
428 
429  dol_syslog ( get_class ( $this ) . "::".__METHOD__, LOG_DEBUG );
430  $resql = $this->db->query ( $sql );
431  if ($resql) {
432 
433 
434  $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
435  if ($showempty)
436  $out .= '<option value=""></option>';
437  $num = $this->db->num_rows ( $resql );
438  $i = 0;
439  if ($num) {
440  while ( $i < $num ) {
441  $obj = $this->db->fetch_object ( $resql );
442  $label = $obj->name;
443  if (empty($label)) {
444  $label=$obj->fk_mailing;
445  }
446 
447  if ($selected > 0 && $selected == $obj->rowid) {
448  $out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>';
449  } else {
450  $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>';
451  }
452  $i ++;
453  }
454  }
455  $out .= '</select>';
456  } else {
457  dol_print_error ( $this->db );
458  }
459  $this->db->free ( $resql );
460  return $out;
461  }
462 }
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.
multiselectProspectionStatus($selected_array=array(), $htmlname= 'cust_prospect_status')
Affiche un champs select contenant une liste.
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...
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.
advMultiselectarraySelllist($htmlname, $sqlqueryparam=array(), $selected_array=array())
Return multiselect list of entities for extrafeild type sellist.
selectAdvtargetemailingTemplate($htmlname='template_id', $selected=0, $showempty=0)
selectAdvtargetemailingTemplate
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)
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
multiselectselectLanguage($htmlname='', $selected_array=array())
Return select list for categories (to use in form search selectors)
multiselectCountry($htmlname= 'country_id', $selected_array=array())
Return combo list of activated countries, into language of user.