<?
//***************************************************
// http://www.scriptindonesia.com
// Solusi Hemat Script Bisnis Online Anda
// Menerima Jasa Pembuatan Website & Template Website
//***************************************************
?>
<?
//Edit Script AW 20160221
//if (session_is_registered("valid_admin")) {
  if (isset($_SESSION['valid_admin'])) {
?>

<script type="text/javascript">
<!--
function confirmation(noid) {
	var answer = confirm("Are You sure to delete this Article?")
	if (answer){
		//alert("Bye bye!")
		window.location = "?m=faq&page=delete&no=" + noid;
		
	}
	
}
//-->
</script>
<h2><img src="images/icon-48-article.png" width="48" height="48" align="absmiddle"> FAQ Manager</h2>
<?
switch($page) {
	default :
?>	
<div id="menu_button2">
  <ul>
    <li><a href="?m=faq&page=addnew">Add New FAQ</a></li>
    <li><a href="?m=category&type=faq">FAQ Category </a></li>
  </ul>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr class="tbl_header">
    <td width="4%" align="center">#</td>
    <td width="5%" align="center">ID</td>
    <td width="56%" align="center">Question</td>
    <td width="9%" align="center">Published</td>
    <td width="14%" align="center">Category</td>
    <td width="12%" align="center">&nbsp;</td>
  </tr>
<?
$db->select("no, tanya, jawab, published, kat", "faq", "");

$j=$db->num_rows();
for($i=0;$i<$j;$i++) {
	$nom = $i + 1;
	$lid = $i - 1;
	if(is_odd($i) == 0) {
		$class = "tblrow_ganjil";
	} else {
		$class = "tblrow_genap";
	} 	
	if($db->result($i, "published") > 0) {
		$img = "<a href='?m=faq&page=publish&pub=0&no=".$db->result($i, "no")."'><img src='images/tick.png' border=0 title='Click to Unpublish'></a>";
	} else {
		$img = "<a href='?m=faq&page=publish&pub=1&no=".$db->result($i, "no")."'><img src='images/publish_x.png' border=0 title='Click to Publish'></a>";
	} 	

?>
 
  <tr class="<?= $class; ?>">
    <td width="4%"><?= $nom; ?> </td>
    <td width="5%"><?= $db->result($i, "no"); ?></td>
    <td><a href="?m=faq&page=addnew&edit=1&no=<?= $db->result($i, "no"); ?>"><?= $db->result($i, "tanya"); ?></a></td>
    <td align="center"><?= $img; ?></td>
    <td align="center"><?= category_name($db->result($i, "kat")); ?></td>
    <td align="center"><div id="delete"><a href="#" onClick='confirmation(<?= $db->result($i, "no"); ?>)' style='cursor:hand; padding-left:15px'>Delete</a></div></td>
  </tr>
<?
	}
?>	  
</table>
<p>&nbsp;</p>
<?
	break;
	case addnew :
	//include("fckeditor/fckeditor.php") ;
		if($edit > 0) {
			$db->select("no, tanya, jawab, kat, published", "faq", "no='$no'");
			$title = $db->result($i, "tanya"); 
			$jawab = $db->result($i, "jawab"); 
			
			$publish = $db->result($i, "published"); 
			$catid = $db->result($i, "kat"); 
			
			$judul = "Edit FAQ";
		} else {
			$author = $valid_admin; 
			$crdate = $clientdate; 
			$judul = "Create New FAQ";
		}		
?>
<form name="faq" method="post" action="?m=faq&page=submit">
  <table width="98%" border="0" align="center" cellpadding="5" cellspacing="0">
    <tr>
      <td colspan="4"><h4><?= $judul; ?></h4></td>
    </tr>
    <tr>
      <td width="10%" align="right" valign="top">Question :</td>
      <td><label>
        <textarea name="title" cols="50" rows="2" id="title"><?= $title; ?></textarea>
      </label></td>
      <td align="right">Category :</td>
      <td><select name="cat" id="cat">
        <option value="0">- Select Category -</option>
        <?
	 	$db->select("id, title", "categories", "section='faq'");
		$j=$db->num_rows();
for($i=0;$i<$j;$i++) {	
		if($catid == $db->result($i, "id")) {
			$sel = " selected='selected'";
		} else {
			$sel = "";
		}	
		echo "<option value='".$db->result($i, "id")."' $sel>".$db->result($i, "title")."</option>";
	}	
	 
	 ?>
      </select></td>
    </tr>
    <tr>
      <td align="right" valign="top">Answer : </td>
      <td width="52%"><textarea name="answer" cols="50" rows="5" id="answer"><?= $jawab; ?></textarea></td>
      <td width="16%" align="right">&nbsp;</td>
      <td width="22%">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" valign="top">Published :</td>
      <td colspan="3"><p>
        <label>
          <input name="publish" type="radio" id="publish_0" value="1" checked>
          Yes</label> 
        <label>
          <input type="radio" name="publish" value="0" id="publish_1">
          No</label>
        <input name="no" type="hidden" id="no" value="<?= $no; ?>" size="20">
        <input name="edit" type="hidden" id="edit" value="<?= $edit; ?>" size="20">
        <br>
      </p></td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td colspan="3"><label>
        <input type="submit"  value="SAVE" class="button">
        
      </label><label><input type="button" name="cancel" id="cancel" value="CANCEL" onClick="javascript:history.go(-1)" class="cancelbutton">
      </label></td>
    </tr>
  </table>
</form>
  <script language="JavaScript" type="text/javascript">
 var frmvalidator = new Validator("faq");
 frmvalidator.addValidation("title","req","Question  harus diisi, silahkan ulangi lagi!");
 frmvalidator.addValidation("answer","req","Answer harus diisi, silahkan ulangi lagi!");
  frmvalidator.addValidation("cat","dontselect=0","Pilih katagori FAQ!");


</script>  
<?	
	break;
	case submit :
		
		if($edit > 0) {
			$db->update("faq", "tanya='$title', jawab='$answer', kat='$cat', published='$publish'", "no='$no'");
	} else {
			$db->insert("faq", "", "'', '$title', '$answer', $cat, $publish");
	}		
			echo "<meta http-equiv='refresh' content='0;URL=?m=faq'>";
	break;
	
	case publish :
		$db->update("faq", "published='$pub'", "no='$no'");
		echo "<meta http-equiv='refresh' content='0;URL=?m=faq'>";
	break;
	case delete :
		//echo "delete no $no";
		$db->delete("faq", "no=$no");
		echo "<meta http-equiv='refresh' content='0;URL=?m=faq'>";
	break;	
	

}
?>	
<?
} else {
echo "<meta http-equiv=\"refresh\" content=\"1; url=illegal.html\">";
}
?>