Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php admin interface help needed

Status
Not open for further replies.

may1hem

Programmer
Joined
Jul 28, 2002
Messages
262
Location
GB
Hi,

I would need some help here. I have this code here which is supposed to be an administrator interface to manage the stored data in MySql db. It does display the right data from the right tables, but when it comes to edit the "pods" for example it doesn't respond, it displays the "page" interface for editing. Can you please help me?

I have copied the whole page here.


<?

// --------------------------------------------------------------------------
// Set error reporting
// --------------------------------------------------------------------------
error_reporting(E_ALL ^ E_NOTICE);

// --------------------------------------------------------------------------
// Globals
// --------------------------------------------------------------------------
global $rootpath, $basepath, $user, $currentlocale;

// --------------------------------------------------------------------------
// Establish root path and script name
// --------------------------------------------------------------------------
$rootpath = realpath("..");
$basepath = ' . $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_PORT'] != '80') {
$basepath .= ':' . $_SERVER['SERVER_PORT'];
}

// --------------------------------------------------------------------------
// Reset the search path
// --------------------------------------------------------------------------
ini_set('include_path', $rootpath);

// --------------------------------------------------------------------------
// Include configuration
// --------------------------------------------------------------------------
require_once 'config.php';

// --------------------------------------------------------------------------
// Start the session
// --------------------------------------------------------------------------
session_start();

// --------------------------------------------------------------------------
// Connect to the database
// --------------------------------------------------------------------------
$edb = new EDb();
$edb->Connect();

// --------------------------------------------------------------------------
// Get admin user from session
// --------------------------------------------------------------------------
$user = $_SESSION['adminuser'];
if ( !isset( $user ) ) {
$user = new EUser( 'GB' );
$_SESSION['adminuser'] = $user;
}

// --------------------------------------------------------------------------
// Get current mode from session.
// Modes are:
// 'languages'
// 'countries'
// 'regionlanguages'
// 'layouts'
// 'pages'
// 'pods'
// 'images'
// 'users'
// 'atoz'
// --------------------------------------------------------------------------
$mode = $_GET['m'];
if (isset($mode)) {
$_SESSION['mode'] = $mode;
} else {
$mode = $_SESSION['mode'];
if ( !isset( $mode ) ) {
$mode = 'pages';
$_SESSION['mode'] = $mode;
}
}
$submode = $_GET['sm'];
if ($submode=='') {
$submode = $_POST['sm'];
}
if (isset($submode)) {
$_SESSION['submode'] = $submode;
} else {
$submode = $_SESSION['submode'];
if ( !isset( $submode ) ) {
$submode = 'list';
$_SESSION['submode'] = $submode;
}
}

// ==========================================================================
// Perform any page actions
// ==========================================================================
$action = $_GET['a'];
if ($action == '') {
$action = $_POST['a'];
}
$formErrors = '';
if ($action != '') {
switch ( $action ) {
case 'login':
// ------------------------------------------------------------------
// LOGIN
// ------------------------------------------------------------------
$email = $_POST['email'];
$password = $_POST['password'];
if ( $user->Validate( $email, $password ) == false ) {
$formErrors = $user->GetLastError();
} else {
$_SESSION['adminuser'] = $user;
}
break;
case 'logout':
// ------------------------------------------------------------------
// LOGOUT
// ------------------------------------------------------------------
$user->m_loggedin = false;
$_SESSION['adminuser'] = $user;
break;
}
}

