<?PHP

/**
 * Sample code demonstrating how to use omNovia's Single Sign On in PHP
 *
 *  omNovia Technologies Inc.
 *  Latest modifications: October 1, 2009
 *
 * NOTE: *** For a ASP.NET example,     see http://www.omnovia.com/support/apis/examples/SSO/sso_asp.txt
 *       *** For a Java server example, see http://www.omnovia.com/support/apis/examples/SSO/sso_java.txt
 *
 *
 *  Single Sign On (SSO) is an API that allows you to send your members, once authenticated to your site, to the omNovia Secure
 *  Conference login page. By passing their identification and other security parametres, they do not need to enter yet another
 *  password to access your Secure Conference room
 *  This PHP example can be easily ported to other web server programs such as ASP, JSP ...
 *
 * 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
 * @copyright  omNovia Technologies
 * @version    1.3
**/

/**
 * NOTE:
 *
 * $companyUsername is a unique identifier needed by omNovia.
 * In most cases, this is the email address of the user.
 * You must replace the @ sign with _ (underscore)
 *
 * PLEASE ENSURE YOUR SERVER TIME IS GMT *******  THIS IS CRITICAL!
 *
 *
 *
 *
**/


// IMPORTANT This determines how the hash is verified
$version '1.3';



$companyID 000000;        // supplied by omNovia Support
$companyPass 'test';    // supplied by omNovia Support
$roomID 0000;              // supplied by omNovia Support


/*** Construct Company Username ***/
// You must do one of the following and comment the other one!

// Example 1 : with Email address
$companyUsername =    str_replace("@""_""joe@smith.com");

// Example 2: with username
$companyUsername "joemartin";    // must come from your database. No spaces or special characters.

$firstName 'joe';
$lastName 'martin';

// This is a unique identifier of the person in your database
// It does not have to be an email address but can be. It could be the username they use to log in to your site
// You have to replace the @ sign with _


/*** Construct Time Stamp in GMT with 10 min Expiration ***/

$link_duration 10;    // duration in number of minutes between the time they leave your site and the time they can actually access the room
                      // This is a very important parameter! If it is too large, they may bookmark the login page and access the room without going through your site
                      // If it is too little, they might not have enough time to access the room. We suggest you between 5 and 30 minutes
                      // Please also note that your server time (even in GMT) might differ from the omNovia time by a few minutes.

$timestamp time() + (60 $link_duration);


/*** Whether the user is an attendee or presenter / moderator ***/

$isPresenter 0;   // 0 for attendees.  1 for presenter or moderator

$userNo 0;        // ** MUST be 0 for guest attendees. 
                    // ** For moderators, presenters or regular attendeesCAN be 0 if the person does not 
                    // have an account at omNovia OR it should be the userNo in the omNovia system if they have one

/*** Whether you want the user to first go to an omNovia login page or directly access the room ***/

$directAccess 0;
// If $directAccess is 0 it first takes the users to an omNovia login page which would test their Flash install and provide other info
// THIS IS RECOMMENDED
// If $directAccess is 1, they would access the room directly . Not Recommended.


$openInSeparateWindow 0;  // ONLY if you set $directAccess = 1; you might want to open the room in a separate window. The advantage is
                // the room will have a bigger interface as you can remove the navigation buttons and other menus on top of
                // a newly opened browser. You cannot do so on an already open browser.


// -------------------------- NO NEED FOR ANY CHANGES BEYOOND THIS LINE ----------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------------


$inquiry = ($directAccess == '&inquiry=login' '');

/*** Create a md5 hash - IT MUST BE IN THIS ORDER***/
if ($userNo == 0)
  
$md5 md5($companyID.$companyPass.$roomID.$firstName.$lastName.$isPresenter.$version.$companyUsername.$timestamp);
else
  
$md5 md5($companyID.$companyPass.$roomID.$userNo.$isPresenter.$version.$companyUsername.$timestamp);




/*** Construct the link ***/
$base_omnovia_link "https://www.omnovia.com/pages/sc2/roomlogin?";

if (
$userNo == 0)
{
  
$room_link "companyID=$companyID&isPresenter=$isPresenter&loginType=2&roomID=$roomID$inquiry"
    
"&firstName=" rawurlencode($firstName) . "&lastName=" rawurlencode($lastName)
    . 
"&companyUsername=$companyUsername&_ts=$timestamp&_t=$md5&_v=$version";
}
else
{
  
$room_link "companyID=$companyID&isPresenter=$isPresenter&loginType=2&roomID=$roomID$inquiry"
    
"&userNo=$userNo&companyUsername=$companyUsername&_ts=$timestamp&_t=$md5&_v=$version";
}


/*** Construct the full link ***/
$room_link $base_omnovia_link $room_link;


/**
 * You can now use $room_link anywhere in your PHP script as the URL
 * to one of your rooms. If you have multiple rooms, you will need to
 * loop through the $room_link, $enc_room_link generation code for each $roomID you have
**/
if ($openInSeparateWindow == )
{
    print 
"<script>var isIE  = (navigator.appVersion.indexOf('MSIE') != -1) ? true : false;  var scrollbars = (isIE ? 'no' : 'yes');";
    print 
"function openRoom(){ window.open('".$room_link."', 'w" $roomID "', 'height=700, width=850, toolbar=no, menubar=no, scrollbars=' + scrollbars + ', location=no, directories=no, status=yes, resizable=1');}</script>";
}

// ... you can add your own code here and then add a link:

if ($openInSeparateWindow == )
{
    print 
"<a href='javascript:void(0)' onClick='openRoom()'>Access the room Here</a>";
}
else
{
    print 
"<a href=\"$room_link\">Access the room Here</a>";
}

?>