document.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/comm/action/document.php
  24. * \ingroup agenda
  25. * \brief Page of documents linked to actions
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. if (isModEnabled('project')) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('companies', 'commercial', 'other', 'bills'));
  41. $id = GETPOST('id', 'int');
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. // Security check
  45. $socid = GETPOST('socid', 'int');
  46. if ($user->socid) {
  47. $socid = $user->socid;
  48. }
  49. if ($user->socid > 0) {
  50. unset($_GET["action"]);
  51. $action = '';
  52. }
  53. $object = new ActionComm($db);
  54. if ($id > 0) {
  55. $ret = $object->fetch($id);
  56. $object->fetch_thirdparty();
  57. }
  58. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  59. $hookmanager->initHooks(array('actioncard', 'globalcard'));
  60. // Get parameters
  61. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  62. $sortfield = GETPOST('sortfield', 'aZ09comma');
  63. $sortorder = GETPOST('sortorder', 'aZ09comma');
  64. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  65. if (empty($page) || $page == -1) {
  66. $page = 0;
  67. } // If $page is not defined, or '' or -1
  68. $offset = $limit * $page;
  69. $pageprev = $page - 1;
  70. $pagenext = $page + 1;
  71. if (!$sortorder) {
  72. $sortorder = "ASC";
  73. }
  74. if (!$sortfield) {
  75. $sortfield = "name";
  76. }
  77. $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
  78. $modulepart = 'actions';
  79. $result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  80. if ($user->socid && $socid) {
  81. $result = restrictedArea($user, 'societe', $socid);
  82. }
  83. $usercancreate = $user->rights->agenda->allactions->create || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create);
  84. $permissiontoadd = $usercancreate;
  85. /*
  86. * Actions
  87. */
  88. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  89. /*
  90. * View
  91. */
  92. $form = new Form($db);
  93. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  94. llxHeader('', $langs->trans("Agenda"), $help_url);
  95. $now = dol_now();
  96. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  97. if ($object->id > 0) {
  98. $result1 = $object->fetch($id);
  99. $result2 = $object->fetch_thirdparty();
  100. $result3 = $object->fetch_contact();
  101. $result4 = $object->fetch_userassigned();
  102. $result5 = $object->fetch_optionals();
  103. if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
  104. dol_print_error($db, $object->error);
  105. exit;
  106. }
  107. if ($object->authorid > 0) {
  108. $tmpuser = new User($db); $res = $tmpuser->fetch($object->authorid); $object->author = $tmpuser;
  109. }
  110. if ($object->usermodid > 0) {
  111. $tmpuser = new User($db); $res = $tmpuser->fetch($object->usermodid); $object->usermod = $tmpuser;
  112. }
  113. $author = new User($db);
  114. $author->fetch($object->author->id);
  115. $object->author = $author;
  116. $head = actions_prepare_head($object);
  117. print dol_get_fiche_head($head, 'documents', $langs->trans("Action"), -1, 'action');
  118. $linkback = img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="hideonsmartphone pictoactionview"');
  119. $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list">'.$langs->trans("BackToList").'</a>';
  120. // Link to other agenda views
  121. $out = '';
  122. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
  123. $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">'.$langs->trans("ViewPerUser").'</a>';
  124. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="hideonsmartphone pictoactionview"');
  125. $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">'.$langs->trans("ViewCal").'</a>';
  126. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
  127. $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">'.$langs->trans("ViewWeek").'</a>';
  128. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
  129. $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">'.$langs->trans("ViewDay").'</a>';
  130. // Add more views from hooks
  131. $parameters = array();
  132. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  133. if (empty($reshook)) {
  134. $out .= $hookmanager->resPrint;
  135. } elseif ($reshook > 1) {
  136. $out = $hookmanager->resPrint;
  137. }
  138. $linkback .= $out;
  139. $morehtmlref = '<div class="refidno">';
  140. // Thirdparty
  141. //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  142. // Project
  143. if (isModEnabled('project')) {
  144. $langs->load("projects");
  145. //$morehtmlref .= '<br>';
  146. if (0) {
  147. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  148. if ($action != 'classify') {
  149. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  150. }
  151. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  152. } else {
  153. if (!empty($object->fk_project)) {
  154. $proj = new Project($db);
  155. $proj->fetch($object->fk_project);
  156. $morehtmlref .= $proj->getNomUrl(1);
  157. if ($proj->title) {
  158. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  159. }
  160. }
  161. }
  162. }
  163. $morehtmlref .= '</div>';
  164. dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref);
  165. print '<div class="fichecenter">';
  166. print '<div class="underbanner clearboth"></div>';
  167. // Affichage fiche action en mode visu
  168. print '<table class="border tableforfield centpercent">';
  169. // Type of event
  170. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  171. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">';
  172. print $object->getTypePicto();
  173. print $langs->trans("Action".$object->type_code);
  174. print '</td></tr>';
  175. }
  176. // Full day event
  177. print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent ? 1 : 0, 3).'</td></tr>';
  178. // Date start
  179. print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
  180. if (empty($object->fulldayevent)) {
  181. print dol_print_date($object->datep, 'dayhour', 'tzuser');
  182. } else {
  183. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  184. print dol_print_date($object->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  185. }
  186. if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) {
  187. print img_warning($langs->trans("Late"));
  188. }
  189. print '</td>';
  190. print '</tr>';
  191. // Date end
  192. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
  193. if (empty($object->fulldayevent)) {
  194. print dol_print_date($object->datef, 'dayhour', 'tzuser');
  195. } else {
  196. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  197. print dol_print_date($object->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  198. }
  199. if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now - $delay_warning)) {
  200. print img_warning($langs->trans("Late"));
  201. }
  202. print '</td></tr>';
  203. // Location
  204. if (empty($conf->global->AGENDA_DISABLE_LOCATION)) {
  205. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$object->location.'</td></tr>';
  206. }
  207. // Assigned to
  208. print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  209. $listofuserid = array();
  210. if (empty($donotclearsession)) {
  211. if ($object->userownerid > 0) {
  212. $listofuserid[$object->userownerid] = array('id'=>$object->userownerid, 'transparency'=>$object->transparency); // Owner first
  213. }
  214. if (!empty($object->userassigned)) { // Now concat assigned users
  215. // Restore array with key with same value than param 'id'
  216. $tmplist1 = $object->userassigned;
  217. foreach ($tmplist1 as $key => $val) {
  218. if ($val['id'] && $val['id'] != $object->userownerid) {
  219. $listofuserid[$val['id']] = $val;
  220. }
  221. }
  222. }
  223. $_SESSION['assignedtouser'] = json_encode($listofuserid);
  224. } else {
  225. if (!empty($_SESSION['assignedtouser'])) {
  226. $listofuserid = json_decode($_SESSION['assignedtouser'], true);
  227. }
  228. }
  229. $listofcontactid = array(); // not used yet
  230. $listofotherid = array(); // not used yet
  231. print '<div class="assignedtouser">';
  232. print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
  233. print '</div>';
  234. /*if (in_array($user->id,array_keys($listofuserid)))
  235. {
  236. print '<div class="myavailability">';
  237. print $langs->trans("MyAvailability").': '.(($object->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody
  238. print '</div>';
  239. }*/
  240. print ' </td></tr>';
  241. print '</table>';
  242. print '<table class="border tableforfield centpercent">';
  243. // Build file list
  244. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  245. $totalsize = 0;
  246. foreach ($filearray as $key => $file) {
  247. $totalsize += $file['size'];
  248. }
  249. print '<tr><td class="titlefield" class="nowrap">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  250. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  251. print '</table>';
  252. print '</div>';
  253. print dol_get_fiche_end();
  254. $modulepart = 'actions';
  255. $permissiontoadd = $user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create;
  256. $param = '&id='.$object->id;
  257. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  258. } else {
  259. print $langs->trans("ErrorUnknown");
  260. }
  261. // End of page
  262. llxFooter();
  263. $db->close();