1<?php
2/* Copyright (C) 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/**
19 *   	\file       conferenceorboothattendee_card.php
20 *		\ingroup    eventorganization
21 *		\brief      Page to create/edit/view conferenceorboothattendee
22 */
23
24require '../main.inc.php';
25
26require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
29require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
30require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
31require_once DOL_DOCUMENT_ROOT.'/eventorganization/lib/eventorganization_conferenceorbooth.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array("eventorganization", "other", "projects", "companies"));
37
38// Get parameters
39$id = GETPOST('id', 'int');
40$ref = GETPOST('ref', 'alpha');
41$action = GETPOST('action', 'aZ09');
42$confirm = GETPOST('confirm', 'alpha');
43$cancel = GETPOST('cancel', 'aZ09');
44$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'conferenceorboothattendeecard'; // To manage different context of search
45$backtopage = GETPOST('backtopage', 'alpha');
46$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
47//$lineid   = GETPOST('lineid', 'int');
48
49$conf_or_booth_id = GETPOST('conforboothid', 'int');
50$fk_project = GETPOST('fk_project', 'int');
51$withproject = 1;
52
53// Initialize technical objects
54$object = new ConferenceOrBoothAttendee($db);
55$extrafields = new ExtraFields($db);
56$projectstatic = new Project($db);
57$diroutputmassaction = $conf->eventorganization->dir_output.'/temp/massgeneration/'.$user->id;
58$hookmanager->initHooks(array('conferenceorboothattendeecard', 'globalcard')); // Note that conf->hooks_modules contains array
59
60
61if ($conf_or_booth_id > 0) {
62	$confOrBooth = new ConferenceOrBooth($db);
63	$result = $confOrBooth->fetch($id > 0 ? $id : $conf_or_booth_id);
64	if ($result < 0) {
65		setEventMessages(null, $confOrBooth->errors, 'errors');
66	} else {
67		$object->fk_actioncomm = $confOrBooth->id;
68		$object->fk_project = $confOrBooth->fk_project;
69		$fk_project = $object->fk_project;
70	}
71}
72
73// Fetch optionals attributes and labels
74$extrafields->fetch_name_optionals_label($object->table_element);
75
76$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
77
78// Initialize array of search criterias
79$search_all = GETPOST('search_all', 'alphanohtml');
80$search = array();
81foreach ($object->fields as $key => $val) {
82	if (GETPOST('search_'.$key, 'alpha') !== '') {
83		$search[$key] = GETPOST('search_'.$key, 'alpha');
84	}
85	if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
86		$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
87		$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
88	}
89}
90
91// List of fields to search into when doing a "search in all"
92$fieldstosearchall = array();
93foreach ($object->fields as $key => $val) {
94	if (!empty($val['searchall'])) {
95		$fieldstosearchall['t.'.$key] = $val['label'];
96	}
97}
98
99if (empty($action) && empty($id) && empty($ref)) {
100	$action = 'view';
101}
102
103// Load object
104include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
105
106// Now we have loaded the attendee, we can force the project (in case value provided as parameter is wrong or value not provided)
107if ($object->fk_project > 0) {
108	$fk_project = $object->fk_project;
109}
110
111$permissiontoread = $user->rights->eventorganization->read;
112$permissiontoadd = $user->rights->eventorganization->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
113$permissiontodelete = $user->rights->eventorganization->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
114$permissionnote = $user->rights->eventorganization->write; // Used by the include of actions_setnotes.inc.php
115$permissiondellink = $user->rights->eventorganization->write; // Used by the include of actions_dellink.inc.php
116$upload_dir = $conf->eventorganization->multidir_output[isset($object->entity) ? $object->entity : 1];
117
118
119/*
120 * Actions
121 */
122
123$parameters = array();
124$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
125if ($reshook < 0) {
126	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
127}
128
129if (empty($reshook)) {
130	$error = 0;
131
132	if (!empty($withproject)) {
133		$backurlforlist = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php?withproject=1&fk_project='.((int) $fk_project);
134	} else {
135		$backurlforlist = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_list.php';
136	}
137
138	if (empty($backtopage) || ($cancel && empty($id))) {
139		if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
140			if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
141				$backtopage = $backurlforlist;
142			} else {
143				$backtopage = DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?fk_project='.((int) $fk_project).'&id='.($id > 0 ? $id : '__ID__');
144			}
145		}
146	}
147
148	if ($cancel) {
149		if (!empty($backtopageforcancel)) {
150			header("Location: ".$backtopageforcancel);
151			exit;
152		} elseif (!empty($backtopage)) {
153			header("Location: ".$backtopage);
154			exit;
155		}
156		$action = '';
157	}
158
159	$triggermodname = 'EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_MODIFY'; // Name of trigger action code to execute when we modify record
160
161	// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
162	include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
163
164	// Actions when linking object each other
165	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
166
167	// Actions when printing a doc from card
168	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
169
170	// Action to move up and down lines of object
171	//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
172
173	// Action to build doc
174	include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
175
176	if ($action == 'set_thirdparty' && $permissiontoadd) {
177		$object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
178	}
179	if ($action == 'classin' && $permissiontoadd) {
180		$object->setProject(GETPOST('projectid', 'int'));
181	}
182
183	// Actions to send emails
184	$triggersendname = 'EVENTORGANIZATION_CONFERENCEORBOOTHATTENDEE_SENTBYMAIL';
185	$autocopy = 'MAIN_MAIL_AUTOCOPY_CONFERENCEORBOOTHATTENDEE_TO';
186	$trackid = 'conferenceorboothattendee'.$object->id;
187	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
188}
189
190
191
192
193/*
194 * View
195 */
196
197$form = new Form($db);
198$formfile = new FormFile($db);
199$formproject = new FormProjets($db);
200
201$title = $langs->trans("ConferenceOrBoothAttendee");
202$help_url = '';
203llxHeader('', $title, $help_url);
204
205$result = $projectstatic->fetch(empty($confOrBooth->fk_project)?$fk_project:$confOrBooth->fk_project);
206if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
207	$projectstatic->fetchComments();
208}
209if (!empty($projectstatic->socid)) {
210	$projectstatic->fetch_thirdparty();
211}
212
213
214$object->project = clone $projectstatic;
215
216if (!empty($withproject)) {
217	// Tabs for project
218	$tab = 'eventorganisation';
219	$head = project_prepare_head($projectstatic);
220	print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'), 0, '', '');
221
222	$param = ($mode == 'mine' ? '&mode=mine' : '');
223
224	// Project card
225
226	$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
227
228	$morehtmlref = '<div class="refidno">';
229	// Title
230	$morehtmlref .= $projectstatic->title;
231	// Thirdparty
232	if ($projectstatic->thirdparty->id > 0) {
233		$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
234	}
235	$morehtmlref .= '</div>';
236
237	// Define a complementary filter for search of next/prev ref.
238	if (!$user->rights->projet->all->lire) {
239		$objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
240		$projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
241	}
242
243	dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
244
245	print '<div class="fichecenter">';
246	print '<div class="fichehalfleft">';
247	print '<div class="underbanner clearboth"></div>';
248
249	print '<table class="border tableforfield centpercent">';
250
251	// Usage
252	if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
253		print '<tr><td class="tdtop">';
254		print $langs->trans("Usage");
255		print '</td>';
256		print '<td>';
257		if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
258			print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
259			$htmltext = $langs->trans("ProjectFollowOpportunity");
260			print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
261			print '<br>';
262		}
263		if (empty($conf->global->PROJECT_HIDE_TASKS)) {
264			print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
265			$htmltext = $langs->trans("ProjectFollowTasks");
266			print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
267			print '<br>';
268		}
269		if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
270			print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
271			$htmltext = $langs->trans("ProjectBillTimeDescription");
272			print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
273			print '<br>';
274		}
275		if (!empty($conf->eventorganization->enabled)) {
276			print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')).'"> ';
277			$htmltext = $langs->trans("EventOrganizationDescriptionLong");
278			print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
279		}
280		print '</td></tr>';
281	}
282
283	// Visibility
284	print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
285	if ($projectstatic->public) {
286		print $langs->trans('SharedProject');
287	} else {
288		print $langs->trans('PrivateProject');
289	}
290	print '</td></tr>';
291
292	// Date start - end
293	print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
294	$start = dol_print_date($projectstatic->date_start, 'day');
295	print ($start ? $start : '?');
296	$end = dol_print_date($projectstatic->date_end, 'day');
297	print ' - ';
298	print ($end ? $end : '?');
299	if ($projectstatic->hasDelay()) {
300		print img_warning("Late");
301	}
302	print '</td></tr>';
303
304	// Budget
305	print '<tr><td>'.$langs->trans("Budget").'</td><td>';
306	if (strcmp($projectstatic->budget_amount, '')) {
307		print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
308	}
309	print '</td></tr>';
310
311	// Other attributes
312	$cols = 2;
313	//include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
314
315	print '</table>';
316
317	print '</div>';
318
319	print '<div class="fichehalfright">';
320	print '<div class="ficheaddleft">';
321	print '<div class="underbanner clearboth"></div>';
322
323	print '<table class="border tableforfield centpercent">';
324
325	// Description
326	print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
327	print nl2br($projectstatic->description);
328	print '</td></tr>';
329
330	// Categories
331	if ($conf->categorie->enabled) {
332		print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
333		print $form->showCategories($projectstatic->id, 'project', 1);
334		print "</td></tr>";
335	}
336
337	print '<tr><td class="nowrap">';
338	$typeofdata = 'checkbox:'.($projectstatic->accept_conference_suggestions ? ' checked="checked"' : '');
339	$htmltext = $langs->trans("AllowUnknownPeopleSuggestConfHelp");
340	print $form->editfieldkey('AllowUnknownPeopleSuggestConf', 'accept_conference_suggestions', '', $projectstatic, 0, $typeofdata, '', 0, 0, 'projectid', $htmltext);
341	print '</td><td>';
342	print $form->editfieldval('AllowUnknownPeopleSuggestConf', 'accept_conference_suggestions', '1', $projectstatic, 0, $typeofdata, '', 0, 0, '', 0, '', 'projectid');
343	print "</td></tr>";
344
345	print '<tr><td>';
346	$typeofdata = 'checkbox:'.($projectstatic->accept_booth_suggestions ? ' checked="checked"' : '');
347	$htmltext = $langs->trans("AllowUnknownPeopleSuggestBoothHelp");
348	print $form->editfieldkey('AllowUnknownPeopleSuggestBooth', 'accept_booth_suggestions', '', $projectstatic, 0, $typeofdata, '', 0, 0, 'projectid', $htmltext);
349	print '</td><td>';
350	print $form->editfieldval('AllowUnknownPeopleSuggestBooth', 'accept_booth_suggestions', '1', $projectstatic, 0, $typeofdata, '', 0, 0, '', 0, '', 'projectid');
351	print "</td></tr>";
352
353	print '<tr><td>';
354	print $form->editfieldkey($form->textwithpicto($langs->trans('PriceOfBooth'), $langs->trans("PriceOfBoothHelp")), 'price_booth', '', $projectstatic, 0, 'amount', '', 0, 0, 'projectid');
355	print '</td><td>';
356	print $form->editfieldval($form->textwithpicto($langs->trans('PriceOfBooth'), $langs->trans("PriceOfBoothHelp")), 'price_booth', $projectstatic->price_booth, $projectstatic, 0, 'amount', '', 0, 0, '', 0, '', 'projectid');
357	print "</td></tr>";
358
359	print '<tr><td>';
360	print $form->editfieldkey($form->textwithpicto($langs->trans('PriceOfRegistration'), $langs->trans("PriceOfRegistrationHelp")), 'price_registration', '', $projectstatic, 0, 'amount', '', 0, 0, 'projectid');
361	print '</td><td>';
362	print $form->editfieldval($form->textwithpicto($langs->trans('PriceOfRegistration'), $langs->trans("PriceOfRegistrationHelp")), 'price_registration', $projectstatic->price_registration, $projectstatic, 0, 'amount', '', 0, 0, '', 0, '', 'projectid');
363	print "</td></tr>";
364
365	print '<tr><td valign="middle">'.$langs->trans("EventOrganizationICSLink").'</td><td>';
366	// Define $urlwithroot
367	$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
368	$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
369
370	// Show message
371	$message = '<a target="_blank" href="'.$urlwithroot.'/public/agenda/agendaexport.php?format=ical'.($conf->entity > 1 ? "&entity=".$conf->entity : "");
372	$message .= '&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : '...');
373	$message .= "&project=".$projectstatic->id.'&module='.urlencode('@eventorganization').'&status='.ConferenceOrBooth::STATUS_CONFIRMED.'">'.$langs->trans('DownloadICSLink').img_picto('', 'download', 'class="paddingleft"').'</a>';
374	print $message;
375	print "</td></tr>";
376
377	// Link to the submit vote/register page
378	print '<tr><td>';
379	//print '<span class="opacitymedium">';
380	print $form->textwithpicto($langs->trans("SuggestOrVoteForConfOrBooth"), $langs->trans("EvntOrgRegistrationHelpMessage"));
381	//print '</span>';
382	print '</td><td>';
383	$linksuggest = $dolibarr_main_url_root.'/public/project/index.php?id='.$projectstatic->id;
384	$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$projectstatic->id, 'md5');
385	$linksuggest .= '&securekey='.urlencode($encodedsecurekey);
386	//print '<div class="urllink">';
387	//print '<input type="text" value="'.$linksuggest.'" id="linkregister" class="quatrevingtpercent paddingrightonly">';
388	print '<div class="tdoverflowmax200 inline-block valignmiddle"><a target="_blank" href="'.$linksuggest.'" class="quatrevingtpercent">'.$linksuggest.'</a></div>';
389	print '<a target="_blank" href="'.$linksuggest.'">'.img_picto('', 'globe').'</a>';
390	//print '</div>';
391	//print ajax_autoselect("linkregister");
392	print '</td></tr>';
393
394	// Link to the subscribe
395	print '<tr><td>';
396	//print '<span class="opacitymedium">';
397	print $langs->trans("PublicAttendeeSubscriptionGlobalPage");
398	//print '</span>';
399	print '</td><td>';
400	$link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_register.php?id='.$projectstatic->id.'&type=global';
401	$encodedsecurekey = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$projectstatic->id, 'md5');
402	$link_subscription .= '&securekey='.urlencode($encodedsecurekey);
403	//print '<div class="urllink">';
404	//print '<input type="text" value="'.$linkregister.'" id="linkregister" class="quatrevingtpercent paddingrightonly">';
405	print '<div class="tdoverflowmax200 inline-block valignmiddle"><a target="_blank" href="'.$link_subscription.'" class="quatrevingtpercent">'.$link_subscription.'</a></div>';
406	print '<a target="_blank" href="'.$link_subscription.'">'.img_picto('', 'globe').'</a>';
407	//print '</div>';
408	//print ajax_autoselect("linkregister");
409	print '</td></tr>';
410
411	print '</table>';
412
413	print '</div>';
414	print '</div>';
415	print '</div>';
416
417	print '<div class="clearboth"></div>';
418
419	print dol_get_fiche_end();
420
421	print '<br>';
422}
423
424// Part to create
425if ($action == 'create') {
426	print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("ConferenceOrBoothAttendee")), '', 'object_'.$object->picto);
427
428
429	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].(empty($withproject) ? '' : '?withproject=1').'">';
430	print '<input type="hidden" name="token" value="'.newToken().'">';
431	print '<input type="hidden" name="action" value="add">';
432
433	if ($confOrBooth->id > 0) {
434		print '<input type="hidden" name="conforboothid" value="'.$confOrBooth->id.'">';
435	}
436	if ($projectstatic->id > 0) {
437		print '<input type="hidden" name="fk_project" value="'.$projectstatic->id.'">';
438		print '<input type="hidden" name="projectid" value="'.$projectstatic->id.'">';
439	}
440
441	if ($backtopage) {
442		print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
443	}
444	if ($backtopageforcancel) {
445		print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
446	}
447
448	print dol_get_fiche_head(array(), '');
449
450	print '<table class="border centpercent tableforfieldcreate">'."\n";
451
452	// Common attributes
453	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
454
455	// Other attributes
456	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
457
458	print '</table>'."\n";
459
460	print dol_get_fiche_end();
461
462	print '<div class="center">';
463	print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
464	print '&nbsp; ';
465	print '<input type="'.($backtopage ? "submit" : "button").'" class="button button-cancel" 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
466	print '</div>';
467
468	print '</form>';
469
470	//dol_set_focus('input[name="ref"]');
471}
472
473// Part to edit record
474if (($id || $ref) && $action == 'edit') {
475	print load_fiche_titre($langs->trans("ConferenceOrBoothAttendee"), '', 'object_'.$object->picto);
476
477	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
478	print '<input type="hidden" name="token" value="'.newToken().'">';
479	print '<input type="hidden" name="action" value="update">';
480	print '<input type="hidden" name="id" value="'.$object->id.'">';
481	if ($confOrBooth->id > 0) {
482		print '<input type="hidden" name="conforboothid" value="'.$confOrBooth->id.'">';
483	}
484	if ($object->fk_actioncomm > 0) {
485		print '<input type="hidden" name="fk_actioncomm" value="'.$object->fk_actioncomm.'">';
486	}
487	if ($backtopage) {
488		print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
489	}
490	if ($backtopageforcancel) {
491		print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
492	}
493	if ($projectstatic->id > 0) {
494		print '<input type="hidden" name="fk_project" value="'.$projectstatic->id.'">';
495	}
496
497	print dol_get_fiche_head();
498
499	print '<table class="border centpercent tableforfieldedit">'."\n";
500
501	// Common attributes
502	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
503
504	// Other attributes
505	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
506
507	print '</table>';
508
509	print dol_get_fiche_end();
510
511	print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
512	print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
513	print '</div>';
514
515	print '</form>';
516}
517
518// Part to show record
519if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
520	$object->fetch_optionals();
521
522	$moreparam = '';
523	if ($withproject) {
524		$moreparam .= '&withproject=1';
525	}
526	if ($fk_project) {
527		$moreparam .= '&fk_project='.((int) $fk_project);
528	}
529
530	$head = conferenceorboothattendeePrepareHead($object);
531	print dol_get_fiche_head($head, 'card', $langs->trans("ConferenceOrBoothAttendee"), -1, $object->picto);
532
533	$formconfirm = '';
534
535	// Confirmation to delete
536	if ($action == 'delete') {
537		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteConferenceOrBoothAttendee'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
538	}
539	// Confirmation to delete line
540	if ($action == 'deleteline') {
541		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
542	}
543	// Clone confirmation
544	if ($action == 'clone') {
545		// Create an array for form
546		$formquestion = array();
547		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
548	}
549
550	// Confirmation of action xxxx
551	if ($action == 'xxx') {
552		$formquestion = array();
553		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
554	}
555
556	// Call Hook formConfirm
557	$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
558	$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
559	if (empty($reshook)) {
560		$formconfirm .= $hookmanager->resPrint;
561	} elseif ($reshook > 0) {
562		$formconfirm = $hookmanager->resPrint;
563	}
564
565	// Print form confirm
566	print $formconfirm;
567
568	// Object card
569	// ------------------------------------------------------------
570	$linkback = '<a href="'.dol_buildpath('/eventorganization/conferenceorboothattendee_list.php', 1).'?restore_lastsearch_values=1'.($confOrBooth->id > 0 ? '&conforboothid='.((int) $confOrBooth->id) : '').$moreparam.'">'.$langs->trans("BackToList").'</a>';
571
572	$morehtmlref = '<div class="refidno">';
573
574	$morehtmlref .= '</div>';
575
576	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam);
577
578	print '<div class="fichecenter">';
579	print '<div class="fichehalfleft">';
580	print '<div class="underbanner clearboth"></div>';
581	print '<table class="border centpercent tableforfield">'."\n";
582
583	$keyforbreak = 'note_public';
584
585	// Common attributes
586	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
587
588	// Other attributes. Fields from hook formObjectOptions and Extrafields.
589	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
590
591	print '</table>';
592	print '</div>';
593	print '</div>';
594
595	print '<div class="clearboth"></div>';
596
597	print dol_get_fiche_end();
598
599
600	/*
601	 * Lines
602	 */
603
604	if (!empty($object->table_element_line)) {
605		// Show object lines
606		$result = $object->getLinesArray();
607
608		print '	<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
609		<input type="hidden" name="token" value="' . newToken().'">
610		<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
611		<input type="hidden" name="mode" value="">
612		<input type="hidden" name="page_y" value="">
613		<input type="hidden" name="id" value="' . $object->id.'">
614		';
615
616		if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
617			include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
618		}
619
620		print '<div class="div-table-responsive-no-min">';
621		if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
622			print '<table id="tablelines" class="noborder noshadow" width="100%">';
623		}
624
625		if (!empty($object->lines)) {
626			$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
627		}
628
629		// Form to add new line
630		if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
631			if ($action != 'editline') {
632				// Add products/services form
633
634				$parameters = array();
635				$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
636				if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
637				if (empty($reshook))
638					$object->formAddObjectLine(1, $mysoc, $soc);
639			}
640		}
641
642		if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
643			print '</table>';
644		}
645		print '</div>';
646
647		print "</form>\n";
648	}
649
650
651	// Buttons for actions
652
653	if ($action != 'presend' && $action != 'editline') {
654		print '<div class="tabsAction">'."\n";
655		$parameters = array();
656		$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
657		if ($reshook < 0) {
658			setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
659		}
660
661		if (empty($reshook)) {
662			// Send
663			if (empty($user->socid)) {
664				print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
665			}
666			print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.(!empty($confOrBooth->id)?'&conforboothid='.$confOrBooth->id:'').(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:'').'&action=edit&token='.newToken(), '', $permissiontoadd);
667
668			// Clone
669			print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:''), '', $permissiontoadd);
670
671			// Delete (need delete permission, or if draft, just need create/modify permission)
672			print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().(!empty($projectstatic->id)?'&fk_project='.$projectstatic->id:''), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
673		}
674		print '</div>'."\n";
675	}
676
677
678	// Select mail models is same action as presend
679	if (GETPOST('modelselected')) {
680		$action = 'presend';
681	}
682
683	if ($action != 'presend') {
684		print '<div class="fichecenter"><div class="fichehalfleft">';
685		print '<a name="builddoc"></a>'; // ancre
686
687		$includedocgeneration = 0;
688
689		// Documents
690		if ($includedocgeneration) {
691			$objref = dol_sanitizeFileName($object->ref);
692			$relativepath = $objref.'/'.$objref.'.pdf';
693			$filedir = $conf->eventorganization->dir_output.'/'.$object->element.'/'.$objref;
694			$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
695			$genallowed = $user->rights->eventorganization->conferenceorboothattendee->read; // If you can read, you can build the PDF to read content
696			$delallowed = $user->rights->eventorganization->conferenceorboothattendee->write; // If you can create/edit, you can remove a file on card
697			print $formfile->showdocuments('eventorganization:ConferenceOrBoothAttendee', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
698		}
699
700		// Show links to link elements
701		$linktoelem = $form->showLinkToObjectBlock($object, null, array('conferenceorboothattendee'));
702		$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
703
704
705		print '</div><div class="fichehalfright">';
706
707		print '</div></div>';
708	}
709
710	//Select mail models is same action as presend
711	if (GETPOST('modelselected')) {
712		$action = 'presend';
713	}
714
715	// Presend form
716	$modelmail = 'conferenceorboothattendee';
717	$defaulttopic = 'InformationMessage';
718	$diroutput = $conf->eventorganization->dir_output;
719	$trackid = 'conferenceorboothattendee'.$object->id;
720
721	include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
722}
723
724// End of page
725llxFooter();
726$db->close();
727