<?PHP

/**
 * Sample code demonstrating how to call/use the omNovia Event Manager API
 *
 * Tested with PHP 4.4.0
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @category   Web Services
 * @author     Matthew Boehm <mboehm@omnovia.com>
 * @copyright  2006 Matthew Boehm, omNovia Technologies
 * @version    1.0
 * @link       http://pear.php.net/package/XML_RPC
**/

/**
 * NOTE: All RPC commands require 'unique ID' and 'company password'.
 * Both of these are supplied to you by omNovia Support.
 *
 * NOTE: You are able to use any combination of the functions below,
 * and the event manager itself, located in the omNovia Members Area.
 *
 * For example, you can create an event in the Members Area and then use
 * the API code below to just add more emails.  Or you can use the code
 * below to handle all aspects of event creation, modification and deletion
 * and never touch/use the omNovia Members Area.
 *
**/

/**
 * The PEAR package, XML_RPC, is required to be installed.
 * Visit the @link in the header comments for install procedures.
**/
require_once 'XML/RPC.php';

/**
 * All 'commands' are called by constructing an array of
 * XML_RPC_Value elements. Depending on which RPC you are
 * calling, different numbers of elements (aka parameters)
 * are needed.
 *
**/

/* Sample Parameters for adding an event. addEvent is the most complex as there are
 * many options for creating an event. These options are explained in more detail
 * near the bottom of this document.
**/
$addEventParams = array(
        new 
XML_RPC_Value(9999"int"),                    // unique ID from omnovia
        
new XML_RPC_Value("XXXXXXX""string"),                // company password
        
new XML_RPC_Value(9999"int"),                    // room id to add event to
        
new XML_RPC_Value('howdy eveasdfasdfnt'"string"),        // event name
        
new XML_RPC_Value('someasdfasdf description'"string"),    // event description
        
new XML_RPC_Value('2006-07-07'"string"),            // date of event
        
new XML_RPC_Value('17:35'"string"),                // time of event
        
new XML_RPC_Value('myPasddddds'"string"),            // event password
        
new XML_RPC_Value(10"int"),                    // allowed to enter duration
        
new XML_RPC_Value(5"int"),                    // until to enter duration
        
new XML_RPC_Value(0"int"),                    // registration level
        
new XML_RPC_Value(1"int"),                    // access level
        
new XML_RPC_Value('N'"string")                // recurrence level
);

/* Sample Parameters for modifying an event. addEvent and modEvent take the same 11
 * basic parameters with modEvent taking an additional 12th, the eventID to modify
**/
$modEventParams = array(
        new 
XML_RPC_Value(9999"int"),                    // unique ID from omnovia
        
new XML_RPC_Value("XXXXXX""string"),                // company password
        
new XML_RPC_Value(557"int"),                    // eventID to modify
        
new XML_RPC_Value('howdy eveasdfasdfnt'"string"),        // event name
        
new XML_RPC_Value('someasdfasdf description'"string"),    // event description
        
new XML_RPC_Value('2006-07-07'"string"),            // date of event
        
new XML_RPC_Value('17:35'"string"),                // time of event
        
new XML_RPC_Value('myPasddddds'"string"),            // event password
        
new XML_RPC_Value(10"int"),                    // allowed to enter duration
        
new XML_RPC_Value(5"int"),                    // until to enter duration
        
new XML_RPC_Value(0"int"),                    // registration level
        
new XML_RPC_Value(1"int")                    // access level
);

/* Sample Parameters for deleting an event */
$delEventParams = array(
        new 
XML_RPC_Value(9999"int"),                    // unique ID from omnovia
        
new XML_RPC_Value("XXXXXX""string"),                // company password
        
new XML_RPC_Value(557"int"),                    // eventID to delete
);

/* Sample Parameters for adding more invitees */
$addInviteesParams = array(
        new 
XML_RPC_Value(9999"int"),                    // unique ID from omnovia
        
new XML_RPC_Value("XXXXXX""string"),                // company password
        
new XML_RPC_Value(557"int"),                    // eventID to add invitees to
        
new XML_RPC_Value(1"int"),                    // future recurrning event iteration
        
new XML_RPC_Value(
            array(
                new 
XML_RPC_Value("Jac4k1"),            // Firstname of invitee
                
new XML_RPC_Value("Tra4des12"),            // Lastname of invitee
                
new XML_RPC_Value("1ja4ck@jack.com"),        // email of invitee
                
new XML_RPC_Value("gb2312")                // charset
            
), "array"),
        new 
XML_RPC_Value(
            array(
                new 
XML_RPC_Value("Ja3ck2"),            // Repeat for X num of invitees to add
                
new XML_RPC_Value("Trad3es11"),
                new 
XML_RPC_Value("2ja3ck@jack.com")
            ), 
"array")
);
/*
Returns:
2ja3ck@jack.com:added|1ja4ck@jack.com:exists
*/

