Location: PHPKode > projects > NCD Toolkit > ncdtoolkit1.2/ncd/installation/setup.php
<?php
	session_start();
	include("../library.inc.php");

	// This page will check connection data, create an admin account to start going and a second system language if necessary.
	// It will automatically be linked to if a user attempts to open a page in the toolkit while the connection data have not been set yet.
	
	if (!file_exists("../settings.inc.php"))
		$error = "The file 'settings.inc.php' cannot be found! Please reinstall it at the root level of the NCD toolkit.";
	else
	{
		require_once("../settings.inc.php");
		if (is_writable("../settings.inc.php"))
			$error = "The file 'settings.inc.php' is writable, this poses a security risk! Please set the permissions of 'settings.inc.php' to read-only (chmod 755) before continuing.";
		else
		{
			if ($mysql_host == "localhost" && $mysql_user == "user" && $mysql_password == "password" && $mysql_database == "ncd")
				$error = "Please change the settings in the 'settings.inc.php' to continue.";	
			else
			{
				@$connect = mysql_connect($mysql_host, $mysql_user, $mysql_password);
				if (!$connect)
					$error = "Could not connect to the NCD database. Please verify the settings in 'settings.inc.php'.";
				else
				{
					@mysql_select_db($mysql_database, $connect) or die ("Could not connect to $mysql_database: ".mysql_error());
					mysql_query("SET SQL_MODE=''");
					mysql_query("SET NAMES 'utf8'");
					$error = "";
				}
			}
		}
	}
	
	$request_variables = array ("language_setup_id", "iso", "step", "new_user_name", "new_user_real_name", "new_user_password", "new_user_email");
	$user_variables = array ("new_user_name", "new_user_real_name", "new_user_password", "new_user_email");

	foreach ($request_variables as $variable)
	{
		if (isset($_REQUEST[$variable]))
			$$variable = trim($_REQUEST[$variable]);
		else
			$$variable = "";
	}

	$missing_data = "";
	foreach ($user_variables as $variable)
	{
		if ($$variable == "" || $$variable == "0")
			$missing_data = "y";
	}
	
	// Check if user exists (if page is reloaded)
	$user_exists = "";
	if ($new_user_name != "")
	{
		$query = "SELECT UserName FROM Users WHERE UserName = '$new_user_name'";
		$result = mysql_query($query);
		if (mysql_num_rows($result) != 0)
			$user_exists = "y";
	}

	// Check if setup has not already been completed. By default SecondLanguageID is set to 'xxx'.
	// After setup this has been changed to real ISO code or a blank entry if no language has been chosen.

	$setup_completed = "";
	if ($connect != "")
	{
		$result = mysql_query("SELECT SecondLanguageID FROM Settings");
		$row = mysql_fetch_array($result);
		if (mysql_num_rows($result) > 0 && $row[0] != "xxx")
			$setup_completed = "y";
	}
	$menu = "index";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <link href="../ncd.css" rel="stylesheet" media="screen" type="text/css">
  <script type="text/javascript" src="../library.js"></script>

  <title>NCD toolkit - Setup</title>
</head>
<body>
<div id="main_container">
<div id="banner"><?php include("../banner.inc.php"); ?></div>
<div id="content_container">
<div id="content">


