agenda.php 10.0 KB

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