1<?php 2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net> 3 * Copyright (C) 2021 Florian HENRY <florian.henry@scopen.fr> 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/** 20 * \file conferenceorbooth_contact.php 21 * \ingroup eventorganization 22 * \brief Tab for contacts linked to ConferenceOrBooth 23 */ 24 25// Load Dolibarr environment 26$res = 0; 27// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) 28if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { 29 $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; 30} 31// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME 32$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; 33while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { 34 $i--; $j--; 35} 36if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { 37 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; 38} 39if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { 40 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; 41} 42// Try main.inc.php using relative path 43if (!$res && file_exists("../main.inc.php")) { 44 $res = @include "../main.inc.php"; 45} 46if (!$res && file_exists("../../main.inc.php")) { 47 $res = @include "../../main.inc.php"; 48} 49if (!$res && file_exists("../../../main.inc.php")) { 50 $res = @include "../../../main.inc.php"; 51} 52if (!$res) { 53 die("Include of main fails"); 54} 55 56require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 57require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 58require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php'; 59require_once DOL_DOCUMENT_ROOT.'/eventorganization/lib/eventorganization_conferenceorbooth.lib.php'; 60require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 61require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; 62// Load translation files required by the page 63$langs->loadLangs(array("eventorganization@eventorganization", "companies", "other", "mails")); 64 65$id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility 66$ref = GETPOST('ref', 'alpha'); 67$lineid = GETPOST('lineid', 'int'); 68$socid = GETPOST('socid', 'int'); 69$action = GETPOST('action', 'aZ09'); 70$withproject = GETPOST('withproject', 'int'); 71 72// Initialize technical objects 73$object = new ConferenceOrBooth($db); 74$extrafields = new ExtraFields($db); 75$projectstatic = new Project($db); 76$diroutputmassaction = $conf->eventorganization->dir_output.'/temp/massgeneration/'.$user->id; 77$hookmanager->initHooks(array('conferenceorboothcontact', 'globalcard')); // Note that conf->hooks_modules contains array 78// Fetch optionals attributes and labels 79$extrafields->fetch_name_optionals_label($object->table_element); 80 81// Load object 82include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals 83 84// Security check 85if ($user->socid > 0) { 86 accessforbidden(); 87} 88$isdraft = (($object->status== $object::STATUS_DRAFT) ? 1 : 0); 89$result = restrictedArea($user, 'eventorganization', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); 90 91$permission = $user->rights->eventorganization->write; 92 93 94/* 95 * Actions 96 */ 97 98if ($action == 'addcontact' && $permission) { // Add a new contact 99 $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); 100 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 101 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); 102 103 if ($result >= 0) { 104 header("Location: ".$_SERVER['PHP_SELF']."?id=".((int) $object->id).(!empty($withproject)?'&withproject=1':'')); 105 exit; 106 } else { 107 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { 108 $langs->load("errors"); 109 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 110 } else { 111 setEventMessages($object->error, $object->errors, 'errors'); 112 } 113 } 114} elseif ($action == 'swapstatut' && $permission) { 115 // Toggle the status of a contact 116 $result = $object->swapContactStatus(GETPOST('ligne', 'int')); 117} elseif ($action == 'deletecontact' && $permission) { 118 // Deletes a contact 119 $result = $object->delete_contact($lineid); 120 121 if ($result >= 0) { 122 header("Location: ".$_SERVER['PHP_SELF']."?id=".((int) $object->id).(!empty($withproject)?'&withproject=1':'')); 123 exit; 124 } else { 125 dol_print_error($db); 126 } 127} 128 129 130/* 131 * View 132 */ 133 134$title = $langs->trans('ConferenceOrBooth')." - ".$langs->trans('ContactsAddresses'); 135$help_url = ''; 136//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; 137llxHeader('', $title, $help_url); 138 139$form = new Form($db); 140$formcompany = new FormCompany($db); 141$contactstatic = new Contact($db); 142$userstatic = new User($db); 143 144 145/* *************************************************************************** */ 146/* */ 147/* View and edit mode */ 148/* */ 149/* *************************************************************************** */ 150 151$result = $projectstatic->fetch($object->fk_project); 152if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) { 153 $projectstatic->fetchComments(); 154} 155if (!empty($projectstatic->socid)) { 156 $projectstatic->fetch_thirdparty(); 157} 158$withProjectUrl=''; 159$object->project = clone $projectstatic; 160 161if (!empty($withproject)) { 162 // Tabs for project 163 $tab = 'eventorganisation'; 164 $withProjectUrl = "&withproject=1"; 165 $head = project_prepare_head($projectstatic); 166 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'), 0, '', ''); 167 168 $param = ($mode == 'mine' ? '&mode=mine' : ''); 169 170 // Project card 171 172 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 173 174 $morehtmlref = '<div class="refidno">'; 175 // Title 176 $morehtmlref .= $projectstatic->title; 177 // Thirdparty 178 if ($projectstatic->thirdparty->id > 0) { 179 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project'); 180 } 181 $morehtmlref .= '</div>'; 182 183 // Define a complementary filter for search of next/prev ref. 184 if (!$user->rights->projet->all->lire) { 185 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0); 186 $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")"; 187 } 188 189 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref); 190 191 print '<div class="fichecenter">'; 192 print '<div class="fichehalfleft">'; 193 print '<div class="underbanner clearboth"></div>'; 194 195 print '<table class="border tableforfield centpercent">'; 196 197 // Usage 198 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) { 199 print '<tr><td class="tdtop">'; 200 print $langs->trans("Usage"); 201 print '</td>'; 202 print '<td>'; 203 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { 204 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> '; 205 $htmltext = $langs->trans("ProjectFollowOpportunity"); 206 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext); 207 print '<br>'; 208 } 209 if (empty($conf->global->PROJECT_HIDE_TASKS)) { 210 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> '; 211 $htmltext = $langs->trans("ProjectFollowTasks"); 212 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext); 213 print '<br>'; 214 } 215 if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) { 216 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"' : '')).'"> '; 217 $htmltext = $langs->trans("ProjectBillTimeDescription"); 218 print $form->textwithpicto($langs->trans("BillTime"), $htmltext); 219 print '<br>'; 220 } 221 if (!empty($conf->eventorganization->enabled)) { 222 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"' : '')).'"> '; 223 $htmltext = $langs->trans("EventOrganizationDescriptionLong"); 224 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); 225 } 226 print '</td></tr>'; 227 } 228 229 // Visibility 230 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>'; 231 if ($projectstatic->public) { 232 print $langs->trans('SharedProject'); 233 } else { 234 print $langs->trans('PrivateProject'); 235 } 236 print '</td></tr>'; 237 238 // Date start - end 239 print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>'; 240 $start = dol_print_date($projectstatic->date_start, 'day'); 241 print ($start ? $start : '?'); 242 $end = dol_print_date($projectstatic->date_end, 'day'); 243 print ' - '; 244 print ($end ? $end : '?'); 245 if ($projectstatic->hasDelay()) { 246 print img_warning("Late"); 247 } 248 print '</td></tr>'; 249 250 // Budget 251 print '<tr><td>'.$langs->trans("Budget").'</td><td>'; 252 if (strcmp($projectstatic->budget_amount, '')) { 253 print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency); 254 } 255 print '</td></tr>'; 256 257 // Other attributes 258 $cols = 2; 259 //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; 260 261 print '</table>'; 262 263 print '</div>'; 264 265 print '<div class="fichehalfright">'; 266 print '<div class="ficheaddleft">'; 267 print '<div class="underbanner clearboth"></div>'; 268 269 print '<table class="border centpercent">'; 270 271 // Description 272 print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'; 273 print nl2br($projectstatic->description); 274 print '</td></tr>'; 275 276 // Categories 277 if ($conf->categorie->enabled) { 278 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>'; 279 print $form->showCategories($projectstatic->id, 'project', 1); 280 print "</td></tr>"; 281 } 282 283 print '<tr><td>'; 284 $typeofdata = 'checkbox:'.($projectstatic->accept_conference_suggestions ? ' checked="checked"' : ''); 285 $htmltext = $langs->trans("AllowUnknownPeopleSuggestConfHelp"); 286 print $form->editfieldkey('AllowUnknownPeopleSuggestConf', 'accept_conference_suggestions', '', $projectstatic, 0, $typeofdata, '', 0, 0, 'projectid', $htmltext); 287 print '</td><td>'; 288 print $form->editfieldval('AllowUnknownPeopleSuggestConf', 'accept_conference_suggestions', '1', $projectstatic, 0, $typeofdata, '', 0, 0, '', 0, '', 'projectid'); 289 print "</td></tr>"; 290 291 print '<tr><td>'; 292 $typeofdata = 'checkbox:'.($projectstatic->accept_booth_suggestions ? ' checked="checked"' : ''); 293 $htmltext = $langs->trans("AllowUnknownPeopleSuggestBoothHelp"); 294 print $form->editfieldkey('AllowUnknownPeopleSuggestBooth', 'accept_booth_suggestions', '', $projectstatic, 0, $typeofdata, '', 0, 0, 'projectid', $htmltext); 295 print '</td><td>'; 296 print $form->editfieldval('AllowUnknownPeopleSuggestBooth', 'accept_booth_suggestions', '1', $projectstatic, 0, $typeofdata, '', 0, 0, '', 0, '', 'projectid'); 297 print "</td></tr>"; 298 299 print '<tr><td>'; 300 print $form->editfieldkey('PriceOfRegistration', 'price_registration', '', $projectstatic, 0, 'amount', '', 0, 0, 'projectid'); 301 print '</td><td>'; 302 print $form->editfieldval('PriceOfRegistration', 'price_registration', $projectstatic->price_registration, $projectstatic, 0, 'amount', '', 0, 0, '', 0, '', 'projectid'); 303 print "</td></tr>"; 304 305 print '<tr><td>'; 306 print $form->editfieldkey('PriceOfBooth', 'price_booth', '', $projectstatic, 0, 'amount', '', 0, 0, 'projectid'); 307 print '</td><td>'; 308 print $form->editfieldval('PriceOfBooth', 'price_booth', $projectstatic->price_booth, $projectstatic, 0, 'amount', '', 0, 0, '', 0, '', 'projectid'); 309 print "</td></tr>"; 310 311 print '<tr><td valign="middle">'.$langs->trans("EventOrganizationICSLink").'</td><td>'; 312 // Define $urlwithroot 313 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); 314 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; 315 316 // Show message 317 $message = '<a href="'.$urlwithroot.'/public/agenda/agendaexport.php?format=ical'.($conf->entity > 1 ? "&entity=".$conf->entity : ""); 318 $message .= '&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : '...'); 319 $message .= "&project=".$projectstatic->id.'&module='.urlencode('@eventorganization').'&status='.ConferenceOrBooth::STATUS_CONFIRMED.'">'.$langs->trans('DownloadICSLink').'</a>'; 320 print $message; 321 print "</td></tr>"; 322 323 print '</table>'; 324 325 print '</div>'; 326 print '</div>'; 327 print '</div>'; 328 329 print '<div class="clearboth"></div>'; 330 331 print dol_get_fiche_end(); 332 333 print '<br>'; 334} 335 336if ($object->id) { 337 /* 338 * Show tabs 339 */ 340 $head = conferenceorboothPrepareHead($object, $withproject); 341 342 print dol_get_fiche_head($head, 'contact', $langs->trans("ConferenceOrBooth"), -1, $object->picto); 343 344 $linkback = '<a href="'.dol_buildpath('/eventorganization/conferenceorbooth_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 345 346 $morehtmlref = '<div class="refidno">'; 347 /* 348 // Ref customer 349 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); 350 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); 351 // Thirdparty 352 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : ''); 353 // Project 354 if (! empty($conf->projet->enabled)) 355 { 356 $langs->load("projects"); 357 $morehtmlref.='<br>'.$langs->trans('Project') . ' '; 358 if ($permissiontoadd) 359 { 360 if ($action != 'classify') 361 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; 362 $morehtmlref.=' : '; 363 if ($action == 'classify') { 364 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 365 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 366 $morehtmlref.='<input type="hidden" name="action" value="classin">'; 367 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">'; 368 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); 369 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 370 $morehtmlref.='</form>'; 371 } else { 372 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 373 } 374 } else { 375 if (! empty($object->fk_project)) { 376 $proj = new Project($db); 377 $proj->fetch($object->fk_project); 378 $morehtmlref .= ': '.$proj->getNomUrl(); 379 } else { 380 $morehtmlref .= ''; 381 } 382 } 383 }*/ 384 $morehtmlref .= '</div>'; 385 386 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 387 388 print dol_get_fiche_end(); 389 390 print '<br>'; 391 392 // Contacts lines (modules that overwrite templates must declare this into descriptor) 393 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); 394 foreach ($dirtpls as $reldir) { 395 $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); 396 if ($res) { 397 break; 398 } 399 } 400} 401 402// End of page 403llxFooter(); 404$db->close(); 405