dolibarr 19.0.3
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 global $conf;
161
162 $options_array = array();
163
164 $sql_usr = '';
165 $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
166 $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
167 $sql_usr .= " WHERE u2.entity IN (0,".$conf->entity.")";
168 $sql_usr .= " AND u2.rowid = sc.fk_user ";
169
170 if (getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX')) {
171 $sql_usr .= " AND u2.statut<>0 ";
172 }
173 $sql_usr .= " ORDER BY name ASC";
174 // print $sql_usr;exit;
175
176 $resql_usr = $this->db->query($sql_usr);
177 if ($resql_usr) {
178 while ($obj_usr = $this->db->fetch_object($resql_usr)) {
179 $label = $obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
180
181 $options_array [$obj_usr->rowid] = $label;
182 }
183 $this->db->free($resql_usr);
184 } else {
185 dol_print_error($this->db);
186 }
187
188 return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
189 }
190
198 public function multiselectselectLanguage($htmlname = '', $selected_array = array())
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 $label = $value;
208 $options_array[$key] = $label;
209 }
210 asort($options_array);
211 return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
212 }
213
223 public function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
224 {
225 $options_array = array();
226
227 if (is_array($sqlqueryparam)) {
228 $param_list = array_keys($sqlqueryparam);
229 $InfoFieldList = explode(":", $param_list [0]);
230
231 // 0 1 : tableName
232 // 1 2 : label field name Name of field that contains the label
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 $num = $this->db->num_rows($resql);
302 $i = 0;
303 if ($num) {
304 while ($i < $num) {
305 $obj = $this->db->fetch_object($resql);
306 // If a translation exists, we use it, else we use the default label
307 $label = ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite != '-' ? $obj->civilite : ''));
308
309 $options_array[$obj->code] = $label;
310
311 $i++;
312 }
313 }
314 } else {
315 dol_print_error($this->db);
316 }
317
318 return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
319 }
320
330 public function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0)
331 {
332 global $conf, $langs;
333
334 $form = new Form($this->db);
335 $return = $form->multiselectarray($htmlname, $options_array, $selected_array, 0, 0, '', 0, 295);
336 return $return;
337 }
338
349 public function selectAdvtargetemailingTemplate($htmlname = 'template_id', $selected = 0, $showempty = 0, $type_element = 'mailing', $morecss = '')
350 {
351 global $conf, $user, $langs;
352
353 $out = '';
354
355 $sql = "SELECT c.rowid, c.name, c.fk_element";
356 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_advtarget as c";
357 $sql .= " WHERE type_element = '".$this->db->escape($type_element)."'";
358 $sql .= " ORDER BY c.name";
359
360 dol_syslog(__METHOD__, LOG_DEBUG);
361 $resql = $this->db->query($sql);
362 if ($resql) {
363 $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
364 if ($showempty) {
365 $out .= '<option value=""></option>';
366 }
367 $num = $this->db->num_rows($resql);
368 $i = 0;
369 if ($num) {
370 while ($i < $num) {
371 $obj = $this->db->fetch_object($resql);
372 $label = $obj->name;
373 if (empty($label)) {
374 $label = $obj->fk_element;
375 }
376
377 if ($selected > 0 && $selected == $obj->rowid) {
378 $out .= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
379 } else {
380 $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>';
381 }
382 $i++;
383 }
384 }
385 $out .= '</select>';
386 } else {
387 dol_print_error($this->db);
388 }
389 $this->db->free($resql);
390 return $out;
391 }
392}
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.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.