voucherhistory_card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2024 László Szollősi
  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 voucherhistory_card.php
  20. * \ingroup voucher
  21. * \brief Page to create/edit/view voucherhistory
  22. */
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
  27. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
  28. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
  29. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  30. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
  31. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  32. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  33. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  34. //if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
  35. //if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  36. //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
  37. //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
  38. //if (! defined("MAIN_SECURITY_FORCECSP")) define('MAIN_SECURITY_FORCECSP', 'none'); // Disable all Content Security Policies
  39. //if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  40. //if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
  41. //if (! defined('NOSESSION')) define('NOSESSION', '1'); // Disable session
  42. // Load Dolibarr environment
  43. $res = 0;
  44. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  45. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  46. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  47. }
  48. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  49. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  50. $tmp2 = realpath(__FILE__);
  51. $i = strlen($tmp) - 1;
  52. $j = strlen($tmp2) - 1;
  53. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  54. $i--;
  55. $j--;
  56. }
  57. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  58. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  59. }
  60. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  61. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  62. }
  63. // Try main.inc.php using relative path
  64. if (!$res && file_exists("../main.inc.php")) {
  65. $res = @include "../main.inc.php";
  66. }
  67. if (!$res && file_exists("../../main.inc.php")) {
  68. $res = @include "../../main.inc.php";
  69. }
  70. if (!$res && file_exists("../../../main.inc.php")) {
  71. $res = @include "../../../main.inc.php";
  72. }
  73. if (!$res) {
  74. die("Include of main fails");
  75. }
  76. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  77. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  78. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  79. require_once DOL_DOCUMENT_ROOT . '/custom/voucher/class/helper.class.php';
  80. require_once DOL_DOCUMENT_ROOT . '/custom/voucher/class/voucherhistory.class.php';
  81. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  82. dol_include_once('/voucher/class/voucherhistory.class.php');
  83. dol_include_once('/voucher/lib/voucher_voucherhistory.lib.php');
  84. // Load translation files required by the page
  85. $langs->loadLangs(array("voucher@voucher", "other"));
  86. // Get parameters
  87. $id = GETPOST('id', 'int');
  88. $ref = GETPOST('ref', 'alpha');
  89. $lineid = GETPOST('lineid', 'int');
  90. $action = GETPOST('action', 'aZ09');
  91. $confirm = GETPOST('confirm', 'alpha');
  92. $cancel = GETPOST('cancel', 'aZ09');
  93. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search
  94. $backtopage = GETPOST('backtopage', 'alpha');
  95. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  96. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  97. $fk_product = GETPOST('fk_product', 'int');
  98. $eventId = GETPOST('eventId', 'int');
  99. //print_r($_REQUEST);exit;
  100. // Initialize technical objects
  101. $object = new Voucherhistory($db);
  102. $extrafields = new ExtraFields($db);
  103. $VoucherHelper = new VoucherHelper();
  104. $diroutputmassaction = $conf->voucher->dir_output . '/temp/massgeneration/' . $user->id;
  105. $hookmanager->initHooks(array('voucherhistorycard', 'globalcard')); // Note that conf->hooks_modules contains array
  106. // Fetch optionals attributes and labels
  107. $extrafields->fetch_name_optionals_label($object->table_element);
  108. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  109. // Initialize array of search criterias
  110. $search_all = GETPOST("search_all", 'alpha');
  111. $search = array();
  112. foreach ($object->fields as $key => $val) {
  113. if (GETPOST('search_' . $key, 'alpha')) {
  114. $search[$key] = GETPOST('search_' . $key, 'alpha');
  115. }
  116. }
  117. if (empty($action) && empty($id) && empty($ref)) {
  118. $action = 'view';
  119. }
  120. // Load object
  121. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  122. // There is several ways to check permission.
  123. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  124. $enablepermissioncheck = 0;
  125. if ($enablepermissioncheck) {
  126. $permissiontoread = $user->hasRight('voucher', 'voucherhistory', 'read');
  127. $permissiontoadd = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  128. $permissiontodelete = $user->hasRight('voucher', 'voucherhistory', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  129. $permissionnote = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_setnotes.inc.php
  130. $permissiondellink = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_dellink.inc.php
  131. } else {
  132. $permissiontoread = 1;
  133. $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  134. $permissiontodelete = 1;
  135. $permissionnote = 1;
  136. $permissiondellink = 1;
  137. }
  138. $upload_dir = $conf->voucher->multidir_output[isset($object->entity) ? $object->entity : 1] . '/voucherhistory';
  139. // Security check (enable the most restrictive one)
  140. //if ($user->socid > 0) accessforbidden();
  141. //if ($user->socid > 0) $socid = $user->socid;
  142. //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  143. //restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
  144. if (!isModEnabled("voucher")) {
  145. accessforbidden();
  146. }
  147. if (!$permissiontoread) {
  148. accessforbidden();
  149. }
  150. /*
  151. * Actions
  152. */
  153. $parameters = array();
  154. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  155. if ($reshook < 0) {
  156. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  157. }
  158. if (empty($reshook)) {
  159. $error = 0;
  160. $backurlforlist = dol_buildpath('/voucher/voucherhistory_list.php', 1);
  161. if (empty($backtopage) || ($cancel && empty($id))) {
  162. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  163. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  164. $backtopage = $backurlforlist;
  165. } else {
  166. $backtopage = dol_buildpath('/voucher/voucherhistory_card.php', 1) . '?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
  167. }
  168. }
  169. }
  170. $triggermodname = 'VOUCHER_VOUCHERHISTORY_MODIFY'; // Name of trigger action code to execute when we modify record
  171. /* if ($action == 'add') {
  172. # Search Product
  173. $productObj = new Product($db);
  174. $productResult = $productObj->fetch($product_id);
  175. # Search bundle
  176. # Create BBTicket
  177. $newticket = new BbTicket($db);
  178. $newticket->fk_facture = null;
  179. $newticket->bundle_id = $fk_product;
  180. $newticket->usable_occasions = $ticket->usable_occasions;
  181. $newticket->usage = $ticket->usage;
  182. $newticket->available_at = $ticket->available_at;
  183. $newticket->validated_at = $ticket->validated_at;
  184. $newticket->expire_at = $ticket->expire_at;
  185. $newticket->ticket_id = $ticket->ticket_id;
  186. $newticket->fk_settlements_group_id = $group_id;
  187. if ($newticket->create($this->user) == -1) {
  188. dol_syslog("Nem sikerult a ticketek mentese. facture_id: " . $object->fk_facture);
  189. }
  190. # Save VoucherHistory OBject
  191. $object->fk_bundle = $fk_product;
  192. $object->fk_product = $fk_product;
  193. $object->fk_event = $eventId;
  194. $object->fk_ticket = 100;
  195. $object->pdf_path = 'asd';
  196. $object->date_creation = dol_now();
  197. $object->status = "0";
  198. } */
  199. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  200. //include DOL_DOCUMENT_ROOT . '/custom/voucher/core/actions_addupdatedelete.inc.php';
  201. include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
  202. // Actions when linking object each other
  203. include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
  204. // Actions when printing a doc from card
  205. include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
  206. // Action to move up and down lines of object
  207. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  208. // Action to build doc
  209. include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
  210. if ($action == 'set_thirdparty' && $permissiontoadd) {
  211. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  212. }
  213. if ($action == 'classin' && $permissiontoadd) {
  214. $object->setProject(GETPOST('projectid', 'int'));
  215. }
  216. // Actions to send emails
  217. $triggersendname = 'VOUCHER_VOUCHERHISTORY_SENTBYMAIL';
  218. $autocopy = 'MAIN_MAIL_AUTOCOPY_VOUCHERHISTORY_TO';
  219. $trackid = 'voucherhistory' . $object->id;
  220. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  221. }
  222. /*
  223. * View
  224. *
  225. * Put here all code to build page
  226. */
  227. $form = new Form($db);
  228. $formfile = new FormFile($db);
  229. $formproject = new FormProjets($db);
  230. $title = $langs->trans("Voucherhistory");
  231. $help_url = '';
  232. llxHeader('', $title, $help_url);
  233. // Part to create
  234. if ($action == 'create') {
  235. if (empty($permissiontoadd)) {
  236. accessforbidden('NotEnoughPermissions', 0, 1);
  237. }
  238. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Voucherhistory")), '', 'object_' . $object->picto);
  239. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  240. print '<input type="hidden" name="token" value="' . newToken() . '">';
  241. print '<input type="hidden" name="action" value="add">';
  242. if ($backtopage) {
  243. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  244. }
  245. if ($backtopageforcancel) {
  246. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  247. }
  248. print $_SESSION['token'];
  249. print '<br>';
  250. print $_SESSION['newtoken'];
  251. print dol_get_fiche_head(array(), '');
  252. // Set some default values
  253. //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
  254. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  255. // Common attributes
  256. //include DOL_DOCUMENT_ROOT . '/custom/voucher/core/tpl/commonfields_add.tpl.php';
  257. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  258. // Other attributes
  259. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  260. print '</table>' . "\n";
  261. print dol_get_fiche_end();
  262. print $form->buttonsSaveCancel("Create");
  263. print '</form>';
  264. //dol_set_focus('input[name="ref"]');
  265. }
  266. // Part to edit record
  267. if (($id || $ref) && $action == 'edit') {
  268. print load_fiche_titre($langs->trans("Voucherhistory"), '', 'object_' . $object->picto);
  269. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  270. print '<input type="hidden" name="token" value="' . newToken() . '">';
  271. print '<input type="hidden" name="action" value="update">';
  272. print '<input type="hidden" name="id" value="' . $object->id . '">';
  273. if ($backtopage) {
  274. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  275. }
  276. if ($backtopageforcancel) {
  277. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  278. }
  279. print dol_get_fiche_head();
  280. print '<table class="border centpercent tableforfieldedit">' . "\n";
  281. // Common attributes
  282. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  283. // Other attributes
  284. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
  285. print '</table>';
  286. print dol_get_fiche_end();
  287. print $form->buttonsSaveCancel();
  288. print '</form>';
  289. }
  290. // Part to show record
  291. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  292. $head = voucherhistoryPrepareHead($object);
  293. print dol_get_fiche_head($head, 'card', $langs->trans("Voucherhistory"), -1, $object->picto);
  294. $formconfirm = '';
  295. // Confirmation to delete
  296. if ($action == 'delete') {
  297. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteVoucherhistory'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  298. }
  299. // Confirmation to delete line
  300. if ($action == 'deleteline') {
  301. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  302. }
  303. // Clone confirmation
  304. if ($action == 'clone') {
  305. // Create an array for form
  306. $formquestion = array();
  307. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  308. }
  309. // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
  310. if ($action == 'xxx') {
  311. $text = $langs->trans('ConfirmActionVoucherhistory', $object->ref);
  312. /*if (isModEnabled('notification'))
  313. {
  314. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  315. $notify = new Notify($db);
  316. $text .= '<br>';
  317. $text .= $notify->confirmMessage('VOUCHERHISTORY_CLOSE', $object->socid, $object);
  318. }*/
  319. $formquestion = array();
  320. /*
  321. $forcecombo=0;
  322. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  323. $formquestion = array(
  324. // 'text' => $langs->trans("ConfirmClone"),
  325. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  326. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  327. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  328. );
  329. */
  330. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  331. }
  332. // Call Hook formConfirm
  333. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  334. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  335. if (empty($reshook)) {
  336. $formconfirm .= $hookmanager->resPrint;
  337. } elseif ($reshook > 0) {
  338. $formconfirm = $hookmanager->resPrint;
  339. }
  340. // Print form confirm
  341. print $formconfirm;
  342. // Object card
  343. // ------------------------------------------------------------
  344. $linkback = '<a href="' . dol_buildpath('/voucher/voucherhistory_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  345. $morehtmlref = '<div class="refidno">';
  346. /*
  347. // Ref customer
  348. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
  349. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1);
  350. // Thirdparty
  351. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  352. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  353. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  354. }
  355. // Project
  356. if (isModEnabled('project')) {
  357. $langs->load("projects");
  358. $morehtmlref .= '<br>';
  359. if ($permissiontoadd) {
  360. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  361. if ($action != 'classify') {
  362. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  363. }
  364. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  365. } else {
  366. if (!empty($object->fk_project)) {
  367. $proj = new Project($db);
  368. $proj->fetch($object->fk_project);
  369. $morehtmlref .= $proj->getNomUrl(1);
  370. if ($proj->title) {
  371. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  372. }
  373. }
  374. }
  375. }
  376. */
  377. $morehtmlref .= '</div>';
  378. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  379. print '<div class="fichecenter">';
  380. print '<div class="fichehalfleft">';
  381. print '<div class="underbanner clearboth"></div>';
  382. print '<table class="border centpercent tableforfield">' . "\n";
  383. // Common attributes
  384. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  385. //unset($object->fields['fk_project']); // Hide field already shown in banner
  386. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  387. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  388. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  389. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  390. print '</table>';
  391. print '</div>';
  392. print '</div>';
  393. print '<div class="clearboth"></div>';
  394. print dol_get_fiche_end();
  395. /*
  396. * Lines
  397. */
  398. if (!empty($object->table_element_line)) {
  399. // Show object lines
  400. $result = $object->getLinesArray();
  401. print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
  402. <input type="hidden" name="token" value="' . newToken() . '">
  403. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
  404. <input type="hidden" name="mode" value="">
  405. <input type="hidden" name="page_y" value="">
  406. <input type="hidden" name="id" value="' . $object->id . '">
  407. ';
  408. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  409. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  410. }
  411. print '<div class="div-table-responsive-no-min">';
  412. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  413. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  414. }
  415. if (!empty($object->lines)) {
  416. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  417. }
  418. // Form to add new line
  419. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  420. if ($action != 'editline') {
  421. // Add products/services form
  422. $parameters = array();
  423. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  424. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  425. if (empty($reshook))
  426. $object->formAddObjectLine(1, $mysoc, $soc);
  427. }
  428. }
  429. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  430. print '</table>';
  431. }
  432. print '</div>';
  433. print "</form>\n";
  434. }
  435. // Buttons for actions
  436. if ($action != 'presend' && $action != 'editline') {
  437. print '<div class="tabsAction">' . "\n";
  438. $parameters = array();
  439. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  440. if ($reshook < 0) {
  441. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  442. }
  443. if (empty($reshook)) {
  444. // Send
  445. if (empty($user->socid)) {
  446. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&token=' . newToken() . '&mode=init#formmailbeforetitle');
  447. }
  448. // Back to draft
  449. if ($object->status == $object::STATUS_VALIDATED) {
  450. print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  451. }
  452. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
  453. // Validate
  454. if ($object->status == $object::STATUS_DRAFT) {
  455. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  456. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=confirm_validate&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  457. } else {
  458. $langs->load("errors");
  459. print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
  460. }
  461. }
  462. // Clone
  463. if ($permissiontoadd) {
  464. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . (!empty($object->socid) ? '&socid=' . $object->socid : '') . '&action=clone&token=' . newToken(), '', $permissiontoadd);
  465. }
  466. /*
  467. if ($permissiontoadd) {
  468. if ($object->status == $object::STATUS_ENABLED) {
  469. print dolGetButtonAction('', $langs->trans('Disable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
  470. } else {
  471. print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
  472. }
  473. }
  474. if ($permissiontoadd) {
  475. if ($object->status == $object::STATUS_VALIDATED) {
  476. print dolGetButtonAction('', $langs->trans('Cancel'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
  477. } else {
  478. print dolGetButtonAction('', $langs->trans('Re-Open'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
  479. }
  480. }
  481. */
  482. // Delete
  483. $params = array();
  484. print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=delete&token=' . newToken(), 'delete', $permissiontodelete, $params);
  485. }
  486. print '</div>' . "\n";
  487. }
  488. // Select mail models is same action as presend
  489. if (GETPOST('modelselected')) {
  490. $action = 'presend';
  491. }
  492. if ($action != 'presend') {
  493. print '<div class="fichecenter"><div class="fichehalfleft">';
  494. print '<a name="builddoc"></a>'; // ancre
  495. $includedocgeneration = 0;
  496. // Documents
  497. if ($includedocgeneration) {
  498. $objref = dol_sanitizeFileName($object->ref);
  499. $relativepath = $objref . '/' . $objref . '.pdf';
  500. $filedir = $conf->voucher->dir_output . '/' . $object->element . '/' . $objref;
  501. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  502. $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
  503. $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
  504. print $formfile->showdocuments('voucher:Voucherhistory', $object->element . '/' . $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  505. }
  506. // Show links to link elements
  507. $linktoelem = $form->showLinkToObjectBlock($object, null, array('voucherhistory'));
  508. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  509. print '</div><div class="fichehalfright">';
  510. $MAXEVENT = 10;
  511. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/voucher/voucherhistory_agenda.php', 1) . '?id=' . $object->id);
  512. // List of actions on element
  513. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  514. $formactions = new FormActions($db);
  515. $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  516. print '</div></div>';
  517. }
  518. //Select mail models is same action as presend
  519. if (GETPOST('modelselected')) {
  520. $action = 'presend';
  521. }
  522. // Presend form
  523. $modelmail = 'voucherhistory';
  524. $defaulttopic = 'InformationMessage';
  525. $diroutput = $conf->voucher->dir_output;
  526. $trackid = 'voucherhistory' . $object->id;
  527. include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
  528. }
  529. //print_r($_REQUEST);
  530. // End of page
  531. llxFooter();
  532. $db->close();
  533. //echo '<link rel="stylesheet" type="text/css" href="' . dol_buildpath('/custom/voucher/css/voucher.css', 1) . '">';
  534. //echo '<script type="text/javascript" src="' . dol_buildpath('/custom/voucher/scripts/voucher.js', 1) . '"></script>';