agenda.php 11 KB

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