66 public function selectWebsite($selected =
'', $htmlname =
'exportmodelid', $useempty = 0)
70 $sql =
"SELECT rowid, ref";
71 $sql .=
" FROM ".$this->db->prefix().
"website";
72 $sql .=
" WHERE 1 = 1";
73 $sql .=
" ORDER BY rowid";
74 $result = $this->db->query($sql);
76 $out .=
'<select class="flat minwidth100" name="'.$htmlname.
'" id="'.$htmlname.
'">';
78 $out .=
'<option value="-1"> </option>';
81 $num = $this->db->num_rows($result);
84 $obj = $this->db->fetch_object($result);
85 if ($selected == $obj->rowid) {
86 $out .=
'<option value="'.$obj->rowid.
'" selected>';
88 $out .=
'<option value="'.$obj->rowid.
'">';
96 dol_print_error($this->db);
114 public function selectTypeOfContainer($htmlname, $selected =
'', $useempty = 0, $moreattrib =
'', $addjscombo = 0, $morecss =
'minwidth200')
116 global $langs,
$conf, $user;
118 $langs->load(
"admin");
122 $sql =
"SELECT rowid, code, label, entity, position, typecontainer";
123 $sql .=
" FROM ".$this->db->prefix().
'c_type_container';
124 $sql .=
" WHERE active = 1 AND entity IN (".getEntity(
'c_type_container').
")";
125 $sql .=
" ORDER BY position ASC, typecontainer DESC, label ASC";
127 dol_syslog(get_class($this).
"::selectTypeOfContainer", LOG_DEBUG);
129 $result = $this->db->query($sql);
131 $num = $this->db->num_rows($result);
134 $out .=
'<select id="select'.$htmlname.
'" class="flat selectTypeOfContainer'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'"'.($moreattrib ?
' '.$moreattrib :
'').
'>';
135 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
136 $out .=
'<option value="-1"> </option>';
139 $lasttypecontainer =
'';
143 $arrayofcontainers = array();
145 $arrayofcontainers[] = $this->db->fetch_object($result);
148 usort($arrayofcontainers, array(
'FormWebsite',
'compareTypeOfContainer'));
150 foreach ($arrayofcontainers as $obj) {
157 if ($obj->typecontainer != $lasttypecontainer) {
158 $out .=
'<option value="0" disabled>--- ';
159 $transcodecontainer = ucfirst($obj->typecontainer);
160 if ($transcodecontainer ==
'Library') {
161 $transcodecontainer =
'System';
163 if ($obj->typecontainer ==
'page') {
164 $transcodecontainer =
'CompletePage';
165 } elseif ($obj->typecontainer ==
'container') {
166 $transcodecontainer =
'PortionOfPage';
167 } elseif ($obj->typecontainer ==
'service') {
168 $transcodecontainer =
'ServiceComponent';
170 $out .= $langs->trans($transcodecontainer);
171 $out .=
' ---</option>';
172 $lasttypecontainer = $obj->typecontainer;
175 if ($selected == $obj->rowid || $selected == $obj->code) {
176 $out .=
'<option value="'.$obj->code.
'" selected>';
178 $out .=
'<option value="'.$obj->code.
'">';
180 $out .= $langs->trans($obj->label);
183 $conf->cache[
'type_of_container'][$obj->code] = $obj->label;
187 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
194 $out .= $langs->trans(
"NoTypeOfPagePleaseEditDictionary");
197 $this->error = $this->db->lasterror();
213 $rankofgroup = array(
'page' => 0,
'container' => 1,
'library' => 2);
215 $ga = array_key_exists($a->typecontainer, $rankofgroup) ? $rankofgroup[$a->typecontainer] : 3;
216 $gb = array_key_exists($b->typecontainer, $rankofgroup) ? $rankofgroup[$b->typecontainer] : 3;
220 if ($a->position != $b->position) {
221 return $a->position - $b->position;
223 return strcmp($a->label, $b->label);
237 public function selectSampleOfContainer($htmlname, $selected =
'', $useempty = 0, $moreattrib =
'', $addjscombo = 0, $morecss =
'minwidth200')
239 global $langs, $user;
241 $langs->load(
"admin");
243 $listofsamples =
dol_dir_list(DOL_DOCUMENT_ROOT.
'/website/samples',
'files', 0,
'^page-sample-.*\.html$');
244 $arrayofsamples = array();
245 $arrayofsamples[
'empty'] =
'EmptyPage';
246 foreach ($listofsamples as $sample) {
248 if (preg_match(
'/^page-sample-(.*)\.html$/', $sample[
'name'], $reg)) {
250 $labelkey = ucfirst($key);
251 if ($key ==
'empty') {
252 $labelkey =
'EmptyPage';
254 $arrayofsamples[$key] = $labelkey;
259 $out .=
'<select id="select'.$htmlname.
'" class="selectSampleOfContainer'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'"'.($moreattrib ?
' '.$moreattrib :
'').
'>';
261 if ($useempty == 1 || $useempty == 2) {
262 $out .=
'<option value="-1"> </option>';
265 foreach ($arrayofsamples as $key => $val) {
266 if ($selected == $key) {
267 $out .=
'<option value="'.$key.
'" selected>';
269 $out .=
'<option value="'.$key.
'">';
271 $out .= $langs->trans($val);
297 public function selectContainer($website, $htmlname =
'pageid', $pageid = 0, $showempty = 0, $action =
'', $morecss =
'minwidth200', $excludeids =
null)
299 global
$conf, $langs;
303 $atleastonepage = (is_array($website->lines) && count($website->lines) > 0);
306 if ($atleastonepage && $action !=
'editsource') {
307 $out .=
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="maxwidth300'.($morecss ?
' '.$morecss :
'').
'">';
309 $out .=
'<select name="pageidbis" id="pageid" class="maxwidth300'.($morecss ?
' '.$morecss :
'').
'"'.($action ==
'editsource' ?
' disabled="disabled"' :
'').
'>';
312 if ($showempty || !$atleastonepage) {
313 $out .=
'<option class="optiongrey" value="-1">'.(is_numeric($showempty) ?
' ' : $showempty).
'</option>';
321 if ($atleastonepage) {
322 if (empty($pageid) && $action !=
'createcontainer') {
325 foreach ($website->lines as $key => $valpage) {
326 if (empty($firstpageid)) {
327 $firstpageid = $valpage->id;
329 if ($website->fk_default_home && $key == $website->fk_default_home) {
330 $homepageid = $valpage->id;
333 $pageid = $homepageid ? $homepageid : $firstpageid;
336 foreach ($website->lines as $key => $valpage) {
337 if (is_array($excludeids) && count($excludeids) && in_array($valpage->id, $excludeids)) {
341 $valueforoption =
'<span class="opacitymedium">['.$valpage->type_container.
' '.sprintf(
"%03d", $valpage->id).
']</span> ';
342 $valueforoption .= $valpage->pageurl.
' - '.$valpage->title;
343 if ($website->otherlang) {
344 if ($valpage->lang) {
345 $valueforoption .=
' <span class="opacitymedium">('.$valpage->lang.
')</span>';
348 if ($website->fk_default_home && $key == $website->fk_default_home) {
350 $valueforoption .=
' <span class="opacitymedium fas fa-home"></span>';
353 $out .=
'<option value="'.$key.
'"';
354 if ($pageid > 0 && $pageid == $key) {
357 $out .=
' data-html="'.dol_escape_htmltag($valueforoption).
'"';
359 $out .= $valueforoption;
367 if ($atleastonepage && $action !=
'editsource') {
370 $out .=
'<input type="hidden" name="'.$htmlname.
'" value="'.$pageid.
'">';
386 global $user, $langs;
388 $htmlContent = preg_replace(
'/[^a-z0-9_]/',
'', $htmlContent);
390 require_once DOL_DOCUMENT_ROOT.
'/core/lib/emaillayout.lib.php';
392 $listofsamples =
dol_dir_list(DOL_DOCUMENT_ROOT.
'/website/samples',
'files', 0,
'^page-sample-.*\.html$');
395 $arrayofsamples = array(
396 'empty' =>
'EmptyPage',
399 foreach ($listofsamples as $sample) {
401 if (preg_match(
'/^page-sample-(.*)\.html$/', $sample[
'name'], $reg)) {
403 $labelkey = ucfirst($key);
404 if ($key ==
'empty') {
405 $labelkey =
'EmptyPage';
407 $arrayofsamples[$key] = $labelkey;
410 $out =
'<div id="template-selector" class="template-selector template-container hidden">';
413 unset($arrayofsamples[
'dynamiccontent']);
416 $templates = $arrayofsamples;
418 foreach ($templates as $template => $templateFunction) {
419 $substitutionarray = array();
420 $substitutionarray[
'__WEBSITE_CREATED_BY__'] = $user->getFullName($langs);
421 $substitutionarray[
'__WEBSITE_CONTENT__'] = $langs->trans(
"WebpageContent");
422 $substitutionarray[
'__WEBSITE_TITLE1__'] = $langs->trans(
"Title1");
423 $substitutionarray[
'__WEBSITE_TITLE2__'] = $langs->trans(
"Title2");
425 $pathtoTemplateFile = DOL_DOCUMENT_ROOT.
'/website/samples/page-sample-'.
dol_sanitizeFileName($template).
'.html';
426 $contentHtml = file_exists($pathtoTemplateFile) ?
make_substitutions(@file_get_contents($pathtoTemplateFile), $substitutionarray) :
'';
428 $out .=
'<div class="template-option" data-template="'.$template.
'" data-content="'.htmlentities($contentHtml).
'">';
429 $out .=
'<img class="maillayout" alt="'.$template.
'" src="'.DOL_URL_ROOT.
'/theme/common/maillayout/'.($template ===
'empty' ?
'none' : $template).
'.png" />';
430 $out .=
'<span class="template-option-text">'.($template !=
'text' ? ucfirst($template) : ucfirst($templateFunction)).
'</span>';
433 $out .=
'<input type="hidden" name="sample" value="" />';
436 $out .=
'<!-- Js code to manage choice of a page layout for website -->'.
"\n";
437 $out .=
'<script type="text/javascript">
438 $(document).ready(function() {
439 $(".template-option").click(function() {
440 console.log("We choose a layout for website, we fill the field \''.$htmlContent.
'\'");
442 $(".
template-option
").removeClass("selected
");
443 $(this).addClass("selected
");
445 var template = $(this).data("template");
446 var contentHtml = $(this).data("content
");
448 jQuery("#
'.$htmlContent.'").val(contentHtml);
449 //jQuery("#
'.$htmlContent.'preview
").val(contentHtml);
451 var editorInstance = CKEDITOR.instances.'.$htmlContent.';
452 if (editorInstance) {
453 editorInstance.setData(contentHtml);
455 //var editorInstance = CKEDITOR.instances.'.$htmlContent.'preview;
456 //if (editorInstance) {
457 // editorInstance.setData(contentHtml);
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_dir_list($utf8_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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.