Issues (1940)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

programs/events.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
//-------------------------------------------------------------------------
3
// OVIDENTIA http://www.ovidentia.org
4
// Ovidentia is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2, or (at your option)
7
// any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
// See the GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17
// USA.
18
//-------------------------------------------------------------------------
19
/**
20
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
21
 * @copyright Copyright (c) 2006 by CANTICO ({@link http://www.cantico.fr})
22
 */
23
24
include_once dirname(__FILE__).'/functions.php';
25
26
27
function absences_onUserDeleted(bab_eventUserDeleted $event) {
28
29
	require_once dirname(__FILE__).'/utilit/agent.class.php';
30
	
31
	$agent = absences_Agent::getFromIdUser($event->id_user);
32
	$agent->delete();
33
}
34
35
36
/**
37
 * before sitemap creation
38
 * registered on this event to add more nodes to core sitemap
39
 *
40
 * @param	bab_eventBeforeSiteMapCreated 	$event
41
 */
42
function absences_onBeforeSiteMapCreated(bab_eventBeforeSiteMapCreated $event) {
43
44
	
45
	require_once dirname(__FILE__).'/utilit/agent.class.php';
46
	
47
	$addon = bab_getAddonInfosInstance('absences');
48
	bab_functionality::includeOriginal('Icons');
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class bab_functionality as the method includeOriginal() does only exist in the following sub-classes of bab_functionality: Func_Archive, Func_Archive_Zip, Func_Archive_Zip_ZipArchive, Func_Archive_Zip_Zlib, Func_CalendarBackend, Func_CalendarBackend_Ovi, Func_ContextActions, Func_ContextActions_Article, Func_ContextActions_ArticleTopic, Func_Home, Func_Home_Ovidentia, Func_Icons, Func_Icons_Default, Func_Ovml, Func_Ovml_Container, Func_Ovml_Container_Addon, Func_Ovml_Container_Article, Func_Ovml_Container_ArticleCategories, Func_Ovml_Container_ArticleCategory, Func_Ovml_Container_ArticleCategoryNext, Func_Ovml_Container_ArticleCategoryPrevious, Func_Ovml_Container_ArticleFiles, Func_Ovml_Container_ArticleNext, Func_Ovml_Container_ArticlePrevious, Func_Ovml_Container_ArticleTopic, Func_Ovml_Container_ArticleTopicNext, Func_Ovml_Container_ArticleTopicPrevious, Func_Ovml_Container_ArticleTopics, Func_Ovml_Container_Articles, Func_Ovml_Container_ArticlesHomePages, Func_Ovml_Container_CalendarCategories, Func_Ovml_Container_CalendarEventDomains, Func_Ovml_Container_CalendarEvents, Func_Ovml_Container_CalendarGroupEvents, Func_Ovml_Container_CalendarResourceEvents, Func_Ovml_Container_CalendarUserEvents, Func_Ovml_Container_Calendars, Func_Ovml_Container_DbDirectories, Func_Ovml_Container_DbDirectory, Func_Ovml_Container_DbDirectoryAcl, Func_Ovml_Container_DbDirectoryEntry, Func_Ovml_Container_DbDirectoryEntryFields, Func_Ovml_Container_DbDirectoryFields, Func_Ovml_Container_DbDirectoryMemberFields, Func_Ovml_Container_DbDirectoryMembers, Func_Ovml_Container_Delegation, Func_Ovml_Container_DelegationAdministrators, Func_Ovml_Container_DelegationItems, Func_Ovml_Container_DelegationManaged, Func_Ovml_Container_Delegations, Func_Ovml_Container_DelegationsCategories, Func_Ovml_Container_DelegationsCategory, Func_Ovml_Container_DelegationsManaged, Func_Ovml_Container_Faq, Func_Ovml_Container_FaqNext, Func_Ovml_Container_FaqPrevious, Func_Ovml_Container_FaqQuestion, Func_Ovml_Container_FaqQuestionNext, Func_Ovml_Container_FaqQuestionPrevious, Func_Ovml_Container_FaqQuestions, Func_Ovml_Container_FaqSubCategories, Func_Ovml_Container_FaqSubCategory, Func_Ovml_Container_Faqs, Func_Ovml_Container_File, Func_Ovml_Container_FileFields, Func_Ovml_Container_FileNext, Func_Ovml_Container_FilePrevious, Func_Ovml_Container_Files, Func_Ovml_Container_Folder, Func_Ovml_Container_FolderNext, Func_Ovml_Container_FolderPrevious, Func_Ovml_Container_Folders, Func_Ovml_Container_Forum, Func_Ovml_Container_ForumNext, Func_Ovml_Container_ForumPrevious, Func_Ovml_Container_Forums, Func_Ovml_Container_IfEqual, Func_Ovml_Container_IfGreaterThan, Func_Ovml_Container_IfGreaterThanOrEqual, Func_Ovml_Container_IfIsSet, Func_Ovml_Container_IfLessThan, Func_Ovml_Container_IfLessThanOrEqual, Func_Ovml_Container_IfNotEqual, Func_Ovml_Container_IfNotIsSet, Func_Ovml_Container_IfUserMemberOfGroups, Func_Ovml_Container_Multipages, Func_Ovml_Container_ObjectsInfo, Func_Ovml_Container_OrgPathToEntity, Func_Ovml_Container_OrgUserEntities, Func_Ovml_Container_OvmlArray, Func_Ovml_Container_OvmlArrayFields, Func_Ovml_Container_OvmlSoap, Func_Ovml_Container_ParentsArticleCategory, Func_Ovml_Container_Post, Func_Ovml_Container_PostFiles, Func_Ovml_Container_RecentArticles, Func_Ovml_Container_RecentComments, Func_Ovml_Container_RecentFaqQuestions, Func_Ovml_Container_RecentFiles, Func_Ovml_Container_RecentPosts, Func_Ovml_Container_RecentThreads, Func_Ovml_Container_SitemapCustomNode, Func_Ovml_Container_SitemapEntries, Func_Ovml_Container_SitemapEntry, Func_Ovml_Container_SitemapPath, Func_Ovml_Container_Soap, Func_Ovml_Container_SubFolders, Func_Ovml_Container_Tags, Func_Ovml_Container_Thread, Func_Ovml_Container_TmProjects, Func_Ovml_Container_TmSpaces, Func_Ovml_Container_TmTaskFields, Func_Ovml_Container_TmTasks, Func_Ovml_Container_WaitingArticles, Func_Ovml_Container_WaitingComments, Func_Ovml_Container_WaitingFiles, Func_Ovml_Container_WaitingPosts, Func_Ovml_Function, Func_Ovml_Function_AOAddition, Func_Ovml_Function_AODivision, Func_Ovml_Function_AOModulus, Func_Ovml_Function_AOMultiplication, Func_Ovml_Function_AOSubtraction, Func_Ovml_Function_AddStyleSheet, Func_Ovml_Function_Addon, Func_Ovml_Function_Ajax, Func_Ovml_Function_ArticleTree, Func_Ovml_Function_CurrentNode, Func_Ovml_Function_FileTree, Func_Ovml_Function_Get, Func_Ovml_Function_GetCookie, Func_Ovml_Function_GetCsrfProtectToken, Func_Ovml_Function_GetCurrentAdmGroup, Func_Ovml_Function_GetLanguage, Func_Ovml_Function_GetPageTitle, Func_Ovml_Function_GetPath, Func_Ovml_Function_GetSelectedSkinPath, Func_Ovml_Function_GetSessionVar, Func_Ovml_Function_GetVar, Func_Ovml_Function_Header, Func_Ovml_Function_IfNotIsSet, Func_Ovml_Function_Include, Func_Ovml_Function_NextArticle, Func_Ovml_Function_Post, Func_Ovml_Function_PreviousArticle, Func_Ovml_Function_PreviousOrNextArticle, Func_Ovml_Function_PutArray, Func_Ovml_Function_PutSoapArray, Func_Ovml_Function_PutVar, Func_Ovml_Function_Recurse, Func_Ovml_Function_Request, Func_Ovml_Function_SetCookie, Func_Ovml_Function_SetSessionVar, Func_Ovml_Function_SitemapCustomNodeId, Func_Ovml_Function_SitemapMenu, Func_Ovml_Function_SitemapPosition, Func_Ovml_Function_SitemapUrl, Func_Ovml_Function_Translate, Func_Ovml_Function_UrlContent, Func_Ovml_Function_WebStat, Func_PortalAuthentication, Func_PortalAuthentication_AuthOvidentia, Func_PwdComplexity, Func_PwdComplexity_DefaultPortal, Func_SearchUi, Func_SitemapDynamicNode, Func_SitemapDynamicNode_Topic, Func_UserEditor, Func_WorkingHours, Func_WorkingHours_Ovidentia, Ovml_Container_Sitemap, bab_ArithmeticOperator, bab_Ovml_Container_Operator, bab_rgp. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
49
	
50
	if (bab_isUserLogged())
51
	{
52
		$agent = absences_Agent::getCurrentUser();
53
	}
54
55
	// add node to access sitemap editor
56
57
	$delegations = bab_getUserSitemapDelegations();
58
59
60
	foreach( $delegations as $key => $deleg ) {
61
		
62
		if (bab_isUserAdministrator())
63
		{
64
65
			$position = array('root', $key, 'babAdmin', 'babAdminSection');
66
	
67
			$item = $event->createItem('absencesAdmin');
68
	
69
			$item->setLabel(absences_translate('Vacations'));
70
			$item->setDescription(absences_translate('Vacations management'));
71
			$item->setLink($addon->getUrl().'admvacs');
72
			$item->addIconClassname(Func_Icons::APPS_VACATIONS);
73
			$item->setPosition($position);
74
	
75
			$event->addFunction($item);
76
		
77
		}
78
79
80
		if (isset($agent) && ($agent->isInPersonnel() || $agent->isManager() || $agent->isEntityManager()))
81
		{
82
		
83
			$position = array('root', $key, 'babUser', 'babUserSection');
84
	
85
			$item = $event->createItem('absencesUser');
86
	
87
			$item->setLabel(absences_translate('Vacations'));
88
			$item->setDescription(absences_translate('Vacations management'));
89
			$item->setLink($addon->getUrl().'vacuser');
90
			$item->addIconClassname(Func_Icons::APPS_VACATIONS);
91
			$item->setPosition($position);
92
	
93
			$event->addFunction($item);
94
95
		}
96
	}
97
}
98
99
100
101
function absences_onUserModified(bab_eventUserModified $event)
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
{
103
	
104
}
105
106
107
108
109
function absences_onBeforeWaitingItemsDisplayed(bab_eventBeforeWaitingItemsDisplayed $event)
110
{
111
112
	include_once $GLOBALS['babInstallPath']."utilit/wfincl.php";
113
	include_once dirname(__FILE__)."/utilit/vacincl.php";
114
	
115
	global $babDB;
116
	
117
	$inst = bab_getWaitingIdSAInstance(bab_getUserId());
118
	
119
	if (!$inst)
0 ignored issues
show
Bug Best Practice introduced by
The expression $inst of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
120
	{
121
		return;
122
	}
123
	
124
	
125
	absences_listWaitingEntries($event, $inst);
126
	absences_listWaitingWorkperiod($event, $inst);
127
	absences_listWaitingDeposit($event, $inst);
128
}
129
130
131
132
133
134
function absences_onConfirmMultipleWaitingItems(bab_eventConfirmMultipleWaitingItems $event)
135
{
136
	require_once dirname(__FILE__).'/utilit/entry.class.php';
137
	require_once dirname(__FILE__).'/utilit/workperiod_recover_request.class.php';
138
	require_once dirname(__FILE__).'/utilit/cet_deposit_request.class.php';
139
	require_once dirname(__FILE__).'/utilit/request.notify.php';
140
	require_once dirname(__FILE__).'/utilit/vacincl.php';
141
	
142
	$entries = $event->getItems('absences_listWaitingEntries');
143
	foreach($entries as $id_entry)
144
	{
145
		$entry = absences_Entry::getById($id_entry);
146
		$entry->approbationNext(true, '');
147
		$entry->applyDynamicRight();
148
		$entry->notifyOwner();
149
	}
150
	
151
	$workperiods = $event->getItems('absences_listWaitingWorkperiod');
152
	foreach($workperiods as $id_workperiod)
153
	{
154
		$workperiod = absences_WorkperiodRecoverRequest::getById($id_workperiod);
155
		$workperiod->approbationNext(true, '');	
156
		$workperiod->notifyOwner();
157
	}
158
	
159
	$deposits = $event->getItems('absences_listWaitingDeposit');
160
	foreach($deposits as $id_deposit)
161
	{
162
		$deposit = absences_CetDepositRequest::getById($id_deposit);
163
		$deposit->approbationNext(true, '');
164
		$deposit->notifyOwner();
165
	}
166
	
167
	
168
	$defer = (bool) absences_getVacationOption('approb_email_defer');
169
	if (!$defer)
170
	{
171
		
172
		absences_notifyRequestApprovers();
173
	}
174
}
175
176
177
178
179
180
function absences_listWaitingEntries(bab_eventBeforeWaitingItemsDisplayed $event, Array $inst)
181
{
182
	global $babDB;
183
	$res = $babDB->db_query("select e.*, GROUP_CONCAT(DISTINCT t.name ORDER BY t.name ASC SEPARATOR ', ') types from ".ABSENCES_ENTRIES_TBL." e 
184
				LEFT JOIN absences_entries_elem ee ON ee.id_entry=e.id 
185
				LEFT JOIN absences_rights r ON r.id=ee.id_right 
186
				LEFT JOIN absences_types t ON t.id=r.id_type 
187
	            
188
			where idfai IN (".$babDB->quote($inst).") GROUP BY e.id ORDER BY date_begin ASC");
189
	
190
	if (0 === $babDB->db_num_rows($res))
191
	{
192
		return;
193
	}
194
	
195
	if ($event instanceof bab_eventWaitingItemsCount)
196
	{
197
		$event->addItemCount(absences_translate("Vacations requests waiting to be validated"), $babDB->db_num_rows($res));
198
		return;
199
	} 
200
	
201
	$arr = array();
202
203
	while ($row = $babDB->db_fetch_assoc($res))
204
	{
205
		$quantity = absences_vacEntryQuantity($row['id']);
206
		$period = absences_DateTimePeriod($row['date_begin'], $row['date_end']);
207
		$description = bab_toHtml(sprintf("%s (%s)\n%s", $quantity, $row['types'], $period), BAB_HTML_ALL ^ BAB_HTML_P);
208
		
209 View Code Duplication
		if ($row['firstconfirm']) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
210
		    $description .= '<br /><img src="'.$GLOBALS['babInstallPath'].'skins/ovidentia/images/Puces/edit.png" align="absmiddle" /> 
211
		    <span style="color:red">'.bab_toHtml(absences_translate('Modification of an allready confirmed request')).'</span>';
212
		}
213
		
214 View Code Duplication
		if ($row['todelete']) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
215
		    $description .= '<br /><img src="'.$GLOBALS['babInstallPath'].'skins/ovidentia/images/Puces/del.gif" align="absmiddle" /> 
216
		    <span style="color:red">'.bab_toHtml(absences_translate('Deletion request')).'</span>';
217
		}
218
		
219
		if (!empty($row['comment']))
220
		{
221
			$description .='<br /><br />';
222
			$description .=sprintf('%s : <em>%s</em>', bab_toHtml(absences_translate('Applicant comment')), bab_toHtml($row['comment']));
223
		}
224
225
		$l = array(
226
				'text' 			=> bab_getUserName($row['id_user']),
227
				'description' 	=> $description,
228
				'url'			=> absences_addon()->getUrl()."approb&idx=confvac&idvac=".$row['id'],
229
				'popup'			=> 1,
230
				'idschi'		=> $row['idfai'],
231
				'id'			=> $row['id']
232
		);
233
234
235
		$arr[] = $l;
236
	}
