<?php 
    include_once dirname(__FILE__) . '/../database.php';
    include_once dirname(__FILE__) . '/../global_functions.php';
    
    // attempt to copy all tasks inside of or this particular task to the task requested
    function deleteStatusInfoNodes($db, $userRow, $statusInfoIdsToDelete) {
        try {
            // Determine if we have nodes to delete
            if ($statusInfoIdsToDelete!=null && $statusInfoIdsToDelete!=""){
                // Create a query do delete the selected nodes
                $sql='DELETE FROM taskstatusinfo_initial ' . 
                     'WHERE TaskStatusInfoID IN (' . $statusInfoIdsToDelete . ');';

                // Run the delete query
                $db->queryDB($sql, $userRow, "delete_old_route_nodes Form occurance 1");
            }
        } 
        catch (Exception $exc) {
            // Create the error string to return back to the caller
            return 'ABORT DELETE STATUS INFO NODES (delete_old_route_nodes)::There was an uncaught error while trying to delete nodes.  The exception is: ' . $exc->getMessage() . '. Deletion aborted...';
        }
        
        // If we got here then assume success
        return "";
    }
    
    $db = new Database();
    $db->setupTmsDB();
    
    // Set defaults for the passed in variables
    $sessionID=-1;

    // check the passed in session ID
    if (isset($_GET['sessionID']) ){
        // get the passed in session ID
        $sessionID = $_GET['sessionID'];
    }

    // Attempt to log in with this user
    $currentUser = $db->getLoggedInSessionUser($sessionID);
    if (mysqli_num_rows($currentUser)!=1){
        echo 'ABORT DELETE STATUS INFO NODES (delete_old_route_nodes)::Your session has expired.  ' . 
             'Refresh the page before cleaning this task.';
    }
    else {
        // Attempt to log in with this user
        $userRow = $currentUser->fetch_assoc();
        
        // Set defaults for the passed in variables
        $updateTaskNumber=-1;
        $statusInfoIdsToDelete='';
        // check the passed in Info IDs to delete
        if (isset($_GET['statusInfoIdsToDelete']) ){
            // get the passed in Info IDs to delete
            $statusInfoIdsToDelete = $_GET['statusInfoIdsToDelete'];
        }
        
        // Attempt to delete the nodes they requested
        $returnString=deleteStatusInfoNodes($db, $userRow, $statusInfoIdsToDelete);

        // return the result
        echo $returnString;
    }
    
?>