<?php
include "chkuser.php";
include "includefilemng.php";

$perpage=10;
$serchstr='';
$searchsql='';

$sSqlQ=mysql_query("SELECT * from ".SINGLEFIELDTABLE." where mastertableid='1' order by display_order ASC");
	while($sSqlR=mysql_fetch_object($sSqlQ)){
	   $pageA[]=array(
	                  'id'=>$sSqlR->id,
					  'name'=>$sSqlR->name
	                 );
	}
 if(isset($_GET['cid'])){
 $cid=$_GET['cid'];
 }
 else {
 $cid=0;
 }


/*if(isset($_REQUEST['page'])){
$serchstr.="&page=".$_REQUEST['page'];
$serchstr.="&perpage=".$_REQUEST['perpage'];
}
if(isset($_REQUEST['search'])){
if(isset($_REQUEST['payment']) && strlen($_REQUEST['payment'])>0 ){
$serchstr.="&payment=".$_REQUEST['payment'];
$searchsql.=" AND od.pay ='".$_REQUEST['payment']."'";
}
if(strlen($searchsql)>5){
$searchsql=substr($searchsql,4,strlen($searchsql));
$searchsql="WHERE ".$searchsql;
}
if(strlen($serchstr)>2){
$serchstr="&search=1".$serchstr;
}
}*/
//$searchsql="WHERE dd.id is null";

$TABLE_NAME=" page pg ";
$FIELD_SELECT=" distinct pg.id as id,pg.name,pg.description,pg.pPosition ";
$ORDER_BY=" ORDER BY pg.name asc ";
$WHERE_CLOUSE=" WHERE pg.pOrder='".$cid."' ";

// end urlstr 
function del_real($delid)
	{
	
	$pdel="delete from page where id='$delid'";
	$rdel=mysql_query($pdel);
	$errormsg = "Record deleted";
	}
