Extension:VoteSystem/VoteSystem module.php

';	$dbr->freeResult( $res ); return $output; }

function showVoteForm ( $id_question, $cut=false ) { $SQLQuery = "	select		q.name as question_name,		q.type,		a.id as id_answer,		a.name as answer_name,		a.hasText	from vote_question as q left outer join vote_answer as a		on q.id = a.id_question	where q.id = $id_question		and q.del is null		and q.finished is null		and a.del is null	order by a.sort asc;	"; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query($SQLQuery); $output = '  function changeVoteInputEnable(checkbox, voteTextName) { if (checkbox.checked) { document.getElementById(voteTextName).disabled = false; }				else { document.getElementById(voteTextName).disabled = true; }		}	 '; $dbr->freeResult( $res ); return $output; }

function checkPermissions( $id_question = 0 ) { global $wgUser; $dbr =& wfGetDB( DB_SLAVE ); $permission = ''; $user = ($wgUser->getName > '') ? $wgUser->getName : $_SERVER['REMOTE_ADDR']; $SQLQuery = "	set @was_answer = (	select count(*) 	from vote_result 	where `id_question` = $id_question 		and `user` = '".$user."'	);"; $dbr->query($SQLQuery); $SQLQuery = "	select		`permissions_read`,		`permissions_write`,		IF(`multi_count` IS NOT NULL, 0, @was_answer) as was_answer	from vote_question	where id = $id_question;	"; $res = $dbr->query($SQLQuery); $row = $dbr->fetchObject( $res );

$intersection_read = array_intersect(		array_map('strtolower',split(',',$row->permissions_read)),		array_map('strtolower',$wgUser->getEffectiveGroups)	); $intersection_write = array_intersect(		array_map('strtolower',split(',',$row->permissions_write)),		array_map('strtolower',$wgUser->getEffectiveGroups)	); if (count($intersection_write) && !$row->was_answer) { $permission = 'write'; }	else if (count($intersection_read)) { $permission = 'read'; }	else if ($row->was_answer && count($intersection_write)) { $permission = 'was_answer'; }	else { $permission = ''; }	$dbr->freeResult( $res ); return $permission; }

?>