<?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_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE content SET title=%s, block_content=%s WHERE id=%s",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['editor1'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

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

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

$colname_updateconfirm = "-1";
if (isset($_GET['idedit'])) {
  $colname_updateconfirm = $_GET['idedit'];
}
mysql_select_db($database_telmanik_press, $telmanik_press);
$query_updateconfirm = sprintf("SELECT * FROM content WHERE id = %s", GetSQLValueString($colname_updateconfirm, "int"));
$updateconfirm = mysql_query($query_updateconfirm, $telmanik_press) or die(mysql_error());
$row_updateconfirm = mysql_fetch_assoc($updateconfirm);
$totalRows_updateconfirm = mysql_num_rows($updateconfirm);

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_selectalbums = "SELECT * FROM gallerys";
$selectalbums = mysql_query($query_selectalbums, $telmanik_press) or die(mysql_error());
$row_selectalbums = mysql_fetch_assoc($selectalbums);
$totalRows_selectalbums = mysql_num_rows($selectalbums);
?>

<?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 action="" method="get" name="gallerygall">

<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_selectalbums['gallery_name']?>"><?php echo $row_selectalbums['gallery_name']?></option>
  <?php
} while ($row_selectalbums = mysql_fetch_assoc($selectalbums));
  $rows = mysql_num_rows($selectalbums);
  if($rows > 0) {
      mysql_data_seek($selectalbums, 0);
	  $row_selectalbums = mysql_fetch_assoc($selectalbums);
  }
?>
</select></form>
<p>
<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>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
 
 
        <label for="id"></label>
      <input name="id" type="hidden" id="id" value="<?php echo $row_updateconfirm['id']; ?>"  />
      <label for="listdate"></label>
        
     <div id="edithead"> <?php echo $translate->__('Title');?>
       <input name="title" type="text" id="title" value="<?php echo $row_updateconfirm['title']; ?>" /></div>
      
      <label for="editstory"></label>        <label for="status"></label>
      
      
      <label for="editor1">
  </label>
		  <textarea cols="80" id="editor1" name="editor1" rows="10"><?php echo $row_updateconfirm['block_content']; ?></textarea>
	  <script type="text/javascript">
			//<![CDATA[

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

			//]]>
			</script>
    
  <p>&nbsp;  </p>
  <p>
    <input type="submit" name="iddelete" id="iddelete" value="<?php echo $translate->__('Confirm Update');?>" />
  </p>
  <input type="hidden" name="MM_update" value="form1" />
</form>
</div>
  <p>&nbsp;  </p>
    <p>&nbsp;  </p>
      <p>&nbsp;  </p>
<?php
mysql_free_result($updateconfirm);

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