26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
34 $langs->loadLangs(array(
"bookcal@bookcal",
"other"));
39 $lineid =
GETPOST(
'lineid',
'int');
41 $action =
GETPOST(
'action',
'aZ09');
42 $confirm =
GETPOST(
'confirm',
'alpha');
43 $cancel =
GETPOST(
'cancel',
'aZ09');
44 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') : str_replace(
'_',
'', basename(dirname(__FILE__)).basename(__FILE__,
'.php'));
45 $backtopage =
GETPOST(
'backtopage',
'alpha');
46 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
47 $dol_openinpopup =
GETPOST(
'dol_openinpopup',
'aZ09');
52 $diroutputmassaction = $conf->bookcal->dir_output.
'/temp/massgeneration/'.$user->id;
53 $hookmanager->initHooks(array(
'bookingcard',
'globalcard'));
56 $extrafields->fetch_name_optionals_label($object->table_element);
58 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
61 $search_all =
GETPOST(
"search_all",
'alpha');
63 foreach ($object->fields as $key => $val) {
64 if (
GETPOST(
'search_'.$key,
'alpha')) {
65 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
69 if (empty($action) && empty($id) && empty($ref)) {
74 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
78 $enablepermissioncheck = 0;
79 if ($enablepermissioncheck) {
80 $permissiontoread = $user->rights->bookcal->booking->read;
81 $permissiontoadd = $user->rights->bookcal->booking->write;
82 $permissiontodelete = $user->rights->bookcal->booking->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
83 $permissionnote = $user->rights->bookcal->booking->write;
84 $permissiondellink = $user->rights->bookcal->booking->write;
86 $permissiontoread = 1;
88 $permissiontodelete = 1;
90 $permissiondellink = 1;
93 $upload_dir = $conf->bookcal->multidir_output[isset($object->entity) ? $object->entity : 1].
'/booking';
108 $parameters = array();
109 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
114 if (empty($reshook)) {
117 $backurlforlist =
dol_buildpath(
'/bookcal/booking_list.php', 1);
119 if (empty($backtopage) || ($cancel && empty($id))) {
120 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
121 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
122 $backtopage = $backurlforlist;
124 $backtopage =
dol_buildpath(
'/bookcal/booking_card.php', 1).
'?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
129 $triggermodname =
'BOOKCAL_BOOKING_MODIFY';
132 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
135 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
138 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
144 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
146 if ($action ==
'set_thirdparty' && $permissiontoadd) {
147 $object->setValueFrom(
'fk_soc',
GETPOST(
'fk_soc',
'int'),
'',
'',
'date',
'', $user, $triggermodname);
149 if ($action ==
'classin' && $permissiontoadd) {
150 $object->setProject(
GETPOST(
'projectid',
'int'));
154 $triggersendname =
'BOOKCAL_BOOKING_SENTBYMAIL';
155 $autocopy =
'MAIN_MAIL_AUTOCOPY_BOOKING_TO';
156 $trackid =
'booking'.$object->id;
157 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
173 $title = $langs->trans(
"Booking");
194 if ($action ==
'create') {
195 if (empty($permissiontoadd)) {
200 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Booking")),
'',
'object_'.$object->picto);
202 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
203 print
'<input type="hidden" name="token" value="'.newToken().
'">';
204 print
'<input type="hidden" name="action" value="add">';
206 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
208 if ($backtopageforcancel) {
209 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
217 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
220 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
223 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
225 print
'</table>'.
"\n";
229 print
$form->buttonsSaveCancel(
"Create");
237 if (($id || $ref) && $action ==
'edit') {
238 print
load_fiche_titre($langs->trans(
"Booking"),
'',
'object_'.$object->picto);
240 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
241 print
'<input type="hidden" name="token" value="'.newToken().
'">';
242 print
'<input type="hidden" name="action" value="update">';
243 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
245 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
247 if ($backtopageforcancel) {
248 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
253 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
256 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
259 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
265 print
$form->buttonsSaveCancel();
271 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
272 $res = $object->fetch_optionals();
275 print
dol_get_fiche_head($head,
'card', $langs->trans(
"Booking"), -1, $object->picto);
280 if ($action ==
'delete') {
281 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteBooking'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
284 if ($action ==
'deleteline') {
285 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
289 if ($action ==
'clone') {
291 $formquestion = array();
292 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
296 if ($action ==
'xxx') {
297 $text = $langs->trans(
'ConfirmActionBooking', $object->ref);
306 $formquestion = array();
317 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
321 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
322 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
323 if (empty($reshook)) {
325 } elseif ($reshook > 0) {
335 $linkback =
'<a href="'.dol_buildpath(
'/bookcal/booking_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
337 $morehtmlref =
'<div class="refidno">';
372 $morehtmlref .=
'</div>';
375 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
378 print
'<div class="fichecenter">';
379 print
'<div class="fichehalfleft">';
380 print
'<div class="underbanner clearboth"></div>';
381 print
'<table class="border centpercent tableforfield">'.
"\n";
387 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
390 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
396 print
'<div class="clearboth"></div>';
405 if (!empty($object->table_element_line)) {
407 $result = $object->getLinesArray();
409 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
410 <input type="hidden" name="token" value="' .
newToken().
'">
411 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
412 <input type="hidden" name="mode" value="">
413 <input type="hidden" name="page_y" value="">
414 <input type="hidden" name="id" value="' . $object->id.
'">
417 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
418 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
421 print
'<div class="div-table-responsive-no-min">';
422 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
423 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
426 if (!empty($object->lines)) {
427 $object->printObjectLines($action, $mysoc,
null,
GETPOST(
'lineid',
'int'), 1);
431 if ($object->status == 0 && $permissiontoadd && $action !=
'selectlines') {
432 if ($action !=
'editline') {
435 $parameters = array();
436 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
437 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
439 $object->formAddObjectLine(1, $mysoc, $soc);
443 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action !=
'selectlines' && $action !=
'editline')) {
454 if ($action !=
'presend' && $action !=
'editline') {
455 print
'<div class="tabsAction">'.
"\n";
456 $parameters = array();
457 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
462 if (empty($reshook)) {
464 if (empty($user->socid)) {
465 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init&token='.
newToken().
'#formmailbeforetitle');
469 if ($object->status == $object::STATUS_VALIDATED) {
470 print
dolGetButtonAction($langs->trans(
'SetToDraft'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_setdraft&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
473 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken(),
'', $permissiontoadd);
476 if ($object->status == $object::STATUS_DRAFT) {
477 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
478 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=confirm_validate&confirm=yes&token='.
newToken(),
'', $permissiontoadd);
480 $langs->load(
"errors");
481 print
dolGetButtonAction($langs->trans(
"ErrorAddAtLeastOneLineFirst"), $langs->trans(
"Validate"),
'default',
'#',
'', 0);
486 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.(!empty($object->socid)?
'&socid='.$object->socid:
'').
'&action=clone&token='.
newToken(),
'', $permissiontoadd);
506 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
513 if (
GETPOST(
'modelselected')) {
517 if ($action !=
'presend') {
518 print
'<div class="fichecenter"><div class="fichehalfleft">';
519 print
'<a name="builddoc"></a>';
521 $includedocgeneration = 0;
524 if ($includedocgeneration) {
526 $relativepath = $objref.
'/'.$objref.
'.pdf';
527 $filedir = $conf->bookcal->dir_output.
'/'.$object->element.
'/'.$objref;
528 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
529 $genallowed = $permissiontoread;
530 $delallowed = $permissiontoadd;
531 print $formfile->showdocuments(
'bookcal:Booking', $object->element.
'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
535 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'booking'));
536 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
539 print
'</div><div class="fichehalfright">';
543 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode',
dol_buildpath(
'/bookcal/booking_agenda.php', 1).
'?id='.$object->id);
546 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
548 $somethingshown =
$formactions->showactions($object, $object->element.
'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1,
'', $MAXEVENT,
'', $morehtmlcenter);
550 print
'</div></div>';
554 if (
GETPOST(
'modelselected')) {
559 $modelmail =
'booking';
560 $defaulttopic =
'InformationMessage';
561 $diroutput = $conf->bookcal->dir_output;
562 $trackid =
'booking'.$object->id;
564 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';