PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contact/agenda.php

http://github.com/Dolibarr/dolibarr
PHP | 292 lines | 179 code | 53 blank | 60 comment | 60 complexity | 58d8eefddb3f3c4f404ed3dfd483dc0d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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", 'alpha');
  81. $sortorder = GETPOST("sortorder", 'alpha');
  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 = '<div class="refidno">';
  182. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  183. $objsoc = new Societe($db);
  184. $objsoc->fetch($object->socid);
  185. // Thirdparty
  186. $morehtmlref .= $langs->trans('ThirdParty').' : ';
  187. if ($objsoc->id > 0) {
  188. $morehtmlref .= $objsoc->getNomUrl(1);
  189. } else {
  190. $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
  191. }
  192. }
  193. $morehtmlref .= '</div>';
  194. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  195. print '<div class="fichecenter">';
  196. print '<div class="underbanner clearboth"></div>';
  197. $object->info($id);
  198. dol_print_object_info($object, 1);
  199. print '</div>';
  200. print dol_get_fiche_end();
  201. // Actions buttons
  202. $objcon = $object;
  203. $object->fetch_thirdparty();
  204. $objthirdparty = $object->thirdparty;
  205. $out = '';
  206. $permok = $user->rights->agenda->myactions->create;
  207. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  208. if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
  209. $out .= '&amp;originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&amp;socid='.$objthirdparty->id : '');
  210. }
  211. $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 : ''));
  212. $out .= '&amp;datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog'));
  213. }
  214. $newcardbutton = '';
  215. if (!empty($conf->agenda->enabled)) {
  216. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  217. $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  218. }
  219. }
  220. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  221. print '<br>';
  222. $param = '&id='.$id;
  223. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  224. $param .= '&contextpage='.$contextpage;
  225. }
  226. if ($limit > 0 && $limit != $conf->liste_limit) {
  227. $param .= '&limit='.$limit;
  228. }
  229. print load_fiche_titre($langs->trans("ActionsOnContact"), $newcardbutton, '');
  230. //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
  231. // List of all actions
  232. $filters = array();
  233. $filters['search_agenda_label'] = $search_agenda_label;
  234. show_actions_done($conf, $langs, $db, $objthirdparty, $object, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  235. }
  236. }
  237. }
  238. llxFooter();
  239. $db->close();