28require_once DOL_DOCUMENT_ROOT .
'/webportal/class/html.formwebportal.class.php';
44 public $backtopage =
'';
49 public $backtopageforcancel =
'';
64 public $elementEn =
'';
84 public $permissiontoread = 0;
89 public $permissiontoadd = 0;
94 public $permissiontodelete = 0;
99 public $permissionnote = 0;
104 public $permissiondellink = 0;
114 public $titleKey =
'';
119 public $titleDescKey =
'';
144 public function init($elementEn, $id = 0, $permissiontoread = 0, $permissiontoadd = 0, $permissiontodelete = 0, $permissionnote = 0, $permissiondellink = 0)
146 global $hookmanager, $langs;
148 $elementEnUpper = strtoupper($elementEn);
149 $objectclass =
'WebPortal' . ucfirst($elementEn);
151 $elementCardAccess =
getDolGlobalString(
'WEBPORTAL_' . $elementEnUpper .
'_CARD_ACCESS',
'hidden');
152 if ($elementCardAccess ==
'hidden' || $id <= 0) {
160 $langs->loadLangs(array(
'website',
'other'));
164 $ref =
GETPOST(
'ref',
'alpha');
165 $action =
GETPOST(
'action',
'aZ09');
166 $confirm =
GETPOST(
'confirm',
'alpha');
168 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'webportal' . $elementEn .
'card';
169 $backtopage =
GETPOST(
'backtopage',
'alpha');
170 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
173 $object =
new $objectclass($this->db);
175 $hookmanager->initHooks(array(
'webportal' . $elementEn .
'card',
'globalcard'));
181 if (empty($action) && empty($id) && empty($ref)) {
186 include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
189 if (!isModEnabled(
'webportal')) {
192 if (!$permissiontoread) {
197 $this->action = $action;
198 $this->backtopage = $backtopage;
199 $this->backtopageforcancel = $backtopageforcancel;
200 $this->cancel = $cancel;
201 $this->elementEn = $elementEn;
202 $this->
id = (int) $id;
203 $this->
object = $object;
204 $this->permissiontoread = $permissiontoread;
205 $this->permissiontoadd = $permissiontoadd;
206 $this->permissiontodelete = $permissiontodelete;
207 $this->permissionnote = $permissionnote;
208 $this->permissiondellink = $permissiondellink;
209 $this->titleKey = $objectclass .
'CardTitle';
223 $action = $this->action;
224 $backtopage = $this->backtopage;
225 $backtopageforcancel = $this->backtopageforcancel;
226 $cancel = $this->cancel;
227 $elementEn = $this->elementEn;
229 $object = $this->object;
231 $permissiontoadd = $this->permissiontoadd;
237 $backurlforlist =
$context->getControllerUrl(
'default');
240 if (empty($backtopage) || ($cancel && empty($id))) {
241 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
242 $backtopage =
$context->getControllerUrl($elementEn .
'card');
248 if (!empty($backtopageforcancel)) {
249 header(
"Location: " . $backtopageforcancel);
251 } elseif (!empty($backtopage)) {
252 header(
"Location: " . $backtopage);
259 if ($action ==
'update' && !empty($permissiontoadd)) {
260 foreach ($object->fields as $key => $val) {
262 if ($object->fields[$key][
'type'] ==
'duration') {
263 if (!GETPOSTISSET($key .
'hour') || !GETPOSTISSET($key .
'min')) {
266 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
267 if (!GETPOSTISSET($key)) {
272 if (!GETPOSTISSET($key) && !preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) && $object->fields[$key][
'type'] !==
'checkbox') {
277 if (in_array($key, array(
'rowid',
'entity',
'import_key'))) {
280 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
281 if (!in_array(abs($val[
'visible']), array(1, 3, 4))) {
287 if (preg_match(
'/^text/', $object->fields[$key][
'type'])) {
288 $tmparray = explode(
':', $object->fields[$key][
'type']);
289 if (!empty($tmparray[1])) {
290 $value =
GETPOST($key, $tmparray[1]);
292 $value =
GETPOST($key,
'nohtml');
294 } elseif (preg_match(
'/^html/', $object->fields[$key][
'type'])) {
295 $tmparray = explode(
':', $object->fields[$key][
'type']);
296 if (!empty($tmparray[1])) {
297 $value =
GETPOST($key, $tmparray[1]);
299 $value =
GETPOST($key,
'restricthtml');
301 } elseif (in_array($object->fields[$key][
'type'], array(
'date',
'datetime'))) {
302 $postDate =
GETPOST($key,
'alphanohtml');
304 $dateArr = explode(
'-', $postDate);
308 if (count($dateArr) == 3) {
309 $dateYear = (int) $dateArr[0];
310 $dateMonth = (int) $dateArr[1];
311 $dateDay = (int) $dateArr[2];
314 $postTime =
GETPOST($key .
'_time',
'alphanohtml');
315 $timeArr = explode(
':', $postTime);
319 if (!empty($timeArr)) {
320 if (isset($timeArr[0])) {
321 $timeHours = (int) $timeArr[0];
323 if (isset($timeArr[1])) {
324 $timeMinutes = (int) $timeArr[1];
326 if (isset($timeArr[2])) {
327 $timeSeconds = (int) $timeArr[2];
330 $value =
dol_mktime($timeHours, $timeMinutes, $timeSeconds, $dateMonth, $dateDay, $dateYear);
331 } elseif ($object->fields[$key][
'type'] ==
'duration') {
337 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
339 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
340 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
344 } elseif (preg_match(
'/^chkbxlst:/', $object->fields[$key][
'type']) || $object->fields[$key][
'type'] ==
'checkbox') {
346 $values_arr =
GETPOST($key,
'array');
347 if (!empty($values_arr)) {
348 $value = implode(
',', $values_arr);
351 if ($key ==
'lang') {
352 $value =
GETPOST($key,
'aZ09');
354 $value =
GETPOST($key,
'alphanohtml');
357 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') {
360 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') {
364 $object->$key = $value;
365 if (!empty($val[
'notnull']) && $val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default'])) {
367 $context->setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])),
null,
'errors');
372 if (!$error && !empty($val[
'validate']) && is_callable(array($object,
'validateField'))) {
373 if (!$object->validateField($object->fields, $key, $value)) {
379 if (isModEnabled(
'category')) {
380 $categories =
GETPOST(
'categories',
'array');
381 if (method_exists($object,
'setCategories')) {
382 $object->setCategories($categories);
396 $result = $object->update(
$context->logged_user);
399 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
400 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string) $object->id, $urltogo);
401 if ($urltogo && empty($noback)) {
402 header(
"Location: " . $urltogo);
408 $context->setEventMessages($object->error, $object->errors,
'errors');
416 $this->
object = $object;
417 $this->action = $action;
433 $object = $this->object;
449 $html .=
'<!-- html.formcardwebportal.class.php -->';
453 $html .=
'<div class="header-card-left-block inline-block" style="width: 75%;">';
457 $form =
new Form($this->db);
458 $html .=
'<div class="inline-block floatleft valignmiddle">';
459 $html .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
460 $html .= $form->showphoto(
'memberphoto', $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, 1);
467 $html .=
'<div class="header-card-main-information inline-block valignmiddle">';
469 $html .=
'<div><strong>' . $langs->trans(
"Ref").
' : '.
dol_escape_htmltag($object->ref) .
'</strong></div>';
472 if (method_exists($object,
'getFullName')) {
473 $fullname = $object->getFullName($langs);
475 $html .=
'<div><strong>';
476 if ($object->element ==
'member') {
477 '@phan-var-force Adherent $object';
478 if ($object->morphy ==
'mor' && !empty($object->societe)) {
480 $html .= (!empty($fullname) && $object->societe != $fullname) ?
' (' .
dol_htmlentities($fullname) . $addgendertxt .
')' :
'';
483 if (empty($object->fk_soc)) {
484 $html .= (!empty($object->societe) && $object->societe != $fullname) ?
' (' .
dol_htmlentities((
string) $object->societe) .
')' :
'';
490 $html .=
'</strong></div>';
492 if (method_exists($object,
'getBannerAddressForWebPortal')) {
493 $moreaddress = $object->getBannerAddressForWebPortal(
'refaddress');
495 $html .=
'<div class="refidno refaddress">';
496 $html .= $moreaddress;
508 $html .=
'<div class="header-card-right-block inline-block" style="width: 24%;">';
510 $htmlStatus = $object->getLibStatut(6);
511 if (empty($htmlStatus) || $htmlStatus == $object->getLibStatut(3)) {
512 $htmlStatus = $object->getLibStatut(5);
514 $html .= $htmlStatus;
518 $html .=
'</header>';
535 $object = $this->object;
540 $fieldShowList = array();
541 foreach ($object->fields as $key => $val) {
543 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4 && abs($val[
'visible']) != 5) {
547 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
551 if (!empty($val[
'showonheader'])) {
555 $fieldShowList[$key] = $val;
558 $nbFieldShow = count($fieldShowList);
559 $lastKeyFieldLeft = $keyforbreak;
560 $lastNumFieldLeft = 0;
561 if ($lastKeyFieldLeft ==
'') {
562 $lastNumFieldLeft = ceil($nbFieldShow / 2);
565 $html .=
'<div class="grid">';
566 $html .=
'<div class="card-left">';
567 foreach ($object->fields as $key => $val) {
568 if (!array_key_exists($key, $fieldShowList)) {
572 $value = $object->$key;
574 $html .=
'<div class="grid field_' . $key .
'">';
576 $html .=
'<div class="' . (empty($val[
'tdcss']) ?
'' : $val[
'tdcss']) .
' fieldname_' . $key;
579 $labeltoshow .=
'<strong>' . $langs->trans($val[
'label']) .
'</strong>';
580 $html .= $labeltoshow;
583 $html .=
'<div class="valuefield fieldname_' . $key;
584 if (!empty($val[
'cssview'])) {
585 $html .=
' ' . $val[
'cssview'];
588 if ($key ==
'lang') {
589 $langs->load(
'languages');
590 $labellang = ($value ? $langs->trans(
'Language_' . $value) :
'');
594 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
604 if ($keyforbreak !=
'') {
605 if ($key == $keyforbreak) {
609 if ($numField == $lastNumFieldLeft) {
615 $html .=
'<div class="card-right">';
636 $object = $this->object;
640 foreach ($object->fields as $key => $val) {
642 if (abs($val[
'visible']) != 1 && abs($val[
'visible']) != 3 && abs($val[
'visible']) != 4) {
646 if (array_key_exists(
'enabled', $val) && isset($val[
'enabled']) && !
verifCond($val[
'enabled'])) {
650 $html .=
'<div class="grid field_' . $key .
'">';
651 $html .=
'<div class="titlefieldcreate';
652 if (isset($val[
'notnull']) && $val[
'notnull'] > 0) {
653 $html .=
' required';
656 $html .= $langs->trans($val[
'label']);
659 $html .=
'<div class="valuefieldcreate">';
660 if (in_array($val[
'type'], array(
'int',
'integer'))) {
661 $value = GETPOSTISSET($key) ?
GETPOSTINT($key) : $object->$key;
662 } elseif ($val[
'type'] ==
'double') {
663 $value = GETPOSTISSET($key) ?
price2num(
GETPOST($key,
'alphanohtml')) : $object->$key;
664 } elseif (preg_match(
'/^text/', $val[
'type'])) {
665 $tmparray = explode(
':', $val[
'type']);
666 if (!empty($tmparray[1])) {
667 $check = $tmparray[1];
671 $value = GETPOSTISSET($key) ?
GETPOST($key, $check) : $object->$key;
672 } elseif (preg_match(
'/^html/', $val[
'type'])) {
673 $tmparray = explode(
':', $val[
'type']);
674 if (!empty($tmparray[1])) {
675 $check = $tmparray[1];
677 $check =
'restricthtml';
679 $value = GETPOSTISSET($key) ?
GETPOST($key, $check) : $object->$key;
680 } elseif (in_array($val[
'type'], array(
'date',
'datetime'))) {
681 $isPostDate = GETPOSTISSET($key);
682 $isPostTime = GETPOSTISSET($key .
'_time');
684 $postDate =
GETPOST($key,
'alphanohtml');
686 $postTime =
GETPOST($key .
'_time',
'alphanohtml') .
':00';
688 $postTime =
'00:00:00';
690 $valueDateTimeStr = $postDate .
' ' . $postTime;
693 $valueDateTimeStr =
dol_print_date($object->$key,
'%Y-%m-%d %H:%M:%S');
696 $value = $valueDateTimeStr;
697 } elseif ($val[
'type'] ==
'price') {
699 } elseif ($key ==
'lang') {
700 $value = GETPOSTISSET($key) ?
GETPOST($key,
'aZ09') : $object->lang;
702 $value = GETPOSTISSET($key) ?
GETPOST($key,
'alphanohtml') : $object->$key;
705 if (!empty($val[
'noteditable'])) {
706 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $value,
'',
'',
'', 0);
709 $html .= $this->form->showInputFieldForObject($object, $val, $key, $value,
'',
'',
'',
'');
728 $html .=
'</footer>';
741 global $hookmanager, $langs;
743 $html =
'<!-- elementCard -->';
746 $action = $this->action;
747 $backtopage = $this->backtopage;
748 $backtopageforcancel = $this->backtopageforcancel;
751 $object = $this->object;
753 $permissiontoadd = $this->permissiontoadd;
755 $titleKey = $this->titleKey;
756 $title = $langs->trans($titleKey);
759 if (($id || $ref) && $action ==
'edit') {
760 $html .=
'<article>';
763 $html .=
'<h2>' . $title .
'</h2>';
764 $html .=
'</header>';
767 $html .=
'<form method="POST" action="' . $url_file .
'">';
769 $html .=
'<input type="hidden" name="action" value="update">';
770 $html .=
'<input type="hidden" name="id" value="' . $object->id .
'">';
772 $html .=
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
774 if ($backtopageforcancel) {
775 $html .=
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
788 $html .=
'<div class="grid">';
789 $html .=
'<div><input type="submit" name="save" role="button" value="' .
dol_escape_htmltag($langs->trans(
'Save')) .
'" /></div>';
790 $html .=
'<div><input type="submit" name="cancel" role="button" value="' .
dol_escape_htmltag($langs->trans(
'Cancel')) .
'" /></div>';
794 $html .=
'</article>';
798 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
799 $html .=
'<article>';
804 $parameters = array(
'formConfirm' => $formconfirm);
805 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
806 if (empty($reshook)) {
807 $formconfirm .= $hookmanager->resPrint;
808 } elseif ($reshook > 0) {
809 $formconfirm = $hookmanager->resPrint;
813 $html .= $formconfirm;
821 $html .= $this->
bodyView($keyforbreak);
827 $html .=
'</article>';
830 if ($action !=
'presend' && $action !=
'editline') {
831 $html .=
'<div>' .
"\n";
832 $parameters = array();
833 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
835 $context->setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
838 if (empty($reshook)) {
839 if ($permissiontoadd) {
841 $html .=
'<a href="' . $url_file .
'&id=' . $object->id .
'&action=edit" role="button">' . $langs->trans(
'Modify') .
'</a>';
844 $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.