dokeos-chat
[ class tree: dokeos-chat ] [ index: dokeos-chat ] [ all elements ]

Source for file chat_chat.php

Documentation is available at chat_chat.php

  1. <?php // $Id: chat_chat.php,v 1.10 2005/05/18 13:58:10 bvanderkimpen Exp $
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004 Dokeos S.A.
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) Olivier Brouckaert
  10.  
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.  
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.  
  19.     See the GNU General Public License for more details.
  20.  
  21.     Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  22. ==============================================================================
  23. */
  24. /**
  25. ==============================================================================
  26. *    Chat frame that shows the message list
  27. *
  28. *    @author Olivier Brouckaert
  29. *    @package dokeos.chat
  30. ==============================================================================
  31. */
  32.  
  33. define('FRAME','chat');
  34.  
  35. $language_file array ('chat');
  36. require('../inc/global.inc.php');
  37. include(api_get_path(LIBRARY_PATH).'document.lib.php');
  38. include (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  39.  
  40. // if we have the session set up 
  41. if (!empty($course))
  42. {    
  43.     $reset=$_GET['reset']?true:false;
  44.     $tbl_user Database::get_main_table(TABLE_MAIN_USER);
  45.     $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  46.     $result=api_sql_query($query,__FILE__,__LINE__);
  47.     
  48.     list($pseudoUser)=mysql_fetch_row($result);
  49.     
  50.     $isAllowed=(empty($pseudoUser|| !$_cid)?false:true;
  51.     $isMaster=$is_courseAdmin?true:false;
  52.     
  53.     
  54.     $dateNow=date('Y-m-d');
  55.     
  56.     $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  57.     $chatPath=$documentPath.'chat_files/';
  58.     $TABLEITEMPROPERTYDatabase::get_course_table(TABLE_ITEM_PROPERTY);
  59.     
  60.     if(!is_dir($chatPath))
  61.     {
  62.         if(is_file($chatPath))
  63.         {
  64.             @unlink($chatPath);
  65.         }
  66.         
  67.         $perm api_get_setting('permissions_for_new_directories');
  68.         $perm octdec(!empty($perm)?$perm:'0770');
  69.         @mkdir($chatPath,$perm);
  70.         @chmod($chatPath,$perm);
  71.     
  72.         $doc_id=add_document($_course,'/chat_files','folder',0,'chat_files');
  73.     
  74.         api_sql_query("INSERT INTO ".$TABLEITEMPROPERTY " (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$doc_id,'DocumentAdded',1,0,NULL,0)");
  75.         
  76.     }
  77.     
  78.     if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
  79.     {
  80.         @fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
  81.     
  82.         $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
  83.     
  84.         api_item_property_update($_courseTOOL_DOCUMENT$doc_id'DocumentAdded'$_user['user_id']);
  85.         item_property_update_on_folder($_course,'/chat_files'$_user['user_id']);
  86.     }
  87.     
  88.     if($reset && $isMaster)
  89.     {
  90.         $i=1;
  91.     
  92.         while(file_exists($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'))
  93.         {
  94.             $i++;
  95.         }
  96.     
  97.         @rename($chatPath.'messages-'.$dateNow.'.log.html',$chatPath.'messages-'.$dateNow.'-'.$i.'.log.html');
  98.     
  99.         @fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
  100.     
  101.         $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'-'.$i.'.log.html','file',filesize($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'),'messages-'.$dateNow.'-'.$i.'.log.html');
  102.     
  103.         api_item_property_update($_courseTOOL_DOCUMENT$doc_id'DocumentAdded'$_user['user_id']);
  104.         item_property_update_on_folder($_course,'/chat_files'$_user['user_id']);
  105.     
  106.         $doc_id DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
  107.     
  108.         update_existing_document($_course$doc_id,0);
  109.     }
  110.     
  111.     $content=file($chatPath.'messages-'.$dateNow.'.log.html');
  112.     $nbr_lines=sizeof($content);
  113.     $remove=$nbr_lines-100;
  114.     
  115.     if($remove 0)
  116.     {
  117.         $remove=0;
  118.     }
  119.     
  120.     array_splice($content,0,$remove);
  121.     include('header_frame.inc.php');
  122.     
  123.     if ($_GET["origin"]=='whoisonline'{  //the caller
  124.         $content[0]=get_lang('CallSent').'<br>'.$content[0];
  125.     }
  126.     if ($_GET["origin"]=='whoisonlinejoin'{   //the joiner (we have to delete the chat request to him when he joins the chat)
  127.         $track_user_table Database::get_main_table(TABLE_MAIN_USER);
  128.         $sql="update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='' where (user_id = ".$_user['user_id'].")";
  129.         $result=api_sql_query($sql,__FILE__,__LINE__);
  130.     }
  131.     
  132.     echo '<div style="margin-left: 5px;">';
  133.     foreach($content as $thisLine)
  134.     {
  135.         echo strip_tags(html_entity_decode($thisLine),'<br> <span> <b>');
  136.     }
  137.     echo '</div>';
  138.     
  139.     ?>
  140.     
  141.     <a name="bottom" style="text-decoration:none;">&nbsp;</a>
  142.     
  143.     <?php
  144.     if($isMaster || $is_courseCoach)
  145.     {
  146.         $rand=mt_rand(1,1000);        
  147.         echo '<div style="margin-left: 5px;">';
  148.         echo '<a href="'.api_get_self().'?rand='.$rand.'&reset=1#bottom" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang('ConfirmReset'),ENT_QUOTES,$charset)).'\')) return false;"><img src="../img/delete.gif" border="0" alt="" align="absbottom">'.get_lang('ClearList').'</a>';
  149.         echo '</div>';
  150.     }
  151. }
  152. else
  153. {    include('header_frame.inc.php');
  154.     $message=get_lang('CloseOtherSession');    
  155.     Display :: display_error_message($message);    
  156. }
  157. include('footer_frame.inc.php');
  158. ?>

Documentation generated on Thu, 12 Jun 2008 13:03:14 -0500 by phpDocumentor 1.4.1