<?php

/*
   +----------------------------------------------------------------------+
   | File Class                                                           |
   | Author: Adam Goldberg                                                |
   +----------------------------------------------------------------------+
   | Copyright (c) 2008-2009 Adam J Goldberg                              |
   | This file is part of Lifebox.                                        |
   |                                                                      |
   | Lifebox 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.                                  |
   |                                                                      |
   | Lifebox 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 Lifebox.  If not, see <http://www.gnu.org/licenses/>.     |
   +----------------------------------------------------------------------+
   | Perform file manipulations						  |
   +----------------------------------------------------------------------+
	function installationCheck() {
   +----------------------------------------------------------------------+
*/

class File {

	/*****************************************************************
	 * Perform simple check to make sure all binaries are installed
         *****************************************************************/
	function installationCheck() {
	global $CONFIG;

		#############################################################
		#Check that the required directories have been configured
		#############################################################
		#1 - Check for media directory
		if (!file_exists($CONFIG['media_path'])) {
			$ERROR['media_path'] = 'The media path specified in your config file does not exist';
			break;
		}

		#2 -- Check for dump directory
		if (!file_exists($CONFIG['dump_dir'])) {
                        $ERROR['dump_dir'] = 'The dump directory specified in your config file does not exist';
                        break;
                }

                #3 -- Check for dump directory: thumbs
                if (!file_exists($CONFIG['lifebox_cache'])) {
                        $ERROR['lifebox_cache'] = 'The lifebox cache directory does not exist';
                        break;
                }

                #4 -- Check for dump directory
                if (!file_exists($ADODB_CACHE_DIR)) {
                        $ERROR['ADODB_CACHE_DIR'] = 'The cache directory required for adodb does not exist';
                        break;
                }

                #5 -- Check for dump directory
                if (!file_exists($CONFIG['smarty_templates_c'])) {
                        $ERROR['dump_dir'] = 'The template cache directory required for smarty does not exist';
                        break;
                }


		#############################################################
		# Check for write permissions for the dump directories
                #############################################################
		#1 -- Check for lifebox cache thumbnail directory
		if (!touch($CONFIG['lifebox_cache'].'/.lifebox_write_test')) {
			$ERROR['write_lifebox_cache'] = 'Could not write to the lifebox cache directory';
			break;
		} else {
			unlink($CONFIG['lifebox_cache'].'/.lifebox_write_test');
		}

		#2 -- Check for lifebox cache thumbnail directory
                if (!touch($CONFIG['ADODB_CACHE_DIR'].'/.lifebox_write_test')) {
                        $ERROR['write_ADODB_CACHE_DIR'] = 'Could not write to the adodb cache directory';
                        break;
                } else {
                        unlink($ADODB_CACHE_DIR.'/.lifebox_write_test');
                }

		#3 -- Check for lifebox cache thumbnail directory
                if (!touch($CONFIG['smarty_templates_c'].'/.lifebox_write_test')) {
                        $ERROR['smarty_templates_c'] = 'Could not write to the smarty template cache directory';
                        break;
                } else {
                        unlink($CONFIG['smarty_templates_c'].'/.lifebox_write_test');
                }

		#############################################################
		# Check that certain binary files exist
                #############################################################
                #1 -- Check for lifebox cache thumbnail directory

	}
}