// ------------------------------------------------------------------
// Columns
// ------------------------------------------------------------------
$columns = Array(
//'atoz' => Array(
//'c_region' => Array('heading'=>'Region', 'show'=>false, 'sortable'=>true),
//'c_language' => Array('heading'=>'Language', 'show'=>false, 'sortable'=>true),
//'c_label' => Array('heading'=>'Label', 'show'=>false, 'sortable'=>true),
//'c_page' => Array('heading'=>'Page', 'show'=>false, 'sortable'=>true),
//'KEYS' => Array('c_region','c_language','c_label'),
//),
//'countries' => Array(
//'c_code' => Array('heading'=>'Code', 'show'=>false, 'sortable'=>true),
//'c_name' => Array('heading'=>'Name', 'show'=>false, 'sortable'=>true),
//'KEYS' => Array('c_code'),
//),
//'images' => Array(
//'c_id' => Array('heading'=>'Id', 'show'=>true, 'sortable'=>true),
//'c_name' => Array('heading'=>'Name', 'show'=>true, 'sortable'=>true),
//'c_alt' => Array('heading'=>'Alt', 'show'=>true, 'sortable'=>true),
//'KEYS' => Array('c_id'),
//),
//'languages' => Array(
//'c_code' => Array('heading'=>'Code', 'show'=>false, 'sortable'=>true),
//'c_name' => Array('heading'=>'Name', 'show'=>false, 'sortable'=>true),
//'KEYS' => Array('c_code'),
//),
'layouts' => Array(
'c_name' => Array('heading'=>'Name', 'show'=>true, 'sortable'=>true),
'c_layout' => Array('heading'=>'Layout', 'show'=>true, 'sortable'=>true),
'KEYS' => Array('c_name'),
),
'pages' => Array(
'c_name' => Array('heading'=>'Name', 'show'=>true, 'sortable'=>true),
'c_region' => Array('heading'=>'Region', 'show'=>false, 'sortable'=>false),
'c_lang' => Array('heading'=>'Lang', 'show'=>false, 'sortable'=>false),
'c_title' => Array('heading'=>'Title', 'show'=>true, 'sortable'=>true),
'c_layout' => Array('heading'=>'Layout', 'show'=>true, 'sortable'=>true),
'c_pod1' => Array('heading'=>'Pod1', 'show'=>false, 'sortable'=>true),
'c_pod2' => Array('heading'=>'Pod2', 'show'=>false, 'sortable'=>true),
'c_pod3' => Array('heading'=>'Pod3', 'show'=>false, 'sortable'=>true),
'c_pod4' => Array('heading'=>'Pod4', 'show'=>false, 'sortable'=>true),
'c_pod5' => Array('heading'=>'Pod5', 'show'=>false, 'sortable'=>true),
'c_pod6' => Array('heading'=>'Pod6', 'show'=>false, 'sortable'=>true),
'c_pod7' => Array('heading'=>'Pod7', 'show'=>false, 'sortable'=>true),
'c_pod8' => Array('heading'=>'Pod8', 'show'=>false, 'sortable'=>true),
'c_pod9' => Array('heading'=>'Pod9', 'show'=>false, 'sortable'=>true),
'KEYS' => Array('c_name','c_region'),
),
'pods' => Array(
'c_name' => Array('heading'=>'Name', 'show'=>true, 'sortable'=>true),
'c_type' => Array('heading'=>'Type', 'show'=>true, 'sortable'=>true),
'c_content' => Array('heading'=>'Content', 'show'=>false, 'sortable'=>true),
'KEYS' => Array('c_name'),
),
//'regionlanguages' => Array(
//'c_name' => Array('heading'=>'Name', 'show'=>false, 'sortable'=>true),
//'c_active' => Array('heading'=>'Active', 'show'=>false, 'sortable'=>true),
//'c_region' => Array('heading'=>'Region', 'show'=>false, 'sortable'=>true),
//'c_language' => Array('heading'=>'Language', 'show'=>false, 'sortable'=>true),
//'KEYS' => Array('c_name'),
//),
'users' => Array(
),
);

