PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/inventory/card.php

https://github.com/atm-maxime/dolibarr
PHP | 425 lines | 207 code | 90 blank | 128 comment | 40 complexity | 60f99b75c3713612ac8aa940ba325db4 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, CC-BY-SA-4.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0, LGPL-2.0, MIT
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  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. /**
  18. * \file htdocs/product/inventory/card.php
  19. * \ingroup inventory
  20. * \brief Inventory card
  21. */
  22. require '../../main.inc.php';
  23. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  24. include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
  25. include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array("stocks", "other"));
  28. // Get parameters
  29. $id = GETPOST('id', 'int');
  30. $ref = GETPOST('ref', 'alpha');
  31. $action = GETPOST('action', 'aZ09');
  32. $confirm = GETPOST('confirm', 'alpha');
  33. $cancel = GETPOST('cancel', 'aZ09');
  34. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
  35. $backtopage = GETPOST('backtopage', 'alpha');
  36. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  37. {
  38. $result = restrictedArea($user, 'stock', $id);
  39. }
  40. else
  41. {
  42. $result = restrictedArea($user, 'stock', $id, '', 'inventory_advance');
  43. }
  44. // Initialize technical objects
  45. $object = new Inventory($db);
  46. $extrafields = new ExtraFields($db);
  47. $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
  48. $hookmanager->initHooks(array('inventorycard')); // Note that conf->hooks_modules contains array
  49. // Fetch optionals attributes and labels
  50. $extrafields->fetch_name_optionals_label($object->table_element);
  51. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  52. // Initialize array of search criterias
  53. $search_all = trim(GETPOST("search_all", 'alpha'));
  54. $search = array();
  55. foreach ($object->fields as $key => $val)
  56. {
  57. if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  58. }
  59. if (empty($action) && empty($id) && empty($ref)) $action = 'view';
  60. // Load object
  61. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  62. // Security check - Protection if external user
  63. //if ($user->socid > 0) accessforbidden();
  64. //if ($user->socid > 0) $socid = $user->socid;
  65. //$result = restrictedArea($user, 'mymodule', $id);
  66. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  67. {
  68. $permissiontoadd = $user->rights->stock->creer;
  69. $permissiontodelete = $user->rights->stock->supprimer;
  70. }
  71. else
  72. {
  73. $permissiontoadd = $user->rights->stock->inventory_advance->write;
  74. $permissiontodelete = $user->rights->stock->inventory_advance->write;
  75. }
  76. /*
  77. * Actions
  78. */
  79. $parameters = array();
  80. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  81. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. if (empty($reshook))
  83. {
  84. $error = 0;
  85. $backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php';
  86. // Actions cancel, add, update, delete or clone
  87. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  88. // Actions when linking object each other
  89. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  90. // Actions when printing a doc from card
  91. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  92. // Actions to send emails
  93. /*$triggersendname = 'MYOBJECT_SENTBYMAIL';
  94. $autocopy='MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
  95. $trackid='myobject'.$object->id;
  96. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';*/
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. llxHeader('', $langs->trans('Inventory'), '');
  103. // Example : Adding jquery code
  104. print '<script type="text/javascript" language="javascript">
  105. jQuery(document).ready(function() {
  106. function init_myfunc()
  107. {
  108. jQuery("#myid").removeAttr(\'disabled\');
  109. jQuery("#myid").attr(\'disabled\',\'disabled\');
  110. }
  111. init_myfunc();
  112. jQuery("#mybutton").click(function() {
  113. init_myfunc();
  114. });
  115. });
  116. </script>';
  117. // Part to create
  118. if ($action == 'create')
  119. {
  120. print load_fiche_titre($langs->trans("NewInventory"), '', 'product');
  121. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  122. print '<input type="hidden" name="token" value="'.newToken().'">';
  123. print '<input type="hidden" name="action" value="add">';
  124. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  125. dol_fiche_head(array(), '');
  126. print '<table class="border centpercent tableforfieldcreate">'."\n";
  127. // Common attributes
  128. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  129. // Other attributes
  130. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  131. print '</table>'."\n";
  132. dol_fiche_end();
  133. print '<div class="center">';
  134. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  135. print '&nbsp; ';
  136. 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
  137. print '</div>';
  138. print '</form>';
  139. dol_set_focus('input[name="ref"]');
  140. }
  141. // Part to edit record
  142. if (($id || $ref) && $action == 'edit')
  143. {
  144. print load_fiche_titre($langs->trans("Inventory"), '', 'product');
  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="update">';
  148. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  149. print '<input type="hidden" name="id" value="'.$object->id.'">';
  150. dol_fiche_head();
  151. print '<table class="border centpercent tableforfieldcreate">'."\n";
  152. // Common attributes
  153. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  154. // Other attributes
  155. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  156. print '</table>';
  157. dol_fiche_end();
  158. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  159. print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  160. print '</div>';
  161. print '</form>';
  162. }
  163. // Part to show record
  164. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
  165. {
  166. $res = $object->fetch_optionals();
  167. $head = inventoryPrepareHead($object);
  168. dol_fiche_head($head, 'card', $langs->trans("Inventory"), -1, 'stock');
  169. $formconfirm = '';
  170. // Confirmation to delete
  171. if ($action == 'delete') {
  172. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
  173. }
  174. // Confirmation to delete line
  175. if ($action == 'deleteline')
  176. {
  177. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  178. }
  179. // Clone confirmation
  180. if ($action == 'clone') {
  181. // Create an array for form
  182. $formquestion = array();
  183. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  184. }
  185. // Call Hook formConfirm
  186. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  187. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  188. if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
  189. elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
  190. // Print form confirm
  191. print $formconfirm;
  192. // Object card
  193. // ------------------------------------------------------------
  194. $linkback = '<a href="'.DOL_URL_ROOT.'/product/inventory/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  195. $morehtmlref = '<div class="refidno">';
  196. /*
  197. // Ref bis
  198. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', 0, 1);
  199. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', null, null, '', 1);
  200. // Thirdparty
  201. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  202. // Project
  203. if (! empty($conf->projet->enabled))
  204. {
  205. $langs->load("projects");
  206. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  207. if ($user->rights->inventory->creer)
  208. {
  209. if ($action != 'classify')
  210. {
  211. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  212. if ($action == 'classify') {
  213. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  214. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  215. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  216. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  217. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  218. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  219. $morehtmlref.='</form>';
  220. } else {
  221. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  222. }
  223. }
  224. } else {
  225. if (! empty($object->fk_project)) {
  226. $proj = new Project($db);
  227. $proj->fetch($object->fk_project);
  228. $morehtmlref.=$proj->getNomUrl();
  229. } else {
  230. $morehtmlref.='';
  231. }
  232. }
  233. }
  234. */
  235. $morehtmlref .= '</div>';
  236. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  237. print '<div class="fichecenter">';
  238. print '<div class="fichehalfleft">';
  239. print '<div class="underbanner clearboth"></div>';
  240. print '<table class="border centpercent tableforfield">'."\n";
  241. // Common attributes
  242. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  243. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  244. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  245. print '</table>';
  246. print '</div>';
  247. print '</div>';
  248. print '<div class="clearboth"></div>';
  249. dol_fiche_end();
  250. // Buttons for actions
  251. if ($action != 'presend' && $action != 'editline') {
  252. print '<div class="tabsAction">'."\n";
  253. $parameters = array();
  254. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  255. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  256. if (empty($reshook))
  257. {
  258. // Send
  259. if (empty($user->socid)) {
  260. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
  261. }
  262. if ($permissiontoadd)
  263. {
  264. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'."\n";
  265. }
  266. else
  267. {
  268. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  269. }
  270. if ($permissiontoadd)
  271. {
  272. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Validate").'</a>'."\n";
  273. }
  274. else
  275. {
  276. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Validate').'</a>'."\n";
  277. }
  278. if ($permissiontodelete)
  279. {
  280. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n";
  281. }
  282. else
  283. {
  284. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  285. }
  286. }
  287. print '</div>'."\n";
  288. }
  289. // Select mail models is same action as presend
  290. if (GETPOST('modelselected')) {
  291. $action = 'presend';
  292. }
  293. if ($action != 'presend')
  294. {
  295. print '<div class="fichecenter"><div class="fichehalfleft">';
  296. print '<a name="builddoc"></a>'; // ancre
  297. // Documents
  298. /*$objref = dol_sanitizeFileName($object->ref);
  299. $relativepath = $comref . '/' . $comref . '.pdf';
  300. $filedir = $conf->mymodule->dir_output . '/' . $objref;
  301. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  302. $genallowed = $user->rights->mymodule->read; // If you can read, you can build the PDF to read content
  303. $delallowed = $user->rights->mymodule->create; // If you can create/edit, you can remove a file on card
  304. print $formfile->showdocuments('mymodule', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  305. */
  306. // Show links to link elements
  307. $linktoelem = $form->showLinkToObjectBlock($object, null, array('inventory'));
  308. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  309. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  310. $MAXEVENT = 10;
  311. $morehtmlright = '<a href="'.dol_buildpath('/product/inventory/inventory_info.php', 1).'?id='.$object->id.'">';
  312. $morehtmlright .= $langs->trans("SeeAll");
  313. $morehtmlright .= '</a>';
  314. // List of actions on element
  315. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  316. $formactions = new FormActions($db);
  317. $somethingshown = $formactions->showactions($object, 'inventory', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
  318. print '</div></div></div>';
  319. }
  320. //Select mail models is same action as presend
  321. /*
  322. if (GETPOST('modelselected')) $action = 'presend';
  323. // Presend form
  324. $modelmail='inventory';
  325. $defaulttopic='InformationMessage';
  326. $diroutput = $conf->product->dir_output.'/inventory';
  327. $trackid = 'stockinv'.$object->id;
  328. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  329. */
  330. }
  331. // End of page
  332. llxFooter();
  333. $db->close();