dolibarr 19.0.3
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 $langs->trans($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 global $conf, $langs;
235
236 $this->num = 0;
237
238 $atleastonepage = (is_array($website->lines) && count($website->lines) > 0);
239
240 $out = '';
241 if ($atleastonepage && $action != 'editsource') {
242 $out .= '<select name="'.$htmlname.'" id="'.$htmlname.'" class="maxwidth300'.($morecss ? ' '.$morecss : '').'">';
243 } else {
244 $out .= '<select name="pageidbis" id="pageid" class="maxwidth300'.($morecss ? ' '.$morecss : '').'"'.($action == 'editsource' ? ' disabled="disabled"' : '').'>';
245 }
246
247 if ($showempty || !$atleastonepage) {
248 $out .= '<option class="optiongrey" value="-1">'.(is_numeric($showempty) ? '&nbsp;' : $showempty).'</option>';
249 }
250
251 /*if (!empty($conf->use_javascript_ajax)) {
252 $valueoption = '<span class="classlink">'.img_picto('', 'add', 'class="paddingrightonly"').$langs->trans("AddPage").'</span>';
253 $out .= '<option value="-2" data-html="'.dol_escape_htmltag($valueoption).'">'.$valueoption.'</option>';
254 }*/
255
256 if ($atleastonepage) {
257 if (empty($pageid) && $action != 'createcontainer') { // Page id is not defined, we try to take one
258 $firstpageid = 0;
259 $homepageid = 0;
260 foreach ($website->lines as $key => $valpage) {
261 if (empty($firstpageid)) {
262 $firstpageid = $valpage->id;
263 }
264 if ($website->fk_default_home && $key == $website->fk_default_home) {
265 $homepageid = $valpage->id;
266 }
267 }
268 $pageid = $homepageid ? $homepageid : $firstpageid; // We choose home page and if not defined yet, we take first page
269 }
270
271 foreach ($website->lines as $key => $valpage) {
272 if (is_array($excludeids) && count($excludeids) && in_array($valpage->id, $excludeids)) {
273 continue;
274 }
275
276 $valueforoption = '<span class="opacitymedium">['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).']</span> ';
277 $valueforoption .= $valpage->pageurl.' - '.$valpage->title;
278 if ($website->otherlang) { // If there is alternative lang for this web site, we show the language code
279 if ($valpage->lang) {
280 $valueforoption .= ' <span class="opacitymedium">('.$valpage->lang.')</span>';
281 }
282 }
283 if ($website->fk_default_home && $key == $website->fk_default_home) {
284 //$valueforoption .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
285 $valueforoption .= ' <span class="opacitymedium fas fa-home"></span>';
286 }
287
288 $out .= '<option value="'.$key.'"';
289 if ($pageid > 0 && $pageid == $key) {
290 $out .= ' selected'; // To preselect a value
291 }
292 $out .= ' data-html="'.dol_escape_htmltag($valueforoption).'"';
293 $out .= '>';
294 $out .= $valueforoption;
295 $out .= '</option>';
296
297 ++$this->num;
298 }
299 }
300 $out .= '</select>';
301
302 if ($atleastonepage && $action != 'editsource') {
303 $out .= ajax_combobox($htmlname);
304 } else {
305 $out .= '<input type="hidden" name="'.$htmlname.'" value="'.$pageid.'">';
306 $out .= ajax_combobox($htmlname);
307 }
308 return $out;
309 }
310}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:455
Class to manage component html for module website.
selectContainer($website, $htmlname='pageid', $pageid=0, $showempty=0, $action='', $morecss='minwidth200', $excludeids=null)
Return a HTML select list of containers of a website.
selectWebsite($selected='', $htmlname='exportmodelid', $useempty=0)
Return HTML select list of websites.
selectTypeOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='', $addjscombo=0, $morecss='minwidth200')
Return a HTML select list of type of containers from the dictionary.
__construct($db)
Constructor.
selectSampleOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='', $addjscombo=0, $morecss='minwidth200')
Return a HTML select list of samples of containers content.
$num
var int A number of lines
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.