<?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"] == "select_theme")) {
  $updateSQL = sprintf("UPDATE theme SET theme=%s WHERE id=%s",
                       GetSQLValueString($_POST['theme'], "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));
}

mysql_select_db($database_telmanik_press, $telmanik_press);
$query_current_theme = "SELECT * FROM theme";
$current_theme = mysql_query($query_current_theme, $telmanik_press) or die(mysql_error());
$row_current_theme = mysql_fetch_assoc($current_theme);
$totalRows_current_theme = mysql_num_rows($current_theme);
?>
<?php require("assets/wrapper/header.php"); ?>
<div align="center"><div class="mainlayout">
  <p>&nbsp;</p>
 <p><b><?php echo $translate->__('Themes');?></b></p>
 <p>&nbsp;</p>
 
 <?php
//if ($handle = opendir('../themes')) {
//   $blacklist = array('.', '..', 'index.php');
//demo - $blacklist = array('.', '..', 'somedir', 'somefile.php');
//    while (false !== ($file = readdir($handle))) {
//        if (!in_array($file, $blacklist)) {
//            echo "$file\n";
			//$link =$file;
//			$link = implode("", "", $file);
//        }
//    }
  
//}
?> 



   
<?php echo $translate->__('Your current theme is');?>  <b> <?php echo $row_current_theme['theme']; ?></b><BR /><BR />


<form action="<?php echo $editFormAction; ?>" method="POST" name="select_theme">
<?php echo $translate->__('Please select a theme');?> \/ <BR /><BR />


<!---fake--->


<!-- fake rkskfs--/\-->
<input type="hidden" name="id" id="id" value="1"/>
<!--<select name="theme">
  <option>Please Select</option>
  <option value="test">test</option>
</select>-->

 <?php
    $path = "../themes";
    $handle = opendir($path);
    echo '<select name="theme">';
    while ($file = readdir($handle)) {
    if (substr($file,0,1) != "." ) {
    echo "<option value ='$file'>$file</option>";
    }
    }
    echo '</select>';
    closedir($handle);
    ?>
<input type="hidden" name="MM_update" value="select_theme" />
<input type="submit" name="submit" id="submit" value="<?php echo $translate->__('Update');?>" />
</form><p>&nbsp;</p> 
 
</div>
</div>
<?php require("assets/wrapper/footer.php"); ?>
<?php
mysql_free_result($current_theme);
?>
