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

CALL `CheckIdLogin`(p_sid,p_password, outputCode);
IF outputCode = 42 OR outputCode = 2005 THEN 
	SET outputCode = 42;
	SELECT adminLevel > 8 INTO canCreate FROM membres WHERE ID=p_sid;
	INSERT INTO discuts SELECT d.ID AS ID, d.name AS Name, m.pseudo AS creatorPseudo FROM discussions AS d LEFT JOIN membres AS m ON d.creatorID = m.ID WHERE CheckInGroup(p_sid,authorizedGroupId) = 42;
END IF;

END//
DELIMITER ;
