<?php
/*
 *
 * sflog!
 * Copyright (C) 2005 Alberto Sfolcini <a.sfolcini@gmail.com>
 *
 * This file is a part of sflog!.
 *
 * sflog! 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 2
 * of the License, or (at your option) any later version.
 *
 * sflog! 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

define ('APPEND',0);
define ('REWRITE',1);

/**
 * @title		: WriteFile       
 * @description	: Manages read/write operations 
 * @date		: 12-Oct-2005   
 * @author		: Alberto Sfolcini  <a.sfolcini@gmail.com>
 */
 class WriteFile { 
 	
 	var $fileName = "";
 	var $fp;
 	 
 	/**
 	 * Constructor 1
 	 * @param string $fileName
 	 * @param string $action 0=>append, 1=>rewrite
 	 */
 	function WriteFile($fileName,$action){
 		$this->fileName = $fileName;
 		switch ("$action"){
 			case APPEND; {
 					$this->fp = fopen($this->fileName, 'a+'); //The file is opened and the cursor is placed at the end of the file, if the file doesn't exists it will be created.' 
 					break;						
 			}
 			case REWRITE; {
 					$this->fp = fopen($this->fileName, 'w'); //The file is opened and the cursor is placed at the beginning of the file, if the file doesn't exists it will be created, any data in the file will be erased.'
 					break;
 			}
 		} 		
 	}
 

 	/**
 	 * 
 	 * @param string $data
 	 * @return	0 if sucessfull
 	 * 		  	-1 if fails	
 	 */
 	function writeStr($data=""){
 		 				
		fwrite($this->fp, $data."\n");
		
		 	}
 		 
 	/**
 	 * Close file
 	 */
	function closeFile(){
		fclose($this->fp);
		} 		 
 		 
} // end class
?>
