hotel_card.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. // Load Dolibarr environment
  3. $res = 0;
  4. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  5. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  6. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  7. }
  8. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  9. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  10. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  11. $i--; $j--;
  12. }
  13. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  14. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  15. }
  16. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  17. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  18. }
  19. // Try main.inc.php using relative path
  20. if (!$res && file_exists("../main.inc.php")) {
  21. $res = @include "../main.inc.php";
  22. }
  23. if (!$res && file_exists("../../main.inc.php")) {
  24. $res = @include "../../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../../main.inc.php")) {
  27. $res = @include "../../../main.inc.php";
  28. }
  29. if (!$res) {
  30. die("Include of main fails");
  31. }
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. dol_include_once('/settlements/class/hotel.class.php');
  36. dol_include_once('/settlements/lib/settlements_hotel.lib.php');
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("settlements@settlements", "other"));
  39. // Get parameters
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $lineid = GETPOST('lineid', 'int');
  43. $action = GETPOST('action', 'aZ09');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. $cancel = GETPOST('cancel', 'aZ09');
  46. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  47. $backtopage = GETPOST('backtopage', 'alpha');
  48. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  49. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  50. // Initialize technical objects
  51. $object = new Hotel($db);
  52. $extrafields = new ExtraFields($db);
  53. $diroutputmassaction = $conf->settlements->dir_output.'/temp/massgeneration/'.$user->id;
  54. $hookmanager->initHooks(array('hotelcard', 'globalcard')); // Note that conf->hooks_modules contains array
  55. // Fetch optionals attributes and labels
  56. $extrafields->fetch_name_optionals_label($object->table_element);
  57. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  58. // Initialize array of search criterias
  59. $search_all = GETPOST("search_all", 'alpha');
  60. $search = array();
  61. foreach ($object->fields as $key => $val) {
  62. if (GETPOST('search_'.$key, 'alpha')) {
  63. $search[$key] = GETPOST('search_'.$key, 'alpha');
  64. }
  65. }
  66. if (empty($action) && empty($id) && empty($ref)) {
  67. $action = 'view';
  68. }
  69. // Load object
  70. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  71. // There is several ways to check permission.
  72. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  73. $enablepermissioncheck = 0;
  74. if ($enablepermissioncheck) {
  75. $permissiontoread = $user->rights->settlements->hotel->read;
  76. $permissiontoadd = $user->rights->settlements->hotel->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  77. $permissiontodelete = $user->rights->settlements->hotel->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  78. $permissionnote = $user->rights->settlements->hotel->write; // Used by the include of actions_setnotes.inc.php
  79. $permissiondellink = $user->rights->settlements->hotel->write; // Used by the include of actions_dellink.inc.php
  80. } else {
  81. $permissiontoread = 1;
  82. $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  83. $permissiontodelete = 1;
  84. $permissionnote = 1;
  85. $permissiondellink = 1;
  86. }
  87. $upload_dir = $conf->settlements->multidir_output[isset($object->entity) ? $object->entity : 1].'/hotel';
  88. // Security check (enable the most restrictive one)
  89. //if ($user->socid > 0) accessforbidden();
  90. //if ($user->socid > 0) $socid = $user->socid;
  91. //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  92. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  93. if (empty($conf->settlements->enabled)) accessforbidden();
  94. if (!$permissiontoread) accessforbidden();
  95. /*
  96. * Actions
  97. */
  98. $parameters = array();
  99. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  100. if ($reshook < 0) {
  101. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  102. }
  103. if (empty($reshook)) {
  104. $error = 0;
  105. $backurlforlist = dol_buildpath('/settlements/hotel_list.php', 1);
  106. if (empty($backtopage) || ($cancel && empty($id))) {
  107. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  108. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  109. $backtopage = $backurlforlist;
  110. } else {
  111. $backtopage = dol_buildpath('/settlements/hotel_card.php', 1).'?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  112. }
  113. }
  114. }
  115. $triggermodname = 'SETTLEMENTS_HOTEL_MODIFY'; // Name of trigger action code to execute when we modify record
  116. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  117. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  118. // Actions when linking object each other
  119. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  120. // Actions when printing a doc from card
  121. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  122. // Action to move up and down lines of object
  123. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  124. // Action to build doc
  125. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  126. if ($action == 'set_thirdparty' && $permissiontoadd) {
  127. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  128. }
  129. if ($action == 'classin' && $permissiontoadd) {
  130. $object->setProject(GETPOST('projectid', 'int'));
  131. }
  132. // Actions to send emails
  133. $triggersendname = 'SETTLEMENTS_HOTEL_SENTBYMAIL';
  134. $autocopy = 'MAIN_MAIL_AUTOCOPY_HOTEL_TO';
  135. $trackid = 'hotel'.$object->id;
  136. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  137. }
  138. /*
  139. * View
  140. *
  141. * Put here all code to build page
  142. */
  143. $form = new Form($db);
  144. $formfile = new FormFile($db);
  145. $formproject = new FormProjets($db);
  146. $title = $langs->trans("Hotel");
  147. $help_url = '';
  148. llxHeader('', $title, $help_url);
  149. // Example : Adding jquery code
  150. // print '<script type="text/javascript">
  151. // jQuery(document).ready(function() {
  152. // function init_myfunc()
  153. // {
  154. // jQuery("#myid").removeAttr(\'disabled\');
  155. // jQuery("#myid").attr(\'disabled\',\'disabled\');
  156. // }
  157. // init_myfunc();
  158. // jQuery("#mybutton").click(function() {
  159. // init_myfunc();
  160. // });
  161. // });
  162. // </script>';
  163. // Part to create
  164. if ($action == 'create') {
  165. if (empty($permissiontoadd)) {
  166. accessforbidden($langs->trans('NotEnoughPermissions'), 0, 1);
  167. exit;
  168. }
  169. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Hotel")), '', 'object_'.$object->picto);
  170. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  171. print '<input type="hidden" name="token" value="'.newToken().'">';
  172. print '<input type="hidden" name="action" value="add">';
  173. if ($backtopage) {
  174. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  175. }
  176. if ($backtopageforcancel) {
  177. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  178. }
  179. print dol_get_fiche_head(array(), '');
  180. // Set some default values
  181. //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
  182. print '<table class="border centpercent tableforfieldcreate">'."\n";
  183. // Common attributes
  184. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  185. // Other attributes
  186. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  187. print '</table>'."\n";
  188. print dol_get_fiche_end();
  189. print $form->buttonsSaveCancel("Create");
  190. print '</form>';
  191. //dol_set_focus('input[name="ref"]');
  192. }
  193. // Part to edit record
  194. if (($id || $ref) && $action == 'edit') {
  195. print load_fiche_titre($langs->trans("Hotel"), '', 'object_'.$object->picto);
  196. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  197. print '<input type="hidden" name="token" value="'.newToken().'">';
  198. print '<input type="hidden" name="action" value="update">';
  199. print '<input type="hidden" name="id" value="'.$object->id.'">';
  200. if ($backtopage) {
  201. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  202. }
  203. if ($backtopageforcancel) {
  204. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  205. }
  206. print dol_get_fiche_head();
  207. print '<table class="border centpercent tableforfieldedit">'."\n";
  208. // Common attributes
  209. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  210. // Other attributes
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  212. print '</table>';
  213. print dol_get_fiche_end();
  214. print $form->buttonsSaveCancel();
  215. print '</form>';
  216. }
  217. // Part to show record
  218. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  219. $res = $object->fetch_optionals();
  220. $head = hotelPrepareHead($object);
  221. print dol_get_fiche_head(array(), '');
  222. $formconfirm = '';
  223. // Confirmation to delete
  224. if ($action == 'delete') {
  225. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteHotel'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  226. }
  227. // Confirmation to delete line
  228. if ($action == 'deleteline') {
  229. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  230. }
  231. // Call Hook formConfirm
  232. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  233. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  234. if (empty($reshook)) {
  235. $formconfirm .= $hookmanager->resPrint;
  236. } elseif ($reshook > 0) {
  237. $formconfirm = $hookmanager->resPrint;
  238. }
  239. // Print form confirm
  240. print $formconfirm;
  241. // Object card
  242. // ------------------------------------------------------------
  243. $linkback = '<a href="'.dol_buildpath('/settlements/hotel_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  244. $morehtmlref = '<div class="refidno">';
  245. $morehtmlref .= '</div>';
  246. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  247. print '<div class="fichecenter">';
  248. print '<div class="fichehalfleft">';
  249. print '<div class="underbanner clearboth"></div>';
  250. print '<table class="border centpercent tableforfield">'."\n";
  251. // Common attributes
  252. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  253. //unset($object->fields['fk_project']); // Hide field already shown in banner
  254. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  255. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  256. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  257. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  258. print '</table>';
  259. print '</div>';
  260. print '</div>';
  261. print '<div class="clearboth"></div>';
  262. print dol_get_fiche_end();
  263. /*
  264. * Lines
  265. */
  266. if (!empty($object->table_element_line)) {
  267. // Show object lines
  268. $result = $object->getLinesArray();
  269. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
  270. <input type="hidden" name="token" value="' . newToken().'">
  271. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  272. <input type="hidden" name="mode" value="">
  273. <input type="hidden" name="page_y" value="">
  274. <input type="hidden" name="id" value="' . $object->id.'">
  275. ';
  276. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  277. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  278. }
  279. print '<div class="div-table-responsive-no-min">';
  280. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  281. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  282. }
  283. if (!empty($object->lines)) {
  284. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  285. }
  286. // Form to add new line
  287. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  288. if ($action != 'editline') {
  289. // Add products/services form
  290. $parameters = array();
  291. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  292. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  293. if (empty($reshook))
  294. $object->formAddObjectLine(1, $mysoc, $soc);
  295. }
  296. }
  297. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  298. print '</table>';
  299. }
  300. print '</div>';
  301. print "</form>\n";
  302. }
  303. // Buttons for actions
  304. if ($action != 'presend' && $action != 'editline') {
  305. print '<div class="tabsAction">'."\n";
  306. $parameters = array();
  307. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  308. if ($reshook < 0) {
  309. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  310. }
  311. if (empty($reshook)) {
  312. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  313. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
  314. }
  315. print '</div>'."\n";
  316. }
  317. // Presend form
  318. $modelmail = 'hotel';
  319. $defaulttopic = 'InformationMessage';
  320. $diroutput = $conf->settlements->dir_output;
  321. $trackid = 'hotel'.$object->id;
  322. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  323. }
  324. // End of page
  325. llxFooter();
  326. $db->close();
  327. ?>
  328. <style>
  329. .badge-status1{
  330. background-color: green!important;
  331. }
  332. .badge-status0{
  333. background-color: red!important;
  334. color: white!important;
  335. border: none!important;
  336. }
  337. </style>