dolibarr  x.y.z
availabilities_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 
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_availabilities.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("bookcal@bookcal", "companies", "other", "mails"));
35 
36 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
37 $ref = GETPOST('ref', 'alpha');
38 $lineid = GETPOST('lineid', 'int');
39 $socid = GETPOST('socid', 'int');
40 $action = GETPOST('action', 'aZ09');
41 
42 // Initialize technical objects
43 $object = new Availabilities($db);
44 $extrafields = new ExtraFields($db);
45 $diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
46 $hookmanager->initHooks(array('availabilitiescontact', 'globalcard')); // Note that conf->hooks_modules contains array
47 // Fetch optionals attributes and labels
48 $extrafields->fetch_name_optionals_label($object->table_element);
49 
50 // Load object
51 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
52 
53 // There is several ways to check permission.
54 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
55 $enablepermissioncheck = 0;
56 if ($enablepermissioncheck) {
57  $permissiontoread = $user->rights->bookcal->availabilities->read;
58  $permission = $user->rights->bookcal->availabilities->write;
59 } else {
60  $permissiontoread = 1;
61  $permission = 1;
62 }
63 
64 // Security check (enable the most restrictive one)
65 //if ($user->socid > 0) accessforbidden();
66 //if ($user->socid > 0) $socid = $user->socid;
67 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
68 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
69 if (empty($conf->bookcal->enabled)) accessforbidden();
70 if (!$permissiontoread) accessforbidden();
71 
72 
73 /*
74  * Add a new contact
75  */
76 
77 if ($action == 'addcontact' && $permission) {
78  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
79  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81 
82  if ($result >= 0) {
83  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
84  exit;
85  } else {
86  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
87  $langs->load("errors");
88  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
89  } else {
90  setEventMessages($object->error, $object->errors, 'errors');
91  }
92  }
93 } elseif ($action == 'swapstatut' && $permission) {
94  // Toggle the status of a contact
95  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
96 } elseif ($action == 'deletecontact' && $permission) {
97  // Deletes a contact
98  $result = $object->delete_contact($lineid);
99 
100  if ($result >= 0) {
101  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
102  exit;
103  } else {
104  dol_print_error($db);
105  }
106 }
107 
108 
109 /*
110  * View
111  */
112 
113 $title = $langs->trans('Availabilities')." - ".$langs->trans('ContactsAddresses');
114 $help_url = '';
115 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
116 llxHeader('', $title, $help_url);
117 
118 $form = new Form($db);
119 $formcompany = new FormCompany($db);
120 $contactstatic = new Contact($db);
121 $userstatic = new User($db);
122 
123 
124 /* *************************************************************************** */
125 /* */
126 /* View and edit mode */
127 /* */
128 /* *************************************************************************** */
129 
130 if ($object->id) {
131  /*
132  * Show tabs
133  */
134  $head = availabilitiesPrepareHead($object);
135 
136  print dol_get_fiche_head($head, 'contact', $langs->trans("Availabilities"), -1, $object->picto);
137 
138  $linkback = '<a href="'.dol_buildpath('/bookcal/availabilities_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
139 
140  $morehtmlref = '<div class="refidno">';
141  /*
142  // Ref customer
143  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
144  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
145  // Thirdparty
146  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
147  // Project
148  if (! empty($conf->project->enabled))
149  {
150  $langs->load("projects");
151  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
152  if ($permissiontoadd)
153  {
154  if ($action != 'classify')
155  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
156  $morehtmlref.=' : ';
157  if ($action == 'classify') {
158  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
159  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
160  $morehtmlref.='<input type="hidden" name="action" value="classin">';
161  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
162  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
163  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
164  $morehtmlref.='</form>';
165  } else {
166  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
167  }
168  } else {
169  if (! empty($object->fk_project)) {
170  $proj = new Project($db);
171  $proj->fetch($object->fk_project);
172  $morehtmlref .= ': '.$proj->getNomUrl();
173  } else {
174  $morehtmlref .= '';
175  }
176  }
177  }*/
178  $morehtmlref .= '</div>';
179 
180  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
181 
182  print dol_get_fiche_end();
183 
184  print '<br>';
185 
186  // Contacts lines (modules that overwrite templates must declare this into descriptor)
187  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
188  foreach ($dirtpls as $reldir) {
189  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
190  if ($res) {
191  break;
192  }
193  }
194 }
195 
196 // End of page
197 llxFooter();
198 $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
availabilitiesPrepareHead($object)
Prepare array of tabs for Availabilities.
Class for Availabilities.
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:45
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.
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.