//echo '$submode==['.$submode.']<br />';
//print_r_ln($_POST);
if ($submode == 'edit') {
$id = $_GET['id'];
// echo '$id==['.$id.']<br />';
$parts = split('\^', $id);
// print_r_ln($parts);
$where = Array();
foreach ($parts as $part) {
$bits = split('@',$part);
// print_r_ln($bits);
$where[] = $bits[0] . ' = \'' . $bits[1] . '\'';
}
$whereclause = join(' and ', $where);
// echo '['.$whereclause.']';
$sql = 'select * from '.$mode.' where '.$whereclause;
$rows = $edb->Read($sql);
// print_r_ln($rows);
$row = $rows[0];
if ($mode == 'atoz') {
$c_region = $row['c_region'];
$c_language = $row['c_language'];
$c_label = $row['c_label'];
$c_page = $row['c_page'];
} elseif ($mode == 'countries') {
$c_code = $row['c_code'];
$c_name = $row['c_name'];
} elseif ($mode == 'images') {
$c_id = $row['c_id'];
$c_name = $row['c_name'];
$c_alt = $row['c_alt'];
} elseif ($mode == 'languages') {
$c_code = $row['c_code'];
$c_name = $row['c_name'];
} elseif ($mode == 'layouts') {
$c_layout = $row['c_layout'];
$c_name = $row['c_name'];
} elseif ($mode == 'pages') {
$c_name = $row['c_name'];
$c_region = $row['c_region'];
$c_language = $row['c_lang'];
$c_title = $row['c_title'];
$c_layout = $row['c_layout'];
$c_pod1 = $row['c_pod1'];
$c_pod2 = $row['c_pod2'];
$c_pod3 = $row['c_pod3'];
$c_pod4 = $row['c_pod4'];
$c_pod5 = $row['c_pod5'];
$c_pod6 = $row['c_pod6'];
$c_pod7 = $row['c_pod7'];
$c_pod8 = $row['c_pod8'];
$c_pod9 = $row['c_pod9'];
} elseif ($mode == 'pods') {
$c_name = $row['c_name'];
$c_type = $row['c_type'];
$c_content = $row['c_content'];
} elseif ($mode == 'regionlanguages') {
$c_name = $row['c_name'];
$c_active = $row['c_active'];
$c_region = $row['c_region'];
$c_language = $row['c_language'];
} elseif ($mode == 'users') {
}
} else if ($submode == 'update' || $submode == 'new' || $submode == 'delete') {
// --------------------------------------------------------------------------
// Automatically snarf the form variables
// --------------------------------------------------------------------------
$keys = $columns[$mode]['KEYS'];
//print_r_ln($keys);
$c_code = $_POST['c_code'];
$c_name = $_POST['c_name'];
$c_id = $_POST['c_id'];
$c_region = $_POST['c_region'];
$c_language = $_POST['c_language'];
$c_label = $_POST['c_label'];
$c_page = $_POST['c_page'];
$c_alt = $_POST['c_alt'];
$c_layout = $_POST['c_layout'];
$c_title = $_POST['c_title'];
$c_layout = $_POST['c_layout'];
$c_pod1 = $_POST['c_pod1'];
$c_pod2 = $_POST['c_pod2'];
$c_pod3 = $_POST['c_pod3'];
$c_pod4 = $_POST['c_pod4'];
$c_pod5 = $_POST['c_pod5'];
$c_pod6 = $_POST['c_pod6'];
$c_pod7 = $_POST['c_pod7'];
$c_pod8 = $_POST['c_pod8'];
$c_pod9 = $_POST['c_pod9'];
$c_type = $_POST['c_type'];
$c_content = $_POST['c_content'];
$c_active = $_POST['c_active'];
$keys = $columns[$mode]['KEYS'];
// print_r_ln($keys);
if ($submode == 'delete') {
$id = $_GET['id'];
// echo '$id==['.$id.']<br />';
$parts = split('\^', $id);
$where = Array();
foreach ($parts as $part) {
$bits = split('@',$part);
$where[] = $bits[0] . ' = \'' . $bits[1] . '\'';
}
$whereclause = join(' and ', $where);
$sql = 'delete from '.$mode.' where '.$whereclause;
}

elseif ($submode == 'new') {
$sql = 'insert into '.$mode.' (';
$cols = Array();
foreach ($columns[$mode] as $key => $value) {
if ($key != 'KEYS') {
$cols[] = $key;
}
}
$sql .= join(',', $cols) . ') values (';
if ($mode == 'atoz') {
$sql .=
'\''.$c_region.'\', '."\n".
'\''.$c_language.'\', '."\n".
'\''.$c_label.'\', '."\n".
'\''.$c_page.'\' '."\n".
'';
} elseif ($mode == 'countries') {
$sql .=
'\''.$c_code.'\', '."\n".
'\''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'images') {
$sql .=
'\''.$c_name.'\', '."\n".
'\''.$c_alt.'\' '."\n".
'';
} elseif ($mode == 'languages') {
$sql .=
'\''.$c_code.'\', '."\n".
'\''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'layouts') {
$sql .=
'\''.$c_layout.'\', '."\n".
'\''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'pages') {
$sql .=
'\''.$c_name.'\', '."\n".
'\''.$c_region.'\', '."\n".
'\''.$c_language.'\', '."\n".
'\''.$c_title.'\', '."\n".
'\''.$c_layout.'\', '."\n".
'\''.$c_pod1.'\', '."\n".
'\''.$c_pod2.'\', '."\n".
'\''.$c_pod3.'\', '."\n".
'\''.$c_pod4.'\', '."\n".
'\''.$c_pod5.'\', '."\n".
'\''.$c_pod6.'\', '."\n".
'\''.$c_pod7.'\', '."\n".
'\''.$c_pod8.'\', '."\n".
'\''.$c_pod9.'\' '."\n".
'';
} elseif ($mode == 'pods') {
$sql .=
'\''.$c_name.'\', '."\n".
'\''.$c_type.'\', '."\n".
'\''.$c_content.'\' '."\n".
'';
} elseif ($mode == 'regionlanguages') {
$sql .=
'\''.$c_name.'\', '."\n".
'\''.$c_active.'\', '."\n".
'\''.$c_region.'\', '."\n".
'\''.$c_language.'\' '."\n".
'';
} elseif ($mode == 'users') {
}
$sql .= ')';
} else {
if ($mode == 'atoz') {
$sql =
'update '.$mode.' set '."\n".
'c_region = \''.$c_region.'\', '."\n".
'c_language = \''.$c_language.'\', '."\n".
'c_label = \''.$c_label.'\', '."\n".
'c_page = \''.$c_page.'\' '."\n".
'where c_region = \''.$c_region.'\' '."\n".
'and c_language = \''.$c_language.'\' '."\n".
'and c_label = \''.$c_label.'\' '."\n".
'and c_page = \''.$c_page.'\' '."\n".
'';
} elseif ($mode == 'countries') {
$sql =
'update '.$mode.' set '."\n".
'c_code = \''.$c_code.'\', '."\n".
'c_name = \''.$c_name.'\' '."\n".
'where c_code = \''.$c_code.'\' '."\n".
'';
} elseif ($mode == 'images') {
$sql =
'update '.$mode.' set '."\n".
'c_name = \''.$c_name.'\', '."\n".
'c_alt = \''.$c_alt.'\' '."\n".
'where c_id = \''.$c_id.'\' '."\n".
'';
} elseif ($mode == 'languages') {
$sql =
'update '.$mode.' set '."\n".
'c_code = \''.$c_code.'\', '."\n".
'c_name = \''.$c_name.'\' '."\n".
'where c_code = \''.$c_code.'\' '."\n".
'';
} elseif ($mode == 'layouts') {
$sql =
'update '.$mode.' set '."\n".
'c_layout = \''.$c_layout.'\', '."\n".
'c_name = \''.$c_name.'\' '."\n".
'where c_layout = \''.$c_layout.'\' '."\n".
'';
} elseif ($mode == 'pages') {
$sql =
'update '.$mode.' set '."\n".
'c_name = \''.$c_name.'\', '."\n".
'c_region = \''.$c_region.'\', '."\n".
'c_language = \''.$c_language.'\', '."\n".
'c_title = \''.$c_title.'\', '."\n".
'c_layout = \''.$c_layout.'\', '."\n".
'c_pod1 = \''.$c_pod1.'\', '."\n".
'c_pod2 = \''.$c_pod2.'\', '."\n".
'c_pod3 = \''.$c_pod3.'\', '."\n".
'c_pod4 = \''.$c_pod4.'\', '."\n".
'c_pod5 = \''.$c_pod5.'\', '."\n".
'c_pod6 = \''.$c_pod6.'\', '."\n".
'c_pod7 = \''.$c_pod7.'\', '."\n".
'c_pod8 = \''.$c_pod8.'\', '."\n".
'c_pod9 = \''.$c_pod9.'\' '."\n".
'where c_name = \''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'pods') {
$sql =
'update '.$mode.' set '."\n".
'c_name = \''.$c_name.'\', '."\n".
'c_type = \''.$c_type.'\', '."\n".
'c_content = \''.$c_content.'\' '."\n".
'where c_name = \''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'regionlanguages') {
$sql =
'update '.$mode.' set '."\n".
'c_name = \''.$c_name.'\', '."\n".
'c_active = \''.$c_active.'\', '."\n".
'c_region = \''.$c_region.'\', '."\n".
'c_language = \''.$c_language.'\' '."\n".
'where c_name = \''.$c_name.'\' '."\n".
'';
} elseif ($mode == 'users') {
}
}
// echo '<code><pre>$sql==['.$sql.']</pre></code>';
$edb->Execute($sql);
$submode = 'list';
}

