예제 #1
0
function deleteDiagramExe()
{
    if (!is_numeric($_SESSION['userId'])) {
        print "Wrong way";
        exit;
    }
    if (!is_numeric($_REQUEST['diagramId'])) {
        print "Wrong diagram id : " . $_REQUEST['diagramId'];
        exit;
    }
    //TODO: usually ONLY the author can delete the diagram
    $d = new Delegate();
    $userdiagram = $d->userdiagramGetByIds($_SESSION['userId'], $_REQUEST['diagramId']);
    if (is_object($userdiagram) && is_numeric($userdiagram->userId)) {
        //delete diagramdata
        $diagramDatas = $d->diagramdataGetByDiagramId($userdiagram->diagramId);
        $storageFolder = getStorageFolder();
        foreach ($diagramDatas as $diagramData) {
            //TODO: we can make more tests here
            unlink($storageFolder . '/' . $diagramData->fileName);
            $d->diagramdataDeleteByDiagramIdAndType($diagramData->diagramId, $diagramData->type);
        }
        //delete all users linked to this diagram
        $userdiagrams = $d->userdiagramGetByDiagramId($userdiagram->diagramId);
        foreach ($userdiagrams as $userdiagram) {
            $d->userdiagramDelete($userdiagram->userId, $userdiagram->diagramId);
        }
        //delete diagram
        if ($d->diagramDelete($userdiagram->diagramId)) {
            addMessage("Diagram deleted");
        } else {
            addError("Diagram could not be deleted from database");
        }
        redirect('../myDiagrams.php');
    } else {
        print 'Error: no right over that diagram';
    }
}
예제 #2
0
function deleteDiagramExe()
{
    if (!is_numeric($_SESSION['userId'])) {
        print "Wrong way";
        exit;
    }
    if (!is_numeric($_REQUEST['diagramId'])) {
        print "Wrong diagram id : " . $_REQUEST['diagramId'];
        exit;
    }
    //TODO: usually ONLY the author can delete the diagram
    $d = new Delegate();
    //    print_r($_REQUEST);
    //    exit();
    //delete diagramdata
    $diagramDatas = $d->diagramdataGetByDiagramId($_REQUEST['diagramId']);
    $storageFolder = getStorageFolder();
    foreach ($diagramDatas as $diagramData) {
        //TODO: we can make more tests here
        unlink($storageFolder . '/' . $diagramData->fileName);
        $d->diagramdataDeleteByDiagramIdAndType($diagramData->diagramId, $diagramData->type);
    }
    //delete diagram
    if ($d->diagramDelete($_REQUEST['diagramId'])) {
        addMessage("Diagram deleted");
    } else {
        addError("Diagram could not be deleted from database");
    }
    redirect('../myDiagrams.php');
}