-2

i'm implementing CMR Application in CakePHP Framework 2x. In that app, i have a requirement of Online text Chat, Audio Chat, screen sharing and Video Chat. After searching quite a time, i have ended up with a decision of using CometChat 5.0 Platinum Edition. Work Progress:

  • Placed Cometchat folder in webroot directory.
  • Installed it correctly.
  • Configured database correctly.

Actually right now i'm facing issues in using it with my Applicaton. For resolving issues i have searched google, but there is not a single place to tell me:

  • How and Where to use getUserID() or chatLogin() function in CakePHP ?
  • Where or What to do with session like: $_SESSION['basedata' and $session['session_auth_user_id'] etc, there are other many sessions variables that have no meaning with my table fields or tables it had created itself.

Right now it is showing chat bar tray correctly but The Error or Alert i have to see all the time is "Please login to use the chat", after analyzing, i came to know that ChometChat should know about logined user information to start but it seems it can only get it through the sessions or somewhere else, that i probably should know. If u think i had any integeration issues, i'm posting some code here, u can see it urself : (integeration.php)

Advanced Settings:

define('SET_SESSION_NAME','');          // Session name
define('DO_NOT_START_SESSION','1');     // Set to 1 if you have already started the session
define('DO_NOT_DESTROY_SESSION','0');   // Set to 1 if you do not want to destroy session on logout
define('SWITCH_ENABLED','1');       
define('INCLUDE_JQUERY','1');   
define('FORCE_MAGIC_QUOTES','0');

DATABASE Configurations:

define('DB_SERVER',                 'localhost'                     );
define('DB_PORT',                   "3306"                             );
define('DB_USERNAME',               'root'                 );
define('DB_PASSWORD',               ''                 );
define('DB_NAME',                   'cakechat'                     );
define('TABLE_PREFIX',              ""                              );
define('DB_USERTABLE',              "users"                            );
define('DB_USERTABLE_USERID',       "id"                          );
define('DB_USERTABLE_NAME',         "username"                 );
define('DB_AVATARTABLE',            " "                                );
define('DB_AVATARFIELD',            " CONCAT(".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID."        ,CONCAT('/',".TABLE_PREFIX.DB_USERTABLE.".user_photo))" );
define('DB_USERTABLE_LASTACTIVITY', "user_lastactive");

Functions 1:

function getUserID() {
    $userid = 0;

if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
    $_REQUEST['basedata'] = $_SESSION['basedata'];
}

if (!empty($_REQUEST['basedata'])) {
    $userid = $_REQUEST['basedata'];
}

if (!empty($_COOKIE['se_auth_token'])) {
    $sql = ("select session_auth_user_id from ".TABLE_PREFIX."session_auth where session_auth_key = '".mysql_real_escape_string($_COOKIE['se_auth_token'])."'");
    $query = mysql_query($sql);
    $session = mysql_fetch_array($query);
    $userid = $session['session_auth_user_id'];
}

return $userid;

}

My only request: Please share any reference link or walk-through to make things right and functional, any little effort, will be highly appreciated. Thanks in advance !

  • It's a commercial software, you paid 499$ for it, so the first thing you should do is to [**contact their support**](http://www.cometchat.com/contact), they say that [**it integrates seamlessly with CakePHP**](http://www.cometchat.com/cakephp-chat), so they know about CakePHP and should be able to help you. – ndm Oct 04 '14 at 15:08
  • 1
    Doesn't look like you paid for it considering the latest version is 5.4. If you did, email them. I've worked with them before, friendly people. – Alec Smart Oct 06 '14 at 05:31

2 Answers2

0

user_photoMake sure you have Red5 installed on your localhost to use video,audio and screen sharing functionality, and you are using your localhost as VPS.

Use this configuration in your integration.php (E:\xampp\htdocs\project\app\webroot\cometchat)file :

define('DB_SERVER',             $config->default['host']);
define('DB_PORT',               '3306');
define('DB_USERNAME',               $config->default['login']);
define('DB_PASSWORD',               $config->default['password']);
define('DB_NAME',               $config->default['database']);
define('TABLE_PREFIX',              $config->default['prefix']);
define('DB_USERTABLE',              "users");
define('DB_USERTABLE_USERID',       "id" );
define('DB_USERTABLE_NAME',         "username");
define('DB_AVATARTABLE',            " ");
define('DB_AVATARFIELD',            " ".TABLE_PREFIX.DB_USERTABLE.".user_photo ");

and make some changes in function getAvatar()

function getAvatar($image) {
    if ($image) {
         return '../'.$image;
    } else {    
        return '../img/no-image.jpg';
    }
}
PHP Worm...
  • 4,109
  • 1
  • 25
  • 48
  • i have replaced it with my code, but nothing happened. Also it is telling me: **Undefined variable: config in C:\xampp\htdocs\CakeCometChat\app\webroot\cometchat\integration.php on line 25** – Naeem qaswar Oct 14 '14 at 10:55
0

Add this to your getUserID() function:

/*
    if (!empty($_SESSION['Auth']['User']['id'])) {
            $userid = $_SESSION['Auth']['User']['id'];
        }
    */

   function getUserID() {
        $userid = 0;

    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }

    if (!empty($_REQUEST['basedata'])) {
        $userid = $_REQUEST['basedata'];
    }

    if (!empty($_COOKIE['se_auth_token'])) {
        $sql = ("select session_auth_user_id from ".TABLE_PREFIX."session_auth where session_auth_key = '".mysql_real_escape_string($_COOKIE['se_auth_token'])."'");
        $query = mysql_query($sql);
        $session = mysql_fetch_array($query);
        $userid = $session['session_auth_user_id'];
    }

     if (!empty($_SESSION['Auth']['User']['id'])) {
            $userid = $_SESSION['Auth']['User']['id'];/*pass logged in user id here, which is stored in your session variable*/
        }

    return $userid;
    }
PHP Worm...
  • 4,109
  • 1
  • 25
  • 48
  • I have tried your code, but doesn't works for me. I was thinking where should i set this session **$_SESSION['Auth']['User']['id']**, haven't done anything related to it in my app. In CakePHP in Controller->UsersController->login() i used **$this->Session->write('User',$loginfo);** to write my session ("$loginfo" contains login information about user as $loginfo['User']['id'] and $loginfo['User']['email']). And tired to debug components of **function getUserID()** to see values, but nothing have called ever from this function and i don't get anything. – Naeem qaswar Oct 14 '14 at 11:12
  • if you are not using auth component in your project then simply use this: `if (!empty($_SESSION['Auth']['User']['id'])) { $userid = $_SESSION['variable_name']['user_id'];/*pass logged in user id here, which is stored in your session variable*/ }` – PHP Worm... Oct 14 '14 at 11:45