agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. /**
  26. * \file htdocs/contact/card.php
  27. * \ingroup societe
  28. * \brief Card of a contact
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  40. require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  44. $langs->load("companies");
  45. $langs->load("users");
  46. $langs->load("other");
  47. $langs->load("commercial");
  48. $mesg=''; $error=0; $errors=array();
  49. $action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
  50. $confirm = GETPOST('confirm','alpha');
  51. $backtopage = GETPOST('backtopage','alpha');
  52. $id = GETPOST('id','int');
  53. $socid = GETPOST('socid','int');
  54. $object = new Contact($db);
  55. $extrafields = new ExtraFields($db);
  56. // fetch optionals attributes and labels
  57. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  58. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  59. $object->getCanvas($id);
  60. $objcanvas=null;
  61. $canvas = (! empty($object->canvas)?$object->canvas:GETPOST("canvas"));
  62. if (! empty($canvas))
  63. {
  64. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  65. $objcanvas = new Canvas($db, $action);
  66. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  67. }
  68. if (GETPOST('actioncode','array'))
  69. {
  70. $actioncode=GETPOST('actioncode','array',3);
  71. if (! count($actioncode)) $actioncode='0';
  72. }
  73. else
  74. {
  75. $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));
  76. }
  77. $search_agenda_label=GETPOST('search_agenda_label');
  78. // Security check
  79. if ($user->societe_id) $socid=$user->societe_id;
  80. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission
  81. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  82. $sortfield = GETPOST("sortfield",'alpha');
  83. $sortorder = GETPOST("sortorder",'alpha');
  84. $page = GETPOST("page",'int');
  85. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  86. $offset = $limit * $page;
  87. $pageprev = $page - 1;
  88. $pagenext = $page + 1;
  89. if (! $sortfield) $sortfield='a.datep, a.id';
  90. if (! $sortorder) $sortorder='DESC';
  91. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  92. $hookmanager->initHooks(array('contactcard','globalcard'));
  93. /*
  94. * Actions
  95. */
  96. $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
  97. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  98. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  99. if (empty($reshook))
  100. {
  101. // Cancel
  102. if (GETPOST("cancel") && ! empty($backtopage))
  103. {
  104. header("Location: ".$backtopage);
  105. exit;
  106. }
  107. // Purge search criteria
  108. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  109. {
  110. $actioncode='';
  111. $search_agenda_label='';
  112. }
  113. }
  114. /*
  115. * View
  116. */
  117. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  118. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
  119. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  120. llxHeader('', $title, $help_url);
  121. $form = new Form($db);
  122. $formcompany = new FormCompany($db);
  123. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  124. if ($socid > 0)
  125. {
  126. $objsoc = new Societe($db);
  127. $objsoc->fetch($socid);
  128. }
  129. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
  130. {
  131. // -----------------------------------------
  132. // When used with CANVAS
  133. // -----------------------------------------
  134. if (empty($object->error) && $id)
  135. {
  136. $object = new Contact($db);
  137. $result=$object->fetch($id);
  138. if ($result <= 0) dol_print_error('',$object->error);
  139. }
  140. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  141. $objcanvas->display_canvas($action); // Show template
  142. }
  143. else
  144. {
  145. // -----------------------------------------
  146. // When used in standard mode
  147. // -----------------------------------------
  148. // Confirm deleting contact
  149. if ($user->rights->societe->contact->supprimer)
  150. {
  151. if ($action == 'delete')
  152. {
  153. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
  154. }
  155. }
  156. /*
  157. * Onglets
  158. */
  159. $head=array();
  160. if ($id > 0)
  161. {
  162. // Si edition contact deja existant
  163. $object = new Contact($db);
  164. $res=$object->fetch($id, $user);
  165. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  166. $res=$object->fetch_optionals($object->id,$extralabels);
  167. // Show tabs
  168. $head = contact_prepare_head($object);
  169. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  170. }
  171. if (! empty($id) && $action != 'edit' && $action != 'create')
  172. {
  173. $objsoc = new Societe($db);
  174. /*
  175. * Fiche en mode visualisation
  176. */
  177. dol_htmloutput_errors($error,$errors);
  178. dol_fiche_head($head, 'agenda', $title, -1, 'contact');
  179. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
  180. $morehtmlref='<div class="refidno">';
  181. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  182. {
  183. $objsoc=new Societe($db);
  184. $objsoc->fetch($object->socid);
  185. // Thirdparty
  186. $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
  187. if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1);
  188. else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
  189. }
  190. $morehtmlref.='</div>';
  191. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  192. print '<div class="fichecenter">';
  193. print '<div class="underbanner clearboth"></div>';
  194. $object->info($id);
  195. print dol_print_object_info($object, 1);
  196. print '</div>';
  197. print dol_fiche_end();
  198. // Actions buttons
  199. $objcon=$object;
  200. $object->fetch_thirdparty();
  201. $objthirdparty=$object->thirdparty;
  202. $out='';
  203. $permok=$user->rights->agenda->myactions->create;
  204. if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
  205. {
  206. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  207. if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
  208. $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
  209. //$out.=$langs->trans("AddAnAction").' ';
  210. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  211. //$out.="</a>";
  212. }
  213. print '<div class="tabsAction">';
  214. if (! empty($conf->agenda->enabled))
  215. {
  216. if (! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create))
  217. {
  218. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  219. }
  220. else
  221. {
  222. print '<a class="butActionRefused" href="#">'.$langs->trans("AddAction").'</a>';
  223. }
  224. }
  225. print '</div>';
  226. if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
  227. {
  228. $param='&id='.$id;
  229. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  230. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  231. print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'','');
  232. // List of all actions
  233. $filters=array();
  234. $filters['search_agenda_label']=$search_agenda_label;
  235. show_actions_done($conf,$langs,$db,$objthirdparty,$object,0,$actioncode, '', $filters, $sortfield, $sortorder);
  236. }
  237. }
  238. }
  239. llxFooter();
  240. $db->close();