dolibarr  13.0.2
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 {
70  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
71  $objcanvas = new Canvas($db, $action);
72  $objcanvas->getCanvas('contact', 'contactcard', $canvas);
73 }
74 
75 if (GETPOST('actioncode', 'array'))
76 {
77  $actioncode = GETPOST('actioncode', 'array', 3);
78  if (!count($actioncode)) $actioncode = '0';
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) $socid = $user->socid;
86 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
87 
88 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
89 $sortfield = GETPOST("sortfield", 'alpha');
90 $sortorder = GETPOST("sortorder", 'alpha');
91 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
92 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
93 $offset = $limit * $page;
94 $pageprev = $page - 1;
95 $pagenext = $page + 1;
96 if (!$sortfield) $sortfield = 'a.datep, a.id';
97 if (!$sortorder) $sortorder = 'DESC';
98 
99 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
100 $hookmanager->initHooks(array('contactagenda', 'globalcard'));
101 
102 
103 /*
104  * Actions
105  */
106 
107 $parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
108 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 
111 if (empty($reshook))
112 {
113  // Cancel
114  if (GETPOST('cancel', 'alpha') && !empty($backtopage))
115  {
116  header("Location: ".$backtopage);
117  exit;
118  }
119 
120  // Purge search criteria
121  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
122  {
123  $actioncode = '';
124  $search_agenda_label = '';
125  }
126 }
127 
128 
129 /*
130  * View
131  */
132 
133 $form = new Form($db);
134 
135 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
136 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
137 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
138 llxHeader('', $title, $help_url);
139 
140 
141 if ($socid > 0)
142 {
143  $objsoc = new Societe($db);
144  $objsoc->fetch($socid);
145 }
146 
147 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
148 {
149  // -----------------------------------------
150  // When used with CANVAS
151  // -----------------------------------------
152  if (empty($object->error) && $id)
153  {
154  $object = new Contact($db);
155  $result = $object->fetch($id);
156  if ($result <= 0) dol_print_error('', $object->error);
157  }
158  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
159  $objcanvas->display_canvas($action); // Show template
160 } else {
161  // -----------------------------------------
162  // When used in standard mode
163  // -----------------------------------------
164 
165  // Confirm deleting contact
166  if ($user->rights->societe->contact->supprimer)
167  {
168  if ($action == 'delete')
169  {
170  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
171  }
172  }
173 
174  /*
175  * Onglets
176  */
177  $head = array();
178  if ($id > 0)
179  {
180  // Si edition contact deja existant
181  $object = new Contact($db);
182  $res = $object->fetch($id, $user);
183  if ($res < 0) { dol_print_error($db, $object->error); exit; }
184  $res = $object->fetch_optionals();
185  if ($res < 0) { dol_print_error($db, $object->error); exit; }
186 
187  // Show tabs
188  $head = contact_prepare_head($object);
189 
190  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
191  }
192 
193  if (!empty($id) && $action != 'edit' && $action != 'create')
194  {
195  $objsoc = new Societe($db);
196 
197  /*
198  * Fiche en mode visualisation
199  */
200 
201  dol_htmloutput_errors($error, $errors);
202 
203  print dol_get_fiche_head($head, 'agenda', $title, -1, 'contact');
204 
205  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
206 
207  $morehtmlref = '<div class="refidno">';
208  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
209  {
210  $objsoc = new Societe($db);
211  $objsoc->fetch($object->socid);
212  // Thirdparty
213  $morehtmlref .= $langs->trans('ThirdParty').' : ';
214  if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
215  else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
216  }
217  $morehtmlref .= '</div>';
218 
219  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
220 
221  print '<div class="fichecenter">';
222 
223  print '<div class="underbanner clearboth"></div>';
224 
225  $object->info($id);
226  dol_print_object_info($object, 1);
227 
228  print '</div>';
229 
231 
232 
233  // Actions buttons
234 
235  $objcon = $object;
236  $object->fetch_thirdparty();
237  $objthirdparty = $object->thirdparty;
238 
239  $out = '';
240  $permok = $user->rights->agenda->myactions->create;
241  if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
242  {
243  if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '');
244  $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 : ''));
245  $out .= '&amp;datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog'));
246  }
247 
248  $newcardbutton = '';
249  if (!empty($conf->agenda->enabled))
250  {
251  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
252  {
253  $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
254  }
255  }
256 
257  if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
258  {
259  print '<br>';
260 
261  $param = '&id='.$id;
262  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
263  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
264 
265  print load_fiche_titre($langs->trans("ActionsOnContact"), $newcardbutton, '');
266  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
267 
268  // List of all actions
269  $filters = array();
270  $filters['search_agenda_label'] = $search_agenda_label;
271 
272  show_actions_done($conf, $langs, $db, $objthirdparty, $object, 0, $actioncode, '', $filters, $sortfield, $sortorder);
273  }
274  }
275 }
276 
277 
278 llxFooter();
279 
280 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage canvas.
Class to manage contact/addresses.
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.
dol_now($mode= 'auto')
Return date for now.
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
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).
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
llxFooter()
Empty footer.
Definition: wrapper.php:59