dolibarr  17.0.4
booking_contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
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 
25 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 dol_include_once('/bookcal/class/booking.class.php');
30 dol_include_once('/bookcal/lib/bookcal_booking.lib.php');
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("bookcal@bookcal", "companies", "other", "mails"));
34 
35 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
36 $ref = GETPOST('ref', 'alpha');
37 $lineid = GETPOST('lineid', 'int');
38 $socid = GETPOST('socid', 'int');
39 $action = GETPOST('action', 'aZ09');
40 
41 // Initialize technical objects
42 $object = new Booking($db);
43 $extrafields = new ExtraFields($db);
44 $diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
45 $hookmanager->initHooks(array('bookingcontact', 'globalcard')); // Note that conf->hooks_modules contains array
46 // Fetch optionals attributes and labels
47 $extrafields->fetch_name_optionals_label($object->table_element);
48 
49 // Load object
50 include 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
51 
52 // There is several ways to check permission.
53 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
54 $enablepermissioncheck = 0;
55 if ($enablepermissioncheck) {
56  $permissiontoread = $user->rights->bookcal->booking->read;
57  $permission = $user->rights->bookcal->booking->write;
58 } else {
59  $permissiontoread = 1;
60  $permission = 1;
61 }
62 
63 // Security check (enable the most restrictive one)
64 //if ($user->socid > 0) accessforbidden();
65 //if ($user->socid > 0) $socid = $user->socid;
66 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
67 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
68 if (empty($conf->bookcal->enabled)) accessforbidden();
69 if (!$permissiontoread) accessforbidden();
70 
71 
72 /*
73  * Add a new contact
74  */
75 
76 if ($action == 'addcontact' && $permission) {
77  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
78  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
79  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
80 
81  if ($result >= 0) {
82  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
83  exit;
84  } else {
85  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
86  $langs->load("errors");
87  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
88  } else {
89  setEventMessages($object->error, $object->errors, 'errors');
90  }
91  }
92 } elseif ($action == 'swapstatut' && $permission) {
93  // Toggle the status of a contact
94  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
95 } elseif ($action == 'deletecontact' && $permission) {
96  // Deletes a contact
97  $result = $object->delete_contact($lineid);
98 
99  if ($result >= 0) {
100  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
101  exit;
102  } else {
103  dol_print_error($db);
104  }
105 }
106 
107 
108 /*
109  * View
110  */
111 
112 $title = $langs->trans('Booking')." - ".$langs->trans('ContactsAddresses');
113 $help_url = '';
114 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
115 llxHeader('', $title, $help_url);
116 
117 $form = new Form($db);
118 $formcompany = new FormCompany($db);
119 $contactstatic = new Contact($db);
120 $userstatic = new User($db);
121 
122 
123 /* *************************************************************************** */
124 /* */
125 /* View and edit mode */
126 /* */
127 /* *************************************************************************** */
128 
129 if ($object->id) {
130  /*
131  * Show tabs
132  */
133  $head = bookingPrepareHead($object);
134 
135  print dol_get_fiche_head($head, 'contact', $langs->trans("Booking"), -1, $object->picto);
136 
137  $linkback = '<a href="'.dol_buildpath('/bookcal/booking_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
138 
139  $morehtmlref = '<div class="refidno">';
140  /*
141  // Ref customer
142  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
143  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
144  // Thirdparty
145  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
146  // Project
147  if (! empty($conf->project->enabled))
148  {
149  $langs->load("projects");
150  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
151  if ($permissiontoadd)
152  {
153  if ($action != 'classify')
154  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
155  $morehtmlref.=' : ';
156  if ($action == 'classify') {
157  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
158  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
159  $morehtmlref.='<input type="hidden" name="action" value="classin">';
160  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
161  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
162  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
163  $morehtmlref.='</form>';
164  } else {
165  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
166  }
167  } else {
168  if (! empty($object->fk_project)) {
169  $proj = new Project($db);
170  $proj->fetch($object->fk_project);
171  $morehtmlref .= ': '.$proj->getNomUrl();
172  } else {
173  $morehtmlref .= '';
174  }
175  }
176  }*/
177  $morehtmlref .= '</div>';
178 
179  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
180 
181  print dol_get_fiche_end();
182 
183  print '<br>';
184 
185  // Contacts lines (modules that overwrite templates must declare this into descriptor)
186  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
187  foreach ($dirtpls as $reldir) {
188  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
189  if ($res) {
190  break;
191  }
192  }
193 }
194 
195 // End of page
196 llxFooter();
197 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
bookingPrepareHead($object)
Prepare array of tabs for Booking.
Class for Booking.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.