Index: lib.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/email_list/email/lib.php,v
retrieving revision 1.10
diff -c -w -r1.10 lib.php
*** lib.php	22 Aug 2008 17:43:48 -0000	1.10
--- lib.php	26 Aug 2008 11:02:11 -0000
***************
*** 2771,2776 ****
--- 2771,2886 ----
  }
  
  /**
+  * This function returns an object of all users whithin current course who match
+  * the search query.
+  *  *Modified version of datalib.php's search_user() function
+  *
+  * @param object $course Current Course object
+  * @param string $query Search query
+  * @param boolean $dispadmins Flag to return course admins or not
+  * @param boolean $displayunconfirmed Flag to specify to return unconfirmed users
+  * @return object result set of all matching users
+  * @todo Add option to remove active user from results
+ */
+ function email_search_course_users($course, $query = '', $dispadmins = false, $dispunconfirmed = true) {
+     global $CFG, $USER;
+ 
+     $LIKE      = sql_ilike();
+ 
+     $order = 'ORDER BY firstname, lastname, id';
+ 
+     $select = 'u.deleted = \'0\'';
+     if (!$dispunconfirmed) {
+         $select .= ' AND u.confirmed = \'1\'';
+     }
+ 
+     if (!$course or $course->id == SITEID) {
+         $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
+                       FROM {$CFG->prefix}user u
+                       WHERE $select
+                           AND (u.firstname $LIKE '$query%' OR u.lastname $LIKE '$query%')
+                           AND u.username != 'guest'
+                           $order");
+     } else {
+         if ($course->id == SITEID) {
+             $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+         } else {
+             $context = get_context_instance(CONTEXT_COURSE, $course->id);
+         }
+ 
+         $contextlists = get_related_contexts_string($context);
+ 
+         // Returns only group(s) members for users without the viewallgroups capability
+         $groupmembers = '';
+         // Separate groups
+         $groupmode = groups_get_course_groupmode($course);
+         if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
+             // Returns all groups current user is assigned to in course
+             if ($groups = groups_get_all_groups($course->id, $USER->id)) {
+                 $groupmembers = array();
+                 foreach ($groups as $group) {
+                     $groupmembers += groups_get_members($group->id, 'u.id');
+                 }
+                 if (!empty($groupmembers)) {
+                     $groupmembers = 'AND u.id IN ('.implode(',', array_keys($groupmembers)).')';
+                 } else {
+                     // Nobody in their groups :(
+                     return false;
+                 }
+             } else {
+                 // They have no group :(
+                 return false;
+             }
+         }
+ 
+         // Hides course admin roles (eg: admin && course creator) if requested (default)
+         if (!$dispadmins) {
+             $avoidroles = array();
+ 
+             if ($roles = get_roles_used_in_context($context, true)) {
+                 $canviewroles    = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
+                 $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $context);
+ 
+                 foreach ($roles as $role) {
+                     if (!isset($canviewroles[$role->id])) {   // Avoid this role (eg course creator)
+                         $avoidroles[] = $role->id;
+                         unset($roles[$role->id]);
+                         continue;
+                     }
+                     if (isset($doanythingroles[$role->id])) {   // Avoid this role (ie admin)
+                         $avoidroles[] = $role->id;
+                         unset($roles[$role->id]);
+                         continue;
+                     }
+                 }
+             }
+ 
+             // exclude users with roles we are avoiding
+             if ($avoidroles) {
+                 $adminroles = 'AND ra.roleid NOT IN (';
+                 $adminroles .= implode(',', $avoidroles);
+                 $adminroles .= ')';
+             } else {
+                 $adminroles = '';
+             }
+         } else {
+             $adminroles = '';
+         }
+ 
+         $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
+                       FROM {$CFG->prefix}user u,
+                            {$CFG->prefix}role_assignments ra
+                       WHERE $select AND ra.contextid $contextlists AND ra.userid = u.id
+                           AND (u.firstname $LIKE '$query%' OR u.lastname $LIKE '$query%')
+                           AND (u.username != 'guest')
+                           $adminroles $groupmembers $order");
+     }
+ 
+     return $results;
+ }
+ 
+ 
+ /**
   * Prints the print emails button
   *
   * Idaho State University & MoodleRooms contrib - Thanks!
Index: mail_edit_form.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/email_list/email/mail_edit_form.php,v
retrieving revision 1.3
diff -c -w -r1.3 mail_edit_form.php
*** mail_edit_form.php	22 Aug 2008 17:08:31 -0000	1.3
--- mail_edit_form.php	26 Aug 2008 11:02:11 -0000
***************
*** 35,52 ****
          /// Print the required moodle fields first
          $mform->addElement('header', 'moodle', get_string('mail','email', NULL, EMAIL_LANG_PATH));
  
! 		$mform->addElement('button', 'urlcc', get_string('participants', 'email', NULL, EMAIL_LANG_PATH).'...' , array( 'onclick' => "this.target='participants'; return openpopup('/blocks/email_list/email/participants.php?id=$COURSE->id', 'participants', 'menubar=0,location=0,scrollbars=0,resizable,width=550,height=440', 0);" ) );
  
  		// Mail to
!         $mform->addElement('textarea', 'nameto', get_string('for', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '2', 'cols'=>'65', 'class'=>'textareacontacts', 'disabled'=>'true'));
  		//$mform->addRule('nameto', get_string('nosenders', 'email'), 'required', null, 'server');
  
          // Mail cc
!         $mform->addElement('textarea', 'namecc', get_string('cc', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '1', 'cols'=>'65', 'class'=>'textareacontacts', 'disabled'=>'true'));
  		//$mform->addRule('namecc', get_string('nosenders', 'email'), 'required', null, 'server');
  
  		// Mail bcc
! 		$mform->addElement('textarea', 'namebcc', get_string('bcc', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '1', 'cols'=>'65', 'class'=>'textareacontacts', 'disabled'=>'true'));
  		//$mform->addRule('namebcc', get_string('nosenders', 'email'), 'required', null, 'server');
  
          $mform->addElement('text','subject', get_string('subject', 'email', NULL, EMAIL_LANG_PATH),'class="emailsubject" maxlength="254" size="60"');
--- 35,79 ----
          /// Print the required moodle fields first
          $mform->addElement('header', 'moodle', get_string('mail','email', NULL, EMAIL_LANG_PATH));
  
! 		$mform->addElement('button', 'urlcc', get_string('participants', 'email', NULL, EMAIL_LANG_PATH).'...' , array( 'onclick' => "this.target='participants'; return openpopup('/blocks/email_list/email/participants.php?id=$COURSE->id', 'participants', 'menubar=0,location=0,scrollbars=1,resizable=1,width=500,height=540', 0);" ) );
  
  		// Mail to
! 
! 		// Added to allow for YUI autocomplete styling
! 		$mform->addElement('html','<div class="yui-skin-sam">');
! 
!         	$mform->addElement('textarea', 'nameto', get_string('for', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '2', 'cols'=>'65', 'class'=>'textareacontacts', 'multiple'=>'multiple'));
! 
! 		// Stores the YUI autocomplete results
! 		$mform->addElement('static', 'qResultsTo', '', '<div id="qResultsTo"></div>');
! 		$mform->addElement('html','</div>');
! 
  		//$mform->addRule('nameto', get_string('nosenders', 'email'), 'required', null, 'server');
  
          	// Mail cc
! 
! 		// Added to allow for YUI autocomplete styling
! 		$mform->addElement('html','<div class="yui-skin-sam">');
! 			
! 		$mform->addElement('textarea', 'namecc', get_string('cc', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '2', 'cols'=>'65', 'class'=>'textareacontacts', 'multiple'=>'multiple'));
! 
! 		// Stores the YUI autocomplete results
! 		$mform->addElement('static', 'qResultsCC', '', '<div id="qResultsCC"></div>');
! 		$mform->addElement('html','</div>');
! 
  		//$mform->addRule('namecc', get_string('nosenders', 'email'), 'required', null, 'server');
  
  		// Mail bcc
! 
! 		// Added to allow for YUI autocomplete styling
! 		$mform->addElement('html','<div class="yui-skin-sam">');
! 
! 		$mform->addElement('textarea', 'namebcc', get_string('bcc', 'email', NULL, EMAIL_LANG_PATH), array('rows'=> '2', 'cols'=>'65', 'class'=>'textareacontacts', 'multiple'=>'multiple'));
! 
! 		// Stores the YUI autocomplete results
! 		$mform->addElement('static', 'qResultsBCC', '', '<div id="qResultsBCC"></div>');
! 		$mform->addElement('html','</div>');
! 
  		//$mform->addRule('namebcc', get_string('nosenders', 'email'), 'required', null, 'server');
  
          $mform->addElement('text','subject', get_string('subject', 'email', NULL, EMAIL_LANG_PATH),'class="emailsubject" maxlength="254" size="60"');
Index: manage.js
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/email_list/email/manage.js,v
retrieving revision 1.1
diff -c -w -r1.1 manage.js
*** manage.js	23 Jul 2008 04:01:47 -0000	1.1
--- manage.js	26 Aug 2008 11:02:11 -0000
***************
*** 72,78 ****
  
      // Adds Name to sendtype list
      if (field.value == '') {
!     	field.value = user;
      } else {
      	// Checks for valid string entry for post-send validation
          if ((field.value.charAt(field.value.length-2) != ',')) {
--- 72,78 ----
  
      // Adds Name to sendtype list
      if (field.value == '') {
!     	field.value = user+', ';
      } else {
      	// Checks for valid string entry for post-send validation
          if ((field.value.charAt(field.value.length-2) != ',')) {
***************
*** 83,89 ****
              }
          }
  
!         field.value = field.value + user;
  	}
      return true;
  }
--- 83,89 ----
              }
          }
  
!         field.value = field.value + user+', ';
  	}
      return true;
  }
***************
*** 248,254 ****
  
  //recarrega la cosa amb els par?metres
  function reloadiframe (params) {
!     var url = "search.php?id=<?php echo $id;?>"+params;
      document.getElementById("idsearch").src = url;
      // document.write( "Somthing" + url);
      //document.getElementById("search_res").innerHTML = url;
--- 248,254 ----
  
  //recarrega la cosa amb els par?metres
  function reloadiframe (params) {
!     var url = "get_users.php?"+params;
      document.getElementById("idsearch").src = url;
      // document.write( "Somthing" + url);
      //document.getElementById("search_res").innerHTML = url;
Index: sendmail.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/email_list/email/sendmail.php,v
retrieving revision 1.6
diff -c -w -r1.6 sendmail.php
*** sendmail.php	22 Aug 2008 17:43:48 -0000	1.6
--- sendmail.php	26 Aug 2008 11:02:11 -0000
***************
*** 424,429 ****
--- 424,431 ----
  
      	$mailform->display();
  
+ 	require_once($CFG->dirroot.'/blocks/email_list/email/contacts/yui_autocomplete.html');
+ 
      	if ( $action == EMAIL_REPLY ) {
      	echo ' <script type="text/javascript" language="JavaScript"> var contacts = window.document.createElement("span");
  			        window.document.getElementById(\'id_nameto\').parentNode.appendChild(contacts);
