예제 #1
0
function shareCanvas()
{
    global $db;
    //$rst = array();
    $vid = $_REQUEST['vid'];
    $shareTo = $_REQUEST['shareTo'];
    $sql = "";
    if (substr_count($shareTo, "@") == 0) {
        $sql = "select user_id from colfusion_users where user_login ='******'";
    } else {
        $sql = "select user_id from colfusion_users where user_email ='" . $shareTo . "'";
    }
    $r = $db->get_row($sql);
    $user_id;
    if (is_null($r)) {
        $RST['status'] = 0;
        $RST['msg'] = "Can't find the user.";
    } else {
        $user_id = $r->user_id;
        $canvas;
        if ($_SESSION['Canvases'][$vid] != null) {
            $canvas = unserialize($_SESSION['Canvases'][$_REQUEST['vid']]);
            //$rst = $canvas->shareCanvas($user_id,$_REQUEST['authorization']);
        } else {
            $canvas = Canvas::openCanvas($_REQUEST['vid']);
        }
        if ($canvas == null) {
            $RST['status'] = '0';
            $RST['msg'] = 'No permit or no canvas exists.';
        } else {
            if (is_null($canvas->shareCanvas($user_id, $_REQUEST['authorization']))) {
                $RST['status'] = 0;
                $RST['msg'] = 'Unable to share this canvas to ' . $shareTo;
            } else {
                $RST['status'] = 1;
            }
        }
    }
    echo json_encode($RST);
    error_reporting(E_ALL);
}