Exemplo n.º 1
0
function JLMS_getChatXML($course_id, $group_id, $option, $checked = false)
{
    global $JLMS_DB, $my, $JLMS_CONFIG;
    $do_chat = $checked;
    if (!$do_chat) {
        $JLMS_ACL =& JLMSFactory::getACL();
        if ($JLMS_ACL->CheckPermissions('chat', 'view')) {
            if ($JLMS_ACL->CheckPermissions('chat', 'manage')) {
                if ($group_id) {
                    if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                        $query = "SELECT group_chat FROM #__lms_usergroups WHERE course_id = 0 AND id = {$group_id}";
                        $JLMS_DB->SetQuery($query);
                        if ($JLMS_DB->LoadResult()) {
                            $do_chat = true;
                        }
                    } else {
                        $query = "SELECT group_chat FROM #__lms_usergroups WHERE course_id = {$course_id} AND id = {$group_id}";
                        $JLMS_DB->SetQuery($query);
                        if ($JLMS_DB->LoadResult()) {
                            $do_chat = true;
                        }
                    }
                } else {
                    $do_chat = true;
                }
            } else {
                if ($group_id) {
                    if ($JLMS_CONFIG->get('use_global_groups', 1)) {
                        $query = "SELECT group_chat FROM #__lms_users_in_global_groups AS uigg, #__lms_usergroups AS ug WHERE uigg.user_id = {$my->id} AND uigg.group_id = {$group_id} AND ug.id = uigg.group_id";
                        $JLMS_DB->setQuery($query);
                        if ($JLMS_DB->LoadResult()) {
                            $do_chat = true;
                        }
                    } else {
                        $query = "SELECT b.group_chat FROM #__lms_users_in_groups as a, #__lms_usergroups as b" . "\n WHERE a.course_id = {$course_id} AND a.group_id = {$group_id} AND a.user_id = '" . $my->id . "' AND a.group_id = b.id AND b.id = {$group_id} AND b.course_id = {$course_id}";
                        $JLMS_DB->SetQuery($query);
                        if ($JLMS_DB->LoadResult()) {
                            $do_chat = true;
                        }
                    }
                } else {
                    $do_chat = true;
                }
            }
        }
    }
    if ($do_chat) {
        $last_msg = intval(mosGetParam($_REQUEST, 'last_msg', 0));
        //query (Drop users)
        $tim_minus_15 = time() - date('Z') - 15 * 60;
        $query = "DELETE FROM #__lms_chat_users WHERE time_post < '" . date('Y-m-d H:i:s', $tim_minus_15) . "'";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        $query = "SELECT time_enter, time_post FROM #__lms_chat_users" . "\n WHERE user_id = '" . $my->id . "' AND course_id = '" . $course_id . "' AND group_id = '" . $group_id . "'";
        $JLMS_DB->SetQuery($query);
        $XML_data = '';
        $user_time_obj = $JLMS_DB->LoadObject();
        if (is_object($user_time_obj) && isset($user_time_obj->time_enter)) {
            $time_online = $user_time_obj->time_enter;
            $time_prev_post = $user_time_obj->time_post;
            if ($time_online) {
                //query (Update time)
                $query = "UPDATE #__lms_chat_users SET time_post = '" . gmdate('Y-m-d H:i:s') . "'" . "\n WHERE user_id = '" . $my->id . "' AND course_id = '" . $course_id . "' AND group_id = '" . $group_id . "'";
                $JLMS_DB->SetQuery($query);
                $JLMS_DB->query();
                $query = "SELECT a.username FROM #__users as a, #__lms_chat_users as b" . "\n WHERE a.id = b.user_id AND b.course_id = '" . $course_id . "' AND b.group_id = '" . $group_id . "'" . "\n ORDER BY a.username";
                $JLMS_DB->SetQuery($query);
                $chat_users = $JLMS_DB->LoadObjectList();
                $query = "SELECT a.username, b.user_message, b.mes_time, b.id FROM #__users as a, #__lms_chat_history as b" . "\n WHERE a.id = b.user_id AND b.course_id = '" . $course_id . "' AND b.mes_time > '" . $time_online . "'" . "\n AND b.group_id = '" . $group_id . "' AND (b.recv_id = '0' OR b.recv_id = '" . $my->id . "')" . "\n ORDER BY b.mes_time DESC, b.id DESC LIMIT 0, 100";
                $JLMS_DB->SetQuery($query);
                $chat_history = $JLMS_DB->LoadObjectList();
                $new_chat_history = array();
                $time_prev_post_time = strtotime($time_prev_post);
                $do_scroll_chat = false;
                $new_last_id = 0;
                $i = count($chat_history) - 1;
                if (isset($chat_history[0]->mes_time)) {
                    $time_last_post_time = strtotime($chat_history[0]->mes_time);
                    if ($time_last_post_time >= $time_prev_post_time) {
                        $do_scroll_chat = true;
                    }
                }
                while ($i >= 0) {
                    $new_chat_history[] = $chat_history[$i];
                    $i--;
                }
                /* 29.05.2008 - changes by DEN */
                $show_chat_history = array();
                for ($i = 0; $i < count($new_chat_history); $i++) {
                    if ($new_chat_history[$i]->id > $last_msg) {
                        $show_chat_history[] = $new_chat_history[$i];
                        if ($new_chat_history[$i]->id > $new_last_id) {
                            $new_last_id = $new_chat_history[$i]->id;
                        }
                    }
                }
                $count_mes = count($show_chat_history);
                $XML_data .= "\t" . '<task>chat_xml</task>' . "\n";
                $XML_data .= "\t" . '<count_new_msgs>' . $count_mes . '</count_new_msgs>' . "\n";
                $XML_data .= "\t" . '<chat_last_id>' . $new_last_id . '</chat_last_id>' . "\n";
                $XML_data .= "\t" . '<chat_users><![CDATA[' . JLMS_chat_html::prepareUserList($chat_users) . ']]></chat_users>' . "\n";
                //$XML_data .= "\t" . '<chat_history><![CDATA['.JLMS_chat_html::prepareChatHistory($new_chat_history).']]></chat_history>' . "\n";
                $i = 1;
                foreach ($show_chat_history as $data) {
                    $CDATA = '<b>' . $data->username . ': </b><br />';
                    $CDATA .= JLMS_nl2br($data->user_message);
                    $XML_data .= "\t" . '<chat_message_' . $i . '><![CDATA[' . $CDATA . ']]></chat_message_' . $i . '>' . "\n";
                    $i++;
                }
            }
        }
        $iso = explode('=', _ISO);
        echo "\n" . "some notices :)";
        $debug_str = ob_get_contents();
        $debug_str = "no debug info";
        ob_end_clean();
        header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Cache-Control: no-cache, must-revalidate');
        header('Pragma: no-cache');
        if (class_exists('JFactory')) {
            $document =& JFactory::getDocument();
            $charset_xml = $document->getCharset();
            header('Content-Type: text/xml; charset=' . $charset_xml);
        } else {
            header('Content-Type: text/xml');
        }
        if ($XML_data != "") {
            echo '<?xml version="1.0" encoding="' . $iso[1] . '" standalone="yes"?>';
            echo '<response>' . "\n";
            echo $XML_data;
            echo "\t" . '<debug><![CDATA[' . $debug_str . ']]></debug>' . "\n";
            echo '</response>' . "\n";
        } else {
            echo '<?xml version="1.0" encoding="' . $iso[1] . '" standalone="yes"?>';
            echo '<response>' . "\n";
            echo "\t" . '<task>failed</task>' . "\n";
            echo "\t" . '<info>boom</info>' . "\n";
            echo "\t" . '<debug><![CDATA[' . $debug_str . ']]></debug>' . "\n";
            echo '</response>' . "\n";
        }
    }
    exit;
}
Exemplo n.º 2
0
/**
 * 28.02.2007 - DEN
 * Function return string, which is safe for overlib windows.
 * exampe of use this string in html code:
 * 		 echo "<a onmouseover='overlib(\"".JLMS_txt2overlib($description)."\", ......
 * !!! ordering of quotes is important
 * 
 * @param string $string -- bad string with double quotes and linebreakes (\n,\r)
 * @return string -- well-formed string for overlib using
 */
function JLMS_txt2overlib($string)
{
    $string = JLMS_nl2br($string);
    $string = str_replace('\\"', '\\\\"', $string);
    $string = str_replace('"', '\\"', $string);
    $string = str_replace("'", "&#039;", $string);
    $string = str_replace('\\&quot;', '\\\\\\"', $string);
    $string = str_replace('&quot;', '\\"', $string);
    return $string;
}