/*! \page page1 Example Code Documentation Svetlozar.NET Contacts Importer Example Code Documentation


./index.php:

All logic moved to ContactsHandler class (./example/contacts.main.php)
include_once 'example/contacts.main.php';
$handler = new ContactsHandler();
$handler->handle_request($_POST);

./example/contacts.main.php (this is where most of the code is, the rest of the files are templates for forms and pages)
    Please see comments within the file, I've tried tried to explain almost every single step
    The main method is handle_request

Forms:
A note for all forms: the instance of ContactsHandler is made available in the forms (so $this->[property] points to propery of ContactsHandler), forms are loaded within handle_request scope

./example/contacts.import.php
    Based on the type of contacts importer class display:
        - username and password (+ captcha if captcha response is returned)
        - or just a button to open the external authentication window

./example/contacts.invite.php
    Display a list of imported contacts for user selection (if your implementation requires to do so)

./example/contacts.done.php
      Any feedback to the user after submitting selected contacts

./contacts.page.php
      Javascript documentation:
          Important parts
                form_ready global (available to the whole page) is set to True if the form is simple import form (username/password), or for external authentication forms, it is True only after the user clicks the button for external authentication (used in the onclick event of the button so that form submission is not triggered during opening the external authentication window)
                External authentication does trigger form submission but only when the user goes through the process of authorizing the request (at that point the popup window calls back its parent window and as a result the form is submitted with any additional data that the popup window may provide)

           More Javascript (second block)
                (function(){...}) is used to create local scope (not creating any globals, not necessary otherwise)
                external_auth - url to the page that will handle external authentication redirection (url used in opening the popup window)
                submit_form - replaces (wraps) the onsubmit event of the form (it is a decorator), makes sure the form is only submitted when form_ready is true and opens up the external authentication window otherwise
                toggle_checked, cancel_propagation, set_checked - provided for user friendliness (allow for checking all checkboxes at once, clicking on table row toggles on/off the checkbox on that row), you may use any javascript library to provide the same

                The last part of the javascript code is where the form submit event is wrapped in a call to submit_form

        var import_form = document.getElementById("import_form");
        if (import_form)
        {
            import_form.onsubmit = submit_form(import_form);
        }


./external.php
                Contains definition of ExternalAuthHandler which overrides handle_request from ContactsHandler (again, it will be most useful if you follow the comments in the code for handle_request)

./example/external.page.php
                   A template page for the external authentication page
                   QueryParms = the query string parsed into dictionary (or associative array in PHP terms), we need to extract oauth_verifier from it when the user authorizes the request
                    ReturnToParent() - sets form_ready in the parent window to true, and passes oauth_verifier to ImportContacts function in the parent window (which will trigger submission of the form with oauth_verifier as part of the "state" of the form)


Settings
Svetlozar.NET/settings.php
(comments include urls for getting private keys/secret for your application. I could not find one for Plaxo)
    Sign up for your own keys and enter them here (this file may remotely look like a file of global definitions but it is actually included within the scope of SPUserSettings::init())
*/