237
238
239
	if ($arr) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $arr of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
240
		$event->addObject(absences_translate("Vacations requests waiting to be validated"), $arr, __FUNCTION__);
241
	}
242
	
243
}
244
245
246
247
248
function absences_listWaitingWorkperiod(bab_eventBeforeWaitingItemsDisplayed $event, Array $inst)
249
{
250
	global $babDB;
251
	
252
	$res = $babDB->db_query("select r.*, t.name type from
253
			absences_workperiod_recover_request r
254
			LEFT JOIN absences_workperiod_type t ON t.id=r.id_type
255
			where r.idfai IN (".$babDB->quote($inst).") order by r.date_begin asc");
256
	
257
	if (0 === $babDB->db_num_rows($res))
258
	{
259
		return;
260
	}
261
	
262
	
263
	if ($event instanceof bab_eventWaitingItemsCount)
264
	{
265
		$event->addItemCount(absences_translate("Worked days entitling recovery waiting to be validated"), $babDB->db_num_rows($res));
266
		return;
267
	} 
268
	
269
	$arr = array();
270
271
	while ($row = $babDB->db_fetch_assoc($res))
272
	{
273
274
275
		$l = array(
276
				'text' 			=> bab_getUserName($row['id_user']),
277
				'description' 	=> sprintf(absences_translate('%s from %s to %s'), $row['type'], absences_shortDate(bab_mktime($row['date_begin'])), absences_shortDate(bab_mktime($row['date_end']))),
278
				'url'			=> absences_addon()->getUrl()."approb&idx=recover&id_workperiod=".$row['id'],
279
				'popup'			=> 1,
280
				'idschi'		=> $row['idfai'],
281
				'id'			=> $row['id']
282
		);
283
284
285
		$arr[] = $l;
286
	}
287
288
289
	if ($arr) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $arr of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
290
		$event->addObject(absences_translate("Worked days entitling recovery waiting to be validated"),$arr, __FUNCTION__);
291
	}
292
	
293
	
294
}
295
296
297
298
299
function absences_listWaitingDeposit(bab_eventBeforeWaitingItemsDisplayed $event, Array $inst)
300
{
301
	global $babDB;
302
	
303
	
304
	$res = $babDB->db_query("
305
		SELECT cet.*, r.quantity_unit, r.description
306
		FROM
307
			absences_cet_deposit_request cet
308
			LEFT JOIN absences_users_rights ur ON ur.id=cet.id_agent_right_source
309
			LEFT JOIN absences_rights r ON r.id=ur.id_right
310
		WHERE
311
			cet.idfai IN (".$babDB->quote($inst).") order by cet.createdOn asc");
312
	
313
	if (0 === $babDB->db_num_rows($res))
314
	{
315
		return;
316
	}
317
	
318
	if ($event instanceof bab_eventWaitingItemsCount)
319
	{
320
		$event->addItemCount(absences_translate("Deposits in the time saving account waiting to be validated"), $babDB->db_num_rows($res));
321
		return;
322
	} 
323
	
324
	$arr = array();
325
326
	while ($row = $babDB->db_fetch_assoc($res))
327
	{
328
		$description = isset($row['description']) ? $row['description'] : absences_translate('unknown');
329
		$quantity_unit = isset($row['quantity_unit']) ? $row['quantity_unit'] : absences_translate('unknown');
330
331
		$l = array(
332
				'text' 			=> bab_getUserName($row['id_user']),
333
				'description' 	=> sprintf(absences_translate('Move %s from %s'), absences_quantity($row['quantity'], $quantity_unit), $description),
334
				'url'			=> absences_addon()->getUrl()."approb&idx=cet&id_deposit=".$row['id'],
335
				'popup'			=> 1,
336
				'idschi'		=> $row['idfai'],
337
				'id'			=> $row['id']
338
		);
339
340
341
		$arr[] = $l;
342
	}
343
344
345
	if ($arr) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $arr of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
346
		$event->addObject(absences_translate("Deposits in the time saving account waiting to be validated"),$arr, __FUNCTION__);
347
	}
348
	
349
}
350
351
352
353
/**
354
 * Refresh calendar if modified
355
 * @param	bab_eventPeriodModified	$event
356
 */
