Integrate Smart PHP Calendar to Your Web Application

Smart PHP Calendar is very flexible. You can use it as a standalone application or integrate it to your existing web application. At the end of the integration Smart PHP Calendar will behave as a native part of your application.
When your users login to your own web application they can use Smart PHP Calendar without logging in to it again.

To integrate Smart PHP Calendar to your web application follow these steps:

  1. Install Smart PHP Calendar
  2. Login to Smart PHP Calendar and create an administrator.
  3. Require Smart PHP Calendar Engine "SpcEngine.php" file and import your application's users to Smart PHP Calendar.
    <?php
    //your-import-file.php
    
    require 'path/to/smartphpcalendar/SpcEngine.php';
    
    //define your users
    //example users, here you can connect to your application database and fetch your own users
    //usernames and emails must be same in your own web application
    $users = array(
        array('username' => 'user1', 'email' => 'user1@your-host.com'),
        array('username' => 'user2', 'email' => 'user2@your-host.com'),
        array('username' => 'user3', 'email' => 'user2@your-host.com'),
        ...
    );
    
    try {
        Spc::importUsers($adminUsername, $users);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    
  4. Override Smart PHP Calendar's user authentication.
    <?php
    
    // In your own user authentication logic require Smart PHP Calendar Engine "SpcEngine.php"
    // and run Spc::login($username) method.
    
    function yourApplicationUserAuthenticationFunction($username, $password, $otherParams) {
        //...
        // your own application and user authentication codes
        //...
    
        //Login to Smart PHP Calendar
        if ($yourApplicationUserLoginSuccess == true) {
            require 'path/to/smartphpcalendar/SpcEngine.php';
            
            try {
                Spc::login($username);
            } catch (Exception $e) {
                echo $e->getMessage();
            }
        }
    }
    
  5. Add new users to Smart PHP Calendar when you create users in your application.
    <?php
    
    // when you create a new user in your web application you must add this code for 
    // importing your user to Smart PHP Calendar
    
    //...
    // your own application codes for creating a user
    //...
    
    require 'path/to/smartphpcalendar/SpcEngine.php';
    $user = array('username' => 'user1', 'email' => 'user1@your-host.com');
    
    try {
        Spc::createUser($user);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    
  6. Delete users when you delete them from your application.
    <?php
    
    //...
    // your own application codes for deleting a user
    //...
    
    require 'path/to/smartphpcalendar/SpcEngine.php';
    
    try {
        Spc::deleteUser($username);
    } catch (Exception $e) {
        echo $e->getMessage();
    }