document.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. if (!empty($conf->projet->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. }
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('companies', 'commercial', 'other', 'bills'));
  40. $id = GETPOST('id', 'int');
  41. $action = GETPOST('action', 'aZ09');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. // Security check
  44. $socid = GETPOST('socid', 'int');
  45. if ($user->socid) {
  46. $socid = $user->socid;
  47. }
  48. if ($user->socid > 0) {
  49. unset($_GET["action"]);
  50. $action = '';
  51. }
  52. $object = new ActionComm($db);
  53. if ($id > 0) {
  54. $ret = $object->fetch($id);
  55. $object->fetch_thirdparty();
  56. }
  57. // Get parameters
  58. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  59. $sortfield = GETPOST('sortfield', 'aZ09comma');
  60. $sortorder = GETPOST('sortorder', 'aZ09comma');
  61. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  62. if (empty($page) || $page == -1) {
  63. $page = 0;
  64. } // If $page is not defined, or '' or -1
  65. $offset = $limit * $page;
  66. $pageprev = $page - 1;
  67. $pagenext = $page + 1;
  68. if (!$sortorder) {
  69. $sortorder = "ASC";
  70. }
  71. if (!$sortfield) {
  72. $sortfield = "name";
  73. }
  74. $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
  75. $modulepart = 'actions';
  76. $result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  77. if ($user->socid && $socid) {
  78. $result = restrictedArea($user, 'societe', $socid);
  79. }
  80. $permissiontoadd = $user->rights->agenda->myactions->read; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  81. /*
  82. * Actions
  83. */
  84. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  85. /*
  86. * View
  87. */
  88. $form = new Form($db);
  89. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  90. llxHeader('', $langs->trans("Agenda"), $help_url);
  91. $now = dol_now();
  92. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  93. if ($object->id > 0) {
  94. $result1 = $object->fetch($id);
  95. $result2 = $object->fetch_thirdparty();
  96. $result3 = $object->fetch_contact();
  97. $result4 = $object->fetch_userassigned();
  98. $result5 = $object->fetch_optionals();
  99. if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
  100. dol_print_error($db, $object->error);
  101. exit;
  102. }
  103. if ($object->authorid > 0) {
  104. $tmpuser = new User($db); $res = $tmpuser->fetch($object->authorid); $object->author = $tmpuser;
  105. }
  106. if ($object->usermodid > 0) {
  107. $tmpuser = new User($db); $res = $tmpuser->fetch($object->usermodid); $object->usermod = $tmpuser;
  108. }
  109. $author = new User($db);
  110. $author->fetch($object->author->id);
  111. $object->author = $author;
  112. $head = actions_prepare_head($object);
  113. print dol_get_fiche_head($head, 'documents', $langs->trans("Action"), -1, 'action');
  114. $linkback = img_picto($langs->trans("BackToList"), 'object_list', 'class="hideonsmartphone pictoactionview"');
  115. $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list">'.$langs->trans("BackToList").'</a>';
  116. // Link to other agenda views
  117. $out = '';
  118. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
  119. $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>';
  120. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="hideonsmartphone pictoactionview"');
  121. $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>';
  122. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
  123. $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>';
  124. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
  125. $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>';
  126. $linkback .= $out;
  127. $morehtmlref = '<div class="refidno">';
  128. // Thirdparty
  129. //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  130. // Project
  131. if (!empty($conf->projet->enabled)) {
  132. $langs->load("projects");
  133. //$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  134. $morehtmlref .= $langs->trans('Project').': ';
  135. if (!empty($object->fk_project)) {
  136. $proj = new Project($db);
  137. $proj->fetch($object->fk_project);
  138. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  139. if ($proj->title) {
  140. $morehtmlref .= ' - '.$proj->title;
  141. }
  142. } else {
  143. $morehtmlref .= '';
  144. }
  145. }
  146. $morehtmlref .= '</div>';
  147. dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref);
  148. print '<div class="fichecenter">';
  149. print '<div class="underbanner clearboth"></div>';
  150. // Affichage fiche action en mode visu
  151. print '<table class="border tableforfield centpercent">';
  152. // Type of event
  153. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  154. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">';
  155. print $object->getTypePicto();
  156. print $langs->trans("Action".$object->type_code);
  157. print '</td></tr>';
  158. }
  159. // Full day event
  160. print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent, 3).'</td></tr>';
  161. // Date start
  162. print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
  163. if (!$object->fulldayevent) {
  164. print dol_print_date($object->datep, 'dayhour', 'tzuser');
  165. } else {
  166. print dol_print_date($object->datep, 'day', 'tzuser');
  167. }
  168. if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) {
  169. print img_warning($langs->trans("Late"));
  170. }
  171. print '</td>';
  172. print '</tr>';
  173. // Date end
  174. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
  175. if (!$object->fulldayevent) {
  176. print dol_print_date($object->datef, 'dayhour', 'tzuser');
  177. } else {
  178. print dol_print_date($object->datef, 'day', 'tzuser');
  179. }
  180. if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now - $delay_warning)) {
  181. print img_warning($langs->trans("Late"));
  182. }
  183. print '</td></tr>';
  184. // Location
  185. if (empty($conf->global->AGENDA_DISABLE_LOCATION)) {
  186. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$object->location.'</td></tr>';
  187. }
  188. // Assigned to
  189. print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  190. $listofuserid = array();
  191. if (empty($donotclearsession)) {
  192. if ($object->userownerid > 0) {
  193. $listofuserid[$object->userownerid] = array('id'=>$object->userownerid, 'transparency'=>$object->transparency); // Owner first
  194. }
  195. if (!empty($object->userassigned)) { // Now concat assigned users
  196. // Restore array with key with same value than param 'id'
  197. $tmplist1 = $object->userassigned;
  198. foreach ($tmplist1 as $key => $val) {
  199. if ($val['id'] && $val['id'] != $object->userownerid) {
  200. $listofuserid[$val['id']] = $val;
  201. }
  202. }
  203. }
  204. $_SESSION['assignedtouser'] = json_encode($listofuserid);
  205. } else {
  206. if (!empty($_SESSION['assignedtouser'])) {
  207. $listofuserid = json_decode($_SESSION['assignedtouser'], true);
  208. }
  209. }
  210. $listofcontactid = array(); // not used yet
  211. $listofotherid = array(); // not used yet
  212. print '<div class="assignedtouser">';
  213. print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
  214. print '</div>';
  215. /*if (in_array($user->id,array_keys($listofuserid)))
  216. {
  217. print '<div class="myavailability">';
  218. 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
  219. print '</div>';
  220. }*/
  221. print ' </td></tr>';
  222. print '</table>';
  223. print '<table class="border tableforfield centpercent">';
  224. // Build file list
  225. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  226. $totalsize = 0;
  227. foreach ($filearray as $key => $file) {
  228. $totalsize += $file['size'];
  229. }
  230. print '<tr><td class="titlefield" class="nowrap">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  231. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  232. print '</table>';
  233. print '</div>';
  234. print dol_get_fiche_end();
  235. $modulepart = 'actions';
  236. $permissiontoadd = $user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create;
  237. $param = '&id='.$object->id;
  238. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  239. } else {
  240. print $langs->trans("ErrorUnknown");
  241. }
  242. // End of page
  243. llxFooter();
  244. $db->close();