2011-02-16 17:00:55 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
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 , version 2.
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 should have received a copy of the GNU General Public License
along with this program ; see the file COPYING . If not , write to
the Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
Boston , MA 02111 - 1307 , USA .
*/
echo " <?xml version= \" 1.0 \" encoding= \" iso-8859-1 \" ?> \n " ;
?>
2024-12-13 15:42:19 +00:00
<! DOCTYPE html >
< html >
< head >
< meta charset = " utf-8 " />
< title > SFIAB Installation </ title >
2011-02-16 17:00:55 +00:00
< link rel = " stylesheet " href = " sfiab.css " type = " text/css " />
</ head >
< body >
< h1 > SFIAB Installation - Step 3 </ h1 >
< ?
if ( ! file_exists ( " data/config.inc.php " ))
{
echo " <div class= \" error \" >SFIAB Installation Step 1 is not yet complete.</div> " ;
echo " <a href= \" install.php \" >Go back to installation step 1</a><br /> " ;
echo " </body></html> " ;
exit ;
}
require_once ( " data/config.inc.php " );
require_once ( " config_editor.inc.php " );
require_once ( " user.inc.php " );
require_once ( " committee.inc.php " );
$DBUSER = substr ( $DBUSER , 0 , 16 );
2024-11-25 23:06:33 +00:00
pdo = new PDO ( $DBHOST , $DBUSER , $DBPASS )
2011-02-16 17:00:55 +00:00
echo " Checking for SFIAB database... " ;
2024-11-25 23:06:33 +00:00
$stmt = $pdo -> prepare ( " SELECT val FROM config WHERE var = :var AND year = :year " );
$stmt -> execute ([ ':var' => 'DBVERSION' , ':year' => 0 ]);
$r = $stmt -> fetch ( PDO :: FETCH_OBJ );
2011-02-16 17:00:55 +00:00
$dbdbversion = $r -> val ;
if ( ! $dbdbversion )
{
echo " <div class= \" error \" >SFIAB Installation Step 2 is not yet complete.</div> " ;
echo " <a href= \" install2.php \" >Go back to installation step 2</a><br /> " ;
echo " </body></html> " ;
exit ;
}
//a fresh install should ONLY have DBVERSION defined in the config table. If there are others (FAIRYEAR, SFIABDIRECTORY) then this is NOT fresh
2024-11-25 23:06:33 +00:00
$q = pdo -> query ( " SELECT * FROM config WHERE year='0' AND ( var='DBVERSION' OR var='FAIRYEAR' OR var='SFIABDIRECTORY') " );
2011-02-16 17:00:55 +00:00
//we might get an error if the config table does not exist (ie, installer step 2 failed)
2024-11-25 23:06:33 +00:00
if ( pdo -> errorInfo )
2011-02-16 17:00:55 +00:00
{
//we say all tables, but really only we check for config where year=0;
echo " <div class= \" error \" >ERROR: No SFIAB tables detected, It seems like step 2 failed. Please go <a href= \" install2.php \" >Back to Installation Step 2</a> and try again.</div> " ;
echo " </body></html> " ;
exit ;
}
//1 is okay (DBVERSION). More than 1 is bad (already isntalled)
2024-12-12 21:24:45 +00:00
if ( $q -> rowCount () > 1 )
2011-02-16 17:00:55 +00:00
{
//we say all tables, but really only we check for config where year=0;
echo " <div class= \" error \" >ERROR: Detected existing table data, SFIAB Installation Step 3 requires a clean SFIAB database installation.</div> " ;
echo " </body></html> " ;
exit ;
}
echo " <b>Found!</b><br /> " ;
if ( $_POST [ 'action' ] == " save " )
{
$err = false ;
if ( ! $_POST [ 'fairyear' ])
{
echo " Fair Year is required " ;
$err = true ;
}
if ( ! $_POST [ 'email' ])
{
echo " Superuser email address is required " ;
$err = true ;
}
if ( ! ( $_POST [ 'pass1' ] && $_POST [ 'pass2' ]))
{
echo " Superuser password and password confirmation are required " ;
$err = true ;
}
if ( $_POST [ 'pass1' ] != $_POST [ 'pass2' ])
{
echo " Password and Password confirmation do not match " ;
$err = true ;
}
if ( ! $err )
{
echo " Creating configuration settings... " ;
2024-11-25 23:06:33 +00:00
$stmt = $pdo -> prepare ( " INSERT INTO config (var, val, category, ord, year) VALUES (:var, :val, :category, :ord, :year) " );
$stmt -> execute ([
':var' => 'FAIRYEAR' ,
':val' => $_POST [ 'fairyear' ],
':category' => 'Special' ,
':ord' => '0' ,
':year' => '0'
]);
$stmt -> execute ([
':var' => 'FISCALYEAR' ,
':val' => $_POST [ 'fiscalyear' ],
':category' => 'Special' ,
':ord' => '0' ,
':year' => '0'
]);
$stmt -> execute ([
':var' => 'SFIABDIRECTORY' ,
':val' => $_POST [ 'sfiabdirectory' ],
':category' => 'Special' ,
':ord' => '' ,
':year' => '0'
]);
2011-02-16 17:00:55 +00:00
$year = intval ( $_POST [ 'fairyear' ]);
//copy over the config defautls
config_update_variables ( $year );
// Update some variables
2024-11-25 23:06:33 +00:00
2011-02-16 17:00:55 +00:00
2024-11-25 23:06:33 +00:00
$stmt = pdo -> prepare ( " UPDATE config SET val = :fairname WHERE var = 'fairname' AND year = :year " )
$stmt . execute ( ':fairname' => stripslashes ( $_POST [ 'fairname' ]),
':year' => $year )
$stmt = pdo -> prepare ( " UPDATE config SET val = :email WHERE var = 'fairmanageremail' AND year = :year " )
$stmt -> execute ([ ':email' => $_POST [ 'email' ], ':year' => $year
]);
2011-02-16 17:00:55 +00:00
2024-11-25 23:06:33 +00:00
$stmt = $pdo -> prepare ( " SELECT * FROM dates WHERE year = :year " );
$stmt -> execute ([ ':year' => '-1' ]);
$results = $stmt -> fetchAll ( PDO :: FETCH_OBJ );
$stmt = pdo -> prepare ( " INSERT INTO dates (date, name, description, year) VALUES (:date, :name, :description, :fairyear) " )
foreach ( $results as $r ){
$stmt -> execute ([
':date' => $r -> date ,
':name' => $r -> name ,
':description' => $r -> description ,
':fairyear' => $_POST [ 'fairyear' ]
]);
2011-02-16 17:00:55 +00:00
}
2024-11-25 23:06:33 +00:00
$stmt = pdo -> prepare ( 'SELECT * FROM award_types WHERE year=:year' )
$stmt -> execute ([ 'year' => - 1 ])
$results = $stmt -> fetchAll ( PDO :: FETCH_OBJ );
$insertStmt = $pdo -> prepare ( " INSERT INTO award_types (id, type, `order`, year) VALUES (:id, :type, :order, :year) " );
2011-02-16 17:00:55 +00:00
//copy over the award_types defautls
2024-11-25 23:06:33 +00:00
foreach ( $results as $r ){
$insertStmt -> execute ([
'id' => $r -> id ,
'type' => $r -> type ,
'order' => $r -> order ,
'year' => $fairYear
]);
2011-02-16 17:00:55 +00:00
}
echo " <b>Done!</b><br /> " ;
echo " Creating superuser account... " ;
$u = user_create ( 'committee' , $_POST [ 'email' ]);
if ( $_POST [ 'firstname' ] && $_POST [ 'lastname' ]) {
2024-12-12 21:24:45 +00:00
$u [ 'firstname' ] = stripslashes ( $_POST [ 'firstname' ]);
$u [ 'lastname' ] = stripslashes ( $_POST [ 'lastname' ]);
2011-02-16 17:00:55 +00:00
}
else {
$u [ 'firstname' ] = 'Superuser' ;
$u [ 'lastname' ] = 'Account' ;
}
2024-12-12 21:24:45 +00:00
$u [ 'emailprivate' ] = stripslashes ( $_POST [ 'email' ]);
$u [ 'email' ] = stripslashes ( $_POST [ 'email' ]);
$u [ 'username' ] = stripslashes ( $_POST [ 'email' ]);
$u [ 'password' ] = stripslashes ( $_POST [ 'pass1' ]);
2011-02-16 17:00:55 +00:00
$u [ 'access_admin' ] = 'yes' ;
$u [ 'access_config' ] = 'yes' ;
2024-11-25 23:06:33 +00:00
$u [ 'access_super' ] = 'yes' ;
2011-02-16 17:00:55 +00:00
user_save ( $u );
echo " <b>Done!</b><br /> " ;
echo " Installation is now complete! You can now proceed to the following location: <br /> " ;
echo " <a href= \" " . $_POST [ 'sfiabdirectory' ] . " \" >Your SFIAB main page</a><br /> " ;
echo " </body></html> " ;
exit ;
}
}
echo " <br /> " ;
2024-11-25 23:06:33 +00:00
2011-02-16 17:00:55 +00:00
echo " Please enter the following options <br /> " ;
2024-11-25 23:06:33 +00:00
}
2011-02-16 17:00:55 +00:00
echo " <br /> " ;
$month = date ( " m " );
if ( $month > 4 ) $fairyearsuggest = date ( " Y " ) + 1 ;
else $fairyearsuggest = date ( " Y " );
if ( $month > 6 ) $fiscalyearsuggest = date ( " Y " ) + 1 ;
else $fiscalyearsuggest = date ( " Y " );
2011-02-24 18:12:03 +00:00
// Dennis $_SERVER['REQUEST_URI'] is not available on many Windows servers
//$directorysuggest = substr($_SERVER['REQUEST_URI'],0,-13);
$directorysuggest = substr ( getenv ( " SCRIPT_NAME " ), 0 , - 13 );
2011-02-16 17:00:55 +00:00
echo " <h3>Options</h3> " ;
echo " <form method= \" post \" action= \" install3.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" save \" /> " ;
echo " <table> " ;
echo " <tr><td>Fair Name</td><td><input size= \" 25 \" type= \" text \" name= \" fairname \" value= \" \" ></td><td>The name of the fair you are installing SFIAB to run</td></tr> " ;
echo " <tr><td>Fair Year</td><td><input size= \" 8 \" type= \" text \" name= \" fairyear \" value= \" $fairyearsuggest\ " ></ td >< td > The year of the fair you are installing SFIAB to run </ td ></ tr > " ;
echo " <tr><td>Fiscal Year</td><td><input size= \" 8 \" type= \" text \" name= \" fiscalyear \" value= \" $fiscalyearsuggest\ " ></ td >< td > The current fiscal year ( for fundraising / accounting purposes ) </ td ></ tr > " ;
echo " <tr><td>Directory</td><td><input size= \" 25 \" type= \" text \" name= \" sfiabdirectory \" value= \" $directorysuggest\ " ></ td >< td > The directory of this SFIAB installation as seen by the web browser </ td ></ tr > " ;
echo " </table> " ;
echo " <br /> " ;
echo " <h3>Superuser Account</h3> " ;
echo " Please choose your superuser account which is required to login to SFIAB and configure the system, as well as to add other users. <br /> " ;
echo " <table> " ;
echo " <tr><td>Superuser Email Address</td><td><input size= \" 40 \" type= \" text \" name= \" email \" ></td></tr> " ;
2024-11-25 23:06:33 +00:00
echo " <tr><td>Superuser Password</td><td><input size= \" 15 \" type= \" password \" name=
} \ " pass1 \" ></td></tr> " ;
2011-02-16 17:00:55 +00:00
echo " <tr><td>Superuser Password (Confirm)</td><td><input size= \" 15 \" type= \" password \" name= \" pass2 \" ></td></tr> " ;
echo " </table> " ;
echo " <br /> " ;
echo " <input type= \" submit \" value= \" Complete Installation \" > " ;
echo " </form> " ;
?>
</ body ></ html >