1<?php 2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> 3 * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * \file htdocs/asset/card.php 21 * \ingroup asset 22 * \brief Page to create/edit/view asset 23 */ 24 25require '../main.inc.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php'; 27require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 30 31// Load translation files required by the page 32$langs->loadLangs(array("asset")); 33 34// Get parameters 35$id = GETPOST('id', 'int'); 36$ref = GETPOST('ref', 'alpha'); 37$action = GETPOST('action', 'aZ09'); 38$confirm = GETPOST('confirm', 'alpha'); 39$cancel = GETPOST('cancel', 'aZ09'); 40$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'assetcard'; // To manage different context of search 41$backtopage = GETPOST('backtopage', 'alpha'); 42$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); 43 44// Initialize technical objects 45$object = new Asset($db); 46$extrafields = new ExtraFields($db); 47$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id; 48$hookmanager->initHooks(array('assetcard', 'globalcard')); // Note that conf->hooks_modules contains array 49 50// Fetch optionals attributes and labels 51$extrafields->fetch_name_optionals_label($object->table_element); 52 53$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); 54 55// Initialize array of search criterias 56$search_all = GETPOST("search_all", 'alpha'); 57$search = array(); 58foreach ($object->fields as $key => $val) 59{ 60 if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); 61} 62 63if (empty($action) && empty($id) && empty($ref)) $action = 'view'; 64 65// Load object 66include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. 67 68// Security check 69if (!empty($user->socid)) $socid = $user->socid; 70$result = restrictedArea($user, 'asset', $id); 71 72$permissiontoread = $user->rights->asset->read; 73$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php 74$permissiontodelete = $user->rights->asset->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); 75$permissionnote = $user->rights->asset->write; // Used by the include of actions_setnotes.inc.php 76$permissiondellink = $user->rights->asset->write; // Used by the include of actions_dellink.inc.php 77$upload_dir = $conf->mymodule->multidir_output[isset($object->entity) ? $object->entity : 1]; 78 79 80/* 81 * Actions 82 */ 83 84$parameters = array(); 85$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 86if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 87 88if (empty($reshook)) 89{ 90 $error = 0; 91 92 $backurlforlist = dol_buildpath('/asset/list.php', 1); 93 94 // Actions cancel, add, update or delete 95 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; 96 97 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen 98 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; 99 100 // Actions when linking object each other 101 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; 102 103 // Actions when printing a doc from card 104 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; 105 106 // Action to move up and down lines of object 107 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; 108 109 // Action to build doc 110 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; 111 112 if ($action == 'set_thirdparty' && $permissiontoadd) 113 { 114 $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY'); 115 } 116 if ($action == 'classin' && $permissiontoadd) 117 { 118 $object->setProject(GETPOST('projectid', 'int')); 119 } 120 121 // Actions to send emails 122 $triggersendname = 'ASSET_SENTBYMAIL'; 123 $autocopy = 'MAIN_MAIL_AUTOCOPY_ASSET_TO'; 124 $trackid = 'asset'.$object->id; 125 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; 126} 127 128/* 129 * View 130 * 131 */ 132 133$form = new Form($db); 134$formfile = new FormFile($db); 135 136$title = $langs->trans("Asset").' - '.$langs->trans("Card"); 137$help_url = ''; 138llxHeader('', $title, $help_url); 139 140// Part to create 141if ($action == 'create') 142{ 143 print load_fiche_titre($langs->trans("NewAsset"), '', 'accountancy'); 144 145 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 146 print '<input type="hidden" name="token" value="'.newToken().'">'; 147 print '<input type="hidden" name="action" value="add">'; 148 if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 149 if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">'; 150 151 print dol_get_fiche_head(array(), ''); 152 153 print '<table class="border centpercent tableforfieldcreate">'."\n"; 154 155 // Common attributes 156 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; 157 158 // Other attributes 159 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; 160 161 print '</table>'."\n"; 162 163 print dol_get_fiche_end(); 164 165 print '<div class="center">'; 166 print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">'; 167 print ' '; 168 print '<input type="'.($backtopage ? "submit" : "button").'" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage 169 print '</div>'; 170 171 print '</form>'; 172 173 //dol_set_focus('input[name="ref"]'); 174} 175 176// Part to edit record 177if (($id || $ref) && $action == 'edit') 178{ 179 print load_fiche_titre($langs->trans("Assets")); 180 181 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 182 print '<input type="hidden" name="token" value="'.newToken().'">'; 183 print '<input type="hidden" name="action" value="update">'; 184 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 185 print '<input type="hidden" name="id" value="'.$object->id.'">'; 186 if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 187 if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">'; 188 189 print dol_get_fiche_head(); 190 191 print '<table class="border centpercent tableforfieldedit">'."\n"; 192 193 // Common attributes 194 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; 195 196 // Other attributes 197 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; 198 199 print '</table>'; 200 201 print dol_get_fiche_end(); 202 203 print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">'; 204 print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; 205 print '</div>'; 206 207 print '</form>'; 208} 209 210// Part to show record 211if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) 212{ 213 $res = $object->fetch_optionals(); 214 215 $head = asset_prepare_head($object); 216 print dol_get_fiche_head($head, 'card', $langs->trans("Asset"), -1, $object->picto); 217 218 $formconfirm = ''; 219 220 // Confirmation to delete 221 if ($action == 'delete') 222 { 223 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAssets'), $langs->trans('ConfirmDeleteAsset'), 'confirm_delete', '', 0, 1); 224 } 225 226 // Call Hook formConfirm 227 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); 228 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 229 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; 230 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; 231 232 // Print form confirm 233 print $formconfirm; 234 235 236 // Object card 237 // ------------------------------------------------------------ 238 $linkback = '<a href="'.dol_buildpath('/asset/list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 239 240 $morehtmlref = '<div class="refidno">'; 241 /* 242 // Ref bis 243 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', 0, 1); 244 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', null, null, '', 1); 245 // Thirdparty 246 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); 247 */ 248 $morehtmlref .= '</div>'; 249 250 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); 251 252 print '<div class="fichecenter">'; 253 print '<div class="fichehalfleft">'; 254 print '<div class="underbanner clearboth"></div>'; 255 print '<table class="border centpercent">'."\n"; 256 257 // Common attributes 258 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field 259 //unset($object->fields['fk_project']); // Hide field already shown in banner 260 //unset($object->fields['fk_soc']); // Hide field already shown in banner 261 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; 262 263 // Other attributes. Fields from hook formObjectOptions and Extrafields. 264 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; 265 266 print '</table>'; 267 print '</div>'; 268 269 print '<div class="clearboth"></div>'; 270 271 print dol_get_fiche_end(); 272 273 274 /* 275 * Buttons 276 */ 277 if ($user->socid == 0) 278 { 279 print '<div class="tabsAction">'; 280 281 $parameters = array(); 282 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 283 284 if (empty($reshook)) 285 { 286 if ($user->rights->asset->write) 287 { 288 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n"; 289 } else { 290 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n"; 291 } 292 293 if ($user->rights->asset->delete) 294 { 295 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n"; 296 } else { 297 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n"; 298 } 299 } 300 print "</div>"; 301 } 302 303 if ($action != 'presend') 304 { 305 print '<div class="fichecenter"><div class="fichehalfleft">'; 306 print '<a name="builddoc"></a>'; // ancre 307 308 // Documents 309 $filename = dol_sanitizeFileName($object->ref); 310 $filedir = $conf->contrat->dir_output."/".dol_sanitizeFileName($object->ref); 311 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; 312 $genallowed = $user->rights->asset->read; // If you can read, you can build the PDF to read content 313 $delallowed = $user->rights->asset->write; // If you can create/edit, you can remove a file on card 314 315 print $formfile->showdocuments('asset', $filename, $filedir, $urlsource, 0, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); 316 317 // Show links to link elements 318 $linktoelem = $form->showLinkToObjectBlock($object, null, array('asset')); 319 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); 320 321 print '</div><div class="fichehalfright"><div class="ficheaddleft">'; 322 323 $MAXEVENT = 10; 324 325 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/asset/info.php?id='.$object->id); 326 327 // List of actions on element 328 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; 329 $formactions = new FormActions($db); 330 $somethingshown = $formactions->showactions($object, 'asset', $socid, 1, '', $MAXEVENT, '', $morehtmlright); 331 332 print '</div></div></div>'; 333 } 334} 335 336 337// End of page 338llxFooter(); 339$db->close(); 340