357
function absences_onModifyPeriod($event) {
358
	global $babDB;
359
360
	$vacation 	= (BAB_PERIOD_VACATION 	=== ($event->types & BAB_PERIOD_VACATION));
361
	$nwday		= (BAB_PERIOD_NWDAY 	=== ($event->types & BAB_PERIOD_NWDAY));
362
	$working	= (BAB_PERIOD_WORKING	=== ($event->types & BAB_PERIOD_WORKING));
363
364
	if (!$vacation && !$nwday && !$working) {
365
		return;
366
	}
367
368
	if (false === $event->id_user) {
369
		$babDB->db_query("TRUNCATE absences_calendar");
370
		return;
371
	}
372
373
	require_once dirname(__FILE__).'/utilit/vacincl.php';
374
	absences_clearUserCalendar($event->id_user);
375
	return;
376
377
	// le code si dessous existait pour optimiser le cache mais dans de rares cas cela ne fonctionne pas
378
	// la modification d'une periode peut entrainer des changement de couleurs sur une autre periode qui n'a pas
379
	// ete modifiee
380
381
	/*
382
	 if (false === $event->begin || false === $event->end) {
383
	absences_clearUserCalendar($event->id_user);
384
	return;
385
	}
386
387
388
	include_once $GLOBALS['babInstallPath']."utilit/dateTime.php";
389
390
	$date_begin = BAB_DateTime::fromTimeStamp($event->begin);
391
	$date_end	= BAB_DateTime::fromTimeStamp($event->end);
392
	$date_end->add(1, BAB_DATETIME_MONTH);
393
394
	while ($date_begin->getTimeStamp() <= $date_end->getTimeStamp()) {
395
	$month	= $date_begin->getMonth();
396
	$year	= $date_begin->getYear();
397
	absences_updateCalendar($event->id_user, $year, $month);
398
	$date_begin->add(1, BAB_DATETIME_MONTH);
399
	}
400
401
	*/
402
}
403
404
405
406
407
408
function absences_onBeforePeriodsCreated(bab_eventBeforePeriodsCreated $event)
409
{
410
	$userperiods = $event->periods;
411
	/*@var $userperiods bab_UserPeriods */
412
	
413
	$users = $userperiods->getUsers();
414
	
415
	if ($userperiods->isPeriodCollection('bab_VacationPeriodCollection') && $users) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $users of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
416
		require_once dirname(__FILE__)."/utilit/vacincl.php";
417
		absences_setVacationPeriods($userperiods, $users);
418
	}
