card.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 <http://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', 'alpha');
  34. $cancel = GETPOST('cancel', 'aZ09');
  35. $backtopage = GETPOST('backtopage', 'alpha');
  36. // Initialize technical objects
  37. $object=new Asset($db);
  38. $extrafields = new ExtraFields($db);
  39. $diroutputmassaction=$conf->asset->dir_output . '/temp/massgeneration/'.$user->id;
  40. $hookmanager->initHooks(array('assetcard')); // Note that conf->hooks_modules contains array
  41. // Fetch optionals attributes and labels
  42. $extralabels = $extrafields->fetch_name_optionals_label('asset');
  43. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  44. // Initialize array of search criterias
  45. $search_all=trim(GETPOST("search_all",'alpha'));
  46. $search=array();
  47. foreach($object->fields as $key => $val)
  48. {
  49. if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
  50. }
  51. if (empty($action) && empty($id) && empty($ref)) $action='view';
  52. // Security check - Protection if external user
  53. //if ($user->societe_id > 0) access_forbidden();
  54. //if ($user->societe_id > 0) $socid = $user->societe_id;
  55. //$result = restrictedArea($user, 'asset', $id);
  56. // fetch optionals attributes and labels
  57. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  58. // Load object
  59. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  60. /*
  61. * Actions
  62. *
  63. * Put here all code to do according to value of "action" parameter
  64. */
  65. $parameters=array();
  66. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  67. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  68. if (empty($reshook))
  69. {
  70. $error=0;
  71. $permissiontoadd = $user->rights->asset->create;
  72. $permissiontodelete = $user->rights->asset->delete;
  73. $backurlforlist = dol_buildpath('/asset/list.php',1);
  74. // Actions cancel, add, update or delete
  75. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  76. // Actions when printing a doc from card
  77. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  78. // Actions to send emails
  79. $trigger_name='ASSET_SENTBYMAIL';
  80. $autocopy='MAIN_MAIL_AUTOCOPY_ASSET_TO';
  81. $trackid='asset'.$object->id;
  82. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  83. }
  84. /*
  85. * View
  86. *
  87. * Put here all code to build page
  88. */
  89. $form=new Form($db);
  90. $formfile=new FormFile($db);
  91. $title=$langs->trans("Assets").' - '.$langs->trans("Card");
  92. $help_url='';
  93. llxHeader('',$title,$help_url);
  94. // Example : Adding jquery code
  95. print '<script type="text/javascript" language="javascript">
  96. jQuery(document).ready(function() {
  97. function init_myfunc()
  98. {
  99. jQuery("#myid").removeAttr(\'disabled\');
  100. jQuery("#myid").attr(\'disabled\',\'disabled\');
  101. }
  102. init_myfunc();
  103. jQuery("#mybutton").click(function() {
  104. init_myfunc();
  105. });
  106. });
  107. </script>';
  108. // Part to create
  109. if ($action == 'create')
  110. {
  111. print load_fiche_titre($langs->trans("NewAsset"));
  112. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  113. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  114. print '<input type="hidden" name="action" value="add">';
  115. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  116. dol_fiche_head(array(), '');
  117. print '<table class="border centpercent">'."\n";
  118. // Common attributes
  119. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  120. // Other attributes
  121. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  122. print '</table>'."\n";
  123. dol_fiche_end();
  124. print '<div class="center">';
  125. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  126. print '&nbsp; ';
  127. print '<input type="'.($backtopage?"submit":"button").'" class="button" 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
  128. print '</div>';
  129. print '</form>';
  130. }
  131. // Part to edit record
  132. if (($id || $ref) && $action == 'edit')
  133. {
  134. print load_fiche_titre($langs->trans("Assets"));
  135. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<input type="hidden" name="action" value="update">';
  138. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  139. print '<input type="hidden" name="id" value="'.$object->id.'">';
  140. dol_fiche_head();
  141. print '<table class="border centpercent">'."\n";
  142. // Common attributes
  143. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  144. // Other attributes
  145. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
  146. print '</table>';
  147. dol_fiche_end();
  148. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  149. print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  150. print '</div>';
  151. print '</form>';
  152. }
  153. // Part to show record
  154. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
  155. {
  156. $res = $object->fetch_optionals($object->id, $extralabels);
  157. $head = asset_prepare_head($object);
  158. dol_fiche_head($head, 'card', $langs->trans("Asset"), -1, 'generic');
  159. $formconfirm = '';
  160. // Confirmation to delete
  161. if ($action == 'delete')
  162. {
  163. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteAssets'), $langs->trans('ConfirmDeleteAssets'), 'confirm_delete', '', 0, 1);
  164. }
  165. // Confirmation of action xxxx
  166. if ($action == 'xxx')
  167. {
  168. $formquestion=array();
  169. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  170. }
  171. // Call Hook formConfirm
  172. $parameters = array('lineid' => $lineid);
  173. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  174. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  175. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
  176. // Print form confirm
  177. print $formconfirm;
  178. // Object card
  179. // ------------------------------------------------------------
  180. $linkback = '<a href="' .dol_buildpath('/asset/list.php',1) . '?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  181. $morehtmlref='<div class="refidno">';
  182. /*
  183. // Ref bis
  184. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', 0, 1);
  185. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->asset->creer, 'string', '', null, null, '', 1);
  186. // Thirdparty
  187. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  188. */
  189. $morehtmlref.='</div>';
  190. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  191. print '<div class="fichecenter">';
  192. print '<div class="fichehalfleft">';
  193. print '<div class="underbanner clearboth"></div>';
  194. print '<table class="border centpercent">'."\n";
  195. // Common attributes
  196. //$keyforbreak='fieldkeytoswithonsecondcolumn';
  197. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  198. // Other attributes
  199. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  200. print '</table>';
  201. print '</div>';
  202. print '</div>';
  203. print '</div>';
  204. print '<div class="clearboth"></div><br>';
  205. dol_fiche_end();
  206. // Buttons for actions
  207. if ($action != 'presend' && $action != 'editline') {
  208. print '<div class="tabsAction">'."\n";
  209. $parameters=array();
  210. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  211. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  212. if (empty($reshook))
  213. {
  214. // Send
  215. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
  216. if ($user->rights->asset->write)
  217. {
  218. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'."\n";
  219. }
  220. else
  221. {
  222. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  223. }
  224. if ($user->rights->asset->delete)
  225. {
  226. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n";
  227. }
  228. else
  229. {
  230. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  231. }
  232. }
  233. print '</div>'."\n";
  234. }
  235. // Select mail models is same action as presend
  236. if (GETPOST('modelselected')) {
  237. $action = 'presend';
  238. }
  239. if ($action != 'presend')
  240. {
  241. print '<div class="fichecenter"><div class="fichehalfleft">';
  242. print '<a name="builddoc"></a>'; // ancre
  243. // Documents
  244. /*$objref = dol_sanitizeFileName($object->ref);
  245. $relativepath = $comref . '/' . $comref . '.pdf';
  246. $filedir = $conf->asset->dir_output . '/' . $objref;
  247. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  248. $genallowed = $user->rights->asset->read; // If you can read, you can build the PDF to read content
  249. $delallowed = $user->rights->asset->create; // If you can create/edit, you can remove a file on card
  250. print $formfile->showdocuments('asset', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  251. */
  252. // Show links to link elements
  253. $linktoelem = $form->showLinkToObjectBlock($object, null, array('asset'));
  254. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  255. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  256. $MAXEVENT = 10;
  257. $morehtmlright = '<a href="'.dol_buildpath('/asset/asset_info.php', 1).'?id='.$object->id.'">';
  258. $morehtmlright.= $langs->trans("SeeAll");
  259. $morehtmlright.= '</a>';
  260. // List of actions on element
  261. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  262. $formactions = new FormActions($db);
  263. $somethingshown = $formactions->showactions($object, 'asset', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
  264. print '</div></div></div>';
  265. }
  266. //Select mail models is same action as presend
  267. /*
  268. if (GETPOST('modelselected')) $action = 'presend';
  269. // Presend form
  270. $modelmail='inventory';
  271. $defaulttopic='InformationMessage';
  272. $diroutput = $conf->product->dir_output.'/inventory';
  273. $trackid = 'stockinv'.$object->id;
  274. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  275. */
  276. }
  277. // End of page
  278. llxFooter();
  279. $db->close();