dolibarr  13.0.2
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 ".MAIN_DB_PREFIX."website";
68  $sql .= " WHERE 1 = 1";
69  $sql .= " ORDER BY rowid";
70  $result = $this->db->query($sql);
71  if ($result)
72  {
73  $out .= '<select class="flat minwidth100" name="'.$htmlname.'" id="'.$htmlname.'">';
74  if ($useempty)
75  {
76  $out .= '<option value="-1">&nbsp;</option>';
77  }
78 
79  $num = $this->db->num_rows($result);
80  $i = 0;
81  while ($i < $num)
82  {
83  $obj = $this->db->fetch_object($result);
84  if ($selected == $obj->rowid)
85  {
86  $out .= '<option value="'.$obj->rowid.'" selected>';
87  } else {
88  $out .= '<option value="'.$obj->rowid.'">';
89  }
90  $out .= $obj->ref;
91  $out .= '</option>';
92  $i++;
93  }
94  $out .= "</select>";
95  } else {
96  dol_print_error($this->db);
97  }
98 
99  return $out;
100  }
101 
102 
113  public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0)
114  {
115  global $langs, $conf, $user;
116 
117  $langs->load("admin");
118 
119  $sql = "SELECT rowid, code, label, entity";
120  $sql .= " FROM ".MAIN_DB_PREFIX.'c_type_container';
121  $sql .= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")";
122  $sql .= " ORDER BY label";
123 
124  dol_syslog(get_class($this)."::selectTypeOfContainer", LOG_DEBUG);
125  $result = $this->db->query($sql);
126  if ($result)
127  {
128  $num = $this->db->num_rows($result);
129  $i = 0;
130  if ($num)
131  {
132  print '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer minwidth200" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
133  if ($useempty == 1 || ($useempty == 2 && $num > 1))
134  {
135  print '<option value="-1">&nbsp;</option>';
136  }
137 
138  while ($i < $num)
139  {
140  $obj = $this->db->fetch_object($result);
141  if ($selected == $obj->rowid || $selected == $obj->code)
142  {
143  print '<option value="'.$obj->code.'" selected>';
144  } else {
145  print '<option value="'.$obj->code.'">';
146  }
147  print $obj->label;
148  print '</option>';
149  $i++;
150  }
151  print "</select>";
152  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
153 
154  if ($addjscombo) {
155  print ajax_combobox('select'.$htmlname);
156  }
157  } else {
158  print $langs->trans("NoTypeOfPagePleaseEditDictionary");
159  }
160  } else {
161  dol_print_error($this->db);
162  }
163  }
164 
165 
176  public function selectSampleOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0)
177  {
178  global $langs, $conf, $user;
179 
180  $langs->load("admin");
181 
182  $listofsamples = dol_dir_list(DOL_DOCUMENT_ROOT.'/website/samples', 'files', 0, '^page-sample-.*\.html$');
183 
184  $arrayofsamples = array();
185  $arrayofsamples['empty'] = 'EmptyPage'; // Always this one first
186  foreach ($listofsamples as $sample)
187  {
188  $reg = array();
189  if (preg_match('/^page-sample-(.*)\.html$/', $sample['name'], $reg))
190  {
191  $key = $reg[1];
192  $labelkey = ucfirst($key);
193  if ($key == 'empty') $labelkey = 'EmptyPage';
194  $arrayofsamples[$key] = $labelkey;
195  }
196  }
197 
198  $out = '';
199  $out .= '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer minwidth200" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
200 
201  if ($useempty == 1 || $useempty == 2)
202  {
203  $out .= '<option value="-1">&nbsp;</option>';
204  }
205 
206  foreach ($arrayofsamples as $key => $val)
207  {
208  if ($selected == $key)
209  {
210  $out .= '<option value="'.$key.'" selected>';
211  } else {
212  $out .= '<option value="'.$key.'">';
213  }
214  $out .= $langs->trans($val);
215  $out .= '</option>';
216  }
217  $out .= "</select>";
218 
219  if ($addjscombo) {
220  $out .= ajax_combobox('select'.$htmlname);
221  }
222 
223  return $out;
224  }
225 
226 
240  public function selectContainer($website, $htmlname = 'pageid', $pageid = 0, $showempty = 0, $action = '', $morecss = 'minwidth200', $excludeids = null)
241  {
242  $this->num = 0;
243 
244  $atleastonepage = (is_array($website->lines) && count($website->lines) > 0);
245 
246  $out = '';
247  if ($atleastonepage && $action != 'editsource')
248  {
249  $out .= '<select name="'.$htmlname.'" id="'.$htmlname.'" class="maxwidth300'.($morecss ? ' '.$morecss : '').'">';
250  } else {
251  $out .= '<select name="pageidbis" id="pageid" class="maxwidth300'.($morecss ? ' '.$morecss : '').'" disabled="disabled">';
252  }
253 
254  if ($showempty || !$atleastonepage) $out .= '<option value="-1">&nbsp;</option>';
255 
256  if ($atleastonepage)
257  {
258  if (empty($pageid) && $action != 'createcontainer') // Page id is not defined, we try to take one
259  {
260  $firstpageid = 0; $homepageid = 0;
261  foreach ($website->lines as $key => $valpage)
262  {
263  if (empty($firstpageid)) $firstpageid = $valpage->id;
264  if ($website->fk_default_home && $key == $website->fk_default_home) $homepageid = $valpage->id;
265  }
266  $pageid = $homepageid ? $homepageid : $firstpageid; // We choose home page and if not defined yet, we take first page
267  }
268 
269  foreach ($website->lines as $key => $valpage)
270  {
271  if (is_array($excludeids) && count($excludeids) && in_array($valpage->id, $excludeids)) continue;
272 
273  $valueforoption = '<span class="opacitymedium">['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).']</span> ';
274  $valueforoption .= $valpage->pageurl.' - '.$valpage->title;
275  if ($website->otherlang) { // If there is alternative lang for this web site, we show the language code
276  if ($valpage->lang) {
277  $valueforoption .= ' <span class="opacitymedium">('.$valpage->lang.')</span>';
278  }
279  }
280  if ($website->fk_default_home && $key == $website->fk_default_home) {
281  //$valueforoption .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
282  $valueforoption .= ' <span class="opacitymedium fa fa-home"></span>';
283  }
284 
285  $out .= '<option value="'.$key.'"';
286  if ($pageid > 0 && $pageid == $key) $out .= ' selected'; // To preselect a value
287  $out .= ' data-html="'.dol_escape_htmltag($valueforoption).'"';
288  $out .= '>';
289  $out .= $valueforoption;
290  $out .= '</option>';
291 
292  ++$this->num;
293  }
294  }
295  $out .= '</select>';
296 
297  if ($atleastonepage && $action != 'editsource')
298  {
299  $out .= ajax_combobox($htmlname);
300  } else {
301  $out .= '<input type="hidden" name="'.$htmlname.'" value="'.$pageid.'">';
302  $out .= ajax_combobox($htmlname);
303  }
304  return $out;
305  }
306 }
selectSampleOfContainer($htmlname, $selected= '', $useempty=0, $moreattrib= '', $addjscombo=0)
Return a HTML select list of samples of containers content.
selectWebsite($selected= '', $htmlname= 'exportmodelid', $useempty=0)
Return HTML select list of websites.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:391
selectTypeOfContainer($htmlname, $selected= '', $useempty=0, $moreattrib= '', $addjscombo=0)
Return a HTML select list of type of containers from the dictionary.
$conf db
API class for accounts.
Definition: inc.php:54
selectContainer($website, $htmlname= 'pageid', $pageid=0, $showempty=0, $action= '', $morecss= 'minwidth200', $excludeids=null)
Return a HTML select list of containers of a website.
__construct($db)
Constructor.
Class to manage component html for module website.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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
$num
var int A number of lines
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.