<?
  include_once("config.php");

  $link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die ("Could not connect");

  @mysql_select_db(DB_NAME, $link);
  
function admin_step1() {

  $r=mysql_query("select name from blog_templates");

?>
<center><h1>Edit Templates</h1></center>
<form action="admin.php?step=2" method="post">
<table width="100%">
<?php
 for ($i=1;$i<=10;$i++) {
   list($name)=mysql_fetch_row($r);
   $template_name[$i]=$name;

?>
 <tr>
  <td width="10%">
  </td>
  <td width="30%" valign="top" align="right">
   Template <?php echo "$i"; ?> name :<br>
  </td>
  <td>
   <input type="text" name="template[<?php echo "$i"; ?>]" value="<?php echo "$template_name[$i]"; ?>" size="30">
  </td>
 </tr>

<?php
 }
?>

</table>
<center><br><input type="submit" value="  Update  "></center>
</form>
<? 
    return(0);
  }

function admin_step2() {
    global $link;

    $template_name = $_POST['template'];

    for ($i=1;$i<=10;$i++) {
      $r=mysql_query("update blog_templates set name='".mysql_escape_string($template_name[$i])."' where id='$i'",$link);
    }
    if (!$r) {
      echo mysql_error();
    }

    admin_step1();
 
    return(0);
  }

  if (isset($_GET['step'])) {
    admin_step2();
  }
  else {
    admin_step1();
  }  

?>