dolibarr  16.0.5
html.formwebsite.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
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 <https://www.gnu.org/licenses/>.
16  */
17 
29 {
30  private $db;
31 
35  public $error;
36 
40  public $num;
41 
42 
48  public function __construct($db)
49  {
50  $this->db = $db;
51  }
52 
53 
62  public function selectWebsite($selected = '', $htmlname = 'exportmodelid', $useempty = 0)
63  {
64  $out = '';
65 
66  $sql = "SELECT rowid, ref";
67  $sql .= " FROM ".$this->db->prefix()."website";
68  $sql .= " WHERE 1 = 1";
69  $sql .= " ORDER BY rowid";
70  $result = $this->db->query($sql);
71  if ($result) {
72  $out .= '<select class="flat minwidth100" name="'.$htmlname.'" id="'.$htmlname.'">';
73  if ($useempty) {
74  $out .= '<option value="-1">&nbsp;</option>';
75  }
76 
77  $num = $this->db->num_rows($result);
78  $i = 0;
79  while ($i < $num) {
80  $obj = $this->db->fetch_object($result);
81  if ($selected == $obj->rowid) {
82  $out .= '<option value="'.$obj->rowid.'" selected>';
83  } else {
84  $out .= '<option value="'.$obj->rowid.'">';
85  }
86  $out .= $obj->ref;
87  $out .= '</option>';
88  $i++;
89  }
90  $out .= "</select>";
91  } else {
92  dol_print_error($this->db);
93  }
94 
95  return $out;
96  }
97 
98 
110  public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0, $morecss = 'minwidth200')
111  {
112  global $langs, $conf, $user;
113 
114  $langs->load("admin");
115 
116  $sql = "SELECT rowid, code, label, entity";
117  $sql .= " FROM ".$this->db->prefix().'c_type_container';
118  $sql .= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")";
119  $sql .= " ORDER BY label";
120 
121  dol_syslog(get_class($this)."::selectTypeOfContainer", LOG_DEBUG);
122  $result = $this->db->query($sql);
123  if ($result) {
124  $num = $this->db->num_rows($result);
125  $i = 0;
126  if ($num) {
127  print '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
128  if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
129  print '<option value="-1">&nbsp;</option>';
130  }
131 
132  while ($i < $num) {
133  $obj = $this->db->fetch_object($result);
134  if ($selected == $obj->rowid || $selected == $obj->code) {
135  print '<option value="'.$obj->code.'" selected>';
136  } else {
137  print '<option value="'.$obj->code.'">';
138  }
139  print $obj->label;
140  print '</option>';
141  $i++;
142  }
143  print "</select>";
144  if ($user->admin) {
145  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
146  }
147 
148  if ($addjscombo) {
149  print ajax_combobox('select'.$htmlname);
150  }
151  } else {
152  print $langs->trans("NoTypeOfPagePleaseEditDictionary");
153  }
154  } else {
155  dol_print_error($this->db);
156  }
157  }
158 
159 
171  public function selectSampleOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0, $morecss = 'minwidth200')
172  {
173  global $langs, $conf, $user;
174 
175  $langs->load("admin");
176 
177  $listofsamples = dol_dir_list(DOL_DOCUMENT_ROOT.'/website/samples', 'files', 0, '^page-sample-.*\.html$');
178 
179  $arrayofsamples = array();
180  $arrayofsamples['empty'] = 'EmptyPage'; // Always this one first
181  foreach ($listofsamples as $sample) {
182  $reg = array();
183  if (preg_match('/^page-sample-(.*)\.html$/', $sample['name'], $reg)) {
184  $key = $reg[1];
185  $labelkey = ucfirst($key);
186  if ($key == 'empty') {
187  $labelkey = 'EmptyPage';
188  }
189  $arrayofsamples[$key] = $labelkey;
190  }
191  }
192 
193  $out = '';
194  $out .= '<select id="select'.$htmlname.'" class="selectSampleOfContainer'.($morecss? ' '.$morecss : '').'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
195 
196  if ($useempty == 1 || $useempty == 2) {
197  $out .= '<option value="-1">&nbsp;</option>';
198  }
199 
200  foreach ($arrayofsamples as $key => $val) {
201  if ($selected == $key) {
202  $out .= '<option value="'.$key.'" selected>';
203  } else {
204  $out .= '<option value="'.$key.'">';
205  }
206  $out .= $langs->trans($val);
207  $out .= '</option>';
208  }
209  $out .= "</select>";
210 
211  if ($addjscombo) {
212  $out .= ajax_combobox('select'.$htmlname);
213  }
214 
215  return $out;
216  }
217 
218 
232  public function selectContainer($website, $htmlname = 'pageid', $pageid = 0, $showempty = 0, $action = '', $morecss = 'minwidth200', $excludeids = null)
233  {
234  $this->num = 0;
235 
236  $atleastonepage = (is_array($website->lines) && count($website->lines) > 0);
237 
238  $out = '';
239  if ($atleastonepage && $action != 'editsource') {
240  $out .= '<select name="'.$htmlname.'" id="'.$htmlname.'" class="maxwidth300'.($morecss ? ' '.$morecss : '').'">';
241  } else {
242  $out .= '<select name="pageidbis" id="pageid" class="maxwidth300'.($morecss ? ' '.$morecss : '').'" disabled="disabled">';
243  }
244 
245  if ($showempty || !$atleastonepage) {
246  $out .= '<option value="-1">&nbsp;</option>';
247  }
248 
249  if ($atleastonepage) {
250  if (empty($pageid) && $action != 'createcontainer') { // Page id is not defined, we try to take one
251  $firstpageid = 0;
252  $homepageid = 0;
253  foreach ($website->lines as $key => $valpage) {
254  if (empty($firstpageid)) {
255  $firstpageid = $valpage->id;
256  }
257  if ($website->fk_default_home && $key == $website->fk_default_home) {
258  $homepageid = $valpage->id;
259  }
260  }
261  $pageid = $homepageid ? $homepageid : $firstpageid; // We choose home page and if not defined yet, we take first page
262  }
263 
264  foreach ($website->lines as $key => $valpage) {
265  if (is_array($excludeids) && count($excludeids) && in_array($valpage->id, $excludeids)) {
266  continue;
267  }
268 
269  $valueforoption = '<span class="opacitymedium">['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).']</span> ';
270  $valueforoption .= $valpage->pageurl.' - '.$valpage->title;
271  if ($website->otherlang) { // If there is alternative lang for this web site, we show the language code
272  if ($valpage->lang) {
273  $valueforoption .= ' <span class="opacitymedium">('.$valpage->lang.')</span>';
274  }
275  }
276  if ($website->fk_default_home && $key == $website->fk_default_home) {
277  //$valueforoption .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
278  $valueforoption .= ' <span class="opacitymedium fa fa-home"></span>';
279  }
280 
281  $out .= '<option value="'.$key.'"';
282  if ($pageid > 0 && $pageid == $key) {
283  $out .= ' selected'; // To preselect a value
284  }
285  $out .= ' data-html="'.dol_escape_htmltag($valueforoption).'"';
286  $out .= '>';
287  $out .= $valueforoption;
288  $out .= '</option>';
289 
290  ++$this->num;
291  }
292  }
293  $out .= '</select>';
294 
295  if ($atleastonepage && $action != 'editsource') {
296  $out .= ajax_combobox($htmlname);
297  } else {
298  $out .= '<input type="hidden" name="'.$htmlname.'" value="'.$pageid.'">';
299  $out .= ajax_combobox($htmlname);
300  }
301  return $out;
302  }
303 }
FormWebsite\selectTypeOfContainer
selectTypeOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='', $addjscombo=0, $morecss='minwidth200')
Return a HTML select list of type of containers from the dictionary.
Definition: html.formwebsite.class.php:110
FormWebsite\selectWebsite
selectWebsite($selected='', $htmlname='exportmodelid', $useempty=0)
Return HTML select list of websites.
Definition: html.formwebsite.class.php:62
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
db
$conf db
API class for accounts.
Definition: inc.php:41
FormWebsite\selectContainer
selectContainer($website, $htmlname='pageid', $pageid=0, $showempty=0, $action='', $morecss='minwidth200', $excludeids=null)
Return a HTML select list of containers of a website.
Definition: html.formwebsite.class.php:232
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormWebsite
Class to manage component html for module website.
Definition: html.formwebsite.class.php:28
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
FormWebsite\__construct
__construct($db)
Constructor.
Definition: html.formwebsite.class.php:48
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
FormWebsite\$num
$num
var int A number of lines
Definition: html.formwebsite.class.php:40
FormWebsite\selectSampleOfContainer
selectSampleOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='', $addjscombo=0, $morecss='minwidth200')
Return a HTML select list of samples of containers content.
Definition: html.formwebsite.class.php:171