Browse Source

Added feature for admin to recover attendances - see BT#3002

Yannick Warnier 13 years ago
parent
commit
902cea5c6b

+ 3 - 2
documentation/changelog.html

@@ -26,9 +26,10 @@
 <p>Chamilo 1.9.0 is a major stable version with loads of added features.</p>
 
 <h3>New Features</h3>
-This version of Chamilo only includes a few minor new features:
+This version of Chamilo only includes new features:
 <ul>
-  <li></li>
+  <li>Extra reports generation feature by CBlue</li>
+  <li>Feature for admin to recover deleted attendances (BT#3002)</li>
 </ul>
 <h3>Debugging</h3>
 <ul>

+ 17 - 2
main/attendance/attendance_controller.php

@@ -158,7 +158,7 @@
 	} 
 	
 	/**
-	 * It's used for delete attendace,
+	 * It's used for delete attendaces
 	 * render to attendance_list view
 	 * @param int	attendance id
 	 */
@@ -173,6 +173,21 @@
 		}
 		$this->attendance_list();	
 	}
+	/**
+	 * Restores an attendance entry and fallback to attendances rendering
+	 * @param int	attendance id
+	 */
+	public function attendance_restore($attendance_id) {
+		$attendance = new Attendance();   
+		//$attendance_id = intval($attendance_id);
+		if (!empty($attendance_id)) {
+			$affected_rows = $attendance->attendance_restore($attendance_id);
+		}		
+		if ($affected_rows) {        			
+			$message['message_attendance_restore'] = true;        			
+		}
+		$this->attendance_list();	
+	}
 
     /**
      * Lock or unlock an attendance
@@ -512,4 +527,4 @@
         export_pdf_attendance(&$head_table, &$data_table, &$header_pdf, $footer_pdf, $title_pdf);
 
     } 	
-}
+}

+ 7 - 2
main/attendance/index.php

@@ -30,7 +30,7 @@ $this_section = SECTION_COURSES;
 api_protect_course_script(true);
 
 // get actions
-$actions = array('attendance_list', 'attendance_sheet_list', 'attendance_sheet_print', 'attendance_sheet_add', 'attendance_add', 'attendance_edit', 'attendance_delete', 'attendance_delete_select');
+$actions = array('attendance_list', 'attendance_sheet_list', 'attendance_sheet_print', 'attendance_sheet_add', 'attendance_add', 'attendance_edit', 'attendance_delete', 'attendance_delete_select', 'attendance_restore');
 $actions_calendar = array('calendar_list', 'calendar_add', 'calendar_edit', 'calendar_delete', 'calendar_all_delete');
 $action  = 'attendance_list';
 
@@ -235,6 +235,11 @@ switch ($action) {
 	case 'attendance_delete'	:
     	if (api_is_allowed_to_edit(null, true)) {
         $attendance_controller->attendance_delete($attendance_id);
+        } else { api_not_allowed();}
+		 break;									
+	case 'attendance_restore':
+    	if (api_is_allowed_to_edit(null, true)) {
+        $attendance_controller->attendance_restore($attendance_id);
         } else { api_not_allowed();}
 		 break;									
 	case 'attendance_sheet_list':	
@@ -268,4 +273,4 @@ switch ($action) {
 		break;
 	default		  		:	
         $attendance_controller->attendance_list();
-}
+}

+ 49 - 4
main/inc/lib/attendance.lib.php

@@ -90,15 +90,18 @@ class Attendance
                     if (!in_array($direction, array('ASC','DESC'))) {
                     $direction = 'ASC';
                 }
+                $active_plus = 'att.active = 1';
+                if (api_is_platform_admin()) { $active_plus = ' 1=1 ';}
 		$sql = "SELECT
 				att.id AS col0,
 				att.name AS col1,
 				att.description AS col2,
 				att.attendance_qualify_max AS col3,
                 att.locked AS col4,
+                att.active AS col5,
                 att.session_id
 				FROM $tbl_attendance att
-				WHERE att.active = 1 $condition_session
+				WHERE $active_plus $condition_session
 				ORDER BY col$column $direction LIMIT $from,$number_of_items ";
 		$res = Database::query($sql);
 		$attendances = array ();
@@ -117,10 +120,14 @@ class Attendance
 			
             $session_star = '';
             
-            if (api_get_session_id() == $attendance[5]) {
+            if (api_get_session_id() == $attendance[6]) {
                 $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
             }
-			$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$param_gradebook.$student_param.'">'.$attendance[1].'</a>'.$session_star;
+                        if ($attendance[5] == 1) {
+                            $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$param_gradebook.$student_param.'">'.$attendance[1].'</a>'.$session_star;
+                        } else {
+                            $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$param_gradebook.$student_param.'"><del>'.$attendance[1].'</del></a>'.$session_star;
+                        }
 			$attendance[3] = '<center>'.$attendance[3].'</center>';
 			if (api_is_allowed_to_edit(null, true)) {
 				$actions  = '';
@@ -128,7 +135,11 @@ class Attendance
 
                 if (api_is_platform_admin()) {
                     $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.png',get_lang('Edit'), array(), 22).'</a>&nbsp;';
-                    $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'), array(), 22).'</a>';
+                    if ($attendance[5] == 1) {
+                        $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'), array(), 22).'</a>';
+                    } else {
+                        $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToRestore').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_restore&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('invisible.png',get_lang('Restore'), array(), 22).'</a>';
+                    }
                 } else {
                     $is_locked_attendance = self::is_locked_attendance($attendance[0]);
                     if ($is_locked_attendance) {
@@ -279,6 +290,40 @@ class Attendance
 		return $last_id;
 	}
 
+	/**
+	 * Restore attendance
+	 * @param 	int|array	   one or many attendances id
+	 * @return 	int    		   affected rows
+	 */
+	public function attendance_restore($attendance_id) {
+		global $_course;
+		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
+		$user_id 		= api_get_user_id();
+		if (is_array($attendance_id)) {
+			foreach ($attendance_id as $id) {
+				$id	= intval($id);
+				$sql = "UPDATE $tbl_attendance SET active = 1 WHERE id = '$id'";
+				Database::query($sql);
+				$affected_rows = Database::affected_rows();
+				if (!empty($affected_rows)) {
+					// update row item property table
+					api_item_property_update($_course, TOOL_ATTENDANCE, $id,"restore", $user_id);
+				}
+			}
+		} else  {
+			$attendance_id	= intval($attendance_id);
+			$sql = "UPDATE $tbl_attendance SET active = 1 WHERE id = '$attendance_id'";
+			Database::query($sql);
+			$affected_rows = Database::affected_rows();
+			if (!empty($affected_rows)) {
+				// update row item property table
+				api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id,"restore", $user_id);
+			}
+		}
+		return $affected_rows;
+	}
+
+
 	/**
 	 * delete attendaces
 	 * @param 	int|array	   one or many attendances id