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 if (!empty($conf->use_javascript_ajax)) {
242 print '<script type="text/javascript">';
243 print '$(document).ready(function () {
244 $("#selectcountry_id").change(function() {
245 console.log("selectcountry_id change");
246 document.formresource.action.value="create";
247 document.formresource.submit();
248 });
249 });';
250 print '</script>'."\n";
251 }
252
253
254 // Create/Edit object
255
256 print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST" name="formresource">';
257 print '<input type="hidden" name="token" value="'.newToken().'">';
258 print '<input type="hidden" name="action" value="'.($action == "create" ? "add" : "update").'">';
259
260 print '<table class="border centpercent">';
261
262 // Ref
263 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("ResourceFormLabel_ref").'</td>';
264 print '<td><input class="minwidth200" name="ref" value="'.($ref ?: $object->ref).'" autofocus="autofocus"></td></tr>';
265
266 // Type
267 print '<tr><td>'.$langs->trans("ResourceType").'</td>';
268 print '<td>';
269 $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2, 0, 0, 0, 1, 'minwidth200');
270 print '</td></tr>';
271
272 // Description
273 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
274 print '<td>';
275 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
276 $doleditor = new DolEditor('description', ($description ?: $object->description), '', 200, 'dolibarr_notes');
277 $doleditor->Create();
278 print '</td></tr>';
279
280 // Address
281 print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
282 print '<td><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
283 print dol_escape_htmltag(GETPOSTISSET('address') ? GETPOST('address') : $object->address, 0, 1);
284 print '</textarea>';
285 print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
286 print '</td></tr>';
287
288 // Zip
289 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
290 print $formresource->select_ziptown(GETPOSTISSET('zipcode') ? GETPOST('zipcode') : $object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
291 print '</td>';
292 print '</tr>';
293
294 // Town
295 print '<tr>';
296 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
297 print $formresource->select_ziptown(GETPOSTISSET('town') ? GETPOST('town') : $object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
298 print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
299 print '</td></tr>';
300
301 // Origin country
302 print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
303 print $form->select_country(GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id, 'country_id');
304 if ($user->admin) {
305 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
306 }
307 print '</td></tr>';
308
309 // State
310 $countryid = GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id;
311 if (!getDolGlobalString('SOCIETE_DISABLE_STATE') && $countryid > 0) {
312 if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
313 print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
314 } else {
315 print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
316 }
317
318 if ($country_id > 0) {
319 print img_picto('', 'state', 'class="pictofixedwidth"');
320 print $formresource->select_state($countryid, $country_id);
321 } else {
322 print '<span class="opacitymedium">'.$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')</span>';
323 }
324 print '</td></tr>';
325 }
326
327 // Phone
328 print '<td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
329 print '<td>';
330 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
331 print '<input type="tel" name="phone" id="phone" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
332 print '</tr>';
333
334 // Email
335 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0).'</td>';
336 print '<td>';
337 print img_picto('', 'object_email', 'class="pictofixedwidth"');
338 print '<input type="email" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
339 print '</tr>';
340
341 // Max users
342 print '<tr><td>'.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0).'</td>';
343 print '<td>';
344 print img_picto('', 'object_user', 'class="pictofixedwidth"');
345 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>';
346 print '</tr>';
347
348 // URL
349 print '<tr><td>'.$form->editfieldkey('URL', 'url', '', $object, 0).'</td>';
350 print '<td>';
351 print img_picto('', 'object_url', 'class="pictofixedwidth"');
352 print '<input type="url" name="url" id="url" value="'.(GETPOSTISSET('url') ? GETPOST('url', 'alpha') : $object->url).'"></td>';
353 print '</tr>';
354
355 // Other attributes
356 $parameters = array();
357 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
358 print $hookmanager->resPrint;
359 if (empty($reshook)) {
360 print $object->showOptionals($extrafields, 'edit');
361 }
362
363 print '</table>';
364
365 print dol_get_fiche_end();
366
367 $button_label = ($action == "create" ? "Create" : "Modify");
368 print $form->buttonsSaveCancel($button_label);
369
370 print '</div>';
371
372 print '</form>';
373 } else {
374 $formconfirm = '';
375
376 // Confirm deleting resource line
377 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
378 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', 0, "action-delete");
379 }
380
381 // Print form confirm
382 print $formconfirm;
383
384
385 $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
386
387 dol_banner_tab($object, 'ref', $linkback, 1, 'ref');
388
389
390 print '<div class="fichecenter">';
391 print '<div class="underbanner clearboth"></div>';
392
393 print '<table class="border tableforfield centpercent">';
394
395 // Resource type
396 print '<tr>';
397 print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
398 print '<td>';
399 print $object->type_label;
400 print '</td>';
401 print '</tr>';
402
403 // Description
404 print '<tr>';
405 print '<td>'.$langs->trans("ResourceFormLabel_description").'</td>';
406 print '<td>';
407 print $object->description;
408 print '</td>';
409 print '</tr>';
410
411 // Max users
412 print '<tr>';
413 print '<td>'.$langs->trans("MaxUsers").'</td>';
414 print '<td>';
415 print $object->max_users;
416 print '</td>';
417 print '</tr>';
418
419 // Other attributes
420 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
421
422 print '</tr>';
423
424 print '</table>';
425
426 print '</div>';
427
428 print '<div class="clearboth"></div><br>';
429
430 print dol_get_fiche_end();
431 }
432
433
434 /*
435 * Boutons actions
436 */
437 print '<div class="tabsAction">';
438 $parameters = array();
439 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
440 // modified by hook
441 if (empty($reshook)) {
442 if ($action != "create" && $action != "edit") {
443 // Edit resource
444 if ($user->hasRight('resource', 'write')) {
445 print '<div class="inline-block divButAction">';
446 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans('Modify').'</a>';
447 print '</div>';
448 }
449 }
450 if ($action != "create" && $action != "edit") {
451 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
452 $buttonId = 'action-delete-no-ajax';
453 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
454 $deleteUrl = '';
455 $buttonId = 'action-delete';
456 }
457 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
458 }
459 }
460 print '</div>';
461} else {
463}
464
465// End of page
466llxFooter();
467$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...
div refaddress div address
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.