dolibarr 19.0.4
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
29require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array('resource', 'companies', 'other', 'main'));
36
37// Get parameters
38$id = GETPOST('id', 'int');
39$action = GETPOST('action', 'aZ09');
40$cancel = GETPOST('cancel', 'alpha');
41$ref = GETPOST('ref', 'alpha');
42$description = GETPOST('description', 'restricthtml');
43$confirm = GETPOST('confirm', 'aZ09');
44$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha');
45$country_id = GETPOST('country_id', 'int');
46
47// Protection if external user
48if ($user->socid > 0) {
50}
51
52$object = new Dolresource($db);
53$extrafields = new ExtraFields($db);
54
55// fetch optionals attributes and labels
56$extrafields->fetch_name_optionals_label($object->table_element);
57
58// Load object
59include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
60
61
62$result = restrictedArea($user, 'resource', $object->id, 'resource');
63
64$permissiontoadd = $user->rights->resource->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
65$permissiontodelete = $user->rights->resource->delete;
66
67
68/*
69 * Actions
70 */
71
72$hookmanager->initHooks(array('resource', 'resource_card', 'globalcard'));
73$parameters = array('resource_id'=>$id);
74$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
75if ($reshook < 0) {
76 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
77}
78
79if (empty($reshook)) {
80 if ($cancel) {
81 if (!empty($backtopage)) {
82 header("Location: ".$backtopage);
83 exit;
84 }
85 if ($action == 'add') {
86 header("Location: ".DOL_URL_ROOT.'/resource/list.php');
87 exit;
88 }
89 $action = '';
90 }
91
92 if ($action == 'add' && $user->hasRight('resource', 'write')) {
93 if (!$cancel) {
94 $error = '';
95
96 if (empty($ref)) {
97 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
98 $action = 'create';
99 } else {
100 $object->ref = $ref;
101 $object->description = $description;
102 $object->fk_code_type_resource = $fk_code_type_resource;
103 $object->country_id = $country_id;
104
105 // Fill array 'array_options' with data from add form
106 $ret = $extrafields->setOptionalsFromPost(null, $object);
107 if ($ret < 0) {
108 $error++;
109 }
110
111 $result = $object->create($user);
112 if ($result > 0) {
113 // Creation OK
114 setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs');
115 Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
116 exit;
117 } else {
118 // Creation KO
119 setEventMessages($object->error, $object->errors, 'errors');
120 $action = 'create';
121 }
122 }
123 } else {
124 Header("Location: list.php");
125 exit;
126 }
127 }
128
129 if ($action == 'update' && !$cancel && $user->hasRight('resource', 'write')) {
130 $error = 0;
131
132 if (empty($ref)) {
133 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
134 $error++;
135 }
136
137 if (!$error) {
138 $res = $object->fetch($id);
139 if ($res > 0) {
140 $object->ref = $ref;
141 $object->description = $description;
142 $object->fk_code_type_resource = $fk_code_type_resource;
143 $object->country_id = $country_id;
144
145 // Fill array 'array_options' with data from add form
146 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
147 if ($ret < 0) {
148 $error++;
149 }
150
151 $result = $object->update($user);
152 if ($result > 0) {
153 Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
154 exit;
155 } else {
156 setEventMessages($object->error, $object->errors, 'errors');
157 $error++;
158 }
159 } else {
160 setEventMessages($object->error, $object->errors, 'errors');
161 $error++;
162 }
163 }
164
165 if ($error) {
166 $action = 'edit';
167 }
168 }
169
170 if ($action == 'confirm_delete_resource' && $user->hasRight('resource', 'delete') && $confirm === 'yes') {
171 $res = $object->fetch($id);
172 if ($res > 0) {
173 $result = $object->delete($id);
174
175 if ($result >= 0) {
176 setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null, 'mesgs');
177 header('Location: '.DOL_URL_ROOT.'/resource/list.php');
178 exit;
179 } else {
180 setEventMessages($object->error, $object->errors, 'errors');
181 }
182 } else {
183 setEventMessages($object->error, $object->errors, 'errors');
184 }
185 }
186}
187
188
189/*
190 * View
191 */
192
193$title = $langs->trans($action == 'create' ? 'AddResource' : 'ResourceSingular');
194llxHeader('', $title, '');
195
196$form = new Form($db);
197$formresource = new FormResource($db);
198
199if ($action == 'create' || $object->fetch($id, $ref) > 0) {
200 if ($action == 'create') {
201 print load_fiche_titre($title, '', 'object_resource');
202 print dol_get_fiche_head('');
203 } else {
204 $head = resource_prepare_head($object);
205 print dol_get_fiche_head($head, 'resource', $title, -1, 'resource');
206 }
207
208 if ($action == 'create' || $action == 'edit') {
209 if (!$user->hasRight('resource', 'write')) {
210 accessforbidden('', 0, 1);
211 }
212
213 // Create/Edit object
214
215 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
216 print '<input type="hidden" name="token" value="'.newToken().'">';
217 print '<input type="hidden" name="action" value="'.($action == "create" ? "add" : "update").'">';
218
219 print '<table class="border centpercent">';
220
221 // Ref
222 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("ResourceFormLabel_ref").'</td>';
223 print '<td><input class="minwidth200" name="ref" value="'.($ref ? $ref : $object->ref).'" autofocus="autofocus"></td></tr>';
224
225 // Type
226 print '<tr><td>'.$langs->trans("ResourceType").'</td>';
227 print '<td>';
228 $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2);
229 print '</td></tr>';
230
231 // Description
232 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
233 print '<td>';
234 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
235 $doleditor = new DolEditor('description', ($description ? $description : $object->description), '', '200', 'dolibarr_notes', false);
236 $doleditor->Create();
237 print '</td></tr>';
238
239 // Origin country
240 print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
241 print $form->select_country($object->country_id, 'country_id');
242 if ($user->admin) {
243 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
244 }
245 print '</td></tr>';
246
247 // Other attributes
248 $parameters = array();
249 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
250 print $hookmanager->resPrint;
251 if (empty($reshook)) {
252 print $object->showOptionals($extrafields, 'edit');
253 }
254
255 print '</table>';
256
257 print dol_get_fiche_end();
258
259 $button_label = ($action == "create" ? "Create" : "Modify");
260 print $form->buttonsSaveCancel($button_label);
261
262 print '</div>';
263
264 print '</form>';
265 } else {
266 $formconfirm = '';
267
268 // Confirm deleting resource line
269 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
270 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', 0, "action-delete");
271 }
272
273 // Print form confirm
274 print $formconfirm;
275
276
277 $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
278
279
280 $morehtmlref = '<div class="refidno">';
281 $morehtmlref .= '</div>';
282
283
284 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
285
286
287 print '<div class="fichecenter">';
288 print '<div class="underbanner clearboth"></div>';
289
290 /*---------------------------------------
291 * View object
292 */
293 print '<table class="border tableforfield centpercent">';
294
295 // Resource type
296 print '<tr>';
297 print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
298 print '<td>';
299 print $object->type_label;
300 print '</td>';
301 print '</tr>';
302
303 // Description
304 print '<tr>';
305 print '<td>'.$langs->trans("ResourceFormLabel_description").'</td>';
306 print '<td>';
307 print $object->description;
308 print '</td>';
309 print '</tr>';
310
311 // Origin country code
312 print '<tr>';
313 print '<td>'.$langs->trans("CountryOrigin").'</td>';
314 print '<td>';
315 print getCountry($object->country_id, 0, $db);
316 print '</td>';
317
318
319 // Other attributes
320 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
321
322 print '</tr>';
323
324 print '</table>';
325
326 print '</div>';
327
328 print '<div class="clearboth"></div><br>';
329
330 print dol_get_fiche_end();
331 }
332
333
334 /*
335 * Boutons actions
336 */
337 print '<div class="tabsAction">';
338 $parameters = array();
339 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
340 // modified by hook
341 if (empty($reshook)) {
342 if ($action != "create" && $action != "edit") {
343 // Edit resource
344 if ($user->hasRight('resource', 'write')) {
345 print '<div class="inline-block divButAction">';
346 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans('Modify').'</a>';
347 print '</div>';
348 }
349 }
350 if ($action != "create" && $action != "edit") {
351 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
352 $buttonId = 'action-delete-no-ajax';
353 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
354 $deleteUrl = '';
355 $buttonId = 'action-delete';
356 }
357 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
358 }
359 }
360 print '</div>';
361} else {
363}
364
365// End of page
366llxFooter();
367$db->close();
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.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.