dolibarr  9.0.0
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.dolibarr@gmail.com>
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 <http://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 $extralabels=$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 }
80 else
81 {
82  $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));
83 }
84 $search_agenda_label=GETPOST('search_agenda_label');
85 
86 // Security check
87 if ($user->societe_id) $socid=$user->societe_id;
88 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // 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",'alpha');
92 $sortorder = GETPOST("sortorder",'alpha');
93 $page = GETPOST("page",'int');
94 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
95 $offset = $limit * $page;
96 $pageprev = $page - 1;
97 $pagenext = $page + 1;
98 if (! $sortfield) $sortfield='a.datep, a.id';
99 if (! $sortorder) $sortorder='DESC';
100 
101 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
102 $hookmanager->initHooks(array('contactagenda','globalcard'));
103 
104 
105 /*
106  * Actions
107  */
108 
109 $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
110 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
111 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112 
113 if (empty($reshook))
114 {
115  // Cancel
116  if (GETPOST('cancel','alpha') && ! empty($backtopage))
117  {
118  header("Location: ".$backtopage);
119  exit;
120  }
121 
122  // Purge search criteria
123  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
124  {
125  $actioncode='';
126  $search_agenda_label='';
127  }
128 }
129 
130 
131 /*
132  * View
133  */
134 
135 $form = new Form($db);
136 
137 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
138 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
139 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
140 llxHeader('', $title, $help_url);
141 
142 
143 if ($socid > 0)
144 {
145  $objsoc = new Societe($db);
146  $objsoc->fetch($socid);
147 }
148 
149 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
150 {
151  // -----------------------------------------
152  // When used with CANVAS
153  // -----------------------------------------
154  if (empty($object->error) && $id)
155  {
156  $object = new Contact($db);
157  $result=$object->fetch($id);
158  if ($result <= 0) dol_print_error('',$object->error);
159  }
160  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
161  $objcanvas->display_canvas($action); // Show template
162 }
163 else
164 {
165  // -----------------------------------------
166  // When used in standard mode
167  // -----------------------------------------
168 
169  // Confirm deleting contact
170  if ($user->rights->societe->contact->supprimer)
171  {
172  if ($action == 'delete')
173  {
174  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
175  }
176  }
177 
178  /*
179  * Onglets
180  */
181  $head=array();
182  if ($id > 0)
183  {
184  // Si edition contact deja existant
185  $object = new Contact($db);
186  $res=$object->fetch($id, $user);
187  if ($res < 0) { dol_print_error($db,$object->error); exit; }
188  $res=$object->fetch_optionals();
189  if ($res < 0) { dol_print_error($db,$object->error); exit; }
190 
191  // Show tabs
192  $head = contact_prepare_head($object);
193 
194  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
195  }
196 
197  if (! empty($id) && $action != 'edit' && $action != 'create')
198  {
199  $objsoc = new Societe($db);
200 
201  /*
202  * Fiche en mode visualisation
203  */
204 
205  dol_htmloutput_errors($error,$errors);
206 
207  dol_fiche_head($head, 'agenda', $title, -1, 'contact');
208 
209  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
210 
211  $morehtmlref='<div class="refidno">';
212  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
213  {
214  $objsoc=new Societe($db);
215  $objsoc->fetch($object->socid);
216  // Thirdparty
217  $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
218  if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1);
219  else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
220  }
221  $morehtmlref.='</div>';
222 
223  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
224 
225  print '<div class="fichecenter">';
226 
227  print '<div class="underbanner clearboth"></div>';
228 
229  $object->info($id);
230  print dol_print_object_info($object, 1);
231 
232  print '</div>';
233 
235 
236 
237  // Actions buttons
238 
239  $objcon=$object;
240  $object->fetch_thirdparty();
241  $objthirdparty=$object->thirdparty;
242 
243  $out='';
244  $permok=$user->rights->agenda->myactions->create;
245  if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
246  {
247  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
248  if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
249  $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
250  //$out.=$langs->trans("AddAnAction").' ';
251  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
252  //$out.="</a>";
253  }
254 
255 
256  //print '<div class="tabsAction">';
257  //print '</div>';
258 
259  $newcardbutton='';
260  if (! empty($conf->agenda->enabled))
261  {
262  if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create))
263  {
264  $newcardbutton.='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'"><span class="valignmiddle">'.$langs->trans("AddAction").'</span>';
265  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
266  $newcardbutton.= '</a>';
267  }
268  }
269 
270  if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
271  {
272  print '<br>';
273 
274  $param='&id='.$id;
275  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
276  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
277 
278  print load_fiche_titre($langs->trans("ActionsOnContact"), $newcardbutton, '');
279  //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
280 
281  // List of all actions
282  $filters=array();
283  $filters['search_agenda_label']=$search_agenda_label;
284 
285  show_actions_done($conf,$langs,$db,$objthirdparty,$object,0,$actioncode, '', $filters, $sortfield, $sortorder);
286  }
287  }
288 }
289 
290 
291 llxFooter();
292 
293 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
Class to manage canvas.
Class to manage contact/addresses.
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_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_fiche_end($notab=0)
Show tab footer of a card.
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
llxHeader()
Empty header.
Definition: wrapper.php:44
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.
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions (done or not, ignore the name of function)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.