agenda.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. $result = restrictedArea($user, 'contrat', $object->id);
  81. /*
  82. * Actions
  83. */
  84. $parameters = array('id' => $id, 'ref' => $ref);
  85. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  86. if ($reshook < 0) {
  87. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  88. }
  89. if (empty($reshook)) {
  90. // Cancel
  91. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  92. header("Location: ".$backtopage);
  93. exit;
  94. }
  95. // Purge search criteria
  96. 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
  97. $actioncode = '';
  98. $search_agenda_label = '';
  99. }
  100. }
  101. /*
  102. * View
  103. */
  104. $form = new Form($db);
  105. $formfile = new FormFile($db);
  106. if (isModEnabled('project')) {
  107. $formproject = new FormProjets($db);
  108. }
  109. if ($object->id > 0) {
  110. // Load object modContract
  111. $module = (getDolGlobalString('CONTRACT_ADDON') ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
  112. if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
  113. $module = substr($module, 0, dol_strlen($module) - 4);
  114. }
  115. $result = dol_include_once('/core/modules/contract/'.$module.'.php');
  116. if ($result > 0) {
  117. $modCodeContract = new $module();
  118. }
  119. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  120. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  121. $object->fetch_thirdparty();
  122. $title = $langs->trans("Agenda");
  123. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {
  124. $title = $object->ref." - ".$title;
  125. }
  126. $help_url = 'EN:Module_Contracts|FR:Module_Contrat';
  127. llxHeader('', $title, $help_url);
  128. if (isModEnabled('notification')) {
  129. $langs->load("mails");
  130. }
  131. $head = contract_prepare_head($object);
  132. print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
  133. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  134. $morehtmlref = '';
  135. if (!empty($modCodeContract->code_auto)) {
  136. $morehtmlref .= $object->ref;
  137. } else {
  138. $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 3);
  139. $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->hasRight('contrat', 'creer'), 'string', '', 0, 2);
  140. }
  141. $permtoedit = 0;
  142. $morehtmlref .= '<div class="refidno">';
  143. // Ref customer
  144. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
  145. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  146. // Ref supplier
  147. $morehtmlref .= '<br>';
  148. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
  149. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  150. // Thirdparty
  151. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  152. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  153. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
  154. }
  155. // Project
  156. if (isModEnabled('project')) {
  157. $langs->load("projects");
  158. $morehtmlref .= '<br>';
  159. if (0) {
  160. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  161. if ($action != 'classify') {
  162. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  163. }
  164. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  165. } else {
  166. if (!empty($object->fk_project)) {
  167. $proj = new Project($db);
  168. $proj->fetch($object->fk_project);
  169. $morehtmlref .= $proj->getNomUrl(1);
  170. if ($proj->title) {
  171. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  172. }
  173. }
  174. }
  175. }
  176. $morehtmlref .= '</div>';
  177. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  178. print '<div class="fichecenter">';
  179. print '<div class="underbanner clearboth"></div>';
  180. $object->info($object->id);
  181. dol_print_object_info($object, 1);
  182. print '</div>';
  183. print dol_get_fiche_end();
  184. // Actions buttons
  185. /*$objthirdparty=$object;
  186. $objcon=new stdClass();
  187. $out='';
  188. $permok=$user->rights->agenda->myactions->create;
  189. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
  190. {
  191. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  192. if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
  193. $out.=(!empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1';
  194. //$out.=$langs->trans("AddAnAction").' ';
  195. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  196. //$out.="</a>";
  197. }*/
  198. //print '<div class="tabsAction">';
  199. //print '</div>';
  200. $newcardbutton = '';
  201. if (isModEnabled('agenda')) {
  202. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  203. $backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  204. $out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage);
  205. $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  206. }
  207. }
  208. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  209. print '<br>';
  210. $param = '&id='.$object->id;
  211. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  212. $param .= '&contextpage='.$contextpage;
  213. }
  214. if ($limit > 0 && $limit != $conf->liste_limit) {
  215. $param .= '&limit='.$limit;
  216. }
  217. // Try to know count of actioncomm from cache
  218. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  219. $cachekey = 'count_events_thirdparty_'.$object->id;
  220. $nbEvent = dol_getcache($cachekey);
  221. print load_fiche_titre($langs->trans("ActionsOnContract").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : ''), $newcardbutton, '');
  222. //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
  223. // List of all actions
  224. $filters = array();
  225. $filters['search_agenda_label'] = $search_agenda_label;
  226. $filters['search_rowid'] = $search_rowid;
  227. // TODO Replace this with same code than into list.php
  228. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  229. }
  230. }
  231. llxFooter();
  232. $db->close();