For the life of me, I can't figure out why I'm getting an unexpected end of file error when I link this code to another file using the line"
require(PATH_LIB.'/grid.php');
This ONLY occurs on my localhost testing server and not on the host website. The error disappears if I comment out the command mentioned above. Here's the error:
Parse error: syntax error, unexpected end of file in C:\Apache\htdocs\Website\includes\lib\grid.php on line 222
Please help! Aaargh.
Code:
<?php
class grid {
var $db, $config, $query;
//function __construct($db) {
function grid($db) {
$this->db = $db;
}
function config($key,$value = '') {
$this->config[$key] = $value;
}
function render() {
$edit = ($temp = $this->config['edit']) ? $temp : $this->config['table'].'_edit.php';
$delete = ($temp = $this->config['delete']) ? $temp : $this->config['table'].'_delete.php';
$add = ($temp = $this->config['add']) ? $temp : $edit;
$query_where = $this->config['query_where'];
// Load the relevant variables from $_GET into the current scope,
// stripping out the _table suffix that keeps multiple instances
// separated in $_GET...
foreach(array("order","desc","search","page") as $variable)
$$variable = $_GET[$variable.'_'.$this->config['table']];
// .
$columns_count = count($this->config['columns']);
if(!$order) {
$order = $this->config['default_order'];
$desc = $this->config['default_desc'];
}
$d = (($desc)?"DESC":"ASC");
if(!$this->config['pagesize']) $this->config['pagesize'] = 8;
$order_list = $this->config['columns'][$order]['order'];
foreach(explode(",",$order_list) as $field) {
if($query_order) $query_order .= ", ";
$query_order .= "$field $d";
}
$headers = "<tr>";
foreach($this->config['columns'] as $label=>$column) {
$order_list = $column['order'];
if($query_select) $query_select .= ",";
$query_select .= $order_list;
if($label == $order) {
$class = "grid_head_sorted";
$class_a = "grid_head_sorted_a";
if($desc) {
$desc_new = 0;
$graphic = "arrow_down.gif";
}
else {
$desc_new = 1;
$graphic = "arrow_up.gif";
}
}
else {
$class = "grid_head_normal";
$class_a = "";
$desc_new = 0;
$graphic = "space.gif";
}
$headers .= "<td class='$class' nowrap><a class='$class_a' href='$_SERVER[PHP_SELF]?";
$headers .= $this->qs_replace("order_".$this->config['table']."=$label&desc_".$this->config['table']."=$desc_new&search_".$this->config['table']."=".urlencode($search));
$headers .= "'>$label</a> <img src='".PATH_IMAGES."/$graphic' width='9' height='5'></td>\n";
}
if(!$simple) $headers .= "<td class='grid_head_sorted' nowrap>Controls</td>";
$headers .= "</tr>\n";
if($search) {
$query_where_temp = "";
foreach(explode(",",$query_select) as $field) {
if(!preg_match('|^_|',$field)) {
if($query_where_temp) $query_where_temp .= " || ";
$query_where_temp .= "$field like '%".addslashes($search)."%'";
}
}
if($query_where) $query_where = "where (($query_where) && ($query_where_temp))";
else $query_where = "where ($query_where_temp)";
}
else if($this->config['query_where']) $query_where = "where (".$this->config['query_where'].")";
$query_limit = ($page*$this->config['pagesize']).",".$this->config['pagesize'];
if(!($query = $this->config['query'])) $query = "select * from ".$this->config['table'];
$query .= " $query_where ".$this->config['query_group'];
$results = $this->db->resource_query($query);
$rows = mysql_num_rows($results);
$page_last = (int)(($rows-1)/$this->config['pagesize']);
if($page_last > 0) {
$pager = "<table border='0'><tr><td>Page ".($page+1)." of ".($page_last+1)."</td><td width='5'></td>";
$pager .= "<td>".(($page>0)?"<a href='$_SERVER[PHP_SELF]?".$this->qs_replace("page_".$this->config['table']."=".($page-1))."'><img src='".PATH_IMAGES."/arrow_left.gif' border='0'></a>":"<img src='".PATH_IMAGES."/arrow_left_off.gif'>")."</td>";
$pager .= "<td><select style='text-align: right;' onchange='document.location=this.options[this.selectedIndex].value;'>";
for($p=0; $p<=$page_last; $p++) {
$pager .= "<option value='$_SERVER[PHP_SELF]?".$this->qs_replace("page_".$this->config['table']."=$p")."'".(($p==$page)?' selected':'').">".($p+1)."</option>";
/*
$pager .= "<td>";
if($p == $page) $pager .= "<b>".($p+1)."</b>";
else $pager .= "<a href='$_SERVER[PHP_SELF]?".$this->qs_replace("page_".$this->config['table']."=$p")."'>".($p+1)."</a>";
$pager .= "</td>";
*/
}
$pager .= "</select></td>";
$pager .= "<td>".(($page<$page_last)?"<a href='$_SERVER[PHP_SELF]?".$this->qs_replace("page_".$this->config['table']."=".($page+1))."'><img src='".PATH_IMAGES."/arrow_right.gif' border='0'></a>":"<img src='".PATH_IMAGES."/arrow_right_off.gif'>")."</td>";
$pager .= "</tr></table>";
}
$query .= " order by $query_order limit $query_limit";
$this->query = $query;
$results = $this->db->resource_query($query);
?>
<form method='get'>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<? if($this->config['simple']) { ?>
<td align='right'><?=$pager;?></td>
<? } else { ?>
<td valign='bottom'><span class='grid_title'><?=$this->config['title'];?></span>
<? if($search) print " · Containing \"<b>$search</b>\""; ?> <b>(<?=(int)$rows;?> results)</b></td>
<td align='center' valign='bottom'><? if(!$this->config['no_add']) { ?><a href='<?=$add;?>'>Add Record</a><? } ?></td>
<table border='0' cellspacing='0' cellpadding='2'><tr><td valign='bottom'>
<?=$pager;?>
<td width='10'></td>
<td>Refine: <input type='text' name='search_<?=$this->config['table'];?>'
size='25' maxlength='25'
value="<?=$this->escape($search);?>">
<input type='submit' value='Go'
class = 'button_off'
onmouseover = 'this.className="button_on";'
onmouseout = 'this.className="button_off";'
>
<input type='hidden' name='condition' value="<?=str_replace('"','"',$_GET['condition']);?>">
</td></tr></table>
</td>
<? } ?>
</tr>
</table>
<table border='0' width='100%' cellspacing='2' cellpadding='0'>
<?=$headers;?>
<?
$row = 0;
while($data = $this->db->resource_get($results)) {
extract($data);
$odd = (($rows++%2)?1:0);
$class = (($odd)?"grid_data_shaded":"grid_data_normal");
if($odd) print "<tr><td colspan='$columns_count' class='grid_lines'></td></tr>";
print "<tr>";
foreach($this->config['columns'] as $label => $column) {
$field = $column['data'];
print "<td class='".(($label==$order)?"grid_data_sorted":$class)."'".(($temp = $column['style'])?" style=\"$temp\"":'').">";
$string = "print \"$field\";";
eval($string);
print "</td>";
}
if(!$this->config['simple']) {
print "<td class='grid_head_normal'><a href='$edit?i=$data[i]'>Edit</a>";
if(!$this->config['no_delete']) print " - <a href='javascript:del_".$this->config['table']."($data[i]);'>Delete</a>";
print "</td>";
}
print "</tr>\n";
if($odd) print "<tr><td colspan='$columns_count' class='grid_lines'></td></tr>";
++$row;
}
if(!$row) {
print "<tr><td colspan='$columns_count' align='center'>";
if($search) print "Refining search produced no results";
else print "Search produced no results";
print "</td></tr>\n";
}
?>
<?=$headers;?>
</table>
<input type='hidden' name='order_<?=$this->config['table'];?>' value='<?=$order;?>'>
<input type='hidden' name='desc_<?=$this->config['table'];?>' value='<?=$desc;?>'>
</form>
<script>
function del_<?=$this->config['table'];?>(i) {
if(confirm("Confirm desire to remove record.")) document.location='<?=$delete;?>?i='+i;
}
</script>
<?
}
function qs_replace($qs) {
foreach(explode("&",$_SERVER['QUERY_STRING']) as $pair) {
list($label,$value) = explode("=",$pair,2);
$query_hash[$label] = $value;
}
foreach(explode("&",$qs) as $pair) {
list($label,$value) = explode("=",$pair,2);
$query_hash[$label] = $value;
}
foreach($query_hash as $label=>$value) {
if(preg_match("/^\D/",$label)) {
if($return) $return .= "&";
$return .= "$label=$value";
}
}
return $return;
}
function escape($string) {
return str_replace("\"",""",$string);
}
}
?>