<?php
/*
Officity - Web application platform - Version 6.0 - 2011-07-05

François Dispaux, Boris Verdeyen, Thomas Hermant,
Jérémie Roy, Grégory Meurice, Abdelila Harbi, 
Marc Mignonsin, Jonathan Sanchez, Julien Gonzalez, Pierre Fouchez

Sushee and Officity is © Copyright 2011 Nectil SA.

`/sushee-source/sushee/private/tasks.php` is part of Officity.

Sushee 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.

Officity and Sushee are distributed in the hope that they 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 Sushee. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(dirname(__FILE__)."/../common/common_functions.inc.php");
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// put here all the files you want to have started on a regular basis
set_time_limit(0);
//
$db_conn = db_connect();
debug_log('Kernel/private/tasks.php : Scheduled tasks start ');
$rs = $db_conn->Execute('select * from dependencytypes');
if(!$rs){
	debug_log("/Kernel/private/tasks.php : No connection to DB");
	die("Kernel/private/tasks.php: No connection to DB");
}

include_once(dirname(__FILE__)."/../private/warn_before_expiration.php");
echo 'warn_before_expiration OK<br/>';

if( file_exists($GLOBALS["Public_dir"]."tasks.php") )
	include_once($GLOBALS["Public_dir"]."tasks.php");

include_once(dirname(__FILE__)."/../private/clean_tmpfiles.php");
echo 'clean_tmpfiles OK<br/>';

debug_log('Kernel/private/tasks.php : Scheduled tasks executed ');
echo 'Scheduled tasks executed';
if ( isNectilMaster($GLOBALS["nectil_url"]) && $GLOBALS["generic_backoffice"]){
	debug_log('Calling the scheduled tasks for the residents');
	$sql = 'SELECT `ID`,`DbName`,`MailingMinInterval`,`MailingCurInterval`,`LastSendingDate`,`URL` FROM `residents` WHERE (`Activity`=1 AND `IsTemplate`!=1 AND (`ExpirationDate`="0000-00-00" OR `ExpirationDate` > "'.$GLOBALS["sushee_today"].'" OR `ExpirationDate`="0000-01-01"))';
	$rs = $db_conn->Execute($sql);
	echo '*'.$sql.'*';
	if($rs){
		while($row = $rs->FetchRow()){
			$url = $row['URL'].'/'.Sushee_dirname.'/private/tasks.php';
			debug_log('calling '.$url);
			$fp = @fopen($url,'r');
			if($fp){
				while (!feof ($fp)) {
					$buffer = fgets($fp, 64);
					//echo $buffer;
				  }
				  fclose ($fp);
			}
		}	
	}
}
if($GLOBALS["PopServer"])
	include_once(dirname(__FILE__)."/../private/check_mailings.php");
?>
