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

$currentPage = $_SERVER["PHP_SELF"];

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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addpg")) {
  $insertSQL = sprintf("INSERT INTO gallerys (gallery_name) VALUES (%s)",
                       GetSQLValueString($_POST['galleryname'], "text"));

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

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

$maxRows_addgallery = 10;
$pageNum_addgallery = 0;
if (isset($_GET['pageNum_addgallery'])) {
  $pageNum_addgallery = $_GET['pageNum_addgallery'];
}
$startRow_addgallery = $pageNum_addgallery * $maxRows_addgallery;

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_addgallery = "SELECT * FROM gallerys";
$query_limit_addgallery = sprintf("%s LIMIT %d, %d", $query_addgallery, $startRow_addgallery, $maxRows_addgallery);
$addgallery = mysql_query($query_limit_addgallery, $telmanik_press) or die(mysql_error());
$row_addgallery = mysql_fetch_assoc($addgallery);

if (isset($_GET['totalRows_addgallery'])) {
  $totalRows_addgallery = $_GET['totalRows_addgallery'];
} else {
  $all_addgallery = mysql_query($query_addgallery);
  $totalRows_addgallery = mysql_num_rows($all_addgallery);
}
$totalPages_addgallery = ceil($totalRows_addgallery/$maxRows_addgallery)-1;

$queryString_addgallery = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_addgallery") == false && 
        stristr($param, "totalRows_addgallery") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_addgallery = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_addgallery = sprintf("&totalRows_addgallery=%d%s", $totalRows_addgallery, $queryString_addgallery);
?>
<?php require("assets/wrapper/header.php"); ?>
<div class="mainlayout"><div id="editload"> <div id="edithead">
  <p></p>


<form action="<?php echo $editFormAction; ?>" method="POST" name="addpg">
<?php echo $translate->__('Gallery Name:');?><BR />
<input name="galleryname" type="text" size="100" maxlength="255" /><BR />
<BR />
<input name="submit" type="submit" value="<?php echo $translate->__('Add Gallery Name');?>" />
<input type="hidden" name="MM_insert" value="addpg" />
</form>
  <p>&nbsp;</p>
<?php echo $translate->__('Current Galleries -');?>
<?php do { ?>
  <form action="" method="get" name="current">
    <?php echo $row_addgallery['gallery_name']; ?>
    
    
  </form>
  <?php } while ($row_addgallery = mysql_fetch_assoc($addgallery)); ?>
<table border="0">
  <tr>
    <td><?php if ($pageNum_addgallery > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_addgallery=%d%s", $currentPage, 0, $queryString_addgallery); ?>"><?php echo $translate->__('First');?></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_addgallery > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_addgallery=%d%s", $currentPage, max(0, $pageNum_addgallery - 1), $queryString_addgallery); ?>"><?php echo $translate->__('Previous');?></a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_addgallery < $totalPages_addgallery) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_addgallery=%d%s", $currentPage, min($totalPages_addgallery, $pageNum_addgallery + 1), $queryString_addgallery); ?>"><?php echo $translate->__('Next');?></a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_addgallery < $totalPages_addgallery) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_addgallery=%d%s", $currentPage, $totalPages_addgallery, $queryString_addgallery); ?>"><?php echo $translate->__('Last');?></a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
<?php echo $translate->__('Records');?> <?php echo ($startRow_addgallery + 1) ?> <?php echo $translate->__('to');?> <?php echo min($startRow_addgallery + $maxRows_addgallery, $totalRows_addgallery) ?> <?php echo $translate->__('of');?> <?php echo $totalRows_addgallery ?> </div></div></div>
<?php require("assets/wrapper/footer.php"); ?>
<?php
mysql_free_result($addgallery);
?>