<?php
	echo "<h2>Setup of the NCD toolkit</h2>\n";
	if ($setup_completed != "y")
	{
		if ($step == "" || $step == 1 && $error != "")
		{
			echo "<h3>Step 1: Connection to the NCD database</h3>\n";
			echo "<p>Welcome to the setup pages of the NCD toolkit. Before the toolkit can be used, a few steps have to be taken. The first step is to create a connection to the MySQL database. This requires you to enter the name of the server on which the database is installed, the name and password of a MySQL user with sufficient privileges to create, update and delete records and the name of the database in which the tables ncd_mysql4.sql or ncd_mysql5.sql were imported (see INSTALLATION.txt).</p>\n<p>Please navigate to the installation folder of the NCD toolkit and enter the data in the 'settings.inc.php' file. After entering the data, set the permission of the file to read-only (chmod 755) and click 'Continue setup'</p>\n";
			
			if ($error != "" && $step != "")
				echo "<p class=\"error\">Error: $error</p>\n";
		
			echo "<br><br><form method=\"post\" action=\"setup.php\">";
			echo "<input name=\"step\" type=\"hidden\" value=\"1\">";
			echo "<input type=\"submit\" value=\"Continue setup\"></form>";
		}
	
		else if ($step == 1 && $error == "" && $connect || $step == 2 && $missing_data == "y")
		{
			echo "<h3>Step 2: Create administrator account</h3>\n";
			echo "<p>A connection to the NCD database was succesfully established!</p>\n<p>The next step is to add an administrator to control the NCD toolkit. Administrators have full control over all records on the database and also can add, update or delete users. The user name in this form is used to log in, the real name is used in email correspondence. Additional administrators and users can be created later with the user management system, which will also allow you to create user groups. User groups control the privileges users have to edit records created by other users: only users in the same user group can edit each others records. For now there is only a single user group labelled 'General', to which the main administrator will be added. You can use the user management system later to rename this group.<br><br></p>\n";
	
			echo "<form method=\"post\" action=\"setup.php\"><table>";
			if ($step == 2 && $new_user_name == "")
				$extra1a = "class=\"missing\"";
			if ($step == 2 && $user_exists == "y")
			{
				$extra1a = "class=\"missing\"";
				$extra1b = " <span class=\"error\">User name '$new_user_name' already exists!</span>";
			}
			echo "<tr><td class=\"label\">User name</td><td><input type=\"text\" name=\"new_user_name\" value=\"$new_user_name\" size=\"25\" $extra1a>$extra1b</td></tr>\n";
		
			if ($step == 2 && $new_user_password == "")
				$extra2= "class=\"missing\"";
			echo "<tr><td class=\"label\">Password</b></td><td><input type=\"password\" name=\"new_user_password\" value=\"$new_user_password\" size=\"25\" $extra2></td></tr>\n";
		
			if ($step == 2 && $new_user_real_name == "")
				$extra3 = "class=\"missing\"";
			echo "<tr><td class=\"label\">Real name</td><td><input type=\"text\" name=\"new_user_real_name\" value=\"$new_user_real_name\" size=\"25\" $extra3></td></tr>\n";
		
			if ($step == 2 && $new_user_email == "")
				$extra4 = "class=\"missing\"";
			echo "<tr><td class=\"label\">Email</td><td><input type=\"text\" name=\"new_user_email\" value=\"$new_user_email\" size=\"25\" $extra4></td></tr>\n";
		
			echo "<tr><td align=\"right\"></td><td height=\"50\">";
			echo "<input name=\"step\" type=\"hidden\" value=\"2\">";
			echo "<input type=\"submit\" value=\"Continue setup\">";
			echo "</td></tr>\n</table>\n</form>";
		}
		else if ($step == 2 && $missing_data != "y" || $step == 3 || ($_POST["language"] != "" && $_POST["language_setup_id"] == ""))
		{
			echo "<h3>Step 3: Select second language</h3>\n";
			if ($new_user_name != "" && $user_exists != "y")
			{
				$insert = "INSERT INTO Users (UserName, RealName, Password, Email, UserRoleID, UserGroupID)
						   VALUES ('$new_user_name', '$new_user_real_name', AES_ENCRYPT('$new_user_password','$password_key'), '$new_user_email', 1, 1)";
				mysql_query($insert);

				echo "<p><b>$new_user_real_name</b> (login name: $new_user_name) has been created.</b></p>\n";
				
				$_SESSION["username"] = $new_user_name;
				$_SESSION["userroleid"] = 1;
				$_SESSION["usergroupid"] = 1;
				$_SESSION["userid"] = mysql_insert_id();
				$_SESSION["realname"] = $new_user_real_name;
			}
	
			echo "<p>The data in the NCD toolkit is entered in English by default. The toolkit offers you to enter data in a second language as well. This could be useful e.g. if you want to present the collection data in a localized portal. This step in the setup offers you to select a second language. If you decide to choose a second language, be prepared to enter much of the data twice: in English and in the second language of choice. Please choose the second language carefully, as you will not be able to change it once you have set up the toolkit!</p><p>Please select a language from the menu below, which lists all individual living languages from the ISO standard. If the language of your choice is not present, please switch to the ISO 639-2 or the ISO 639-3 standards which cover a wider selection of languages. Select 'Select language' or 'No second language' to continue.";
			
			if ($_POST["language"] != "" && $_POST["language_setup_id"] == "")
				echo "</p><p class=\"error\">Please select a language from the menu or click 'No second language'.";
			
			echo "<br><br></p>\n";
	
	
			$checked1 = $checked2 = $checked3 = "";
			if ($iso == "" || $iso == 1)
			{
				$iso_query = "`ISO639-1`";
				$checked1 = "checked";
			}
			else if  ($iso == 2)
			{
				$iso_query = "`ISO639-2T`";
				$checked2 = "checked";
			}
			else
			{
				$iso_query = "`ISO639-3`";
				$checked3 = "checked";
			}
		
			$query = "SELECT `ISO639-3`, Language FROM Languages WHERE $iso_query != '' ORDER BY Language";
			$result = mysql_query($query);
		
			$language_menu = "<select name=\"language_setup_id\">\n<option value=\"\">Select second language...</option>\n";
			while ($row = mysql_fetch_array($result))
			{
				$language_id = $row[0];
				$language = $row[1];
				$language_menu .= "<option value=\"$language_id\">$language</option>\n";
			}
			$language_menu .= "</select>\n";
	
			echo "<form name=\"select_iso\" action=\"setup.php\" method=\"post\"><table border=\"0\">\n";
			echo "<tr><td>$language_menu</td>\n";
			echo "<td><input type=\"radio\" name=\"iso\" value=\"1\" $checked1 onchange=\"javascript:window.location.href='setup.php?iso=1&amp;step=3'\"></td>\n";
			echo "<td>ISO 639-1</td>\n";
			echo "<td><input type=\"radio\" name=\"iso\" value=\"2\" $checked2 onchange=\"javascript:window.location.href='setup.php?iso=2&amp;step=3'\"></td>\n";
			echo "<td>ISO 639-2</td>\n";
			echo "<td><input type=\"radio\" name=\"iso\" value=\"3\" $checked3 onchange=\"javascript:window.location.href='setup.php?iso=3&amp;step=3'\"></td>\n";
			echo "<td>ISO 639-3";
			echo "<input type=\"hidden\" name=\"step\" value=\"4\">";
			echo "<input type=\"hidden\" name=\"iso\" value=\"$iso\">";
			echo "<input type=\"hidden\" name=\"new_user_name\" value=\"$new_user_name\"></td></tr>\n";
			echo "<tr><td height=\"50\" class=\"bottom\" colspan=\"7\"><table><tr><td>";
			echo "<input type=\"submit\" name=\"language\" value=\"Select language\"></td><td>";
			echo "<td><input type=\"submit\" name=\"nolanguage\" value=\"No second language\"></td></tr>\n</table>\n</tr>\n</table>\n</form>";
		}
		else if ($step == 4)
		{
			echo "<h3>Step 4: Confirm second language</h3>\n";
			if ($_POST["language"] != "")	
			{
				$language_setup_id = $_POST["language_setup_id"];
				$_SESSION["setup_second_language"] = $language_setup_id;
				$result = mysql_query("SELECT Language from Languages WHERE `ISO639-3` LIKE '$language_setup_id'");
				$row = mysql_fetch_array($result);
				$language = $row[0];
				
				echo "<p><b>$language has been selected as the second language.</b></p>\n<p>".
					 "Click 'Edit language' if you want to change the second language or click ";
			}
			else if ($_POST["nolanguage"] != "")
			{
				$_SESSION["setup_second_language"] = "";
				$language_setup_id = "";
				echo "<p>English will the only language used in the NCD toolkit. Click ";
			}
			else {
				$language_setup_id = $_SESSION["setup_second_language"];
				if ($language_setup_id != "") {
					$result = mysql_query("SELECT Language from Languages WHERE `ISO639-3` LIKE '$language_setup_id'");
					$row = mysql_fetch_array($result);
					$language = $row[0];
				} else {
					$language = "English";
				}
				echo "<p>$language has been selected as the second language. ";
			}
			
			echo " 'Continue setup' to proceed to the last step of the NCD toolkit setup.<br><br></p><table><tr>";
			
			echo "<td><form method=\"post\" action=\"setup.php\">";
			echo "<input name=\"step\" type=\"hidden\" value=\"3\">";
			echo "<input name=\"iso\" type=\"hidden\" value=\"$iso\">";
			echo "<input name=\"language_setup_id\" type=\"hidden\" value=\"$language_setup_id\">";
			echo "<input type=\"submit\" value=\"Edit language\"></form></td>";

			echo "<td><form method=\"post\" action=\"setup.php\">";
			echo "<input name=\"step\" type=\"hidden\" value=\"5\">";
			echo "<input name=\"language_setup_id\" type=\"hidden\" value=\"$language_setup_id\">";
			echo "<input type=\"submit\" value=\"Continue setup\"></form>";
			echo "</td></tr>\n</table>\n";
		}
		else if ($step == 5)
		{
			echo "<h3>Step 5: Default rights texts</h3>\n";
			echo "<p>This last step offers you the option to enter default texts (in English) regarding rights of the collections you enter into the NCD toolkit. These concern general rights of a collection, access rights and usage restrictions. Entering default texts here saves you the effort of entering them on a per collection basis if they identical for each collection. Note that for each institution and collection these default texts can be adjusted or made more specific. You can leave the fields empty and enter the default texts at a later stage if necessary (Administrator tasks &gt; Update default right texts).</p>\n<p>Click 'Finish setup' to finialize the setup and to proceed to the main index.<br><br></p>\n";
			echo "<form action=\"../index.php\" method=\"post\"><table border=\"0\">\n";
			echo "<tr><td class=\"label\">Collection rights</td><td><textarea name=\"rights\" rows=\"8\" cols=\"50\"></textarea>".help("Rights")."</td></tr>\n";
			echo "<tr><td class=\"label\">Access rights</td><td><textarea name=\"access_rights\" rows=\"8\" cols=\"50\"></textarea>".help("AccessRights")."</td></tr>\n";
			echo "<tr><td class=\"label\">Usage restrictions</td><td><textarea name=\"usage_restrictions\" rows=\"8\" cols=\"50\"></textarea>".help("UsageRestrictions")."</td></tr>\n";
			echo "<tr><td height=\"50\" class=\"bottom\"></td>";
			echo "<td><input type=\"submit\" value=\"Finish setup\"></td></tr>\n</table>\n";
		}
	}
	else
		echo "<p>Setup has already been completed! <a href=\"../index.php\">Go to the main index</a>.</p>\n";
?>


</div>
</div>

<div id="menu">
<div id="navcontainer">
<ul id="navlist">
<?php echo "<li id=\"active\"><a href=\"setup.php?step=$step\">Setup</a></li>"; ?>
</ul>
</div>
</div>

</div>
<div id="footer"><?php include("../footer.inc.php"); ?></div>
</div>
<div id="infotextbox" style="visibility: hidden; left: 0px; top: 0px;"></div>
</body>
</html>
Return current item: NCD Toolkit