*
 * @param  string $user The username, in e-mail address format, to authenticate
 * @param  string $pass The password for the user specified
 * @return Zend_Http_Client
 */
function getClientLoginHttpClient($user, $pass)
{
    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
    return $client;
}
/**
 * Outputs an HTML unordered list (ul), with each list item representing a
 * calendar in the authenticated user's calendar list.
 *
 * @param  Zend_Http_Client $client The authenticated client object
 * @return void
 */
function outputCalendarList($client)
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $calFeed = $gdataCal->getCalendarListFeed();
    echo "<h1>" . $calFeed->title->text . "</h1>\n";
    echo "<ul>\n";
    foreach ($calFeed as $calendar) {
        echo "\t<li>" . $calendar->title->text . "</li>\n";
    }
    echo "</ul>\n";
}
$client = getClientLoginHttpClient("*****@*****.**", "crimsongroups");
$_SESSION["client"] = $client;
                deleteAtomEntryById($client, $argv[4]);
            } else {
                echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " . "<eventId>\n";
            }
            break;
        case 'deleteAtomEntryByUrl':
            if ($argc == 5) {
                $client = getClientLoginHttpClient($argv[2], $argv[3]);
                deleteAtomEntryByUrl($client, $argv[4]);
            } else {
                echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " . "<eventUrl>\n";
            }
            break;
        case 'createEvent':
            if ($argc == 12) {
                $client = getClientLoginHttpClient($argv[2], $argv[3]);
                createEvent($client, $argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9], $argv[10], $argv[11]);
            } else {
                echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " . "<title> <description> <where> " . "<startDate> <startTime> <endDate> <endTime> <tzOffset>\n";
                echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <password> " . "'Tennis with Beth' 'Meet for a quick lesson' 'On the courts' " . "'2008-01-01' '10:00' '2008-01-01' '11:00' '-08'\n";
            }
            break;
    }
} else {
    if (!isset($_SERVER["HTTP_HOST"])) {
        // running from command line, but action left unspecified
        echo "Usage: php {$argv[0]} <action> [<username>] [<password>] " . "[<arg1> <arg2> ...]\n\n";
        echo "Possible action values include:\n" . "outputCalendar\n" . "outputCalendarMagicCookie\n" . "outputCalendarByDateRange\n" . "outputCalendarList\n" . "updateAtomEntry\n" . "deleteAtomEntryById\n" . "deleteAtomEntryByUrl\n" . "createEvent\n";
    } else {
        // running through web server - demonstrate AuthSub
        processPageLoad();
/**
 * Processes loading of this sample code through a web browser.
 *
 * @return void
 */
function runWWWVersion()
{
    session_start();
    // Note that all calls to endHTML() below end script execution!
    // Check to make sure that the user has set a password.
    $p = LOGIN_PASSWORD;
    if (empty($p)) {
        startHTML(false);
        displayPasswordNotSetNotice();
        endHTML();
    }
    // Grab any login credentials that might be waiting in the request
    if (!empty($_POST['password'])) {
        if ($_POST['password'] == LOGIN_PASSWORD) {
            $_SESSION['authenticated'] = 'true';
        } else {
            // Invalid password. Stop and display a login screen.
            startHTML(false);
            requestUserLogin("Incorrect password.");
            endHTML();
        }
    }
    // If the user isn't authenticated, display a login screen
    if (!isset($_SESSION['authenticated'])) {
        startHTML(false);
        requestUserLogin();
        endHTML();
    }
    // Try to login. If login fails, log the user out and display an
    // error message.
    try {
        $client = getClientLoginHttpClient(GAPPS_USERNAME . '@' . GAPPS_DOMAIN, GAPPS_PASSWORD);
        $gapps = new Zend_Gdata_Gapps($client, GAPPS_DOMAIN);
    } catch (Zend_Gdata_App_AuthException $e) {
        session_destroy();
        startHTML(false);
        displayAuthenticationFailedNotice();
        endHTML();
    }
    // Success! We're logged in.
    // First we check for commands that can be submitted either though
    // POST or GET (they don't make any changes).
    if (!empty($_REQUEST['command'])) {
        switch ($_REQUEST['command']) {
            case 'retrieveUser':
                startHTML();
                retrieveUser($gapps, true, $_REQUEST['user']);
                endHTML(true);
            case 'retrieveAllUsers':
                startHTML();
                retrieveAllUsers($gapps, true);
                endHTML(true);
            case 'retrieveNickname':
                startHTML();
                retrieveNickname($gapps, true, $_REQUEST['nickname']);
                endHTML(true);
            case 'retrieveNicknames':
                startHTML();
                retrieveNicknames($gapps, true, $_REQUEST['user']);
                endHTML(true);
            case 'retrieveAllNicknames':
                startHTML();
                retrieveAllNicknames($gapps, true);
                endHTML(true);
            case 'retrieveEmailLists':
                startHTML();
                retrieveEmailLists($gapps, true, $_REQUEST['recipient']);
                endHTML(true);
            case 'retrieveAllEmailLists':
                startHTML();
                retrieveAllEmailLists($gapps, true);
                endHTML(true);
            case 'retrieveAllRecipients':
                startHTML();
                retrieveAllRecipients($gapps, true, $_REQUEST['emailList']);
                endHTML(true);
        }
    }
    // Now we handle the potentially destructive commands, which have to
    // be submitted by POST only.
    if (!empty($_POST['command'])) {
        switch ($_POST['command']) {
            case 'createUser':
                startHTML();
                createUser($gapps, true, $_POST['user'], $_POST['givenName'], $_POST['familyName'], $_POST['pass']);
                endHTML(true);
            case 'updateUserName':
                startHTML();
                updateUserName($gapps, true, $_POST['user'], $_POST['givenName'], $_POST['familyName']);
                endHTML(true);
            case 'updateUserPassword':
                startHTML();
                updateUserPassword($gapps, true, $_POST['user'], $_POST['pass']);
                endHTML(true);
            case 'setUserSuspended':
                if ($_POST['mode'] == 'suspend') {
                    startHTML();
                    suspendUser($gapps, true, $_POST['user']);
                    endHTML(true);
                } elseif ($_POST['mode'] == 'restore') {
                    startHTML();
                    restoreUser($gapps, true, $_POST['user']);
                    endHTML(true);
                } else {
                    header('HTTP/1.1 400 Bad Request');
                    startHTML();
                    echo "<h2>Invalid mode.</h2>\n";
                    echo "<p>Please check your request and try again.</p>";
                    endHTML(true);
                }
            case 'setUserAdmin':
                if ($_POST['mode'] == 'issue') {
                    startHTML();
                    giveUserAdminRights($gapps, true, $_POST['user']);
                    endHTML(true);
                } elseif ($_POST['mode'] == 'revoke') {
                    startHTML();
                    revokeUserAdminRights($gapps, true, $_POST['user']);
                    endHTML(true);
                } else {
                    header('HTTP/1.1 400 Bad Request');
                    startHTML();
                    echo "<h2>Invalid mode.</h2>\n";
                    echo "<p>Please check your request and try again.</p>";
                    endHTML(true);
                }
            case 'setForceChangePassword':
                if ($_POST['mode'] == 'set') {
                    startHTML();
                    setUserMustChangePassword($gapps, true, $_POST['user']);
                    endHTML(true);
                } elseif ($_POST['mode'] == 'clear') {
                    startHTML();
                    clearUserMustChangePassword($gapps, true, $_POST['user']);
                    endHTML(true);
                } else {
                    header('HTTP/1.1 400 Bad Request');
                    startHTML();
                    echo "<h2>Invalid mode.</h2>\n";
                    echo "<p>Please check your request and try again.</p>";
                    endHTML(true);
                }
            case 'deleteUser':
                startHTML();
                deleteUser($gapps, true, $_POST['user']);
                endHTML(true);
            case 'createNickname':
                startHTML();
                createNickname($gapps, true, $_POST['user'], $_POST['nickname']);
                endHTML(true);
            case 'deleteNickname':
                startHTML();
                deleteNickname($gapps, true, $_POST['nickname']);
                endHTML(true);
            case 'createEmailList':
                startHTML();
                createEmailList($gapps, true, $_POST['emailList']);
                endHTML(true);
            case 'deleteEmailList':
                startHTML();
                deleteEmailList($gapps, true, $_POST['emailList']);
                endHTML(true);
            case 'modifySubscription':
                if ($_POST['mode'] == 'subscribe') {
                    startHTML();
                    addRecipientToEmailList($gapps, true, $_POST['recipient'], $_POST['emailList']);
                    endHTML(true);
                } elseif ($_POST['mode'] == 'unsubscribe') {
                    startHTML();
                    removeRecipientFromEmailList($gapps, true, $_POST['recipient'], $_POST['emailList']);
                    endHTML(true);
                } else {
                    header('HTTP/1.1 400 Bad Request');
                    startHTML();
                    echo "<h2>Invalid mode.</h2>\n";
                    echo "<p>Please check your request and try again.</p>";
                    endHTML(true);
                }
        }
    }
    // Check for an invalid command. If so, display an error and exit.
    if (!empty($_REQUEST['command'])) {
        header('HTTP/1.1 400 Bad Request');
        startHTML();
        echo "<h2>Invalid command.</h2>\n";
        echo "<p>Please check your request and try again.</p>";
        endHTML(true);
    }
    // If a menu parameter is available, display a submenu.
    if (!empty($_REQUEST['menu'])) {
        switch ($_REQUEST['menu']) {
            case 'user':
                startHTML();
                displayUserMenu();
                endHTML();
            case 'nickname':
                startHTML();
                displayNicknameMenu();
                endHTML();
            case 'emailList':
                startHTML();
                displayEmailListMenu();
                endHTML();
            case 'logout':
                startHTML(false);
                logout();
                endHTML();
            default:
                header('HTTP/1.1 400 Bad Request');
                startHTML();
                echo "<h2>Invalid menu selection.</h2>\n";
                echo "<p>Please check your request and try again.</p>";
                endHTML(true);
        }
    }
    // If we get this far, that means there's nothing to do. Display
    // the main menu.
    // If no command was issued and no menu was selected, display the
    // main menu.
    startHTML();
    displayMenu();
    endHTML();
}
示例#4
0
/**
 * Parse command line arguments and execute appropriate function when
 * running from the command line.
 *
 * If no arguments are provided, usage information will be provided.
 *
 * @param array $argv The array of command line arguments provided by PHP.
 *          $argv[0] should be the current executable name or '-' if
 *          not available.
 * @param int $argc The size of $argv.
 */
function runCLIVersion($argv, $argc)
{
    if (isset($argc) && $argc >= 2) {
        # Prepare a server connection
        if ($argc >= 4) {
            try {
                $client = getClientLoginHttpClient($argv[2], $argv[3]);
                $docs = new Zend_Gdata_Docs($client);
            } catch (Zend_Gdata_App_AuthException $e) {
                echo "Error: Unable to authenticate. Please check your";
                echo " credentials.\n";
                exit(1);
            }
        }

        # Dispatch arguments to the desired method
        switch ($argv[1]) {
            case 'retrieveAllDocuments':
                if ($argc >= 4) {
                    retrieveAllDocuments($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the documents in the user's";
                    echo " account.\n";
                }
                break;
            case 'retrieveWPDocs':
                if ($argc >= 4) {
                    //echo "!WP Docs:";
                    //var_dump($docs);
                    retrieveWPDocs($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the word processing documents in";
                    echo " the user's account.\n";
                }
                break;
            case 'retrieveSpreadsheets':
                if ($argc >= 4) {
                    retrieveAllDocuments($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the spreadsheets in the user's";
                    echo " account.\n";
                }
                break;
            case 'fullTextSearch':
                if ($argc >= 4) {
                    // Combine all of the query args into one query string. 
                    // The command line split the query string on space 
                    // characters.
                    $queryString = implode(' ', array_slice($argv, 4));
                    fullTextSearch($docs, false, $queryString);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> <query string>\n\n";
                    echo "This lists all of the documents which contain the";
                    echo " query string.\n";
                }
                break;
            case 'uploadDocument':
                if ($argc >= 5) {
                    // Pass in the file name of the document to be uploaded. 
                    // Since the document is on this machine, we  do not need
                    // to set the temporary file name. The temp file name is
                    // used only when uploading to a webserver.
                    uploadDocument($docs, false, $argv[4], null);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> <file_with_path>\n\n";
                    echo "This lists all of the documents which contain the";
                    echo " query string.\n";
                    echo "\nExample: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> /tmp/testSpreadsheet.ods\n";
                }
                break;
            default:
                // Invalid action entered
                displayHelp($argv[0]);
        // End switch block
        }
    } else {
        // action left unspecified
        displayHelp($argv[0]);
    }
}
 function onAddEntry($data)
 {
     createEvent(getClientLoginHttpClient("*****@*****.**", "noviembre11"), $data['nombre'], "Carrera normal", $data['lugar'], $data['fecha'], '00:00', $data['fecha'], '23:59', '+01');
 }