diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index a3d086e2dd8291e696d8fc0e844c170f61015845..2719793922327d3fb0b91b5467faf81a3e2b9083 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -2850,6 +2850,42 @@ END //
 
 
 
+DROP FUNCTION IF EXISTS RestrictAfterMilestone//
+CREATE FUNCTION `RestrictAfterMilestone`	(	`TeacherID` 	INT,
+												`DisciplineID` 	INT
+			 								) 	RETURNS int(11)
+    NO SQL
+BEGIN 				 
+
+	UPDATE `disciplines`
+	SET disciplines.MilestoneDate = CURDATE(),
+		disciplines.isMilestone = 1
+	WHERE disciplines.ID = DisciplineID
+	LIMIT 1;
+
+	RETURN 0;
+END //
+
+
+
+DROP FUNCTION IF EXISTS SetMilestoneForCredits//
+CREATE FUNCTION `RestrictAfterMilestoneForCredits`	(	`TeacherID` 	INT
+													) 	RETURNS int(11)
+    NO SQL
+BEGIN 	
+	DECLARE semID INT;
+
+	SET semID = GetCurSemesterID();
+	
+	UPDATE `disciplines`
+	SET disciplines.MilestoneDate = CURDATE(),
+		disciplines.isMilestone = 1
+	WHERE 	disciplines.SemesterID = semID AND
+			disciplines.ExamType = 'credit';
+
+	RETURN 0;
+END //
+
 -- -------------------------------------------------------------------------------------------
 -- Label: modules
 -- -------------------------------------------------------------------------------------------
@@ -3566,7 +3602,7 @@ CREATE FUNCTION `SetStudentRate`(	`TeacherID` 	INT,
 									RETURNS int(11)
     NO SQL
 BEGIN
-    DECLARE checker, DisciplineID, groupID, rateID, maxRate INT;
+    DECLARE checker, DisciplineID, groupID, rateID, maxRate, isOver, mtype INT;
     DECLARE isLocked, isUsed tinyint; 
 
 	SET groupID = -1;
@@ -3579,10 +3615,18 @@ BEGIN
 		RETURN -1;
 	END IF;					 
 
+	SET isOver = 1;
     SET isLocked = 0;
     SET DisciplineID = -1;
-    SELECT modules.DisciplineID, disciplines.isLocked, rating_table.StudentID, submodules.isUsed, submodules.MaxRate
-    INTO DisciplineID, isLocked, rateID, isUsed, maxRate
+    SET mtype = -1;
+    SELECT 	modules.DisciplineID, 
+    		disciplines.isLocked, 
+    		disciplines.isMilestone, 
+    		rating_table.StudentID, 
+    		submodules.isUsed, 
+    		submodules.MaxRate,
+    		modules.Type
+    INTO DisciplineID, isLocked, isOver, rateID, isUsed, maxRate, mtype
 	FROM `submodules`
 	INNER JOIN `modules` 				ON 	submodules.ModuleID = modules.ID
 	INNER JOIN `disciplines` 			ON 	modules.DisciplineID = disciplines.ID
@@ -3600,7 +3644,10 @@ BEGIN
 				disciplines_groups.ID IS NOT NULL
 			)
 	LIMIT 1;
-	IF DisciplineID <= 0 OR Rate > maxRate THEN
+	IF 	DisciplineID <= 0 OR 
+		Rate > maxRate OR 
+		(isOver > 0 AND (mtype = 1 OR mtype = 3))
+	THEN
 		RETURN -1;
 	END IF;
 
