<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<meta http-equiv="Content-Language" content="nl">
<TITLE>Site@School migration tool</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<STYLE>A:link {
	BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #638ab9; TEXT-DECORATION: none
}
A:active {
	BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #638ab9; TEXT-DECORATION: none
}
A:visited {
	BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #638ab9; TEXT-DECORATION: none
}
A:hover {
	BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #ff0000; TEXT-DECORATION: none
}
TEXTAREA {
	COLOR: #000000; FONT-FAMILY: verdana, arial; BACKGROUND-COLOR: #ccdaec
}
Input.BUTTON {
	border:1px outset #ccdaec; BACKGROUND-COLOR: #ccdaec
}
SELECT {
	BORDER-RIGHT: #ccdaec 1px inset; BORDER-TOP: #ccdaec 1px inset; BORDER-LEFT: #ccdaec 1px inset; COLOR: #000000; BORDER-BOTTOM: #ccdaec 1px inset; FONT-FAMILY: verdana, arial; BACKGROUND-COLOR: #ccdaec
}
.text {
	FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial
}
.link {
	FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #638ab9; FONT-FAMILY: Verdana, Arial
}
.heading {
	FONT-WEIGHT: bold; FONT-SIZE: 13pt; COLOR: #638ab9; FONT-FAMILY: Verdana, Arial
}


INPUT.textfield {
	BORDER-RIGHT: #ccdaec 1px inset; BORDER-TOP: #ccdaec 1px inset; BORDER-LEFT: #ccdaec 1px inset; BORDER-BOTTOM: #ccdaec 1px inset; BACKGROUND-COLOR: #ccdaec
}
</STYLE>


</HEAD>
<BODY style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial, Helvetica" bottomMargin=0 vLink=#000000 aLink=#466c9b link=#000000 bgColor=#ffffff leftMargin=0 topMargin=0 rightMargin=0>


<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 height=45
cellSpacing=0 cellPadding=0 width="100%"
background=../graphics/banner-bg.gif border=0>
  <TBODY>
  <TR>
    <TD align=left width="5%"><IMG height=45
      src="../graphics/banner-left.gif" width=4 border=0></TD>
    <TD align=right width="70%">
    <b><font size="6" color="#FFFFFF">Migration of 2.3 to 2.4.03</font></b></TD>
    <TD align=right width="3%"><IMG height=45
      src="../graphics/banner-right.gif" width=3
border=0></TD></TR></TBODY></TABLE>
<TABLE id=AutoNumber3 style="BORDER-COLLAPSE: collapse" borderColor=#111111
cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD vAlign=top>
      <TABLE cellPadding=5 width="100%" border=0>
        <TBODY>
        <TR>
          <TD>
