dolibarr 21.0.0-beta
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
45// Load translation files required by the page
46$langs->loadLangs(array('resource', 'companies', 'other', 'main'));
47
48// Get parameters
49$id = GETPOSTINT('id');
50$action = GETPOST('action', 'aZ09');
51$cancel = GETPOST('cancel', 'alpha');
52$ref = GETPOST('ref', 'alpha');
53$address = GETPOST('address', 'alpha');
54$zip = GETPOST('zipcode', 'alpha');
55$town = GETPOST('town', 'alpha');
56$country_id = GETPOSTINT('country_id');
57$state_id = GETPOSTINT('state_id');
58$description = GETPOST('description', 'restricthtml');
59$phone = GETPOST('phone', 'alpha');
60$email = GETPOST('email', 'alpha');
61$max_users = GETPOSTINT('max_users');
62$url = GETPOST('url', 'alpha');
63$confirm = GETPOST('confirm', 'aZ09');
64$fk_code_type_resource = GETPOST('fk_code_type_resource', 'aZ09');
65
66// Protection if external user
67if ($user->socid > 0) {
69}
70
71$object = new Dolresource($db);
72$extrafields = new ExtraFields($db);
73
74// fetch optionals attributes and labels
75$extrafields->fetch_name_optionals_label($object->table_element);
76
77// Load object
78include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
79
80$hookmanager->initHooks(array('resource', 'resource_card', 'globalcard'));
81
82$result = restrictedArea($user, 'resource', $object->id, 'resource');
83
84$permissiontoadd = $user->hasRight('resource', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
85$permissiontodelete = $user->hasRight('resource', 'delete');
86
87
88/*
89 * Actions
90 */
91
92$parameters = array('resource_id' => $id);
93$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
94if ($reshook < 0) {
95 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
96}
97
98if (empty($reshook)) {
99 if ($cancel) {
100 if (!empty($backtopage)) {
101 header("Location: ".$backtopage);
102 exit;
103 }
104 if ($action == 'add') { // Test on permission not required here
105 header("Location: ".DOL_URL_ROOT.'/resource/list.php');
106 exit;
107 }
108 $action = '';
109 }
110
111 if ($action == 'add' && $permissiontoadd) {
112 if (!$cancel) {
113 $error = '';
114
115 if (empty($ref)) {
116 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
117 $action = 'create';
118 } else {
119 $object->ref = $ref;
120 $object->address = $address;
121 $object->zip = $zip;
122 $object->town = $town;
123 $object->country_id = $country_id;
124 $object->state_id = $state_id;
125 $object->description = $description;
126 $object->phone = $phone;
127 $object->email = $email;
128 $object->max_users = $max_users;
129 $object->url = $url;
130 $object->fk_code_type_resource = $fk_code_type_resource;
131
132 // Fill array 'array_options' with data from add form
133 $ret = $extrafields->setOptionalsFromPost(null, $object);
134 if ($ret < 0) {
135 $error++;
136 }
137
138 $result = $object->create($user);
139 if ($result > 0) {
140 // Creation OK
141 setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null);
142 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
143 exit;
144 } else {
145 // Creation KO
146 setEventMessages($object->error, $object->errors, 'errors');
147 $action = 'create';
148 }
149 }
150 } else {
151 header("Location: list.php");
152 exit;
153 }
154 }
155
156 if ($action == 'update' && !$cancel && $permissiontoadd) {
157 $error = 0;
158
159 if (empty($ref)) {
160 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
161 $error++;
162 }
163
164 if (!$error) {
165 $res = $object->fetch($id);
166 if ($res > 0) {
167 $object->ref = $ref;
168 $object->address = $address;
169 $object->zip = $zip;
170 $object->town = $town;
171 $object->country_id = $country_id;
172 $object->state_id = $state_id;
173 $object->description = $description;
174 $object->phone = $phone;
175 $object->email = $email;
176 $object->max_users = $max_users;
177 $object->url = $url;
178 $object->fk_code_type_resource = $fk_code_type_resource;
179
180 // Fill array 'array_options' with data from add form
181 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
182 if ($ret < 0) {
183 $error++;
184 }
185
186 $result = $object->update($user);
187 if ($result > 0) {
188 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
189 exit;
190 } else {
191 setEventMessages($object->error, $object->errors, 'errors');
192 $error++;
193 }
194 } else {
195 setEventMessages($object->error, $object->errors, 'errors');
196 $error++;
197 }
198 }
199
200 if ($error) {
201 $action = 'edit';
202 }
203 }
204
205 if ($action == 'confirm_delete_resource' && $permissiontodelete && $confirm === 'yes') {
206 $res = $object->fetch($id);
207 if ($res > 0) {
208 $result = $object->delete($user);
209
210 if ($result >= 0) {
211 setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null);
212 header('Location: '.DOL_URL_ROOT.'/resource/list.php');
213 exit;
214 } else {
215 setEventMessages($object->error, $object->errors, 'errors');
216 }
217 } else {
218 setEventMessages($object->error, $object->errors, 'errors');
219 }
220 }
221}
222
223
224/*
225 * View
226 */
227
228$title = $langs->trans($action == 'create' ? 'AddResource' : 'ResourceSingular');
229$help_url = '';
230llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-resource page-card');
231
232$form = new Form($db);
233$formresource = new FormResource($db);
234
235if ($action == 'create' || $object->fetch($id, $ref) > 0) {
236 if ($action == 'create') {
237 print load_fiche_titre($title, '', 'object_resource');
238 print dol_get_fiche_head();
239 } else {
241 print dol_get_fiche_head($head, 'resource', $title, -1, 'resource');
242 }
243
244 if ($action == 'create' || $action == 'edit') {
245 if (!$user->hasRight('resource', 'write')) {
246 accessforbidden('', 0);
247 }
248
249 if (!empty($conf->use_javascript_ajax)) {
250 print '<script type="text/javascript">';
251 print '$(document).ready(function () {
252 $("#selectcountry_id").change(function() {
253 console.log("selectcountry_id change");
254 document.formresource.action.value="create";
255 document.formresource.submit();
256 });
257 });';
258 print '</script>'."\n";
259 }
260
261
262 // Create/Edit object
263
264 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST" name="formresource">';
265 print '<input type="hidden" name="token" value="'.newToken().'">';
266 print '<input type="hidden" name="action" value="'.($action == "create" ? "add" : "update").'">';
267
268 print '<table class="border centpercent">';
269
270 // Ref
271 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("ResourceFormLabel_ref").'</td>';
272 print '<td><input class="minwidth200" name="ref" value="'.($ref ?: $object->ref).'" autofocus="autofocus"></td></tr>';
273
274 // Type
275 print '<tr><td>'.$langs->trans("ResourceType").'</td>';
276 print '<td>';
277 $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2, 0, 0, 0, 1, 'minwidth200');
278 print '</td></tr>';
279
280 // Description
281 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
282 print '<td>';
283 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
284 $doleditor = new DolEditor('description', ($description ?: $object->description), '', 200, 'dolibarr_notes');
285 $doleditor->Create();
286 print '</td></tr>';
287
288 // Address
289 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
290 print '<td><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
291 print dol_escape_htmltag(GETPOSTISSET('address') ? GETPOST('address') : $object->address, 0, 1);
292 print '</textarea>';
293 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
294 print '</td></tr>';
295
296 // Zip
297 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
298 print $formresource->select_ziptown(GETPOSTISSET('zipcode') ? GETPOST('zipcode') : $object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
299 print '</td>';
300 print '</tr>';
301
302 // Town
303 print '<tr>';
304 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
305 print $formresource->select_ziptown(GETPOSTISSET('town') ? GETPOST('town') : $object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
306 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
307 print '</td></tr>';
308
309 // Origin country
310 print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
311 print $form->select_country(GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id, 'country_id');
312 if ($user->admin) {
313 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
314 }
315 print '</td></tr>';
316
317 // State
318 $countryid = GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id;
319 if (!getDolGlobalString('SOCIETE_DISABLE_STATE') && $countryid > 0) {
320 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
321 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
322 } else {
323 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
324 }
325
326 if ($country_id > 0) {
327 print img_picto('', 'state', 'class="pictofixedwidth"');
328 print $formresource->select_state($countryid, $country_id);
329 } else {
330 print '<span class="opacitymedium">'.$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')</span>';
331 }
332 print '</td></tr>';
333 }
334
335 // Phone
336 print '<td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
337 print '<td>';
338 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
339 print '<input type="tel" name="phone" id="phone" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
340 print '</tr>';
341
342 // Email
343 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0).'</td>';
344 print '<td>';
345 print img_picto('', 'object_email', 'class="pictofixedwidth"');
346 print '<input type="email" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
347 print '</tr>';
348
349 // Max users
350 print '<tr><td>'.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0).'</td>';
351 print '<td>';
352 print img_picto('', 'object_user', 'class="pictofixedwidth"');
353 print '<input type="text" class="width75 right" name="max_users" id="max_users" value="'.(GETPOSTISSET('max_users') ? GETPOST('max_users', 'int') : $object->max_users).'"></td>';
354 print '</tr>';
355
356 // URL
357 print '<tr><td>'.$form->editfieldkey('URL', 'url', '', $object, 0).'</td>';
358 print '<td>';
359 print img_picto('', 'object_url', 'class="pictofixedwidth"');
360 print '<input type="url" name="url" id="url" value="'.(GETPOSTISSET('url') ? GETPOST('url', 'alpha') : $object->url).'"></td>';
361 print '</tr>';
362
363 // Other attributes
364 $parameters = array();
365 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
366 print $hookmanager->resPrint;
367 if (empty($reshook)) {
368 print $object->showOptionals($extrafields, 'edit');
369 }
370
371 print '</table>';
372
373 print dol_get_fiche_end();
374
375 $button_label = ($action == "create" ? "Create" : "Modify");
376 print $form->buttonsSaveCancel($button_label);
377
378 print '</div>';
379
380 print '</form>';
381 } else {
382 $formconfirm = '';
383
384 // Confirm deleting resource line
385 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
386 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', 0, "action-delete");
387 }
388
389 // Print form confirm
390 print $formconfirm;
391
392
393 $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
394
395 dol_banner_tab($object, 'ref', $linkback, 1, 'ref');
396
397
398 print '<div class="fichecenter">';
399 print '<div class="underbanner clearboth"></div>';
400
401 print '<table class="border tableforfield centpercent">';
402
403 // Resource type
404 print '<tr>';
405 print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
406 print '<td>';
407 print $object->type_label;
408 print '</td>';
409 print '</tr>';
410
411 // Description
412 print '<tr>';
413 print '<td>'.$langs->trans("ResourceFormLabel_description").'</td>';
414 print '<td>';
415 print $object->description;
416 print '</td>';
417 print '</tr>';
418
419 // Max users
420 print '<tr>';
421 print '<td>'.$langs->trans("MaxUsers").'</td>';
422 print '<td>';
423 print $object->max_users;
424 print '</td>';
425 print '</tr>';
426
427 // Other attributes
428 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
429
430 print '</tr>';
431
432 print '</table>';
433
434 print '</div>';
435
436 print '<div class="clearboth"></div><br>';
437
438 print dol_get_fiche_end();
439 }
440
441
442 /*
443 * Boutons actions
444 */
445 print '<div class="tabsAction">';
446 $parameters = array();
447 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
448 // modified by hook
449 if (empty($reshook)) {
450 if ($action != "create" && $action != "edit") {
451 // Edit resource
452 if ($user->hasRight('resource', 'write')) {
453 print '<div class="inline-block divButAction">';
454 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans('Modify').'</a>';
455 print '</div>';
456 }
457 }
458 if ($action != "create" && $action != "edit") {
459 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
460 $buttonId = 'action-delete-no-ajax';
461 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
462 $deleteUrl = '';
463 $buttonId = 'action-delete';
464 }
465 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
466 }
467 }
468 print '</div>';
469} else {
471}
472
473// End of page
474llxFooter();
475$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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...
div refaddress div address
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.