dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
31require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_availabilities.lib.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array("agenda", "companies", "other", "mails"));
43
44$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
45$ref = GETPOST('ref', 'alpha');
46$lineid = GETPOSTINT('lineid');
47$socid = GETPOSTINT('socid');
48$action = GETPOST('action', 'aZ09');
49
50// Initialize a technical objects
51$object = new Availabilities($db);
52$extrafields = new ExtraFields($db);
53$diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
54$hookmanager->initHooks(array('availabilitiescontact', 'globalcard')); // Note that conf->hooks_modules contains array
55// Fetch optionals attributes and labels
56$extrafields->fetch_name_optionals_label($object->table_element);
57
58// Load object
59include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
60
61// There is several ways to check permission.
62// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
63$enablepermissioncheck = 0;
64if ($enablepermissioncheck) {
65 $permissiontoread = $user->hasRight('bookcal', 'availabilities', 'read');
66 $permission = $user->hasRight('bookcal', 'availabilities', 'write');
67} else {
68 $permissiontoread = 1;
69 $permission = 1;
70}
71
72// Security check (enable the most restrictive one)
73//if ($user->socid > 0) accessforbidden();
74//if ($user->socid > 0) $socid = $user->socid;
75//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
76//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
77if (!isModEnabled('bookcal')) {
79}
80if (!$permissiontoread) {
82}
83
84
85/*
86 * Add a new contact
87 */
88
89if ($action == 'addcontact' && $permission) {
90 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
91 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
92 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
93
94 if ($result >= 0) {
95 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
96 exit;
97 } else {
98 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
99 $langs->load("errors");
100 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
101 } else {
102 setEventMessages($object->error, $object->errors, 'errors');
103 }
104 }
105} elseif ($action == 'swapstatut' && $permission) {
106 // Toggle the status of a contact
107 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
108} elseif ($action == 'deletecontact' && $permission) {
109 // Deletes a contact
110 $result = $object->delete_contact($lineid);
111
112 if ($result >= 0) {
113 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
114 exit;
115 } else {
116 dol_print_error($db);
117 }
118}
119
120
121/*
122 * View
123 */
124
125$title = $langs->trans('Availabilities')." - ".$langs->trans('ContactsAddresses');
126$help_url = '';
127//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
128llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-bookcal page-card_availabilities_contact');
129
130$form = new Form($db);
131$formcompany = new FormCompany($db);
132$contactstatic = new Contact($db);
133$userstatic = new User($db);
134
135
136/* *************************************************************************** */
137/* */
138/* View and edit mode */
139/* */
140/* *************************************************************************** */
141
142if ($object->id) {
143 /*
144 * Show tabs
145 */
146 $head = availabilitiesPrepareHead($object);
147
148 print dol_get_fiche_head($head, 'contact', $langs->trans("Availabilities"), -1, $object->picto);
149
150 $linkback = '<a href="'.dol_buildpath('/bookcal/availabilities_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
151
152 $morehtmlref = '<div class="refidno">';
153 /*
154 // Ref customer
155 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
156 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
157 // Thirdparty
158 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
159 // Project
160 if (isModEnabled('project'))
161 {
162 $langs->load("projects");
163 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
164 if ($permissiontoadd)
165 {
166 if ($action != 'classify')
167 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
168 $morehtmlref.=' : ';
169 if ($action == 'classify') {
170 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
171 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
172 $morehtmlref.='<input type="hidden" name="action" value="classin">';
173 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
174 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
175 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
176 $morehtmlref.='</form>';
177 } else {
178 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
179 }
180 } else {
181 if (! empty($object->fk_project)) {
182 $proj = new Project($db);
183 $proj->fetch($object->fk_project);
184 $morehtmlref .= ': '.$proj->getNomUrl();
185 } else {
186 $morehtmlref .= '';
187 }
188 }
189 }*/
190 $morehtmlref .= '</div>';
191
192 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
193
194 print dol_get_fiche_end();
195
196 print '<br>';
197
198 // Contacts lines (modules that overwrite templates must declare this into descriptor)
199 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
200 foreach ($dirtpls as $reldir) {
201 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
202 if ($res) {
203 break;
204 }
205 }
206}
207
208// End of page
209llxFooter();
210$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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.
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.