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

Source for file chat_message.php

Documentation is available at chat_message.php

  1. <?php // $Id: chat_message.php,v 1.11 2005/05/18 13:58:20 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. *    Allows to type the messages that will be displayed on chat_chat.php
  27. *
  28. *    @author Olivier Brouckaert
  29. *    @package dokeos.chat
  30. ==============================================================================
  31. */
  32.  
  33. /*
  34. ==============================================================================
  35.         INIT SECTION
  36. ==============================================================================
  37. */
  38.  
  39. define('FRAME','message');
  40.  
  41. $language_file array ('chat');
  42.  
  43. require('../inc/global.inc.php');
  44.  
  45. // if we have the session set up 
  46. if (!empty($course))
  47. {
  48.     include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  49.     include_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  50.     include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  51.     
  52.     /*
  53.     -----------------------------------------------------------
  54.         Constants and variables
  55.     -----------------------------------------------------------
  56.     */
  57.     $tbl_user    Database::get_main_table(TABLE_MAIN_USER);
  58.     $sent $_REQUEST['sent'];
  59.     
  60.     /*
  61.     ==============================================================================
  62.             MAIN CODE
  63.     ==============================================================================
  64.     */
  65.     $query="SELECT lastname, firstname, username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  66.     $result=api_sql_query($query,__FILE__,__LINE__);
  67.     
  68.     list($pseudoUser)=mysql_fetch_row($result);
  69.     
  70.     $isAllowed=(empty($pseudoUser|| !$_cid)?false:true;
  71.     $isMaster=$is_courseAdmin?true:false;
  72.     
  73.     $firstname=mysql_result($result,0,'firstname');
  74.     $lastname=mysql_result($result,0,'lastname');
  75.     
  76.     $dateNow=date('Y-m-d');
  77.     
  78.     $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  79.     $chatPath=$documentPath.'chat_files/';
  80.     $TABLEITEMPROPERTYDatabase::get_course_table(TABLE_ITEM_PROPERTY);
  81.     
  82.     if(!is_dir($chatPath))
  83.     {
  84.         if(is_file($chatPath))
  85.         {
  86.             @unlink($chatPath);
  87.         }
  88.     
  89.         $perm api_get_setting('permissions_for_new_directories');
  90.         $perm octdec(!empty($perm)?$perm:'0770');
  91.         @mkdir($chatPath,$perm);
  92.         @chmod($chatPath,$perm);
  93.     
  94.         $doc_id=add_document($_course,'/chat_files','folder',0,'chat_files');
  95.     
  96.         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)");
  97.         
  98.     }
  99.  
  100.     
  101.     include('header_frame.inc.php');
  102.     
  103.     $chat_size=0;
  104.     
  105.     if($sent)
  106.     {
  107.         $message=trim(htmlspecialchars(stripslashes($_POST['message']),ENT_QUOTES,$charset));
  108.         
  109.         if(!empty($message))
  110.         {
  111.             $message=make_clickable($message);
  112.     
  113.             if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
  114.             {
  115.                 $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
  116.     
  117.                 api_item_property_update($_courseTOOL_DOCUMENT$doc_id'DocumentAdded'$_user['user_id']);
  118.                 item_property_update_on_folder($_course,'/chat_files'$_user['user_id']);
  119.             }
  120.             else
  121.             {
  122.                 $doc_id DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
  123.             }
  124.     
  125.             $fp=fopen($chatPath.'messages-'.$dateNow.'.log.html','a');
  126.     
  127.             if($isMaster)
  128.             {
  129.                 fputs($fp,'<span id="chat_login_name"><b>'.$firstname.' '.$lastname.'</b></span> : '.$message.'<br>'."\n");             
  130.                 
  131.             }
  132.             else
  133.             {
  134.                 fputs($fp,"<b>$firstname $lastname</b> : $message<br>\n");
  135.             }
  136.     
  137.             fclose($fp);
  138.     
  139.             $chat_size=filesize($chatPath.'messages-'.$dateNow.'.log.html');
  140.     
  141.             update_existing_document($_course$doc_id,$chat_size);
  142.             item_property_update_on_folder($_course,'/chat_files'$_user['user_id']);
  143.         }
  144.     }
  145.     ?>
  146.     <form name="formMessage" method="post" action="<?php echo api_get_self()?>" onsubmit="javascript:if(document.formMessage.message.value == '') { alert('<?php echo addslashes(htmlentities(get_lang('TypeMessage'),ENT_QUOTES,$charset))?>'); document.formMessage.message.focus(); return false; }" autocomplete="off">
  147.     <input type="hidden" name="sent" value="1">
  148.     <table border="0" cellpadding="5" cellspacing="0" width="100%">
  149.     <tr>
  150.       <td width="520" valign="middle">
  151.           <textarea name="message" style="width: 520px; height: 35px" onkeydown="send_message(event);"></textarea>
  152.       </td>
  153.       <td>
  154.           <input type="submit" value="<?php echo get_lang("Send")?>" class="background_submit">
  155.       </td>
  156.     </tr>
  157.     </table>
  158.     </form>
  159.     <?php
  160. }
  161. include('footer_frame.inc.php');
  162. ?>

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