From fa53ef5ac26d60ae55951888f62595667bee2080 Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.Silence@gmail.com>
Date: Tue, 30 Dec 2014 23:44:46 +0300
Subject: [PATCH] it's session time!

---
 db/StoredProcedures.sql | 58 +++++++++++++++++++++++++++++++++++---
 db/Structure.sql        |  4 +++
 db/fix.sql              | 62 ++---------------------------------------
 3 files changed, 61 insertions(+), 63 deletions(-)

diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index a3d086e2d..87e2c8bc1 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -2850,6 +2850,45 @@ END //
 
 
 
+DROP FUNCTION IF EXISTS OverSession//
+CREATE FUNCTION `OverSession`	(	`TeacherID` 	INT,
+									`DisciplineID` 	INT
+			 					) 	RETURNS int(11)
+    NO SQL
+BEGIN 				 
+	IF 	NOT InternalIsTeacherAuthor(TeacherID,DisciplineID)
+	THEN 
+		RETURN -1;
+	END IF;
+
+	UPDATE `disciplines`
+	SET disciplines.OverDate = CURDATE(),
+		disciplines.isOver = 1
+	WHERE disciplines.ID = DisciplineID
+	LIMIT 1;
+
+	RETURN 0;
+END //
+
+
+
+DROP FUNCTION IF EXISTS OverSessionAllCredit//
+CREATE FUNCTION `OverSessionAllCredit`	(	) 	RETURNS int(11)
+    NO SQL
+BEGIN 	
+	DECLARE semID INT;
+
+	SET semID = GetCurSemesterID();
+	
+	UPDATE `disciplines`
+	SET disciplines.OverDate = CURDATE(),
+		disciplines.isOver = 1
+	WHERE 	disciplines.SemesterID = semID AND
+			disciplines.ExamType = 'credit';
+
+	RETURN 0;
+END //
+
 -- -------------------------------------------------------------------------------------------
 -- Label: modules
 -- -------------------------------------------------------------------------------------------
@@ -3566,7 +3605,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 +3618,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.isOver, 
+    		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 +3647,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 fc1dfe61c..d16e12a98 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`),
diff --git a/db/fix.sql b/db/fix.sql
index b148817ce..d1383adc4 100644
--- a/db/fix.sql
+++ b/db/fix.sql
@@ -1,60 +1,4 @@
-DELETE FROM `page_access`;
-
-
-INSERT INTO `user_roles` (`ID`, `Type`, `RoleName`, `Mark`) VALUES
-(4, 'teacher', 'Работник деканата', 21);
-
-
-
-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', 16);
+ALTER TABLE `disciplines`
+ADD `isOver`  tinyint(1) NOT NULL DEFAULT '0',
+ADD `OverDate` DATE NULL DEFAULT NULL;
 
-- 
GitLab