document.php 10 KB

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