<?/*
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 'dd.php';
  require_once 'attribute.php';

  $att = new Attribute ($dbi);

  if ($add_att_name) {
    $att->Add ($add_att_name, $add_att_ai, $REMOTE_USER, $attribute_type, $value_group_id);
  }

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

  if ($del) {
    $att->Delete ($del);
  }
?>

<table border=0>

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

<tr>
  <th>&nbsp;</th>
  <th>Attribute Name</th>
  <th>Category Name</th>
  <th>Additional Info</th>
  <th>Attribute_type</th>
</tr>

<?php
  $h = $dbi->parse ('
    select a.attribute_name,
           a.attribute_id,
           a.additional_info,
           vg.value_group_name,
           a.attribute_type
      from attribute a,
           value_group vg
     where a.value_group_id = vg.value_group_id
  order by a.attribute_name
  ');
  $h->execute ();

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

<tr>
  <td>Add:</td>
  <td><input name=add_att_name value="<?php echo $add_att_name;?>"></td>
  <td><select name=value_group_id><?php echo $dd->value_group ($value_group_id); ?>
</select></td>
  <td><input name=add_att_ai   value="<?php echo $add_att_ai;  ?>"></td>
  <td><select name=attribute_type><?php echo $dd->attribute_types ($attribute_type); ?></select></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td align=center><input type=submit name=submit value=Update></td>
</tr>
</table>
</form>
