#
# You should have received a copy of the GNU
# 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: milestone_edit.php,v 1.3 2005/02/19 16:53:34 filetreefrog Exp $
##################################################
if (!defined("PATHOS")) {
    exit("");
}
$milestone = null;
if (isset($_GET['id'])) {
    $milestone = $db->selectObject("codemap_milestone", "id=" . $_GET['id']);
}
if ($milestone) {
    $loc = unserialize($milestone->location_data);
}
if (pathos_permissions_check("manage_miles", $loc)) {
    $form = codemap_milestone::form($milestone);
    $form->location($loc);
    $form->meta("action", "milestone_save");
    $template = new template("codemapmodule", "_form_editMilestone");
    $template->assign("is_edit", $milestone == null ? 0 : 1);
    $template->assign("form_html", $form->toHTML());
    $template->output();
}
# not, write to:
#
# Free Software Foundation, Inc.,
# 59 Temple Place,
# Suite 330,
# Boston, MA 02111-1307  USA
#
# $Id: milestone_save.php,v 1.3 2005/02/19 16:53:34 filetreefrog Exp $
##################################################
if (!defined("PATHOS")) {
    exit("");
}
$milestone = null;
if (isset($_POST['id'])) {
    $milestone = $db->selectObject("codemap_milestone", "id=" . $_POST['id']);
}
if ($milestone) {
    $loc = unserialize($milestone->location_data);
}
if (pathos_permissions_check("manage_miles", $loc)) {
    $milestone = codemap_milestone::update($_POST, $milestone);
    $milestone->rank = $db->max("codemap_milestone", "rank", "location_data", "location_data='" . serialize($loc) . "'") + 1;
    $milestone->location_data = serialize($loc);
    if (isset($milestone->id)) {
        $db->updateObject($milestone, "codemap_milestone");
    } else {
        $milestone->rank = $db->max("codemap_milestone", "rank", "location_data", "location_data='" . serialize($loc) . "'") + 1;
        $db->insertObject($milestone, "codemap_milestone");
    }
    pathos_flow_redirect();
}