dolibarr 18.0.6
agenda.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
51function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $action, $showextcals = array(), $actioncode = '', $usergroupid = '', $excludetype = '', $resourceid = 0)
52{
53 global $conf, $user, $langs, $db, $hookmanager;
54 global $begin_h, $end_h, $begin_d, $end_d;
55 global $massaction;
56
57 $langs->load("companies");
58
59 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
60 $formactions = new FormActions($db);
61
62 // Filters
63 //print '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="get">';
64 print '<input type="hidden" name="token" value="'.newToken().'">';
65 print '<input type="hidden" name="year" value="'.((int) $year).'">';
66 print '<input type="hidden" name="month" value="'.((int) $month).'">';
67 print '<input type="hidden" name="day" value="'.((int) $day).'">';
68 if ($massaction != 'predelete' && $massaction != 'preaffecttag') { // When $massaction == 'predelete', action may be already output to 'delete' by the mass action system.
69 print '<input type="hidden" name="action" value="'.$action.'">';
70 }
71 print '<input type="hidden" name="search_showbirthday" value="'.((int) $showbirthday).'">';
72
73 print '<div class="divsearchfield">';
74 // Type
75 $multiselect = 0;
76 if (!empty($conf->global->MAIN_ENABLE_MULTISELECT_TYPE)) { // We use an option here because it adds bugs when used on agenda page "peruser" and "list"
77 $multiselect = (!empty($conf->global->AGENDA_USE_EVENT_TYPE));
78 }
79 print img_picto($langs->trans("ActionType"), 'square', 'class="pictofixedwidth inline-block" style="color: #ddd;"');
80 print $formactions->select_type_actions($actioncode, "search_actioncode", $excludetype, (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1), 0, $multiselect, 0, 'maxwidth500 widthcentpercentminusx');
81 print '</div>';
82
83 if ($canedit) {
84 // Assigned to user
85 print '<div class="divsearchfield">';
86 print img_picto($langs->trans("ActionsToDoBy"), 'user', 'class="pictofixedwidth inline-block"');
87 print $form->select_dolusers($filtert, 'search_filtert', 1, '', !$canedit, '', '', 0, 0, 0, '', 0, '', 'minwidth150 maxwidth500 widthcentpercentminusxx');
88 print '</div>';
89
90 // Assigned to user group
91 print '<div class="divsearchfield">';
92 print img_picto($langs->trans("ToUserOfGroup"), 'object_group', 'class="pictofixedwidth inline-block"');
93 print $form->select_dolgroups($usergroupid, 'usergroup', 1, '', !$canedit, '', '', '0', false, 'minwidth100 maxwidth500 widthcentpercentminusxx');
94 print '</div>';
95
96 if (isModEnabled('resource')) {
97 include_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
98 $formresource = new FormResource($db);
99
100 // Resource
101 print '<div class="divsearchfield">';
102 print img_picto($langs->trans("Resource"), 'object_resource', 'class="pictofixedwidth inline-block"');
103 print $formresource->select_resource_list($resourceid, "search_resourceid", '', 1, 0, 0, null, '', 2, 0, 'maxwidth500');
104 print '</div>';
105 }
106 }
107
108 if (isModEnabled('societe') && $user->hasRight('societe', 'lire')) {
109 print '<div class="divsearchfield">';
110 print img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth inline-block"');
111 print $form->select_company($socid, 'search_socid', '', '&nbsp;', 0, 0, null, 0, 'minwidth100 maxwidth500');
112 print '</div>';
113 }
114
115 if (isModEnabled('projet') && !empty($user->rights->projet->lire)) {
116 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
117 $formproject = new FormProjets($db);
118
119 print '<div class="divsearchfield">';
120 print img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth inline-block"');
121 print $formproject->select_projects($socid ? $socid : -1, $pid, 'search_projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'maxwidth500');
122 print '</div>';
123 }
124
125 if ($canedit && !preg_match('/list/', $_SERVER["PHP_SELF"])) {
126 // Status
127 print '<div class="divsearchfield">';
128 print img_picto($langs->trans("Status"), 'setup', 'class="pictofixedwidth inline-block"');
129 $formactions->form_select_status_action('formaction', $status, 1, 'search_status', 1, 2, 'minwidth100');
130 print '</div>';
131 }
132
133 // Hooks
134 $parameters = array('canedit'=>$canedit, 'pid'=>$pid, 'socid'=>$socid);
135 $object = null;
136 $reshook = $hookmanager->executeHooks('searchAgendaFrom', $parameters, $object, $action); // Note that $action and $object may have been
137
138 print '<div class="clearboth"></div>';
139}
140
141
148function show_array_actions_to_do($max = 5)
149{
150 global $langs, $conf, $user, $db, $socid;
151
152 $now = dol_now();
153
154 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
155 include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
156
157 $sql = "SELECT a.id, a.label, a.datep as dp, a.datep2 as dp2, a.fk_user_author, a.percent";
158 $sql .= ", c.code, c.libelle as type_label";
159 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
160 $sql .= ", s.code_client, s.code_compta, s.client";
161 $sql .= ", s.logo, s.email, s.entity";
162 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a LEFT JOIN ";
163 $sql .= " ".MAIN_DB_PREFIX."c_actioncomm as c ON c.id = a.fk_action";
164 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
165 if (empty($user->rights->societe->client->voir) && !$socid) {
166 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
167 }
168 $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
169 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))";
170 if (empty($user->rights->societe->client->voir) && !$socid) {
171 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
172 }
173 if ($socid) {
174 $sql .= " AND s.rowid = ".((int) $socid);
175 }
176 $sql .= " ORDER BY a.datep DESC, a.id DESC";
177 $sql .= $db->plimit($max, 0);
178
179 $resql = $db->query($sql);
180 if ($resql) {
181 $num = $db->num_rows($resql);
182
183 print '<div class="div-table-responsive-no-min">';
184 print '<table class="noborder centpercent">';
185 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastActionsToDo", $max).'</th>';
186 print '<th colspan="2" class="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&status=todo">'.$langs->trans("FullList").'</a></th>';
187 print '</tr>';
188
189 $i = 0;
190
191 $staticaction = new ActionComm($db);
192 $customerstatic = new Client($db);
193
194 while ($i < $num) {
195 $obj = $db->fetch_object($resql);
196
197
198 print '<tr class="oddeven">';
199
200 $staticaction->type_code = $obj->code;
201 $staticaction->label = ($obj->label ? $obj->label : $obj->type_label);
202 $staticaction->id = $obj->id;
203 print '<td>'.$staticaction->getNomUrl(1, 34).'</td>';
204
205 // print '<td>'.dol_trunc($obj->label,22).'</td>';
206
207 print '<td>';
208 if ($obj->socid > 0) {
209 $customerstatic->id = $obj->socid;
210 $customerstatic->name = $obj->name;
211 //$customerstatic->name_alias = $obj->name_alias;
212 $customerstatic->code_client = $obj->code_client;
213 $customerstatic->code_compta = $obj->code_compta;
214 $customerstatic->client = $obj->client;
215 $customerstatic->logo = $obj->logo;
216 $customerstatic->email = $obj->email;
217 $customerstatic->entity = $obj->entity;
218 print $customerstatic->getNomUrl(1, '', 40);
219 }
220 print '</td>';
221
222 $datep = $db->jdate($obj->dp);
223 $datep2 = $db->jdate($obj->dp2);
224
225 // Date
226 print '<td width="100" class="right tddate">'.dol_print_date($datep, 'day').'&nbsp;';
227 $late = 0;
228 if ($obj->percent == 0 && $datep && $datep < time()) {
229 $late = 1;
230 }
231 if ($obj->percent == 0 && !$datep && $datep2 && $datep2 < time()) {
232 $late = 1;
233 }
234 if ($obj->percent > 0 && $obj->percent < 100 && $datep2 && $datep2 < time()) {
235 $late = 1;
236 }
237 if ($obj->percent > 0 && $obj->percent < 100 && !$datep2 && $datep && $datep < time()) {
238 $late = 1;
239 }
240 if ($late) {
241 print img_warning($langs->trans("Late"));
242 }
243 print "</td>";
244
245 // Statut
246 print '<td class="right" width="14">'.$staticaction->LibStatut($obj->percent, 3)."</td>\n";
247
248 print "</tr>\n";
249
250 $i++;
251 }
252 print "</table></div><br>";
253
254 $db->free($resql);
255 } else {
256 dol_print_error($db);
257 }
258}
259
260
268{
269 global $langs, $conf, $user, $db, $socid;
270
271 $now = dol_now();
272
273 $sql = "SELECT a.id, a.percent, a.datep as da, a.datep2 as da2, a.fk_user_author, a.label";
274 $sql .= ", c.code, c.libelle";
275 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
276 $sql .= ", s.code_client, s.code_compta, s.client";
277 $sql .= ", s.logo, s.email, s.entity";
278 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a LEFT JOIN ";
279 $sql .= " ".MAIN_DB_PREFIX."c_actioncomm as c ON c.id = a.fk_action ";
280 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
281 if (empty($user->rights->societe->client->voir) && !$socid) {
282 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
283 }
284 $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
285 $sql .= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))";
286 if (empty($user->rights->societe->client->voir) && !$socid) {
287 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
288 }
289 if ($socid) {
290 $sql .= " AND s.rowid = ".((int) $socid);
291 }
292 $sql .= " ORDER BY a.datep2 DESC";
293 $sql .= $db->plimit($max, 0);
294
295 $resql = $db->query($sql);
296 if ($resql) {
297 $num = $db->num_rows($resql);
298
299 print '<div class="div-table-responsive-no-min">';
300 print '<table class="noborder centpercent">';
301 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastDoneTasks", $max).'</th>';
302 print '<th colspan="2" class="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&status=done">'.$langs->trans("FullList").'</a></th>';
303 print '</tr>';
304
305 $i = 0;
306
307 $staticaction = new ActionComm($db);
308 $customerstatic = new Societe($db);
309
310 while ($i < $num) {
311 $obj = $db->fetch_object($resql);
312
313
314 print '<tr class="oddeven">';
315
316 $staticaction->type_code = $obj->code;
317 $staticaction->label = $obj->label;
318 $staticaction->id = $obj->id;
319 print '<td>'.$staticaction->getNomUrl(1, 34).'</td>';
320
321 //print '<td>'.dol_trunc($obj->label,24).'</td>';
322
323 print '<td>';
324 if ($obj->socid > 0) {
325 $customerstatic->id = $obj->socid;
326 $customerstatic->name = $obj->name;
327 //$customerstatic->name_alias = $obj->name_alias;
328 $customerstatic->code_client = $obj->code_client;
329 $customerstatic->code_compta = $obj->code_compta;
330 $customerstatic->client = $obj->client;
331 $customerstatic->logo = $obj->logo;
332 $customerstatic->email = $obj->email;
333 $customerstatic->entity = $obj->entity;
334 print $customerstatic->getNomUrl(1, '', 30);
335 }
336 print '</td>';
337
338 // Date
339 print '<td width="100" class="right tddate">'.dol_print_date($db->jdate($obj->da2), 'day');
340 print "</td>";
341
342 // Status
343 print '<td class="right" width="14">'.$staticaction->LibStatut($obj->percent, 3)."</td>\n";
344
345 print "</tr>\n";
346 $i++;
347 }
348 // TODO Ajouter rappel pour "il y a des contrats a mettre en service"
349 // TODO Ajouter rappel pour "il y a des contrats qui arrivent a expiration"
350 print "</table></div><br>";
351
352 $db->free($resql);
353 } else {
354 dol_print_error($db);
355 }
356}
357
358
365{
366 global $langs, $conf, $user, $db;
367
368 $extrafields = new ExtraFields($db);
369 $extrafields->fetch_name_optionals_label('actioncomm');
370
371 $h = 0;
372 $head = array();
373
374 $head[$h][0] = DOL_URL_ROOT."/admin/agenda_other.php";
375 $head[$h][1] = $langs->trans("Miscellaneous");
376 $head[$h][2] = 'other';
377 $h++;
378
379 $head[$h][0] = DOL_URL_ROOT."/admin/agenda.php";
380 $head[$h][1] = $langs->trans("AutoActions");
381 $head[$h][2] = 'autoactions';
382 $h++;
383
384 $head[$h][0] = DOL_URL_ROOT."/admin/agenda_reminder.php";
385 $head[$h][1] = $langs->trans("Reminders");
386 $head[$h][2] = 'reminders';
387 $h++;
388
389 $head[$h][0] = DOL_URL_ROOT."/admin/agenda_xcal.php";
390 $head[$h][1] = $langs->trans("ExportCal");
391 $head[$h][2] = 'xcal';
392 $h++;
393
394 $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extsites.php";
395 $head[$h][1] = $langs->trans("ExtSites");
396 $head[$h][2] = 'extsites';
397 $h++;
398
399 complete_head_from_modules($conf, $langs, null, $head, $h, 'agenda_admin');
400
401 $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extrafields.php";
402 $head[$h][1] = $langs->trans("ExtraFields");
403 $nbExtrafields = $extrafields->attributes['actioncomm']['count'];
404 if ($nbExtrafields > 0) {
405 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
406 }
407 $head[$h][2] = 'attributes';
408 $h++;
409
410 complete_head_from_modules($conf, $langs, null, $head, $h, 'agenda_admin', 'remove');
411
412
413 return $head;
414}
415
422function actions_prepare_head($object)
423{
424 global $db, $langs, $conf, $user;
425
426 $h = 0;
427 $head = array();
428
429 $head[$h][0] = DOL_URL_ROOT.'/comm/action/card.php?id='.$object->id;
430 $head[$h][1] = $langs->trans("CardAction");
431 $head[$h][2] = 'card';
432 $h++;
433
434 // Tab to link resources
435 if (isModEnabled('resource')) {
436 include_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
437 $resource = new Dolresource($db);
438
439 $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=action&element_id='.$object->id;
440 $listofresourcelinked = $resource->getElementResources($object->element, $object->id);
441 $nbResources = (is_array($listofresourcelinked) ?count($listofresourcelinked) : 0);
442 $head[$h][1] = $langs->trans("Resources");
443 if ($nbResources > 0) {
444 $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbResources).'</span>' : '');
445 }
446 $head[$h][2] = 'resources';
447 $h++;
448 }
449
450 // Attached files
451 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
452 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
453 $upload_dir = $conf->agenda->dir_output."/".$object->id;
454 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
455 $nbLinks = Link::count($db, $object->element, $object->id);
456 $head[$h][0] = DOL_URL_ROOT.'/comm/action/document.php?id='.$object->id;
457 $head[$h][1] = $langs->trans("Documents");
458 if (($nbFiles + $nbLinks) > 0) {
459 $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
460 }
461 $head[$h][2] = 'documents';
462 $h++;
463
464 $head[$h][0] = DOL_URL_ROOT.'/comm/action/info.php?id='.$object->id;
465 $head[$h][1] = $langs->trans('Info');
466 $head[$h][2] = 'info';
467 $h++;
468
469 complete_head_from_modules($conf, $langs, $object, $head, $h, 'action');
470
471 complete_head_from_modules($conf, $langs, $object, $head, $h, 'action', 'remove');
472
473 return $head;
474}
475
476
484{
485 global $langs, $conf, $user;
486
487 $h = 0;
488 $head = array();
489
490 $head[$h][0] = DOL_URL_ROOT.'/comm/action/list.php?mode=show_list'.($param ? '&'.$param : '');
491 $head[$h][1] = $langs->trans("ViewList");
492 $head[$h][2] = 'cardlist';
493 $h++;
494
495 $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php?mode=show_month'.($param ? '&'.$param : '');
496 $head[$h][1] = $langs->trans("ViewCal");
497 $head[$h][2] = 'cardmonth';
498 $h++;
499
500 $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php?mode=show_week'.($param ? '&'.$param : '');
501 $head[$h][1] = $langs->trans("ViewWeek");
502 $head[$h][2] = 'cardweek';
503 $h++;
504
505 $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php?mode=show_day'.($param ? '&'.$param : '');
506 $head[$h][1] = $langs->trans("ViewDay");
507 $head[$h][2] = 'cardday';
508 $h++;
509
510 //if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
511 if (!empty($conf->global->AGENDA_SHOW_PERTYPE)) {
512 $head[$h][0] = DOL_URL_ROOT.'/comm/action/pertype.php'.($param ? '?'.$param : '');
513 $head[$h][1] = $langs->trans("ViewPerType");
514 $head[$h][2] = 'cardpertype';
515 $h++;
516 }
517
518 $newparam = $param;
519 $newparam = preg_replace('/&?search_filtert=\d+/', '', $newparam);
520 $head[$h][0] = DOL_URL_ROOT.'/comm/action/peruser.php'.($newparam ? '?'.$newparam : '');
521 $head[$h][1] = $langs->trans("ViewPerUser");
522 $head[$h][2] = 'cardperuser';
523 $h++;
524
525
526 // Show more tabs from modules
527 // Entries must be declared in modules descriptor with line
528 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
529 // $this->tabs = array('entity:-tabname); to remove a tab
530 complete_head_from_modules($conf, $langs, null, $head, $h, 'agenda');
531
532 complete_head_from_modules($conf, $langs, null, $head, $h, 'agenda', 'remove');
533
534 return $head;
535}
show_array_actions_to_do($max=5)
Show actions to do array.
show_array_last_actions_done($max=5)
Show last actions array.
print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid='', $excludetype='', $resourceid=0)
Show filter form in agenda view.
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
agenda_prepare_head()
Prepare array with list of tabs.
actions_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
Class to manage agenda events (actions)
Class to manage customers or prospects.
DAO Resource object.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to manage building of HTML components.
Class to manage forms for the module resource.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).