Location: PHPKode > projects > ACollab > install/include/common.inc.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2005  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may 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.                                               */
/*                                                                                      */
/* This program 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 may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: common.inc.php 363 2005-02-04 21:41:04Z shozubq $

if (!defined('AC_INCLUDE_PATH')) { exit; }
error_reporting(E_ALL ^ E_NOTICE);


/* atutor default configuration options */
/* used on: ustep1.php, step3.php */
$_defaults['admin_username'] = ($_POST['old_path'] ? 'admin' : '');
$_defaults['admin_password'] = '';
$_defaults['admin_email'] = '';

$_defaults['site_name'] = 'My ACollab';
$_defaults['site_url'] = '';
$_defaults['upload_dir'] = '';

require('include/classes/sqlutility.php');

function my_add_null_slashes( $string ) {
    return ( $string );
}

if (get_magic_quotes_gpc()==1) {
	$addslashes = 'my_add_null_slashes';
} else {
	$addslashes = 'addslashes';
}

    function queryFromFile($sql_file_path){
		global $db, $progress, $errors;
		
		$tables = array();

        if (!file_exists($sql_file_path)) {
            return false;
        }

        $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)));
        SqlUtility::splitSqlFile($pieces, $sql_query);

	    foreach ($pieces as $piece) {
	        $piece = trim($piece);
            // [0] contains the prefixed query
            // [4] contains unprefixed table name

			if ($_POST['tb_prefix'] || ($_POST['tb_prefix'] == '')) {
	            $prefixed_query = SqlUtility::prefixQuery($piece, $_POST['tb_prefix']);
			} else {
				$prefixed_query = $piece;
			}
	
			if ($prefixed_query != false ) {
                $table = $_POST['tb_prefix'].$prefixed_query[4];
                if($prefixed_query[1] == 'CREATE TABLE'){
                    if (mysql_query($prefixed_query[0],$db) !== false) {
						$progress[] = 'Table <b>'.$table . '</b> created successfully.';
                    } else {
						if (mysql_errno($db) == 1050) {
							$progress[] = 'Table <b>'.$table . '</b> already exists. Skipping.';
						} else {
							$errors[] = 'Table <b>' . $table . '</b> creation failed.';
							echo mysql_error($db);
						}
                    }
                }
                elseif($prefixed_query[1] == 'INSERT INTO'){
                    mysql_query($prefixed_query[0],$db);
                }elseif($prefixed_query[1] == 'ALTER TABLE'){
                    mysql_query($prefixed_query[0],$db);
                }elseif($prefixed_query[1] == 'DROP TABLE'){
                    mysql_query($prefixed_query[1] . ' ' .$table,$db);
                }
            }
		}
        return true;
    }

function print_errors( $errors ) {
	?>
	<table border="0" class="errbox" cellpadding="3" cellspacing="2" width="90%" summary="" align="center">
	<tr class="errbox">
	<td>
		<h3 class="err"><img src="images/bad.gif" align="top" alt="" class="img" /> Error</h3>
		<?php
			echo '<ul>';
			foreach ($errors as $p) {
				echo '<li>'.$p.'</li>';
			}
			echo '</ul>';
		?>
		</td>
	</tr>
	</table>	<br />
<?php
}

function print_feedback( $feedback ) {
	?>
	<table border="0" class="fbkbox" cellpadding="3" cellspacing="2" width="90%" summary="" align="center">
	<tr class="fbkbox">
	<td><h3 class="good"><img src="images/feedback.gif" align="top" alt="" class="img" /> Feedback</h3>
		<?php
			echo '<ul>';
			foreach ($feedback as $p) {
				echo '<li>'.$p.'</li>';
			}
			echo '</ul>';
		?></td>
	</tr>
	</table>
	<br />
<?php
}

function store_steps($step) {
	global $addslashes;

	foreach($_POST as $key => $value) {
		if (substr($key, 0, strlen('step')) == 'step') {
			continue;
		} else if ($key == 'step') {
			continue;
		} else if ($key == 'action') {
			continue;
		} else if ($key == 'submit') {
			continue;
		}

		$_POST['step'.$step][$key] = urlencode(stripslashes($addslashes($value)));
	}
}


function print_hidden($current_step) {
	for ($i=1; $i<$current_step; $i++) {
		if (is_array($_POST['step'.$i])) {
			foreach($_POST['step'.$i] as $key => $value) {
				echo '<input type="hidden" name="step'.$i.'['.$key.']" value="'.$value.'" />'."\n";
			}
		}
	}
}

function print_progress($step) {
	global $install_steps;
	
	echo '<h4>Installation Progress</h4><p>';

		
			$num_steps = count($install_steps);
			for ($i=0; $i<$num_steps; $i++) {
				if ($i == $step) {
					echo '<b style="margin-left: 0px; font-size: 1.2em; color: #006699;">Step '.$i.': '.$install_steps[$i]['name'].'</b>';
				} else {
					echo '<small style="margin-left: 10px; font-size: 1em; color: gray;">';
					if ($step > $i) {
						echo '<img src="../images/check.gif" height="9" width="9" alt="Step Done!" /> ';
					} else {
						echo '<img src="../images/clr.gif" height="9" width="9"> ';
					}
					echo 'Step '.$i.': '.$install_steps[$i]['name'].'</small>';
				}
				
				echo '<br />';
			}

	echo '</p>';

	echo '<h3>'.$install_steps[$step]['name'].'</h3>';
}

if (version_compare(phpversion(), '5.0') < 0) {
	function scandir($dirstr) {
		$files = array();
		$fh = opendir($dirstr);
		while (false !== ($filename = readdir($fh))) {
			array_push($files, $filename);
		}
		closedir($fh);
		return $files;
	}
}
?>
Return current item: ACollab