46 public $backtopage =
'';
51 public $backtopageforcancel =
'';
66 public $elementEn =
'';
91 public $permissiontoread = 0;
96 public $permissiontoadd = 0;
101 public $permissiontodelete = 0;
106 public $permissionnote = 0;
111 public $permissiondellink = 0;
121 public $titleKey =
'';
126 public $titleDescKey =
'';
131 public $key_for_break =
'';
136 public $modal =
false;
141 public $fieldsmanager;
146 public $updateType = 1;
173 public function init($elementEn, $id = 0, $permissiontoread = 0, $permissiontoadd = 0, $permissiontodelete = 0, $permissionnote = 0, $permissiondellink = 0)
175 global $hookmanager, $langs;
177 $elementEnUpper = strtoupper($elementEn);
178 $objectclass =
'WebPortal' . ucfirst($elementEn);
180 $elementCardAccess =
getDolGlobalString(
'WEBPORTAL_' . $elementEnUpper .
'_CARD_ACCESS',
'hidden');
181 if ($elementCardAccess ==
'hidden' || $id <= 0) {
191 $langs->loadLangs(array(
'website',
'other'));
195 $ref =
GETPOST(
'ref',
'alpha');
196 $action =
GETPOST(
'action',
'aZ09');
197 $confirm =
GETPOST(
'confirm',
'alpha');
199 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'webportal' . $elementEn .
'card';
200 $backtopage =
GETPOST(
'backtopage',
'alpha');
201 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
205 $object =
new $objectclass($this->db);
206 '@phan-var-force CommonObject $object';
209 $hookmanager->initHooks(array(
'webportal' . $elementEn .
'card',
'globalcard'));
213 $this->extrafields->fetch_name_optionals_label($object->table_element);
216 if (empty($action) && empty($id) && empty($ref)) {
221 if (($id > 0 || (!empty($ref) && !in_array($action, array(
'create',
'createtask',
'add')))) && (empty($cancel) || $id > 0)) {
222 if (($id > 0 && is_numeric((
string) $id)) || !empty($ref)) {
223 if ($object->element ==
'usergroup') {
224 $ret = $object->fetch($id, (empty($ref) ?
'' : $ref), true);
226 $ret = $object->fetch($id, (empty($ref) ?
'' : $ref));
229 $object->fetch_thirdparty();
232 if (empty($object->error) && !count($object->errors)) {
234 $context->setEventMessages(
'Fetch on object (type ' . get_class($object) .
') return an error without filling $object->error nor $object->errors',
null,
'errors');
237 $context->setEventMessages($object->error, $object->errors,
'errors');
248 if (!$permissiontoread) {
253 $this->action = $action;
254 $this->backtopage = $backtopage;
255 $this->backtopageforcancel = $backtopageforcancel;
256 $this->cancel = $cancel;
257 $this->elementEn = $elementEn;
258 $this->
id = (int) $id;
259 $this->
object = $object;
260 $this->permissiontoread = $permissiontoread;
261 $this->permissiontoadd = $permissiontoadd;
262 $this->permissiontodelete = $permissiontodelete;
263 $this->permissionnote = $permissionnote;
264 $this->permissiondellink = $permissiondellink;
265 $this->titleKey = $objectclass .
'CardTitle';
267 $this->modal = $modal;
278 $action = $this->action;
279 $backtopage = $this->backtopage;
280 $backtopageforcancel = $this->backtopageforcancel;
281 $cancel = $this->cancel;
282 $elementEn = $this->elementEn;
284 $object = $this->object;
286 $permissiontoadd = $this->permissiontoadd;
290 $backurlforlist =
$context->getControllerUrl(
'default');
293 if (empty($backtopage) || ($cancel && empty(
$id))) {
294 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
295 $backtopage =
$context->getControllerUrl($elementEn .
'card');
301 if (!empty($backtopageforcancel)) {
302 header(
"Location: " . $backtopageforcancel);
304 } elseif (!empty($backtopage)) {
305 header(
"Location: " . $backtopage);
312 if ($action ==
'update' && !empty($permissiontoadd)) {
315 $result = $this->fieldsmanager->setFieldValuesFromPost($object, $this->extrafields,
'',
'',
'edit');
318 $context->setEventMessages($this->fieldsmanager->error, $this->fieldsmanager->errors,
'errors');
320 if ($this->updateType == 2) {
321 $result = $object->update($this->
id,
$context->logged_user);
323 $result = $object->update(
$context->logged_user);
327 $context->setEventMessages($object->error, $object->errors,
'errors');
335 $urltogo = $backtopage ? str_replace(
'__ID__', (
string) $object->id, $backtopage) : $backurlforlist;
336 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', (
string) $object->id, $urltogo);
337 if ($urltogo && empty($noback)) {
338 header(
"Location: " . $urltogo);
344 $this->
object = $object;
345 $this->action = $action;
static getInstance()
Singleton method to create one instance of this object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.