dolibarr  20.0.0-alpha
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 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_availabilities.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("agenda", "companies", "other", "mails"));
34 
35 $id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
36 $ref = GETPOST('ref', 'alpha');
37 $lineid = GETPOSTINT('lineid');
38 $socid = GETPOSTINT('socid');
39 $action = GETPOST('action', 'aZ09');
40 
41 // Initialize technical objects
42 $object = new Availabilities($db);
43 $extrafields = new ExtraFields($db);
44 $diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
45 $hookmanager->initHooks(array('availabilitiescontact', '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->hasRight('bookcal', 'availabilities', 'read');
57  $permission = $user->hasRight('bookcal', 'availabilities', '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 (!isModEnabled('bookcal')) {
70 }
71 if (!$permissiontoread) {
73 }
74 
75 
76 /*
77  * Add a new contact
78  */
79 
80 if ($action == 'addcontact' && $permission) {
81  $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
82  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
83  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
84 
85  if ($result >= 0) {
86  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
87  exit;
88  } else {
89  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
90  $langs->load("errors");
91  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
92  } else {
93  setEventMessages($object->error, $object->errors, 'errors');
94  }
95  }
96 } elseif ($action == 'swapstatut' && $permission) {
97  // Toggle the status of a contact
98  $result = $object->swapContactStatus(GETPOSTINT('ligne'));
99 } elseif ($action == 'deletecontact' && $permission) {
100  // Deletes a contact
101  $result = $object->delete_contact($lineid);
102 
103  if ($result >= 0) {
104  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105  exit;
106  } else {
107  dol_print_error($db);
108  }
109 }
110 
111 
112 /*
113  * View
114  */
115 
116 $title = $langs->trans('Availabilities')." - ".$langs->trans('ContactsAddresses');
117 $help_url = '';
118 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
119 llxHeader('', $title, $help_url);
120 
121 $form = new Form($db);
122 $formcompany = new FormCompany($db);
123 $contactstatic = new Contact($db);
124 $userstatic = new User($db);
125 
126 
127 /* *************************************************************************** */
128 /* */
129 /* View and edit mode */
130 /* */
131 /* *************************************************************************** */
132 
133 if ($object->id) {
134  /*
135  * Show tabs
136  */
138 
139  print dol_get_fiche_head($head, 'contact', $langs->trans("Availabilities"), -1, $object->picto);
140 
141  $linkback = '<a href="'.dol_buildpath('/bookcal/availabilities_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
142 
143  $morehtmlref = '<div class="refidno">';
144  /*
145  // Ref customer
146  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
147  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
148  // Thirdparty
149  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
150  // Project
151  if (isModEnabled('project'))
152  {
153  $langs->load("projects");
154  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
155  if ($permissiontoadd)
156  {
157  if ($action != 'classify')
158  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
159  $morehtmlref.=' : ';
160  if ($action == 'classify') {
161  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
162  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
163  $morehtmlref.='<input type="hidden" name="action" value="classin">';
164  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
165  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
166  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
167  $morehtmlref.='</form>';
168  } else {
169  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
170  }
171  } else {
172  if (! empty($object->fk_project)) {
173  $proj = new Project($db);
174  $proj->fetch($object->fk_project);
175  $morehtmlref .= ': '.$proj->getNomUrl();
176  } else {
177  $morehtmlref .= '';
178  }
179  }
180  }*/
181  $morehtmlref .= '</div>';
182 
183  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
184 
185  print dol_get_fiche_end();
186 
187  print '<br>';
188 
189  // Contacts lines (modules that overwrite templates must declare this into descriptor)
190  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
191  foreach ($dirtpls as $reldir) {
192  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
193  if ($res) {
194  break;
195  }
196  }
197 }
198 
199 // End of page
200 llxFooter();
201 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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:50
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.