BaseEventTypeController::actionSaveCanvasImages PHP Method

actionSaveCanvasImages() public method

public actionSaveCanvasImages ( $id )
    public function actionSaveCanvasImages($id)
    {
        if (!($event = Event::model()->findByPk($id))) {
            throw new Exception("Event not found: {$id}");
        }
        if (strtotime($event->last_modified_date) != @$_POST['last_modified_date']) {
            echo 'outofdate';
            return;
        }
        $event->lock();
        if (!file_exists($event->imageDirectory)) {
            if (!@mkdir($event->imageDirectory, 0755, true)) {
                throw new Exception("Unable to create directory: {$event->imageDirectory}");
            }
        }
        if (!empty($_POST['canvas'])) {
            foreach ($_POST['canvas'] as $drawingName => $blob) {
                if (!file_exists($event->imageDirectory . "/{$drawingName}.png")) {
                    if (!@file_put_contents($event->imageDirectory . "/{$drawingName}.png", base64_decode(preg_replace('/^data\\:image\\/png;base64,/', '', $blob)))) {
                        throw new Exception("Failed to write to {$event->imageDirectory}/{$drawingName}.png: check permissions.");
                    }
                }
            }
        }
        ob_start();
        $this->actionPrint($id, false);
        $html = ob_get_contents();
        ob_end_clean();
        $event->unlock();
        $this->printLog($id, false);
        // Verify we have all the images by detecting eyedraw canvas elements in the page.
        // If we don't, the "outofdate" response will trigger a page-refresh so we can re-send the canvas elements to the
        // server as PNGs.
        if (preg_match('/<canvas.*?class="ed-canvas-display"/is', $html)) {
            echo 'outofdate';
            return;
        }
        echo 'ok';
    }
BaseEventTypeController