Completed
Branch develop (00c8ea)
by
unknown
39:19
created

modAgenda   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 387
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 387
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 377 12
1
<?php
2
/* Copyright (C) 2003,2005 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2003      Jean-Louis Bergamo   <[email protected]>
4
 * Copyright (C) 2004-2014 Laurent Destailleur  <[email protected]>
5
 * Copyright (C) 2004      Sebastien Di Cintio  <[email protected]>
6
 * Copyright (C) 2004      Benoit Mortier       <[email protected]>
7
 * Copyright (C) 2009-2011 Regis Houssin        <[email protected]>
8
 * Copyright (C) 2013      Cedric Gross         <[email protected]>
9
 * Copyright (C) 2015      Bahfir Abbes         <[email protected]>
10
 * Copyright (C) 2017      Juanjo Menent        <[email protected]>
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 */
25
26
/**
27
 *		\defgroup   agenda     Module agenda
28
 *      \brief      Module to manage agenda and events
29
 *      \file       htdocs/core/modules/modAgenda.class.php
30
 *      \ingroup    agenda
31
 *      \brief      File of class to describe and enable/disable module Agenda
32
 */
33
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
34
35
/**
36
 *	Class to describe and enable/disable module Agenda
37
 */
38
class modAgenda extends DolibarrModules
39
{
40
41
	/**
42
	 *   Constructor. Define names, constants, directories, boxes, permissions
43
	 *
44
	 *   @param      DoliDB		$db      Database handler
45
	 */
46
	function __construct($db)
47
	{
48
		global $conf, $user;
49
50
		$this->db = $db;
51
		$this->numero = 2400;
52
53
		$this->family = "projects";
54
		$this->module_position = 15;
55
		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
56
		$this->name = preg_replace('/^mod/i','',get_class($this));
57
		$this->description = "Follow events or rendez-vous. Record manual events into Agendas or let application record automatic events for log tracking.";
58
		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59
		$this->version = 'dolibarr';
60
		// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
61
		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62
		$this->picto='action';
63
64
		// Data directories to create when module is enabled
65
		$this->dirs = array("/agenda/temp");
66
67
		// Config pages
68
		//-------------
69
		$this->config_page_url = array("agenda_other.php");
70
71
		// Dependancies
72
		//-------------
73
		$this->depends = array();
74
		$this->requiredby = array();
75
		$this->langfiles = array("companies");
76
77
		// Module parts
78
        $this->module_parts = array();
79
80
		// Constants
81
        //-----------
82
        // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
83
        // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
84
        //                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
85
        // );
86
		$this->const = array();
87
		//$this->const[] = array('AGENDA_DEFAULT_FILTER_TYPE', 'chaine', 'AC_NON_AUTO', 'Default filter for type of event on agenda', 0, 'current');
88
		$sqlreadactions="SELECT code, label, description FROM ".MAIN_DB_PREFIX."c_action_trigger ORDER by rang";
89
		$resql = $this->db->query($sqlreadactions);
90
		if ($resql)
91
		{
92
		    while ($obj = $this->db->fetch_object($sqlreadactions))
93
		    {
94
		        //if (preg_match('/_CREATE$/',$obj->code) && (! in_array($obj->code, array('COMPANY_CREATE','PRODUCT_CREATE','TASK_CREATE')))) continue;    // We don't track such events (*_CREATE) by default, we prefer validation (except thirdparty/product/task creation because there is no validation).
95
		        if (preg_match('/^TASK_/',$obj->code)) continue;      // We don't track such events by default.
96
		        //if (preg_match('/^_MODIFY/',$obj->code)) continue;    // We don't track such events by default.
97
		        $this->const[] = array('MAIN_AGENDA_ACTIONAUTO_'.$obj->code, "chaine", "1", '', 0, 'current');
98
		    }
99
		}
100
		else
101
		{
102
		    dol_print_error($this->db->lasterror());
103
		}
104
105
		// New pages on tabs
106
		// -----------------
107
		$this->tabs = array();
108
109
		// Boxes
110
		//------
111
		$this->boxes = array(0=>array('file'=>'box_actions.php','enabledbydefaulton'=>'Home'));
112
113
		// Cronjobs
114
		//------------
115
		$this->cronjobs = array(
116
			0=>array('label'=>'SendEmailsReminders', 'jobtype'=>'method', 'class'=>'comm/action/class/actioncomm.class.php', 'objectname'=>'ActionComm', 'method'=>'sendEmailsReminder', 'parameters'=>'', 'comment'=>'SendEMailsReminder', 'frequency'=>10, 'unitfrequency'=>60, 'priority'=>10, 'status'=>1, 'test'=>'1'),
117
		    // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
118
		);
119
120
		// Permissions
121
		//------------
122
		$this->rights = array();
123
		$this->rights_class = 'agenda';
124
		$r=0;
125
126
		// $this->rights[$r][0]     Id permission (unique tous modules confondus)
127
		// $this->rights[$r][1]     Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
128
		// $this->rights[$r][2]     Non utilise
129
		// $this->rights[$r][3]     1=Permis par defaut, 0=Non permis par defaut
130
		// $this->rights[$r][4]     Niveau 1 pour nommer permission dans code
131
		// $this->rights[$r][5]     Niveau 2 pour nommer permission dans code
132
		// $r++;
133
134
		$this->rights[$r][0] = 2401;
135
		$this->rights[$r][1] = 'Read actions/tasks linked to his account';
136
		$this->rights[$r][2] = 'r';
137
		$this->rights[$r][3] = 0;
138
		$this->rights[$r][4] = 'myactions';
139
		$this->rights[$r][5] = 'read';
140
		$r++;
141
142
		$this->rights[$r][0] = 2402;
143
		$this->rights[$r][1] = 'Create/modify actions/tasks linked to his account';
144
		$this->rights[$r][2] = 'w';
145
		$this->rights[$r][3] = 0;
146
		$this->rights[$r][4] = 'myactions';
147
		$this->rights[$r][5] = 'create';
148
		$r++;
149
150
		$this->rights[$r][0] = 2403;
151
		$this->rights[$r][1] = 'Delete actions/tasks linked to his account';
152
		$this->rights[$r][2] = 'w';
153
		$this->rights[$r][3] = 0;
154
		$this->rights[$r][4] = 'myactions';
155
		$this->rights[$r][5] = 'delete';
156
		$r++;
157
158
		$this->rights[$r][0] = 2411;
159
		$this->rights[$r][1] = 'Read actions/tasks of others';
160
		$this->rights[$r][2] = 'r';
161
		$this->rights[$r][3] = 0;
162
		$this->rights[$r][4] = 'allactions';
163
		$this->rights[$r][5] = 'read';
164
		$r++;
165
166
		$this->rights[$r][0] = 2412;
167
		$this->rights[$r][1] = 'Create/modify actions/tasks of others';
168
		$this->rights[$r][2] = 'w';
169
		$this->rights[$r][3] = 0;
170
		$this->rights[$r][4] = 'allactions';
171
		$this->rights[$r][5] = 'create';
172
		$r++;
173
174
		$this->rights[$r][0] = 2413;
175
		$this->rights[$r][1] = 'Delete actions/tasks of others';
176
		$this->rights[$r][2] = 'w';
177
		$this->rights[$r][3] = 0;
178
		$this->rights[$r][4] = 'allactions';
179
		$this->rights[$r][5] = 'delete';
180
		$r++;
181
182
		$this->rights[$r][0] = 2414;
183
		$this->rights[$r][1] = 'Export actions/tasks of others';
184
		$this->rights[$r][2] = 'w';
185
		$this->rights[$r][3] = 0;
186
		$this->rights[$r][4] = 'export';
187
188
		// Main menu entries
189
		$this->menu = array();			// List of menus to add
190
		$r=0;
191
192
		// Add here entries to declare new menus
193
		// Example to declare the Top Menu entry:
194
		// $this->menu[$r]=array(	'fk_menu'=>0,			// Put 0 if this is a top menu
195
		//							'type'=>'top',			// This is a Top menu entry
196
		//							'titre'=>'MyModule top menu',
197
		//							'mainmenu'=>'mymodule',
198
		//							'url'=>'/mymodule/pagetop.php',
199
		//							'langs'=>'mylangfile',	// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
200
		//							'position'=>100,
201
		//							'enabled'=>'1',			// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
202
		//							'perms'=>'1',			// Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
203
		//							'target'=>'',
204
		//							'user'=>2);				// 0=Menu for internal users, 1=external users, 2=both
205
		// $r++;
206
		$this->menu[$r]=array('fk_menu'=>0,
207
													'type'=>'top',
208
													'titre'=>'TMenuAgenda',
209
													'mainmenu'=>'agenda',
210
													'url'=>'/comm/action/index.php',
211
													'langs'=>'agenda',
212
													'position'=>15,
213
													'perms'=>'$user->rights->agenda->myactions->read',
214
													'enabled'=>'$conf->agenda->enabled',
215
													'target'=>'',
216
													'user'=>2);
217
		$r++;
218
219
		$this->menu[$r]=array('fk_menu'=>'r=0',
220
													'type'=>'left',
221
													'titre'=>'Actions',
222
													'mainmenu'=>'agenda',
223
													'url'=>'/comm/action/index.php?mainmenu=agenda&amp;leftmenu=agenda',
224
													'langs'=>'agenda',
225
													'position'=>100,
226
													'perms'=>'$user->rights->agenda->myactions->read',
227
													'enabled'=>'$conf->agenda->enabled',
228
													'target'=>'',
229
													'user'=>2);
230
		$r++;
231
		$this->menu[$r]=array('fk_menu'=>'r=1',
232
													'type'=>'left',
233
													'titre'=>'NewAction',
234
													'mainmenu'=>'agenda',
235
													'url'=>'/comm/action/card.php?mainmenu=agenda&amp;leftmenu=agenda&amp;action=create',
236
													'langs'=>'commercial',
237
													'position'=>101,
238
													'perms'=>'($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create)',
239
													'enabled'=>'$conf->agenda->enabled',
240
													'target'=>'',
241
													'user'=>2);
242
		$r++;
243
		// Calendar
244
		$this->menu[$r]=array('fk_menu'=>'r=1',
245
													'type'=>'left',
246
													'titre'=>'Agenda',
247
													'mainmenu'=>'agenda',
248
													'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda',
249
													'langs'=>'agenda',
250
													'position'=>140,
251
													'perms'=>'$user->rights->agenda->myactions->read',
252
													'enabled'=>'$conf->agenda->enabled',
253
													'target'=>'',
254
													'user'=>2);
255
		$r++;
256
		$this->menu[$r]=array('fk_menu'=>'r=3',
257
													'type'=>'left',
258
													'titre'=>'MenuToDoMyActions',
259
													'mainmenu'=>'agenda',
260
													'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
261
													'langs'=>'agenda',
262
													'position'=>141,
263
													'perms'=>'$user->rights->agenda->myactions->read',
264
													'enabled'=>'$conf->agenda->enabled',
265
													'target'=>'',
266
													'user'=>2);
267
		$r++;
268
		$this->menu[$r]=array('fk_menu'=>'r=3',
269
													'type'=>'left',
270
													'titre'=>'MenuDoneMyActions',
271
													'mainmenu'=>'agenda',
272
													'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
273
													'langs'=>'agenda',
274
													'position'=>142,
275
													'perms'=>'$user->rights->agenda->myactions->read',
276
													'enabled'=>'$conf->agenda->enabled',
277
													'target'=>'',
278
													'user'=>2);
279
		$r++;
280
		$this->menu[$r]=array('fk_menu'=>'r=3',
281
													'type'=>'left',
282
													'titre'=>'MenuToDoActions',
283
													'mainmenu'=>'agenda',
284
													'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
285
													'langs'=>'agenda',
286
													'position'=>143,
287
													'perms'=>'$user->rights->agenda->allactions->read',
288
													'enabled'=>'$user->rights->agenda->allactions->read',
289
													'target'=>'',
290
													'user'=>2);
291
		$r++;
292
		$this->menu[$r]=array('fk_menu'=>'r=3',
293
													'type'=>'left',
294
													'titre'=>'MenuDoneActions',
295
													'mainmenu'=>'agenda',
296
													'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
297
													'langs'=>'agenda',
298
													'position'=>144,
299
													'perms'=>'$user->rights->agenda->allactions->read',
300
													'enabled'=>'$user->rights->agenda->allactions->read',
301
													'target'=>'',
302
													'user'=>2);
303
304
		// List
305
		$r++;
306
		$this->menu[$r]=array('fk_menu'=>'r=1',
307
													'type'=>'left',
308
													'titre'=>'List',
309
													'mainmenu'=>'agenda',
310
													'url'=>'/comm/action/list.php?mainmenu=agenda&amp;leftmenu=agenda',
311
													'langs'=>'agenda',
312
													'position'=>110,
313
													'perms'=>'$user->rights->agenda->myactions->read',
314
													'enabled'=>'$conf->agenda->enabled',
315
													'target'=>'',
316
													'user'=>2);
317
		$r++;
318
		$this->menu[$r]=array('fk_menu'=>'r=8',
319
													'type'=>'left',
320
													'titre'=>'MenuToDoMyActions',
321
													'mainmenu'=>'agenda',
322
													'url'=>'/comm/action/list.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filter=mine',
323
													'langs'=>'agenda',
324
													'position'=>111,
325
													'perms'=>'$user->rights->agenda->myactions->read',
326
													'enabled'=>'$conf->agenda->enabled',
327
													'target'=>'',
328
													'user'=>2);
329
		$r++;
330
		$this->menu[$r]=array('fk_menu'=>'r=8',
331
													'type'=>'left',
332
													'titre'=>'MenuDoneMyActions',
333
													'mainmenu'=>'agenda',
334
													'url'=>'/comm/action/list.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filter=mine',
335
													'langs'=>'agenda',
336
													'position'=>112,
337
													'perms'=>'$user->rights->agenda->myactions->read',
338
													'enabled'=>'$conf->agenda->enabled',
339
													'target'=>'',
340
													'user'=>2);
341
		$r++;
342
		$this->menu[$r]=array('fk_menu'=>'r=8',
343
													'type'=>'left',
344
													'titre'=>'MenuToDoActions',
345
													'mainmenu'=>'agenda',
346
													'url'=>'/comm/action/list.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=todo&amp;filtert=-1',
347
													'langs'=>'agenda',
348
													'position'=>113,
349
													'perms'=>'$user->rights->agenda->allactions->read',
350
													'enabled'=>'$user->rights->agenda->allactions->read',
351
													'target'=>'',
352
													'user'=>2);
353
		$r++;
354
		$this->menu[$r]=array('fk_menu'=>'r=8',
355
													'type'=>'left',
356
													'titre'=>'MenuDoneActions',
357
													'mainmenu'=>'agenda',
358
													'url'=>'/comm/action/list.php?mainmenu=agenda&amp;leftmenu=agenda&amp;status=done&amp;filtert=-1',
359
													'langs'=>'agenda',
360
													'position'=>114,
361
													'perms'=>'$user->rights->agenda->allactions->read',
362
													'enabled'=>'$user->rights->agenda->allactions->read',
363
													'target'=>'',
364
													'user'=>2);
365
		$r++;
366
		// Reports
367
		$this->menu[$r]=array('fk_menu'=>'r=1',
368
													'type'=>'left',
369
													'titre'=>'Reportings',
370
													'mainmenu'=>'agenda',
371
													'url'=>'/comm/action/rapport/index.php?mainmenu=agenda&amp;leftmenu=agenda',
372
													'langs'=>'agenda',
373
													'position'=>160,
374
													'perms'=>'$user->rights->agenda->allactions->read',
375
													'enabled'=>'$conf->agenda->enabled',
376
													'target'=>'',
377
													'user'=>2);
378
		$r++;
379
380
381
		// Exports
382
		//--------
383
		$r=0;
384
385
		$r++;
386
		$this->export_code[$r]=$this->rights_class.'_'.$r;
387
		$this->export_label[$r]="ExportDataset_event1";
388
		$this->export_permission[$r]=array(array("agenda","export"));
389
		$this->export_fields_array[$r]=array('ac.id'=>"IdAgenda",'ac.ref_ext'=>"ExternalRef",'ac.datec'=>"DateCreation",'ac.datep'=>"DateActionBegin",
390
			'ac.datep2'=>"DateActionEnd",'ac.label'=>"Title",'ac.note'=>"Note",'ac.percent'=>"Percent",'ac.durationp'=>"Duration",
391
			'cac.libelle'=>"ActionType",
392
			's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town',
393
			'co.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6',
394
			's.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra');
395
		$this->export_TypeFields_array[$r]=array('ac.ref_ext'=>"Text",'ac.datec'=>"Date",'ac.datep'=>"Date",
396
			'ac.datep2'=>"Date",'ac.label'=>"Text",'ac.note'=>"Text",'ac.percent'=>"Numeric",
397
			'ac.durationp'=>"Duree",
398
			'cac.libelle'=>"List:c_actioncomm:libelle:id",
399
			's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text',
400
			'co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.idprof5'=>'Text','s.idprof6'=>'Text',
401
			's.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text');
402
		$this->export_entities_array[$r]=array('ac.id'=>"action",'ac.ref_ext'=>"action",'ac.datec'=>"action",'ac.datep'=>"action",
403
			'ac.datep2'=>"action",'ac.label'=>"action",'ac.note'=>"action",'ac.percent'=>"action",'ac.durationp'=>"action",
404
			'cac.libelle'=>"action",
405
			's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company',
406
			'co.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company',
407
			's.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',);
408
409
		$this->export_sql_start[$r]='SELECT DISTINCT ';
410
		$this->export_sql_end[$r]  =' FROM  '.MAIN_DB_PREFIX.'actioncomm as ac';
411
		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id';
412
		if (! empty($user) && empty($user->rights->agenda->allactions->read)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm';
413
		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid';
414
		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid';
415
		if (! empty($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
416
		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid';
417
		$this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda').')';
418
		if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.(empty($user)?0:$user->id).' OR ac.fk_soc IS NULL)';
419
		if (empty($user->rights->agenda->allactions->read)) $this->export_sql_end[$r] .=' AND acr.fk_element = '.(empty($user)?0:$user->id);
420
		$this->export_sql_end[$r] .=' ORDER BY ac.datep';
421
422
	}
423
424
}
425