PageRenderTime 769ms CodeModel.GetById 112ms app.highlight 552ms RepoModel.GetById 92ms app.codeStats 1ms

/public/zf-demos/Zend/Gdata/Gapps.php

https://bitbucket.org/hieronim1981/tunethemusic
PHP | 1992 lines | 1502 code | 121 blank | 369 comment | 183 complexity | 29cd901faa83329e30bd85e22be50995 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * Zend Framework
   4 *
   5 * LICENSE
   6 *
   7 * This source file is subject to the new BSD license that is bundled
   8 * with this package in the file LICENSE.txt.
   9 * It is also available through the world-wide-web at this URL:
  10 * http://framework.zend.com/license/new-bsd
  11 * If you did not receive a copy of the license and are unable to
  12 * obtain it through the world-wide-web, please send an email
  13 * to license@zend.com so we can send you a copy immediately.
  14 *
  15 * @category   Zend
  16 * @package    Zend_Gdata
  17 * @subpackage Demos
  18 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20 */
  21
  22/**
  23 * PHP sample code for the Google Calendar data API.  Utilizes the
  24 * Zend Framework Gdata components to communicate with the Google API.
  25 *
  26 * Requires the Zend Framework Gdata components and PHP >= 5.1.4
  27 *
  28 * You can run this sample both from the command line (CLI) and also
  29 * from a web browser.  Run this script without any command line options to
  30 * see usage, eg:
  31 *     /usr/bin/env php Gapps.php
  32 *
  33 * More information on the Command Line Interface is available at:
  34 *     http://www.php.net/features.commandline
  35 *
  36 * When running this code from a web browser, be sure to fill in your
  37 * Google Apps credentials below and choose a password for authentication
  38 * via the web browser.
  39 *
  40 * Since this is a demo, only minimal error handling and input validation
  41 * are performed. THIS CODE IS FOR DEMONSTRATION PURPOSES ONLY. NOT TO BE
  42 * USED IN A PRODUCTION ENVIRONMENT.
  43 *
  44 * NOTE: You must ensure that Zend Framework is in your PHP include
  45 * path.  You can do this via php.ini settings, or by modifying the
  46 * argument to set_include_path in the code below.
  47 */
  48
  49// ************************ BEGIN WWW CONFIGURATION ************************
  50
  51/**
  52 * Google Apps username. This is the username (without domain) used
  53 * to administer your Google Apps account. This value is only
  54 * used when accessing this demo on a web server.
  55 *
  56 * For example, if you login to Google Apps as 'foo@bar.com.inavlid',
  57 * your username is 'foo'.
  58 */
  59define('GAPPS_USERNAME', 'username');
  60
  61/**
  62 * Google Apps domain. This is the domain associated with your
  63 * Google Apps account. This value is only used when accessing this demo
  64 * on a web server.
  65 *
  66 * For example, if you login to Google Apps as foo@bar.com.inavlid,
  67 * your domain is 'bar.com.invalid'.
  68 */
  69define('GAPPS_DOMAIN', 'example.com.invalid');
  70
  71/**
  72 * Google Apps password. This is the password associated with the above
  73 * username. This value is only used when accessing this demo on a
  74 * web server.
  75 */
  76define('GAPPS_PASSWORD', 'your password here');
  77
  78/**
  79 * Login password. This password is used to protect your account from
  80 * unauthorized access when running this demo on a web server.
  81 *
  82 * If this field is blank, all access will be denied. A blank password
  83 * field is not the same as no password (which is disallowed for
  84 * security reasons).
  85 *
  86 * NOTE: While we could technically just ask the user for their Google Apps
  87 *       credentials, the ClientLogin API is not intended for direct use by
  88 *       web applications. If you are the only user of the application, this
  89 *       is fine--- but you should not ask other users to enter their
  90 *       credentials via your web application.
  91 */
  92define('LOGIN_PASSWORD', '');
  93
  94// ************************* END WWW CONFIGURATION *************************
  95
  96/**
  97 * @see Zend_Loader
  98 */
  99require_once 'Zend/Loader.php';
 100
 101/**
 102 * @see Zend_Gdata
 103 */
 104Zend_Loader::loadClass('Zend_Gdata');
 105
 106/**
 107 * @see Zend_Gdata_ClientLogin
 108 */
 109Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
 110
 111/**
 112 * @see Zend_Gdata_Gapps
 113 */
 114Zend_Loader::loadClass('Zend_Gdata_Gapps');
 115
 116/**
 117 * Returns a HTTP client object with the appropriate headers for communicating
 118 * with Google using the ClientLogin credentials supplied.
 119 *
 120 * @param  string $user The username, in e-mail address format, to authenticate
 121 * @param  string $pass The password for the user specified
 122 * @return Zend_Http_Client
 123 */
 124function getClientLoginHttpClient($user, $pass)
 125{
 126  $service = Zend_Gdata_Gapps::AUTH_SERVICE_NAME;
 127  $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
 128  return $client;
 129}
 130
 131/**
 132 * Creates a new user for the current domain. The user will be created
 133 * without admin privileges.
 134 *
 135 * @param  Zend_Gdata_Gapps $gapps      The service object to use for communicating with the Google
 136 *                                      Apps server.
 137 * @param  boolean          $html       True if output should be formatted for display in a web browser.
 138 * @param  string           $username   The desired username for the user.
 139 * @param  string           $givenName  The given name for the user.
 140 * @param  string           $familyName The family name for the user.
 141 * @param  string           $password   The plaintext password for the user.
 142 * @return void
 143 */
 144function createUser($gapps, $html, $username, $givenName, $familyName,
 145        $password)
 146{
 147    if ($html) {echo "<h2>Create User</h2>\n";}
 148    $gapps->createUser($username, $givenName, $familyName,
 149        $password);
 150    if ($html) {echo "<p>Done.</p>\n";}
 151}
 152
 153/**
 154 * Retrieves a user for the current domain by username. Information about
 155 * that user is then output.
 156 *
 157 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google Apps server.
 158 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 159 * @param  string           $username The desired username for the user.
 160 * @return void
 161 */
 162function retrieveUser($gapps, $html, $username)
 163{
 164    if ($html) {echo "<h2>User Information</h2>\n";}
 165
 166    $user = $gapps->retrieveUser($username);
 167
 168    if ($html) {echo '<p>';}
 169
 170    if ($user !== null) {
 171        echo '             Username: ' . $user->login->username;
 172        if ($html) {echo '<br />';}
 173        echo "\n";
 174
 175        echo '           Given Name: ';
 176        if ($html) {
 177            echo htmlspecialchars($user->name->givenName);
 178        } else {
 179            echo $user->name->givenName;
 180        }
 181        if ($html) {echo '<br />';}
 182        echo "\n";
 183
 184        echo '          Family Name: ';
 185        if ($html) {
 186            echo htmlspecialchars($user->name->familyName);
 187        } else {
 188            echo $user->name->familyName;
 189        }
 190        if ($html) {echo '<br />';}
 191        echo "\n";
 192
 193        echo '            Suspended: ' . ($user->login->suspended ? 'Yes' : 'No');
 194        if ($html) {echo '<br />';}
 195        echo "\n";
 196
 197        echo '                Admin: ' . ($user->login->admin ? 'Yes' : 'No');
 198        if ($html) {echo '<br />';}
 199        echo "\n";
 200
 201        echo ' Must Change Password: ' .
 202            ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No');
 203        if ($html) {echo '<br />';}
 204        echo "\n";
 205
 206        echo '  Has Agreed To Terms: ' .
 207            ($user->login->agreedToTerms ? 'Yes' : 'No');
 208
 209    } else {
 210        echo 'Error: Specified user not found.';
 211    }
 212    if ($html) {echo '</p>';}
 213    echo "\n";
 214}
 215
 216/**
 217 * Retrieves the list of users for the current domain and outputs
 218 * that list.
 219 *
 220 * @param  Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google Apps server.
 221 * @param  boolean          $html  True if output should be formatted for display in a web browser.
 222 * @return void
 223 */
 224function retrieveAllUsers($gapps, $html)
 225{
 226    if ($html) {echo "<h2>Registered Users</h2>\n";}
 227
 228    $feed = $gapps->retrieveAllUsers();
 229
 230    if ($html) {echo "<ul>\n";}
 231
 232    foreach ($feed as $user) {
 233        if ($html) {
 234            echo "  <li>";
 235        } else {
 236            echo "  * ";
 237        }
 238        echo $user->login->username . ' (';
 239        if ($html) {
 240            echo htmlspecialchars($user->name->givenName . ' ' .
 241                $user->name->familyName);
 242        } else {
 243            echo $user->name->givenName . ' ' . $user->name->familyName;
 244        }
 245        echo ')';
 246        if ($html) {echo '</li>';}
 247        echo "\n";
 248    }
 249    if ($html) {echo "</ul>\n";}
 250}
 251
 252/**
 253 * Change the name for an existing user.
 254 *
 255 * @param  Zend_Gdata_Gapps $gapps         The service object to use for communicating with the Google
 256 *                                         Apps server.
 257 * @param  boolean          $html          True if output should be formatted for display in a web browser.
 258 * @param  string           $username      The username which should be updated
 259 * @param  string           $newGivenName  The new given name for the user.
 260 * @param  string           $newFamilyName The new family name for the user.
 261 * @return void
 262 */
 263function updateUserName($gapps, $html, $username, $newGivenName, $newFamilyName)
 264{
 265    if ($html) {echo "<h2>Update User Name</h2>\n";}
 266
 267    $user = $gapps->retrieveUser($username);
 268
 269    if ($user !== null) {
 270        $user->name->givenName = $newGivenName;
 271        $user->name->familyName = $newFamilyName;
 272        $user->save();
 273    } else {
 274        if ($html) {echo '<p>';}
 275        echo 'Error: Specified user not found.';
 276        if ($html) {echo '</p>';}
 277        echo "\n";
 278    }
 279
 280    if ($html) {echo "<p>Done.</p>\n";}
 281}
 282
 283/**
 284 * Change the password for an existing user.
 285 *
 286 * @param  Zend_Gdata_Gapps $gapps       The service object to use for communicating with the Google
 287 *                                       Apps server.
 288 * @param  boolean          $html        True if output should be formatted for display in a web browser.
 289 * @param  string           $username    The username which should be updated
 290 * @param  string           $newPassword The new password for the user.
 291 * @return void
 292 */
 293function updateUserPassword($gapps, $html, $username, $newPassword)
 294{
 295    if ($html) {echo "<h2>Update User Password</h2>\n";}
 296
 297    $user = $gapps->retrieveUser($username);
 298
 299    if ($user !== null) {
 300        $user->login->password = $newPassword;
 301        $user->save();
 302    } else {
 303        if ($html) {echo '<p>';}
 304        echo 'Error: Specified user not found.';
 305        if ($html) {echo '</p>';}
 306        echo "\n";
 307    }
 308
 309    if ($html) {echo "<p>Done.</p>\n";}
 310}
 311
 312/**
 313 * Suspend a given user. The user will not be able to login until restored.
 314 *
 315 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 316 *                                    Apps server.
 317 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 318 * @param  string           $username The username which should be updated.
 319 * @return void
 320 */
 321function suspendUser($gapps, $html, $username)
 322{
 323    if ($html) {echo "<h2>Suspend User</h2>\n";}
 324
 325    $user = $gapps->retrieveUser($username);
 326
 327    if ($user !== null) {
 328        $user->login->suspended = true;
 329        $user->save();
 330    } else {
 331        if ($html) {echo '<p>';}
 332        echo 'Error: Specified user not found.';
 333        if ($html) {echo '</p>';}
 334        echo "\n";
 335    }
 336
 337    if ($html) {echo "<p>Done.</p>\n";}
 338}
 339
 340/**
 341 * Restore a given user after being suspended.
 342 *
 343 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 344 *                                    Apps server.
 345 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 346 * @param  string           $username The username which should be updated.
 347 * @return void
 348 */
 349function restoreUser($gapps, $html, $username)
 350{
 351    if ($html) {echo "<h2>Restore User</h2>\n";}
 352
 353    $user = $gapps->retrieveUser($username);
 354
 355    if ($user !== null) {
 356        $user->login->suspended = false;
 357        $user->save();
 358    } else {
 359        if ($html) {echo '<p>';}
 360        echo 'Error: Specified user not found.';
 361        if ($html) {echo '</p>';}
 362        echo "\n";
 363    }
 364
 365    if ($html) {echo "<p>Done.</p>\n";}
 366}
 367
 368/**
 369 * Give a user admin rights.
 370 *
 371 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 372 *                                    Apps server.
 373 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 374 * @param  string           $username The username which should be updated.
 375 * @return void
 376 */
 377function giveUserAdminRights($gapps, $html, $username)
 378{
 379    if ($html) {echo "<h2>Grant Administrative Rights</h2>\n";}
 380
 381    $user = $gapps->retrieveUser($username);
 382
 383    if ($user !== null) {
 384        $user->login->admin = true;
 385        $user->save();
 386    } else {
 387        if ($html) {echo '<p>';}
 388        echo 'Error: Specified user not found.';
 389        if ($html) {echo '</p>';}
 390        echo "\n";
 391    }
 392
 393    if ($html) {echo "<p>Done.</p>\n";}
 394}
 395
 396/**
 397 * Revoke a user's admin rights.
 398 *
 399 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 400 *                                    Apps server.
 401 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 402 * @param  string           $username The username which should be updated.
 403 * @return void
 404 */
 405function revokeUserAdminRights($gapps, $html, $username)
 406{
 407    if ($html) {echo "<h2>Revoke Administrative Rights</h2>\n";}
 408
 409    $user = $gapps->retrieveUser($username);
 410
 411    if ($user !== null) {
 412        $user->login->admin = false;
 413        $user->save();
 414    } else {
 415        if ($html) {echo '<p>';}
 416        echo 'Error: Specified user not found.';
 417        if ($html) {echo '</p>';}
 418        echo "\n";
 419    }
 420
 421    if ($html) {echo "<p>Done.</p>\n";}
 422}
 423
 424/**
 425 * Force a user to change their password at next login.
 426 *
 427 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 428 *                                    Apps server.
 429 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 430 * @param  string           $username The username which should be updated.
 431 * @return void
 432 */
 433function setUserMustChangePassword($gapps, $html, $username)
 434{
 435    if ($html) {echo "<h2>Force User To Change Password</h2>\n";}
 436
 437    $user = $gapps->retrieveUser($username);
 438
 439    if ($user !== null) {
 440        $user->login->changePasswordAtNextLogin = true;
 441        $user->save();
 442    } else {
 443        if ($html) {echo '<p>';}
 444        echo 'Error: Specified user not found.';
 445        if ($html) {echo '</p>';}
 446        echo "\n";
 447    }
 448
 449    if ($html) {echo "<p>Done.</p>\n";}
 450}
 451
 452/**
 453 * Undo forcing a user to change their password at next login.
 454 *
 455 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 456 *                                    Apps server.
 457 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 458 * @param  string           $username The username which should be updated.
 459 * @return void
 460 */
 461function clearUserMustChangePassword($gapps, $html, $username)
 462{
 463    if ($html) {echo "<h2>Undo Force User To Change Password</h2>\n";}
 464
 465    $user = $gapps->retrieveUser($username);
 466
 467    if ($user !== null) {
 468        $user->login->changePasswordAtNextLogin = false;
 469        $user->save();
 470    } else {
 471        if ($html) {echo '<p>';}
 472        echo 'Error: Specified user not found.';
 473        if ($html) {echo '</p>';}
 474        echo "\n";
 475    }
 476
 477    if ($html) {echo "<p>Done.</p>\n";}
 478}
 479
 480/**
 481 * Delete the user who owns a given username.
 482 *
 483 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 484 *                                    Apps server.
 485 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 486 * @param  string           $username The username which should be deleted.
 487 * @return void
 488 */
 489function deleteUser($gapps, $html, $username)
 490{
 491    if ($html) {echo "<h2>Delete User</h2>\n";}
 492
 493    $gapps->deleteUser($username);
 494
 495    if ($html) {echo "<p>Done.</p>\n";}
 496}
 497
 498/**
 499 * Create a new nickname.
 500 *
 501 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 502 *                                    Apps server.
 503 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 504 * @param  string           $username The username to which the nickname should be assigned.
 505 * @param  string           $nickname The name of the nickname to be created.
 506 * @return void
 507 */
 508function createNickname($gapps, $html, $username, $nickname)
 509{
 510    if ($html) {echo "<h2>Create Nickname</h2>\n";}
 511
 512    $gapps->createNickname($username, $nickname);
 513
 514    if ($html) {echo "<p>Done.</p>\n";}
 515}
 516
 517/**
 518 * Retrieve a specified nickname and output its ownership information.
 519 *
 520 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 521 *                                    Apps server.
 522 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 523 * @param  string           $nickname The name of the nickname to be retrieved.
 524 * @return void
 525 */
 526function retrieveNickname($gapps, $html, $nickname)
 527{
 528    if ($html) {echo "<h2>Nickname Information</h2>\n";}
 529
 530    $nickname = $gapps->retrieveNickname($nickname);
 531
 532    if ($html) {echo '<p>';}
 533
 534    if ($nickname !== null) {
 535        echo ' Nickname: ' . $nickname->nickname->name;
 536        if ($html) {echo '<br />';}
 537        echo "\n";
 538
 539        echo '    Owner: ' . $nickname->login->username;
 540    } else {
 541        echo 'Error: Specified nickname not found.';
 542    }
 543    if ($html) {echo '</p>';}
 544    echo "\n";
 545}
 546
 547/**
 548 * Outputs all nicknames owned by a specific username.
 549 *
 550 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 551 *                                    Apps server.
 552 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 553 * @param  string           $username The username whose nicknames should be displayed.
 554 * @return void
 555 */
 556function retrieveNicknames($gapps, $html, $username)
 557{
 558    if ($html) {echo "<h2>Registered Nicknames For {$username}</h2>\n";}
 559
 560    $feed = $gapps->retrieveNicknames($username);
 561
 562    if ($html) {echo "<ul>\n";}
 563
 564    foreach ($feed as $nickname) {
 565        if ($html) {
 566            echo "  <li>";
 567        } else {
 568            echo "  * ";
 569        }
 570        echo $nickname->nickname->name;
 571        if ($html) {echo '</li>';}
 572        echo "\n";
 573    }
 574    if ($html) {echo "</ul>\n";}
 575}
 576
 577
 578/**
 579 * Retrieves the list of nicknames for the current domain and outputs
 580 * that list.
 581 *
 582 * @param  Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
 583 *                                 Apps server.
 584 * @param  boolean          $html  True if output should be formatted for display in a web browser.
 585 * @return void
 586 */
 587function retrieveAllNicknames($gapps, $html)
 588{
 589    if ($html) {echo "<h2>Registered Nicknames</h2>\n";}
 590
 591    $feed = $gapps->retrieveAllNicknames();
 592
 593    if ($html) {echo "<ul>\n";}
 594
 595    foreach ($feed as $nickname) {
 596        if ($html) {
 597            echo "  <li>";
 598        } else {
 599            echo "  * ";
 600        }
 601        echo $nickname->nickname->name . ' => ' . $nickname->login->username;
 602        if ($html) {echo '</li>';}
 603        echo "\n";
 604    }
 605    if ($html) {echo "</ul>\n";}
 606}
 607
 608/**
 609 * Delete's a specific nickname from the current domain.
 610 *
 611 * @param  Zend_Gdata_Gapps $gapps    The service object to use for communicating with the Google
 612 *                                    Apps server.
 613 * @param  boolean          $html     True if output should be formatted for display in a web browser.
 614 * @param  string           $nickname The nickname that should be deleted.
 615 * @return void
 616 */
 617function deleteNickname($gapps, $html, $nickname)
 618{
 619    if ($html) {echo "<h2>Delete Nickname</h2>\n";}
 620
 621    $gapps->deleteNickname($nickname);
 622
 623    if ($html) {echo "<p>Done.</p>\n";}
 624
 625}
 626
 627/**
 628 * Create a new email list.
 629 *
 630 * @param  Zend_Gdata_Gapps $gapps     The service object to use for communicating with the Google
 631 *                                     Apps server.
 632 * @param  boolean          $html      True if output should be formatted for display in a web browser.
 633 * @param  string           $emailList The name of the email list to be created.
 634 * @return void
 635 */
 636function createEmailList($gapps, $html, $emailList)
 637{
 638    if ($html) {echo "<h2>Create Email List</h2>\n";}
 639
 640    $gapps->createEmailList($emailList);
 641
 642    if ($html) {echo "<p>Done.</p>\n";}
 643}
 644
 645/**
 646 * Outputs the list of email lists to which the specified address is
 647 * subscribed.
 648 *
 649 * @param  Zend_Gdata_Gapps $gapps     The service object to use for communicating with the Google
 650 *                                     Apps server.
 651 * @param  boolean          $html      True if output should be formatted for display in a web browser.
 652 * @param  string           $recipient The email address of the recipient whose subscriptions should
 653 *                                     be retrieved. Only a username is required if the recipient is a
 654 *                                     member of the current domain.
 655 * @return void
 656 */
 657function retrieveEmailLists($gapps, $html, $recipient)
 658{
 659    if ($html) {echo "<h2>Email List Subscriptions For {$recipient}</h2>\n";}
 660
 661    $feed = $gapps->retrieveEmailLists($recipient);
 662
 663    if ($html) {echo "<ul>\n";}
 664
 665    foreach ($feed as $list) {
 666        if ($html) {
 667            echo "  <li>";
 668        } else {
 669            echo "  * ";
 670        }
 671        echo $list->emailList->name;
 672        if ($html) {echo '</li>';}
 673        echo "\n";
 674    }
 675    if ($html) {echo "</ul>\n";}
 676}
 677
 678/**
 679 * Outputs the list of all email lists on the current domain.
 680 *
 681 * @param  Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
 682 *                                 Apps server.
 683 * @param  boolean          $html  True if output should be formatted for display in a web browser.
 684 * @return void
 685 */
 686function retrieveAllEmailLists($gapps, $html)
 687{
 688    if ($html) {echo "<h2>Registered Email Lists</h2>\n";}
 689
 690    $feed = $gapps->retrieveAllEmailLists();
 691
 692    if ($html) {echo "<ul>\n";}
 693
 694    foreach ($feed as $list) {
 695        if ($html) {
 696            echo "  <li>";
 697        } else {
 698            echo "  * ";
 699        }
 700        echo $list->emailList->name;
 701        if ($html) {echo '</li>';}
 702        echo "\n";
 703    }
 704    if ($html) {echo "</ul>\n";}
 705}
 706
 707/**
 708 * Delete's a specific email list from the current domain.
 709 *
 710 * @param  Zend_Gdata_Gapps $gapps     The service object to use for communicating with the Google
 711 *                                     Apps server.
 712 * @param  boolean          $html      True if output should be formatted for display in a web browser.
 713 * @param  string           $emailList The email list that should be deleted.
 714 * @return void
 715 */
 716function deleteEmailList($gapps, $html, $emailList)
 717{
 718    if ($html) {echo "<h2>Delete Email List</h2>\n";}
 719
 720    $gapps->deleteEmailList($emailList);
 721
 722    if ($html) {echo "<p>Done.</p>\n";}
 723}
 724
 725/**
 726 * Add a recipient to an existing email list.
 727 *
 728 * @param  Zend_Gdata_Gapps $gapps            The service object to use for communicating with the
 729 *                                            Google Apps server.
 730 * @param  boolean          $html             True if output should be formatted for display in a
 731 *                                            web browser.
 732 * @param  string           $recipientAddress The address of the recipient who should be added.
 733 * @param  string           $emailList        The name of the email address the recipient be added to.
 734 * @return void
 735 */
 736function addRecipientToEmailList($gapps, $html, $recipientAddress,
 737        $emailList)
 738{
 739    if ($html) {echo "<h2>Subscribe Recipient</h2>\n";}
 740
 741    $gapps->addRecipientToEmailList($recipientAddress, $emailList);
 742
 743    if ($html) {echo "<p>Done.</p>\n";}
 744}
 745
 746/**
 747 * Outputs the list of all recipients for a given email list.
 748 *
 749 * @param  Zend_Gdata_Gapps $gapps     The service object to use for communicating with the Google
 750 *                                     Apps server.
 751 * @param  boolean          $html      True if output should be formatted for display in a web browser.
 752 * @param  string           $emailList The email list whose recipients should be output.
 753 * @return void
 754 */
 755function retrieveAllRecipients($gapps, $html, $emailList)
 756{
 757    if ($html) {echo "<h2>Email List Recipients For {$emailList}</h2>\n";}
 758
 759    $feed = $gapps->retrieveAllRecipients($emailList);
 760
 761    if ($html) {echo "<ul>\n";}
 762
 763    foreach ($feed as $recipient) {
 764        if ($html) {
 765            echo "  <li>";
 766        } else {
 767            echo "  * ";
 768        }
 769        echo $recipient->who->email;
 770        if ($html) {echo '</li>';}
 771        echo "\n";
 772    }
 773    if ($html) {echo "</ul>\n";}
 774}
 775
 776/**
 777 * Remove an existing recipient from an email list.
 778 *
 779 * @param  Zend_Gdata_Gapps $gapps            The service object to use for communicating with the
 780 *                                            Google Apps server.
 781 * @param  boolean          $html             True if output should be formatted for display in a
 782 *                                            web browser.
 783 * @param  string           $recipientAddress The address of the recipient who should be removed.
 784 * @param  string           $emailList        The email list from which the recipient should be removed.
 785 * @return void
 786 */
 787function removeRecipientFromEmailList($gapps, $html, $recipientAddress,
 788        $emailList)
 789{
 790    if ($html) {echo "<h2>Unsubscribe Recipient</h2>\n";}
 791
 792    $gapps->removeRecipientFromEmailList($recipientAddress, $emailList);
 793
 794    if ($html) {echo "<p>Done.</p>\n";}
 795
 796}
 797
 798// ************************ BEGIN CLI SPECIFIC CODE ************************
 799
 800/**
 801 * Display list of valid commands.
 802 *
 803 * @param  string $executable The name of the current script. This is usually available as $argv[0].
 804 * @return void
 805 */
 806function displayHelp($executable)
 807{
 808    echo "Usage: php {$executable} <action> [<username>] [<password>] " .
 809        "[<arg1> <arg2> ...]\n\n";
 810    echo "Possible action values include:\n" .
 811        "createUser\n" .
 812        "retrieveUser\n" .
 813        "retrieveAllUsers\n" .
 814        "updateUserName\n" .
 815        "updateUserPassword\n" .
 816        "suspendUser\n" .
 817        "restoreUser\n" .
 818        "giveUserAdminRights\n" .
 819        "revokeUserAdminRights\n" .
 820        "setUserMustChangePassword\n" .
 821        "clearUserMustChangePassword\n" .
 822        "deleteUser\n" .
 823        "createNickname\n" .
 824        "retrieveNickname\n" .
 825        "retrieveNicknames\n" .
 826        "retrieveAllNicknames\n" .
 827        "deleteNickname\n" .
 828        "createEmailList\n" .
 829        "retrieveEmailLists\n" .
 830        "retrieveAllEmailLists\n" .
 831        "deleteEmailList\n" .
 832        "addRecipientToEmailList\n" .
 833        "retrieveAllRecipients\n" .
 834        "removeRecipientFromEmailList\n";
 835}
 836
 837/**
 838 * Parse command line arguments and execute appropriate function when
 839 * running from the command line.
 840 *
 841 * If no arguments are provided, usage information will be provided.
 842 *
 843 * @param  array   $argv    The array of command line arguments provided by PHP.
 844 *                 $argv[0] should be the current executable name or '-' if not available.
 845 * @param  integer $argc    The size of $argv.
 846 * @return void
 847 */
 848function runCLIVersion($argv, $argc)
 849{
 850    if (isset($argc) && $argc >= 2) {
 851        # Prepare a server connection
 852        if ($argc >= 5) {
 853            try {
 854                $client = getClientLoginHttpClient($argv[2] . '@' . $argv[3], $argv[4]);
 855                $gapps = new Zend_Gdata_Gapps($client, $argv[3]);
 856            } catch (Zend_Gdata_App_AuthException $e) {
 857                echo "Error: Unable to authenticate. Please check your credentials.\n";
 858                exit(1);
 859            }
 860        }
 861
 862        # Dispatch arguments to the desired method
 863        switch ($argv[1]) {
 864            case 'createUser':
 865                if ($argc == 9) {
 866                    createUser($gapps, false, $argv[5], $argv[6], $argv[7], $argv[8]);
 867                } else {
 868                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 869                        "<user's username> <given name> <family name> <user's password>\n\n";
 870                    echo "This creates a new user with the given username.\n";
 871                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 872                        "jdoe John Doe p4ssw0rd\n";
 873                }
 874                break;
 875            case 'retrieveUser':
 876                if ($argc == 6) {
 877                    retrieveUser($gapps, false, $argv[5]);
 878                } else {
 879                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 880                        "<user's username>\n\n";
 881                    echo "This retrieves the user with the specified " .
 882                        "username and displays information about that user.\n";
 883                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 884                        "jdoe\n";
 885                }
 886                break;
 887            case 'retrieveAllUsers':
 888                if ($argc == 5) {
 889                    retrieveAllUsers($gapps, false);
 890                } else {
 891                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 892                        "\n\n";
 893                    echo "This lists all users on the current domain.\n";
 894                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password>\n";
 895                }
 896                break;
 897            case 'updateUserName':
 898                if ($argc == 8) {
 899                    updateUserName($gapps, false, $argv[5], $argv[6], $argv[7]);
 900                } else {
 901                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 902                        "<user's username> <new given name> <new family name>\n\n";
 903                    echo "Renames an existing user.\n";
 904                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 905                        "jdoe Jane Doe\n";
 906                }
 907                break;
 908            case 'updateUserPassword':
 909                if ($argc == 7) {
 910                    updateUserPassword($gapps, false, $argv[5], $argv[6]);
 911                } else {
 912                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 913                        "<user's username> <new user password>\n\n";
 914                    echo "Changes the password for an existing user.\n";
 915                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 916                        "jdoe password1\n";
 917                }
 918                break;
 919            case 'suspendUser':
 920                if ($argc == 6) {
 921                    suspendUser($gapps, false, $argv[5]);
 922                } else {
 923                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 924                        "<user's username>\n\n";
 925                    echo "This suspends the given user.\n";
 926                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 927                        "jdoe\n";
 928                }
 929                break;
 930            case 'restoreUser':
 931                if ($argc == 6) {
 932                    restoreUser($gapps, false, $argv[5]);
 933                } else {
 934                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 935                        "<user's username>\n\n";
 936                    echo "This restores the given user after being suspended.\n";
 937                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 938                        "jdoe\n";
 939                }
 940                break;
 941            case 'giveUserAdminRights':
 942                if ($argc == 6) {
 943                    giveUserAdminRights($gapps, false, $argv[5]);
 944                } else {
 945                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 946                        "<user's username>\n\n";
 947                    echo "Give a user admin rights for this domain.\n";
 948                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 949                        "jdoe\n";
 950                }
 951                break;
 952            case 'revokeUserAdminRights':
 953                if ($argc == 6) {
 954                    revokeUserAdminRights($gapps, false, $argv[5]);
 955                } else {
 956                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 957                        "<user's username>\n\n";
 958                    echo "Remove a user's admin rights for this domain.\n";
 959                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 960                        "jdoe\n";
 961                }
 962                break;
 963            case 'setUserMustChangePassword':
 964                if ($argc == 6) {
 965                    setUserMustChangePassword($gapps, false, $argv[5]);
 966                } else {
 967                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 968                        "<user's username>\n\n";
 969                    echo "Force a user to change their password at next login.\n";
 970                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 971                        "jdoe\n";
 972                }
 973                break;
 974            case 'clearUserMustChangePassword':
 975                if ($argc == 6) {
 976                    clearUserMustChangePassword($gapps, false, $argv[5]);
 977                } else {
 978                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 979                        "<user's username>\n\n";
 980                    echo "Clear the flag indicating that a user must change " .
 981                        "their password at next login.\n";
 982                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 983                        "jdoe\n";
 984                }
 985                break;
 986            case 'deleteUser':
 987                if ($argc == 6) {
 988                    deleteUser($gapps, false, $argv[5]);
 989                } else {
 990                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 991                        "<user's username>\n\n";
 992                    echo "Delete the user who owns a given username.\n";
 993                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
 994                        "jdoe\n";
 995                }
 996                break;
 997            case 'createNickname':
 998                if ($argc == 7) {
 999                    createNickname($gapps, false, $argv[5], $argv[6]);
1000                } else {
1001                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1002                        "<user's username> <nickname>\n\n";
1003                    echo "Create a new nickname for the specified user.\n";
1004                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1005                        "jdoe johnny\n";
1006                }
1007                break;
1008            case 'retrieveNickname':
1009                if ($argc == 6) {
1010                    retrieveNickname($gapps, false, $argv[5]);
1011                } else {
1012                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1013                        "<nickname>\n\n";
1014                    echo "Retrieve a nickname and display its ownership " .
1015                        "information.\n";
1016                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1017                        "johnny\n";
1018                }
1019                break;
1020            case 'retrieveNicknames':
1021                if ($argc == 6) {
1022                    retrieveNicknames($gapps, false, $argv[5]);
1023                } else {
1024                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1025                        "<user's username>\n\n";
1026                    echo "Output all nicknames owned by a specific username.\n";
1027                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1028                        "jdoe\n";
1029                }
1030                break;
1031            case 'retrieveAllNicknames':
1032                if ($argc == 5) {
1033                    retrieveAllNicknames($gapps, false);
1034                } else {
1035                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1036                        "\n\n";
1037                    echo "Output all registered nicknames on the system.\n";
1038                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1039                        "\n";
1040                }
1041                break;
1042            case 'deleteNickname':
1043                if ($argc == 6) {
1044                    deleteNickname($gapps, false, $argv[5]);
1045                } else {
1046                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1047                        "<nickname>\n\n";
1048                    echo "Delete a specific nickname.\n";
1049                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1050                        "johnny\n";
1051                }
1052                break;
1053            case 'createEmailList':
1054                if ($argc == 6) {
1055                    createEmailList($gapps, false, $argv[5]);
1056                } else {
1057                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1058                        "<email list>\n\n";
1059                    echo "Create a new email list with the specified name.\n";
1060                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1061                        "friends\n";
1062                }
1063                break;
1064            case 'retrieveEmailLists':
1065                if ($argc == 6) {
1066                    retrieveEmailLists($gapps, false, $argv[5]);
1067                } else {
1068                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1069                        "<recipient>\n\n";
1070                    echo "Retrieve all email lists to which the specified " .
1071                        "address is subscribed.\n";
1072                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1073                        "johnny@somewhere.com.invalid\n";
1074                }
1075                break;
1076            case 'retrieveAllEmailLists':
1077                if ($argc == 5) {
1078                    retrieveAllEmailLists($gapps, false);
1079                } else {
1080                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1081                        "\n\n";
1082                    echo "Retrieve a list of all email lists on the current " .
1083                        "domain.\n";
1084                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1085                        "\n";
1086                }
1087                break;
1088            case 'deleteEmailList':
1089                if ($argc == 6) {
1090                    deleteEmailList($gapps, false, $argv[5]);
1091                } else {
1092                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1093                        "<email list>\n\n";
1094                    echo "Delete a specified email list.\n";
1095                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1096                        "friends\n";
1097                }
1098                break;
1099            case 'addRecipientToEmailList':
1100                if ($argc == 7) {
1101                    addRecipientToEmailList($gapps, false, $argv[5], $argv[6]);
1102                } else {
1103                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1104                        "<recipient> <email list>\n\n";
1105                    echo "Add a recipient to an existing email list.\n";
1106                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1107                        "johnny@somewhere.com.invalid friends\n";
1108                }
1109                break;
1110            case 'retrieveAllRecipients':
1111                if ($argc == 6) {
1112                    retrieveAllRecipients($gapps, false, $argv[5]);
1113                } else {
1114                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1115                        "<email list>\n\n";
1116                    echo "Retrieve all recipients for an existing email list.\n";
1117                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1118                        "friends\n";
1119                }
1120                break;
1121            case 'removeRecipientFromEmailList':
1122                if ($argc == 7) {
1123                    removeRecipientFromEmailList($gapps, false, $argv[5], $argv[6]);
1124                } else {
1125                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1126                        "<recipient> <email list>\n\n";
1127                    echo "Remove an existing recipient from an email list.\n";
1128                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
1129                        "johnny@somewhere.com.invalid friends\n";
1130                }
1131                break;
1132            default:
1133                // Invalid action entered
1134                displayHelp($argv[0]);
1135        // End switch block
1136        }
1137    } else {
1138        // action left unspecified
1139        displayHelp($argv[0]);
1140    }
1141}
1142
1143// ************************ BEGIN WWW SPECIFIC CODE ************************
1144
1145/**
1146 * Writes the HTML prologue for this app.
1147 *
1148 * NOTE: We would normally keep the HTML/CSS markup separate from the business
1149 *       logic above, but have decided to include it here for simplicity of
1150 *       having a single-file sample.
1151 *
1152 *
1153 * @param  boolean $displayMenu (optional) If set to true, a navigation
1154 *                              menu is displayed at the top of the page. Default is true.
1155 * @return void
1156 */
1157function startHTML($displayMenu = true)
1158{
1159?>
1160<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
1161    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1162
1163<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1164<head>
1165    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
1166
1167    <title>Google Apps Provisioning API Demo</title>
1168
1169    <style type="text/css" media="screen">
1170        body {
1171            font-family: Arial, Helvetica, sans-serif;
1172            font-size: small;
1173        }
1174
1175        #header {
1176            background-color: #9cF;
1177            -moz-border-radius: 5px;
1178            -webkit-border-radius: 5px;
1179            padding-left: 5px;
1180            height: 2.4em;
1181        }
1182
1183        #header h1 {
1184            width: 49%;
1185            display: inline;
1186            float: left;
1187            margin: 0;
1188            padding: 0;
1189            font-size: 2em;
1190        }
1191
1192        #header p {
1193            width: 49%;
1194            margin: 0;
1195            padding-right: 15px;
1196            float: right;
1197            line-height: 2.4em;
1198            text-align: right;
1199        }
1200
1201        .clear {
1202            clear:both;
1203        }
1204
1205        h2 {
1206            background-color: #ccc;
1207            -moz-border-radius: 5px;
1208            -webkit-border-radius: 5px;
1209            margin-top: 1em;
1210            padding-left: 5px;
1211        }
1212
1213        .error {
1214            color: red;
1215        }
1216
1217        form {
1218            width: 500px;
1219            background: #ddf8cc;
1220            border: 1px solid #80c605;
1221            padding: 0 1em;
1222            margin: 1em auto;
1223        }
1224
1225        .warning {
1226            width: 500px;
1227            background: #F4B5B4;
1228            border: 1px solid #900;
1229            padding: 0 1em;
1230            margin: 1em auto;
1231        }
1232
1233        label {
1234            display: block;
1235            width: 130px;
1236            float: left;
1237            text-align: right;
1238            padding-top: 0.3em;
1239            padding-right: 3px;
1240        }
1241
1242        .radio {
1243            margin: 0;
1244            padding-left: 130px;
1245        }
1246
1247        #menuSelect {
1248            padding: 0;
1249        }
1250
1251        #menuSelect li {
1252            display: block;
1253            width: 500px;
1254            background: #ddf8cc;
1255            border: 1px solid #80c605;
1256            margin: 1em auto;
1257            padding: 0;
1258            font-size: 1.3em;
1259            text-align: center;
1260            list-style-type: none;
1261        }
1262
1263        #menuSelect li:hover {
1264            background: #c4faa2;
1265        }
1266
1267        #menuSelect a {
1268            display: block;
1269            height: 2em;
1270            margin: 0px;
1271            padding-top: 0.75em;
1272            padding-bottom: -0.25em;
1273            text-decoration: none;
1274        }
1275
1276        #content {
1277            width: 600px;
1278            margin: 0 auto;
1279            padding: 0;
1280            text-align: left;
1281        }
1282    </style>
1283
1284</head>
1285
1286<body>
1287
1288<div id="header">
1289    <h1>Google Apps API Demo</h1>
1290    <?php if ($displayMenu === true) { ?>
1291        <p><?php echo GAPPS_DOMAIN ?> | <a href="?">Main</a> | <a href="?menu=logout">Logout</a></p>
1292    <?php } ?>
1293    <div class="clear"></div>
1294</div>
1295
1296<div id="content">
1297<?php
1298}
1299
1300/**
1301 * Writes the HTML epilogue for this app and exit.
1302 *
1303 * @param  boolean $displayBackButton (optional) If true, displays a
1304 *                                    link to go back at the bottom of the page. Defaults to false.
1305 * @return void
1306 */
1307function endHTML($displayBackButton = false)
1308{
1309    if ($displayBackButton === true) {
1310        echo '<a href="javascript:history.go(-1)">&larr; Back</a>';
1311    }
1312?>
1313</div>
1314</body>
1315</html>
1316<?php
1317exit();
1318}
1319
1320/**
1321 * Displays a notice indicating that a login password needs to be
1322 * set before continuing.
1323 *
1324 * @return void
1325 */
1326function displayPasswordNotSetNotice()
1327{
1328?>
1329    <div class="warning">
1330        <h3>Almost there...</h3>
1331        <p>Before using this demo, you must set an application password
1332            to protect your account. You will also need to set your
1333            Google Apps credentials in order to communicate with the Google
1334            Apps servers.</p>
1335        <p>To continue, open this file in a text editor and fill
1336            out the information in the configuration section.</p>
1337    </div>
1338<?php
1339}
1340
1341/**
1342 * Displays a notice indicating that authentication to Google Apps failed.
1343 *
1344 * @return void
1345 */
1346function displayAuthenticationFailedNotice()
1347{
1348?>
1349    <div class="warning">
1350        <h3>Google Apps Authentication Failed</h3>
1351        <p>Authentication with the Google Apps servers failed.</p>
1352        <p>Please open this file in a text editor and make
1353            sure your credentials are correct.</p>
1354    </div>
1355<?php
1356}
1357
1358/**
1359 * Outputs a request to the user to enter their login password.
1360 *
1361 * @param  string $errorText (optional) Error text to be displayed next to the login form.
1362 * @return void
1363 */
1364function requestUserLogin($errorText = null)
1365{
1366?>
1367    <form method="post" accept-charset="utf-8">
1368        <h3>Authentication Required</h3>
1369        <?php
1370            if ($errorText !== null) {
1371                echo '<span class="error">' . $errorText . "</span>\n";
1372            }
1373        ?>
1374        <p>Please enter your login password to continue.</p>
1375        <p><label for="password">Password: </label>
1376             <input type="password" name="password" value="" /></p>
1377        <p><strong>Notice:</strong> This application is for demonstration
1378            purposes only. Not for use in a production environment.</p>
1379        <p><input type="submit" value="Continue &rarr;"></p>
1380    </form>
1381<?php
1382}
1383
1384/**
1385 * Display the main menu for running in a web browser.
1386 *
1387 * @return void
1388 */
1389function displayMenu()
1390{
1391?>
1392<h2>Main Menu</h2>
1393
1394<p>Welcome to the Google Apps Provisioning API demo page. Please select
1395    from one of the following three options to see a list of commands.</p>
1396
1397    <ul id="menuSelect">
1398        <li><a class="menuSelect" href="?menu=user">User Maintenance Menu</a></li>
1399        <li><a class="menuSelect" href="?menu=nickname">Nickname Maintenance Menu</a></li>
1400        <li><a class="menuSelect" href="?menu=emailList">Email List Maintenance Menu</a></li>
1401    </ul>
1402
1403<p>Tip: You can also run this demo from the command line if your system
1404    has PHP CLI support enabled.</p>
1405<?php
1406}
1407
1408/**
1409 * Display the user maintenance menu for running in a web browser.
1410 *
1411 * @return void
1412 */
1413function displayUserMenu()
1414{
1415?>
1416<h2>User Maintenance Menu</h2>
1417
1418<form method="post" accept-charset="utf-8">
1419    <h3>Create User</h3>
1420    <p>Create a new user with the given properties.</p>
1421    <p>
1422        <input type="hidden" name="command" value="createUser" />
1423        <label for="user">Username: </label>
1424        <input type="text" name="user" value="" /><br />
1425        <label for="givenName">Given Name: </label>
1426        <input type="text" name="givenName" value="" /><br />
1427        <label for="familyName">Family Name: </label>
1428        <input type="text" name="familyName" value="" /><br />
1429        <label for="pass">Password: </label>
1430        <input type="password" name="pass" value="" />
1431    </p>
1432
1433    <p><input type="submit" value="Create User &rarr;"></p>
1434</form>
1435<form method="get" accept-charset="utf-8">
1436    <h3>Retrieve User</h3>
1437    <p>Retrieve the information for an existing user.</p>
1438    <p>
1439        <input type="hidden" name="command" value="retrieveUser" />
1440        <label for="user">Username: </label>
1441        <input type="text" name="user" value="" /><br />
1442    </p>
1443
1444    <p><input type="submit" value="Retrieve User &rarr;"></p>
1445</form>
1446<form method="get" accept-charset="utf-8">
1447    <h3>Retrieve All Users</h3>
1448    <p>Retrieve the list of all users on the current domain.</p>
1449    <p>
1450        <input type="hidden" name="command" value="retrieveAllUsers" />
1451    </p>
1452

Large files files are truncated, but you can click here to view the full file