<?/*
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
*/?>
<div class="athenatitleshadow">Edit Problem Types<div class="athenatitle">Edit Problem Types</div></div>
<br />
<font color="red">Make sure you have at least 1 source otherwise your RMS won't work.</font>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
  require_once 'dd.php';
  require_once 'problem_type.php';
  require_once 'server_functions.php';

  globalize_request_keys('add_ptype', 'selected', 'action', 'to_ptype');

  $problem_type = new Problem_Type ();

  if ($add_ptype) {
    $prob_id = $problem_type->Add (array (
      'problem_type' => $add_ptype,
      'updated_by' => $REMOTE_USER,
    ));
  }

  if (!$selected) $selected = array ();

  if ($action == 'Delete Selected') {
    foreach ($selected as $del) {
      if (!$problem_type->Delete ($del)) print "Unable to delete $del.<br />\n";
    }

  } elseif ($action == 'Move Selected') {
    foreach ($selected as $move) {
      if (!$problem_type->Move ($move, $to_ptype)) print "Unable to move $move to $to_type.<r />\n";
    }

  } elseif ($action == 'Remove from Drop-downs') {
    foreach ($selected as $move) {
      $pt_rec = $problem_type->Select_by_Problem_Type ($move);
      $pt_rec->Set ('in_drop_downs', 'N');
      $pt_rec->Update ();
    }

  } elseif ($action == 'Add to Drop-downs') {
    foreach ($selected as $move) {
      $pt_rec = $problem_type->Select_by_Problem_Type ($move);
      $pt_rec->Set ('in_drop_downs', 'Y');
      $pt_rec->Update ();
    }
  }

  $prob_list = $problem_type->List_All ();

  foreach ($prob_list as $ptype) {
    list ($pid, $ptype, $indd) = $ptype;
    $check = '';
    if (in_array ($pid, $selected)) $check = ' checked="checked"';
    print '<input type="checkbox" name="selected[]" value="'.$pid."\" $check />$ptype<br />\n";
  }
?>
<br />
<input type="submit" name="action" value="Delete Selected" /> or
<br /><br />
<input type="submit" name="action" value="Remove from Drop-downs" /> or
<br><br>
<input type="submit" name="action" value="Add to Drop-downs" /> or
<br><br>
<input type="submit" name="action" value="Move Selected" /> to <select name="to_ptype"><?php echo $dd->problem_types ($to_ptype); ?></select>
<br><br>
<input type="submit" name="action" value="Add" /> <input type="text" name="add_ptype" />
</form>
