Location: PHPKode > projects > O - OpenSource GroupWare > osgw/config/upgrade_data.php
<?php
/**************************************************************************
   This program 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.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: upgrade_data.php,v 1.3 2003/12/10 04:53:28 rthomp Exp $*/
$service['no_session'] = TRUE;
require('../config.inc.php');

$db->query("SELECT location FROM o_services");
while($db->fetch_results())
{
	$locations[] = $db->record['location'];	
}

$locations[] = 'osgw';

foreach($locations AS $location)
{

	$dir = "{$O->dir}/$location/config/data";
	if(is_dir($dir))
	{
		$handle = opendir($dir);
  		while (false !== ($file = readdir($handle))) 
  		{
  		
  			
  			if(is_file("$dir/$file") && $file != 'o_users.php' && $file != 'o_languages.php')
  			{
  			
  				$table = explode('.', $file);
  				$table = $table[0];
				include("$dir/$file");
				
				unset($flag);
				foreach($data AS $key => $value)
				{
					foreach($value AS $field =>$data)
					{
						$sql = "SELECT * FROM $table WHERE $field='$data'";
						//echo "<Br />";
						$db->query($sql);
						if($db->num_rows == 0)
						{
							$flag = TRUE;
							break;
						}
					}
					
					if($flag)
					{
						unset($fields);
						unset($insert);
						foreach($value AS $field => $data)
						{
							
							$fields .=  "$field,";
							$insert .= "'$data',";
						}	
						$fields = substr($fields, 0, strlen($fields) - 1);
						$insert = substr($insert, 0, strlen($insert) - 1);
						$sql = "INSERT INTO $table ($fields) VALUES ($insert)";
						$db->query($sql);
						
					}
				}
				
  			}
		}
	}
		
			
}

//To save on code we're using this to install and upgrade plugins from administrator

if(isset($_GET['pl']))
{
	$O->redirect('/admin');
} else {
	$O->redirect('/config/upgrade_config.php');
}
Return current item: O - OpenSource GroupWare