diff --git a/db/Structure.sql b/db/Structure.sql
index 82ffa04a22e69da5e1efc930cbea51eb81afce91..d16e12a988788fa03370431453a701ff127b4764 100644
--- a/db/Structure.sql
+++ b/db/Structure.sql
@@ -90,7 +90,11 @@ CREATE TABLE IF NOT EXISTS `disciplines` (
   `LectionCount` int(11) NOT NULL DEFAULT '0',
   `LabCount` int(11) NOT NULL DEFAULT '0',
   `FacultyID` int(11) NOT NULL,
+  -- isLocked (for editing structure)
   `isLocked`  tinyint(1) NOT NULL DEFAULT '0',
+  -- isOver semester time (or is session time)
+  `isOver`  tinyint(1) NOT NULL DEFAULT '0',
+  `OverDate` DATE NULL DEFAULT NULL,
   PRIMARY KEY (`ID`),
   KEY `GradeID`   (`GradeID`),
   KEY `SubjectID` (`SubjectID`),
@@ -557,7 +561,7 @@ INSERT INTO `page_access` (`ID`, `Pagename`, `Bitmask`) VALUES
 (24, 'handler:Rating', 4),
 (25, 'handler:Settings', 1),
 (26, 'teacher:exam', 4),
-(27, 'dean_office:index', 24)//
+(27, 'dean_office:index', 16)//
 
 
 INSERT INTO `general_settings` (`ID`, `Val`, `ValS`) VALUES
diff --git a/db/fix.sql b/db/fix.sql
index b005e538021916f7a03d7adfabce57ecdbff6de1..af042e239690b9e3398119b00e8fc6899333ab8a 100644
--- a/db/fix.sql
+++ b/db/fix.sql
@@ -1,48 +1,4 @@
-DELETE FROM `page_access`;
-
-UPDATE `user_roles` SET user_roles.Mark = 31 WHERE user_roles.RoleName LIKE 'Преподаватель-Администратор';
-UPDATE `user_roles` SET user_roles.Mark = 21 WHERE user_roles.RoleName LIKE 'Работник деканата';
-UPDATE `user_roles` SET user_roles.Mark = 5 WHERE user_roles.RoleName LIKE 'Преподаватель';
-UPDATE `user_roles` SET user_roles.Mark = 3 WHERE user_roles.RoleName LIKE 'Студент';
-
-
--- 1 - common
--- 2 - student
--- 4 - teacher
--- 8 - admin
--- 16 - deans
--- INSERT INTO `user_roles` (`ID`, `Type`, `RoleName`, `Mark`) VALUES
--- (1, 'student', 'Студент', 3),
--- (2, 'teacher', 'Преподаватель', 5),
--- (3, 'teacher', 'Преподаватель-Администратор', 31),
--- (4, 'teacher', 'Работник деканата', 21)//
-
-INSERT INTO `page_access` (`ID`, `Pagename`, `Bitmask`) VALUES
-(1, 'common:index', 1),
-(2, 'common:settings', 1),
-(3, 'common:profile', 1),
-(4, 'teacher:index', 4),
-(5, 'teacher:settings', 4),
-(6, 'teacher:map:create', 4),
-(7, 'teacher:map:edit', 4),
-(8, 'teacher:rating', 4),
-(9, 'teacher:profile', 4),
-(10, 'admin:common', 8),
-(11, 'student:index', 2),
-(12, 'student:settings', 2),
-(13, 'student:subject', 2),
-(14, 'teacher:map:discipline', 4),
-(15, 'teacher:map:structure', 4),
-(16, 'teacher:map:groups', 4),
-(17, 'teacher:map:students', 4),
-(18, 'teacher:map:teachers', 4),
-(19, 'handler:AdmAccounts', 8),
-(20, 'handler:AdmStudents', 8),
-(21, 'handler:AdmTeachers', 8),
-(22, 'handler:GetHelp', 1),
-(23, 'handler:Map', 4),
-(24, 'handler:Rating', 4),
-(25, 'handler:Settings', 1),
-(26, 'teacher:exam', 4),
-(27, 'dean_office:index', 24);
+ALTER TABLE `disciplines`
+ADD `isMilestone`  int(11) NOT NULL DEFAULT '0',
+ADD `MilestoneDate` DATE NULL DEFAULT NULL;