document.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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->hasRight('agenda', 'allactions', 'create') || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('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|DE:Modul_Terminplanung';
  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);
  109. $res = $tmpuser->fetch($object->authorid);
  110. $object->author = $tmpuser;
  111. }
  112. if ($object->usermodid > 0) {
  113. $tmpuser = new User($db);
  114. $res = $tmpuser->fetch($object->usermodid);
  115. $object->usermod = $tmpuser;
  116. }
  117. $author = new User($db);
  118. $author->fetch($object->author->id);
  119. $object->author = $author;
  120. $head = actions_prepare_head($object);
  121. print dol_get_fiche_head($head, 'documents', $langs->trans("Action"), -1, 'action');
  122. $linkback = img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="hideonsmartphone pictoactionview"');
  123. $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list">'.$langs->trans("BackToList").'</a>';
  124. // Link to other agenda views
  125. $out = '';
  126. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
  127. $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>';
  128. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="hideonsmartphone pictoactionview"');
  129. $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>';
  130. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
  131. $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>';
  132. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
  133. $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>';
  134. // Add more views from hooks
  135. $parameters = array();
  136. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  137. if (empty($reshook)) {
  138. $out .= $hookmanager->resPrint;
  139. } elseif ($reshook > 1) {
  140. $out = $hookmanager->resPrint;
  141. }
  142. $linkback .= $out;
  143. $morehtmlref = '<div class="refidno">';
  144. // Thirdparty
  145. //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  146. // Project
  147. if (isModEnabled('project')) {
  148. $langs->load("projects");
  149. //$morehtmlref .= '<br>';
  150. if (0) {
  151. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  152. if ($action != 'classify') {
  153. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  154. }
  155. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  156. } else {
  157. if (!empty($object->fk_project)) {
  158. $proj = new Project($db);
  159. $proj->fetch($object->fk_project);
  160. $morehtmlref .= $proj->getNomUrl(1);
  161. if ($proj->title) {
  162. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  163. }
  164. }
  165. }
  166. }
  167. $morehtmlref .= '</div>';
  168. dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref);
  169. print '<div class="fichecenter">';
  170. print '<div class="underbanner clearboth"></div>';
  171. // Affichage fiche action en mode visu
  172. print '<table class="border tableforfield centpercent">';
  173. // Type of event
  174. if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
  175. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">';
  176. print $object->getTypePicto();
  177. print $langs->trans("Action".$object->type_code);
  178. print '</td></tr>';
  179. }
  180. // Full day event
  181. print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent ? 1 : 0, 3).'</td></tr>';
  182. // Date start
  183. print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
  184. if (empty($object->fulldayevent)) {
  185. print dol_print_date($object->datep, 'dayhour', 'tzuser');
  186. } else {
  187. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  188. print dol_print_date($object->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  189. }
  190. if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) {
  191. print img_warning($langs->trans("Late"));
  192. }
  193. print '</td>';
  194. print '</tr>';
  195. // Date end
  196. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
  197. if (empty($object->fulldayevent)) {
  198. print dol_print_date($object->datef, 'dayhour', 'tzuser');
  199. } else {
  200. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  201. print dol_print_date($object->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  202. }
  203. if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now - $delay_warning)) {
  204. print img_warning($langs->trans("Late"));
  205. }
  206. print '</td></tr>';
  207. // Location
  208. if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
  209. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$object->location.'</td></tr>';
  210. }
  211. // Assigned to
  212. print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  213. $listofuserid = array();
  214. if (empty($donotclearsession)) {
  215. if ($object->userownerid > 0) {
  216. $listofuserid[$object->userownerid] = array('id'=>$object->userownerid, 'transparency'=>$object->transparency); // Owner first
  217. }
  218. if (!empty($object->userassigned)) { // Now concat assigned users
  219. // Restore array with key with same value than param 'id'
  220. $tmplist1 = $object->userassigned;
  221. foreach ($tmplist1 as $key => $val) {
  222. if ($val['id'] && $val['id'] != $object->userownerid) {
  223. $listofuserid[$val['id']] = $val;
  224. }
  225. }
  226. }
  227. $_SESSION['assignedtouser'] = json_encode($listofuserid);
  228. } else {
  229. if (!empty($_SESSION['assignedtouser'])) {
  230. $listofuserid = json_decode($_SESSION['assignedtouser'], true);
  231. }
  232. }
  233. $listofcontactid = array(); // not used yet
  234. $listofotherid = array(); // not used yet
  235. print '<div class="assignedtouser">';
  236. print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
  237. print '</div>';
  238. /*if (in_array($user->id,array_keys($listofuserid)))
  239. {
  240. print '<div class="myavailability">';
  241. 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
  242. print '</div>';
  243. }*/
  244. print ' </td></tr>';
  245. print '</table>';
  246. print '<table class="border tableforfield centpercent">';
  247. // Build file list
  248. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  249. $totalsize = 0;
  250. foreach ($filearray as $key => $file) {
  251. $totalsize += $file['size'];
  252. }
  253. print '<tr><td class="titlefield" class="nowrap">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  254. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  255. print '</table>';
  256. print '</div>';
  257. print dol_get_fiche_end();
  258. $modulepart = 'actions';
  259. $permissiontoadd = $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create');
  260. $param = '&id='.$object->id;
  261. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  262. } else {
  263. print $langs->trans("ErrorUnknown");
  264. }
  265. // End of page
  266. llxFooter();
  267. $db->close();