Yannick Warnier 12 years ago
parent
commit
2e0cca664a

+ 6 - 7
main/announcements/announcements.php

@@ -160,7 +160,7 @@ if(!empty($_GET['remind_inactive'])) {
 
 $group_id = api_get_group_id();
 
-if (!empty($group_id)) {	
+if (!empty($group_id)) {
 	$group_properties  = GroupManager :: get_group_properties($group_id);
 	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
 	$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$group_id, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
@@ -175,9 +175,9 @@ if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
 }
 
 if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
-/*
-	Change visibility of announcement
-*/
+    /*
+        Change visibility of announcement
+    */
 	// $_GET['isStudentView']<>"false" is added to prevent that the visibility
 	// is changed after you do the following:
 	// change visibility -> studentview -> course manager view
@@ -338,8 +338,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
 	/*
 		Submit announcement
 	*/
-	//if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
-
+	
 	$emailTitle=(!empty($_POST['emailTitle'])?$safe_emailTitle:'');
 	$newContent=(!empty($_POST['newContent'])?$safe_newContent:'');
 
@@ -370,7 +369,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
 			}
 		} else {
 			//insert mode
-			if ($ctok == $_POST['sec_token']) {		
+			if ($ctok == $_POST['sec_token']) {
                 $file = $_FILES['user_upload'];
                 $file_comment = $_POST['file_comment'];
                 if (!empty($group_id)) {

+ 154 - 161
main/calendar/agenda.php

@@ -3,26 +3,25 @@
 /**
  * @package chamilo.calendar
  */
+
 /**
  * INIT SECTION
  */
-
 use \ChamiloSession as Session;
 
-
 // name of the language file that needs to be included
-$language_file = array('agenda','group');
+$language_file = array('agenda', 'group');
 
 // use anonymous mode when accessing this course tool
 $use_anonymous = true;
 require_once '../inc/global.inc.php';
-$current_course_tool  = TOOL_CALENDAR_EVENT;
+$current_course_tool = TOOL_CALENDAR_EVENT;
 
 api_protect_course_script(true);
 
 //session
-if(isset($_GET['id_session'])) {
-	$_SESSION['id_session'] = intval($_GET['id_session']);
+if (isset($_GET['id_session'])) {
+    $_SESSION['id_session'] = intval($_GET['id_session']);
 }
 
 $action = isset($_GET['action']) ? $_GET['action'] : null;
@@ -32,8 +31,8 @@ $this_section = SECTION_COURSES;
 
 if (empty($action)) {
     $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course';
-	header("Location: $url");
-	exit;
+    header("Location: $url");
+    exit;
 }
 
 /* 	Resource linker */
@@ -43,68 +42,60 @@ require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 
 if (!empty($addresources)) {
     // When the "Add Resource" button is clicked we store all the form data into a session
-    $form_elements= array ('day'=>Security::remove_XSS($_POST['fday']), 'month'=>Security::remove_XSS($_POST['fmonth']), 'year'=>Security::remove_XSS($_POST['fyear']), 'hour'=>Security::remove_XSS($_POST['fhour']), 'minutes'=>Security::remove_XSS($_POST['fminute']),
-    						'end_day'=>Security::remove_XSS($_POST['end_fday']), 'end_month'=>Security::remove_XSS($_POST['end_fmonth']), 'end_year'=>Security::remove_XSS($_POST['end_fyear']), 'end_hours'=>Security::remove_XSS($_POST['end_fhour']), 'end_minutes'=>Security::remove_XSS($_POST['end_fminute']),
-    						'title'=>Security::remove_XSS(stripslashes($_POST['title'])), 'content'=>Security::remove_XSS(stripslashes($_POST['content'])), 'id'=>Security::remove_XSS($_POST['id']), 'action'=>Security::remove_XSS($_POST['action']), 'to'=>Security::remove_XSS($_POST['selectedform']));
-    $_SESSION['formelements']=$form_elements;
+    $form_elements = array('day' => Security::remove_XSS($_POST['fday']), 'month' => Security::remove_XSS($_POST['fmonth']), 'year' => Security::remove_XSS($_POST['fyear']), 'hour' => Security::remove_XSS($_POST['fhour']), 'minutes' => Security::remove_XSS($_POST['fminute']),
+        'end_day' => Security::remove_XSS($_POST['end_fday']), 'end_month' => Security::remove_XSS($_POST['end_fmonth']), 'end_year' => Security::remove_XSS($_POST['end_fyear']), 'end_hours' => Security::remove_XSS($_POST['end_fhour']), 'end_minutes' => Security::remove_XSS($_POST['end_fminute']),
+        'title' => Security::remove_XSS(stripslashes($_POST['title'])), 'content' => Security::remove_XSS(stripslashes($_POST['content'])), 'id' => Security::remove_XSS($_POST['id']), 'action' => Security::remove_XSS($_POST['action']), 'to' => Security::remove_XSS($_POST['selectedform']));
+    $_SESSION['formelements'] = $form_elements;
     // this is to correctly handle edits
-    if($id){$action="edit";}
+    if ($id) {
+        $action = "edit";
+    }
     //print_r($form_elements);
     header('Location: '.api_get_path(WEB_CODE_PATH)."resourcelinker/resourcelinker.php?source_id=1&action=$action&id=$id&originalresource=no");
     exit;
 }
 
 if (!empty($_GET['view'])) {
-	$_SESSION['view'] = Security::remove_XSS($_GET['view']);
+    $_SESSION['view'] = Security::remove_XSS($_GET['view']);
 }
 
 // Functions for the agenda tool
 require_once 'agenda.inc.php';
 /*
-  			TREATING THE PARAMETERS
-			1. viewing month only or everything
-			2. sort ascending or descending
-			3. showing or hiding the send-to-specific-groups-or-users form
-			4. filter user or group
-*/
+  TREATING THE PARAMETERS
+  1. viewing month only or everything
+  2. sort ascending or descending
+  3. showing or hiding the send-to-specific-groups-or-users form
+  4. filter user or group
+ */
 
 
 // 3. showing or hiding the send-to-specific-groups-or-users form
-$setting_allow_individual_calendar=true;
+$setting_allow_individual_calendar = true;
 if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar'])) {
-	$_SESSION['allow_individual_calendar']="hide";
+    $_SESSION['allow_individual_calendar'] = "hide";
 }
-$allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
-if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide")) {
-	$_SESSION['allow_individual_calendar']="show";
+$allow_individual_calendar_status = $_SESSION['allow_individual_calendar'];
+if (!empty($_POST['To']) and ($allow_individual_calendar_status == "hide")) {
+    $_SESSION['allow_individual_calendar'] = "show";
 }
-if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show")) {
-	$_SESSION['allow_individual_calendar']="hide";
+if (!empty($_GET['sort']) and ($allow_individual_calendar_status == "show")) {
+    $_SESSION['allow_individual_calendar'] = "hide";
 }
 
 // 4. filter user or group
 if (!empty($_GET['user']) or !empty($_GET['group'])) {
-	$_SESSION['user']=(int)$_GET['user'];
-
-	$_SESSION['group']=(int)$_GET['group'];
+    $_SESSION['user'] = (int) $_GET['user'];
+    $_SESSION['group'] = (int) $_GET['group'];
 }
-if ((!empty($_GET['user']) and $_GET['user']=="none") or (!empty($_GET['group']) and $_GET['group']=="none")) {
-	Session::erase("user");
-	Session::erase("group");
-}
-if (!$is_courseAdmin){
-	if (!empty($_GET['toolgroup'])){
-		//$_SESSION['toolgroup']=$_GET['toolgroup'];
-		$toolgroup=Security::remove_XSS($_GET['toolgroup']);
-		Session::write('toolgroup',$toolgroup);
-	}
+if ((!empty($_GET['user']) and $_GET['user'] == "none") or (!empty($_GET['group']) and $_GET['group'] == "none")) {
+    Session::erase("user");
+    Session::erase("group");
 }
+
+$group_id = api_get_group_id();
+
 //It comes from the group tools. If it's define it overwrites $_SESSION['group']
-/*
-if (!empty($_GET['isStudentView']) and $_GET['isStudentView']=="false") {
-	api_session_unregister("user");
-	api_session_unregister("group");
-}*/
 
 $htmlHeadXtra[] = to_javascript();
 $htmlHeadXtra[] = user_group_filter_javascript();
@@ -114,30 +105,27 @@ $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" langua
 
 // setting the name of the tool
 $nameTools = get_lang('Agenda'); // language variable in trad4all.inc.php
-
 // showing the header if we are not in the learning path, if we are in
 // the learning path, we do not include the banner so we have to explicitly
 // include the stylesheet, which is normally done in the header
-if (isset($_GET['toolgroup']) && !empty($_GET['toolgroup'])){
-	$_clean['toolgroup']= intval($_GET['toolgroup']);
-	$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".Security::remove_XSS($_GET['toolgroup']), "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	Display::display_header($nameTools,'Agenda');
-
+if (!empty($group_id)) {
+    $group_properties = GroupManager :: get_group_properties($group_id);
+    $interbreadcrumb[] = array("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array("url" => "../group/group_space.php?gidReq=".$group_id, "name" => get_lang('GroupSpace').' '.$group_properties['name']);
+    Display::display_header($nameTools, 'Agenda');
 } elseif (empty($origin) or $origin != 'learnpath') {
-    Display::display_header($nameTools,'Agenda');
+    Display::display_header($nameTools, 'Agenda');
 } else {
-	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".api_get_path(WEB_CODE_PATH)."css/default.css\"/>";
+    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".api_get_path(WEB_CODE_PATH)."css/default.css\"/>";
 }
 
 /*
-  			TRACKING
+  TRACKING
  */
 event_access_tool(TOOL_CALENDAR_EVENT);
 
 /*   			SETTING SOME VARIABLES
-*/
+ */
 // Variable definitions
 // Defining the shorts for the days. We use camelcase because these are arrays of language variables
 $DaysShort = api_get_week_days_short();
@@ -147,42 +135,42 @@ $DaysLong = api_get_week_days_long();
 $MonthsLong = api_get_months_long();
 
 // Database table definitions
-$TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
-$TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
-$tbl_user       		= Database::get_main_table(TABLE_MAIN_USER);
-$tbl_courseUser 		= Database::get_main_table(TABLE_MAIN_COURSE_USER);
-$tbl_group      		= Database::get_course_table(TABLE_GROUP);
-$tbl_groupUser  		= Database::get_course_table(TABLE_GROUP_USER);
-$tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-
-/*   			ACCESS RIGHTS*/
+$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
+$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
+$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+$tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
+$tbl_group = Database::get_course_table(TABLE_GROUP);
+$tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
+$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+
+/*   			ACCESS RIGHTS */
 // permission stuff - also used by loading from global in agenda.inc.php
-$is_allowed_to_edit = api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
+$is_allowed_to_edit = api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
 
 // Tool introduction
 Display::display_introduction_section(TOOL_CALENDAR_EVENT);
 
-/*		MAIN SECTION	*/
+/* 		MAIN SECTION	 */
 
 //setting the default year and month
 $select_year = '';
 $select_month = '';
 $select_day = '';
 
-if(!empty($_GET['year'])) {
-	$select_year = (int)$_GET['year'];
+if (!empty($_GET['year'])) {
+    $select_year = (int) $_GET['year'];
 }
-if(!empty($_GET['month'])) {
-	$select_month = (int)$_GET['month'];
+if (!empty($_GET['month'])) {
+    $select_month = (int) $_GET['month'];
 }
-if(!empty($_GET['day'])) {
-    $select_day = (int)$_GET['day'];
+if (!empty($_GET['day'])) {
+    $select_day = (int) $_GET['day'];
 }
 
 $today = getdate();
 
 if (empty($select_year)) {
-	$select_year = $today['year'];
+    $select_year = $today['year'];
 }
 if (empty($select_month)) {
     $select_month = $today['mon'];
@@ -190,8 +178,11 @@ if (empty($select_month)) {
 
 echo '<div class="actions">';
 
-if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true)) {
-	echo display_courseadmin_links();
+if (api_is_allowed_to_edit(false, true) OR
+    (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) OR
+    GroupManager::user_has_access(api_get_user_id(), $group_id,  GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
+) {
+    echo display_courseadmin_links();
 }
 
 //display_student_links();
@@ -200,107 +191,109 @@ echo '</div>';
 $event_id = isset($_GET['id']) ? $_GET['id'] : null;
 $course_info = api_get_course_info();
 
-if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false,true))) {
-	switch($action) {
-		case 'add':
-			if (isset($_POST['submit_event']) && $_POST['submit_event']) {
-				$event_start 		= (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
-				$event_stop   		= (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
-				$safe_title 		= Security::remove_XSS($_POST['title']);
-				$safe_file_comment 	= Security::remove_XSS($_POST['file_comment']);
-
-				if ($_POST['empty_end_date'] == 'on' ) {
-					$event_stop = '0000-00-00 00:00:00';
-				}
-				$id = agenda_add_item($course_info,$safe_title,$_POST['content'],$event_start,$event_stop,$_POST['selected_form'],false,$safe_file_comment);
-				if (!empty($_POST['repeat'])) {
-					$end_y = intval($_POST['repeat_end_year']);
-					$end_m = intval($_POST['repeat_end_month']);
-					$end_d = intval($_POST['repeat_end_day']);
-					$end   = mktime(23, 59, 59, $end_m, $end_d, $end_y);
-					$res   = agenda_add_repeat_item($course_info,$id, $_POST['repeat_type'], $end,$_POST['selected_form'], $safe_file_comment);
-				}
-				Display::display_confirmation_message(get_lang('AddSuccess'));
-			} else {
-				show_add_form();
-			}
-			break;
-		case "announce":
-			//copying the agenda item into an announcement
-			if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
-				// a coach can only delete an element belonging to his session
-				$ann_id = store_agenda_item_as_announcement($event_id);
-				$tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
-				Display::display_normal_message(get_lang('CopiedAsAnnouncement').'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
-			}
-			break;
-		case 'importical':
-			if (isset($_POST['ical_submit'])) {
+if (api_is_allowed_to_edit(false, true) OR
+    (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) OR
+     GroupManager::user_has_access(api_get_user_id(), $group_id,  GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
+    ) {
+    switch ($action) {
+        case 'add':
+            if (isset($_POST['submit_event']) && $_POST['submit_event']) {
+                $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
+                $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
+                $safe_title = Security::remove_XSS($_POST['title']);
+                $safe_file_comment = Security::remove_XSS($_POST['file_comment']);
+
+                if ($_POST['empty_end_date'] == 'on') {
+                    $event_stop = '0000-00-00 00:00:00';
+                }
+                $id = agenda_add_item($course_info, $safe_title, $_POST['content'], $event_start, $event_stop, $_POST['selected_form'], false, $safe_file_comment);
+                if (!empty($_POST['repeat'])) {
+                    $end_y = intval($_POST['repeat_end_year']);
+                    $end_m = intval($_POST['repeat_end_month']);
+                    $end_d = intval($_POST['repeat_end_day']);
+                    $end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
+                    $res = agenda_add_repeat_item($course_info, $id, $_POST['repeat_type'], $end, $_POST['selected_form'], $safe_file_comment);
+                }
+                Display::display_confirmation_message(get_lang('AddSuccess'));
+            } else {
+                show_add_form();
+            }
+            break;
+        case "announce":
+            //copying the agenda item into an announcement
+            if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
+                // a coach can only delete an element belonging to his session
+                $ann_id = store_agenda_item_as_announcement($event_id);
+                $tool_group_link = (isset($_SESSION['toolgroup']) ? '&toolgroup='.$_SESSION['toolgroup'] : '');
+                Display::display_normal_message(get_lang('CopiedAsAnnouncement').'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
+            }
+            break;
+        case 'importical':
+            if (isset($_POST['ical_submit'])) {
                 $ical_name = $_FILES['ical_import']['name'];
                 $ical_type = $_FILES['ical_import']['type'];
 
-                $ext = substr($ical_name,(strrpos($ical_name,".")+1));
+                $ext = substr($ical_name, (strrpos($ical_name, ".") + 1));
 
                 //$ical_type === 'text/calendar'
-                if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar'  || $ext === 'ifb') {
-                	$agenda_result = agenda_import_ical($course_info, $_FILES['ical_import']);
-                	$is_ical = true;
+                if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
+                    $agenda_result = agenda_import_ical($course_info, $_FILES['ical_import']);
+                    $is_ical = true;
                 } else {
-                	$is_ical = false;
+                    $is_ical = false;
                 }
 
                 if (!$is_ical) {
-                	Display::display_error_message(get_lang('IsNotiCalFormatFile'));
-                	display_ical_import_form();
-                	break;
+                    Display::display_error_message(get_lang('IsNotiCalFormatFile'));
+                    display_ical_import_form();
+                    break;
                 } else {
-                	Display::display_confirmation_message(get_lang('AddSuccess'));
+                    Display::display_confirmation_message(get_lang('AddSuccess'));
                     echo $agenda_result;
                 }
             } else {
-            	display_ical_import_form();
+                display_ical_import_form();
+            }
+            break;
+        case 'edit':
+            if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) {
+                // a coach can only delete an element belonging to his session
+                if ($_POST['submit_event']) {
+                    store_edited_agenda_item($_REQUEST['id_attach'], $_REQUEST['file_comment']);
+                    $action = 'view';
+                } else {
+                    show_add_form($event_id);
+                }
+            }
+            break;
+        case "delete":
+            if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id) )) {
+                // a coach can only delete an element belonging to his session
+                delete_agenda_item($event_id);
+                $action = 'view';
+            }
+            break;
+        case "showhide":
+            if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
+                // a coach can only delete an element belonging to his session
+                showhide_agenda_item($event_id);
+                $action = 'view';
+            }
+            if (!empty($_GET['agenda_id'])) {
+                display_one_agenda_item($_GET['agenda_id']);
+            }
+            break;
+        case "delete_attach":  //delete attachment file
+            $id_attach = $_GET['id_attach'];
+            if (!empty($id_attach)) {
+                delete_attachment_file($id_attach);
+                $action = 'view';
             }
             break;
-		case 'edit':
-			if(!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) {
-				// a coach can only delete an element belonging to his session
-				if ($_POST['submit_event']) {
-					store_edited_agenda_item($_REQUEST['id_attach'], $_REQUEST['file_comment']);
-					$action = 'view';
-				} else {
-					show_add_form($event_id);
-				}
-			}
-			break;
-		case "delete":
-			if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id ) ) ) {
-				// a coach can only delete an element belonging to his session
-				delete_agenda_item($event_id);
-				$action = 'view';
-			}
-			break;
-		case "showhide":
-			if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
-			     // a coach can only delete an element belonging to his session
-				showhide_agenda_item($event_id);
-				$action = 'view';
-			}
-			if (!empty($_GET['agenda_id'])) {
-				display_one_agenda_item($_GET['agenda_id']);
-			}
-			break;
-		case "delete_attach": 	//delete attachment file
-			$id_attach = $_GET['id_attach'];
-			if (!empty($id_attach)) {
-				delete_attachment_file($id_attach);
-				$action = 'view';
-			}
-			break;
-
-	}
+    }
 }
 
 // The footer is displayed only if we are not in the learnpath
 if ($origin != 'learnpath') {
-	Display::display_footer();
+    Display::display_footer();
 }

+ 76 - 86
main/gradebook/gradebook_add_link.php

@@ -15,7 +15,7 @@ require_once 'lib/gradebook_functions.inc.php';
 require_once 'lib/fe/linkform.class.php';
 require_once 'lib/fe/linkaddeditform.class.php';
 require_once '../forum/forumfunction.inc.php';
-$current_course_tool  = TOOL_GRADEBOOK;
+$current_course_tool = TOOL_GRADEBOOK;
 
 api_protect_course_script();
 api_block_anonymous_users();
@@ -24,128 +24,118 @@ block_students();
 $course_info = api_get_course_info($_GET['course_code']);
 
 $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
-$tbl_link=Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
+$tbl_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 
 $session_id = api_get_session_id();
 $all_categories = Category :: load(null, null, api_get_course_id(), null, null, $session_id);
 
 $category = Category :: load($_GET['selectcat']);
-$url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']). '&newtypeselected=' . (isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : ''). '&course_code=' . (empty($_GET['course_code'])?'':Security::remove_XSS($_GET['course_code']));
-$typeform = new LinkForm(LinkForm :: TYPE_CREATE, $category[0], null, 'create_link', null, $url , $_GET['typeselected']);
+$url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&newtypeselected='.(isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '').'&course_code='.api_get_course_id();
+$typeform = new LinkForm(LinkForm :: TYPE_CREATE, $category[0], null, 'create_link', null, $url, $_GET['typeselected']);
 
 // if user selected a link type
 if ($typeform->validate() && isset($_GET['newtypeselected'])) {
-	// reload page, this time with a parameter indicating the selected type
-	header('Location: '.api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
-											 . '&typeselected='.$typeform->exportValue('select_link')
-											 . '&course_code=' . Security::remove_XSS($_GET['course_code']));
-	exit;
+    // reload page, this time with a parameter indicating the selected type
+    header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat'])
+        .'&typeselected='.$typeform->exportValue('select_link')
+        .'&course_code='.Security::remove_XSS($_GET['course_code']));
+    exit;
 }
 
 // link type selected, show 2nd form to retrieve the link data
 if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0') {
-	$url = api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']).'&typeselected=' . Security::remove_XSS($_GET['typeselected']) . '&course_code=' . Security::remove_XSS($_GET['course_code']);
-	$addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD, $all_categories, intval($_GET['typeselected']),null, 'add_link', $url);
-    
-	if ($addform->validate()) {
-		$addvalues = $addform->exportValues();
-        
-		$link= LinkFactory :: create($_GET['typeselected']);
-        
-		$link->set_user_id(api_get_user_id());
-		/*
-		if ($category[0]->get_course_code() == '' && !empty($_GET['course_code'])) {
-			$link->set_course_code($_GET['course_code']);
-		} else {
-			$link->set_course_code($category[0]->get_course_code());
-		}*/
-		$link->set_course_code(api_get_course_id());
-		
-		$link->set_category_id($addvalues['select_gradebook']);
-
-		if ($link->needs_name_and_description()) {
-			$link->set_name($addvalues['name']);
-		} else {
-			$link->set_ref_id($addvalues['select_link']);
-		}
-        
-        $parent_cat = Category :: load($addvalues['select_gradebook']);            
+    $url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&typeselected='.Security::remove_XSS($_GET['typeselected']).'&course_code='.Security::remove_XSS($_GET['course_code']);
+    $addform = new LinkAddEditForm(LinkAddEditForm :: TYPE_ADD, $all_categories, intval($_GET['typeselected']), null, 'add_link', $url);
+
+    if ($addform->validate()) {
+        $addvalues = $addform->exportValues();
+        $link = LinkFactory :: create($_GET['typeselected']);
+        $link->set_user_id(api_get_user_id());
+        $link->set_course_code(api_get_course_id());
+
+        $link->set_category_id($addvalues['select_gradebook']);
+
+        if ($link->needs_name_and_description()) {
+            $link->set_name($addvalues['name']);
+        } else {
+            $link->set_ref_id($addvalues['select_link']);
+        }
+
+        $parent_cat = Category :: load($addvalues['select_gradebook']);
         $global_weight = $category[0]->get_weight();
-        
-        //$addvalues['weight'] = $addvalues['weight_mask']/$global_weight*$parent_cat[0]->get_weight();    
-        
-		$link->set_weight($addvalues['weight_mask']);
 
-		if ($link->needs_max()) {
-			$link->set_max($addvalues['max']);
-		}
+        $link->set_weight($addvalues['weight_mask']);
+
+        if ($link->needs_max()) {
+            $link->set_max($addvalues['max']);
+        }
 
-		if ($link->needs_name_and_description()) {
-			$link->set_description($addvalues['description']);
-		}
-		$link->set_visible(empty ($addvalues['visible']) ? 0 : 1);
+        if ($link->needs_name_and_description()) {
+            $link->set_description($addvalues['description']);
+        }
+        $link->set_visible(empty($addvalues['visible']) ? 0 : 1);
 
-		//update view_properties		
-		if (isset($_GET['typeselected']) && 5 == $_GET['typeselected'] && (isset($addvalues['select_link']) && $addvalues['select_link']<>"")) {
+        //update view_properties
+        if (isset($_GET['typeselected']) && 5 == $_GET['typeselected'] && (isset($addvalues['select_link']) && $addvalues['select_link'] <> "")) {
 
-			$sql1 = 'SELECT thread_title from '.$tbl_forum_thread.' 
+            $sql1 = 'SELECT thread_title from '.$tbl_forum_thread.'
 					 WHERE c_id = '.$course_info['real_id'].' AND thread_id='.$addvalues['select_link'];
-			$res1	= Database::query($sql1);
-			$rowtit	= Database::fetch_row($res1);
-			$course_id = api_get_course_id();
-			$sql_l='SELECT count(*) FROM '.$tbl_link.' WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
-			$res_l=Database::query($sql_l);
-			$row=Database::fetch_row($res_l);
-			if ( $row[0]==0 ) {
-				$link->add();
-				$sql = 'UPDATE '.$tbl_forum_thread.' SET thread_qualify_max='.$addvalues['weight'].',thread_weight='.$addvalues['weight'].',thread_title_qualify="'.$rowtit[0].'" 
+            $res1 = Database::query($sql1);
+            $rowtit = Database::fetch_row($res1);
+            $course_id = api_get_course_id();
+            $sql_l = 'SELECT count(*) FROM '.$tbl_link.' WHERE ref_id='.$addvalues['select_link'].' and course_code="'.$course_id.'" and type=5;';
+            $res_l = Database::query($sql_l);
+            $row = Database::fetch_row($res_l);
+            if ($row[0] == 0) {
+                $link->add();
+                $sql = 'UPDATE '.$tbl_forum_thread.' SET thread_qualify_max='.$addvalues['weight'].',thread_weight='.$addvalues['weight'].',thread_title_qualify="'.$rowtit[0].'"
 						WHERE thread_id='.$addvalues['select_link'].' AND c_id = '.$course_info['real_id'].' ';
-				Database::query($sql);
-			}
-		}
-        
-		$link->add();
-				
-		$addvalue_result=!empty($addvalues['addresult'])?$addvalues['addresult']:array();
-		if ($addvalue_result == 1) {
-			header('Location: gradebook_add_result.php?selecteval=' . $link->get_ref_id());
-			exit;
-		} else {
-			header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?linkadded=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
-			exit;
-		}
-	}
+                Database::query($sql);
+            }
+        }
+
+        $link->add();
+
+        $addvalue_result = !empty($addvalues['addresult']) ? $addvalues['addresult'] : array();
+        if ($addvalue_result == 1) {
+            header('Location: gradebook_add_result.php?selecteval='.$link->get_ref_id());
+            exit;
+        } else {
+            header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?linkadded=&selectcat='.Security::remove_XSS($_GET['selectcat']));
+            exit;
+        }
+    }
 }
 
 
-$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' .Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
+$interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'].'?selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => get_lang('Gradebook'));
 $this_section = SECTION_COURSES;
 
