Dokeos PHP Cross Reference Learning Management Systems

Source: /main/group/new_message.php - 433 lines - 15215 bytes - Summary - Text - Print

   1  <?php
   2  /* For licensing terms, see /license.txt */
   3  /**
   4  *    @package dokeos.messages
   5  */
   6  
   7  
   8  /**
   9  * This script shows a compose area (wysiwyg editor if supported, otherwise
  10  * a simple textarea) where the user can type a message.
  11  * There are three modes
  12  * - standard: type a message, select a user to send it to, press send
  13  * - reply on message (when pressing reply when viewing a message)
  14  * - send to specific user (when pressing send message in the who is online list)
  15  */
  16  /*         INIT SECTION    */
  17  // name of the language file that needs to be included
  18  $language_file= array('messages','userInfo','group');
  19  $cidReset    = true;
  20  require_once  '../inc/global.inc.php';
  21  
  22  api_block_anonymous_users();
  23  
  24  if (api_get_setting('allow_message_tool')!='true'){
  25      api_not_allowed();
  26  }
  27  
  28  require_once api_get_path(LIBRARY_PATH).'text.lib.php';
  29  require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  30  require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  31  require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  32  require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  33  
  34  $nameTools = api_xml_http_response_encode(get_lang('Messages'));
  35  /*    Constants and variables */
  36  $htmlHeadXtra[] = '<script type="text/javascript">
  37  
  38  function show_icon_edit(element_html) {
  39      ident="#edit_image";
  40      $(ident).show();
  41  }
  42  
  43  function hide_icon_edit(element_html)  {
  44      ident="#edit_image";
  45      $(ident).hide();
  46  }
  47  
  48  </script>';
  49  
  50  $htmlHeadXtra[] = '
  51      <style>
  52      div.row div.label{
  53          width: 10%;
  54      }
  55      div.row div.formw{
  56          width: 85%;
  57      }
  58  
  59      </style>
  60      ';
  61  
  62  $htmlHeadXtra[]='
  63  <script language="javascript">
  64  function validate(form,list) {
  65      if(list.selectedIndex<0)
  66      {
  67          alert("Please select someone to send the message to.")
  68          return false
  69      }
  70      else
  71          return true
  72  }
  73  
  74  </script>';
  75  //$htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  76  
  77  $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.js" type="text/javascript" language="javascript"></script>';
  78  $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css" type="text/css" media="projection, screen">';
  79  
  80  $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
  81  $htmlHeadXtra[] = '<link  href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
  82  
  83  $htmlHeadXtra[] = '<script type="text/javascript">
  84  $(document).ready(function (){
  85  
  86                $("#users").fcbkcomplete({
  87                  json_url: "message.ajax.php?a=find_users",
  88                  cache: false,
  89                  filter_case: false,
  90                  filter_hide: true,                
  91                  firstselected: true,
  92                  //onremove: "testme",
  93                  //onselect: "testme",
  94                  filter_selected: true,
  95                  newel: true
  96                });
  97  });
  98  
  99  var counter_image = 1;
 100  /*
 101  function remove_image_form(id_elem1) {
 102      var elem1 = document.getElementById(id_elem1);
 103      elem1.parentNode.removeChild(elem1);
 104  }
 105  */
 106  function add_image_form() {
 107      // Multiple filepaths for image form
 108      var filepaths = document.getElementById("filepaths");
 109      if (document.getElementById("filepath_"+counter_image)) {
 110          counter_image = counter_image + 1;
 111      }  else {
 112          counter_image = counter_image;
 113      }
 114      var elem1 = document.createElement("div");
 115      elem1.setAttribute("id","filepath_"+counter_image);
 116      filepaths.appendChild(elem1);
 117      id_elem1 = "filepath_"+counter_image;
 118      id_elem1 = "\'"+id_elem1+"\'";
 119      //document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\"  size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"'.api_get_path(WEB_CODE_PATH).'img/delete.gif\"></a>";
 120      document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\"  size=\"28\" />&nbsp;<input type=\"text\" name=\"legend[]\" size=\"20\" /></a>";
 121      if (filepaths.childNodes.length == 6) {
 122          var link_attach = document.getElementById("link-more-attach");
 123          if (link_attach) {
 124              link_attach.innerHTML="";
 125          }
 126      }
 127  }
 128  
 129  </script>';
 130  
 131  $nameTools = get_lang('ComposeMessage');
 132  
 133  /*
 134          FUNCTIONS
 135  */
 136  
 137  /**
 138  * Shows the compose area + a list of users to select from.
 139  */
 140  function show_compose_to_any ($user_id) {
 141      $online_user_list = MessageManager::get_online_user_list($user_id);
 142      $default['user_list'] = 0;
 143      $online_user_list=null;
 144      manage_form($default, $online_user_list);
 145  }
 146  
 147  function show_compose_reply_to_message ($message_id, $receiver_id) {
 148      global $charset;
 149      $table_message = Database::get_main_table(TABLE_MESSAGE);
 150      if(api_is_allowed_to_edit()){
 151      $query = "SELECT user_sender_id FROM $table_message WHERE id='".intval($message_id)."';";
 152      }
 153      else {
 154      $query = "SELECT user_sender_id FROM $table_message WHERE user_receiver_id=".intval($receiver_id)." AND id='".intval($message_id)."';";
 155      }
 156      $result = Database::query($query);
 157      $row = Database::fetch_array($result,'ASSOC');
 158      if (!isset($row['user_sender_id'])) {
 159          echo get_lang('InvalidMessageId');
 160          die();
 161      }
 162  
 163      $pre_html = '<div class="row">
 164                  <div class="label">'.get_lang('Contact').'</div>
 165                  <div class="formw">';
 166      $post = '</div></div>';
 167      $multi_select = '<select id="users" name="users">
 168                       </select>';
 169      echo $pre_html.'<strong>'.GetFullUserName($row['user_sender_id']).'</strong>'.$post;
 170      //echo get_lang('To').':&nbsp;<strong>'.    GetFullUserName($row['user_sender_id']).'</strong>';
 171      //$default['title'] = get_lang('EnterTitle');
 172      $default['users'] = array($row['user_sender_id']);
 173      manage_form($default);
 174  }
 175  
 176  function show_compose_to_user ($receiver_id) {
 177      global $charset;
 178  //    echo get_lang('To').':&nbsp;<strong>'.    GetFullUserName($receiver_id).'</strong>';
 179  //    $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle'));
 180      $pre_html = '<div class="row">
 181                  <div class="label">'.get_lang('Contact').'</div>
 182                  <div class="formw">';
 183      $post = '</div></div>';
 184      $multi_select = '<select id="users" name="users">
 185                       </select>';
 186      echo $pre_html.'<strong>'.GetFullUserName($receiver_id).'</strong>'.$post;
 187  
 188      $default['users'] = array($receiver_id);
 189      manage_form($default);
 190  }
 191  
 192  function manage_form ($default, $select_from_user_list = null) {
 193  
 194      global $charset;
 195      $table_message = Database::get_main_table(TABLE_MESSAGE);
 196  
 197      $group_id     = intval($_REQUEST['group_id']);
 198      $message_id = intval($_GET['message_id']);
 199      $param_f = isset($_GET['f'])?Security::remove_XSS($_GET['f']):'';
 200      $current_group = GroupManager :: get_group_properties($group_id);
 201  
 202  
 203      if(api_is_allowed_to_edit()){
 204          $users = GroupManager::get_group_users($group_id);
 205          $tutors = GroupManager::get_group_tutorslist($group_id);
 206          $users = array_merge($users,$tutors);
 207      }
 208      elseif(api_is_grouptutor($_course,api_get_session_id(),api_get_user_id())){
 209          $users = GroupManager::get_group_users($group_id);
 210          $tutors = GroupManager::get_othergroup_tutors($group_id);
 211          $users = array_merge($users,$tutors);
 212      }
 213      else {
 214          if($current_group['category_id'] == 1){
 215              $users = GroupManager::get_group_tutorslist($group_id);
 216          }
 217          else {
 218              $tutors = GroupManager::get_group_tutorslist($group_id);
 219              $users = GroupManager::get_group_users($group_id);
 220              $users = array_merge($users,$tutors);
 221          }
 222      }
 223  
 224      $form = new FormValidator('compose_message',null,api_get_self().'?'.api_get_cidReq().'&id_session='.api_get_session_id(),null,array('enctype'=>'multipart/form-data'));
 225      if (!empty($group_id)) {
 226          if (isset($select_from_user_list)) {            
 227          /*    $form->add_textfield('id_text_name', get_lang('Contact'),true,array('size' => 30,'id'=>'id_text_name','onkeyup'=>'send_request_and_search()','autocomplete'=>'off','style'=>'padding:0px'));
 228              $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
 229              $form->addElement('html','<div id="id_div_search" style="padding:0px" class="message-select-box" >&nbsp;</div>');*/
 230              $form->addElement('select','users',get_lang('Contact'),$select_from_user_list);
 231              $form->addElement('hidden','user_list',0,array('id'=>'user_list'));
 232          } else {
 233              if (empty($default['users'])) {                
 234                  //the magic should be here
 235              /*    $pre_html = '<div class="row">
 236                              <div class="label">'.get_lang('Contact').'</div>
 237                              <div class="formw">';
 238                  $post = '</div></div>';
 239                  $multi_select = '<select id="users" name="users">
 240                                     </select>';
 241                  $form->addElement('html',$pre_html.$multi_select.$post );*/
 242                  if(sizeof($users) == 0){
 243                  $form->addElement('static','users',get_lang('Contact'),get_lang('NoContacts'));
 244                  }
 245                  else {
 246                  $form->addElement('select','users',get_lang('Contact'),$users,array('multiple' => 'multiple','size' => '5'));
 247                  }
 248  
 249              } else {
 250                  $form->addElement('hidden','hidden_user',$default['users'][0],array('id'=>'hidden_user'));
 251              }
 252          }
 253      } 
 254      /*else {
 255          $group_info = GroupPortalManager::get_group_data($group_id);
 256          $form->addElement('html','<div class="row"><div class="label">'.get_lang('ToGroup').'</div><div class="formw">'.api_xml_http_response_encode($group_info['name']).'</div></div>');
 257          $form->addElement('hidden','group_id',$group_id);
 258          $form->addElement('hidden','parent_id',$message_id);
 259      }*/
 260  
 261      $form->add_textfield('title', get_lang('Subject'),true ,array('size' => 55));
 262  
 263      $form->add_html_editor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250'));
 264      //$form->addElement('textarea','content', get_lang('Message'), array('cols' => 75,'rows'=>8));
 265  
 266      if (isset($_GET['re_id'])) {
 267          $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
 268          $form->addElement('hidden','re_id',Security::remove_XSS($_GET['re_id']));
 269          $form->addElement('hidden','save_form','save_form');
 270          
 271          //adding reply mail
 272          $user_reply_info = UserManager::get_user_info_by_id($message_reply_info['user_sender_id']);
 273          $default['content']='<p></p>'.api_get_person_name($user_reply_info['firstname'],$user_reply_info['lastname']).' '.get_lang('Wrote').' :<i> <br />'.api_html_entity_decode($message_reply_info['content'],ENT_QUOTES,$charset).'</i>';
 274          
 275      }
 276      //if (empty($group_id)) {
 277          $form->addElement('html','<div class="row"><div class="label">'.get_lang('FilesAttachment').'</div><div class="formw">
 278                  <span id="filepaths">
 279                  <div id="filepath_1">
 280                  <input type="file" name="attach_1"  size="28" />
 281                  <input type="text" name="legend[]" size="20" />
 282                  </div></span></div></div>');
 283          $form->addElement('html','<div class="row"><div class="formw"><span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a></span>&nbsp;('.sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize'))).')</div></div>');
 284      //}
 285  
 286      $form->addElement('style_submit_button','compose',api_xml_http_response_encode(get_lang('SendMessage')),'class="save"');
 287      if (!empty($group_id) && !empty($message_id)) {
 288          $message_info = MessageManager::get_message_by_id($message_id);
 289          $default['title']=get_lang('Re:').api_html_entity_decode($message_info['title'],ENT_QUOTES,$charset);
 290      }
 291      $form->setDefaults($default);
 292  
 293      if ($form->validate()) {        
 294          $check = Security::check_token('post');
 295          if ($check) {
 296              $values         = $default;
 297              $user_list        = $values['users'];
 298              $file_comments    = $_POST['legend'];
 299              $title             = $values['title'];
 300              $content         = $values['content'];
 301  
 302              $group_id        = $values['group_id'];
 303              $parent_id         = $values['parent_id'];
 304  
 305              if (is_array($user_list) && count($user_list)> 0) {
 306                  //all is well, send the message
 307                  foreach ($user_list as $user) {                    
 308                      $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
 309                      if ($res) {
 310                          if (is_string($res)) {
 311                              Display::display_error_message($res);
 312                          } else {
 313                              MessageManager::display_success_message($user);
 314                          }
 315                      }
 316                  }
 317              }
 318          }
 319          Security::clear_token();
 320      } else {
 321          $token = Security::get_token();
 322          $form->addElement('hidden','sec_token');
 323          $form->setConstants(array('sec_token' => $token));
 324          $form->display();
 325      }
 326  }
 327  // the section (for the tabs)
 328  $this_section = SECTION_COURSES;
 329  
 330  // current group
 331  $current_group = GroupManager :: get_group_properties($_SESSION['_gid']);
 332  
 333  // tracking
 334  event_access_tool(TOOL_GROUP);
 335  
 336  $nameTools = get_lang('GroupSpace');
 337  
 338  // breadcrumbs
 339  $interbreadcrumb[] = array ("url" => "group.php", "name" => get_lang("Groups"));
 340  
 341  
 342  // display the header
 343  Display::display_header($nameTools.' '.$current_group['name'],'Group');
 344  
 345  
 346  // Display actions
 347  echo '<div class="actions">';
 348  echo '<a href="group.php?'.api_get_cidReq().'">'.Display::return_icon('pixel.gif',get_lang('MyGroup'),array('class'=>'toolactionplaceholdericon toolactiongroupimage')).get_lang('MyGroup').'</a>';
 349  echo '<a href="inbox.php?'.api_get_cidReq().'">'.Display::return_icon('pixel.gif', get_lang('Inbox'),array('class'=>'toolactionplaceholdericon toolactioninbox')).get_lang('Inbox').'</a>';
 350  echo '<a href="new_message.php?'.api_get_cidReq().'">'.Display::return_icon('pixel.gif', get_lang('ComposeMessage'), array('class'=>'toolactionplaceholdericon toolactionsinvite')).get_lang('ComposeMessage').'</a>';
 351  echo '<a href="outbox.php?'.api_get_cidReq().'">'.Display::return_icon('pixel.gif', get_lang('Outbox'),array('class'=>'toolactionplaceholdericon toolactionoutbox')).get_lang('Outbox').'</a>';
 352  $group_id = intval($_REQUEST['group_id']);
 353  
 354  echo '</div>';
 355  // Start content
 356  echo '<div id="content">';
 357  
 358  echo '<div id="social-content" >';
 359      $id_content_right = '';
 360      //LEFT COLUMN
 361      if (api_get_setting('allow_social_tool') != 'true') {
 362      //
 363      } else {
 364          require_once api_get_path(LIBRARY_PATH).'social.lib.php';
 365          /*echo '<div id="social-content-left">';
 366              //this include the social menu div
 367              SocialManager::show_social_menu('messages_compose');
 368          echo '</div>';*/
 369          $id_content_right = 'social-content-all';
 370      }
 371  
 372      echo '<div id="'.$id_content_right.'">';
 373  
 374          //MAIN CONTENT
 375          if (!isset($_POST['compose'])) {
 376              if(isset($_GET['re_id'])) {
 377                  show_compose_reply_to_message($_GET['re_id'], api_get_user_id());
 378              } elseif(isset($_GET['send_to_user'])) {
 379                  show_compose_to_user($_GET['send_to_user']);
 380              } else {
 381                  show_compose_to_any($_user['user_id']);
 382                }
 383          } else {
 384  
 385              $restrict = false;
 386              if (isset($_POST['users'])) {
 387                  $restrict = true;
 388              } elseif (isset($_POST['group_id'])) {
 389                  $restrict = true;
 390              } elseif(isset($_POST['hidden_user'])) {
 391                  $restrict = true;
 392              }
 393  
 394              $default['title']    = $_POST['title'];
 395              $default['content'] = $_POST['content'];
 396  
 397              // comes from a reply button
 398              if (isset($_GET['re_id'])) {
 399                  manage_form($default);
 400              } else {
 401                  // post
 402                  if ($restrict) {
 403                      if (!isset($_POST['group_id'])) {
 404                          $default['users']     = $_POST['users'];
 405                      } else {
 406                          $default['group_id'] = $_POST['group_id'];
 407                      }
 408                      if (isset($_POST['hidden_user'])) {
 409                          $default['users']     = array($_POST['hidden_user']);
 410                      }
 411                      manage_form($default);
 412                  } else {
 413                      echo get_lang('ErrorSendingMessage');
 414                  }
 415              }
 416          }
 417      echo '</div>';
 418  
 419  echo '</div>';
 420  
 421  // End content
 422  echo '</div>';
 423  
 424  // Actions
 425  echo '<div class="actions">';
 426  echo '</div>';
 427  
 428  /*
 429          FOOTER
 430  */
 431  Display::display_footer();
 432  
 433  ?>

title

Description

title

Description

title

Description

title

title

Body