From 5aeedb341e15b747a6e5d3c1d31ee730ce39dc29 Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.Silence@gmail.com>
Date: Sat, 20 Sep 2014 00:00:57 +0400
Subject: [PATCH] =?UTF-8?q?"=D0=9C=D0=B8=D1=85=D0=B0=D0=BB=D0=BA=D0=BE?=
 =?UTF-8?q?=D0=B2=D0=B8=D1=87"=20fix?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/StoredProcedures.sql |  2 +-
 db/fix.sql              | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 db/fix.sql

diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index 8fadd3c1d..38779393c 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -2987,7 +2987,7 @@ BEGIN
 	INNER JOIN `disciplines` 	ON 	disciplines.ID = modules.DisciplineID
 	WHERE 	TeacherID = disciplines.AuthorID AND
 			SubmoduleID = submodules.ID	AND
-			modules.Type = 0
+			modules.Type = 1
 	LIMIT 1;
     IF checker <= 0 THEN
     	RETURN -1;
diff --git a/db/fix.sql b/db/fix.sql
new file mode 100644
index 000000000..3549e82a3
--- /dev/null
+++ b/db/fix.sql
@@ -0,0 +1,31 @@
+DELIMETER //
+DROP FUNCTION IF EXISTS ChangeSubmoduleControlType//
+CREATE FUNCTION `ChangeSubmoduleControlType`(	`TeacherID` 	INT, 
+												`SubmoduleID` 	INT, 
+												`ControlType`	VARCHAR(30) charset utf8
+											)	RETURNS int(11)
+    NO SQL
+BEGIN  
+    DECLARE checker INT;  					 
+	
+	SET checker = -1;
+	SELECT submodules.ID 
+	INTO checker 
+	FROM `submodules`
+	INNER JOIN `modules` 		ON 	submodules.ModuleID = modules.ID
+	INNER JOIN `disciplines` 	ON 	disciplines.ID = modules.DisciplineID
+	WHERE 	TeacherID = disciplines.AuthorID AND
+			SubmoduleID = submodules.ID	AND
+			modules.Type = 1
+	LIMIT 1;
+    IF checker <= 0 THEN
+    	RETURN -1;
+	END IF;
+
+	UPDATE `submodules` 
+	SET submodules.Type = ControlType
+	WHERE submodules.ID = SubmoduleID
+	LIMIT 1;
+	RETURN 0;
+END //
+DELIMETER ;
\ No newline at end of file
-- 
GitLab