-$htmlHeadXtra[] = '<script type="text/javascript">
+$htmlHeadXtra[] = '<script>
 $(document).ready( function() {
 
-    $("#hide_category_id").change(function() {        
+    $("#hide_category_id").change(function() {
        $("#hide_category_id option:selected").each(function () {
            var cat_id = $(this).val();
-            $.ajax({ 
-                url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight", 
+            $.ajax({
+                url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
                 data: "cat_id="+cat_id,
                 success: function(return_value) {
                     if (return_value != 0 ) {
-                        $("#max_weight").html(return_value);                                             
-                    }                    
-                },            
-            });    
+                        $("#max_weight").html(return_value);
+                    }
+                },
+            });
        });
     });
 });
 </script>';
 
 Display :: display_header(get_lang('MakeLink'));
-if (isset ($typeform)) {
-	$typeform->display();
+if (isset($typeform)) {
+    $typeform->display();
 }
-if (isset ($addform)) {
-	$addform->display();
+if (isset($addform)) {
+    $addform->display();
 }
 Display :: display_footer();

+ 6 - 6
main/group/group_creation.php

@@ -184,7 +184,7 @@ EOT;
 			$group_el[] = $form->createElement('text', 'group_'.$group_number.'_name');
 			if (api_get_setting('allow_group_categories') == 'true') {
 				$group_el[] = $form->createElement('select', 'group_'.$group_number.'_category', null, $cat_options, array('id' => 'category_'.$group_number));
-			}			
+			}
 			$group_el[] = $form->createElement('text', 'group_'.$group_number.'_places', null, array('class' => 'span1', 'id' => 'places_'.$group_number));
 
 			if ($_POST['number_of_groups'] < 10000) {
@@ -216,7 +216,7 @@ EOT;
 	 */
 	$categories = GroupManager :: get_categories();
 	//echo '<blockquote>';
-	if (count($categories) > 1 || isset ($categories[0]) && $categories[0]['id'] != VIRTUAL_COURSE_CATEGORY) {
+	if (count($categories) > 1 || isset ($categories[0]) && $categories[0]['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) {
 		$create_groups_form = new FormValidator('create_groups');
 		$create_groups_form->addElement('header', '', $nameTools);
 		$group_el = array ();
@@ -262,7 +262,7 @@ EOT;
 				$base_group_options[$group['id']] = $group['name'].' ('.$number_of_students.' '.get_lang('Users').')';
 			}
 		}
-		if (count($base_group_options) > 0) {			
+		if (count($base_group_options) > 0) {
 			$create_subgroups_form = new FormValidator('create_subgroups');
             $create_subgroups_form->addElement('header', get_lang('CreateSubgroups'));
             $create_subgroups_form->addElement('html', get_lang('CreateSubgroupsInfo'));
@@ -277,7 +277,7 @@ EOT;
 			$defaults = array();
 			$defaults['action'] = 'create_subgroups';
 			$create_subgroups_form->setDefaults($defaults);
-			$create_subgroups_form->display();			
+			$create_subgroups_form->display();
 		}
 	}
 
@@ -285,7 +285,7 @@ EOT;
 	 * Show form to generate groups from classes subscribed to the course
 	 */
     $options['where'] = array(" usergroup.course_id = ? " =>  api_get_real_course_id());
-    $obj = new UserGroup();	 
+    $obj = new UserGroup();
     $classes = $obj->get_usergroup_in_course($options);
 	if (count($classes) > 0) {
 		echo '<b>'.get_lang('GroupsFromClasses').'</b>';
@@ -323,7 +323,7 @@ EOT;
 		$create_class_groups_form->display();
 		echo '</blockquote>';
 	}
-    
+
 }
 
 /*	FOOTER */

File diff suppressed because it is too large
+ 200 - 199
main/inc/lib/groupmanager.lib.php


+ 15 - 4
main/inc/lib/notification.lib.php

@@ -110,28 +110,39 @@ class Notification extends Model {
         switch ($this->type) {
             case NOTIFICATION_TYPE_MESSAGE;
                 $setting_to_check = 'mail_notify_message';
+                $default_status = NOTIFY_MESSAGE_AT_ONCE;
                 break;
             case NOTIFICATION_TYPE_INVITATION;
                 $setting_to_check = 'mail_notify_invitation';
+                $default_status = NOTIFY_INVITATION_AT_ONCE;
                 break;
             case NOTIFICATION_TYPE_GROUP;
                 $setting_to_check = 'mail_notify_group_message';
+                $default_status = NOTIFY_GROUP_AT_ONCE;
                 $avoid_my_self  = true;
                 break;
         }
 
+        $setting_info = UserManager::get_extra_field_information_by_name($setting_to_check);
+
         if (!empty($user_list)) {
             foreach ($user_list as $user_id) {
-                $extra_data = UserManager::get_extra_user_data($user_id);
-                $params = array();
                 if ($avoid_my_self) {
                     if ($user_id == api_get_user_id()) {
                         continue;
                     }
                 }
-
                 $user_info = api_get_user_info($user_id);
-                $user_setting = $extra_data[$setting_to_check];
+
+                //Extra field was deleted or removed? Use the default status
+                if (empty($setting_info)) {
+                    $user_setting = $default_status;
+                } else {
+                    $extra_data = UserManager::get_extra_user_data($user_id);
+                    $user_setting = $extra_data[$setting_to_check];
+                }
+
+                $params = array();
 
                 switch ($user_setting) {
                     //No notifications

+ 9 - 9
main/inc/lib/tracking.lib.php

@@ -1247,7 +1247,7 @@ class Tracking {
         $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
 
         global $_configuration;
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1){
@@ -1274,7 +1274,7 @@ class Tracking {
                     INNER JOIN ' . $tbl_course . ' as course
                         ON course.code = session_course.course_code';
 
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1){
@@ -1292,10 +1292,10 @@ class Tracking {
 
         if (!empty ($id_session)) {
             $sql .= ' WHERE session_course.id_session=' . $id_session;
-            if ($_configuration['multiple_access_urls'])
+            if (api_is_multiple_url_enabled())
             $sql .=  ' AND access_url_id = '.$access_url_id;
         }  else {
-            if ($_configuration['multiple_access_urls'])
+            if (api_is_multiple_url_enabled())
             $sql .=  ' WHERE access_url_id = '.$access_url_id;
         }
 
@@ -1327,7 +1327,7 @@ class Tracking {
                     WHERE id_coach=' . $coach_id;
 
         global $_configuration;
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1){
@@ -1351,7 +1351,7 @@ class Tracking {
                         AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2';
 
         global $_configuration;
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1){
@@ -2136,7 +2136,7 @@ class Tracking {
         $user_id                    = intval($user_id);
 
         // get course list
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $sql = 'SELECT cu.course_code as code, title
                     FROM '.$tbl_course_user.' cu INNER JOIN '.$tbl_access_rel_course.' a  ON(a.course_code = cu.course_code) INNER JOIN '.$tbl_course.' c ON( cu.course_code = c.code)
                     WHERE user_id='.$user_id.' AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND access_url_id = '.api_get_current_access_url_id().' ORDER BY title ';
@@ -2152,7 +2152,7 @@ class Tracking {
         }
 
         // Get the list of sessions where the user is subscribed as student
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $sql = 'SELECT DISTINCT cu.course_code, id_session as session_id, name FROM '.$tbl_session_course_user.' cu INNER JOIN '.$tbl_access_rel_session.' a  ON(a.session_id = cu.id_session) INNER JOIN '.$tbl_session.' s  ON(s.id = a.session_id)
                     WHERE id_user='.$user_id.' AND access_url_id = '.api_get_current_access_url_id().' ORDER BY name ';
         } else {
@@ -3575,7 +3575,7 @@ class TrackingCourseLog {
     		$condition_user .=  " AND  (user.firstname LIKE '%".$keyword."%' OR user.lastname LIKE '%".$keyword."%'  OR user.username LIKE '%".$keyword."%'  OR user.email LIKE '%".$keyword."%' ) ";
     	}
 
-    	if ($_configuration['multiple_access_urls']) {
+    	if (api_is_multiple_url_enabled()) {
     		$url_table = ", ".$tbl_url_rel_user."as url_users";
     		$url_condition = " AND user.user_id = url_users.user_id AND access_url_id='$access_url_id'";
     	}

+ 3 - 3
main/inc/lib/usermanager.lib.php

@@ -30,9 +30,9 @@ class UserManager {
     CONST USER_FIELD_TYPE_TIMEZONE =                11;
     CONST USER_FIELD_TYPE_SOCIAL_PROFILE =          12;
 
-        /**
-         * The default constructor only instanciates an empty user object
-         */
+    /**
+     * The default constructor only instanciates an empty user object
+     */
     public function __construct () {
     }
 

Some files were not shown because too many files changed in this diff