<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

AthenaRMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/?>
<?php
  require_once 'value_group.php';

  $vgm = new Value_Group_Member ($dbi);
  $vg = new Value_Group ($dbi);

  if ($add_cat_name) {
    $vg->Add ($add_cat_name, $ai, $REMOTE_USER);
  }

  if ($submit) {
    foreach ($new as $vgmid => $ary_ref) {
      if (($old[$vgmid][name] != $ary_ref[name]) or
          ($old[$vgmid][ai] != $ary_ref[ai])) {
        $vgm->Update ($vgmid, $ary_ref[name], $ary_ref[ai], $REMOTE_USER);
      }
    }
  }

  if ($del) {
    $vgm->Delete ($del);
  }

  if ($add_opt_val) {
    $vgm->Add ($value_group_id, $add_opt_val, '', $add_opt_ai, $REMOTE_USER);
  }
?>

<table border=0>

<form method=post action="<?php echo $SCRIPT_NAME;?>">

<tr>
  <td colspan=2>Value Group:<select name=value_group_id>
<?php
  include 'dd.php';
  echo $dd->value_group ($value_group_id);
?>
</select>
    <input type="submit" value="Go"> <a href="<?php echo $SCRIPT_NAME;?>">Add New Category</a></td>
</tr>

<?php if (!$value_group_id) : ?>
</form>
<form method=post action="<?php echo $SCRIPT_NAME;?>">

<tr>
  <th colspan=2>Create Category</th>
</tr>
<tr>
  <td>Cat. Name:</td>
  <td><input name=add_cat_name value="<?php echo $add_cat_name;?>"></td>
</tr>
<tr>
  <td>Add. Info.:</td>
  <td><input name=add_cat_ai value="<?php echo $add_cat_ai;?>"></select>
    <input type="submit" name="submit" value="Create" /></td>
</tr>
<?php endif; ?>

</form>
</table>

<?php if (!$value_group_id) { return; } ?>

<table border=0>
<form method=post action="<?php echo $SCRIPT_NAME;?>">
<input type=hidden name=value_group_id value="<?php echo $value_group_id;?>">

<tr>
  <th>&nbsp;</th>
  <th>Option Value</th>
  <th>Additional Info</th>
</tr>

<?php
  $h = $dbi->parse ('
    select member_id,
           member_name,
           additional_info
      from value_group_members 
     where value_group_id = ?
  order by member_name
  ');
  $h->execute ($value_group_id);

  while ($r = $h->fetch_row ()) {
    echo "<input type=hidden name=\"old[$r[0]][name]\" value=\"$r[1]\">\n";
    echo "<input type=hidden name=\"old[$r[0]][ai]\" value=\"$r[2]\">\n";
    echo "<tr>\n";
    echo "  <td><a href=\"$SCRIPT_NAME?del=$r[0]&value_group_id=$value_group_id\">Del</a></td>\n";
    echo "  <td><input name=\"new[$r[0]][name]\" value=\"$r[1]\"></td>\n";
    echo "  <td><input name=\"new[$r[0]][ai]\" value=\"$r[2]\"></td>\n";
    echo "</tr>\n";
  }
?>

<tr>
  <td>Add:</td>
  <td><input name=add_opt_val value="<?php echo $add_opt_val;?>"></td>
  <td><input name=add_opt_ai  value="<?php echo $add_opt_ai; ?>"></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td align=center><input type=submit name=submit value=Update></td>
</tr>
</table>
</form>
