card.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. * \file htdocs/asset/card.php
  20. * \ingroup asset
  21. * \brief Page to create/edit/view asset
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("asset"));
  30. // Get parameters
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'aZ09');
  34. $confirm = GETPOST('confirm', 'alpha');
  35. $cancel = GETPOST('cancel', 'aZ09');
  36. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'assetcard'; // To manage different context of search
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  39. // Initialize technical objects
  40. $object = new Asset($db);
  41. $extrafields = new ExtraFields($db);
  42. $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
  43. $hookmanager->initHooks(array('assetcard', 'globalcard')); // Note that conf->hooks_modules contains array
  44. // Fetch optionals attributes and labels
  45. $extrafields->fetch_name_optionals_label($object->table_element);
  46. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  47. // Initialize array of search criterias
  48. $search_all = GETPOST("search_all", 'alpha');
  49. $search = array();
  50. foreach ($object->fields as $key => $val) {
  51. if (GETPOST('search_'.$key, 'alpha')) {
  52. $search[$key] = GETPOST('search_'.$key, 'alpha');
  53. }
  54. }
  55. if (empty($action) && empty($id) && empty($ref)) {
  56. $action = 'view';
  57. }
  58. // Load object
  59. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  60. // Security check
  61. if (!empty($user->socid)) {
  62. $socid = $user->socid;
  63. }
  64. $result = restrictedArea($user, 'asset', $id);
  65. $permissiontoread = $user->rights->asset->read;
  66. $permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  67. $permissiontodelete = $user->rights->asset->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  68. $permissionnote = $user->rights->asset->write; // Used by the include of actions_setnotes.inc.php
  69. $permissiondellink = $user->rights->asset->write; // Used by the include of actions_dellink.inc.php
  70. $upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1];
  71. /*
  72. * Actions
  73. */
  74. $parameters = array();
  75. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) {
  77. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  78. }
  79. if (empty($reshook)) {
  80. $error = 0;
  81. $backurlforlist = dol_buildpath('/asset/list.php', 1);
  82. // Actions cancel, add, update or delete
  83. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  84. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  85. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  86. // Actions when linking object each other
  87. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  88. // Actions when printing a doc from card
  89. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  90. // Action to move up and down lines of object
  91. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  92. // Action to build doc
  93. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  94. if ($action == 'set_thirdparty' && $permissiontoadd) {
  95. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY');
  96. }
  97. if ($action == 'classin' && $permissiontoadd) {
  98. $object->setProject(GETPOST('projectid', 'int'));
  99. }
  100. // Actions to send emails
  101. $triggersendname = 'ASSET_SENTBYMAIL';
  102. $autocopy = 'MAIN_MAIL_AUTOCOPY_ASSET_TO';
  103. $trackid = 'asset'.$object->id;
  104. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  105. }
  106. /*
  107. * View
  108. *
  109. */
  110. $form = new Form($db);
  111. $formfile = new FormFile($db);
  112. $title = $langs->trans("Asset").' - '.$langs->trans("Card");
  113. $help_url = '';
  114. llxHeader('', $title, $help_url);
  115. // Part to create
  116. if ($action == 'create') {
  117. print load_fiche_titre($langs->trans("NewAsset"), '', $object->picto);
  118. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  119. print '<input type="hidden" name="token" value="'.newToken().'">';
  120. print '<input type="hidden" name="action" value="add">';
  121. if ($backtopage) {
  122. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  123. }
  124. if ($backtopageforcancel) {
  125. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  126. }
  127. print dol_get_fiche_head(array(), '');
  128. print '<table class="border centpercent tableforfieldcreate">'."\n";
  129. // Common attributes
  130. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  131. // Other attributes
  132. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  133. print '</table>'."\n";
  134. print dol_get_fiche_end();
  135. print '<div class="center">';
  136. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  137. print '&nbsp; ';
  138. 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
  139. print '</div>';
  140. print '</form>';
  141. //dol_set_focus('input[name="ref"]');
  142. }
  143. // Part to edit record
  144. if (($id || $ref) && $action == 'edit') {
  145. print load_fiche_titre($langs->trans("Assets"));
  146. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  147. print '<input type="hidden" name="token" value="'.newToken().'">';
  148. print '<input type="hidden" name="action" value="update">';
  149. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  150. print '<input type="hidden" name="id" value="'.$object->id.'">';
  151. if ($backtopage) {
  152. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  153. }
  154. if ($backtopageforcancel) {
  155. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  156. }
  157. print dol_get_fiche_head();
  158. print '<table class="border centpercent tableforfieldedit">'."\n";
  159. // Common attributes
  160. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  161. // Other attributes
  162. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  163. print '</table>';
  164. print dol_get_fiche_end();
  165. print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
  166. print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  167. print '</div>';
  168. print '</form>';
  169. }
  170. // Part to show record
  171. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  172. $res = $object->fetch_optionals();
  173. $head = asset_prepare_head($object);
  174. print dol_get_fiche_head($head, 'card', $langs->trans("Asset"), -1, $object->picto);
  175. $formconfirm = '';
  176. // Confirmation to delete
  177. if ($action == 'delete') {
  178. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAssets'), $langs->trans('ConfirmDeleteAsset'), 'confirm_delete', '', 0, 1);
  179. }
  180. // Call Hook formConfirm
  181. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  182. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  183. if (empty($reshook)) {
  184. $formconfirm .= $hookmanager->resPrint;
  185. } elseif ($reshook > 0) {
  186. $formconfirm = $hookmanager->resPrint;
  187. }
  188. // Print form confirm
  189. print $formconfirm;
  190. // Object card
  191. // ------------------------------------------------------------
  192. $linkback = '<a href="'.dol_buildpath('/asset/list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  193. $morehtmlref = '<div class="refidno">';
  194. /*
  195. // Ref bis
  196. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', 0, 1);
  197. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', null, null, '', 1);
  198. // Thirdparty
  199. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  200. */
  201. $morehtmlref .= '</div>';
  202. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  203. print '<div class="fichecenter">';
  204. print '<div class="fichehalfleft">';
  205. print '<div class="underbanner clearboth"></div>';
  206. print '<table class="border centpercent">'."\n";
  207. // Common attributes
  208. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field
  209. //unset($object->fields['fk_project']); // Hide field already shown in banner
  210. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  212. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  213. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  214. print '</table>';
  215. print '</div>';
  216. print '<div class="clearboth"></div>';
  217. print dol_get_fiche_end();
  218. /*
  219. * Buttons
  220. */
  221. if ($user->socid == 0) {
  222. print '<div class="tabsAction">';
  223. $parameters = array();
  224. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  225. if (empty($reshook)) {
  226. if ($user->rights->asset->write) {
  227. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'."\n";
  228. } else {
  229. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  230. }
  231. if ($user->rights->asset->delete) {
  232. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
  233. } else {
  234. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  235. }
  236. }
  237. print "</div>";
  238. }
  239. if ($action != 'presend') {
  240. print '<div class="fichecenter"><div class="fichehalfleft">';
  241. print '<a name="builddoc"></a>'; // ancre
  242. // Documents
  243. $filename = dol_sanitizeFileName($object->ref);
  244. $filedir = $conf->contrat->dir_output."/".dol_sanitizeFileName($object->ref);
  245. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  246. $genallowed = $user->rights->asset->read; // If you can read, you can build the PDF to read content
  247. $delallowed = $user->rights->asset->write; // If you can create/edit, you can remove a file on card
  248. print $formfile->showdocuments('asset', $filename, $filedir, $urlsource, 0, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  249. // Show links to link elements
  250. $linktoelem = $form->showLinkToObjectBlock($object, null, array('asset'));
  251. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  252. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  253. $MAXEVENT = 10;
  254. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/asset/info.php?id='.$object->id);
  255. // List of actions on element
  256. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  257. $formactions = new FormActions($db);
  258. $somethingshown = $formactions->showactions($object, 'asset', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
  259. print '</div></div></div>';
  260. }
  261. }
  262. // End of page
  263. llxFooter();
  264. $db->close();