# General Public License along with Exponent; if
# not, write to:
#
# Free Software Foundation, Inc.,
# 59 Temple Place,
# Suite 330,
# Boston, MA 02111-1307  USA
#
# $Id: stepstone_save.php,v 1.3 2005/02/19 16:53:34 filetreefrog Exp $
##################################################
if (!defined("PATHOS")) {
    exit("");
}
$stepstone = null;
if (isset($_POST['id'])) {
    $stepstone = $db->selectObject("codemap_stepstone", "id=" . $_POST['id']);
}
if ($stepstone) {
    $loc = unserialize($stepstone->location_data);
}
if (pathos_permissions_check("manage_steps", $loc)) {
    $stepstone = codemap_stepstone::update($_POST, $stepstone);
    $stepstone->milestone_id = $_POST['milestone_id'];
    $stepstone->location_data = serialize($loc);
    if (isset($stepstone->id)) {
        $db->updateObject($stepstone, "codemap_stepstone");
    } else {
        $db->insertObject($stepstone, "codemap_stepstone");
    }
    pathos_flow_redirect();
}
# 59 Temple Place,
# Suite 330,
# Boston, MA 02111-1307  USA
#
# $Id: stepstone_edit.php,v 1.3 2005/02/19 16:53:34 filetreefrog Exp $
##################################################
if (!defined("PATHOS")) {
    exit("");
}
$stepstone = null;
if (isset($_GET['id'])) {
    $stepstone = $db->selectObject("codemap_stepstone", "id=" . $_GET['id']);
}
if ($stepstone) {
    $loc = unserialize($stepstone->location_data);
}
if (pathos_permissions_check("manage_steps", $loc)) {
    $form = codemap_stepstone::form($stepstone);
    $list = array();
    foreach ($db->selectObjects("codemap_milestone", "location_data='" . serialize($loc) . "'") as $m) {
        $list[$m->id] = $m->name;
    }
    uasort($list, "strnatcmp");
    $form->registerBefore("submit", "milestone_id", "Target Milestone", new dropdowncontrol($stepstone ? $stepstone->milestone_id : 0, $list));
    $form->location($loc);
    $form->meta("action", "stepstone_save");
    $template = new template("codemapmodule", "_form_editStepstone");
    $template->assign("is_edit", $stepstone == null ? 0 : 1);
    $template->assign("form_html", $form->toHTML());
    $template->output();
}