Location: PHPKode > projects > Php simple acces data mysql > phpsimpledb_v2/includes/framework/projets/projets.php
<?php
	class DBprojets{
		var $_sPath_projects = '';
		var $_oFilteredPath = array( '.', '..', '.svn' );
		var $sChaineConnexion = '';
		var $sUser = '';
		var $sPass = '';
		
		function DBprojets(){
			$this->_sPath_projects = PATH_BASE.'projects'.DIRECTORY_SEPARATOR;
		}
		
		//recherche la liste de tous les projets
		function getAllProjectList(){
			$oAllProjects = array();
			$oForder = opendir( $this->_sPath_projects );
			while( $oDir = readdir( $oForder ) )
				if( !in_array( $oDir, $this->_oFilteredPath ) && is_dir( $this->_sPath_projects.DIRECTORY_SEPARATOR.$oDir ) )
					$oAllProjects[] = $this->getData( $oDir );
			return $oAllProjects;
		}
		
		//recupere les informations d'un projet
		function getData( $sName ){
			$oProjet = (object)NULL;
			$oProjet->name = $sName;
			
			//lecture du fichier xml du projet
			$sFile = $this->_sPath_projects.$sName.DIRECTORY_SEPARATOR.'data.xml';
			if( !file_exists( $sFile ) ){
				return NULL;
			}
			$oXml = new SimpleXMLElement( file_get_contents( $sFile ) );
			
			if( $oXml )
				foreach( $oXml->children() as $sName=>$oData ){
					eval( "\$oProjet->$sName = '".addslashes( $oData )."';" );
				}

			return $oProjet;
		}
		
		//recupere toutes les tables de la bdd
		function getAllTables(){
			$oBD = new PDO( $this->sChaineConnexion, $this->sUser, $this->sPass );
			$oTables = array();
			foreach ($oBD->query( 'SHOW TABLES' ) as $oRow )
				$oTables[] = $oRow[ 0 ];
			return $oTables;
		}
		
		function convCDATAtoString( $sChaine ) {
			$sTag_cdata = "<![CDATA[";
			$sTag_cdata_fin = "]]>";
			$iPos_cdata = stripos( $sChaine, $sTag_cdata ) + strlen( $sTag_cdata );
			$iPos_cdata_fin = stripos( $sChaine, $sTag_cdata_fin, $iPos_cdata );
			return substr( $sChaine, $iPos_cdata, $iPos_cdata_fin - $iPos_cdata );
		}
		
		//generation du xml d'un projet en fonction d'un tableau
		function generatXmlByArray( $oPost ){
			$sDate = date( 'j/m/y' );
			$sTag = $this->createTagFromName( $oPost[ 'name' ] );
			$sXML = '<?xml version="1.0" encoding="utf-8"?>
<datas>
	<tag><![CDATA['.$sTag.']]></tag>
	<name><![CDATA['.addslashes( $oPost[ 'name' ] ).']]></name>
	<datec><![CDATA['.$sDate.']]></datec>
	<datem><![CDATA['.$sDate.']]></datem>
	<desc><![CDATA['.addslashes( $oPost[ 'desc' ] ).']]></desc>
	<bddServer><![CDATA['.addslashes( $oPost[ 'bddServer' ] ).']]></bddServer>
	<bddBdd><![CDATA['.addslashes( $oPost[ 'bddBdd' ] ).']]></bddBdd>
	<bddUser><![CDATA['.addslashes( $oPost[ 'bddUser' ] ).']]></bddUser>
	<bddPass><![CDATA['.addslashes( $oPost[ 'bddPass' ] ).']]></bddPass>
	<outputPath><![CDATA['.$this->formatPath( $oPost[ 'outputPath' ] ).']]></outputPath>
</datas>';
			return array( $sXML, $sTag );
		}
		
		//enregistre un xml de projet
		function saveXmlByProject( $sName, $sXml ){
			file_put_contents( PATH_BASE.'projects'.DIRECTORY_SEPARATOR.$sName.DIRECTORY_SEPARATOR.'data.xml', $sXml );
		}
		
		//enregistre un nouveau projet
		function newProject( $sName, $sXml ){
			
			//creation de fichier, recuscivite sur creation de repertoire
			$sFile = PATH_BASE.'projects'.DIRECTORY_SEPARATOR.$sName.DIRECTORY_SEPARATOR.'data.xml';
			
			//separe le nom du fichier du nom du dossier
			$sFileName = basename( $sFile );
			$sPath = substr( $sFile, 0, strlen( $sFile ) - strlen( $sFileName ) );
			
			//cree le repertoire si il n'existe pas
			if( !file_exists( $sPath ) || !is_dir( $sPath ) )
				mkdir( $sPath, 0655, true );
			
			//supprime le fichier si il existe
			if( file_exists( $sFile ) ){
				unlink( $sFile );
			}
			//fopen( $sFile, 'w' );
			
			
			//enregistre un xml de projet
			$this->saveXmlByProject( $sName, $sXml );
		}
		
		//supprime un projet
		function delProject( $sName ){
			$sPath = PATH_BASE.'projects'.DIRECTORY_SEPARATOR.$sName;
			$oDir = opendir( $sPath );
			while ($sFile = readdir( $oDir ) ){
				if( is_file( $sPath.DIRECTORY_SEPARATOR.$sFile ) ){
					unlink( $sPath.DIRECTORY_SEPARATOR.$sFile );
				}
			}
			closedir( $oDir );
			rmdir( $sPath );
		}
		
		//methode de formatage d'un chemin de sortie
		function formatPath( $sPath ){
			$sPath = str_replace( DIRECTORY_SEPARATOR, '/', $sPath );
			$sPath = rtrim( $sPath, '/' ).'/';
			return $sPath;
		}
		
		//creation d'un tag en fonction d'un nom
		function createTagFromName( $sName ){
			
			$sName = trim( strtolower( $sName ) );
			$sName = str_replace( 'é', 'e', $sName );
			$sName = str_replace( 'è', 'e', $sName );
			$sName = str_replace( 'ê', 'e', $sName );
			$sName = str_replace( 'à', 'a', $sName );
			$sName = str_replace( 'ç', 'c', $sName );
			
			$oAlphab = array( 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' );
			
			for( $i = 0; $i < strlen( $sName ); $i++ ){
				$sChar = substr( $sName, $i, 1 );
				if( !in_array( $sChar, $oAlphab ) ){
					$sName = str_replace( $sChar, '_', $sName );
				}
			}
			
			return $sName;
		}
	}
?>
Return current item: Php simple acces data mysql