agenda.php 11 KB

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