b2evolution PHP Cross Reference Blogging Systems

Source: /inc/messaging/views/_thread.form.php - 204 lines - 6543 bytes - Summary - Text - Print

Description: This file is part of b2evolution - {@link http://b2evolution.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file is part of b2evolution - {@link http://b2evolution.net/}
   4   * See also {@link http://sourceforge.net/projects/evocms/}.
   5   *
   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.
   8   *
   9   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  10   *
  11   * {@internal Open Source relicensing agreement:
  12   * The Evo Factory grants Francois PLANQUE the right to license
  13   * The Evo Factory's contributions to this file and the b2evolution project
  14   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  15   * }}
  16   *
  17   * @package messaging
  18   *
  19   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  20   * @author efy-maxim: Evo Factory / Maxim.
  21   * @author fplanque: Francois Planque.
  22   *
  23   * @version $Id: _thread.form.php 6136 2014-03-08 07:59:48Z manuel $
  24   */
  25  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  26  
  27  /**
  28   * @var Message
  29   */
  30  global $edited_Message;
  31  global $edited_Thread;
  32  
  33  global $DB, $action;
  34  
  35  global $Blog;
  36  
  37  $creating = is_create_action( $action );
  38  
  39  if( !isset( $params ) )
  40  {
  41      $params = array();
  42  }
  43  $params = array_merge( array(
  44      'form_class' => 'fform',
  45      'form_title' => T_('New thread'),
  46      'form_action' => NULL,
  47      'form_name' => 'thread_checkchanges',
  48      'form_layout' => 'compact',
  49      'redirect_to' => regenerate_url( 'action', '', '', '&' ),
  50      'cols' => 80,
  51      'thrdtype' => param( 'thrdtype', 'string', 'discussion' ),  // alternative: individual
  52      'skin_form_params' => array(),
  53      'allow_select_recipients' => true,
  54      ), $params );
  55  
  56  $Form = new Form( $params['form_action'], $params['form_name'], 'post', $params['form_layout'] );
  57  
  58  $Form->switch_template_parts( $params['skin_form_params'] );
  59  
  60  if( is_admin_page() )
  61  {
  62      $Form->global_icon( T_('Cancel editing!'), 'close', regenerate_url( 'action' ) );
  63  }
  64  
  65  $Form->begin_form( $params['form_class'], $params['form_title'], array( 'onsubmit' => 'return check_form_thread()') );
  66  
  67      $Form->add_crumb( 'messaging_threads' );
  68      $Form->hiddens_by_key( get_memorized( 'action'.( $creating ? ',msg_ID' : '' ) ) ); // (this allows to come back to the right list order & page)
  69      $Form->hidden( 'redirect_to', $params[ 'redirect_to' ] );
  70      if( !empty( $Blog ) )
  71      { // Set blog as hidden param, because we may need the blog locale after submit
  72          // This issues should be solved differently
  73          $Form->hidden( 'blog', $Blog->ID );
  74      }
  75  
  76  if( $params['allow_select_recipients'] )
  77  {    // User can select recipients
  78      $Form->text_input( 'thrd_recipients', $edited_Thread->recipients, $params['cols'], T_('Recipients'),
  79          '<noscript>'.T_('Enter usernames. Separate with comma (,)').'</noscript>', array( 'maxlength'=> 255, 'required'=>true, 'class'=>'wide_input' ) );
  80  
  81      echo '<div id="multiple_recipients">';
  82      $Form->radio( 'thrdtype', $params['thrdtype'], array(
  83                                      array( 'discussion', T_( 'Start a group discussion' ) ),
  84                                      array( 'individual', T_( 'Send individual messages' ) )
  85                                  ), T_('Multiple recipients'), true );
  86      echo '</div>';
  87  }
  88  else
  89  {    // No available to select recipients, Used in /contact.php
  90      $Form->info( T_('Recipients'), $edited_Thread->recipients );
  91      foreach( $recipients_selected as $recipient )
  92      {
  93          $Form->hidden( 'thrd_recipients_array[id][]', $recipient['id'] );
  94          $Form->hidden( 'thrd_recipients_array[title][]', $recipient['title'] );
  95      }
  96  }
  97  
  98  $Form->text_input( 'thrd_title', $edited_Thread->title, $params['cols'], T_('Subject'), '', array( 'maxlength'=> 255, 'required'=>true, 'class'=>'wide_input' ) );
  99  
 100  $Form->textarea_input( 'msg_text', isset( $edited_Thread->text ) ? $edited_Thread->text : $edited_Message->text, 10, T_('Message'), array( 'cols'=>$params['cols'], 'class'=>'wide_textarea', 'required'=>true ) );
 101  
 102  global $thrd_recipients_array, $recipients_selected;
 103  if( !empty( $thrd_recipients_array ) )
 104  {    // Initialize the preselected users (from post request or when user send a message to own contacts)
 105      foreach( $thrd_recipients_array['id'] as $rnum => $recipient_ID )
 106      {
 107          $recipients_selected[] = array(
 108              'id'    => $recipient_ID,
 109              'title' => $thrd_recipients_array['title'][$rnum]
 110          );
 111      }
 112  }
 113  
 114  // display submit button, but only if enabled
 115  $Form->end_form( array( array( 'submit', 'actionArray[create]', T_('Send message'), 'SaveButton' ) ) );
 116  
 117  if( $params['allow_select_recipients'] )
 118  {    // User can select recipients
 119  ?>
 120  <script type="text/javascript">
 121  jQuery( document ).ready( function()
 122  {
 123      check_multiple_recipients();
 124  } );
 125  
 126  jQuery( '#thrd_recipients' ).tokenInput(
 127      '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php?action=get_recipients',
 128      {
 129          theme: 'facebook',
 130          queryParam: 'term',
 131          propertyToSearch: 'title',
 132          preventDuplicates: true,
 133          prePopulate: <?php echo evo_json_encode( $recipients_selected ) ?>,
 134          hintText: '<?php echo TS_('Type in a username') ?>',
 135          noResultsText: '<?php echo TS_('No results') ?>',
 136          searchingText: '<?php echo TS_('Searching...') ?>',
 137          tokenFormatter: function( item )
 138          {
 139              return '<li>' +
 140                      item.title +
 141                      '<input type="hidden" name="thrd_recipients_array[id][]" value="' + item.id + '" />' +
 142                      '<input type="hidden" name="thrd_recipients_array[title][]" value="' + item.title + '" />' +
 143                  '</li>';
 144          },
 145          resultsFormatter: function( item )
 146          {
 147              var title = item.title;
 148              if( item.fullname != null && item.fullname !== undefined )
 149              {
 150                  title += '<br />' + item.fullname;
 151              }
 152              return '<li>' +
 153                      item.picture +
 154                      '<div>' +
 155                          title +
 156                      '</div><span></span>' +
 157                  '</li>';
 158          },
 159          onAdd: function()
 160          {
 161              check_multiple_recipients();
 162          },
 163          onDelete: function()
 164          {
 165              check_multiple_recipients();
 166          },
 167      }
 168  );
 169  
 170  /**
 171   * Show the multiple recipients radio selection if the number of recipients more than one
 172   */
 173  function check_multiple_recipients()
 174  {
 175      if( jQuery( 'input[name="thrd_recipients_array[title][]"]' ).length > 1 )
 176      {
 177          jQuery( '#multiple_recipients' ).show();
 178      }
 179      else
 180      {
 181          jQuery( '#multiple_recipients' ).hide();
 182      }
 183  }
 184  
 185  /**
 186   * Check form fields before send a thread data
 187   *
 188   * @return boolean TRUE - success filling of the fields, FALSE - some erros, stop a submitting of the form
 189   */
 190  function check_form_thread()
 191  {
 192      if( jQuery( 'input#token-input-thrd_recipients' ).val() != '' )
 193      {    // Don't submit a form with incomplete username
 194          alert( '<?php echo TS_('Please complete the entering of an username.') ?>' );
 195          jQuery( 'input#token-input-thrd_recipients' ).focus();
 196          return false;
 197      }
 198  
 199      return true;
 200  }
 201  </script>
 202  <?php
 203  }
 204  ?>

title

Description

title

Description

title

Description

title

title

Body