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