<?php
#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
# About Site@School:
# Original Idea: Mark de Haan (mark@starwave.nl)
# PHP coding & Design: Mark de Haan (mark@starwave.nl)
# Comissioned by: Stadsdeel de Baarsjes, Amsterdam, Netherlands
############################################################################
# migrate2.4_2.4.1.php: last changed 04/10/2006  , version: 2.4.10
#              by Fred Stuurman
#$Id: migrate2.4_2.4.1.php,v 1.1 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
?>
<!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.4 to 2.4.10</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.4_2.4.1.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.4 to 2.4.10 .<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.4_2.4.1.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.10 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>" ;
}

if($sas_config['sas_version'] != "2.4")
{
print "This upgrade is not this version you are running.<br>
		please check that you have 2.4.xx running";
exit;
}

switch ($sas_version)                                                         // start of switch
{
	case "2.410":			//level is ok , quit here
	print "Your Site@School version is already up to the right level!.<br>";
	break;
	
	default:				//sas  version 2.4 I assume.	
	$forumtopics_table = $dbprefix."m_forumtopics";
	//alter reads field forum topics table
	$result = mysql_query("SHOW COLUMNS FROM $forumtopics_table LIKE 'topic_reads'");
	
	if (mysql_num_rows($result) == 0) 
	{
	mysql_query("ALTER TABLE $forumtopics_table CHANGE reads topic_reads int(11)");
	}
	
	//newsletter table extra field
	$table_newsletter_cat = $dbprefix ."m_newsletter_cat";
	$result = mysql_query("SHOW COLUMNS FROM $table_newsletter_cat LIKE 'sender_email'");
	
	if (mysql_num_rows($result) == 0) 
	{
	mysql_query("ALTER TABLE $table_newsletter_cat ADD sender_email varchar(80) not null") ;
	}
	
	//locked_by field newletter table
	$table_newsletters = $dbprefix ."m_newsletters";
	$result = mysql_query("SHOW COLUMNS FROM $table_newsletters LIKE 'locked_by'");
	
	if (mysql_num_rows($result) == 0) 
	{
	$result = mysql_query("ALTER TABLE $table_newsletters ADD locked_by int(11) default null") ;
	}
	
	//locked_by field pages table
	$result = mysql_query("SHOW COLUMNS FROM $table_pages LIKE 'locked_by'");
	
	if (mysql_num_rows($result) == 0) 
	{
	$result = mysql_query("ALTER TABLE $table_pages ADD locked_by int(11) default null") ;
	}
	
	$table_prot_pages = $dbprefix."prot_pages";
	//locked_by field prot pages table
	$result = mysql_query("SHOW COLUMNS FROM $table_prot_pages LIKE 'locked_by'");
	
	if (mysql_num_rows($result) == 0) 
	{
	$result = mysql_query("ALTER TABLE $table_prot_pages ADD locked_by int(11) default null") ;
	}
	
	//invalid_logins field pages table
	$result = mysql_query("SHOW COLUMNS FROM $table_users LIKE 'invalid_logins'");
	
	//invalid_logins field table users
	if (mysql_num_rows($result) == 0) 
	{
	$result = mysql_query("ALTER TABLE $table_users ADD invalid_logins tinyint(1) default 0") ;
	$result = mysql_query("UPDATE $table_users SET invalid_logins = 0 WHERE id > 0") ;
	}
	
	//message
	$message_table = $dbprefix . "m_message";
	$result = mysql_query("SHOW COLUMNS FROM $message_table LIKE 'public'");
	if (mysql_num_rows($result) == 0) 
	{
	mysql_query("ALTER TABLE $message_table ADD public tinyint(4) DEFAULT 0") ;
	}
	
	mysql_query("INSERT INTO $table_configuration VALUES ('message_view_text_prot', '<font size=6><b>VIEW MESSAGES PROTECTED AREA</font></b><hr> ', '')");
	
	//delete orphan studentpages
	$query = "SELECT dir_number FROM $table_studentpages";  
	$result = mysql_query($query) or die(mysql_error());
	while ($student_list = mysql_fetch_array($result)) 
	{ 
	//check if we have a pupil/teacher with this dir_number
		$query1 = "SELECT name FROM $table_users WHERE id = '$student_list[0]'";  
		$result1 = mysql_query($query1) or die(mysql_error());
		$RecordCount = mysql_num_rows($result1);
			if($RecordCount == 0)  
			{   
			//if not delete it.
			mysql_query("DELETE FROM $table_studentpages WHERE dir_number = '$student_list[0]'") ;
			}
	}

	//backup
	$today = time();
	mysql_query("INSERT INTO $table_configuration VALUES ('last_backup_date', '$today', '')");
	
	//forum welcome text
	mysql_query("INSERT INTO $table_configuration VALUES ('forum_welcome_text', '', '')");
	
	//set new patch version
	mysql_query("UPDATE $table_configuration SET config_value = '10' WHERE config_key = 'sas_patch_version'");
	break; 
 
}


print "<p>Migration is finished, current Site@School version is: 2.4.10<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>
