dolibarr  7.0.0-beta
agenda.php
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 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@capnetworks.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 $langs->load("companies");
48 $langs->load("users");
49 $langs->load("other");
50 $langs->load("commercial");
51 
52 $mesg=''; $error=0; $errors=array();
53 
54 $action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
55 $confirm = GETPOST('confirm','alpha');
56 $backtopage = GETPOST('backtopage','alpha');
57 $id = GETPOST('id','int');
58 $socid = GETPOST('socid','int');
59 
60 $object = new Contact($db);
61 $extrafields = new ExtraFields($db);
62 
63 // fetch optionals attributes and labels
64 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
65 
66 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
67 $object->getCanvas($id);
68 $objcanvas=null;
69 $canvas = (! empty($object->canvas)?$object->canvas:GETPOST("canvas"));
70 if (! empty($canvas))
71 {
72  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
73  $objcanvas = new Canvas($db, $action);
74  $objcanvas->getCanvas('contact', 'contactcard', $canvas);
75 }
76 
77 if (GETPOST('actioncode','array'))
78 {
79  $actioncode=GETPOST('actioncode','array',3);
80  if (! count($actioncode)) $actioncode='0';
81 }
82 else
83 {
84  $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));
85 }
86 $search_agenda_label=GETPOST('search_agenda_label');
87 
88 // Security check
89 if ($user->societe_id) $socid=$user->societe_id;
90 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission
91 
92 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
93 $sortfield = GETPOST("sortfield",'alpha');
94 $sortorder = GETPOST("sortorder",'alpha');
95 $page = GETPOST("page",'int');
96 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
97 $offset = $limit * $page;
98 $pageprev = $page - 1;
99 $pagenext = $page + 1;
100 if (! $sortfield) $sortfield='a.datep, a.id';
101 if (! $sortorder) $sortorder='DESC';
102 
103 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
104 $hookmanager->initHooks(array('contactcard','globalcard'));
105 
106 
107 /*
108  * Actions
109  */
110 
111 $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
112 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
113 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
114 
115 if (empty($reshook))
116 {
117  // Cancel
118  if (GETPOST('cancel','alpha') && ! empty($backtopage))
119  {
120  header("Location: ".$backtopage);
121  exit;
122  }
123 
124  // Purge search criteria
125  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
126  {
127  $actioncode='';
128  $search_agenda_label='';
129  }
130 }
131 
132 
133 /*
134  * View
135  */
136 
137 
138 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
139 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
140 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
141 llxHeader('', $title, $help_url);
142 
143 $form = new Form($db);
144 $formcompany = new FormCompany($db);
145 
146 $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
147 
148 if ($socid > 0)
149 {
150  $objsoc = new Societe($db);
151  $objsoc->fetch($socid);
152 }
153 
154 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
155 {
156  // -----------------------------------------
157  // When used with CANVAS
158  // -----------------------------------------
159  if (empty($object->error) && $id)
160  {
161  $object = new Contact($db);
162  $result=$object->fetch($id);
163  if ($result <= 0) dol_print_error('',$object->error);
164  }
165  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
166  $objcanvas->display_canvas($action); // Show template
167 }
168 else
169 {
170  // -----------------------------------------
171  // When used in standard mode
172  // -----------------------------------------
173 
174  // Confirm deleting contact
175  if ($user->rights->societe->contact->supprimer)
176  {
177  if ($action == 'delete')
178  {
179  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
180  }
181  }
182 
183  /*
184  * Onglets
185  */
186  $head=array();
187  if ($id > 0)
188  {
189  // Si edition contact deja existant
190  $object = new Contact($db);
191  $res=$object->fetch($id, $user);
192  if ($res < 0) { dol_print_error($db,$object->error); exit; }
193  $res=$object->fetch_optionals($object->id,$extralabels);
194 
195  // Show tabs
196  $head = contact_prepare_head($object);
197 
198  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
199  }
200 
201  if (! empty($id) && $action != 'edit' && $action != 'create')
202  {
203  $objsoc = new Societe($db);
204 
205  /*
206  * Fiche en mode visualisation
207  */
208 
209  dol_htmloutput_errors($error,$errors);
210 
211  dol_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='<div class="refidno">';
216  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
217  {
218  $objsoc=new Societe($db);
219  $objsoc->fetch($object->socid);
220  // Thirdparty
221  $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
222  if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1);
223  else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
224  }
225  $morehtmlref.='</div>';
226 
227  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
228 
229  print '<div class="fichecenter">';
230 
231  print '<div class="underbanner clearboth"></div>';
232 
233  $object->info($id);
234  print dol_print_object_info($object, 1);
235 
236  print '</div>';
237 
239 
240 
241  // Actions buttons
242 
243  $objcon=$object;
244  $object->fetch_thirdparty();
245  $objthirdparty=$object->thirdparty;
246 
247  $out='';
248  $permok=$user->rights->agenda->myactions->create;
249  if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
250  {
251  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
252  if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
253  $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
254  //$out.=$langs->trans("AddAnAction").' ';
255  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
256  //$out.="</a>";
257  }
258 
259 
260  //print '<div class="tabsAction">';
261  //print '</div>';
262 
263 
264  $morehtmlcenter='';
265  if (! empty($conf->agenda->enabled))
266  {
267  if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create))
268  {
269  $morehtmlcenter.= '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
270  }
271  else
272  {
273  $morehtmlcenter.= '<a class="butActionRefused" href="#">'.$langs->trans("AddAction").'</a>';
274  }
275  }
276 
277 
278  if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
279  {
280  print '<br>';
281 
282  $param='&id='.$id;
283  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
284  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
285 
286  print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
287 
288  // List of all actions
289  $filters=array();
290  $filters['search_agenda_label']=$search_agenda_label;
291 
292  show_actions_done($conf,$langs,$db,$objthirdparty,$object,0,$actioncode, '', $filters, $sortfield, $sortorder);
293  }
294  }
295 }
296 
297 
298 llxFooter();
299 
300 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage canvas.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
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:46
print
Draft customers invoices.
Definition: index.php:91
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
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)