28require_once DOL_DOCUMENT_ROOT .
'/webportal/class/html.formwebportal.class.php';
45 public $backtopage =
'';
50 public $backtopageforcancel =
'';
55 public $backtopagejsfields =
'';
70 public $elementEn =
'';
90 public $permissiontoread = 0;
95 public $permissiontoadd = 0;
100 public $permissiontodelete = 0;
105 public $permissionnote = 0;
110 public $permissiondellink = 0;
120 public $titleKey =
'';
125 public $titleDescKey =
'';
150 public function init($elementEn, $id = 0, $permissiontoread = 0, $permissiontoadd = 0, $permissiontodelete = 0, $permissionnote = 0, $permissiondellink = 0)
152 global $hookmanager, $langs;
154 $elementEnUpper = strtoupper($elementEn);
155 $objectclass =
'WebPortal' . ucfirst($elementEn);
157 $elementCardAccess =
getDolGlobalString(
'WEBPORTAL_' . $elementEnUpper .
'_CARD_ACCESS',
'hidden');
158 if ($elementCardAccess ==
'hidden' || $id <= 0) {
166 $langs->loadLangs(array(
'website',
'other'));
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';
175 $backtopage =
GETPOST(
'backtopage',
'alpha');
176 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
177 $backtopagejsfields =
GETPOST(
'backtopagejsfields',
'alpha');
180 $object =
new $objectclass($this->db);
182 $hookmanager->initHooks(array(
'webportal' . $elementEn .
'card',
'globalcard'));
188 if (empty($action) && empty($id) && empty($ref)) {
193 include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
196 if (!isModEnabled(
'webportal')) {
199 if (!$permissiontoread) {
204 $this->action = $action;
205 $this->backtopage = $backtopage;
206 $this->backtopageforcancel = $backtopageforcancel;
207 $this->backtopagejsfields = $backtopagejsfields;
208 $this->cancel = $cancel;
209 $this->elementEn = $elementEn;
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';
231 $action = $this->action;
232 $backtopage = $this->backtopage;
233 $backtopageforcancel = $this->backtopageforcancel;
234 $cancel = $this->cancel;
235 $elementEn = $this->elementEn;
237 $object = $this->object;
239 $permissiontoadd = $this->permissiontoadd;
245 $backurlforlist =
$context->getControllerUrl(
'default');
248 if (empty($backtopage) || ($cancel && empty($id))) {
249 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
250 $backtopage =
$context->getControllerUrl($elementEn .
'card');
256 if (!empty($backtopageforcancel)) {
257 header(
"Location: " . $backtopageforcancel);
259 } elseif (!empty($backtopage)) {
260 header(
"Location: " . $backtopage);
267 if ($action ==
'update' && !empty($permissiontoadd)) {
268 foreach ($object->fields as $key => $val) {
270 if ($object->fields[$key][
'type'] ==
'duration') {
271 if (!GETPOSTISSET($key .
'hour') || !GETPOSTISSET($key .
'min')) {
274 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
275 if (!GETPOSTISSET($key)) {
280 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) && $object->fields[$key][
'type'] !==
'checkbox') {
285 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
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))) {
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]);
300 $value =
GETPOST($key,
'nohtml');
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]);
307 $value =
GETPOST($key,
'restricthtml');
309 } elseif (in_array($object->fields[$key][
'type'], array(
'date',
'datetime'))) {
310 $postDate =
GETPOST($key,
'alphanohtml');
312 $dateArr = explode(
'-', $postDate);
316 if (count($dateArr) == 3) {
317 $dateYear = (int) $dateArr[0];
318 $dateMonth = (int) $dateArr[1];
319 $dateDay = (int) $dateArr[2];
322 $postTime =
GETPOST($key .
'_time',
'alphanohtml');
323 $timeArr = explode(
':', $postTime);
327 if (!empty($timeArr)) {
328 if (isset($timeArr[0])) {
329 $timeHours = (int) $timeArr[0];
331 if (isset($timeArr[1])) {
332 $timeMinutes = (int) $timeArr[1];
334 if (isset($timeArr[2])) {
335 $timeSeconds = (int) $timeArr[2];
338 $value =
dol_mktime($timeHours, $timeMinutes, $timeSeconds, $dateMonth, $dateDay, $dateYear);
339 } elseif ($object->fields[$key][
'type'] ==
'duration') {
345 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
347 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
348 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
352 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) || $object->fields[$key][
'type'] ==
'checkbox') {
354 $values_arr =
GETPOST($key,
'array');
355 if (!empty($values_arr)) {
356 $value = implode(
',', $values_arr);
359 if ($key ==
'lang') {
360 $value =
GETPOST($key,
'aZ09');
362 $value =
GETPOST($key,
'alphanohtml');
365 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
368 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
372 $object->$key = $value;
373 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
375 $context->setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
380 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
381 if (!$object->validateField($object->fields, $key, $value)) {
387 if (isModEnabled(
'category')) {
388 $categories =
GETPOST(
'categories',
'array');
389 if (method_exists($object,
'setCategories')) {
390 $object->setCategories($categories);
404 $result = $object->update(
$context->logged_user);
407 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
408 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string) $object->id, $urltogo);
409 if ($urltogo && empty($noback)) {
410 header(
"Location: " . $urltogo);
416 $context->setEventMessages($object->error, $object->errors,
'errors');
424 $this->
object = $object;
425 $this->action = $action;
441 $object = $this->object;
457 $html .=
'<!-- html.formcardwebportal.class.php -->';
461 $html .=
'<div class="header-card-left-block inline-block" style="width: 75%;">';
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);
475 $html .=
'<div class="header-card-main-information inline-block valignmiddle">';
477 $html .=
'<div><strong>' . $langs->trans(
"Ref").
' : '.
dol_escape_htmltag($object->ref) .
'</strong></div>';
480 if (method_exists($object,
'getFullName')) {
481 $fullname = $object->getFullName($langs);
483 $html .=
'<div><strong>';
484 if ($object->element ==
'member') {
485 '@phan-var-force Adherent $object';
486 if ($object->morphy ==
'mor' && !empty($object->societe)) {
488 $html .= (!empty($fullname) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'';
491 if (empty($object->fk_soc)) {
492 $html .= (!empty($object->societe) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($object->societe) .
')' :
'';
498 $html .=
'</strong></div>';
500 if (method_exists($object,
'getBannerAddressForWebPortal')) {
501 $moreaddress = $object->getBannerAddressForWebPortal(
'refaddress');
503 $html .=
'<div class="refidno refaddress">';
504 $html .= $moreaddress;
516 $html .=
'<div class="header-card-right-block inline-block" style="width: 24%;">';
518 $htmlStatus = $object->getLibStatut(6);
519 if (empty($htmlStatus) || $htmlStatus == $object->getLibStatut(3)) {
520 $htmlStatus = $object->getLibStatut(5);
522 $html .= $htmlStatus;
526 $html .=
'</header>';
543 $object = $this->object;
548 $fieldShowList = array();
549 foreach ($object->fields as $key => $val) {
551 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4 && abs($val[
'visible']) != 5) {
555 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
559 if (!empty($val[
'showonheader'])) {
563 $fieldShowList[$key] = $val;
566 $nbFieldShow = count($fieldShowList);
567 $lastKeyFieldLeft = $keyforbreak;
568 $lastNumFieldLeft = 0;
569 if ($lastKeyFieldLeft ==
'') {
570 $lastNumFieldLeft = ceil($nbFieldShow / 2);
573 $html .=
'<div class="grid">';
574 $html .=
'<div class="card-left">';
575 foreach ($object->fields as $key => $val) {
576 if (!array_key_exists($key, $fieldShowList)) {
580 $value = $object->$key;
582 $html .=
'<div class="grid field_' . $key .
'">';
584 $html .=
'<div class="' . (empty($val[
'tdcss']) ?
'' : $val[
'tdcss']) .
' fieldname_' . $key;
587 $labeltoshow .=
'<strong>' . $langs->trans($val[
'label']) .
'</strong>';
588 $html .= $labeltoshow;
591 $html .=
'<div class="valuefield fieldname_' . $key;
592 if (!empty($val[
'cssview'])) {
593 $html .=
' ' . $val[
'cssview'];
596 if ($key ==
'lang') {
597 $langs->load(
'languages');
598 $labellang = ($value ? $langs->trans(
'Language_' . $value) :
'');
602 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
612 if ($keyforbreak !=
'') {
613 if ($key == $keyforbreak) {
617 if ($numField == $lastNumFieldLeft) {
623 $html .=
'<div class="card-right">';
644 $object = $this->object;
648 foreach ($object->fields as $key => $val) {
650 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4) {
654 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
658 $html .=
'<div class="grid field_' . $key .
'">';
659 $html .=
'<div class="titlefieldcreate';
660 if (isset($val[
'notnull']) && $val[
'notnull'] > 0) {
661 $html .=
' required';
664 $html .= $langs->trans($val[
'label']);
667 $html .=
'<div class="valuefieldcreate">';
668 if (in_array($val[
'type'], array(
'int',
'integer'))) {
669 $value = GETPOSTISSET($key) ?
GETPOSTINT($key) : $object->$key;
670 } elseif ($val[
'type'] ==
'double') {
671 $value = GETPOSTISSET($key) ?
price2num(
GETPOST($key,
'alphanohtml')) : $object->$key;
672 } elseif (preg_match(
'/^text/', $val[
'type'])) {
673 $tmparray = explode(
':', $val[
'type']);
674 if (!empty($tmparray[1])) {
675 $check = $tmparray[1];
679 $value = GETPOSTISSET($key) ?
GETPOST($key, $check) : $object->$key;
680 } elseif (preg_match(
'/^html/', $val[
'type'])) {
681 $tmparray = explode(
':', $val[
'type']);
682 if (!empty($tmparray[1])) {
683 $check = $tmparray[1];
685 $check =
'restricthtml';
687 $value = GETPOSTISSET($key) ?
GETPOST($key, $check) : $object->$key;
688 } elseif (in_array($val[
'type'], array(
'date',
'datetime'))) {
689 $isPostDate = GETPOSTISSET($key);
690 $isPostTime = GETPOSTISSET($key .
'_time');
692 $postDate =
GETPOST($key,
'alphanohtml');
694 $postTime =
GETPOST($key .
'_time',
'alphanohtml') .
':00';
696 $postTime =
'00:00:00';
698 $valueDateTimeStr = $postDate .
' ' . $postTime;
701 $valueDateTimeStr =
dol_print_date($object->$key,
'%Y-%m-%d %H:%M:%S');
704 $value = $valueDateTimeStr;
705 } elseif ($val[
'type'] ==
'price') {
707 } elseif ($key ==
'lang') {
708 $value = GETPOSTISSET($key) ?
GETPOST($key,
'aZ09') : $object->lang;
710 $value = GETPOSTISSET($key) ?
GETPOST($key,
'alphanohtml') : $object->$key;
713 if (!empty($val[
'noteditable'])) {
714 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
716 $html .= $this->form->showInputField($val, $key, $value,
'',
'',
'',
'');
734 $html .=
'</footer>';
747 global $hookmanager, $langs;
749 $html =
'<!-- elementCard -->';
752 $action = $this->action;
753 $backtopage = $this->backtopage;
754 $backtopageforcancel = $this->backtopageforcancel;
758 $object = $this->object;
760 $permissiontoadd = $this->permissiontoadd;
762 $titleKey = $this->titleKey;
763 $title = $langs->trans($titleKey);
766 if (($id || $ref) && $action ==
'edit') {
767 $html .=
'<article>';
770 $html .=
'<h2>' . $title .
'</h2>';
771 $html .=
'</header>';
774 $html .=
'<form method="POST" action="' . $url_file .
'">';
776 $html .=
'<input type="hidden" name="action" value="update">';
777 $html .=
'<input type="hidden" name="id" value="' . $object->id .
'">';
779 $html .=
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
781 if ($backtopageforcancel) {
782 $html .=
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
795 $html .=
'<div class="grid">';
796 $html .=
'<div><input type="submit" name="save" role="button" value="' .
dol_escape_htmltag($langs->trans(
'Save')) .
'" /></div>';
797 $html .=
'<div><input type="submit" name="cancel" role="button" value="' .
dol_escape_htmltag($langs->trans(
'Cancel')) .
'" /></div>';
801 $html .=
'</article>';
805 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
806 $html .=
'<article>';
811 $parameters = array(
'formConfirm' => $formconfirm);
812 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
813 if (empty($reshook)) {
814 $formconfirm .= $hookmanager->resPrint;
815 } elseif ($reshook > 0) {
816 $formconfirm = $hookmanager->resPrint;
820 $html .= $formconfirm;
828 $html .= $this->
bodyView($keyforbreak);
834 $html .=
'</article>';
837 if ($action !=
'presend' && $action !=
'editline') {
838 $html .=
'<div>' .
"\n";
839 $parameters = array();
840 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
842 $context->setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
845 if (empty($reshook)) {
846 if ($permissiontoadd) {
848 $html .=
'<a href="' . $url_file .
'&id=' . $object->id .
'&action=edit" role="button">' . $langs->trans(
'Modify') .
'</a>';
851 $html .=
'</div>' .
"\n";
static getInstance()
Singleton method to create one instance of this object.
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...
$context
@method int call_trigger(string $triggerName, User $user)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.