<style type="text/css">
<!--
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
-->
</style>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
   
        <td width="38" align="left"><img src="img/showlist.jpg" width="38" height="35" /></td>
         <td width="323" align="left"><span class="head">CONTENT MANAGEMENT SYSTEM</span></td>
    
    
    <? 
	
$cmsdisplay = $_REQUEST["cmsdisplay"];	
if($_GET["action"]==""){?>
    <form action="index.php?option=efe-cms" method="post">
    <td align="right"><span class="search">
      <label for="keyword"></label>
      <input type="text"	name="keyword" id="keyword" />
	  <input type="hidden"	name="cmsdisplay" id="cmsdisplay" value="<?=$cmsdisplay?>"/>
      &nbsp; 
      <label for="imageField"></label>
      <input type="image" name="imageField" id="imageField" width="20" height="20" src="images/search.jpeg" />
    </span></td>
    </form>
        <? }?>
  </tr>
    </table>
<br />
<?PHP
$option=$_GET["option"];
switch($_GET["action"])
{case"addcms":{
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="7" height="5" valign="top"><img src="images/border_01.jpg" width="7" height="5" /></td>
        <td background="images/border_02.jpg" style="background-repeat:repeat-x"></td>
        <td width="6" height="5" valign="top"><img src="images/border_03.jpg" width="6" height="5" /></td>
      </tr>
      <tr>
        <td background="images/border_04.jpg" style="background-repeat:repeat-y"></td>
        <td align="center" valign="top">
<form action="index.php?postdb=cms_all_db" method="post" name="frmtypeadd" id="frmtypeadd" enctype="multipart/form-data">        
        <table width="85%" border="0" align="center" cellpadding="2" cellspacing="0" class="font">
  <tr>
    <th colspan="2" scope="col">&nbsp;</th>
  </tr>
  <?if(getNumRow("select cms_type_id from efe_webcms_type where cms_type_display='".$cmsdisplay."'")>0){?>
  <tr>
    <td width="25%"><strong>Category : </strong></td>
    <td width="75%"><strong>
 <?typelistFuntSc($dbname,cms_cate_id,efe_webcms_type,cms_type_id,cms_type_id,cms_type_name,1,$cms_cate_id,"WHERE cms_type_display='".$cmsdisplay."'","onChange=\"gettype(this.value)\"");?>
</strong></td>
  </tr>
  <tr>
    <td width="25%"><strong>Subject : </strong></td>
    <td width="75%"><strong>
<div id="subject"></div>
	<input type="hidden" name="project_subject_id" id="project_subject_id">
	<script type="text/javascript">
	               function gettype(tank){
                    var d = new Date();
                   $("div#subject").load("ajax/get_subject.php?cat="+tank+"&tt="+d.getTime());
                    }
	               </script>
</strong></td>
  </tr>
  <?}?>
  <tr>
    <td width="25%"><strong>CMS Name : </strong></td>
    <td width="75%"><strong><input type="text" name="cms_name" value="" style="width:99%"></strong></td>
  </tr>
  <tr>
    <td width="25%"><strong>TITLE (Thai): </strong></td>
    <td width="75%"><input type="text" name="cms_title" value="" style="width:99%"></td>
  </tr>
    <tr>
    <td width="25%"><strong>TITLE (English) : </strong></td>
    <td width="75%"><input type="text" name="cms_title_eng" value="" style="width:99%"></td>
  </tr>
    <tr>
    <td width="25%"><strong>Date: </strong></td>
    <td width="75%"><input type="text" name="cms_date" value="" id="cms_date" style="width:99%"></td>
  </tr>
  <tr>
    <td width="25%"><strong>CMS Shortdes (Thai) : </strong></td>
    <td width="75%"><textarea name="cms_shortdes" id="cms_shortdes"></textarea>
   <?=editor("cms_shortdes");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>CMS Shortdes (English) : </strong></td>
    <td width="75%"><textarea name="cms_shortdes_eng" id="cms_shortdes_eng"></textarea>
   <?=editor("cms_shortdes_eng");?></td>
  </tr>
   <tr>
    <td width="25%"><strong>CMS EDIT (Thai) : </strong></td>
    <td width="75%"><textarea name="cms_content" id="cms_content"></textarea>
   <?=editor("cms_content");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>CMS EDIT (English) : </strong></td>
    <td width="75%"><textarea name="cms_content_eng" id="cms_content_eng"></textarea>
   <?=editor("cms_content_eng");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>BANNER / FILE UPLOAD (Thai): </strong></td>
    <td width="75%">
	<strong><input type="file" name="cms_banner"></strong></td>
  </tr>   <tr>
    <td width="25%"><strong>BANNER / FILE UPLOAD (English): </strong></td>
    <td width="75%"><strong>
<strong><input type="file" name="cms_banner_eng"></strong></td>
  </tr>
   <tr>
    <td width="25%"><strong>Preview picture : </strong></td>
    <td width="75%"><strong>
<strong><input type="file" name="cms_pv"></strong></td>
  </tr>
  <tr>
    <td><input name="subsection" type="hidden"  value="addcms">
	    <input name="cmsdisplay" type="hidden"  value="<?=$cmsdisplay?>">
	</td>
    <td><input name="Submit" type="submit" value="Save">
       <input name="input2" type="button" onClick="window.location='index.php?option=<?=$option?>'" value="Cancle" class="button" /></td>
  </tr>
</table>
</form>
</td>
        <td background="images/border_06.jpg" style="background-repeat:repeat-y"></td>
      </tr>
      <tr>
        <td width="7" height="7" valign="top"><img src="images/border_07.jpg" width="7" height="7" /></td>
        <td background="images/border_08.jpg" style="background-repeat:repeat-x">&nbsp;</td>
        <td width="6" height="7" valign="top"><img src="images/border_09.jpg" width="6" height="7" /></td>
      </tr>
    </table>
<?break;}
case"editcms":{ 
 $sql="SELECT * FROM sbs_cms_all WHERE cms_id='".$_GET["itemid"]."'";
 $result=mysql_query($sql) or die ($sql);
 $ROW=mysql_fetch_array($result);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="7" height="5" valign="top"><img src="images/border_01.jpg" width="7" height="5" /></td>
        <td background="images/border_02.jpg" style="background-repeat:repeat-x"></td>
        <td width="6" height="5" valign="top"><img src="images/border_03.jpg" width="6" height="5" /></td>
      </tr>
      <tr>
        <td background="images/border_04.jpg" style="background-repeat:repeat-y"></td>
        <td align="center" valign="top">
<form action="index.php?postdb=cms_all_db" method="post" name="frmtypeadd" id="frmtypeadd" enctype="multipart/form-data">        
        <table width="85%" border="0" align="center" cellpadding="2" cellspacing="0" class="font">
  <tr>
    <th colspan="2" scope="col">&nbsp;</th>
  </tr>
    <? if(getNumRow("select cms_type_id from efe_webcms_type where cms_type_display='".$cmsdisplay."'")>0){?>
   <tr>
    <td width="25%"><strong>Category : </strong></td>
    <td width="75%"><strong>
 <?typelistFuntSc($dbname,cms_cate_id,efe_webcms_type,cms_type_id,cms_type_id,cms_type_name,1,$ROW["cms_cate_id"],"WHERE cms_type_display='".$cmsdisplay."'","onChange=\"gettype(this.value)\"");?>
</strong></td>
  </tr>
  <tr>
    <td width="25%"><strong>Subject : </strong></td>
    <td width="75%"><strong>
<div id="subject"></div>
	<input type="hidden" name="project_subject_id" id="project_subject_id" value="<?=$ROW["project_subject_id"]?>">
	 	<script type="text/javascript">
	               function gettype(tank,baboo){
                    var d = new Date();
                   $("div#subject").load("ajax/get_subject.php?cat="+tank+"&baboo="+baboo+"&tt="+d.getTime());
                    }
	               </script>
	 <body onLoad="gettype('<?=$ROW["cms_cate_id"]?>','<?=$ROW["cms_subject_id"]?>');">
</strong></td>
  </tr>
  <?}?>
  <tr>
    <td width="25%"><strong>CMS : </strong></td>
    <td width="75%"><input type="text" name="cms_name" value="<?=$ROW["cms_name"]?>" style="width:99%"></strong></td>
  </tr>
  <tr>
    <td width="25%"><strong>TITLE (Thai): </strong></td>
    <td width="75%"><input type="text" name="cms_title" value="<?=$ROW["cms_title"]?>" style="width:99%"></td>
  </tr>
    <tr>
    <td width="25%"><strong>TITLE (English) : </strong></td>
    <td width="75%"><input type="text" name="cms_title_eng" value="<?=$ROW["cms_title_eng"] ?>" style="width:99%"></td>
  </tr>
     <tr>
    <td width="25%"><strong>Date: </strong></td>
    <td width="75%"><input type="text" name="cms_date" value="<? if($ROW["cms_date"]!=""){echo date("Y-m-d",$ROW["cms_date"]);}else{} ?>" id="cms_date" style="width:99%"></td>
  </tr>
    <tr>
    <td width="25%"><strong>CMS Shortdes (Thai) : </strong></td>
    <td width="75%"><textarea name="cms_shortdes" id="cms_shortdes"><?=$ROW["cms_shortdes"] ?></textarea>
   <?=editor("cms_shortdes");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>CMS Shortdes (English) : </strong></td>
    <td width="75%"><textarea name="cms_shortdes_eng" id="cms_shortdes_eng"><?=$ROW["cms_shortdes_eng"] ?></textarea>
   <?=editor("cms_shortdes_eng");?></td>
  </tr>
   <tr>
    <td width="25%"><strong>CMS EDIT (Thai) : </strong></td>
    <td width="75%"><textarea name="cms_content" id="cms_content"><?=$ROW["cms_content"]?></textarea>
   <?=editor("cms_content");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>CMS EDIT (English) : </strong></td>
    <td width="75%"><textarea name="cms_content_eng" id="cms_content_eng"><?=$ROW["cms_content_eng"]?></textarea>
   <?=editor("cms_content_eng");?></td>
  </tr>
    <tr>
    <td width="25%"><strong>BANNER / FILE UPLOAD (Thai): </strong></td>
    <td width="75%">
	  <? if($ROW["cms_banner"] !=="")
					   $gms = getExtension($ROW["cms_banner"]);
	{
					   if( $gms=="jpg"|| $gms=="jpeg" || $gms=="png" || $gms=="gif"){
	echo "<IMG SRC=\"../datacenter/banner/".$ROW["cms_banner"]."\" height=\"75\">";
	echo "<BR>"; }else{
	echo "<a href=\"../datacenter/banner/".$ROW["cms_banner"]."\">".$ROW["cms_banner"]."</a>";
	echo "<BR>"; 

	}
	}
	?>
	<strong><input type="file" name="cms_banner"></strong></td>
  </tr>   <tr>
    <td width="25%"><strong>BANNER /FILE UPLOAD (English): </strong></td>
    <td width="75%">
	<? if($ROW["cms_banner_eng"] !=="")
					   $gms = getExtension($ROW["cms_banner"]);
	{
					   if( $gms=="jpg"|| $gms=="jpeg" || $gms=="png" || $gms=="gif"){
	echo "<IMG SRC=\"../datacenter/banner/".$ROW["cms_banner_eng"]."\" height=\"75\">";
	echo "<BR>"; }else{
	echo "<a href=\"../datacenter/banner/".$ROW["cms_banner_eng"]."\">".$ROW["cms_banner_eng"]."</a>";
	echo "<BR>"; 

	}
	}
	?>
<strong><input type="file" name="cms_banner_eng"></strong></td>
  </tr>
  <!--tr>
    <td width="25%"><strong>Preview picture : </strong></td>
    <td width="75%"><strong>
	<? if($ROW["cms_pv"] !=="")
					   $gms = getExtension($ROW["cms_pv"]);
	{
					   if( $gms=="jpg"|| $gms=="jpeg" || $gms=="png" || $gms=="gif"){
	echo "<IMG SRC=\"../datacenter/banner/".$ROW["cms_pv"]."\" height=\"75\">";
	echo "<BR>"; }else{
	echo "<a href=\"../datacenter/banner/".$ROW["cms_pv"]."\">".$ROW["cms_pv"]."</a>";
	echo "<BR>"; 

	}
	}
	?>
<strong><input type="file" name="cms_pv"></strong></td>
  </tr-->
  <tr>
    <td><input name="subsection" type="hidden"  value="editcms">
	     <input name="cmsdisplay" type="hidden"  value="<?=$_GET["cmsdisplay"];?>">
		<input name="itemid" type="hidden"  value="<?=base64_encode($ROW["cms_id"])?>">
	</td>
    <td><input name="Submit" type="submit" value="Save">
       <input name="input2" type="button" onClick="window.location='index.php?option=<?=$option?>'" value="Cancle" class="button" /></td>
  </tr>
</table>
</form>
</td>
        <td background="images/border_06.jpg" style="background-repeat:repeat-y"></td>
      </tr>
      <tr>
        <td width="7" height="7" valign="top"><img src="images/border_07.jpg" width="7" height="7" /></td>
        <td background="images/border_08.jpg" style="background-repeat:repeat-x">&nbsp;</td>
        <td width="6" height="7" valign="top"><img src="images/border_09.jpg" width="6" height="7" /></td>
      </tr>
    </table>
<? break;}default:{ ?>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="7" height="5" valign="top"><img src="images/border_01.jpg" width="7" height="5" /></td>
        <td background="images/border_02.jpg" style="background-repeat:repeat-x"></td>
        <td width="6" height="5" valign="top"><img src="images/border_03.jpg" width="6" height="5" /></td>
      </tr>
      <tr>
        <td background="images/border_04.jpg" style="background-repeat:repeat-y"></td>
        <td>
                  <?PHP
$limit="20";
if(empty($_GET["page"])) {
	$page = 1;
} else {
	$page = $_GET["page"];
}	

$keyword=$_POST["keyword"];
if($_POST["keyword"]==""){
$keyword=$_GET["keyword"];
}


if($keyword!=""){	 		
$sql="select  * from sbs_cms_all where cms_name like '%".$keyword."%' and cms_display = '$cmsdisplay' order by cms_id desc";
} else{
$sql="select  * from sbs_cms_all WHERE cms_display = '$cmsdisplay' order by cms_id desc";
}

$total = mysql_num_rows(mysql_query($sql));
$total=$total;
if($total % $limit) {
	$total_page = floor($total / $limit) + 1;	
} else {
	$total_page = floor($total / $limit);	
}
$start = (($page - 1) * $limit);
$sql = $sql." limit $start, $limit";
$query =mysql_query($sql)or die($sql);
$n = 1;
?>
<table width="97%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
            <td height="5" colspan="3" align="center" class="font"></td>
            </tr>
         <tr>
            <td height="20" colspan="3" align="right" class="font"><table width="300" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="220" align="right"><span class="font-menu">Page&nbsp;                    <?
$end_page = 2;
$start = $page - $end_page;
if($page <= $end_page) {
	$start = 1;
}
$stop = $page + $end_page;
if($stop >= $total_page) {
	$stop = $total_page;
}
for($i = $start; $i <= $stop; $i ++) {
	if($i == $page) {
?>
                    <span class='page-numbers current'>
                      [<?=$page?>]                      </span>
                    <? } else { ?>
<a class='page-numbers' href='index.php?option=<?=$option?>&page=<?=$i?>&keyword=<?=$keyword?>&cmsdisplay=<?=$cmsdisplay?>'>&nbsp;<?=$i?>&nbsp;</a><? }}?></span></td>
                <td width="80" align="right"><span class="font-menu"><a href="index.php?option=<?=$option?>&action=addcms&cmsdisplay=<?=$cmsdisplay?>"><img src="img/add.jpg" width="70" height="26" border="0" /></a></span></td>
              </tr>
            </table></td>
            </tr>
          <tr>
            <td height="10" colspan="3" align="center" class="font"></td>
            </tr>
          <tr>
            <td width="5%" height="30" align="center" bgcolor="#bdd5f6" class="font"><strong>List</strong></td>
            <td align="center" bgcolor="#bdd5f6" class="font"><strong>Name</strong></td>
            <td width="15%" align="center" bgcolor="#bdd5f6" class="font"><strong>Process</strong></td>
        </tr>
<?
$start = (($page - 1) * $limit);
$bg="#d8e8fe";
while($Row = mysql_fetch_array($query)) {
	if($bg=="#d8e8fe"){
				$bg="#EDF4FE";
			}else if($bg=="#EDF4FE"){
				$bg="#d8e8fe";
			}				
				?>
          <tr class="font">
            <td align="center" bgcolor="<?=$bg;?>"><?=$start+$n++;?>.</td>
            <td bgcolor="<?=$bg;?>"> &nbsp;<?=$Row["cms_name"]?></td>
            <td align="center" bgcolor="<?=$bg;?>"><img src="images/faqseditconticon.gif" width="13" height="13" border="0"  style="cursor:pointer" onClick="window.location='index.php?option=<?=$option?>&action=editcms&itemid=<?=$Row["cms_id"]?>&cmsdisplay=<?=$cmsdisplay?>'">&nbsp;

			 <a href="index.php?postdb=cms_all_db&subsection=status&itemid=<?echo base64_encode($Row["cms_id"]); echo"&clearstatus=".$Row["cms_status"];?>&cmsdisplay=<?=$cmsdisplay?>"onclick="javascript:return confirm('ต้องการให้ <?=$ROW["cms_name"]?>
			อยู่ในสถานะ  <?if($Row["cms_status"] =="Y"){echo"ไม่แสดงผล"; }elseif($Row["cms_status"] =="N"){echo"แสดงผล";}else{echo"ไม่แสดงผล";}?> ใช่หรือไม่')"><img  src="images/ball_<?=$Row["cms_status"]?>.gif" width="13" border="0"> </a>
            &nbsp;

            
			 <a href="index.php?postdb=cms_all_db&subsection=trimstatus&itemid=<?echo base64_encode($Row["cms_id"]); echo"&clearstatus=".$Row["cms_trim_status"];?>&cmsdisplay=<?=$cmsdisplay?>"onclick="javascript:return confirm('ต้องการให้ <?=$ROW["cms_name"]?>
			อยู่ในสถานะ  <?if($Row["cms_trim_status"] =="Y"){echo"เนื้อหาธรรมดา"; }elseif($Row["cms_trim_status"] =="N"){echo"เนื้อหาเด่น";}else{echo"เนื้อหาธรรมดา";}?> ใช่หรือไม่')"><img  src="images/star_<?=$Row["cms_trim_status"]?>.png" width="13" border="0"> </a>
            &nbsp;

	<a href="index.php?postdb=cms_all_db&subsection=del&itemid=<?=base64_encode($Row["cms_id"])?>&cmsdisplay=<?=$cmsdisplay?>"onclick="javascript:return confirm('ต้องการลบ CMS <?=$Row["cms_name"]?> ใช่หรือไม่')"><img src="images/faqsdeleteicon.gif" width="13" height="13" border="0"/></a></td>
         		</td>
          </tr>
          <? }?>
                    <tr>
            <td height="10" colspan="3" align="center" class="font"></td>
            </tr>
          <tr>
            <td colspan="3" align="center" class="font"><span class="font-menu">      <? if($page <= $total_page) {
					 $prevpage = $page - 1; 
					 if($prevpage < "1")
						$prevpage="1";
					 ?>
      <a href='index.php?option=<?=$option?>&page=1&keyword=<?=$keyword?>'><span class="hproduct">First</span></a>&nbsp;  <a href='index.php?option=<?=$option?>&page=<?=$prevpage?>&keyword=<?=$keyword?>'><span class="hproduct">Back</span></a>
      <? } ?>&nbsp;Page&nbsp;             
                    <?
$end_page = 2;
$start = $page - $end_page;
if($page <= $end_page) {
	$start = 1;
}
$stop = $page + $end_page;
if($stop >= $total_page) {
	$stop = $total_page;
}
for($i = $start; $i <= $stop; $i ++) {
	if($i == $page) {
?>
                    <span class='page-numbers current'>
                      [<?=$page?>]                      </span>
                    <? } else { ?>
<a class='page-numbers' href='index.php?option=<?=$option?>&page=<?=$i?>&keyword=<?=$keyword?>&cmsdisplay=<?=$cmsdisplay?>'>&nbsp;<?=$i?>&nbsp;</a><? }}?>&nbsp;<? if($page <= $total_page) { 
						$nextpage = $page + 1; 
						if($nextpage > $total_page)
						$nextpage=$total_page;
						?>
      <a href='index.php?option=<?=$option?>&page=<?=$nextpage?>&keyword=<?=$keyword?>&cmsdisplay=<?=$cmsdisplay?>'><span class="hproduct">Next</span></a> <a href='index.php?option=<?=$option?>&page=<?=$total_page?>&keyword=<?=$keyword?>&cmsdisplay=<?=$cmsdisplay?>'><span class="hnews">&nbsp; End</span></a>
      <? } ?> &nbsp;&nbsp;&nbsp;Page <?=$page?> of <?=$total_page?> &nbsp;&nbsp;Total list &nbsp;<?=$total;?> list</td>
</tr>
                      <tr>
            <td height="5" colspan="3" align="center" class="font"></td>
            </tr>
        </table>
</td>
        <td background="images/border_06.jpg" style="background-repeat:repeat-y"></td>
      </tr>
      <tr>
        <td width="7" height="7" valign="top"><img src="images/border_07.jpg" width="7" height="7" /></td>
        <td background="images/border_08.jpg" style="background-repeat:repeat-x">&nbsp;</td>
        <td width="6" height="7" valign="top"><img src="images/border_09.jpg" width="6" height="7" /></td>
      </tr>
    </table>
    <? }}?>