/* Sample Parameters for sending registration emails to a specific email */
$send_registrationParams = array(
        new 
XML_RPC_Value(9999"int"),                        // unique ID from omnovia
        
new XML_RPC_Value("XXXXXX""string"),                // company password
        
new XML_RPC_Value(557"int"),                        // eventID
        
new XML_RPC_Value(1"int"),                        // future recurrning event iteration
        
new XML_RPC_Value('mott@omnovia.com'"string")        // email address
);

$msg = new XML_RPC_Message('event.addEvent'$addEventParams);            // Can only call one function at a time
//$msg = new XML_RPC_Message('event.modEvent', $modEventParams);
//$msg = new XML_RPC_Message('event.delEvent', $delEventParams);
//$msg = new XML_RPC_Message('event.addInvitees', $addInviteesParams);

/*
 * The XML_RPC URL is http://www.omnovia.com/members/eventrpc.php
 */

/* This will create a new client object. */
$client = new XML_RPC_Client('/members/eventrpc.php''www.omnovia.com');

/* For production environment, turn off debugging. */
$client->setDebug(0);

/* Send the command and get back the resultant message (return value) */
$resp $client->send($msg5);

/* If there was no return value, most likely the call didn't happen
 * due to various internet issues.
 */
if(!$resp)
{
    echo 
'Communication error: ' $client->errstr;
    exit();
}

/* If a fault code was returned, this means omNovia received our request,
 * processed it, and an error was generated. Print out the error value
 * and the error message.
 *
 * Fault Codes:
 *   801 - Not enough parameters
 *   802 - Internal DB connection failure
 *   803 - Database Query Failed (please provide the comment code when report an issue)
 *   804 - Other (such as bad eventID, badly formatted email, etc)
 *   805 - Room Capacity Reached. No more registrations accepted.
 *
 * If no fault code was returned, parse out the returned result and display
 * or handle the result in your code.
 */
if(!$resp->faultCode())
{
    
$val $resp->value();
    
$data XML_RPC_decode($val);
    print 
$data;
}
else
{
    echo 
'Fault Code: ' $resp->faultCode() . "\n";
    echo 
'Fault Reason: ' $resp->faultString() . "\n";
}

/**
 * Detailed Documentation of RPC Function: "event.addEvent"
 *
 *  11 Parameters:
 *
 *    UNIQUE         Integer   // Company ID, given to you by omNovia
 *
 *    PASSWORD       String    // Company password, chosen by you in members area
 *
 *    NAME_OF_EVENT  String    // name of the event
 *
 *    DESCRIPTION    String    // Description of the event
 *
 *    YYYY-MM-DD     String    // Date of the event (must be YYYY-DD-MM)
 *
 *    HH:MM          String    // Time of event. Time is local to room time zone in 24-hr format (must be in HH:MM)
 *
 *    PASSWORD       String    // password of event
 *
 *    ALLOWED        Integer   // the number of minutes before start of event that attendees may enter
 *
 *    UNTILTO        Integer   // the number of minutes after start of event that attendees may continue to enter
 *
 *    REGISTRATION   Integer   // 0 - No Registration Required
 *                             // 1 - Registration Optional
 *                             // 2 - Registration Mandatory
 *
 *    REGISTRATION has 3 options: mandatory (2), optional (1) or none (1)
 *       Mandatory: This will reqire anyone and everyone to register before being allowed to enter the event.
 *                  ACCESSLEVEL will place further restrictions on who can get in/register.
 *                  This option will also force a requirement on registrationemail below.
 *
 *       Optional: Attendee's and List members may choose to opt out of registration before entering the event.
 *                 ACCESSLEVEL will place further restrictions on who can get in/register.
 *                 This option will also force a requirement on registrationemail below.
 *
 *       No: No registration is required or allowed.
 *           ACCESSLEVEL restricts who can get in.
 *
 *    ACCESSLEVEL       Integer   // REGISTRATION   ACCESSLEVEL
 *                                //      0             0    // No registration, Allow anyone with password
 *                                //      0             1    // No registration, Allow only people in list
 *                                //      1             -    // Optional registration, allow anyone with password and allow anyone to register
 *                                //      2             0       // Mandatory registration, Allow anyone to register
 *                                //      2             1       // Mandatory registration, Allow only those in the list to register
 *
 *    RECURRENCE     String    // N - Non-Recurring Event. A one time event.
 *                             // W - A weekly recurring event. Will recurr on the same day (ie: Mon, Wed, Sat..) as the
 *                             //     date of the event each week.
 *
 * Further explanation of REGISTRATION and ACCESSLEVEL values
 *
 *    Mandatory Reg: ACCESSLEVEL can be:
 *            'anyone' - allow anyone to register for the event. once registered they will receive
 *                   the email below containing the password and link to enter event.
 *
 *            'list' - use an accesslist. only those emails on the list will be allowed to register.
 *                 once registered they will receive the email below containing the password and
 *                 link to enter event.
 *
 *    Optional Reg: ACCESSLEVEL can be same as mandatory but since registration is optional, the accesslist isn't enforced.
 *
 *    No Reg: ACCESSLEVEL functions the same as mandatory but without the requirement of needing to register before event.
 *
**/
?>