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 if ($object->morphy ==
'mor' && !empty($object->societe)) {
487 $html .= (!empty($fullname) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'';
490 if (empty($object->fk_soc)) {
491 $html .= (!empty($object->societe) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($object->societe) .
')' :
'';
497 $html .=
'</strong></div>';
499 if (method_exists($object,
'getBannerAddressForWebPortal')) {
500 $moreaddress = $object->getBannerAddressForWebPortal(
'refaddress');
502 $html .=
'<div class="refidno refaddress">';
503 $html .= $moreaddress;
515 $html .=
'<div class="header-card-right-block inline-block" style="width: 24%;">';
517 $htmlStatus = $object->getLibStatut(6);
518 if (empty($htmlStatus) || $htmlStatus == $object->getLibStatut(3)) {
519 $htmlStatus = $object->getLibStatut(5);
521 $html .= $htmlStatus;
525 $html .=
'</header>';
542 $object = $this->object;
547 $fieldShowList = array();
548 foreach ($object->fields as $key => $val) {
550 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4 && abs($val[
'visible']) != 5) {
554 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
558 if (!empty($val[
'showonheader'])) {
562 $fieldShowList[$key] = $val;
565 $nbFieldShow = count($fieldShowList);
566 $lastKeyFieldLeft = $keyforbreak;
567 $lastNumFieldLeft = 0;
568 if ($lastKeyFieldLeft ==
'') {
569 $lastNumFieldLeft = ceil($nbFieldShow / 2);
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)) {
579 $value = $object->$key;
581 $html .=
'<div class="grid field_' . $key .
'">';
583 $html .=
'<div class="' . (empty($val[
'tdcss']) ?
'' : $val[
'tdcss']) .
' fieldname_' . $key;
586 $labeltoshow .=
'<strong>' . $langs->trans($val[
'label']) .
'</strong>';
587 $html .= $labeltoshow;
590 $html .=
'<div class="valuefield fieldname_' . $key;
591 if (!empty($val[
'cssview'])) {
592 $html .=
' ' . $val[
'cssview'];
595 if ($key ==
'lang') {
596 $langs->load(
'languages');
597 $labellang = ($value ? $langs->trans(
'Language_' . $value) :
'');
601 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
611 if ($keyforbreak !=
'') {
612 if ($key == $keyforbreak) {
616 if ($numField == $lastNumFieldLeft) {
620 if ($cardRight ===
true) {
622 $html .=
'<div class="card-right">';
643 $object = $this->object;
647 foreach ($object->fields as $key => $val) {
649 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4) {
653 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
657 $html .=
'<div class="grid field_' . $key .
'">';
658 $html .=
'<div class="titlefieldcreate';
659 if (isset($val[
'notnull']) && $val[
'notnull'] > 0) {
660 $html .=
' required';
663 $html .= $langs->trans($val[
'label']);
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];
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];
684 $check =
'restricthtml';
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');
691 $postDate =
GETPOST($key,
'alphanohtml');
693 $postTime =
GETPOST($key .
'_time',
'alphanohtml') .
':00';
695 $postTime =
'00:00:00';
697 $valueDateTimeStr = $postDate .
' ' . $postTime;
700 $valueDateTimeStr =
dol_print_date($object->$key,
'%Y-%m-%d %H:%M:%S');
703 $value = $valueDateTimeStr;
704 } elseif ($val[
'type'] ==
'price') {
706 } elseif ($key ==
'lang') {
707 $value = GETPOSTISSET($key) ?
GETPOST($key,
'aZ09') : $object->lang;
709 $value = GETPOSTISSET($key) ?
GETPOST($key,
'alphanohtml') : $object->$key;
712 if (!empty($val[
'noteditable'])) {
713 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
715 $html .= $this->form->showInputField($val, $key, $value,
'',
'',
'',
'');
733 $html .=
'</footer>';
746 global $hookmanager, $langs;
748 $html =
'<!-- elementCard -->';
751 $action = $this->action;
752 $backtopage = $this->backtopage;
753 $backtopageforcancel = $this->backtopageforcancel;
757 $object = $this->object;
759 $permissiontoadd = $this->permissiontoadd;
761 $titleKey = $this->titleKey;
762 $title = $langs->trans($titleKey);
765 if (($id || $ref) && $action ==
'edit') {
766 $html .=
'<article>';
769 $html .=
'<h2>' . $title .
'</h2>';
770 $html .=
'</header>';
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 .
'">';
778 $html .=
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
780 if ($backtopageforcancel) {
781 $html .=
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
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>';
800 $html .=
'</article>';
804 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
805 $html .=
'<article>';
810 $parameters = array(
'formConfirm' => $formconfirm);
811 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
812 if (empty($reshook)) {
813 $formconfirm .= $hookmanager->resPrint;
814 } elseif ($reshook > 0) {
815 $formconfirm = $hookmanager->resPrint;
819 $html .= $formconfirm;
823 $html .= $this->
header($context);
827 $html .= $this->
bodyView($keyforbreak);
833 $html .=
'</article>';
836 if ($action !=
'presend' && $action !=
'editline') {
837 $html .=
'<div>' .
"\n";
838 $parameters = array();
839 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
841 $context->setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
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>';
850 $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 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.