if (isset($_POST['delete']))
{
	$del_all=$_POST['chk'];
	
	$j= 0;
	for($i=0;$i<count($del_all);$i++)
	{
		if(is_numeric($del_all[$i]))
		{
			$orderid = $del_all[$i];
			del_real($orderid);
					
			
			$j = $j +1;
		}
	}
	$rmsg = $j ." records deleted";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Control Panel </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
<script src="includenp/functions.js"></script>
<script language="javascript">
<!--

//-->
function openSWIN()
{
popwin = open("",'NewWin','height=500,width=500,toolbars=no,menubar=no,scrollbars=yes') 
}				
function openIWIN()
{
popwin = open("",'NewWin','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=632,height=370,left = 362,top = 234') 
}				
</script>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td width="1%"  bgcolor="#C9C9C9"></td>
	<td width="98%"><?php include_once "top.php";?></td>
	<td width="1%"  bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
   <td width="1%"  bgcolor="#C9C9C9"></td>
    <td width="98%"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="centertable">
      <tr>
        <td><table width="90%"  border="0" align="center" cellpadding="3" cellspacing="0">
          
           <?php if($cid ==0){?>
           <tr>
            <td height="40" class="bigblackTxt" style="padding-left:36px;"><a href="view_page.php" class="normalLink">Manage pages</a></td>
          </tr>
          <tr>
            <td><table width="60%" border="0" align="left" cellpadding="0" cellspacing="0">
             <?php 
			 for($i=0;$i<count($pageA);$i++){
			 ?>
            
             <tr>
                <td width="6%">&nbsp;</td>
                <td width="4%"><img src="panelimages/folder.gif" width="16" height="16"></td>
                <td width="90%"><a href="view_page.php?cid=<?php echo $pageA[$i]['id'];?>" class="normalLink"><?php echo $pageA[$i]['name'];?></a></td>
              </tr>              
              <? }?>
               <tr>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
            </table></td>
          </tr>
           <?php }?>
         <?php if($cid >0){?>
         <tr>
            <td height="40" class="bigblackTxt">&nbsp;<a href="view_page.php" class="normalLink">Manage pages</a></td>
          </tr>
          <tr>
            <td><?php 

		  if(isset($errormsg))
		  	{
				echo display_error_msg($errormsg);
		   	}
			?>
			
            </td>
          </tr>
          <tr>
            <td>
              <table width="100%"  border="0" align="center" cellpadding="2" cellspacing="0">
               <?php for($i=0;$i<count($pageA);$i++){?>
                  <tr>
                    <td align="left" valign="bottom" class="normalBoldblackTxt" style="padding-left:10px;">                   
					   <?php 
					    if($pageA[$i]['id']==$cid){
						echo $pageA[$i]['name']."&nbsp;>>";
						  }				 
					?>                  </td>
                  </tr>
                  <?php }?>
                  <tr>
                    <td width="100%" align="center">
                    			<?php 
			$sqln=$SQL_QUERY=" SELECT * FROM ".$TABLE_NAME.$WHERE_CLOUSE;
			$resultn = mysql_query($sqln,$eclipse); 
			$numrows = $row = mysql_num_rows($resultn);
     			if($numrows > 0 )
				{
				?>
				<form action="<?php echo $_SERVER['PHP_SELF'];?>?<?php echo $serchstr;?>" method="post"  name="form1" ID="form1">
				  <table class=table cellspacing=3 cellpadding=3 width="100%" align=center border=0>
                    <tr valign="top" class="thbg">
                     
                      <th height="20" align="center" class="bluebold">Edit</th>
                      <th width="22%" align="center"  class="bluebold">Title <br>                      </th>
                      <th colspan="2" align="center"  class="bluebold">Descriptions</th>
                    </tr>
                    <?php	
			if(!isset($_GET['page'])){$_GET['page']=1;} 
			if (!isset($recordstart)) {$recordstart=1;}
			
			$recordstart = ($_GET['page']-1)*$perpage; 
			
		 	 if(isset($_GET['page']))
			 {
		     $itk = ($_GET['page']* $perpage) - $perpage + 1;
		 	 }
			 	
			 /*$sql = "SELECT
			 * from products";*/
			 
			 $sql=$SQL_QUERY=" SELECT ".$FIELD_SELECT."  FROM ".$TABLE_NAME.$WHERE_CLOUSE.$ORDER_BY."LIMIT $recordstart,$perpage";
			 $result = mysql_query($sql,$eclipse); 
			
			 while ($row = mysql_fetch_array($result))
			 {								
			 extract($row); 					 
			 ?>
                    <tr valign="top" class="trbg">
                     
                      <td width="22%" align=center><a href="new_page.php?cid=<?php echo $_GET['cid'];?>&editid=<?php echo $id; ?><?php echo $serchstr;?>"><img src="panelimages/b_edit.png" width="16" height="16" border="0"></a></td>
                      <td align="center" class="normalTxt"><?php echo $name;?></td>
                      <td colspan="2" align="left" class="normalTxt"><?php
					  echo html_entity_decode($description); 
					   ?></td>
                      <?php
				}
				
				?>
                    </tr>
                    <tr valign="top" class="trbg">
                      <td align=center valign="middle">&nbsp;</td>
                      <td align=center valign="middle">&nbsp;</td>
                      <td width="8%" align=center>&nbsp;</td>
                      <td width="46%" align=left>&nbsp;</td>
                      <td width="2%" colspan="2" align=left>&nbsp;</td>
                    </tr>
                  </table>
				</form>
				
<?php 
$query=$sqln;
$result = mysql_query($query); 
$totalreturned = mysql_num_rows($result); 
$pagecount = ceil($totalreturned/$perpage);     
$recordstart = ($_GET['page']-1)*$perpage; 
echo page_records($_GET['page'],$pagecount,$recordstart,$perpage,$serchstr); 
?>
				<?php
				}
				else
				{
				?>
				
				<TABLE class=table cellSpacing=1 cellPadding=0 
                                width="100%" align=center border=0>
                 
                    <TR>
                      <TD align=center class="bluebold">No Records to view </td>
                    </TR>
                </TABLE>
				<?php
				}
				?></td>
                  </tr>
            </table></td>
          </tr>
          <?php }?>
        </table></td>
      </tr>
    </table></td>
    <td width="1%" bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
    <td  bgcolor="#C9C9C9" width="1%"></td>
	<td><?php include_once "footer.php";?></td>
	<td width="1%"  bgcolor="#C9C9C9"></td>
  </tr>
</table>
</body>
</html>
