<?php session_start(); ?>
<?php require_once('../Connections/telmanik_press.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO content (title, block_content, page_name) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['textfield'], "text"),
                       GetSQLValueString($_POST['editor1'], "text"),
                       GetSQLValueString($_POST['select'], "text"));

  mysql_select_db($database_telmanik_press, $telmanik_press);
  $Result1 = mysql_query($insertSQL, $telmanik_press) or die(mysql_error());

  $insertGoTo = "success.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_insertstory = "SELECT * FROM content";
$insertstory = mysql_query($query_insertstory, $telmanik_press) or die(mysql_error());
$row_insertstory = mysql_fetch_assoc($insertstory);
$totalRows_insertstory = mysql_num_rows($insertstory);

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_caterogry = "SELECT * FROM pages";
$caterogry = mysql_query($query_caterogry, $telmanik_press) or die(mysql_error());
$row_caterogry = mysql_fetch_assoc($caterogry);
$totalRows_caterogry = mysql_num_rows($caterogry);

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_gall = "SELECT * FROM gallerys";
$gall = mysql_query($query_gall, $telmanik_press) or die(mysql_error());
$row_gall = mysql_fetch_assoc($gall);
$totalRows_gall = mysql_num_rows($gall);

$colname_displayphotos = "-1";
if (isset($_POST['selectgallery'])) {
  $colname_displayphotos = $_POST['selectgallery'];
}
mysql_select_db($database_telmanik_press, $telmanik_press);
$query_displayphotos = sprintf("SELECT * FROM photos WHERE gallery = %s", GetSQLValueString($colname_displayphotos, "text"));
$displayphotos = mysql_query($query_displayphotos, $telmanik_press) or die(mysql_error());
$row_displayphotos = mysql_fetch_assoc($displayphotos);
$totalRows_displayphotos = mysql_num_rows($displayphotos);
?>



<?php require("assets/wrapper/header.php"); ?>

<script type="text/javascript" src="ckeditor.js"></script>
	<script src="sample.js" type="text/javascript"></script>
  




<script>
function showgal(str)
{
if (str=="")
  {
  document.getElementById("showphoto").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("showphoto").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getgallery.php?gallery="+str,true);
xmlhttp.send();
}
</script>

<div id="editload">
<BR />
<form id="selectgall" name="selectgall" method="post" action="">
<!-- onchange="this.form.submit()"-- works -->
  <select onchange="showgal(this.value)"  name="selectgallery"  id="selectgallery">
  <option value=""><?php echo $translate->__('Please Select Gallery');?></option>
    <?php
do {  
?>   
    <option value="<?php echo $row_gall['gallery_name']?>"><?php echo $row_gall['gallery_name']?></option>
    <?php
} while ($row_gall = mysql_fetch_assoc($gall));
  $rows = mysql_num_rows($gall);
  if($rows > 0) {
      mysql_data_seek($gall, 0);
	  $row_gall = mysql_fetch_assoc($gall);
  }
?>
  </select>

  <BR /><BR />
   
</form>
<div id="showphoto"><?php echo $translate->__('<b>Your gallery will display here..</b> - Note that to add picture to gallery please select gallery then click and drag and drop on space then click on image to resize it.');?></div>
<p>
 
</p>

<form name="form" action="<?php echo $editFormAction; ?>" method="POST"><div id="edithead">
		
		  <label for="select"></label>
		<?php echo $translate->__('Select Page');?> <select name="select" id="select">
		    <option value=""><?php echo $translate->__('Please Select Page');?></option>
		    <?php
do {  
?>
		    <option value="<?php echo $row_caterogry['page_name']?>"><?php echo $row_caterogry['page_name']?></option>
		    <?php
} while ($row_caterogry = mysql_fetch_assoc($caterogry));
  $rows = mysql_num_rows($caterogry);
  if($rows > 0) {
      mysql_data_seek($caterogry, 0);
	  $row_caterogry = mysql_fetch_assoc($caterogry);
  }
?>
  </select>
	    
        
      <?php echo $translate->__('Title');?>
    <input type="text" name="textfield" id="textfield" /><BR /> </div>
			<label for="editor1">
				</label>
		  <textarea cols="80" id="editor1" name="editor1" rows="20"> <?php echo $translate->__('insert content here');?></textarea>
          
		  <script type="text/javascript">
			//<![CDATA[

				CKEDITOR.replace( 'editor1', {
					extraPlugins : 'autogrow',
					removePlugins : 'resize'
				});

			//]]>
			</script>
  </p>
		<p>
			
			<input type="submit" value="<?php echo $translate->__('Save');?>"/>
		<input type="hidden" name="MM_insert" value="form" />
</form>
<p>&nbsp;  </p>
    <p>&nbsp;  </p>
      <p>&nbsp;  </p>
</div>
<?php
mysql_free_result($insertstory);

mysql_free_result($caterogry);

mysql_free_result($gall);

mysql_free_result($displayphotos);
?>
<?php require("assets/wrapper/footer.php"); ?>