Beispiel #1
0
<?php

require_once dirname(__FILE__) . '/../includes/common.inc.php';
require_once dirname(__FILE__) . "/../includes/kaltura/kaltura_functions.php";
require_once dirname(__FILE__) . "/../database/annotations.php";
startSession();
$userID = $_SESSION['user_id'];
$userName = $_SESSION['name'];
//print "hello";
$annotationIDs = array();
$annotationDB = new annotationsDB();
//$annotations->truncateTable();
//$annotationsCount = $annotations->countAnnotations();
//print "There are $annotationsCount annotation(s) in total.<br /><br />";
$id = $_POST['id'];
$videoAnnotationID = $_POST['video_annotation_id'];
/*
print "POST vars:";
foreach ($_POST as $key=>$val) {
    print "$key:$val\n";
}
print "videoAnnotationID: $videoAnnotationID";
*/
$annotationDB->deleteAnnotation($id, $userID);
$annotationDB->close();
Beispiel #2
0
function handleCleanAnnotations()
{
    global $classID, $className, $classes, $configFolderName, $dbConnection;
    global $session, $department, $courseNo, $sectionNo, $season;
    global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
    global $command, $commandState;
    // get the command itself
    $command = Commands::CleanAnnotations;
    // get the state of the command
    if (array_key_exists("execute", $_POST)) {
        $commandState = CommandStates::Execute;
    } else {
        if (array_key_exists("previewThenExecute", $_POST)) {
            $commandState = CommandStates::PreviewThenExecute;
        } else {
            $commandState = CommandStates::Preview;
        }
    }
    printOutputPageHeading($commandState);
    if (!empty($_POST)) {
        // reading and checking params for the command
        if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
            $errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
        } else {
            $session = $_POST['session'];
            $season = $_POST['season'];
        }
        populateCourseInfoFromPOST();
        printCourseInfo($commandState, $className, $configFolderName, $session, $department, $courseNo, $sectionNo, $season);
        $media = new media();
        $annotationsDB = new annotationsDB();
        $nothingToDo = false;
        $oldAnnotationsAndComments = array();
        $videosInCourse = $media->getVideosByClassID($classID);
        if (!empty($videosInCourse)) {
            $videosInCourseCount = count($videosInCourse);
            foreach ($videosInCourse as $video) {
                $videosInCourseText[] = "ID:" . $video['video_id'] . " Title:\"" . $video['title'] . "\" Length:" . $video['duration'] . "\n";
                $oldAnnotationCollections[] = $annotationsDB->getAnnotations($video['video_id'], null, true, ALL);
            }
            foreach ($oldAnnotationCollections as $annotationCollection) {
                if (!empty($annotationCollection)) {
                    foreach ($annotationCollection as $annotation) {
                        $oldAnnotationsAndComments[] = $annotation;
                    }
                }
            }
            if ($commandState == CommandStates::Preview) {
                print "<br/><b>There are {$videosInCourseCount} videos in course {$className}.</b><br/>";
                DEBUG_printSimpleArray($videosInCourseText, 8, 70, "\n");
                print "<br/>";
            }
            print "<br/>";
            if (empty($oldAnnotationsAndComments)) {
                print "<b>There is no active annotations and general comments in this course. Nothing to do.</b><br/><br/>";
                $nothingToDo = true;
            } else {
                $oldAnnotationsAndCommentsCount = count($oldAnnotationsAndComments);
                if ($commandState == CommandStates::Preview) {
                    print "<b>There are {$oldAnnotationsAndCommentsCount} annotations and general comments\r\n\t\t\t\t\tfor {$videosInCourseCount} VIDEOs in course {$className}. Please verify before deleting.</b><br/>";
                    print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                    print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                    foreach ($oldAnnotationsAndComments as $annotation) {
                        if (!is_null($annotation)) {
                            if ($annotation['is_private'] == 0) {
                                print "Annotation ID " . $annotation['annotation_id'] . " User " . $annotation['user_name'] . " Date " . $annotation['creation_date'] . " Content '" . $annotation['description'] . "' Tags '" . $annotation['tags'];
                            }
                        } else {
                            print "<span style=\"color:red\">null entry. Could be a bug.</span>";
                        }
                        print "<br/>";
                    }
                    print "</div></div>";
                }
            }
        } else {
            print "<b>There is no videos in this course yet. Nothing to do.</b><br/><br/>";
            $nothingToDo = true;
        }
        if (empty($errors)) {
            if (!$nothingToDo) {
                if ($commandState == CommandStates::Execute || $commandState == CommandStates::PreviewThenExecute) {
                    print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                    print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                    foreach ($oldAnnotationsAndComments as $annotation) {
                        $annotationID = $annotation['annotation_id'];
                        $result = $annotationsDB->deleteAnnotation($annotationID);
                        UTIL_printQueryResultNicely("delete annotation " . $annotationID, $result, $dbConnection);
                    }
                    if (empty($oldAnnotationsAndComments)) {
                        print "???";
                    }
                    print "</div></div>";
                    print "<br/><b>STOP! Please check the database query outputs to make sure that everything is\r\n\t\t\t\t\t\t\t<span style=\"color:green;\">green</span>\r\n\t\t\t\t\t\t\tbefore finishing.\r\n\t\t\t\t\t\t\t</b><br/>";
                    print "<br/><span style=\"color:blue;font-weight:bold;\">\r\n\t\t\t\t\t\t\tIf you are cleaning annotations for a new term (so that you can reuse the same videos in a course)<br/>\r\n\t\t\t\t\t\t\tYou might also want to update the enrollment list afterward.\r\n\t\t\t\t\t\t\t</span>\r\n\t\t\t\t\t\t\t<br/><br/>";
                    printOutputPageFooting(CommandStates::Execute, $className);
                } else {
                    if ($commandState == CommandStates::Preview) {
                        printExecuteRemoveAnnotationsForm($classID, $session, $season, "Go Ahead and Execute the Annotations Removal");
                        printOutputPageFooting(CommandStates::Preview, $className);
                    }
                }
            } else {
                printOutputPageFooting(CommandStates::Preview, $className);
            }
        } else {
            print "{$errors}";
            printOutputPageFooting(CommandStates::Error, $className);
        }
        $media->close();
        $annotationsDB->close();
    } else {
        print "<br/><span style=\"color:red;font-weight:bold\">\r\n\t\t\t\tFATAL ERROR! POST parameter list empty. You may have found a bug.<br/>\r\n\t\t\t\tPlease email thomas.dang@ubc.ca with as much info as possible of the context when this error appears.<br/>\r\n\t\t\t\t</span>\r\n\t\t\t\t<br/>";
        printOutputPageFooting(CommandStates::Error, $className);
    }
}