<?

if(isset($_POST['step'])) { $step = $_POST['step']; }
if($step == "") { $step = "0"; }
if($step == 0) { $step_blurb = ""; } else { $step_blurb = "- Step $step of 4"; }

// HEADER
$head = "
<html>
<head>
<title>Webligo IMS Pro Installer $step_blurb</title>
<style type='text/css'>
body { font-family: verdana, arial, tahoma; font-size: 9pt; }
td { font-family: verdana, arial, tahoma; font-size: 9pt; } 
a:link { color: #003366; }
a:visited { color: #003366; }
a:hover { color: #003366; }
</style>
</head>
<body>
<h4>Webligo IMS Pro v4.0 Installer $step_blurb</h4>
<table cellpadding='0' cellspacing='0'>
<tr><td width='550'>
";


// FOOTER
$foot = "
</td></tr></table>
<br><br><br><br><br><br>
</body>
</html>
";





// ### BEGIN STEP 0 ######################################
if($step == 0) {
echo $head;
echo "
Thank you for purchasing the Webligo IMS Pro!
Before continuing, please be sure
you have carefully followed all of the instructions
in <i>readme.txt</i> up to this point.
<br><br>
Remember, your server may not have a standard configuration.
This installer will try to make sure that the IMS will run on
your server, but if you run into any errors during the process,
please check <i>readme.txt</i> or contact us for help. We provide
free installation for anyone who has purchased the IMS Pro, so
do not hesitate to ask if you need help!


<br>
<form action='install.php' method='POST'>
<input class='button' type='submit' value='Continue...'>
<input type='hidden' name='step' value='1'>
</form>
";
echo $foot;
exit();
}





// ### BEGIN STEP 1 ######################################
if($step == 1) {
echo $head;
echo "
First, the installer will make sure that
your server meets all of the requirements needed
to install the IMS. If any of the following results are in red,
you should contact your system administrator and ask them to
fix the problem.
<br><br>

1. Checking PHP Version (must be equal to or greater than 4.2.0)
<br>
";

$v = phpversion();
echo "";
if($v >= "4.2") { 
echo "<font color='#238E23'><b><b>PHP $v Installed</b></b></font>";
} else {
echo "<font color='#FF0000'><b><b>PHP $v Installed</b></b></font>";
}

echo "
<br><br>

2. Checking PHP Safe Mode (must be set to OFF)
<br>
";

if(ini_get('safe_mode')) {
echo "<font color='#FF0000'><b>PHP Safe Mode is ON</b></font>"; $error = "yes";
} else {
echo "<font color='#238E23'><b>PHP Safe Mode is OFF</b></font>";
}

echo "
<br><br>

3. Checking for GD 2.x Support (must be enabled)
<br>
";

function gdVersion() {
   if (! extension_loaded('gd')) { return; }
   ob_start();
   phpinfo(8);
   $info=ob_get_contents();
   ob_end_clean();
   $info=stristr($info, 'gd version');
   preg_match('/\d/', $info, $gd);
   return $gd[0];
} // end function gdVersion()

if ($gdv = gdVersion()) {
  if ($gdv >=2) {
   echo "<font color='#238E23'><b>GD 2.x Support Enabled</b></font>";
  } else {
   echo "<font color='#FF0000'><b>A version older than 2.0 is installed.</b></font>"; $error = "yes";
  }
} else {
  echo "<font color='#FF0000'><b>No GD Libary Support</b></font>"; $error = "yes";
} 



if($error != "yes") {
echo "
<br><br>
<form action='install.php' method='POST'>
<input class='button' type='submit' value='Continue...'>
<input type='hidden' name='step' value='2'>
</form>
";
} else {
echo "
<br><br>
One of the above requirements was not met. Please contact your system administrator or
hosting provider, and return when this has been remedied.
";
}


echo $foot;
exit();
}





// ### BEGIN STEP 2 ######################################
if($step == 2) {
echo $head;
echo "
Now, the installer will check to see that you have uploaded
all of the necessary files/folders and correctly set their permissions. If a
filename is red, it has not been uploaded. If a permissions code
is red, it is incorrect and must be CHMOD to the value in the \"Should Be\" column.<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td width='300' style='padding-bottom: 4px;'><b>File Exists?</b></td>
<td style='padding-bottom: 4px;' width='100'><b>Perm.</b></td>
<td style='padding-bottom: 4px;'><b>Should Be</b></td>
</tr>
";

$error = "no";
function findfile($filename,$perm,$title="") {
global $error;
$path = str_replace("install.php", "", $_SERVER['PATH_TRANSLATED']);
$path .= "$filename";
echo "<tr><td>";
if($title == "") { $title = $filename; }
  if(file_exists($path)) {
  echo "<font color='#000000'>$title</font>"; 
  $decperms = fileperms($filename);
  $octalperms = sprintf("%o",$decperms);
  $perms=(substr($octalperms,-3)); 
  } else {
  echo "<font color='#FF0000'>$title</font>"; 
  $error = "yes";
  }
if($perms == $perm) {
echo "</td><td><font color='#000000'>$perms</font></td>";
} else {
echo "</td><td><font color='#FF0000'>$perms</font></td>";
$error = "yes";
}

echo "<td>$perm</td>";
echo "</tr>";
return $error;
}

$getcwd = getcwd();
$base_dir = str_replace(strrev(strstr(strrev($getcwd), "/")), "", $getcwd);

findfile("../$base_dir", "777", "Base Directory");
findfile("./admin/", "755", "/admin/");
findfile("./icons/", "755", "/icons/");
findfile("./temp/", "777", "/temp/");
findfile("./u/", "777", "/u/");
findfile(".htaccess", "644");
findfile("account_info.php", "755");
findfile("album.php", "755");
findfile("album_folder.php", "755");
findfile("cancel.php", "755");
findfile("change_email.php", "755");
findfile("code.php", "755");
findfile("create_folder.php", "755");
findfile("delete_folder.php", "755");
findfile("delete_images.php", "755");
findfile("first_login.php", "755");
findfile("forgot.php", "755");
findfile("functions.php", "755");
findfile("header.php", "755");
findfile("index.php", "755");
findfile("install.php", "755");
findfile("login.php", "755");
findfile("logout.php", "755");
findfile("modify_folder.php", "755");
findfile("modify_images.php", "755");
findfile("move_images.php", "755");
findfile("paypal.php", "755");
findfile("pic.php", "755");
findfile("prefs.php", "755");
findfile("resize_images.php", "755");
findfile("rotate_images.php", "755");
findfile("signup.php", "755");
findfile("signup_result.php", "755");
findfile("styles.css", "755");
findfile("support.php", "755");
findfile("support_contact.php", "755");
findfile("support_faq.php", "755");
findfile("support_manual.php", "755");
findfile("thumbs.php", "755");
findfile("upgrade.php", "755");
findfile("upload_images.php", "755");
findfile("vars.php", "755");
findfile("view_album.php", "755");
findfile("view_folder.php", "755");
findfile("admin/backup.php", "755");
findfile("admin/backup_tables.php", "755");
findfile("admin/email.php", "755");
findfile("admin/email_list.php", "755");
findfile("admin/faq.php", "755");
findfile("admin/header.php", "755");
findfile("admin/index.php", "755");
findfile("admin/login.php", "755");
findfile("admin/logout.php", "755");
findfile("admin/plan_info.php", "755");
findfile("admin/plans.php", "755");
findfile("admin/plans_add.php", "755");
findfile("admin/settings_demo.php", "755");
findfile("admin/settings_general.php", "755");
findfile("admin/settings_html.php", "755");
findfile("admin/settings_users.php", "755");
findfile("admin/user_cookies.php", "755");
findfile("admin/user_info.php", "755");
findfile("admin/user_info_pending.php", "755");
findfile("admin/users.php", "755");
findfile("admin/users_add.php", "755");
findfile("admin/users_pending.php", "755");
clearstatcache();

echo "</table>";

if($error != "yes") {
echo "
<br>
<form action='install.php' method='POST'>
<input class='button' type='submit' value='Continue...'>
<input type='hidden' name='step' value='3'>
</form>
";
} else {
echo "
<br><br>
You must fix the above file issues before continuing.
";
}

echo $foot;
exit();
}












// ### BEGIN STEP 3 ######################################
if($step == 3) {

function mysql_create() {
  $is_error1 = "no";
  $is_error2 = "no";
  $is_error3 = "no";
  $is_error4 = "no";
  $is_error5 = "no";
  $is_error6 = "no";
  $is_error7 = "no";
  $is_error8 = "no";
  $is_error9 = "no";
  $is_error10 = "no";
  $is_error11 = "no";
  

  // DROP ALL PREVIOUSLY CREATED TABLES
  if(@mysql_query("DROP TABLE IF EXISTS ims, ims_admin, ims_faq, ims_faqcat, ims_folders, ims_image, ims_plans")) {
  $is_error1 = "no";
  } else {
  $is_error1 = "yes";
  }

  // CREATE IMS TABLE
  if(@mysql_query("CREATE TABLE ims (u_id bigint(10) NOT NULL auto_increment, email varchar(200) default NULL, password varchar(100) default NULL, code varchar(255) default NULL, first_login varchar(255) default NULL, payer_paypal_email varchar(255) default NULL, subscribed varchar(255) default NULL, fname varchar(255) default NULL, lname varchar(255) default NULL, account_active varchar(100) default NULL, reset varchar(255) default NULL, new_email_id varchar(255) default NULL, new_email varchar(255) default NULL, new_email_time varchar(255) default NULL, plan varchar(255) default NULL, price varchar(255) default NULL, paypal_email varchar(255) default NULL, signup_date varchar(255) default NULL, IP varchar(255) default NULL, last_login varchar(255) default NULL, ext_list varchar(200) default NULL, space_avail bigint(10) default NULL, folders_avail bigint(10) default NULL, max_filesize bigint(10) default NULL, bandwidth_used varchar(255) default NULL, bandwidth_allotted varchar(255) default NULL, photo_album    varchar(255) default NULL, notes text, is_approved varchar(50) default NULL, prefs_newwin varchar(10) default NULL, prefs_listby varchar(255) default NULL, prefs_images_per_page varchar(255) default NULL, albumprefs_on varchar(10) default NULL, albumprefs_privacy varchar(10) default NULL, albumprefs_password varchar(255) default NULL, albumprefs_logo varchar(255) default NULL, albumprefs_thumbs varchar(10) default NULL, albumprefs_align varchar(10) default NULL, albumprefs_width varchar(5) default NULL, albumprefs_head text, albumprefs_foot text, PRIMARY KEY  (u_id))")) {
  $is_error2 = "no";
  } else {
  $is_error2 = "yes";
  }
  
  // CREATE IMS_ADMIN TABLE
  if(@mysql_query("CREATE TABLE ims_admin (login_name varchar(150) default NULL, password varchar(150) default NULL, special_code varchar(200) default NULL, email varchar(150) default NULL, paypal_email varchar(150) default NULL, timezone varchar(150) default NULL, notify varchar(150) default NULL, welcome varchar(255) default NULL, welcome_sub varchar(150) default NULL, welcome_note longtext, site_name varchar(150) default NULL, site_url varchar(150) default NULL, users_per_page int(4) default NULL, ok_letters varchar(150) default NULL, approve_deny varchar(150) default NULL, appr_email varchar(150) default NULL, appr_sub varchar(150) default NULL, appr_message longtext, den_email varchar(150) default NULL, den_sub varchar(150) default NULL, den_message longtext, inactivity varchar(150) default NULL, ban_ip longtext, ban_email longtext, rotate_feature varchar(150) default NULL, resize_feature varchar(150) default NULL, user_head1 longtext, user_head2 longtext, user_foot longtext, demo_feature varchar(150) 
  default NULL, demo_email varchar(150) default NULL, demo_password varchar(150) default NULL, demo_autofill varchar(150) default NULL, plan_upgrade varchar(150) default NULL, faq_on varchar(5) default NULL, debug_mode varchar(150) default NULL)")) {
  $is_error3 = "no";
  } else {
  $is_error3 = "yes";
  }

  // INSERT DEFAULT VALUES INTO ADMIN TABLE
  if(@mysql_query("INSERT INTO ims_admin VALUES ('admin', 'ims1234', 'Administrator', 'admin@yoursite.com', 'paypal@yoursite.com', '-8', 'yes', 'yes', 'Your New Account Information', 'Dear [name],\r\n\r\nThank you for creating your new account with us.\r\nPlease login with the following information.\r\n\r\nEmail: [email]\r\nPassword: [password]\r\n\r\nTo access your login page, please go to:\r\n[url]\r\n\r\nThank You', 'Image Hosting', 'http://www.yoursite.com', 25, '/[^-,a-z,A-Z,0-9,\\_, ]/', '', 'yes', 'Your New Account Has Been Approved!', 'Dear [name],\r\n\r\nCongratulations! Your new account has been\r\napproved. To login to your account, please follow this link:\r\n[url]\r\n\r\nPlease login with:\r\nEmail: [email]\r\nPassword: [password]\r\n\r\nThank You', 'yes', 'Your New Account Has Been Rejected.', 'Dear [name],\r\n\r\nUnfortunatly we cannot approve your Image Management Account\r\nat this time.\r\n\r\nThank You', '14', '', '', 'yes', 'yes', '', '<br>\r\n<img src=\'./icons/logo.gif\' border=\'0\'>\r\n',   '', 'off', '', '', '', 'yes', 'yes', 'off')")) {
  $is_error4 = "no";
  } else {
  $is_error4 = "yes";
  }

  // CREATE IMS_FAQ TABLE
  if(@mysql_query("CREATE TABLE ims_faq (q_id int(11) NOT NULL auto_increment, c_id varchar(100) NOT NULL default '', q_order int(10) NOT NULL default '0', question varchar(255) NOT NULL default '', answer text NOT NULL, PRIMARY KEY  (q_id))")) {
  $is_error5 = "no";
  } else {
  $is_error5 = "yes";
  }

  // INSERT DEFAULT VALUES INTO IMS_FAQ TABLE
  if(@mysql_query("INSERT INTO ims_faq VALUES (1, '1', 1, 'What is an image folder?', 'Image folders are used to upload, store and organize your images. You can view, create, modify and delete your image folders from your account <a href=\'index.php\'>home</a> page. In order to upload images, you must first create and open an image folder. If your account is new, you will have no image folders.')") & @mysql_query("INSERT INTO ims_faq VALUES (2, '1', 2, 'How do I find my image folders?', 'Your image folders are listed on your account <a href=\'index.php\'>home</a> page. If your account is new, you will have no image folders.')") & @mysql_query("INSERT INTO ims_faq VALUES (3, '1', 3, 'How do I create new image folders?', 'You can create a new image folder by going to your account <a href=\'index.php\'>home</a> page and clicking the \"Create New Folder\" button. ')") & @mysql_query("INSERT INTO ims_faq VALUES (4, '1', 4, 'How do I upload images to an image folder?', 'First, go to your account <a href=\'index.php\'>home</a> page and select an image folder. If there are no image folders, you must first create one. Once you have opened your image folder, click the \"Upload New Images\" button. \r\n\r\nThe upload images page allows you to upload up to three images at once. Starting with Image 1, enter a title and brief description for your image, and then click the \"Browse\" button to find it on your computer. After you have completed this process, click the \"Upload Images\" button.')") & @mysql_query("INSERT INTO ims_faq VALUES (5, '1', 5, 'How do I share or post my images online?', 'If you have already uploaded an image and would like to post it online or share it with others, start by going to your account <a href=\'index.php\'>home</a> page. Next, select the image folder that contains the image you would like to share. \r\n\r\nFind the image that you would like to share. Next to the image thumbnail you will find the URL to the full size image. If you would like to generate HTML or UBB code for this image, click the \"Get Code\" link.')") & @mysql_query("INSERT INTO ims_faq VALUES (6, '1', 6, 'How do I move, modify, or delete images?', 'Images can be moved between folders, modified (including their title and description), and deleted. First, open the folder that contains the image you wish to change. Next, find the image you wish to move, modify, or delete, and click its respective link.')") & @mysql_query("INSERT INTO ims_faq VALUES (7, '1', 7, 'How do I modify or delete image folders?', 'First, return to your account <a href=\'index.php\'>home</a> page. Next, click the \"Modify\" or \"Delete\" button next to the image folder of your choice.')") & @mysql_query("INSERT INTO ims_faq VALUES (8, '1', 8, 'What is space usage?', 'Your account is allocated a certain amount of disk space which is used to store the images that you upload. A representation of your space usage is displayed to the left in the \"Space Usage\" box. If you have filled your allocated space, you will not be able to upload more images until you delete others to free space.')") & @mysql_query("INSERT INTO ims_faq VALUES (9, '1', 9, 'What is bandwidth usage?', 'When one of your images is viewed by someone online, it is transferred from our server to their web browser. This transfer is measured as \"bandwidth\" which is represented by the \"Bandwidth Usage\" box to the left. \r\n\r\nYour account is allotted a certain amount of bandwidth each month (billing cycle). If you exceed the amount of bandwidth allotted to you, your images may not be viewable. Upgrading your account to a more comprehensive package will give you a higher bandwidth allocation.')") & @mysql_query("INSERT INTO ims_faq VALUES (10, '1', 10, 'How do I get more space and bandwidth?', 'If you are running low on space or bandwidth, or would like to take advantage of the extra features offered by our higher packages, you should consider upgrading your account. Upgrading is instant - you will receive your higher space and bandwidth allocations immediately. To learn more about upgrading, <a href=\'upgrade.php\'>click here</a>.')") & @mysql_query("INSERT INTO ims_faq VALUES (11, '1', 11, 'If I find a bug, what should I do?', 'We are constantly improving our system and greatly appreciate any input you could provide, including comments, questions, and bug reports. We encourage you to <a href=\'support_contact.php\'>contact</a> us if you find a bug or problem with the system.')") & @mysql_query("INSERT INTO ims_faq VALUES (12, '2', 1, 'What is my online Photo Album?', 'Some accounts include an online Photo Album. This feature automatically generates a simple gallery of your images that you can share online. To access your Photo Album preferences, <a href=\'view_album.php\'>click here</a>.')") & @mysql_query("INSERT INTO ims_faq VALUES (13, '2', 2, 'How do I view my Photo Album? How can I share it with others?', 'To view your Photo Album, first <a href=\'view_album.php\'>click here</a> to access your album settings page. Next, click the \"View My Photo Album\" button. To share your Photo Album with others, simply send them the URL of this page.')") & @mysql_query("INSERT INTO ims_faq VALUES (14, '2', 3, 'How do I choose which folders are included in my Photo Album?', 'To specify which folders you would like to include in your Photo Album, <a href=\'view_album.php\'>click here</a> to access your settings page. Next, near the middle of the page, check the boxes next to the folders you wish to include. When you are finished, make sure to click the \"Save Changes\" button at the bottom of the page.')") & @mysql_query("INSERT INTO ims_faq VALUES (15, '2', 4, 'How do I password-protect my Photo Album?', 'To password-protect your Photo Album, <a href=\'view_album.php\'>click here</a> to visit your album settings page. Next, in the privacy box, set your album to \"Private\". Finally, enter a password and click the \"Save Changes\" button at the bottom of the page. Now, only users that know the password you provided will be able to access your Photo Album.')") & @mysql_query("INSERT INTO ims_faq VALUES (16, '2', 5, 'How do I choose a custom logo for my Photo Album?', 'You can replace the standard logo on your Photo Album by entering a custom logo URL. First, <a href=\'view_album.php\'>click here</a> to access your Photo Album settings. Next, enter the URL of your logo in the fourth box from the top. This should start with \" http:// \". Of course, it is fine to use an image that you have uploaded to your HostMyPix account.')") & @mysql_query("INSERT INTO ims_faq VALUES (17, '2', 6, 'How do I choose how many images are shown per page?', 'To set the number of images displayed per page, visit the <a href=\'prefs.php\'>preferences</a> section. This setting affects both your account and your Photo Album.')") & @mysql_query("INSERT INTO ims_faq VALUES (18, '2', 7, 'How do I add text or HTML to my Photo Album pages?', 'You can add text or HTML to your photo album by accessing your Photo Album <a href=\'view_album.php\'>settings</a> page. The very last box on the page has two large text fields into which your header/footer HTML or text can be placed.')") & @mysql_query("INSERT INTO ims_faq VALUES (19, '2', 8, 'How do I turn off my Photo Album?', 'If you would like to disable your Photo Album, <a href=\'view_album.php\'>click here</a> to visit your Photo Album settings page. Then, in the first box, select the \"Off\" option.')") & @mysql_query("INSERT INTO ims_faq VALUES (20, '2', 9, 'Error: \"You cannot access this photo album because it has been disabled.\"', 'If you are receiving this error while trying to view your Photo Album, it is because you have disabled your album in your Photo Album settings page. <a href=\'view_album.php\'>Click here</a> to visit this page and make sure that your Photo Album is set to \"On\".\r\n\r\nAnother reason this error may occur is if the administrator has disabled your Photo Album.')") & @mysql_query("INSERT INTO ims_faq VALUES (21, '2', 10, 'Error: \"This photo album contains no image folders.\"', 'If you are receiving this error, it is because you have not included any image folders in your Photo Album. <a href=\'view_album.php\'>Click here</a> to access your Photo Album settings and specify one or more image folders to include in your album.')") & @mysql_query("INSERT INTO ims_faq VALUES (22, '3', 1, 'How often am I billed?', 'You will be billed once every month after you sign up.')") & @mysql_query("INSERT INTO ims_faq VALUES (23, '3', 2, 'How do you accept payments?', 'Secure online payments are sent through PayPal.com.')") & @mysql_query("INSERT INTO ims_faq VALUES (24, '3', 3, 'How do I fix a problem with my bill?', 'Contact us with the <a href=\'support_contact.php\'>contact support form</a>.')") & @mysql_query("INSERT INTO ims_faq VALUES (25, '3', 4, 'How do I upgrade my account?', 'Upgrading is simple and quick. To begin, go to the <a href=\'upgrade.php\'>upgrade page</a>. Unless you are on the highest plan, you will notice different plan listings and their features. If you are on the highest plan and require more space or bandwidth, <a href=\'support_contact.php\'>contact support</a> to make special arrangements. Once you have selected the plan you wish to upgrade to, click the \"Upgrade\" button beneath its description. \r\n\r\nTo upgrade, you must modify your current PayPal subscription. Follow the instructions provided by PayPal. If you have more than one hosting account, be absolutely sure that you have upgraded the correct subscription, otherwise the changes may not take effect.\r\n\r\nIf you experience any difficulty, please contact the administrators via our <a href=\'support_contact.php\'>contact form</a>. ')") & @mysql_query("INSERT INTO ims_faq VALUES (26, '3', 5, 'How do I cancel my account?', 'If you wish to cancel your account, please <a href=\'account_info.php\'>click here</a> to visit the account information page.')") & @mysql_query("INSERT INTO ims_faq VALUES (27, '3', 6, 'How do I change my email address?', 'To change your email address, please <a href=\'account_info.php\'>click here</a> to visit the account information page.')")) {
  $is_error6 = "no";
  } else {
  $is_error6 = "yes";
  }

  // CREATE IMS_FAQCAT TABLE
  if(@mysql_query("CREATE TABLE ims_faqcat (c_id bigint(10) NOT NULL auto_increment, c_order int(10) default NULL, category varchar(250) default NULL, PRIMARY KEY  (c_id))")) {
  $is_error7 = "no";
  } else {
  $is_error7 = "yes";
  }

  // INSERT DEFAULT VALUES INTO IMS_FAQCAT TABLE
  if(@mysql_query("INSERT INTO ims_faqcat VALUES (1, 1, 'General Questions')") & @mysql_query("INSERT INTO ims_faqcat VALUES (2, 2, 'Photo Album Questions')") & @mysql_query("INSERT INTO ims_faqcat VALUES (3, 3, 'Billing Questions')")) {
  $is_error8 = "no";
  } else {
  $is_error8 = "yes";
  }

  // CREATE IMS_FOLDERS TABLE
  if(@mysql_query("CREATE TABLE ims_folders (f_id bigint(10) NOT NULL auto_increment, u_id bigint(10) NOT NULL default '0', name varchar(255) NOT NULL default '', description text NOT NULL, in_album varchar(10) NOT NULL default '', PRIMARY KEY  (f_id))")) {
  $is_error9 = "no";
  } else {
  $is_error9 = "yes";
  }

  // CREATE IMS_IMAGE TABLE
  if(@mysql_query("CREATE TABLE ims_image (i_id bigint(10) NOT NULL auto_increment, u_id bigint(10) NOT NULL default '0', f_id bigint(10) NOT NULL default '0', title varchar(255) NOT NULL default '', description text NOT NULL, thumb varchar(255) NOT NULL default '', ext varchar(20) NOT NULL default '', size varchar(20) NOT NULL default '', views varchar(8) NOT NULL default '', PRIMARY KEY  (i_id))")) {
  $is_error10 = "no";
  } else {
  $is_error10 = "yes";
  }

  // CREATE IMS_PLANS TABLE
  if(@mysql_query("CREATE TABLE ims_plans (p_id bigint(10) NOT NULL auto_increment, plan varchar(255) default NULL, price float default NULL, status varchar(255) NOT NULL default '', plan_description varchar(255) default NULL, photo_album varchar(255) default NULL, allocated_space varchar(255) default NULL, allowed_folders varchar(255) default NULL, max_filesize varchar(255) default NULL, bandwidth_allotted varchar(255) default NULL, ext_list varchar(255) default NULL, PRIMARY KEY  (p_id))")) {
  $is_error11 = "no";
  } else {
  $is_error11 = "yes";
  }

if($is_error1 == "yes" | $is_error2 == "yes" | $is_error3 == "yes" | $is_error4 == "yes" | $is_error5 == "yes" | $is_error6 == "yes" | $is_error7 == "yes" | $is_error8 == "yes" | $is_error9 == "yes" | $is_error10 == "yes" | $is_error11 == "yes") {
return false;
} else {
return true;
}
}






echo $head;

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "main"; }

if($task == "connect") {
$result = "";
$mysql_host = $_POST['mysql_host'];
$mysql_name = $_POST['mysql_name'];
$mysql_user = $_POST['mysql_user'];
$mysql_pass = $_POST['mysql_pass'];
  if(@mysql_connect($mysql_host, $mysql_user, $mysql_pass)) {
  $result .= "Successfully connected to host.<br>";
    if(@mysql_select_db($mysql_name)) {
    $result .= "Successfully connected to database.<br>";
      if(!file_exists("mysqlcon.php")) {
        if(mysql_create()) {
         // SUCCESS, CREATE MYSQLCON.PHP
         $filename = "mysqlcon.php";
         $somecontent = "<?\nmysql_connect(\"$mysql_host\", \"$mysql_user\", \"$mysql_pass\");\nmysql_select_db(\"$mysql_name\");\n?>";
         $handle = fopen($filename, 'w+');
         fwrite($handle, $somecontent);
         fclose($handle);
         $result .= "Successfully created MySQL tables.<br>";
         $result .= "MySQL connection informaton saved.<br>";
         $success = "yes";
        } else {
        $result .= "<font color='#FF0000'>Failed to create MySQL tables.</font><br>";
        }
      } else {
      $result .= "<font color='#FF0000'>The file mysqlcon.php could not be created because it already exists. Please delete it manually and try again.</font><br>";
      }
    } else {
    $result .= "<font color='#FF0000'>Could not connect to database. Please be sure it has been properly created.</font><br>";
    }
  } else {
  $result .= "<font color='#FF0000'>Could not connect to host. Check your user/pass.</font><br>";
  }
} else {
$mysql_host = "localhost";
$mysql_name = "";
$mysql_user = "";
$mysql_pass = "";
}

if($task == "connect") {
if($_POST['mysql_user'] == "" OR $_POST['mysql_pass'] == "") {
$result = "<font color='#FF0000'>Could not connect to host. Check your user/pass.</font><br>";
}}

echo "
Please provide the following information about your MySQL database.
The installer will attempt to make a connection. If the attempt is
successful, your MySQL information will be saved.
<br>
";

if($success != "yes") {
echo "
<form action='install.php' method='POST'>
<b>MySQL Host</b><br>
<input type='text' size='30' name='mysql_host' value='$mysql_host'>
<br><br>

<b>Database Name</b><br>
<input type='text' size='30' name='mysql_name' value='$mysql_name'>
<br><br>

<b>Username</b><br>
<input type='text' size='30' name='mysql_user' value='$mysql_user'>
<br><br>

<b>Password</b><br>
<input type='text' size='30' name='mysql_pass' value='$mysql_pass'>
<br>

<input type='submit' value='Connect' style='margin-top: 5px;'>
<input type='hidden' name='step' value='3'>
<input type='hidden' name='task' value='connect'>
</form>
";
}

echo "
<br>
<b>$result</b>
";

if($success == "yes") {
echo "
<form action='install.php' method='POST'>
<input type='submit' value='Continue...' style='margin-top: 5px;'>
<input type='hidden' name='step' value='4'>
</form>
";
}

echo $foot;
exit();
}











// ### BEGIN STEP 4 ######################################
if($step == 4) {
echo $head;

echo "
Your IMS Pro has been installed! Next, you must login to your
administration area to configure your IMS. Please follow the
instructions in <i>readme.txt</i> carefully.
<br><br>

<b><a href='./admin/index.php'>Continue to your IMS Pro administration area.</a></b>

";

echo $foot;
exit();
}










?>