header($str);
        exit;
    } else {
        //The previous page was display assign papers
        $str = "Location: display_assign_paper.php?back=true&paperID=" . $paperID;
        header($str);
        exit;
    }
}
//Check whether previous page is edit or normal display
if ($_POST["edit"] == "true") {
    //Previous page was edit
    //Get Reviewer of the papers
    $arrEditReviewers = get_Reviewers_Of_Paper($paperID);
    //Call the function to edit the reviewers
    $result = edit_Assigned_Reviewers($paperID, $arrReviewers);
} else {
    //Previous page was not edit
    //Call the function to insert the information to database
    $result = assign_paper($paperID, $arrReviewers);
}
if ($result === true) {
    //Check whether previous page is edit or normal display
    if ($_POST["edit"] == "true") {
        do_html_header("Successful Assignment");
        echo "<br><br>The following paper was successfully edited.<br><br>";
        //Get the paper information
        $paperInfo = get_paper_info($paperID);
        echo "Paper #" . $paperInfo->PaperID . " - " . stripslashes($paperInfo->Title) . "<br><br>";
        if (is_array($arrEditReviewers)) {
            foreach ($arrEditReviewers as $reviewerName) {
        }
        if ($_POST["addReviewer2Paper"] == "true" && $pref == 1) {
            // add the current reviewer to all papers which are in his 1st preference
            $sql = " SELECT P.PaperID FROM " . $GLOBALS["DB_PREFIX"] . "Paper P," . $GLOBALS["DB_PREFIX"] . "PaperStatus PS WHERE P.PaperStatusID = PS.PaperStatusID AND Withdraw = 'false' AND P.TrackID = {$t_id}";
            //echo "<pre>$sql</pre>";
            $paperResult = $db->Execute($sql);
            if (!$paperResult) {
                echo "Could not retrieve the papers' information - please try again later";
                exit;
            }
            while ($paperInfo = $paperResult->FetchNextObj()) {
                $paperID = $paperInfo->PaperID;
                $reviewers = get_Reviewers_Of_Paper($paperID);
                if (!is_array($reviewers)) {
                    // up to now, no reviewers present for this paper
                    assign_paper($paperID, array($Reviewer[$r_value]));
                } else {
                    // add current reviewer
                    $reviewers[] = $Reviewer[$r_value];
                    edit_Assigned_Reviewers($paperID, $reviewers);
                }
            }
        }
    }
}
?>



<?php 
do_html_footer();