agenda.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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/functions2.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  28. if (!empty($conf->projet->enabled)) {
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("companies", "contracts"));
  34. if (GETPOST('actioncode', 'array')) {
  35. $actioncode = GETPOST('actioncode', 'array', 3);
  36. if (!count($actioncode)) {
  37. $actioncode = '0';
  38. }
  39. } else {
  40. $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));
  41. }
  42. $search_agenda_label = GETPOST('search_agenda_label');
  43. $action = GETPOST('action', 'alpha');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. $id = GETPOST('id', 'int');
  46. $ref = GETPOST('ref', 'alpha');
  47. // Security check
  48. if ($user->socid) {
  49. $socid = $user->socid;
  50. }
  51. $result = restrictedArea($user, 'contrat', $id, '');
  52. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  53. $sortfield = GETPOST('sortfield', 'aZ09comma');
  54. $sortorder = GETPOST('sortorder', 'aZ09comma');
  55. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  56. if (empty($page) || $page == -1) {
  57. $page = 0;
  58. } // If $page is not defined, or '' or -1
  59. $offset = $limit * $page;
  60. $pageprev = $page - 1;
  61. $pagenext = $page + 1;
  62. if (!$sortfield) {
  63. $sortfield = 'a.datep,a.id';
  64. }
  65. if (!$sortorder) {
  66. $sortorder = 'DESC,DESC';
  67. }
  68. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  69. $hookmanager->initHooks(array('agendacontract', 'globalcard'));
  70. /*
  71. * Actions
  72. */
  73. $parameters = array('id'=>$id);
  74. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  75. if ($reshook < 0) {
  76. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. }
  78. if (empty($reshook)) {
  79. // Cancel
  80. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  81. header("Location: ".$backtopage);
  82. exit;
  83. }
  84. // Purge search criteria
  85. 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
  86. $actioncode = '';
  87. $search_agenda_label = '';
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. $form = new Form($db);
  94. $formfile = new FormFile($db);
  95. if (!empty($conf->projet->enabled)) {
  96. $formproject = new FormProjets($db);
  97. }
  98. if ($id > 0) {
  99. // Load object modContract
  100. $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
  101. if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
  102. $module = substr($module, 0, dol_strlen($module) - 4);
  103. }
  104. $result = dol_include_once('/core/modules/contract/'.$module.'.php');
  105. if ($result > 0) {
  106. $modCodeContract = new $module();
  107. }
  108. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  109. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  110. $object = new Contrat($db);
  111. $result = $object->fetch($id);
  112. $object->fetch_thirdparty();
  113. $title = $langs->trans("Agenda");
  114. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) {
  115. $title = $object->ref." - ".$title;
  116. }
  117. llxHeader('', $title);
  118. if (!empty($conf->notification->enabled)) {
  119. $langs->load("mails");
  120. }
  121. $head = contract_prepare_head($object);
  122. print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract');
  123. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  124. $morehtmlref = '';
  125. if (!empty($modCodeContract->code_auto)) {
  126. $morehtmlref .= $object->ref;
  127. } else {
  128. $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
  129. $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
  130. }
  131. $permtoedit = 0;
  132. $morehtmlref .= '<div class="refidno">';
  133. // Ref customer
  134. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', 0, 1);
  135. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  136. // Ref supplier
  137. $morehtmlref .= '<br>';
  138. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', 0, 1);
  139. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  140. // Thirdparty
  141. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  142. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  143. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
  144. }
  145. // Project
  146. if (!empty($conf->projet->enabled)) {
  147. $langs->load("projects");
  148. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  149. if ($user->rights->contrat->creer) {
  150. if ($action != 'classify') {
  151. //$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a>';
  152. $morehtmlref .= ' : ';
  153. }
  154. if ($action == 'classify') {
  155. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  156. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  157. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  158. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  159. $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  160. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  161. $morehtmlref .= '</form>';
  162. } else {
  163. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
  164. }
  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 .= ' - '.$proj->title;
  172. }
  173. } else {
  174. $morehtmlref .= '';
  175. }
  176. }
  177. }
  178. $morehtmlref .= '</div>';
  179. dol_banner_tab($object, 'id', $linkback, 1, 'ref', 'none', $morehtmlref);
  180. print '<div class="fichecenter">';
  181. print '<div class="underbanner clearboth"></div>';
  182. $object->info($id);
  183. dol_print_object_info($object, 1);
  184. print '</div>';
  185. print dol_get_fiche_end();
  186. // Actions buttons
  187. /*$objthirdparty=$object;
  188. $objcon=new stdClass();
  189. $out='';
  190. $permok=$user->rights->agenda->myactions->create;
  191. if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
  192. {
  193. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  194. if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
  195. $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1';
  196. //$out.=$langs->trans("AddAnAction").' ';
  197. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  198. //$out.="</a>";
  199. }*/
  200. //print '<div class="tabsAction">';
  201. //print '</div>';
  202. $newcardbutton = '';
  203. if (!empty($conf->agenda->enabled)) {
  204. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  205. $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  206. }
  207. }
  208. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  209. print '<br>';
  210. $param = '&id='.$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. print load_fiche_titre($langs->trans("ActionsOnContract"), $newcardbutton, '');
  218. //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1);
  219. // List of all actions
  220. $filters = array();
  221. $filters['search_agenda_label'] = $search_agenda_label;
  222. // TODO Replace this with same code than into list.php
  223. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  224. }
  225. }
  226. llxFooter();
  227. $db->close();