DROP PROCEDURE IF EXISTS PresentVersion;
DELIMITER //
CREATE PROCEDURE PresentVersion
(
  IN p_sid INT,
  IN p_password TEXT,
  IN p_vid INT,
  OUT outputCode INT(11),
  OUT o_su INT(1),
  OUT o_ssu INT(1),
  OUT o_langageID INT,
  OUT o_projectName VARCHAR(255),
  OUT o_name VARCHAR(255),
  OUT o_fileAccessibility INT,
  OUT o_projectID INT,
  OUT o_tags INT
  
)
MODIFIES SQL DATA
BEGIN

CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN 
	SET outputCode := (SELECT (CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupId) = 42 OR CheckInGroup(p_sid,secondaryOwnersGroupId) = 42 OR p_sid = ownerID FROM projets INNER JOIN versions ON versions.projectID = projets.ID WHERE versions.ID = p_vid) THEN 42 ELSE 2018 END));
	IF outputCode = 42 THEN

		SELECT CheckInGroup(p_sid,projets.secondaryOwnersGroupId) = 42 OR projets.ownerID = p_sid, projets.ownerID = p_sid, versions.languageID, projets.name,versions.name,versions.fileAccessibility,projets.ID,versions.tags INTO o_su,o_ssu,o_langageID,o_projectName,o_name,o_fileAccessibility,o_projectID,o_tags FROM projets INNER JOIN versions ON versions.projectID = projets.ID WHERE versions.ID = p_vid;
		INSERT INTO verzions SELECT languageID AS language, ID, name FROM versions WHERE projectID = o_projectID;

	END IF;
END IF;

END//
DELIMITER ;
