dolibarr 21.0.0-alpha
html.formcardwebportal.class.php
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
28require_once DOL_DOCUMENT_ROOT . '/webportal/class/html.formwebportal.class.php';
29
36{
40 public $action = '';
41
45 public $backtopage = '';
46
50 public $backtopageforcancel = '';
51
55 public $backtopagejsfields = '';
56
60 public $cancel = '';
61
65 public $db;
66
70 public $elementEn = '';
71
75 public $form;
76
80 public $id;
81
85 public $object;
86
90 public $permissiontoread = 0;
91
95 public $permissiontoadd = 0;
96
100 public $permissiontodelete = 0;
101
105 public $permissionnote = 0;
106
110 public $permissiondellink = 0;
111
115 public $ref;
116
120 public $titleKey = '';
121
125 public $titleDescKey = '';
126
132 public function __construct($db)
133 {
134 $this->db = $db;
135 $this->form = new FormWebPortal($this->db);
136 }
137
150 public function init($elementEn, $id = 0, $permissiontoread = 0, $permissiontoadd = 0, $permissiontodelete = 0, $permissionnote = 0, $permissiondellink = 0)
151 {
152 global $hookmanager, $langs;
153
154 $elementEnUpper = strtoupper($elementEn);
155 $objectclass = 'WebPortal' . ucfirst($elementEn);
156
157 $elementCardAccess = getDolGlobalString('WEBPORTAL_' . $elementEnUpper . '_CARD_ACCESS', 'hidden');
158 if ($elementCardAccess == 'hidden' || $id <= 0) {
160 }
161
162 // load module libraries
163 dol_include_once('/webportal/class/webportal' . $elementEn . '.class.php');
164
165 // Load translation files required by the page
166 $langs->loadLangs(array('website', 'other'));
167
168 // Get parameters
169 //$id = $id > 0 ? $id : GETPOST('id', 'int');
170 $ref = GETPOST('ref', 'alpha');
171 $action = GETPOST('action', 'aZ09');
172 $confirm = GETPOST('confirm', 'alpha');
173 $cancel = GETPOST('cancel', 'aZ09');
174 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'webportal' . $elementEn . 'card'; // To manage different context of search
175 $backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
176 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
177 $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
178
179 // Initialize a technical objects
180 $object = new $objectclass($this->db);
181 //$extrafields = new ExtraFields($db);
182 $hookmanager->initHooks(array('webportal' . $elementEn . 'card', 'globalcard')); // Note that conf->hooks_modules contains array
183
184 // Fetch optionals attributes and labels
185 //$extrafields->fetch_name_optionals_label($object->table_element);
186 //$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
187
188 if (empty($action) && empty($id) && empty($ref)) {
189 $action = 'view';
190 }
191
192 // Load object
193 include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
194
195 // Security check (enable the most restrictive one)
196 if (!isModEnabled('webportal')) {
198 }
199 if (!$permissiontoread) {
201 }
202
203 // set form card
204 $this->action = $action;
205 $this->backtopage = $backtopage;
206 $this->backtopageforcancel = $backtopageforcancel;
207 $this->backtopagejsfields = $backtopagejsfields;
208 $this->cancel = $cancel;
209 $this->elementEn = $elementEn;
210 $this->id = $id;
211 $this->object = $object;
212 $this->permissiontoread = $permissiontoread;
213 $this->permissiontoadd = $permissiontoadd;
214 $this->permissiontodelete = $permissiontodelete;
215 $this->permissionnote = $permissionnote;
216 $this->permissiondellink = $permissiondellink;
217 $this->titleKey = $objectclass . 'CardTitle';
218 $this->ref = $ref;
219 }
220
226 public function doActions()
227 {
228 global $langs;
229
230 // initialize
231 $action = $this->action;
232 $backtopage = $this->backtopage;
233 $backtopageforcancel = $this->backtopageforcancel;
234 $cancel = $this->cancel;
235 $elementEn = $this->elementEn;
236 $id = $this->id;
237 $object = $this->object;
238 //$permissiontoread = $this->permissiontoread;
239 $permissiontoadd = $this->permissiontoadd;
240
241 $error = 0;
242
243 $context = Context::getInstance();
244
245 $backurlforlist = $context->getControllerUrl('default');
246 $noback = 1;
247
248 if (empty($backtopage) || ($cancel && empty($id))) {
249 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
250 $backtopage = $context->getControllerUrl($elementEn . 'card');
251 }
252 }
253
254 // Action to cancel record
255 if ($cancel) {
256 if (!empty($backtopageforcancel)) {
257 header("Location: " . $backtopageforcancel);
258 exit;
259 } elseif (!empty($backtopage)) {
260 header("Location: " . $backtopage);
261 exit;
262 }
263 $action = '';
264 }
265
266 // Action to update record
267 if ($action == 'update' && !empty($permissiontoadd)) {
268 foreach ($object->fields as $key => $val) {
269 // Check if field was submitted to be edited
270 if ($object->fields[$key]['type'] == 'duration') {
271 if (!GETPOSTISSET($key . 'hour') || !GETPOSTISSET($key . 'min')) {
272 continue; // The field was not submitted to be saved
273 }
274 } elseif ($object->fields[$key]['type'] == 'boolean') {
275 if (!GETPOSTISSET($key)) {
276 $object->$key = 0; // use 0 instead null if the field is defined as not null
277 continue;
278 }
279 } else {
280 if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type']) && $object->fields[$key]['type'] !== 'checkbox') {
281 continue; // The field was not submitted to be saved
282 }
283 }
284 // Ignore special fields
285 if (in_array($key, array('rowid', 'entity', 'import_key'))) {
286 continue;
287 }
288 if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
289 if (!in_array(abs($val['visible']), array(1, 3, 4))) {
290 continue; // Only 1 and 3 and 4, that are cases to update
291 }
292 }
293
294 // Set value to update
295 if (preg_match('/^text/', $object->fields[$key]['type'])) {
296 $tmparray = explode(':', $object->fields[$key]['type']);
297 if (!empty($tmparray[1])) {
298 $value = GETPOST($key, $tmparray[1]);
299 } else {
300 $value = GETPOST($key, 'nohtml');
301 }
302 } elseif (preg_match('/^html/', $object->fields[$key]['type'])) {
303 $tmparray = explode(':', $object->fields[$key]['type']);
304 if (!empty($tmparray[1])) {
305 $value = GETPOST($key, $tmparray[1]);
306 } else {
307 $value = GETPOST($key, 'restricthtml');
308 }
309 } elseif (in_array($object->fields[$key]['type'], array('date', 'datetime'))) {
310 $postDate = GETPOST($key, 'alphanohtml');
311 // extract date YYYY-MM-DD for year, month and day
312 $dateArr = explode('-', $postDate);
313 $dateYear = 0;
314 $dateMonth = 0;
315 $dateDay = 0;
316 if (count($dateArr) == 3) {
317 $dateYear = (int) $dateArr[0];
318 $dateMonth = (int) $dateArr[1];
319 $dateDay = (int) $dateArr[2];
320 }
321 // extract time HH:ii:ss for hours, minutes and seconds
322 $postTime = GETPOST($key . '_time', 'alphanohtml');
323 $timeArr = explode(':', $postTime);
324 $timeHours = 12;
325 $timeMinutes = 0;
326 $timeSeconds = 0;
327 if (!empty($timeArr)) {
328 if (isset($timeArr[0])) {
329 $timeHours = (int) $timeArr[0];
330 }
331 if (isset($timeArr[1])) {
332 $timeMinutes = (int) $timeArr[1];
333 }
334 if (isset($timeArr[2])) {
335 $timeSeconds = (int) $timeArr[2];
336 }
337 }
338 $value = dol_mktime($timeHours, $timeMinutes, $timeSeconds, $dateMonth, $dateDay, $dateYear);
339 } elseif ($object->fields[$key]['type'] == 'duration') {
340 if (GETPOSTINT($key . 'hour') != '' || GETPOSTINT($key . 'min') != '') {
341 $value = 60 * 60 * GETPOSTINT($key . 'hour') + 60 * GETPOSTINT($key . 'min');
342 } else {
343 $value = '';
344 }
345 } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
346 $value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
347 } elseif ($object->fields[$key]['type'] == 'boolean') {
348 $value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
349 //}
350 //elseif ($object->fields[$key]['type'] == 'reference') {
351 // $value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
352 } elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') {
353 $value = '';
354 $values_arr = GETPOST($key, 'array');
355 if (!empty($values_arr)) {
356 $value = implode(',', $values_arr);
357 }
358 } else {
359 if ($key == 'lang') {
360 $value = GETPOST($key, 'aZ09');
361 } else {
362 $value = GETPOST($key, 'alphanohtml');
363 }
364 }
365 if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
366 $value = ''; // This is an implicit foreign key field
367 }
368 if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
369 $value = ''; // This is an explicit foreign key field
370 }
371
372 $object->$key = $value;
373 if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) {
374 $error++;
375 $context->setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
376 }
377
378 // Validation of fields values
379 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) {
380 if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
381 if (!$object->validateField($object->fields, $key, $value)) {
382 $error++;
383 }
384 }
385 }
386
387 if (isModEnabled('category')) {
388 $categories = GETPOST('categories', 'array');
389 if (method_exists($object, 'setCategories')) {
390 $object->setCategories($categories);
391 }
392 }
393 }
394
395 // Fill array 'array_options' with data from add form
396 //if (!$error) {
397 // $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
398 // if ($ret < 0) {
399 // $error++;
400 // }
401 //}
402
403 if (!$error) {
404 $result = $object->update($context->logged_user);
405 if ($result >= 0) {
406 $action = 'view';
407 $urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
408 $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', (string) $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
409 if ($urltogo && empty($noback)) {
410 header("Location: " . $urltogo);
411 exit;
412 }
413 } else {
414 $error++;
415 // Creation KO
416 $context->setEventMessages($object->error, $object->errors, 'errors');
417 $action = 'edit';
418 }
419 } else {
420 $action = 'edit';
421 }
422 }
423
424 $this->object = $object;
425 $this->action = $action;
426 }
427
434 protected function header($context)
435 {
436 global $langs;
437
438 $html = '';
439
440 // initialize
441 $object = $this->object;
442 $addgendertxt = '';
443 //if (property_exists($object, 'gender') && !empty($object->gender)) {
444 // switch ($object->gender) {
445 // case 'man':
446 // $addgendertxt .= '<i class="fas fa-mars"></i>';
447 // break;
448 // case 'woman':
449 // $addgendertxt .= '<i class="fas fa-venus"></i>';
450 // break;
451 // case 'other':
452 // $addgendertxt .= '<i class="fas fa-transgender"></i>';
453 // break;
454 // }
455 //}
456
457 $html .= '<!-- html.formcardwebportal.class.php -->';
458 $html .= '<header>';
459
460 // Left block - begin
461 $html .= '<div class="header-card-left-block inline-block" style="width: 75%;">';
462 $html .= '<div>';
463
464 // logo or photo
465 $form = new Form($this->db);
466 $html .= '<div class="inline-block floatleft valignmiddle">';
467 $html .= '<div class="floatleft inline-block valignmiddle divphotoref">';
468 $html .= $form->showphoto('memberphoto', $object, 0, 0, 0, 'photowithmargin photoref', 'small', 1, 0, 1);
469 //include DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
470 //$html .= getImagePublicURLOfObject($object, 1, '_small');
471 $html .= '</div>';
472 $html .= '</div>';
473
474 // main information - begin
475 $html .= '<div class="header-card-main-information inline-block valignmiddle">';
476 // ref
477 $html .= '<div><strong>' . $langs->trans("Ref").' : '.dol_escape_htmltag($object->ref) . '</strong></div>';
478 // full name
479 $fullname = '';
480 if (method_exists($object, 'getFullName')) {
481 $fullname = $object->getFullName($langs);
482 }
483 $html .= '<div><strong>';
484 if ($object->element == 'member') {
485 if ($object->morphy == 'mor' && !empty($object->societe)) {
486 $html .= dol_htmlentities($object->societe);
487 $html .= (!empty($fullname) && $object->societe != $fullname) ? ' (' . dol_htmlentities($fullname) . $addgendertxt . ')' : '';
488 } else {
489 $html .= dol_htmlentities($fullname) . $addgendertxt;
490 if (empty($object->fk_soc)) {
491 $html .= (!empty($object->societe) && $object->societe != $fullname) ? ' (' . dol_htmlentities($object->societe) . ')' : '';
492 }
493 }
494 } else {
495 $html .= dol_htmlentities(!empty($object->ref) ? $object->ref : '');
496 }
497 $html .= '</strong></div>';
498 // address
499 if (method_exists($object, 'getBannerAddressForWebPortal')) {
500 $moreaddress = $object->getBannerAddressForWebPortal('refaddress');
501 if ($moreaddress) {
502 $html .= '<div class="refidno refaddress">';
503 $html .= $moreaddress;
504 $html .= '</div>';
505 }
506 }
507 $html .= '</div>';
508 // main information - end
509
510 $html .= '</div>';
511 $html .= '</div>';
512 // Left block - end
513
514 // Right block - begin
515 $html .= '<div class="header-card-right-block inline-block" style="width: 24%;">';
516 // show status
517 $htmlStatus = $object->getLibStatut(6);
518 if (empty($htmlStatus) || $htmlStatus == $object->getLibStatut(3)) {
519 $htmlStatus = $object->getLibStatut(5);
520 }
521 $html .= $htmlStatus;
522 $html .= '</div>';
523 // Right block - end
524
525 $html .= '</header>';
526
527 return $html;
528 }
529
535 protected function bodyView($keyforbreak = '')
536 {
537 global $langs;
538
539 $html = '';
540
541 // initialize
542 $object = $this->object;
543
544 $object->fields = dol_sort_array($object->fields, 'position');
545
546 // separate fields to show on the left and on the right
547 $fieldShowList = array();
548 foreach ($object->fields as $key => $val) {
549 // discard if it's a hidden field on form
550 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
551 continue;
552 }
553
554 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
555 continue; // we don't want this field
556 }
557
558 if (!empty($val['showonheader'])) {
559 continue; // already on header
560 }
561
562 $fieldShowList[$key] = $val;
563 }
564
565 $nbFieldShow = count($fieldShowList);
566 $lastKeyFieldLeft = $keyforbreak;
567 $lastNumFieldLeft = 0;
568 if ($lastKeyFieldLeft == '') {
569 $lastNumFieldLeft = ceil($nbFieldShow / 2);
570 }
571 $numField = 0;
572 $html .= '<div class="grid">';
573 $html .= '<div class="card-left">';
574 foreach ($object->fields as $key => $val) {
575 if (!array_key_exists($key, $fieldShowList)) {
576 continue; // not to show
577 }
578
579 $value = $object->$key;
580
581 $html .= '<div class="grid field_' . $key . '">';
582
583 $html .= '<div class="' . (empty($val['tdcss']) ? '' : $val['tdcss']) . ' fieldname_' . $key;
584 $html .= '">';
585 $labeltoshow = '';
586 $labeltoshow .= '<strong>' . $langs->trans($val['label']) . '</strong>';
587 $html .= $labeltoshow;
588 $html .= '</div>';
589
590 $html .= '<div class="valuefield fieldname_' . $key;
591 if (!empty($val['cssview'])) {
592 $html .= ' ' . $val['cssview'];
593 }
594 $html .= '">';
595 if ($key == 'lang') {
596 $langs->load('languages');
597 $labellang = ($value ? $langs->trans('Language_' . $value) : '');
598 //$html .= picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
599 $html .= $labellang;
600 } else {
601 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value, '', '', '', 0);
602 }
603 $html .= '</div>';
604
605 $html .= '</div>';
606
607 $numField++;
608
609 // fields on the right
610 $cardRight = false;
611 if ($keyforbreak != '') {
612 if ($key == $keyforbreak) {
613 $cardRight = true;
614 }
615 } else {
616 if ($numField == $lastNumFieldLeft) {
617 $cardRight = true;
618 }
619 }
620 if ($cardRight) {
621 $html .= '</div>';
622 $html .= '<div class="card-right">';
623 }
624 }
625 $html .= '</div>';
626 $html .= '</div>';
627
628 return $html;
629 }
630
636 protected function bodyEdit()
637 {
638 global $langs;
639
640 $html = '';
641
642 // initialize
643 $object = $this->object;
644
645 $object->fields = dol_sort_array($object->fields, 'position');
646
647 foreach ($object->fields as $key => $val) {
648 // Discard if filed is a hidden field on form
649 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) {
650 continue;
651 }
652
653 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
654 continue; // We don't want this field
655 }
656
657 $html .= '<div class="grid field_' . $key . '">';
658 $html .= '<div class="titlefieldcreate';
659 if (isset($val['notnull']) && $val['notnull'] > 0) {
660 $html .= ' required';
661 }
662 $html .= '">';
663 $html .= $langs->trans($val['label']);
664 $html .= '</div>';
665
666 $html .= '<div class="valuefieldcreate">';
667 if (in_array($val['type'], array('int', 'integer'))) {
668 $value = GETPOSTISSET($key) ? GETPOSTINT($key) : $object->$key;
669 } elseif ($val['type'] == 'double') {
670 $value = GETPOSTISSET($key) ? price2num(GETPOST($key, 'alphanohtml')) : $object->$key;
671 } elseif (preg_match('/^text/', $val['type'])) {
672 $tmparray = explode(':', $val['type']);
673 if (!empty($tmparray[1])) {
674 $check = $tmparray[1];
675 } else {
676 $check = 'nohtml';
677 }
678 $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
679 } elseif (preg_match('/^html/', $val['type'])) {
680 $tmparray = explode(':', $val['type']);
681 if (!empty($tmparray[1])) {
682 $check = $tmparray[1];
683 } else {
684 $check = 'restricthtml';
685 }
686 $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
687 } elseif (in_array($val['type'], array('date', 'datetime'))) {
688 $isPostDate = GETPOSTISSET($key);
689 $isPostTime = GETPOSTISSET($key . '_time');
690 if ($isPostDate) {
691 $postDate = GETPOST($key, 'alphanohtml');
692 if ($isPostTime) {
693 $postTime = GETPOST($key . '_time', 'alphanohtml') . ':00';
694 } else {
695 $postTime = '00:00:00';
696 }
697 $valueDateTimeStr = $postDate . ' ' . $postTime;
698 } else {
699 // format date timestamp to YYYY-MM-DD HH:ii:ss
700 $valueDateTimeStr = dol_print_date($object->$key, '%Y-%m-%d %H:%M:%S');
701 }
702
703 $value = $valueDateTimeStr;
704 } elseif ($val['type'] == 'price') {
705 $value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key);
706 } elseif ($key == 'lang') {
707 $value = GETPOSTISSET($key) ? GETPOST($key, 'aZ09') : $object->lang;
708 } else {
709 $value = GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : $object->$key;
710 }
711
712 if (!empty($val['noteditable'])) {
713 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value, '', '', '', 0);
714 } else {
715 $html .= $this->form->showInputField($val, $key, $value, '', '', '', '');
716 }
717 $html .= '</div>';
718 $html .= '</div>';
719 }
720
721 return $html;
722 }
723
729 protected function footer()
730 {
731 $html = '';
732 $html .= '<footer>';
733 $html .= '</footer>';
734
735 return $html;
736 }
737
744 public function elementCard($context)
745 {
746 global $hookmanager, $langs;
747
748 $html = '<!-- elementCard -->';
749
750 // initialize
751 $action = $this->action;
752 $backtopage = $this->backtopage;
753 $backtopageforcancel = $this->backtopageforcancel;
754 //$backtopagejsfields = $this->backtopagejsfields;
755 //$elementEn = $this->elementEn;
756 $id = $this->id;
757 $object = $this->object;
758 //$permissiontoread = $this->permissiontoread;
759 $permissiontoadd = $this->permissiontoadd;
760 $ref = $this->ref;
761 $titleKey = $this->titleKey;
762 $title = $langs->trans($titleKey);
763
764 // Part to edit record
765 if (($id || $ref) && $action == 'edit') {
766 $html .= '<article>';
767 //$html .= load_fiche_titre($title, '', 'object_'.$object->picto);
768 $html .= '<header>';
769 $html .= '<h2>' . $title . '</h2>';
770 $html .= '</header>';
771
772 $url_file = $context->getControllerUrl($context->controller, '', false);
773 $html .= '<form method="POST" action="' . $url_file . '">';
774 $html .= $context->getFormToken();
775 $html .= '<input type="hidden" name="action" value="update">';
776 $html .= '<input type="hidden" name="id" value="' . $object->id . '">';
777 if ($backtopage) {
778 $html .= '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
779 }
780 if ($backtopageforcancel) {
781 $html .= '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
782 }
783
784 //$html .= '<table>'."\n";
785 // Common attributes
786 //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
787 $html .= $this->bodyEdit();
788
789 // Other attributes
790 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
791 //$html .= '</table>';
792
793 // Save and Cancel buttons
794 $html .= '<div class="grid">';
795 $html .= '<div><input type="submit" name="save" role="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '" /></div>';
796 $html .= '<div><input type="submit" name="cancel" role="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '" /></div>';
797 $html .= '</div>';
798
799 $html .= '</form>';
800 $html .= '</article>';
801 }
802
803 // Part to show record
804 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
805 $html .= '<article>';
806
807 $formconfirm = '';
808
809 // Call Hook formConfirm
810 $parameters = array('formConfirm' => $formconfirm);
811 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
812 if (empty($reshook)) {
813 $formconfirm .= $hookmanager->resPrint;
814 } elseif ($reshook > 0) {
815 $formconfirm = $hookmanager->resPrint;
816 }
817
818 // Print form confirm
819 $html .= $formconfirm;
820
821 // Object card
822 // ------------------------------------------------------------
823 $html .= $this->header($context);
824
825 // Common attributes
826 $keyforbreak = '';
827 $html .= $this->bodyView($keyforbreak);
828
829 // Other attributes. Fields from hook formObjectOptions and Extrafields.
830 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
831
832 //$html .= $this->footer();
833 $html .= '</article>';
834
835 // Buttons for actions
836 if ($action != 'presend' && $action != 'editline') {
837 $html .= '<div>' . "\n";
838 $parameters = array();
839 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
840 if ($reshook < 0) {
841 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
842 }
843
844 if (empty($reshook)) {
845 if ($permissiontoadd) {
846 $url_file = $context->getControllerUrl($context->controller, '', false);
847 $html .= '<a href="' . $url_file . '&id=' . $object->id . '&action=edit" role="button">' . $langs->trans('Modify') . '</a>';
848 }
849 }
850 $html .= '</div>' . "\n";
851 }
852 }
853
854 return $html;
855 }
856}
$object ref
Definition info.php:79
static getInstance()
Singleton method to create one instance of this object.
Class to manage generation of HTML components Only common components for WebPortal must be here.
header($context)
Html for header.
elementCard($context)
Card for an element in the page context.
bodyEdit()
Html for body (edit mode)
init($elementEn, $id=0, $permissiontoread=0, $permissiontoadd=0, $permissiontodelete=0, $permissionnote=0, $permissiondellink=0)
Init.
bodyView($keyforbreak='')
Html for body (view mode)
Class to manage generation of HTML components Only common components must be here.
Class to manage generation of HTML components Only common components for WebPortal must be here.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.