<?php
/**
 * This file is to manage deleted unused flv capture files
 *
 * This file is having ManageDeleted class to manage deleted files
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		Admin
 * @author 		selvaraj_35ag05
 * @copyright 	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2008-12-26
 *
 **/
require_once('../common/configs/config.inc.php');
require_once('../common/configs/config_encoder.inc.php');
$CFG['mods']['include_files'][] = 'common/classes/class_FormHandler.lib.php';
$CFG['mods']['is_include_only']['non_html_header_files'] = true;
/**
 * To include application top file
 */
require_once($CFG['site']['project_path'].'common/application_top.inc.php');
//---------------------------- Class ConfigEdit begins -------------------->>>>>//
/**
 * ManageDeleted
 *
 * @package
 * @author selvaraj_35ag05
 * @copyright Copyright (c) 2009
 * @version $Id: $
 * @access public
 **/

set_time_limit(0);
class ManageDeleted extends FormHandler
	{
		/**
		 * ManageDeleted::removeFiles()
		 *
		 * @param $file
		 * @return
		 **/
		public function removeFiles($file)
			{
				if(is_file($file))
					{
						echo $file;
						unlink($file);
						return true;
					}
				return false;
			}
		public 	function getTimeDiffernce($date1)
			{
				//current date.
				$date2 = date("Y-m-d H:i:s", time());
				//calculate the difference in seconds.
				$difference = abs(strtotime($date2) - strtotime($date1));
				//calculate the number of hours
				$days = round(((($difference/60)/60)), 0);
				return $days;
			}
		public function deleteNotUsedFiles()
			{
				$dir = $this->CFG['admin']['video']['red5_flv_path'];
				if(!is_dir($dir))
					{
						echo $this->LANG['directory_not_exist'];
						return;
					}
				if ($handle = opendir($dir))
					{
					    while (false !== ($file = readdir($handle)))
							{
						        if ($file != "." && $file != "..")
									{
							          //echo $file;
									 $stat = stat($dir.$file);
									 $date1 = date("F d Y H:i:s.",$stat['mtime']);
								     $diff =  $this->getTimeDiffernce( $date1);
									 if($diff >= $this->CFG['admin']['hours'])
											{
												$this->removeFiles($dir.$file);
											}


							        }
						    }
					    closedir($handle);
					}
			}
	}
//<<<<<-------------- Class ManageDeleted begins ---------------//
//-------------------- Code begins -------------->>>>>//
$ManageDeleted = new ManageDeleted();
$ManageDeleted->deleteNotUsedFiles();
?>