myobject_agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  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/modulebuilder/template/myobject_agenda.php
  20. * \ingroup mymodule
  21. * \brief Page of MyObject events
  22. */
  23. // Load Dolibarr environment
  24. $res = 0;
  25. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  26. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  27. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  28. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  29. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  30. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  31. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  32. // Try main.inc.php using relative path
  33. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  34. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  35. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  36. if (!$res) die("Include of main fails");
  37. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  40. dol_include_once('/mymodule/class/myobject.class.php');
  41. dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
  42. // Load translation files required by the page
  43. $langs->loadLangs(array("mymodule@mymodule", "other"));
  44. // Get parameters
  45. $id = GETPOST('id', 'int');
  46. $ref = GETPOST('ref', 'alpha');
  47. $action = GETPOST('action', 'alpha');
  48. $cancel = GETPOST('cancel', 'aZ09');
  49. $backtopage = GETPOST('backtopage', 'alpha');
  50. if (GETPOST('actioncode', 'array'))
  51. {
  52. $actioncode = GETPOST('actioncode', 'array', 3);
  53. if (!count($actioncode)) $actioncode = '0';
  54. }
  55. else
  56. {
  57. $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));
  58. }
  59. $search_agenda_label = GETPOST('search_agenda_label');
  60. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  61. $sortfield = GETPOST("sortfield", 'alpha');
  62. $sortorder = GETPOST("sortorder", 'alpha');
  63. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  64. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  65. $offset = $limit * $page;
  66. $pageprev = $page - 1;
  67. $pagenext = $page + 1;
  68. if (!$sortfield) $sortfield = 'a.datep,a.id';
  69. if (!$sortorder) $sortorder = 'DESC,DESC';
  70. // Initialize technical objects
  71. $object = new MyObject($db);
  72. $extrafields = new ExtraFields($db);
  73. $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  74. $hookmanager->initHooks(array('myobjectagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  75. // Fetch optionals attributes and labels
  76. $extrafields->fetch_name_optionals_label($object->table_element);
  77. // Load object
  78. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  79. if ($id > 0 || !empty($ref)) $upload_dir = $conf->mymodule->multidir_output[$object->entity]."/".$object->id;
  80. // Security check - Protection if external user
  81. //if ($user->socid > 0) accessforbidden();
  82. //if ($user->socid > 0) $socid = $user->socid;
  83. //$result = restrictedArea($user, 'mymodule', $object->id);
  84. $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php
  85. /*
  86. * Actions
  87. */
  88. $parameters = array('id'=>$id);
  89. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  90. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  91. if (empty($reshook))
  92. {
  93. // Cancel
  94. if (GETPOST('cancel', 'alpha') && !empty($backtopage))
  95. {
  96. header("Location: ".$backtopage);
  97. exit;
  98. }
  99. // Purge search criteria
  100. 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
  101. {
  102. $actioncode = '';
  103. $search_agenda_label = '';
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. $form = new Form($db);
  110. if ($object->id > 0)
  111. {
  112. $title = $langs->trans("Agenda");
  113. //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  114. $help_url = '';
  115. llxHeader('', $title, $help_url);
  116. if (!empty($conf->notification->enabled)) $langs->load("mails");
  117. $head = myobjectPrepareHead($object);
  118. dol_fiche_head($head, 'agenda', $langs->trans("MyObject"), -1, $object->picto);
  119. // Object card
  120. // ------------------------------------------------------------
  121. $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  122. $morehtmlref = '<div class="refidno">';
  123. /*
  124. // Ref customer
  125. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  126. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  127. // Thirdparty
  128. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  129. // Project
  130. if (! empty($conf->projet->enabled))
  131. {
  132. $langs->load("projects");
  133. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  134. if ($permissiontoadd)
  135. {
  136. if ($action != 'classify')
  137. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  138. $morehtmlref.=' : ';
  139. if ($action == 'classify') {
  140. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  141. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  142. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  143. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  144. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  145. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  146. $morehtmlref.='</form>';
  147. } else {
  148. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  149. }
  150. } else {
  151. if (! empty($object->fk_project)) {
  152. $proj = new Project($db);
  153. $proj->fetch($object->fk_project);
  154. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  155. $morehtmlref.=$proj->ref;
  156. $morehtmlref.='</a>';
  157. } else {
  158. $morehtmlref.='';
  159. }
  160. }
  161. }*/
  162. $morehtmlref .= '</div>';
  163. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  164. print '<div class="fichecenter">';
  165. print '<div class="underbanner clearboth"></div>';
  166. $object->info($object->id);
  167. dol_print_object_info($object, 1);
  168. print '</div>';
  169. dol_fiche_end();
  170. // Actions buttons
  171. $objthirdparty = $object;
  172. $objcon = new stdClass();
  173. $out = '&origin='.$object->element.'&originid='.$object->id;
  174. $permok = $user->rights->agenda->myactions->create;
  175. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
  176. {
  177. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  178. if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
  179. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
  180. //$out.=$langs->trans("AddAnAction").' ';
  181. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  182. //$out.="</a>";
  183. }
  184. print '<div class="tabsAction">';
  185. if (!empty($conf->agenda->enabled))
  186. {
  187. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
  188. {
  189. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  190. }
  191. else
  192. {
  193. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  194. }
  195. }
  196. print '</div>';
  197. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
  198. {
  199. $param = '&id='.$object->id.'&socid='.$socid;
  200. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  201. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  202. //print load_fiche_titre($langs->trans("ActionsOnMyObject"), '', '');
  203. // List of all actions
  204. $filters = array();
  205. $filters['search_agenda_label'] = $search_agenda_label;
  206. // TODO Replace this with same code than into list.php
  207. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  208. }
  209. }
  210. // End of page
  211. llxFooter();
  212. $db->close();