diff --git a/~dev_rating/application/classes/Controller/Teacher/Rating.php b/~dev_rating/application/classes/Controller/Teacher/Rating.php
index 40a2526a6470658a8963c3cd47d3709257a48224..5fbf2edf79c42ab8fe141b50e6858a86db908abe 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Rating.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Rating.php
@@ -237,45 +237,54 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
                     $rateHandled[$i_g]['GradeTitle'] = 'Магистратура, '.$row['GradeNum'].' год';
 
                 $groupsHandled[$curGroupID] = $rateHandled[$i_g]['GradeTitle']." ".$row['GroupNum']." РіСЂСѓРїРїР°"; 
+                $i_s = 0;
             }
             // Студенты
-            $i_s++;
             
-            $curStudent = $rateHandled[$i_g]['Students'][$i_s];
-
+            
+            $curStudent = array();
             $curStudent['ID'] = $row['ID'];
             $curStudent['Last'] = $row['Last'];
             $curStudent['First'] = $row['First'];
             $curStudent['Second'] = $row['Second'];
             $curStudent['isAttached'] = $row['isAttached']; // #1
+            $curStudent['RateResult'] = 0;
 
             // Баллы студента
-            $rate = $db->getMapForStudentExam($row['ID'], $id);
             $i_r = 0;
-            $curStudent['RateResult'] = 0;
             $examRate = 0;
             $extraNum = 0;
+            $rate = $db->getMapForStudentExam($row['ID'], $id);
 
+            $lastExam = 0;
+            $lastExtra = 0;
+            
             foreach($rate as $r) {
-                $i_r++;
-                $curRate = $curStudent['Rates'][$i_r];
-
+                
+                $curRate = array();
                 $curRate['SubmoduleID'] = $r['SubmoduleID'];
                 $curRate['Rate'] = $r['Rate'];
-                $curRate['ModuleType'] = $r['ModuleType'];  
-                
-                if ($r['ModuleType'] == 'exam') {
-                    if (!is_null($r['Rate'])) {
-                        for ($k = 1; $k < $i_r; $k++)
-                            if ($curStudent['Rates'][$k]['ModuleType'] == 'exam')
-                                $curStudent['Rates'][$k]['Block'] = 'True';
-                        $examRate = $r['Rate'];
-                    }
-                } else {
-                    $extraNum = $i_r;
-                    $curStudent['RateResult'] += $r['Rate']; 
-                }
+                $curRate['ModuleType'] = $r['ModuleType'];
+
+                if (!is_null($r['Rate'])) 
+                {
+	                if ($r['ModuleType'] == 'exam') {
+	        			if ($lastExam != 0) {
+	    					$curStudent['Rates'][$lastExam]['Block'] = 'True';
+	        			}
+	        			$lastExam = $i_r;
+	        		} else if ($r['ModuleType'] == 'extra') {
+	        			if ($lastExtra != 0) {
+	    					$curStudent['Rates'][$lastExtra]['Block'] = 'True';
+	        			}
+	        			$lastExtra = $i_r;
+	        			$curStudent['RateResult'] += $r['Rate'];
+	        		}
+        		}
+
+
                 $curStudent['Rates'][$i_r] = $curRate;
+                $i_r++;
             }
             $curStudent['RateResult'] += $examRate;
             $total = $db->GetStudentRate($row['ID'], $id);
@@ -284,7 +293,20 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
             $curStudent['RateSemesterResult'] = $total - $curStudent['RateResult'];
             $curStudent['RateResult'] = $total;
 
+            $magic_bottom = 32;
+            $magic_top = 38;
+
+            if ($curStudent['RateSemesterResult'] < $magic_bottom || 
+            	$curStudent['RateSemesterResult'] > $magic_top) 
+            {
+    			$curStudent['RateResult'][$lastExtra]['MaxRate'] = 0;	
+            } else {
+            	$curStudent['RateResult'][$lastExtra]['MaxRate'] = $magic_top - $curStudent['RateSemesterResult'];
+            }
+
+            
             $rateHandled[$i_g]['Students'][$i_s] = $curStudent;
+            $i_s++;
 
         }