<?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;
}
}

// *** Redirect if page exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="page_exists.php";
  $findPage = $_POST['page'];
  $FindRS__query = sprintf("SELECT page_name FROM pages WHERE page_name=%s", GetSQLValueString($findPage, "text"));
  mysql_select_db($database_telmanik_press, $telmanik_press);
  $FindRS=mysql_query($FindRS__query, $telmanik_press) or die(mysql_error());
  $findFoundUser = mysql_num_rows($FindRS);

  //if there is a row in the database, the username was found - can not add the requested username
  if($findFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."reqpage=".$findPage;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}











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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "adpages")) {
  $insertSQL = sprintf("INSERT INTO pages (page_name, page_title) VALUES (%s, %s)",
                       GetSQLValueString($_POST['page'], "text"),
                       GetSQLValueString($_POST['title'], "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));
}
?>
<?php require("assets/wrapper/header.php"); ?>

<div class="mainlayout"><div id="edithead"><div id="editload">


<p><?php echo $translate->__('Add page');?></p>


  <p>&nbsp;</p>
  
  
  
  
  <form action="<?php echo $editFormAction; ?>" method="POST" name="adpages" enctype="multipart/form-data">
  
  

   <?php echo $translate->__('Page');?>: <BR />
    <input name="page" type="text" size="100" maxlength="255" /><BR />
   
    <?php echo $translate->__('Title');?>:<BR />
    <input name="title" size="100" type="text" maxlength="255"  /><BR />
   
    <BR />
    <input name="submit" type="submit" value="<?php echo $translate->__('Add Page');?>" />
    <input type="hidden" name="MM_insert" value="adpages" />
  </form>

  <p>&nbsp;</p>
</div>
</div></div>
<?php require("assets/wrapper/footer.php"); ?>