dolibarr  16.0.5
agenda.php
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
7  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
10  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
49 
50 $mesg = ''; $error = 0; $errors = array();
51 
52 $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
53 $confirm = GETPOST('confirm', 'alpha');
54 $backtopage = GETPOST('backtopage', 'alpha');
55 $id = GETPOST('id', 'int');
56 $socid = GETPOST('socid', 'int');
57 
58 $object = new Contact($db);
59 $extrafields = new ExtraFields($db);
60 
61 // fetch optionals attributes and labels
62 $extrafields->fetch_name_optionals_label($object->table_element);
63 
64 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
65 $object->getCanvas($id);
66 $objcanvas = null;
67 $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
68 if (!empty($canvas)) {
69  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
70  $objcanvas = new Canvas($db, $action);
71  $objcanvas->getCanvas('contact', 'contactcard', $canvas);
72 }
73 
74 if (GETPOST('actioncode', 'array')) {
75  $actioncode = GETPOST('actioncode', 'array', 3);
76  if (!count($actioncode)) {
77  $actioncode = '0';
78  }
79 } else {
80  $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
81 }
82 $search_agenda_label = GETPOST('search_agenda_label');
83 
84 // Security check
85 if ($user->socid) {
86  $socid = $user->socid;
87 }
88 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
89 
90 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
91 $sortfield = GETPOST('sortfield', 'aZ09comma');
92 $sortorder = GETPOST('sortorder', 'aZ09comma');
93 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
94 if (empty($page) || $page == -1) {
95  $page = 0;
96 } // If $page is not defined, or '' or -1
97 $offset = $limit * $page;
98 $pageprev = $page - 1;
99 $pagenext = $page + 1;
100 if (!$sortfield) {
101  $sortfield = 'a.datep, a.id';
102 }
103 if (!$sortorder) {
104  $sortorder = 'DESC';
105 }
106 
107 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
108 $hookmanager->initHooks(array('contactagenda', 'globalcard'));
109 
110 
111 /*
112  * Actions
113  */
114 
115 $parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
116 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117 if ($reshook < 0) {
118  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119 }
120 
121 if (empty($reshook)) {
122  // Cancel
123  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
124  header("Location: ".$backtopage);
125  exit;
126  }
127 
128  // Purge search criteria
129  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
130  $actioncode = '';
131  $search_agenda_label = '';
132  }
133 }
134 
135 
136 /*
137  * View
138  */
139 
140 $form = new Form($db);
141 
142 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
143 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
144  $title = $object->lastname;
145 }
146 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Partner';
147 llxHeader('', $title, $help_url);
148 
149 
150 if ($socid > 0) {
151  $objsoc = new Societe($db);
152  $objsoc->fetch($socid);
153 }
154 
155 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
156  // -----------------------------------------
157  // When used with CANVAS
158  // -----------------------------------------
159  if (empty($object->error) && $id) {
160  $object = new Contact($db);
161  $result = $object->fetch($id);
162  if ($result <= 0) {
163  dol_print_error('', $object->error);
164  }
165  }
166  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
167  $objcanvas->display_canvas($action); // Show template
168 } else {
169  // -----------------------------------------
170  // When used in standard mode
171  // -----------------------------------------
172 
173  // Confirm deleting contact
174  if ($user->rights->societe->contact->supprimer) {
175  if ($action == 'delete') {
176  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
177  }
178  }
179 
180  /*
181  * Onglets
182  */
183  $head = array();
184  if ($id > 0) {
185  // Si edition contact deja existant
186  $object = new Contact($db);
187  $res = $object->fetch($id, $user);
188  if ($res < 0) {
189  dol_print_error($db, $object->error); exit;
190  }
191  $res = $object->fetch_optionals();
192  if ($res < 0) {
193  dol_print_error($db, $object->error); exit;
194  }
195 
196  // Show tabs
197  $head = contact_prepare_head($object);
198 
199  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
200  }
201 
202  if (!empty($id) && $action != 'edit' && $action != 'create') {
203  $objsoc = new Societe($db);
204 
205  /*
206  * Fiche en mode visualisation
207  */
208 
209  dol_htmloutput_errors($error, $errors);
210 
211  print dol_get_fiche_head($head, 'agenda', $title, -1, 'contact');
212 
213  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
214 
215  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
216  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
217  $morehtmlref .= '</a>';
218 
219  $morehtmlref .= '<div class="refidno">';
220  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
221  $objsoc = new Societe($db);
222  $objsoc->fetch($object->socid);
223  // Thirdparty
224  $morehtmlref .= $langs->trans('ThirdParty').' : ';
225  if ($objsoc->id > 0) {
226  $morehtmlref .= $objsoc->getNomUrl(1);
227  } else {
228  $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
229  }
230  }
231  $morehtmlref .= '</div>';
232 
233  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
234 
235  print '<div class="fichecenter">';
236 
237  print '<div class="underbanner clearboth"></div>';
238 
239  $object->info($id);
240  dol_print_object_info($object, 1);
241 
242  print '</div>';
243 
244  print dol_get_fiche_end();
245 
246 
247  // Actions buttons
248 
249  $objcon = $object;
250  $object->fetch_thirdparty();
251  $objthirdparty = $object->thirdparty;
252 
253  $out = '';
254  $newcardbutton = '';
255  if (isModEnabled('agenda')) {
256  $permok = $user->rights->agenda->myactions->create;
257  if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
258  if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
259  $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '');
260  }
261  $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;origin=contact&amp;originid='.$object->id.'&amp;percentage=-1&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].($objcon->id > 0 ? '?id='.$objcon->id : ''));
262  $out .= '&amp;datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog'));
263  }
264 
265  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
266  $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
267  }
268  }
269 
270  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
271  print '<br>';
272 
273  $param = '&id='.$id;
274  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
275  $param .= '&contextpage='.$contextpage;
276  }
277  if ($limit > 0 && $limit != $conf->liste_limit) {
278  $param .= '&limit='.$limit;
279  }
280 
281  print load_fiche_titre($langs->trans("ActionsOnContact"), $newcardbutton, '');
282  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
283 
284  // List of all actions
285  $filters = array();
286  $filters['search_agenda_label'] = $search_agenda_label;
287 
288  show_actions_done($conf, $langs, $db, $objthirdparty, $object, 0, $actioncode, '', $filters, $sortfield, $sortorder);
289  }
290  }
291 }
292 
293 
294 llxFooter();
295 
296 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dol_htmloutput_errors
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
Definition: functions.lib.php:8366
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
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:116
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10604
show_actions_done
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
Definition: company.lib.php:1389
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
Canvas
Class to manage canvas.
Definition: canvas.class.php:29
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_print_object_info
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
Definition: functions2.lib.php:205
contact_prepare_head
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8136
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59