419
}
420
421
422
423
424
function absences_onHourly(LibTimer_eventHourly $event)
425
{
426
	require_once dirname(__FILE__).'/utilit/vacincl.php';
427
	require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
428
	require_once dirname(__FILE__).'/utilit/right.class.php';
429
	require_once dirname(__FILE__).'/utilit/request.class.php';
430
	global $babDB;
431
	
432
	$defer = (bool) absences_getVacationOption('approb_email_defer');
433
	
434
	// daily notification after 12:00
435
	
436
	if ($defer)
437
	{
438
		if (12 <= (int) date('G'))
439
		{
440
			$registry = bab_getRegistryInstance();
441
			$registry->changeDirectory('/absences/');
442
443
			// get last saved call
444
			$lastcall = $registry->getValue('approb_email_defer');
445
			
446
			if (null === $lastcall || ((time() - bab_mktime($lastcall)) / 3600) > 12  )
447
			{
448
				// pas de dernier appel ou dernier appel il y a plus de 12 heures
449
				
450
				$registry->setKeyValue('approb_email_defer', date('Y-m-d H:i:s'));
451
				
452
				require_once dirname(__FILE__).'/utilit/request.notify.php';
453
				absences_notifyRequestApprovers();
454
			}
455
		}
456
	}
457
	
458
	
459
	// droit avec ajout de solde en debut de mois tant que la date de fin n'est pas connue
460
461
	$I = new absences_RightIterator();
462
	$I->kind = absences_Right::INCREMENT;
463
	$I->increment = true;
464
	
465
	foreach($I as $right)
466
	{
467
		/*@var $right absences_Right */
468
		
469
		if ($right->getKind() !== absences_Right::INCREMENT)
470
		{
471
			throw new Exception('Error in iterator, wrong right kind');
472
		}
473
474
		$right->monthlyQuantityUpdate($event);
475
	}
476
	
477
	
478
	// auto approbation
479
	
480
	$auto_confirm = (int) absences_getVacationOption('auto_confirm');
481
	if (0 !== $auto_confirm)
482
	{
483
		$date = BAB_DateTime::now();
484
		$date->less($auto_confirm, BAB_DATETIME_DAY);
485
		
486
		$I = new absences_RequestIterator;
487
		$I->status = '';
488
		$I->modifiedOn = $date->getIsoDateTime();
489
		
490
		foreach($I as $request)
491
		{
492
		    /*@var $request absences_Request */
493
			$request->autoConfirm();
494
		}
495
	}	
496
	
497
	
498
	// synchro
499
	
500
	$I = new absences_RightIterator();
501
	$I->sync_status = absences_Right::SYNC_CLIENT;
502
	
503
	if (0 < $I->count())
504
	{
505
		require_once dirname(__FILE__).'/utilit/client.class.php';
506
		$client = new absences_client;
507
		foreach($I as $right)
508
		{
509
			$client->updateRight($right->uuid);
510
		}
511
	}
512
}
513
514
515
516
function absences_onAfterEventCategoryDeleted(bab_eventAfterEventCategoryDeleted $event)
517
{
518
	global $babDB;
519
	$babDB->db_query("update absences_collections SET id_cat='0' WHERE id_cat=".$babDB->quote($event->id_category));
520
}
521
522
523
524
function absences_onOrgChartEntityAfterDeleted(bab_eventOrgChartEntityAfterDeleted $event)
525
{
526
	global $babDB;
527
	$babDB->db_query("DELETE from absences_planning where id_entity=".$babDB->quote($event->id_entity));
528
}
529
530
531
532
533
/**
534
 * Directory entry modification/creation/delete
535
 * 
536
 * @param bab_eventDirectory $event
537
 */
538
function absences_onDirectory(bab_eventDirectory $event)
539
{
540
    if (!($event instanceof bab_eventUserCreated || $event instanceof bab_eventUserModified)) {
541
        return;
542
    }
543
    
544
    require_once dirname(__FILE__).'/utilit/vacincl.php';
545
    
546
    if (0 === (int) absences_getVacationOption('organization_sync')) {
547
        return;
548
    }
549
    
550
    
551
    $id_user = (int) $event->id_user;
552
    
553
    
554
    require_once dirname(__FILE__).'/utilit/agent.class.php';
555
    
556
    // set the associated organization
557
    $agent = absences_Agent::getFromIdUser($id_user);
558
    
559
    if (!$agent->exists()) {
560
        return;
561
    }
562
    
563
    require_once dirname(__FILE__).'/utilit/organization.class.php';
564
    
565
    // update the organization list
566
    absences_Organization::createFromDirectory();
567
    
568
    try {
569
        $agent->setOrganizationFromDirEntry();
570
    } catch (Exception $e) {
571
        // ignore error, organization is not set in dir entry
572
    }
573
    
574
}
575