Пример #1
0
function firstSaveExe()
{
    if (!is_numeric($_SESSION['userId'])) {
        print "Wrong way";
        exit;
    }
    //store current time
    $nowIsNow = now();
    //save Diagram
    $diagram = new Diagram();
    $diagram->title = trim($_REQUEST['title']);
    $diagram->description = trim($_REQUEST['description']);
    $diagram->public = $_REQUEST['public'] == true ? true : false;
    $diagram->createdDate = $nowIsNow;
    $diagram->lastUpdate = $nowIsNow;
    $diagram->size = strlen($_SESSION['tempDiagram']);
    //TODO: it might be not very accurate
    $delegate = new Delegate();
    $token = '';
    do {
        $token = generateRandom(6);
    } while ($delegate->diagramCountByHash($token) > 0);
    $diagram->hash = $token;
    $diagramId = $delegate->diagramCreate($diagram);
    //end save Diagram
    //create Dia file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_DIA;
    $diagramdata->fileName = $diagramId . '.dia';
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.dia', 'w');
    $size = fwrite($fh, $_SESSION['tempDiagram']);
    fclose($fh);
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end Dia file
    //create SVG file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_SVG;
    $diagramdata->fileName = $diagramId . '.svg';
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.svg', 'w');
    $size = fwrite($fh, $_SESSION['tempSVG']);
    fclose($fh);
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end SVG file
    //clean temporary diagram
    unset($_SESSION['tempDiagram']);
    unset($_SESSION['tempSVG']);
    //attach it to an user
    $userdiagram = new Userdiagram();
    $userdiagram->diagramId = $diagramId;
    $userdiagram->userId = $_SESSION['userId'];
    $userdiagram->invitedDate = now();
    $userdiagram->level = Userdiagram::LEVEL_AUTHOR;
    $userdiagram->status = Userdiagram::STATUS_ACCEPTED;
    $delegate->userdiagramCreate($userdiagram);
    redirect("../editor.php?diagramId=" . $diagramId);
}
Пример #2
0
     #exit();
     $output = shell_exec($command);
     #print $command . ':' . $output;
     #exit();
     //end conversion
     $pngFileSize = filesize($pngPath);
     //see if we need to create the PNG data (first time)
     if (!is_object($pngData)) {
         //create
         $pngData = new Diagramdata();
         $pngData->diagramId = $diagram->id;
         $pngData->type = Diagramdata::TYPE_PNG;
         $pngData->fileName = $diagram->id . '.' . 'png';
         $pngData->fileSize = $pngFileSize;
         $pngData->lastUpdate = $nowIsNow;
         $delegate->diagramdataCreate($pngData);
     } else {
         //Update
         $pngData->fileSize = $pngFileSize;
         $pngData->lastUpdate = $nowIsNow;
         $delegate->diagramdataUpdate($pngData);
     }
 }
 if ($display) {
     //load png binary data
     $handle = fopen($pngPath, "rb");
     //        print "$pngPath:" . filesize($pngPath);
     $contents = fread($handle, filesize($pngPath));
     fclose($handle);
     //end load png binray data
     //print data
Пример #3
0
function firstSaveExe()
{
    //    print_r($_SESSION);
    //    exit();
    if (!is_numeric($_SESSION['userId'])) {
        print "Wrong way";
        exit;
    }
    //store current time
    $nowIsNow = now();
    //save Diagram
    $diagram = new Diagram();
    $diagram->title = trim($_REQUEST['title']);
    $diagram->description = trim($_REQUEST['description']);
    $diagram->public = isset($_REQUEST['public']) && $_REQUEST['public'] == 'true' ? 1 : 0;
    $diagram->createdDate = $nowIsNow;
    $diagram->lastUpdate = $nowIsNow;
    $diagram->size = strlen($_SESSION['tempDiagram']);
    //TODO: it might be not very accurate
    $delegate = new Delegate();
    //    $token = '';
    //    do {
    //        $token = generateRandom(6);
    //    } while ($delegate->diagramCountByHash($token) > 0);
    //
    //    $diagram->hash = $token;
    $diagramId = $delegate->diagramCreate($diagram);
    //end save Diagram
    //create Dia file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_DMO;
    $diagramdata->fileName = $diagramId . '.dmo';
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.dmo', 'w');
    $size = fwrite($fh, $_SESSION['tempDiagram']);
    fclose($fh);
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end Dia file
    /*
    //create SVG file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_SVG;
    $diagramdata->fileName = $diagramId . '.svg';
    
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.svg', 'w');
    $size = fwrite($fh, $_SESSION['tempSVG']);
    fclose($fh);
    
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end SVG file
    */
    //create PNG file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_PNG;
    $diagramdata->fileName = $diagramId . '.png';
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.png', 'wb');
    $data = substr($_SESSION['tempPNG'], strpos($_SESSION['tempPNG'], ','));
    $imgData = base64_decode($data);
    $size = fwrite($fh, $imgData);
    fclose($fh);
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end PNG file
    //create CSV file
    $diagramdata = new Diagramdata();
    $diagramdata->diagramId = $diagramId;
    $diagramdata->type = Diagramdata::TYPE_CSV;
    $diagramdata->fileName = $diagramId . '.csv';
    $fh = fopen(getStorageFolder() . '/' . $diagramId . '.csv', 'w');
    $size = fwrite($fh, $_SESSION['tempLinkMap']);
    fclose($fh);
    $diagramdata->fileSize = $size;
    $diagramdata->lastUpdate = $nowIsNow;
    $delegate->diagramdataCreate($diagramdata);
    //end CSV file
    //clean temporary diagram
    unset($_SESSION['tempDiagram']);
    unset($_SESSION['tempSVG']);
    unset($_SESSION['tempPNG']);
    unset($_SESSION['tempLinkMap']);
    redirect("../editor.php?diagramId=" . $diagramId);
}