<?php
if($_GET[step] == "")
{
?>
          <form method="POST" action="migrate2.3_2.4.php?step=1">
            <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111
            cellSpacing=0 cellPadding=4 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=left width="65%">
                <SPAN class=heading>Welcome<BR></SPAN></TD>
                <TD vAlign=top align=middle width="10%">&nbsp;</TD>
              </TR>
              <TR>
                <TD align=center width="25%">
                <img border="0" src="../graphics/install_banner.jpg"></TD>
                <TD vAlign=top align=middle width="65%">
                <table border="1" height="300" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#E5E5E5" width="100%" id="AutoNumber4" bgcolor="#F7F7F7">
                  <tr>
                    <td width="100%" valign="top"><span class=text>
                    <br><br><br>This wizard will perform the migration of version 2.3 to 2.4.03 .<br><br>
                     Before you continue , please make sure you have made a <b>backup</b> of your MYSQL database.<br>
                     This can be done with <a href="http://phpmyadmin.sourceforge.net/">PHPMYADMIN</a> or via backup tool from S@S.
                    </span></td>
                  </tr>
                </table>
                </TD>
                <TD vAlign=top align=middle width="10%"></TD></TR>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=right width="65%">

                 <p>
                  <input type="submit" value="Continue" name="B1" class="BUTTON">
                  </p>
                </form>
<?php
}
if($_GET[step] == "1")
{
$installdir = $_SERVER["DOCUMENT_ROOT"]."/starnet";
$installdir = str_replace("//","/",$installdir);
?>


          <form method="POST" action="migrate2.3_2.4.php?step=2">

            <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111
            cellSpacing=0 cellPadding=4 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=left width="65%">
                <SPAN class=heading>Step 1<BR></SPAN><span class="text">Database migration.</span></TD>
                <TD vAlign=top align=middle width="10%">&nbsp;</TD>
              </TR>
              <TR>
                <TD align=center width="25%">
                <img border="0" src="../graphics/install_banner.jpg"></TD>
                <TD vAlign=top align=middle width="65%">
                <table border="1" height="300" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#E5E5E5" width="100%" id="AutoNumber4" bgcolor="#F7F7F7">
                  <tr>
                    <td width="100%" valign="top"><span class=text>
                   <br><br>Changes will be made to the tables during the next step..<br>Click on continue.</td>
                  </tr>
                </table>
                </TD>
                <TD vAlign=top align=middle width="10%"></TD></TR>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=right width="65%">


                 <p>
                  <input type="submit" value="Continue" name="B1" class="BUTTON">
                </form>
<?php
}
if($_GET[step] == "2")
{
?>
            <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111
            cellSpacing=0 cellPadding=4 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=left width="65%">
                <SPAN class=heading>Step 2<BR></SPAN></TD>
                <TD vAlign=top align=middle width="10%">&nbsp;</TD>
              </TR>
              <TR>
                <TD align=center width="25%">
                <img border="0" src="../graphics/install_banner.jpg"></TD>
                <TD vAlign=top align=middle width="65%">
                <table border="1" height="300" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#E5E5E5" width="100%" id="AutoNumber4" bgcolor="#F7F7F7">
                  <tr>
                  <td width="100%" valign="top"><span class=text>

<?php
echo "Start 2.4.03 migration .....<br><br>"   ;
include("../configuration/database.inc.php");       
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");

unset($sas_config) ;                                                         //clear the config array first
$query = "SELECT config_key,config_value FROM $table_configuration WHERE config_key NOT LIKE 'agenda_t%'";    
//read all the configuration items except agenda options.

$result = mysql_query($query) or die(mysql_error());
while ($config_list = mysql_fetch_array($result)) 
{ 
$sas_config[$config_list[0]] = $config_list[1] ;                             //put them in the config array
}
//get the sas version
$sas_version = $sas_config['sas_version'].$sas_config['sas_patch_version'] ;

if(isset($sas_version))
{
print "<b>Current Site@School version: " .$sas_version."</b><p>" ;
}

switch ($sas_version)                                                         // start of switch
{
	case "2.400":			//level is ok , quit here
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.401":			//level is ok , quit here
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.402":			//level is ok , quit here
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.403":			//level is ok , quit here
	print "Your Site@School version is already up to the right level!.<br>";
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.400f":			//level is ok , quit here
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.400e":			//level is ok , quit here
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.400d":			//level is ok , just alter the patch version
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 0 ;
	break;
	
	case "2.400c":			//only do step3
	//set new patch version
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	$step1 = 0 ;
	$step2 = 0 ;
	$step3 = 1 ;
	break;                                                                     
	
	case "2.400b":			//only do download module (step2)
	$step1 = 0 ;
	$step2 = 1 ;
	$step3 = 1 ;
	//set new patch version
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	break; 
	
	case "2.400a":			//only do download module (step2)	
	$step1 = 0 ;
	$step2 = 1 ;
	$step3 = 1 ;
	//set new patch version
	mysql_query("UPDATE $table_configuration SET config_value = '03' WHERE config_key = 'sas_patch_version'");
	break; 
	
	default:				//sas  version 2.3 I assume.	
	$step1 = 1 ;
	$step2 = 1 ;
	$step3 = 1 ;
	mysql_query("INSERT INTO $table_configuration VALUES ('sas_version', '2.4', 'Sas main version')");
	mysql_query("INSERT INTO $table_configuration VALUES ('sas_patch_version', '03', 'Sas patch version')");
	break; 
 
}

if($step1 == 1)
{
	//configuration table, search module fix
	mysql_query("UPDATE $table_configuration SET config_value = 'studentid,title,content' WHERE config_key = 'search_module_returnfield3' ");
	
	//users table
	mysql_query("ALTER TABLE $table_users MODIFY class varchar(80)");
	mysql_query("ALTER TABLE $table_users MODIFY project varchar(80)");
	mysql_query("ALTER TABLE $table_users ADD initial tinyint(1) default 0") ;
	
	// pupilpages module
	mysql_query("ALTER TABLE $table_studentpages ADD sort tinyint(4) not null default 0");
	mysql_query("ALTER TABLE $table_studentpages ADD invisible tinyint(1) not null default 0");
	print "Pupilpages table has been altered.<p>";
	
	
	//downloads
	$table_downloads = $dbprefix ."m_downloads";
	mysql_query("ALTER TABLE $table_downloads ADD counter tinyint(11) default 0");
	print "Downloads table has been altered.<p>";
	
	//newsletter
	$table_newsletters = $dbprefix ."m_newsletter_cat";
	mysql_query("ALTER TABLE $table_newsletters MODIFY title text");
	mysql_query("ALTER TABLE $table_newsletters ADD template text default null");
	print "Newsletter table has been altered.<p>";
	
	//stats
	$table_stats = $dbprefix."stats" ;
	//check if the public field already exists
	$result = mysql_query("SHOW COLUMNS FROM $table_stats LIKE 'public'");
		if (!$result) 
		{
		   echo 'Could not run query: ' . mysql_error();
		}
		
		if (mysql_num_rows($result) == 0) 
		{
		 mysql_query("ALTER TABLE $table_stats ADD public tinyint(4)");
		 mysql_query("UPDATE TABLE $table_stats SET public=0 WHERE id > 0");  
		 print "Table alterations for the stats has been done!<p>";
		}
	
	//gbook
	$modtable_guestbook = "$dbprefix" . "m_gbook";
	mysql_query("ALTER TABLE $modtable_guestbook add initial tinyint(1) default 1");
	mysql_query("INSERT INTO $table_configuration VALUES('gbook_check_before_post' , '0' , '')") ;
	
	//ads
	$modtable_ads = "$dbprefix" . "adtext";
	mysql_query("ALTER TABLE $modtable_ads add initial tinyint(1) default 1");
	mysql_query("INSERT INTO $table_configuration VALUES('ads_check_before_post' , '0' , '')") ;
	
	//downloads
	mysql_query("INSERT INTO $table_configuration VALUES('download_welcome_text_prot' , 'Welcome text protected area' , '')") ;
	
	//message
	$message_table = $dbprefix . "m_message";
	
	mysql_query("CREATE TABLE $message_table (
				  id int(11) NOT NULL auto_increment,
				  message text NOT NULL,
				  date datetime default NULL,
				  name varchar(45) default NULL,
				  days int(11) default 0,
				  todate date,
				  PRIMARY KEY (id))");

	$result = mysql_query("SELECT id FROM $table_modules WHERE location = 'sn_message'");
	$RecordCount = mysql_num_rows($result);
		if($RecordCount == 0) 
		{
		mysql_query("INSERT INTO $table_modules VALUES (NULL, 'Messages', 'sn_message', 'message.php,Add messages,view_message.php,View messages', 'admin.php', '')");
		mysql_query("INSERT INTO $table_configuration VALUES ('message_add_text', '<font size=6><b>Add a Message</font></b><hr>', '')");
		mysql_query("INSERT INTO $table_configuration VALUES ('message_view_text', '<font size=6><b>View messages</font></b><hr> ', '')");
		}
	
	//links
	$links_table = $dbprefix . "m_links";
	$links_cat_table = $dbprefix . "m_links_cat";
	
	mysql_query("CREATE TABLE $links_table (
				  id int(11) NOT NULL auto_increment,
				  title varchar(50) NOT NULL default '',
				  url varchar(100) NOT NULL default '',
				  description text NOT NULL,
				  pagename int(11) NOT NULL default '0',
				  initial tinyint(1) NOT NULL default '1',
				  sort tinyint(4) NOT NULL default '0',
				  category varchar(30) NOT NULL default '',
				  PRIMARY KEY  (id))");
	mysql_query("CREATE TABLE $links_cat_table (
				  id int(11) NOT NULL auto_increment,
				  pagename varchar(50) NOT NULL default '',
				  owner_email varchar(80) NOT NULL default '',
				  row_count tinyint(4) NOT NULL default '0',
				  welcome text NOT NULL,
				  icon varchar(50) NOT NULL default '',
				  propose tinyint(1) NOT NULL default '0',
				  propose_welcome text,
				  showlink tinyint(1) NOT NULL default '0',
				  PRIMARY KEY  (id))");
				 
	$result = mysql_query("SELECT id FROM $table_modules WHERE location = 'sn_links'");
	$RecordCount = mysql_num_rows($result);
		if($RecordCount == 0) 
		{
		mysql_query("INSERT INTO $table_modules VALUES (NULL, 'Links', 'sn_links', 'view_links.php,Show Links on page', 'admin.php', '')");
		mysql_query("INSERT INTO $table_configuration VALUES ('links_module_row_count', '1', '')");
		mysql_query("INSERT INTO $table_configuration VALUES ('links_module_icon', '/starnet/modules/sn_links/link.gif', '')");
		}
	
	//encryption and file permissions
	mysql_query("INSERT INTO $table_configuration VALUES ('use_encryption', '0', 'Use encryption?')");
	mysql_query("INSERT INTO $table_configuration VALUES ('file_permissions', '0777', 'File permissions for upload')");
	
	//template editor
	$table_template = $dbprefix . "m_template";
	mysql_query("UPDATE TABLE $table_template SET type8 = 's', name8 = 'Border size in px' WHERE script = 'content1.php'");
	

	//FCK editor
	$result = mysql_query("SELECT id FROM $table_editors WHERE location = 'fckeditor/editor.php'");
	$RecordCount = mysql_num_rows($result);
	if($RecordCount == 0) 
	{
	mysql_query("INSERT INTO $table_editors VALUES (NULL, 'FCK editor', 'fckeditor/editor.php', '')");
	}
} 

if($step2 == 1 )
{
//downloads module coversion

	$downloads_categorytable = $dbprefix."m_downloads_cat";
	$downloads_table = $dbprefix."m_downloads";
	$query = "SELECT * FROM $downloads_table LIMIT 1";
	$result = mysql_query($query) ;

	if(mysql_field_name($result, 6) == "bin_data")		//we have bin_data field , do the conversion
	{
	mysql_query("ALTER TABLE $downloads_table ADD stored_file VARCHAR(40)");
	mysql_query("UPDATE $downloads_table SET stored_file = md5(filename) WHERE id > 0");
	
	$query = "SELECT id, title, public FROM $downloads_categorytable";                             
	$result = mysql_query($query) ;
		if (!$result) 
		{
		   die('Invalid query: ' . mysql_error());
		}
		
			if(mysql_num_rows($result) > 0)
			{
				while ($cat_list = mysql_fetch_array($result))		//loop through the categories
				{
					$cat_dir = "$sas_config[serverpath]$sas_config[user_path]/$sas_config[media_dir]/downloads/".$cat_list[0] ;
		
					if (!file_exists($cat_dir)) 
					{
					mkdir($cat_dir,0755);
					$handle = fopen($cat_dir."/index.html", 'w') ;	//write an empty index.html in the directory
					fwrite($handle, "") ; 	
					}
					
					$query1 = "SELECT id, filename, stored_file, bin_data FROM $downloads_table WHERE category = '$cat_list[0]'";
					$result1 = mysql_query($query1);
					if (!$result1) 
					{
					   die('Invalid query: ' . mysql_error());
					}
		   
					while ($doc_list = mysql_fetch_array($result1))		//loop through the documents
					{
						$write_path_from = "$sas_config[serverpath]$sas_config[user_path]/$sas_config[media_dir]/downloads/" . $doc_list[1];
						$write_path_to = "$sas_config[serverpath]$sas_config[user_path]/$sas_config[media_dir]/downloads/$cat_list[0]/" . $doc_list[2];
						
						if($cat_list[2] == 0)		//category is public
						{
							if (!copy($write_path_from,$write_path_to)) 
							{
							   echo "failed to copy $file...\n";
							}
							else
							{
							unlink($write_path_from) ;
							}
						}
						else
						{
							if (!$handle = fopen($write_path_to, 'w')) 
							{
							 echo "Cannot open file ($write_path_to)";
							}
				
							 //Write content from blobfield to our opened file. Blob is $doc_list[3], not $doclist[2]! 2006-05-31/PF
							if (fwrite($handle, $doc_list[3]) === FALSE) 
							{
							   echo "Cannot write to file ($write_path_to)";
							}	
						}
					}
				
				}
			}
		
		$query1 = "SELECT id, filename, stored_file, category FROM $downloads_table ORDER BY filename";
		$result1 = mysql_query($query1);
		if (!$result1) 
		{
		   die('Invalid query: ' . mysql_error());
		}
		
		$error = FALSE ;  
			while ($doc_list = mysql_fetch_array($result1))		//loop through the documents
			{
			$filename = "$sas_config[serverpath]$sas_config[user_path]/$sas_config[media_dir]/downloads/$doc_list[3]/" . $doc_list[2];
				if (!file_exists($filename)) 
				{
				$error = TRUE ;
				print "File: <b>".$doc_list[1]."</b> does not exists, stored filename is ".$doc_list[3]."/" . $doc_list[2]."<br>" ;
				}
			}
		
		if($error == FALSE)
		{
		mysql_query("ALTER TABLE $downloads_table DROP bin_data");
		print "Download migration finished.<br>";
		}
		else
		{
		print "<br><font color=red>There has been problems migrating the downloads table, see previous messages.</font><br>" ;
		}
	}
}

if($step3 == 1)
{
	$downloads_table = $dbprefix."m_downloads";
	mysql_query("INSERT INTO $table_configuration VALUES('edex_file_name' , '' , '')") ;
	mysql_query("INSERT INTO $table_configuration VALUES('allbum_reverse_order' , '0' , '')") ;
	mysql_query("ALTER TABLE $downloads_table ADD last_download date");
	mysql_query("ALTER TABLE $downloads_table MODIFY date datetime");
	$table_scripts = $dbprefix . "m_scripts";
	mysql_query("ALTER TABLE $table_scripts MODIFY value1 text");
	mysql_query("ALTER TABLE $table_scripts MODIFY value2 text");
	mysql_query("ALTER TABLE $table_scripts MODIFY value3 text");
}

mysql_query("UPDATE $table_modules SET options = 'view_agenda.php,View agenda' WHERE location = 'sn_agenda'");

//tv module
$result = mysql_query("SELECT id FROM $table_modules WHERE location = 'sn_tvmodule'");
$RecordCount = mysql_num_rows($result);
if($RecordCount == 0) 
{
mysql_query("INSERT INTO $table_modules VALUES (NULL, 'TV Module', 'sn_tvmodule', '', 'admin.php', '')");

$table_scripts = $dbprefix . "m_scripts";
mysql_query("CREATE TABLE $table_scripts (id int(11) NOT NULL auto_increment,
  name varchar(50) NOT NULL default '',
  script varchar(30) NOT NULL default '',
  active tinyint(4) default NULL,
  varname1 varchar(15) default NULL,
  value1 text default NULL,
  varname2 varchar(15) default NULL,
  value2 text default NULL,
  varname3 varchar(15) default NULL,
  value3 text default NULL,
  welcome text,
  loc_id tinyint(11),
  PRIMARY KEY  (id))");

mysql_query("INSERT INTO $table_scripts VALUES (1, 'Scrollscript', 'scroll_page.php', 1, 'Page number', '1', 'Speed', '2', NULL, '', '', '1')");
mysql_query("INSERT INTO $table_scripts VALUES (2, 'Slideshow', 'slideshow_full.php', 0, 'Album name', 'slideshow', 'Speed', '5', 'Width', '300', '', '1')");
mysql_query("INSERT INTO $table_scripts VALUES (3, 'Showpage', 'show_page.php', 0, 'Page number', '1', NULL, '', NULL, '', '', '1')");
mysql_query("INSERT INTO $table_scripts VALUES (4, 'Page slideshow', 'page_slideshow.php', 0, 'Pages', '1', NULL, '', NULL, '', '', '1')");
print "TV module has been installed.<p>";
}

print "<p>Migration is finished, current Site@School version is: 2.4.03<br>
		You can now continue normal operation on your site.<p>";
print "<br><font color=red>Please don't forget to delete the content of the <b>starnet/install</b> directory when you are finished!</font>"   ;
?>
<br><br>
<b>The S@S team.</b><br>
</span></td>



                  </tr>
                </table>
                </TD>
                <TD vAlign=top align=middle width="10%"></TD></TR>
              <TR>
                <TD align=center width="25%">&nbsp;
                </TD>
                <TD vAlign=top align=right width="65%">
                  <p>
<?php
}
?>
               </TD>
                <TD vAlign=top align=middle width="10%">&nbsp;</TD></TR>
              </TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
    </TR></TBODY></TABLE></BODY></HTML>