dolibarr  16.0.5
document.php
Go to the documentation of this file.
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 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 if (!empty($conf->project->enabled)) {
38  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39 }
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array('companies', 'commercial', 'other', 'bills'));
43 
44 $id = GETPOST('id', 'int');
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 
48 // Security check
49 $socid = GETPOST('socid', 'int');
50 if ($user->socid) {
51  $socid = $user->socid;
52 }
53 if ($user->socid > 0) {
54  unset($_GET["action"]);
55  $action = '';
56 }
57 
58 $object = new ActionComm($db);
59 
60 if ($id > 0) {
61  $ret = $object->fetch($id);
62  $object->fetch_thirdparty();
63 }
64 
65 // Get parameters
66 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
67 $sortfield = GETPOST('sortfield', 'aZ09comma');
68 $sortorder = GETPOST('sortorder', 'aZ09comma');
69 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
70 if (empty($page) || $page == -1) {
71  $page = 0;
72 } // If $page is not defined, or '' or -1
73 $offset = $limit * $page;
74 $pageprev = $page - 1;
75 $pagenext = $page + 1;
76 if (!$sortorder) {
77  $sortorder = "ASC";
78 }
79 if (!$sortfield) {
80  $sortfield = "name";
81 }
82 
83 $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
84 $modulepart = 'actions';
85 
86 $result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
87 if ($user->socid && $socid) {
88  $result = restrictedArea($user, 'societe', $socid);
89 }
90 
91 $permissiontoadd = $user->rights->agenda->myactions->read; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
92 
93 
94 /*
95  * Actions
96  */
97 
98 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
99 
100 
101 /*
102  * View
103  */
104 
105 $form = new Form($db);
106 
107 $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
108 
109 llxHeader('', $langs->trans("Agenda"), $help_url);
110 
111 $now = dol_now();
112 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
113 
114 if ($object->id > 0) {
115  $result1 = $object->fetch($id);
116  $result2 = $object->fetch_thirdparty();
117  $result3 = $object->fetch_contact();
118  $result4 = $object->fetch_userassigned();
119  $result5 = $object->fetch_optionals();
120 
121  if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
122  dol_print_error($db, $object->error);
123  exit;
124  }
125 
126  if ($object->authorid > 0) {
127  $tmpuser = new User($db); $res = $tmpuser->fetch($object->authorid); $object->author = $tmpuser;
128  }
129  if ($object->usermodid > 0) {
130  $tmpuser = new User($db); $res = $tmpuser->fetch($object->usermodid); $object->usermod = $tmpuser;
131  }
132 
133  $author = new User($db);
134  $author->fetch($object->author->id);
135  $object->author = $author;
136 
137 
138  $head = actions_prepare_head($object);
139 
140  print dol_get_fiche_head($head, 'documents', $langs->trans("Action"), -1, 'action');
141 
142  $linkback = img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="hideonsmartphone pictoactionview"');
143  $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list">'.$langs->trans("BackToList").'</a>';
144 
145  // Link to other agenda views
146  $out = '';
147  $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
148  $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>';
149  $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="hideonsmartphone pictoactionview"');
150  $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>';
151  $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
152  $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>';
153  $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
154  $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>';
155 
156  $linkback .= $out;
157 
158  $morehtmlref = '<div class="refidno">';
159  // Thirdparty
160  //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
161  // Project
162  if (!empty($conf->project->enabled)) {
163  $langs->load("projects");
164  //$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
165  $morehtmlref .= $langs->trans('Project').': ';
166  if (!empty($object->fk_project)) {
167  $proj = new Project($db);
168  $proj->fetch($object->fk_project);
169  $morehtmlref .= ' : '.$proj->getNomUrl(1);
170  if ($proj->title) {
171  $morehtmlref .= ' - '.$proj->title;
172  }
173  } else {
174  $morehtmlref .= '';
175  }
176  }
177  $morehtmlref .= '</div>';
178 
179  dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref);
180 
181  print '<div class="fichecenter">';
182 
183  print '<div class="underbanner clearboth"></div>';
184 
185  // Affichage fiche action en mode visu
186  print '<table class="border tableforfield centpercent">';
187 
188  // Type of event
189  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
190  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">';
191  print $object->getTypePicto();
192  print $langs->trans("Action".$object->type_code);
193  print '</td></tr>';
194  }
195 
196  // Full day event
197  print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent ? 1 : 0, 3).'</td></tr>';
198 
199  // Date start
200  print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
201  if (empty($object->fulldayevent)) {
202  print dol_print_date($object->datep, 'dayhour', 'tzuser');
203  } else {
204  $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
205  print dol_print_date($object->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
206  }
207  if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) {
208  print img_warning($langs->trans("Late"));
209  }
210  print '</td>';
211  print '</tr>';
212 
213  // Date end
214  print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
215  if (empty($object->fulldayevent)) {
216  print dol_print_date($object->datef, 'dayhour', 'tzuser');
217  } else {
218  $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
219  print dol_print_date($object->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
220  }
221  if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now - $delay_warning)) {
222  print img_warning($langs->trans("Late"));
223  }
224  print '</td></tr>';
225 
226  // Location
227  if (empty($conf->global->AGENDA_DISABLE_LOCATION)) {
228  print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$object->location.'</td></tr>';
229  }
230 
231  // Assigned to
232  print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
233  $listofuserid = array();
234  if (empty($donotclearsession)) {
235  if ($object->userownerid > 0) {
236  $listofuserid[$object->userownerid] = array('id'=>$object->userownerid, 'transparency'=>$object->transparency); // Owner first
237  }
238  if (!empty($object->userassigned)) { // Now concat assigned users
239  // Restore array with key with same value than param 'id'
240  $tmplist1 = $object->userassigned;
241  foreach ($tmplist1 as $key => $val) {
242  if ($val['id'] && $val['id'] != $object->userownerid) {
243  $listofuserid[$val['id']] = $val;
244  }
245  }
246  }
247  $_SESSION['assignedtouser'] = json_encode($listofuserid);
248  } else {
249  if (!empty($_SESSION['assignedtouser'])) {
250  $listofuserid = json_decode($_SESSION['assignedtouser'], true);
251  }
252  }
253  $listofcontactid = array(); // not used yet
254  $listofotherid = array(); // not used yet
255  print '<div class="assignedtouser">';
256  print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
257  print '</div>';
258  /*if (in_array($user->id,array_keys($listofuserid)))
259  {
260  print '<div class="myavailability">';
261  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
262  print '</div>';
263  }*/
264  print ' </td></tr>';
265 
266  print '</table>';
267 
268  print '<table class="border tableforfield centpercent">';
269 
270  // Build file list
271  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
272  $totalsize = 0;
273  foreach ($filearray as $key => $file) {
274  $totalsize += $file['size'];
275  }
276 
277 
278  print '<tr><td class="titlefield" class="nowrap">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
279  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
280 
281  print '</table>';
282 
283  print '</div>';
284 
285  print dol_get_fiche_end();
286 
287 
288  $modulepart = 'actions';
289  $permissiontoadd = $user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create;
290  $param = '&id='.$object->id;
291  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
292 } else {
293  print $langs->trans("ErrorUnknown");
294 }
295 
296 // End of page
297 llxFooter();
298 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
Project
Class to manage projects.
Definition: project.class.php:35
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
actions_prepare_head
actions_prepare_head($object)
Prepare array with list of tabs.
Definition: agenda.lib.php:413
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845