Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/database/perform/db_config_edit.php
<?php 
	error_reporting(0);
	/* @version $Revision: 1.4 $ */

	require_once('../../../include/init.inc');
	if(!$USER->check_feature('Admin') && !$USER->check_feature('ac_database'))
	{
		$USER->login_call();
	}

	include_once ('./common.php');
	$ERRORS	= array();
	@$CFG_REPETITIONS	= max (1,intval($CFG_REPETITIONS));

	if (file_exists('./db.cfg'))
	{
		$CONFIG = unserialize(implode('',file('./db.cfg')));
	}
	else
	{
		$CONFIG=array(	array	(	'CFG_DSN'			=>'',
									'CFG_USER_NAME'		=>'',
									'CFG_USER_PASS' 	=>'',
									'CFG_TABLESPACE' =>'',
									'CFG_DB_TYPE'		=>'',
									'CFG_STATEMENT'		=>'',
									'CFG_PROFILE'		=>'',
									'CFG_PERSISTENT'				=>'',
									'CFG_REPETITIONS'				=>'',
									'CFG_NAME'			=>''
								)
					 );
	}
	ksort($CONFIG);
	if (!empty($button_save) && !empty($CFG_NAME) && $CFG_NAME !='--install--')
	{
		foreach ($FIELDS as $idx => $data)	$CONFIG[ $CFG_NAME ][ $data ] = $$data;
		$file_content= serialize($CONFIG);
		$file = fopen ('./db.cfg','wb');
		if ($file)
		{
			fwrite($file,$file_content,strlen($file_content));
			fclose($file);
		}
		else
		{
			$ERRORS[]="Cannot write config file ./db.cfg ";
		}
	}

	if (!empty($button_load))
	{
		if ($button_load=='--install--')
		{
			$CFG_DB_TYPE	= $GLOBALS['sql_conf']['vendor'];
			$CFG_USER_NAME	= $GLOBALS['sql_conf']['uid'];
			$CFG_USER_PASS	= $GLOBALS['sql_conf']['pwd'];
			$CFG_TABLESPACE	= $GLOBALS['sql_conf']['sid'];
			$CFG_DSN		= $GLOBALS['sql_conf']['host'];
			$CFG_NAME		= '--install--';
			$CFG_PROFILE	= 1;
		}
		else
		{
			foreach ($FIELDS as $idx => $data)	$$data = 		$CONFIG[ $button_load ][ $data ] ;
		}
	}

	if (!empty($button_delete) && $CFG_NAME !='--install--')
	{
		unset($CONFIG[ $CFG_NAME ]);
		$file_content= serialize($CONFIG);
		@$file = fopen ('./db.cfg','wb');
		if ($file)
		{
			fwrite($file,$file_content,strlen($file_content));
			fclose($file);
		}
		else
		{
			$ERRORS[]="Cannot write config file ./db.cfg ";
		}
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>DB Config Editor</title>
</head>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
<font class="text">

	<table cellspacing="2" cellpading="2" border="1">
	<tr>
		<td class="title">
				Available profiles
		</td>
		<td class="title">
				Current profile
		</td>
	</tr>
	<tr>
			<form target="_self" >
		<td align="left" valign="top">
			<select class	="select"
					name	="button_load"
					onClick	="this.form.submit();"
					size	="30"
					>
				<option <?php if (empty($CFG_NAME)) echo 'selected'; ?> value=''> ---- NEW ---- </option>
				<option <?php if ($CFG_NAME =='--install--') echo 'selected'; ?> value='--install--'> -- INSTALL -- </option>

				<?php
				foreach ($CONFIG as $idx => $data)
				{
					if (empty($data['CFG_NAME'])) continue;
					$selected= ( $CFG_NAME== $data['CFG_NAME']?  'selected ' : '' );
					echo "<option $selected value='{$data['CFG_NAME']}'>{$data['CFG_NAME']}</option>";
				}
				?>
			</select>
		</td>
			</form>
		<td>
			<form target="db_test" >
			<table border="0" cellspacing="0" cellpadding="2">
				<tr>
					<td class="text">
						Profile name
					</td>
					<td class="text">
						<input type="text" name="CFG_NAME" value="<?php echo $CFG_NAME;?>" class="input">
					</td>
				</tr>
				<tr><td colspan="2"><hr></td></tr>
				<tr>
					<td class="text">
						DB Type
					</td>
					<td class="text">
						<select name="CFG_DB_TYPE" class="select" onChange="this.form.action = './db_'+(this.options[ this.selectedIndex ].value)+'.php';">
							<option value="" 		<?php if (empty($CFG_DB_TYPE)) 	 echo 'selected';  ?> ></option>
							<option value="mysql" 	<?php if ($CFG_DB_TYPE=='mysql') echo 'selected';  ?>>mySQL</option>
							<option value="odbc"	<?php if ($CFG_DB_TYPE=='odbc')  echo 'selected';  ?>>MSSQL via ODBC</option>
							<option value="mssql"	<?php if ($CFG_DB_TYPE=='mssql') echo 'selected';  ?>>MSSQL via PHP</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="text">
						Host / ODBC-ID
					</td>
					<td class="text">
						<input type="text" name="CFG_DSN" value="<?php echo $CFG_DSN;?>" class="input">
					</td>
				</tr>

				<tr>
					<td class="text">
						Tablespace
					</td>
					<td class="text">
						<input type="text" name="CFG_TABLESPACE" value="<?php echo $CFG_TABLESPACE;?>" class="input">
					</td>
				</tr>
				<tr>
					<td class="text">
						User name
					</td>
					<td class="text">
						<input type="text" name="CFG_USER_NAME" value="<?php echo $CFG_USER_NAME;?>" class="input">
					</td>
				</tr>
				<tr>
					<td class="text">
						User password
					</td>
					<td class="text">
						<input type="text" name="CFG_USER_PASS" value="<?php echo $CFG_USER_PASS;?>" class="input">
					</td>
				</tr>
				<tr>
					<td class="text">
						Persistent
					</td>
					<td class="text">
						<input class="radio" type="radio" <?php if (empty($CFG_PERSISTENT)) echo 'checked';  ?>  name="CFG_PERSISTENT" value="0"> NO
						<input class="radio" type="radio" <?php if (!empty($CFG_PERSISTENT)) echo 'checked'; ?> name="CFG_PERSISTENT" value="1"> YES
					</td>
				</tr>
				<tr><td colspan="2"><hr></td></tr>
				<tr>
					<td class="text" colspan="2">
						Statement
					</td>
				</tr>
				<tr>
					<td class="text" colspan="2">
						<textarea class="input" name="CFG_STATEMENT" rows="10" cols="80" ><?php echo htmlspecialchars($CFG_STATEMENT);?></textarea>
					</td>
				</tr>

				<tr>
					<td class="text">
						PROFILING
					</td>
					<td class="text">
						<input class="radio" type="radio" <?php if (empty($CFG_PROFILE)) echo 'checked';  ?> name="CFG_PROFILE" value="0"> NO
						<input class="radio" type="radio" <?php if (!empty($CFG_PROFILE)) echo 'checked'; ?> name="CFG_PROFILE" value="1"> YES
					</td>
				</tr>
				<tr>
					<td class="text">
						Repetitions
					</td>
					<td class="text">
						<input type="text" size="5" name="CFG_REPETITIONS" value="<?php echo $CFG_REPETITIONS;?>" class="input">
						<select class="select"
						onChange="this.form.elements['CFG_REPETITIONS'].value = (this.options[ this.selectedIndex ].value);">
							<option></option>
							<option value="10">10</option>
							<option value="50">50</option>
							<option value="100">100</option>
							<option value="500">500</option>
							<option value="1000">1000</option>
						</select>

					</td>
				</tr>
				<tr>
					<td class="text">
						Show results
					</td>
					<td class="text">
						<input class="radio" type="radio" <?php if (empty($SHOW_RESULT)) echo 'checked';  ?> name="SHOW_RESULT" value="0"> NO
						<input class="radio" type="radio" <?php if (!empty($SHOW_RESULT)) echo 'checked'; ?> name="SHOW_RESULT" value="1"> YES
					</td>
				</tr>
				<tr><td colspan="2"><hr></td></tr>
				<tr>
					<td class="text" colspan="2" align="center">
						<input type="button" 	name="button_clear" 	value="CLEAR" 	class="button" onClick="document.location.href='./db_config_edit.php';">
						<input type="submit" 	name="button_save" 		value="Save" 	class="button" onClick="this.form.action='./db_config_edit.php';">
						<input type="submit" 	name="button_delete"	onClick="return confirm('You really want to delete this profile ?');" value="Delete" 	class="button">
						<input type="button" 	name="button_use" 		value="Use" class="button" onClick="this.form.target='db_select';this.form.action='./db_select.php';this.form.submit();document.location.href='./empty.html';">
					</td>
				</tr>

			</table>
			</form>
		</td>
	</tr>
<?php
if (!empty($ERRORS))
{
	?>
		<tr>
			<td colspan="2">
			<?php
				foreach ($ERRORS as $idx => $data)
				{
					echo "<font class='error'>ERROR : $data </font><br>";
				}
			?>
			</td>
		</tr>
	<?php
}
?>
	</table>

</font>
</body>
</html>
Return current item: Netautor Professional