dolibarr 21.0.0-beta
calendar_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) 2023 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';
28
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php';
32require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_calendar.lib.php';
33
42// Load translation files required by the page
43$langs->loadLangs(array("agenda", "companies", "other", "mails"));
44
45$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
46$ref = GETPOST('ref', 'alpha');
47$lineid = GETPOSTINT('lineid');
48$socid = GETPOSTINT('socid');
49$action = GETPOST('action', 'aZ09');
50
51// Initialize a technical objects
52$object = new Calendar($db);
53$extrafields = new ExtraFields($db);
54$diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
55$hookmanager->initHooks(array('calendarcontact', 'globalcard')); // Note that conf->hooks_modules contains array
56// Fetch optionals attributes and labels
57$extrafields->fetch_name_optionals_label($object->table_element);
58
59// Load object
60include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
61
62// There is several ways to check permission.
63// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
64$enablepermissioncheck = 0;
65if ($enablepermissioncheck) {
66 $permissiontoread = $user->hasRight('bookcal', 'calendar', 'read');
67 $permission = $user->hasRight('bookcal', 'calendar', 'write');
68} else {
69 $permissiontoread = 1;
70 $permission = 1;
71}
72
73// Security check (enable the most restrictive one)
74//if ($user->socid > 0) accessforbidden();
75//if ($user->socid > 0) $socid = $user->socid;
76//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
77//restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
78if (!isModEnabled("bookcal")) {
80}
81if (!$permissiontoread) {
83}
84
85
86/*
87 * Add a new contact
88 */
89
90if ($action == 'addcontact' && $permission) {
91 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
92 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
93 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
94
95 if ($result >= 0) {
96 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
97 exit;
98 } else {
99 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
100 $langs->load("errors");
101 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
102 } else {
103 setEventMessages($object->error, $object->errors, 'errors');
104 }
105 }
106} elseif ($action == 'swapstatut' && $permission) {
107 // Toggle the status of a contact
108 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
109} elseif ($action == 'deletecontact' && $permission) {
110 // Deletes a contact
111 $result = $object->delete_contact($lineid);
112
113 if ($result >= 0) {
114 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
115 exit;
116 } else {
117 dol_print_error($db);
118 }
119}
120
121
122/*
123 * View
124 */
125
126$title = $langs->trans('Calendar')." - ".$langs->trans('ContactsAddresses');
127$help_url = '';
128//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
129llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-bookcal page-card_calendar_contact');
130
131$form = new Form($db);
132$formcompany = new FormCompany($db);
133$contactstatic = new Contact($db);
134$userstatic = new User($db);
135
136
137/* *************************************************************************** */
138/* */
139/* View and edit mode */
140/* */
141/* *************************************************************************** */
142
143if ($object->id) {
144 /*
145 * Show tabs
146 */
147 $head = calendarPrepareHead($object);
148
149 print dol_get_fiche_head($head, 'contact', $langs->trans("Calendar"), -1, $object->picto);
150
151 $linkback = '<a href="'.dol_buildpath('/bookcal/calendar_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
152
153 $morehtmlref = '<div class="refidno">';
154 /*
155 // Ref customer
156 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
157 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
158 // Thirdparty
159 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
160 // Project
161 if (isModEnabled('project')) {
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
calendarPrepareHead($object)
Prepare array of tabs for Calendar.
Class for Calendar.
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.