agenda.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/contrat/agenda.php
  20. * \ingroup contrat
  21. * \brief Page of contract events
  22. */
  23. require "../main.inc.php";
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  29. if (isModEnabled('project')) {
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("companies", "contracts"));
  35. if (GETPOST('actioncode', 'array')) {
  36. $actioncode = GETPOST('actioncode', 'array', 3);
  37. if (!count($actioncode)) {
  38. $actioncode = '0';
  39. }
  40. } else {
  41. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  42. }
  43. $search_rowid = GETPOST('search_rowid');
  44. $search_agenda_label = GETPOST('search_agenda_label');
  45. $action = GETPOST('action', 'alpha');
  46. $confirm = GETPOST('confirm', 'alpha');
  47. $id = GETPOST('id', 'int');
  48. $ref = GETPOST('ref', 'alpha');
  49. // Security check
  50. if ($user->socid) {
  51. $socid = $user->socid;
  52. }
  53. // Security check
  54. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  55. $fieldtype = (!empty($id) ? 'rowid' : 'ref');
  56. $result = restrictedArea($user, 'contrat', $fieldvalue, '', '', '', $fieldtype);
  57. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  58. $sortfield = GETPOST('sortfield', 'aZ09comma');
  59. $sortorder = GETPOST('sortorder', 'aZ09comma');
  60. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  61. if (empty($page) || $page == -1) {
  62. $page = 0;
  63. } // If $page is not defined, or '' or -1
  64. $offset = $limit * $page;
  65. $pageprev = $page - 1;
  66. $pagenext = $page + 1;
  67. if (!$sortfield) {
  68. $sortfield = 'a.datep,a.id';
  69. }
  70. if (!$sortorder) {
  71. $sortorder = 'DESC,DESC';
  72. }
  73. $object = new Contrat($db);
  74. if ($id > 0 || !empty($ref)) {
  75. $result = $object->fetch($id, $ref);
  76. }
  77. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  78. $hookmanager->initHooks(array('agendacontract', 'globalcard'));
  79. $permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  80. /*
  81. * Actions
  82. */
  83. $parameters = array('id' => $id, 'ref' => $ref);
  84. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  85. if ($reshook < 0) {
  86. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  87. }
  88. if (empty($reshook)) {
  89. // Cancel
  90. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  91. header("Location: ".$backtopage);
  92. exit;
  93. }
  94. // Purge search criteria
  95. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  96. $actioncode = '';
  97. $search_agenda_label = '';
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $form = new Form($db);
  104. $formfile = new FormFile($db);
  105. if (isModEnabled('project')) {
  106. $formproject = new FormProjets($db);
  107. }
  108. if ($object->id > 0) {
  109. // Load object modContract
  110. $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
  111. if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
  112. $module = substr($module, 0, dol_strlen($module) - 4);
  113. }
  114. $result = dol_include_once('/core/modules/contract/'.$module.'.php');
  115. if ($result > 0) {
  116. $modCodeContract = new $module();
  117. }
  118. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  119. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  120. $object->fetch_thirdparty();
  121. $title = $langs->trans("Agenda");
  122. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {
  123. $title = $object->ref." - ".$title;
  124. }
  125. llxHeader('', $title);
  126. if (isModEnabled('notification')) {
  127. $langs->load("mails");
  128. }
  129. $head = contract_prepare_head($object);
  130. print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
  131. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  132. $morehtmlref = '';
  133. if (!empty($modCodeContract->code_auto)) {
  134. $morehtmlref .= $object->ref;
  135. } else {
  136. $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
  137. $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
  138. }
  139. $permtoedit = 0;
  140. $morehtmlref .= '<div class="refidno">';
  141. // Ref customer
  142. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
  143. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  144. // Ref supplier
  145. $morehtmlref .= '<br>';
  146. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
  147. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  148. // Thirdparty
  149. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  150. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  151. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
  152. }
  153. // Project
  154. if (isModEnabled('project')) {
  155. $langs->load("projects");
  156. $morehtmlref .= '<br>';
  157. if (0) {
  158. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  159. if ($action != 'classify') {
  160. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  161. }
  162. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  163. } else {
  164. if (!empty($object->fk_project)) {
  165. $proj = new Project($db);
  166. $proj->fetch($object->fk_project);
  167. $morehtmlref .= $proj->getNomUrl(1);
  168. if ($proj->title) {
  169. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  170. }
  171. }
  172. }
  173. }
  174. $morehtmlref .= '</div>';
  175. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  176. print '<div class="fichecenter">';
  177. print '<div class="underbanner clearboth"></div>';
  178. $object->info($object->id);
  179. dol_print_object_info($object, 1);
  180. print '</div>';
  181. print dol_get_fiche_end();
  182. // Actions buttons
  183. /*$objthirdparty=$object;
  184. $objcon=new stdClass();
  185. $out='';
  186. $permok=$user->rights->agenda->myactions->create;
  187. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
  188. {
  189. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  190. if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
  191. $out.=(!empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1';
  192. //$out.=$langs->trans("AddAnAction").' ';
  193. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  194. //$out.="</a>";
  195. }*/
  196. //print '<div class="tabsAction">';
  197. //print '</div>';
  198. $newcardbutton = '';
  199. if (isModEnabled('agenda')) {
  200. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  201. $backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  202. $out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage);
  203. $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  204. }
  205. }
  206. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  207. print '<br>';
  208. $param = '&id='.$object->id;
  209. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  210. $param .= '&contextpage='.$contextpage;
  211. }
  212. if ($limit > 0 && $limit != $conf->liste_limit) {
  213. $param .= '&limit='.$limit;
  214. }
  215. // Try to know count of actioncomm from cache
  216. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  217. $cachekey = 'count_events_thirdparty_'.$object->id;
  218. $nbEvent = dol_getcache($cachekey);
  219. print load_fiche_titre($langs->trans("ActionsOnContract").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>': ''), $newcardbutton, '');
  220. //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
  221. // List of all actions
  222. $filters = array();
  223. $filters['search_agenda_label'] = $search_agenda_label;
  224. $filters['search_rowid'] = $search_rowid;
  225. // TODO Replace this with same code than into list.php
  226. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  227. }
  228. }
  229. llxFooter();
  230. $db->close();