// ==========================================================================
// Minor functions
// ==========================================================================
function dumpServerVariables() {
?><table border="1"><?
foreach ($_SERVER as $key => $value) {
?><tr>
<td><?=$key?></td>
<td><?=$value?></td>
</tr><?
}
?></table><?
}
function print_r_ln( $value='') {
echo '<code><pre>';
print_r($value);
echo '</pre></code>';
}
function codeln( $value = '' ) {
?><code><pre><?=$value?></pre></code><?
}
function errorln( $value = '') {
?><table cellpadding="5" cellspacing="0" border="1" style="border:1px solid yellow;" bgcolor="#79A9A9" align="center">
<tr>
<td align="center" style="color:#ffffff;"><b>A system error has occurred</b><br />
Please note these details and contact our customer support.<br />
<?=codeln( $value )?>
</tr>
</table><?
}

function boxOff( $msg='', $mode='' ) {
return
'<table width="94" height="20" cellpadding="0" cellspacing="0" border="0" style="border:1px solid black" bgcolor="#79A9A9">'.
'<tr>'.
'<td align="center" valign="middle" '.
'class="menubox" '.
'onMouseover="this.className=\'menuboxhover\';" '.
'onMouseout="this.className=\'menubox\';" '.
'>'.
($mode!='' ? '<span onclick="location.href=\'a.php?sm=list&m='.$mode.'\'" '.
'class="menubox" '.
'onMouseover="this.className=\'menuboxhover\';" '.
'onMouseout="this.className=\'menubox\';" '.
'>' : '').
$msg.
($mode!='' ? '</span>' : '').
'</td>'.
'</tr>'.
'</table>';
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<base href="<?=$basepath?>">
<title>Admin</title>
<link rel="stylesheet" href="_inc/e_1.css" type="text/css" />
<style>
.thead {
font-family:Verdana;
font-size:11px;
color:#333333;
font-weight:bold;
cursor:hand;
background-color:#cccccc;
}
.tbox {
border: 1px solid #cccccc;
}
a:hover {
font-family:Verdana,Arial;
font-size:10px;
color:#0000ff;
font-weight:bold;
text-decoration:underline;
}
a {
font-family:Verdana,Arial;
font-size:10px;
color:#0000ff;
font-weight:bold;
text-decoration:underline;
}
h1 {
height: 15px;
font-family:Verdana;
font-size:12px;
color:#333333;
font-weight:bold;
cursor:hand;
background-color:#cccccc;
}
.button {
height: 20px;
background-color: #cccccc;
border-width: 2px;
border-style: solid;
border-top-color: #8888ee;
border-left-color: #8888ee;
border-bottom-color: #4444aa;
border-right-color: #4444aa;
padding-top: 1px;
padding-bottom: 2px;
padding-right: 5px;
padding-left: 5px;
color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: none;
}
</style>
</head>
<body>
<table width="780" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="700" height="83" valign="top"><table width="780" height="83" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#79A9A9">
<?
global $user, $formErrors;
if ( !$user->IsLoggedIn() ) {
?><form name="login" method="post" action="_a/a.php">
<input type="hidden" name="a" value="login" />
<tr>
<td width="10" rowspan="2" valign="bottom"><img src="_img/s.gif" width="17" height="1"></td>
<td height="68" valign="bottom"><a href="page.php?p=index"><img src="images/t.gif" width="149" height="28" border="0" /></a></td>
<td width="378" rowspan="2" align="right" valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#79A9A9">
<tr>
<td height="35" colspan="5">&nbsp;</td>
</tr>
<tr>
<td width="119" align="right" valign="bottom"><img src="_img/login.gif" width="63" height="21"></td>
<td width="124" align="right"><input class="text" value="Email" name="email" /></td>
<td width="14"><img src="_img/s.gif" width=14 height="9"></td>
<td width="100" align="right"><input class="text" style="width:100px;" type="password" value="Password" name="password" /></td>
<td width="20"><img src="_img/s.gif" width="20" height="7"></td>
</tr>
<? } else { ?>
<form name="logout" method="post" action="_a/a.php">
<input type="hidden" name="a" value="logout" />
<tr>
<td width="10" rowspan="2" valign="bottom"><img src="_img/s.gif" width="17" height="1"></td>
<td height="68" valign="bottom"><a href="page.php?p=index"><img src="images/t.gif" width="149" height="28" border="0" /></a></td>
<td width="378" rowspan="2" align="right" valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#79A9A9">
<tr>
<td align="right" height="35" colspan="5">&nbsp;<font color="white"><?=$user->m_fullname?></font></td>
</tr>
<tr>
<td align="right" valign="bottom" colspan="5"><img src="_img/logout.gif" width="70" height="21"></td>
</tr>
<? } ?>
<? if ( $formErrors != '' ) { ?>
<tr>
<td colspan="5" align="right"><font color="white"><b><?=$formErrors?></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
</tr>
<? } ?>
</table>
<img src="_img/s.gif" width="1" height="15"></td>
<td width="21" rowspan="2" valign="bottom"><img src="_img/button1.gif" width="21" height="19" onclick="return submit();" ><img src="_img/s.gif" width="1" height="17"></td>
<td width="24" rowspan="2" align="right" valign="bottom"><img src="_img/s.gif" width="24" height="1"></td>
</tr>
<tr>
<td><img src="_img/s.gif" width="1" height="10"></td>
</tr>
</form>
</table></td>
</tr>
</table>

<table width="780" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="23" valign="top" align="center"><table width="780" border="0" align="center" cellpadding="0" cellspacing="0" id="Table1">
<tr>
<td colspan="9" valign="bottom"><img src="_img/s.gif" width="1" height="3"></td>
</tr>
<tr>
<td width="94" height="19" valign="bottom"><?=boxOff('Pages','pages')?></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"><?=boxOff('Pods','pods')?></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"><?=boxOff('Users','users')?></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"></td>
<td width="3" valign="bottom"><img src="_img/s.gif" width="3" height="1"></td>
<td width="94" valign="bottom"></td>
</tr>
</table></td>
</tr>
</table>


<?
// ------------------------------------------------------------------
// Headings for each mode
// ------------------------------------------------------------------
$headings = Array(
//'atoz' => '<b>Administration</b> - A to Z Guide',
//'countries' => '<b>Administration</b> - Countries',
//'images' => '<b>Administration</b> - Images',
//'languages' => '<b>Administration</b> - Languages',
//'layouts' => '<b>Administration</b> - Layouts',
'pages' => '<b>Administration</b> - Pages',
'pods' => '<b>Administration</b> - Pods',
//'regionlanguages' => '<b>Administration</b> - Region/Languages',
'users' => '<b>Administration</b> - Users',
);


// ------------------------------------------------------------------
// Test for not logged in or session timeout
// ------------------------------------------------------------------
if (!$user->IsLoggedIn()) {
$heading = 'Administration';
$input = 'x';
$listing = 'x';
$preview = 'x';
} elseif ($submode == 'list') {
// ==================================================================
// Build listing screen
// ==================================================================
// ------------------------------------------------------------------
// Get count of records for table
// ------------------------------------------------------------------
$rows = $edb->Read('select count(*) as cnt from ' . $mode);
$pcount = (int)$rows[0]['cnt'];
// ------------------------------------------------------------------
// Get order by if required
// ------------------------------------------------------------------
$orderby = $_GET['ob'];
$ob = $orderby;
// echo '$submode==['.$submode.']';
// echo '$mode==['.$mode.']';
// print_r_ln($columns[$mode]);
if (!isset($orderby)) {
$allkeys = array_keys($columns[$mode]);
$orderby = 'order by '.$allkeys[0];
} else {
$orderby = 'order by '.$orderby;
}
// ------------------------------------------------------------------
// Get next page in grid
// ------------------------------------------------------------------
$npage = $_GET['np'];
if ($npage == '') {
$npage = 0;
}
$npage = (int)$npage;
if (($npage * 15) < 0 || ($npage * 15) > $pcount) {
$npage = 0;
}
$sql = 'select * from '.$mode.' '.$orderby.' limit '.($npage*15).',15';
// echo '['.$sql.']';
$rows = $edb->Read($sql);
$listing =
'<center><h1>'.$headings[$mode].' - Listing</h1></center>'.
'<script language="javascript">'."\n".
'function confirmdelete() {'."\n".
' if (confirm("Deleting things is not recommended. Are you sure?")) {'."\n".
' return true;'."\n".
' }'."\n".
' return false;'."\n".
'}'."\n".
'</script>'.
'<table width="100%" cellpading="0" cellspacing="0" class="tbox">'.
'<tr>'.
'<td class="thead">Action</td>';
$cols = $columns[$mode];
// print_r_ln($columns);
foreach ($cols as $key => $value) {
if ($key != 'KEYS' && $value['show']) {
$listing .= '<td class="thead">';
if ($value['sortable']) {
$listing .= '<a href="_a/a.php?np='.$npage.'&ob='.$key.'&m='.$mode.'">';
}
$listing .= $value['heading'];
if ($value['sortable']) {
$listing .= '</a>';
}
$listing .= '</td>';
}
}
$listing .= '</tr>';
$keys = $cols['KEYS'];
foreach ($rows as $row) {
$href_id = '';
foreach ($keys as $key) {
$href_id .= $key . '@' . $row[$key] . '^';
}
$href_id = substr($href_id, 0, strlen($href_id)-1);
$listing .=
'<tr>'.
'<td>'.
'<a href="_a/a.php?sm=delete&id='.$href_id.'" onclick="return confirmdelete();">delete</a>'.
'&nbsp;&nbsp;'.
'<a href="_a/a.php?sm=edit&id='.$href_id.'">edit</a>'.
'</td>';
foreach ($cols as $key => $value) {
if ($key != 'KEYS' && $value['show']) {
$content = '';
if ($value['truncate']>0) {
$content .= substr($row[$key],0,$value['truncate']);;
} else {
$content .= $row[$key];
}
$listing .=
'<td>'.
$content.
'</td>';
}
}
$listing .= '</tr>';
}
$listing .= '</table>';
if ($pcount > 0) {
$listing .= '<table width="100%" cellpading="0" cellspacing="0" xclass="tbox"><tr>';
$listing .= '<td><a href="_a/a.php?sm=create">Create NEW entry</a></td>';
$listing .= '<td width="70%" align="right">Page:&nbsp;</td>';
$listing .= '<td>';
if ($npage > 0) {
$listing .= '<a href="_a/a.php?np='.($npage-1).($ob!='' ? '&ob='.$ob : '').'&m='.$mode.'">&lt;&lt;</a>&nbsp';
}
for ($i=0; $i<($pcount/15); $i++) {
$listing .= '<a href="_a/a.php?np='.$i.($ob!='' ? '&ob='.$ob : '').'&m='.$mode.'">['.($i+1).']</a>&nbsp;';
}
if ($npage < $pcount) {
$listing .= '<a href="_a/a.php?np='.($npage+1).($ob!='' ? '&ob='.$ob : '').'&m='.$mode.'">&gt;&gt;</a>&nbsp';
}
$listing .= '</td>';
$listing .= '</td></tr></table>';
}
} else {
// ==================================================================
// Now build input screen
// ==================================================================
$input =
'<center><h1>'.$headings[$mode].' - '.$submode.'</h1></center>'.
'<table width="100%" cellpading="0" cellspacing="0" class="tbox">'.
'<form name="input" method="post" action="_a/a.php">'.
'<input type="hidden" name="sm" value="'.($submode=='create'?'new':'update').'" />'.
'<tr>'.
'';
$cols = $columns[$mode];
// print_r_ln($columns);
if ($mode == 'atoz') {
// --------------------------------------------------------------
// ATOZ
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Region</td>'.
'<td><select name="c_region">';
$rows = $edb->Read('select * from regions order by c_name');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_region ? 'selected' : '').'>'.$row['c_name'].'</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Language</td>'.
'<td><select name="c_language">';
$rows = $edb->Read('select * from languages order by c_name');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_language ? 'selected' : '').'>'.$row['c_name'].'</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Label</td>'.
'<td><input type="text" name="c_label" size="48" maxlength="255" value="'.$c_label.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Page</td>'.
'<td><select name="c_page">';
$rows = $edb->Read('select * from pages order by c_name');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_page ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_title'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'';
} elseif ($mode == 'countries') {
// --------------------------------------------------------------
// COUNTRIES
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Code</td>'.
'<td><input type="text" name="c_code" size="2" maxlength="2" value="'.$c_code.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="48" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'';
} elseif ($mode == 'images') {
// --------------------------------------------------------------
// IMAGES
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Id</td>'.
'<td>Auto-Generated</td>'.
'</tr>'.
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="32" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'<tr>'.
'<td>alt</td>'.
'<td><input type="text" name="c_alt" size="32" maxlength="255" value="'.$c_alt.'"></td>'.
'</tr>'.
'';
} elseif ($mode == 'languages') {
// --------------------------------------------------------------
// LANGUAGES
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Code</td>'.
'<td><input type="text" name="c_code" size="2" maxlength="2" value="'.$c_code.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="48" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'';
} elseif ($mode == 'layouts') {
// --------------------------------------------------------------
// LAYOUTS
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Layout</td>'.
'<td><input type="text" name="c_code" size="2" maxlength="2" value="'.$c_code.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="32" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'';
} elseif ($mode == 'pages') {
// --------------------------------------------------------------
// PAGES
// --------------------------------------------------------------
//$input .=

//'<tr>'.
//'<td>Region</td>'.
//'<td><select name="c_region">';
//$rows = $edb->Read('select * from regions order by c_name');
//foreach ($rows as $row) {
//$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_region ? 'selected' : '').'>'.$row['c_name'].'</option>';
//}
//$input .=
//'</select></td>'.
//'</tr>'.
//'<tr>'.
//'<td>Language</td>'.
//'<td><select name="c_language">';
//$rows = $edb->Read('select * from languages order by c_name');
//foreach ($rows as $row) {
//$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_language ? 'selected' : '').'>'.$row['c_name'].'</option>';
//}
$input .=
//'</select></td>'.
//'</tr>'.
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="24" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Title</td>'.
'<td><input type="text" name="c_title" size="48" maxlength="255" value="'.$c_title.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Layout</td>'.
'<td><select name="c_layout">';
for ($i=1; $i<12; $i++) {
$input .= '<option value="'.$i.'" '.($i==$c_layout ? 'selected' : '').'>'.$i.'</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod1</td>'.
'<td><select name="c_pod1">'.
'<option value="">-- no pod selected --</option>';
$rows = $edb->Read('select * from pods order by c_type,c_name');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod1 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod2</td>'.
'<td><select name="c_pod2">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod2 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod3</td>'.
'<td><select name="c_pod3">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod3 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod4</td>'.
'<td><select name="c_pod4">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod4 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod5</td>'.
'<td><select name="c_pod5">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod5 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod6</td>'.
'<td><select name="c_pod6">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod6 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod7</td>'.
'<td><select name="c_pod7">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod7 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod8</td>'.
'<td><select name="c_pod8">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod8 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Pod9</td>'.
'<td><select name="c_pod9">'.
'<option value="">-- no pod selected --</option>';
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_name'].'" '.($row['c_name']==$c_pod9 ? 'selected' : '').'>'.$row['c_name'].' ('.$row['c_type'].')</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'';
} elseif ($mode == 'pods') {
// --------------------------------------------------------------
// PODS
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="32" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Type</td>'.
'<td><select name="c_type">'.
'<option value="image" '.($c_type=='image' ? 'selected' : '').'>Image</option>'.
'<option value="background_img" '.($c_type=='background_img' ? 'selected' : '').'>BackgroundImage</option>'.
'<option value="text" '.($c_type=='text' ? 'selected' : '').'>Text</option>'.
'<option value="menubox1" '.($c_type=='menubox1' ? 'selected' : '').'>MenuBox</option>'.
'<option value="textbox" '.($c_type=='textbox' ? 'selected' : '').'>TextBox</option>'.
'<option value="stylesheet1" '.($c_type=='stylesheet1' ? 'selected' : '').'>Stylesheet1</option>'.
'</select></td>'.
'</tr>'.
'<tr>'.
'<td valign="top">Content</td>'.
'<td><textarea name="c_content" rows="15" cols="80">'.$c_content.'</textarea></td>'.
'</tr>'.
'';
} elseif ($mode == 'regionlanguages') {
// --------------------------------------------------------------
// REGIONLANGUAGES
// --------------------------------------------------------------
$input .=
'<tr>'.
'<td>Name</td>'.
'<td><input type="text" name="c_name" size="32" maxlength="255" value="'.$c_name.'"></td>'.
'</tr>'.
'<tr>'.
'<td>Active</td>'.
'<td><select name="c_active">'.
'<option value="T" '.($c_active=='T' ? 'selected' : '').'>True</option>'.
'<option value="F" '.($c_active=='F' ? 'selected' : '').'>False</option>'.
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Region</td>'.
'<td><select name="c_region">';
$rows = $edb->Read('select * from regions order by c_code');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_region ? 'selected' : '').'>'.$row['c_name'].'</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'<tr>'.
'<td>Language</td>'.
'<td><select name="c_language">';
$rows = $edb->Read('select * from languages order by c_name');
foreach ($rows as $row) {
$input .= '<option value="'.$row['c_code'].'" '.($row['c_code']==$c_language ? 'selected' : '').'>'.$row['c_name'].'</option>';
}
$input .=
'</select></td>'.
'</tr>'.
'';
} elseif ($mode == 'users') {
}
$input .=
'</tr>'.
'<tr>'.
'<td colspan="2" align="center">'.
'<input type="submit" value="'.($submode=='edit' ? 'Update' : 'Create').'" class="button" />'.
'&nbsp;&nbsp;'.
'<input type="button" value="Cancel" onclick="location.href=\'a.php?sm=list\'" class="button" />'.
'</td>'.
'</tr>'.
'</form>'.
'</table>';
}
// ==================================================================
// Now do replacements and display
// ==================================================================
if ($submode == 'list') {
$filename = $rootpath . "/_a/a_listing_template.htm";
} else {
$filename = $rootpath . "/_a/a_input_template.htm";
}
if ( !file_exists( $filename ) ) {
return errorln( 'Unable to load file ' . $filename );
} else {
$html = file_get_contents($filename);
if (!$user->IsLoggedIn()) {
$html = str_replace('
', '<b>Administration</b>', $html);
$html = str_replace('[LISTING]', '<b><font color="red">YOU MUST BE LOGGED IN TO USE THE ADMINISTRATION INTERFACE</font></b>', $html);
$html = str_replace('[PREVIEW]', 'No data', $html);
$html = str_replace('[INPUT]', '<b><font color="red">YOU MUST BE LOGGED IN TO USE THE ADMINISTRATION INTERFACE</font></b>', $html);
} else {
$html = str_replace('
', $headings[$mode], $html);
$html = str_replace('[LISTING]', $listing, $html);
$html = str_replace('[PREVIEW]', $preview, $html);
$html = str_replace('[INPUT]', $input, $html);
}
}
echo $html;
?>




<table width="780" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="94%" height="83" valign="top" align="center"><table cellspacing="0" cellpadding="0" width="755" border="0" id="Table1">
<tr>
<td><img height="7" src="_img/s.gif" width="755"></td>
<tr>
<td><img height="1" src="_img/pointilles.gif" width="755"></td>
<tr>
<td><img height="7" src="_img/s.gif" width="755"></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="755" border="0" id="Table2">
<tr>
<td align="left"><font class="copy"></font></td>
<td width="3"><img height="1" src="_img/s.gif" width="3"></td>
<td align="right"></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="755" border="0" id="Table3">
<tr>
<td width="10"><img height="1" src="_img/s.gif" width="10"></td>
<td width="145"><font class="copy"><?=$rights_msg?></font></td>
<td align="right" width="600"></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="755" border="0" id="Table4">
<tr>
<td height="10">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>


</body>
</html>
<?
// --------------------------------------------------------------------------
// Disconnect to the database
// --------------------------------------------------------------------------
$edb->Disconnect();

?>​
 
I think the problem is somewhere here:

$mode = $_GET['m'];
if (isset($mode)) {
$_SESSION['mode'] = $mode;
} else {
$mode = $_SESSION['mode'];
if ( !isset( $mode ) ) {
$mode = 'pages';
$_SESSION['mode'] = $mode;
}
}
$submode = $_GET['sm'];
if ($submode=='') {
$submode = $_POST['sm'];
}
if (isset($submode)) {
$_SESSION['submode'] = $submode;
} else {
$submode = $_SESSION['submode'];
if ( !isset( $submode ) ) {
$submode = 'list';
$_SESSION['submode'] = $submode;
}
}


Can you see what it is?

Thanks
 
I certainly can't. I have no idea what the variables used in the code snippet are supposed to do or how this script is supposed to work.

And don't just throw 1100 lines of code at the forum and ask, "What's wrong?" You wrote the script -- you should be the one to debug it.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
it was 1089 lines, but I still agree with Sleipnir214, waaaaaay too much code, and waaay too vague on the error(s).






______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
You're right. I had to estimate the number of lines.

Considering that line 1089 cuts off in mid-statement, I suspect it would have been more had the site allowed it.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sorry for submitting this long script. I got a bit frustrated as this code was handed to me for debugging and thought maybe if I put the whole page in, someone would find it easier to see where the problem is. Anyway, I've learned from my mistake! Thanks for pointing it out.


 
mayhem1:

Please tell me that you weren't handed the code at work. I'd hate to think that you're trying to get us to do your job for you.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It was for one project which I'm doing for improving my php skills.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top