dolibarr 20.0.0
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
31require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array('resource', 'companies', 'other', 'main'));
38
39// Get parameters
40$id = GETPOSTINT('id');
41$action = GETPOST('action', 'aZ09');
42$cancel = GETPOST('cancel', 'alpha');
43$ref = GETPOST('ref', 'alpha');
44$address = GETPOST('address', 'alpha');
45$zip = GETPOST('zipcode', 'alpha');
46$town = GETPOST('town', 'alpha');
47$country_id = GETPOSTINT('country_id');
48$state_id = GETPOSTINT('state_id');
49$description = GETPOST('description', 'restricthtml');
50$phone = GETPOST('phone', 'alpha');
51$email = GETPOST('email', 'alpha');
52$max_users = GETPOSTINT('max_users');
53$url = GETPOST('url', 'alpha');
54$confirm = GETPOST('confirm', 'aZ09');
55$fk_code_type_resource = GETPOST('fk_code_type_resource', 'aZ09');
56
57// Protection if external user
58if ($user->socid > 0) {
60}
61
62$object = new Dolresource($db);
63$extrafields = new ExtraFields($db);
64
65// fetch optionals attributes and labels
66$extrafields->fetch_name_optionals_label($object->table_element);
67
68// Load object
69include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
70
71
72$result = restrictedArea($user, 'resource', $object->id, 'resource');
73
74$permissiontoadd = $user->hasRight('resource', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
75$permissiontodelete = $user->hasRight('resource', 'delete');
76
77
78/*
79 * Actions
80 */
81
82$hookmanager->initHooks(array('resource', 'resource_card', 'globalcard'));
83$parameters = array('resource_id' => $id);
84$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
85if ($reshook < 0) {
86 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87}
88
89if (empty($reshook)) {
90 if ($cancel) {
91 if (!empty($backtopage)) {
92 header("Location: ".$backtopage);
93 exit;
94 }
95 if ($action == 'add') {
96 header("Location: ".DOL_URL_ROOT.'/resource/list.php');
97 exit;
98 }
99 $action = '';
100 }
101
102 if ($action == 'add' && $user->hasRight('resource', 'write')) {
103 if (!$cancel) {
104 $error = '';
105
106 if (empty($ref)) {
107 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
108 $action = 'create';
109 } else {
110 $object->ref = $ref;
111 $object->address = $address;
112 $object->zip = $zip;
113 $object->town = $town;
114 $object->country_id = $country_id;
115 $object->state_id = $state_id;
116 $object->description = $description;
117 $object->phone = $phone;
118 $object->email = $email;
119 $object->max_users = $max_users;
120 $object->url = $url;
121 $object->fk_code_type_resource = $fk_code_type_resource;
122
123 // Fill array 'array_options' with data from add form
124 $ret = $extrafields->setOptionalsFromPost(null, $object);
125 if ($ret < 0) {
126 $error++;
127 }
128
129 $result = $object->create($user);
130 if ($result > 0) {
131 // Creation OK
132 setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null);
133 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
134 exit;
135 } else {
136 // Creation KO
137 setEventMessages($object->error, $object->errors, 'errors');
138 $action = 'create';
139 }
140 }
141 } else {
142 header("Location: list.php");
143 exit;
144 }
145 }
146
147 if ($action == 'update' && !$cancel && $user->hasRight('resource', 'write')) {
148 $error = 0;
149
150 if (empty($ref)) {
151 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
152 $error++;
153 }
154
155 if (!$error) {
156 $res = $object->fetch($id);
157 if ($res > 0) {
158 $object->ref = $ref;
159 $object->address = $address;
160 $object->zip = $zip;
161 $object->town = $town;
162 $object->country_id = $country_id;
163 $object->state_id = $state_id;
164 $object->description = $description;
165 $object->phone = $phone;
166 $object->email = $email;
167 $object->max_users = $max_users;
168 $object->url = $url;
169 $object->fk_code_type_resource = $fk_code_type_resource;
170
171 // Fill array 'array_options' with data from add form
172 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
173 if ($ret < 0) {
174 $error++;
175 }
176
177 $result = $object->update($user);
178 if ($result > 0) {
179 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
180 exit;
181 } else {
182 setEventMessages($object->error, $object->errors, 'errors');
183 $error++;
184 }
185 } else {
186 setEventMessages($object->error, $object->errors, 'errors');
187 $error++;
188 }
189 }
190
191 if ($error) {
192 $action = 'edit';
193 }
194 }
195
196 if ($action == 'confirm_delete_resource' && $user->hasRight('resource', 'delete') && $confirm === 'yes') {
197 $res = $object->fetch($id);
198 if ($res > 0) {
199 $result = $object->delete($user);
200
201 if ($result >= 0) {
202 setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null);
203 header('Location: '.DOL_URL_ROOT.'/resource/list.php');
204 exit;
205 } else {
206 setEventMessages($object->error, $object->errors, 'errors');
207 }
208 } else {
209 setEventMessages($object->error, $object->errors, 'errors');
210 }
211 }
212}
213
214
215/*
216 * View
217 */
218
219$title = $langs->trans($action == 'create' ? 'AddResource' : 'ResourceSingular');
220$help_url = '';
221llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-resource page-card');
222
223$form = new Form($db);
224$formresource = new FormResource($db);
225
226if ($action == 'create' || $object->fetch($id, $ref) > 0) {
227 if ($action == 'create') {
228 print load_fiche_titre($title, '', 'object_resource');
229 print dol_get_fiche_head();
230 } else {
232 print dol_get_fiche_head($head, 'resource', $title, -1, 'resource');
233 }
234
235 if ($action == 'create' || $action == 'edit') {
236 if (!$user->hasRight('resource', 'write')) {
237 accessforbidden('', 0);
238 }
239
240 // Create/Edit object
241
242 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
243 print '<input type="hidden" name="token" value="'.newToken().'">';
244 print '<input type="hidden" name="action" value="'.($action == "create" ? "add" : "update").'">';
245
246 print '<table class="border centpercent">';
247
248 // Ref
249 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("ResourceFormLabel_ref").'</td>';
250 print '<td><input class="minwidth200" name="ref" value="'.($ref ?: $object->ref).'" autofocus="autofocus"></td></tr>';
251
252 // Address
253 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
254 print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
255 print dol_escape_htmltag($object->address, 0, 1);
256 print '</textarea>';
257 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
258 print '</td></tr>';
259
260 // Zip / Town
261 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
262 print $formresource->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
263 print '</td>';
264 if ($conf->browser->layout == 'phone') {
265 print '</tr><tr>';
266 }
267 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
268 print $formresource->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
269 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
270 print '</td></tr>';
271
272 // Origin country
273 print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
274 print $form->select_country($object->country_id);
275 if ($user->admin) {
276 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
277 }
278 print '</td></tr>';
279
280 // State
281 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
282 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
283 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
284 } else {
285 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
286 }
287
288 if ($object->country_id) {
289 print img_picto('', 'state', 'class="pictofixedwidth"');
290 print $formresource->select_state($object->state_id, $object->country_code);
291 } else {
292 print $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
293 }
294 print '</td></tr>';
295 }
296
297 // Type
298 print '<tr><td>'.$langs->trans("ResourceType").'</td>';
299 print '<td>';
300 $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2);
301 print '</td></tr>';
302
303 // Description
304 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
305 print '<td>';
306 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
307 $doleditor = new DolEditor('description', ($description ?: $object->description), '', '200', 'dolibarr_notes', false);
308 $doleditor->Create();
309 print '</td></tr>';
310
311 // Phone
312 print '<td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
313 print '<td>';
314 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
315 print '<input type="tel" name="phone" id="phone" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
316 print '</tr>';
317
318 // Email
319 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0).'</td>';
320 print '<td>';
321 print img_picto('', 'object_email', 'class="pictofixedwidth"');
322 print '<input type="email" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
323 print '</tr>';
324
325 // Max users
326 print '<tr><td>'.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0).'</td>';
327 print '<td>';
328 print img_picto('', 'object_user', 'class="pictofixedwidth"');
329 print '<input type="number" name="max_users" id="max_users" value="'.(GETPOSTISSET('max_users') ? GETPOSTINT('max_users') : $object->max_users).'"></td>';
330 print '</tr>';
331
332 // URL
333 print '<tr><td>'.$form->editfieldkey('URL', 'url', '', $object, 0).'</td>';
334 print '<td>';
335 print img_picto('', 'object_url', 'class="pictofixedwidth"');
336 print '<input type="url" name="url" id="url" value="'.(GETPOSTISSET('url') ? GETPOST('url', 'alpha') : $object->url).'"></td>';
337 print '</tr>';
338
339 // Other attributes
340 $parameters = array();
341 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
342 print $hookmanager->resPrint;
343 if (empty($reshook)) {
344 print $object->showOptionals($extrafields, 'edit');
345 }
346
347 print '</table>';
348
349 print dol_get_fiche_end();
350
351 $button_label = ($action == "create" ? "Create" : "Modify");
352 print $form->buttonsSaveCancel($button_label);
353
354 print '</div>';
355
356 print '</form>';
357 } else {
358 $formconfirm = '';
359
360 // Confirm deleting resource line
361 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
362 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', 0, "action-delete");
363 }
364
365 // Print form confirm
366 print $formconfirm;
367
368
369 $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
370
371 dol_banner_tab($object, 'ref', $linkback, 1, 'ref');
372
373
374 print '<div class="fichecenter">';
375 print '<div class="underbanner clearboth"></div>';
376
377 /*---------------------------------------
378 * View object
379 */
380 print '<table class="border tableforfield centpercent">';
381
382 // Resource type
383 print '<tr>';
384 print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
385 print '<td>';
386 print $object->type_label;
387 print '</td>';
388 print '</tr>';
389
390 // Description
391 print '<tr>';
392 print '<td>'.$langs->trans("ResourceFormLabel_description").'</td>';
393 print '<td>';
394 print $object->description;
395 print '</td>';
396 print '</tr>';
397
398 // Max users
399 print '<tr>';
400 print '<td>'.$langs->trans("MaxUsers").'</td>';
401 print '<td>';
402 print $object->max_users;
403 print '</td>';
404 print '</tr>';
405
406 // Other attributes
407 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
408
409 print '</tr>';
410
411 print '</table>';
412
413 print '</div>';
414
415 print '<div class="clearboth"></div><br>';
416
417 print dol_get_fiche_end();
418 }
419
420
421 /*
422 * Boutons actions
423 */
424 print '<div class="tabsAction">';
425 $parameters = array();
426 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
427 // modified by hook
428 if (empty($reshook)) {
429 if ($action != "create" && $action != "edit") {
430 // Edit resource
431 if ($user->hasRight('resource', 'write')) {
432 print '<div class="inline-block divButAction">';
433 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans('Modify').'</a>';
434 print '</div>';
435 }
436 }
437 if ($action != "create" && $action != "edit") {
438 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
439 $buttonId = 'action-delete-no-ajax';
440 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
441 $deleteUrl = '';
442 $buttonId = 'action-delete';
443 }
444 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
445 }
446 }
447 print '</div>';
448} else {
450}
451
452// End of page
453llxFooter();
454$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage a WYSIWYG editor.
DAO Resource object.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage forms for the module resource.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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...
resource_prepare_head($object)
Prepare head for tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.