agenda.php 11 KB

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