Browse Source

Should fix bug in the calendar when sending to many users/groups see #4220

Julio Montoya 13 years ago
parent
commit
ad4b0e7d2b

+ 49 - 13
main/calendar/agenda.lib.php

@@ -406,7 +406,7 @@ class Agenda {
         
 		$course_id = $course_info['real_id'];
         
-        $group_list = GroupManager::get_group_list(null, $course_info['code']);        
+        $group_list = GroupManager::get_group_list(null, $course_info['code']);            
         $group_name_list = array();
         
         if (!empty($group_list)) {
@@ -417,7 +417,7 @@ class Agenda {
         
         if (!api_is_allowed_to_edit()) {
             $group_memberships 	= GroupManager::get_group_ids($course_id, api_get_user_id());
-        } else {
+        } else {            
             $group_memberships = array_keys($group_name_list);            
         }
         
@@ -430,23 +430,23 @@ class Agenda {
             $group_memberships = array($group_id);
         }
 	
-		if (is_array($group_memberships) && count($group_memberships) >0 ) {
+		if (is_array($group_memberships) && count($group_memberships) >0) {
 		    if (api_is_allowed_to_edit()) {
 		        $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
             } else {
                 $where_condition = "( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
             }
             
-            $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
+            $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref, to_user_id
                     FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip
                     WHERE   agenda.id       = ip.ref  AND 
                             ip.tool         ='".TOOL_CALENDAR_EVENT."' AND 
                             $where_condition AND
                             ip.visibility   = '1' AND
                             agenda.c_id     = $course_id AND
-                            ip.c_id         = $course_id";
-                            
-		    
+                            ip.c_id         = $course_id
+                    GROUP BY id
+                    ";
 			
 		} else {
 		    if (api_is_allowed_to_edit()) {
@@ -454,7 +454,7 @@ class Agenda {
             } else {
                 $where_condition = "( ip.to_user_id=$user_id OR ip.to_group_id='0') AND ";
             }         
-            $sql="SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
+            $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref, to_user_id
                     FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip
                     WHERE agenda.id = ip.ref AND
                     ip.tool='".TOOL_CALENDAR_EVENT."' AND
@@ -469,6 +469,27 @@ class Agenda {
 		$events = array();
 		if (Database::num_rows($result)) {
 			while ($row = Database::fetch_array($result, 'ASSOC')) {
+                                 
+                //session_id = {$row['ref']} AND
+                //to gather sent_tos
+                $sql = "SELECT to_user_id, to_group_id
+                    FROM ".$tbl_property." ip
+                    WHERE   ip.tool         ='".TOOL_CALENDAR_EVENT."' AND 
+                            ref = {$row['ref']} AND
+                            ip.visibility   = '1' AND  
+                            ip.c_id         = $course_id";
+                $sent_to_result = Database::query($sql);
+                $user_to_array = array();
+                $group_to_array = array();
+                while ($row_send_to = Database::fetch_array($sent_to_result, 'ASSOC')) {
+                    if (!empty($row_send_to['to_group_id'])) {
+                        $group_to_array[] = $row_send_to['to_group_id'];
+                    }
+                    if (!empty($row_send_to['to_user_id'])) {
+                        $user_to_array[]  = $row_send_to['to_user_id'];
+                    }
+                }
+            
 				//Only show events from the session
 				if (api_get_course_int_id()) {
 					if ($row['session_id'] != api_get_session_id()) {
@@ -505,18 +526,33 @@ class Agenda {
 				}	
                 
                 $event['sent_to'] = '';
-                $event['type']    = $this->type;
-                
+                $event['type']    = $this->type;                
                 
                 //Event Sent to a group?
-                if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {                    
-                    $event['sent_to'] = $group_name_list[$row['to_group_id']];
+                if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
+                    if (!empty($group_to_array)) {
+                        $sent_to = array();
+                        foreach($group_to_array as $group_item) {
+                            $sent_to[] = $group_name_list[$group_item];        
+                        }
+                    }
+                    $event['sent_to'] = implode(', ', $sent_to);
                     $event['type']    = 'group';    
                 }
 
                 //Event sent to a user?
+                //var_dump($row);
                 if (isset($row['to_user_id'])) {
-                    $event['sent_to'] = $row['to_user_id'];
+                    
+                    if (!empty($user_to_array)) {
+                        $sent_to = array();
+                        foreach($user_to_array as $item) {
+                            $user_info = api_get_user_info($item);   
+                            $sent_to[] = $user_info['complete_name'];        
+                        }
+                    }
+                    $event['sent_to'] = implode(', ', $sent_to);
+//                    $event['sent_to'] = $row['to_user_id'];
                 }
                 
                 //Event sent to everyone!

+ 0 - 2
main/calendar/agenda_js.php

@@ -15,7 +15,6 @@ $use_anonymous = true;
 
 require_once '../inc/global.inc.php';
 require_once 'agenda.lib.php';
-
 require_once 'agenda.inc.php';
 
 $htmlHeadXtra[] = api_get_jquery_ui_js();
@@ -106,7 +105,6 @@ if (api_is_allowed_to_edit() && $course_code != '-1' && $type == 'course') {
     $tpl->assign('visible_to', $select);
 }
 
-
 //Loading Agenda template
 $content = $tpl->fetch('default/agenda/month.tpl');
 $tpl->assign('content', $content);

+ 1 - 1
main/glossary/index.php

@@ -176,7 +176,7 @@ if (api_is_allowed_to_edit(null, true)) {
             $form->addElement('header', '', get_lang('ImportGlossary'));
             $form->addElement('checkbox', 'replace', get_lang('ReplaceGlossary'));
             $form->addElement('file', 'file');
-            $form->addElement('style_submit_button', 'SubmitImport', get_lang('ImportGlossaryButton'), 'class="save"');
+            $form->addElement('style_submit_button', 'SubmitImport', get_lang('Import'), 'class="save"');
             $form->display();       
             
             if ($form->validate()) {

+ 3 - 3
main/template/default/agenda/month.tpl

@@ -90,8 +90,7 @@ $(document).ready(function() {
 			var end_date 	= Math.round(end.getTime() / 1000);
 			
 			$('#visible_to_input').show();
-			$('#add_as_announcement_div').show();
-			
+			$('#add_as_announcement_div').show();			
 			$('#visible_to_read_only').hide();
 			
 			//Cleans the selected attr 	
@@ -177,9 +176,10 @@ $(document).ready(function() {
                 $('#add_as_announcement_div').hide();
                 			
                 {if $type != 'admin'}
-                    $('#visible_to_read_only').show();
+                    $('#visible_to_read_only').show();                    
                     $("#visible_to_read_only_users").html(calEvent.sent_to);
 				{/if}
+                    
 				$('#color_calendar').html('{$type_label}');
 				$('#color_calendar').addClass('label_tag');