DROP PROCEDURE IF EXISTS GetDiscutInfo;
DELIMITER //
CREATE PROCEDURE GetDiscutInfo
(
  IN p_sid TEXT,
  IN p_password TEXT,
  IN p_did INT,
  OUT outputCode INT(11),
  OUT o_connected INT(1)
)
MODIFIES SQL DATA
BEGIN

CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode=2005 THEN 
	SET o_connected = 1;
ELSE
	SET o_connected = 0;
END IF;

SET outputCode :=( SELECT CASE WHEN (SELECT CheckInGroup(p_sid,authorizedGroupID)=42 OR p_sid=creatorID FROM discussions WHERE ID=p_did) THEN 42 ELSE 2019 END );
	
END//
DELIMITER ;
