-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
agenda.lib.php
462 lines (380 loc) · 15.4 KB
/
agenda.lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?php
/* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/lib/agenda.lib.php
* \brief Set of function for the agenda module
*/
/**
* Show filter form in agenda view
*
* @param Object $form Form object
* @param int $canedit Can edit filter fields
* @param int $status Status
* @param int $year Year
* @param int $month Month
* @param int $day Day
* @param int $showbirthday Show birthday
* @param string $filtera Filter on create by user
* @param string $filtert Filter on assigned to user
* @param string $filterd Filter of done by user
* @param int $pid Product id
* @param int $socid Third party id
* @param array $showextcals Array with list of external calendars, or -1 to show no legend
* @param string $actioncode Preselected value of actioncode for filter on type
* @return void
*/
function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $showextcals = array(), $actioncode = '') {
global $conf, $user, $langs, $db;
// Filters
print '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER ["PHP_SELF"] . '" method="POST">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="status" value="' . $status . '">';
print '<input type="hidden" name="year" value="' . $year . '">';
print '<input type="hidden" name="month" value="' . $month . '">';
print '<input type="hidden" name="day" value="' . $day . '">';
print '<input type="hidden" name="showbirthday" value="' . $showbirthday . '">';
print '<table class="nobordernopadding" width="100%">';
print '<tr><td class="nowrap">';
print '<table class="nobordernopadding">';
if ($canedit) {
print '<tr>';
print '<td class="nowrap">';
print $langs->trans ( "ActionsAskedBy" );
print ' </td><td class="nowrap">';
print $form->select_dolusers ( $filtera, 'userasked', 1, '', ! $canedit );
print '</td>';
print '</tr>';
print '<tr>';
print '<td class="nowrap">';
print $langs->trans ( "or" ) . ' ' . $langs->trans ( "ActionsToDoBy" );
print ' </td><td class="nowrap">';
print $form->select_dolusers ( $filtert, 'usertodo', 1, '', ! $canedit );
print '</td></tr>';
print '<tr>';
print '<td class="nowrap">';
print $langs->trans ( "or" ) . ' ' . $langs->trans ( "ActionsDoneBy" );
print ' </td><td class="nowrap">';
print $form->select_dolusers ( $filterd, 'userdone', 1, '', ! $canedit );
print '</td></tr>';
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
$formactions = new FormActions ( $db );
print '<tr>';
print '<td class="nowrap">';
print $langs->trans ( "Type" );
print ' </td><td class="nowrap">';
print $formactions->select_type_actions ( $actioncode, "actioncode", '', (empty ( $conf->global->AGENDA_USE_EVENT_TYPE ) ? 1 : 0) );
print '</td></tr>';
}
if (! empty ( $conf->projet->enabled ) && $user->rights->projet->lire) {
print '<tr>';
print '<td class="nowrap">';
print $langs->trans ( "Project" ) . ' ';
print '</td><td class="nowrap">';
select_projects ( $socid ? $socid : - 1, $pid, 'projectid', 64 );
print '</td></tr>';
}
print '</table>';
print '</td>';
// Buttons
print '<td align="center" valign="middle" class="nowrap">';
print img_picto ( $langs->trans ( "ViewCal" ), 'object_calendar', 'class="hideonsmartphone"' ) . ' <input type="submit" class="button" style="min-width:120px" name="viewcal" value="' . $langs->trans ( "ViewCal" ) . '">';
print '<br>';
print img_picto ( $langs->trans ( "ViewWeek" ), 'object_calendarweek', 'class="hideonsmartphone"' ) . ' <input type="submit" class="button" style="min-width:120px" name="viewweek" value="' . $langs->trans ( "ViewWeek" ) . '">';
print '<br>';
print img_picto ( $langs->trans ( "ViewDay" ), 'object_calendarday', 'class="hideonsmartphone"' ) . ' <input type="submit" class="button" style="min-width:120px" name="viewday" value="' . $langs->trans ( "ViewDay" ) . '">';
print '<br>';
print img_picto ( $langs->trans ( "ViewList" ), 'object_list', 'class="hideonsmartphone"' ) . ' <input type="submit" class="button" style="min-width:120px" name="viewlist" value="' . $langs->trans ( "ViewList" ) . '">';
print '</td>';
// Legend
if ($conf->use_javascript_ajax && is_array ( $showextcals )) {
print '<td align="center" valign="middle" class="nowrap">';
print '<script type="text/javascript">' . "\n";
print 'jQuery(document).ready(function () {' . "\n";
print 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });' . "\n";
print 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n";
print 'jQuery(".family_birthday").toggle();' . "\n";
print '});' . "\n";
print '</script>' . "\n";
print '<table>';
if (! empty ( $conf->global->MAIN_JS_SWITCH_AGENDA )) {
if (count ( $showextcals ) > 0) {
print '<tr><td><input type="checkbox" id="check_mytasks" name="check_mytasks" checked="true" disabled="disabled"> ' . $langs->trans ( "LocalAgenda" ) . '</td></tr>';
foreach ( $showextcals as $val ) {
$htmlname = dol_string_nospecial ( $val ['name'] );
print '<script type="text/javascript">' . "\n";
print 'jQuery(document).ready(function () {' . "\n";
print 'jQuery("#check_' . $htmlname . '").click(function() { jQuery(".family_' . $htmlname . '").toggle(); });' . "\n";
print '});' . "\n";
print '</script>' . "\n";
print '<tr><td><input type="checkbox" id="check_' . $htmlname . '" name="check_' . $htmlname . '" checked="true"> ' . $val ['name'] . '</td></tr>';
}
}
}
print '<tr><td><input type="checkbox" id="check_birthday" name="check_birthday checked="false"> ' . $langs->trans ( "AgendaShowBirthdayEvents" ) . '</td></tr>';
print '</table>';
print '</td>';
}
print '</tr>';
print '</table>';
print '</form>';
}
/**
* Show actions to do array
*
* @param int $max Max nb of records
* @return void
*/
function show_array_actions_to_do($max=5)
{
global $langs, $conf, $user, $db, $bc, $socid;
$now=dol_now();
include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
$sql = "SELECT a.id, a.label, a.datep as dp, a.datep2 as dp2, a.fk_user_author, a.percent,";
$sql.= " c.code, c.libelle,";
$sql.= " s.nom as sname, s.rowid, s.client";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN ";
$sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE a.entity = ".$conf->entity;
$sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
$sql.= " ORDER BY a.datep DESC, a.id DESC";
$sql.= $db->plimit($max, 0);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastActionsToDo",$max).'</td>';
print '<td colspan="2" align="right"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?status=todo">'.$langs->trans("FullList").'</a>';
print '</tr>';
$var = true;
$i = 0;
$staticaction=new ActionComm($db);
$customerstatic=new Client($db);
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
$staticaction->type_code=$obj->code;
$staticaction->libelle=$obj->label;
$staticaction->id=$obj->id;
print '<td>'.$staticaction->getNomUrl(1,34).'</td>';
// print '<td>'.dol_trunc($obj->label,22).'</td>';
print '<td>';
if ($obj->rowid > 0)
{
$customerstatic->id=$obj->rowid;
$customerstatic->name=$obj->sname;
$customerstatic->client=$obj->client;
print $customerstatic->getNomUrl(1,'',16);
}
print '</td>';
$datep=$db->jdate($obj->dp);
$datep2=$db->jdate($obj->dp2);
// Date
print '<td width="100" align="right">'.dol_print_date($datep,'day').' ';
$late=0;
if ($obj->percent == 0 && $datep && $datep < time()) $late=1;
if ($obj->percent == 0 && ! $datep && $datep2 && $datep2 < time()) $late=1;
if ($obj->percent > 0 && $obj->percent < 100 && $datep2 && $datep2 < time()) $late=1;
if ($obj->percent > 0 && $obj->percent < 100 && ! $datep2 && $datep && $datep < time()) $late=1;
if ($late) print img_warning($langs->trans("Late"));
print "</td>";
// Statut
print "<td align=\"right\" width=\"14\">".$staticaction->LibStatut($obj->percent,3)."</td>\n";
print "</tr>\n";
$i++;
}
print "</table><br>";
$db->free($resql);
}
else
{
dol_print_error($db);
}
}
/**
* Show last actions array
*
* @param int $max Max nb of records
* @return void
*/
function show_array_last_actions_done($max=5)
{
global $langs, $conf, $user, $db, $bc, $socid;
$now=dol_now();
$sql = "SELECT a.id, a.percent, a.datep as da, a.datep2 as da2, a.fk_user_author, a.label,";
$sql.= " c.code, c.libelle,";
$sql.= " s.rowid, s.nom as sname, s.client";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN ";
$sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action ";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE a.entity = ".$conf->entity;
$sql.= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
$sql .= " ORDER BY a.datep2 DESC";
$sql .= $db->plimit($max, 0);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastDoneTasks",$max).'</td>';
print '<td colspan="2" align="right"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?status=done">'.$langs->trans("FullList").'</a>';
print '</tr>';
$var = true;
$i = 0;
$staticaction=new ActionComm($db);
$customerstatic=new Societe($db);
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
$staticaction->type_code=$obj->code;
$staticaction->libelle=$obj->label;
$staticaction->id=$obj->id;
print '<td>'.$staticaction->getNomUrl(1,34).'</td>';
//print '<td>'.dol_trunc($obj->label,24).'</td>';
print '<td>';
if ($obj->rowid > 0)
{
$customerstatic->id=$obj->rowid;
$customerstatic->name=$obj->sname;
$customerstatic->client=$obj->client;
print $customerstatic->getNomUrl(1,'',24);
}
print '</td>';
// Date
print '<td width="100" align="right">'.dol_print_date($db->jdate($obj->da2),'day');
print "</td>";
// Statut
print "<td align=\"right\" width=\"14\">".$staticaction->LibStatut($obj->percent,3)."</td>\n";
print "</tr>\n";
$i++;
}
// TODO Ajouter rappel pour "il y a des contrats a mettre en service"
// TODO Ajouter rappel pour "il y a des contrats qui arrivent a expiration"
print "</table><br>";
$db->free($resql);
}
else
{
dol_print_error($db);
}
}
/**
* Prepare array with list of tabs
*
* @return array Array of tabs to shoc
*/
function agenda_prepare_head()
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/admin/agenda.php";
$head[$h][1] = $langs->trans("AutoActions");
$head[$h][2] = 'autoactions';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/agenda_xcal.php";
$head[$h][1] = $langs->trans("ExportCal");
$head[$h][2] = 'xcal';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/agenda_extsites.php";
$head[$h][1] = $langs->trans("ExtSites");
$head[$h][2] = 'extsites';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/agenda_other.php";
$head[$h][1] = $langs->trans("Other");
$head[$h][2] = 'other';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin');
$head[$h][0] = DOL_URL_ROOT."/admin/agenda_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'attributes';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin','remove');
return $head;
}
/**
* Prepare array with list of tabs
*
* @param Object $object Object related to tabs
* @return array Array of tabs to shoc
*/
function actions_prepare_head($object)
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/comm/action/fiche.php?id='.$object->id;
$head[$h][1] = $langs->trans("CardAction");
$head[$h][2] = 'card';
$h++;
if (! empty($conf->global->AGENDA_USE_SEVERAL_CONTACTS))
{
$head[$h][0] = DOL_URL_ROOT.'/comm/action/contact.php?id='.$object->id;
$head[$h][1] = $langs->trans("Contacts");
$head[$h][2] = 'contact';
$h++;
}
$head[$h][0] = DOL_URL_ROOT.'/comm/action/document.php?id='.$object->id;
$head[$h][1] = $langs->trans('Documents');
$head[$h][2] = 'documents';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/comm/action/info.php?id='.$object->id;
$head[$h][1] = $langs->trans('Info');
$head[$h][2] = 'info';
$h++;
return $head;
}
/**
* Define head array for tabs of agenda setup pages
*
* @param string $param Parameters to add to url
* @return array Array of head
*/
function calendars_prepare_head($param)
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php'.($param?'?'.$param:'');
$head[$h][1] = $langs->trans("Agenda");
$head[$h][2] = 'card';
$h++;
$object=new stdClass();
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda');
complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda','remove');
return $head;
}
?>