Extension:VoteSystem/VoteSystem body.php

';			$dbr->freeResult( $res ); return $output; }		function questionEdit( $id = 0 ) { global $wgUser; $qname = ''; $type = 0; if ($id > 0) { $SQLQuery = "				select					q.`name`,					q.`type`,					q.permissions_read,					q.permissions_write,					q.user,					q.permissions_edit,					q.multi_count,					count(r.id) as results				from vote_question as q left outer join vote_result as r on q.id = r.id_question				where q.id = $id					and q.del is null				group by q.`name`, q.`type`, q.permissions_read, q.permissions_write, q.user, q.permissions_edit, q.multi_count				"; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query($SQLQuery); $row = $dbr->fetchObject( $res ); $qname = $row->name; $type = $row->type; $permissions_read = $row->permissions_read; $permissions_write = $row->permissions_write; $permissions_edit = $row->permissions_edit; $multi_count = $row->multi_count; $canEditAccess = false; if ( ($wgUser->getName == $row->user) || (in_array('sysop', $wgUser->getEffectiveGroups)) ) { $canEditAccess = true; }				#				$isResults = $row->results; $dbr->freeResult( $res ); }			$delQuestion = ''; if ($id > 0) { $output = '  function delQuestion { if (window.confirm("Do you really want to delete vote ?")) { location.href="'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&mode=question_del&id='. $id .'"; }					}				 ';				$delQuestion = ''; }			$output .= ' Edite vote theme < - Return to list  ';			$output .= ' ';			if ($id > 0) { $output .= $this->answerList( $id, $qname ); }			if ( $isResults ) { $output .= ' Download results log-file '; }			return $output; }		function questionSave( $PostData ) { global $wgUser; $dbw = wfGetDB( DB_MASTER ); $multi_count = 'NULL'; if ($PostData->getInt('multi_count') == 1) { $multi_count = '1'; }			if ($PostData->getInt('id_question') > 0) { $id_question = $PostData->getInt('id_question'); $SQLQuery = ' update vote_question set `name` = "'.$PostData->getVal('qname').'", `type` = "'.$PostData->getVal('qtype').'", `permissions_read` = "'.$PostData->getVal('permissions_read').'", `permissions_write` = "'.$PostData->getVal('permissions_write').'", `permissions_edit` = "'.$PostData->getVal('permissions_edit').'", `multi_count` = '.$multi_count.', `last_updated` = CURRENT_TIMESTAMP where id = '.$PostData->getVal('id_question').' ';				$dbw->query($SQLQuery); }			else { $id_question = 0; $SQLQuery = ' insert into vote_question (				`name`,				`type`,				`permissions_read`,				`permissions_write`,				`permissions_edit`,				`multi_count`,				`user`				) values (				"'.$PostData->getVal('qname').'",				"'.$PostData->getVal('qtype').'",				"'.$PostData->getVal('permissions_read').'",				"'.$PostData->getVal('permissions_write').'",				"'.$PostData->getVal('permissions_edit').'",				'.$multi_count.',				"'.$wgUser->getName.'"				); ';				$dbw->query($SQLQuery); $SQLQuery = 'select LAST_INSERT_ID as id_question;'; $res = $dbw->query($SQLQuery); $row = $dbw->fetchObject( $res ); $id_question = $row->id_question; }			$output = $this->questionEdit( $id_question ); return $output; }		function questionDelete ( $id=0 ) { if ( $id > 0 ) { $dbw = wfGetDB( DB_MASTER ); $SQLQuery = ' update vote_question set del=1 where id = '.$id.' ';				$res = $dbw->query($SQLQuery); }		}		function answerList( $id_question=0, $qname='' ) { $output = ''; if ($id_question > 0) { $output = ' Answer list + New answer ';				}				$output .= ' ';				$dbr->freeResult( $res ); }			else { $output = "Answer list error."; }			return $output; }		function answerEdit( $id_question = 0, $id = 0, $question_name = '' ) { if ( $id_question == 0 ) { $output = "Answer edit error."; return output; }			$aname = ''; $hasText = null; if ($id > 0) { $SQLQuery = "				select				a.`name`,				a.`hasText`,				q.`name` as question_name				from vote_answer as a inner join vote_question as q					on a.id_question = q.id				where a.id = $id				"; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query($SQLQuery); $row = $dbr->fetchObject( $res ); $aname = $row->name; $hasText = $row->hasText; $question_name = $row->question_name; $dbr->freeResult( $res ); }			$output = ' Answer edit  ';			return $output; }		function answerSave( $PostData ) { $dbw = wfGetDB( DB_MASTER ); $hasText = $PostData->getInt('hastext')?'1':'null'; if ($PostData->getInt('id_answer') > 0) { $id_answer = $PostData->getInt('id_answer'); $SQLQuery = ' update vote_answer set `name` = "'.$PostData->getVal('aname').'", `hasText` = '.$hasText.', `last_updated` = CURRENT_TIMESTAMP where id = '.$PostData->getVal('id_answer').' ';				$res = $dbw->query($SQLQuery); }			else { $id_answer = 0; $SQLQuery = ' set @max_sort = (select MAX(sort) from vote_answer where id_question='.$PostData->getVal('id_question').'); '; $dbw->query($SQLQuery); $SQLQuery = ' insert into vote_answer (				`name`,				`id_question`,				`hasText`,				`sort`				) values (				"'.$PostData->getVal('aname').'",				'.$PostData->getInt('id_question').',				'.$hasText.',				IFNULL(@max_sort+1, 1)				); ';				$dbw->query($SQLQuery); $SQLQuery = 'select LAST_INSERT_ID as id_answer;'; $res = $dbw->query($SQLQuery); $row = $dbw->fetchObject( $res ); $id_answer = $row->id_answer; }			$output = $this->questionEdit( $PostData->getInt('id_question') ); return $output; }		function answerDelete ( $id=0 ) { if ( $id > 0 ) { $dbw = wfGetDB( DB_MASTER ); $SQLQuery = ' update vote_answer set del=1 where id = '.$id.' ';				$res = $dbw->query($SQLQuery); }		}		function downloadAnswerLog ( $id_question ) { global $IP; if ($id_question > 0) { $content = array; $content[] = 'Date;Number;Answer;User;Text'; $dbr = wfGetDB( DB_SLAVE ); $SQLQuery = "				select					r.adate,					a.`sort`,					a.`name`,					r.`user`,					ifnull(r.`text`,'') as `text`				from vote_result as r inner join vote_answer a on r.id_answer = a.id				where r.id_question=$id_question					and a.del is null				order by r.adate asc				"; $res = $dbr->query($SQLQuery); while ( $row = $dbr->fetchObject( $res ) ) { $content[] = $row->adate.';'.$row->sort.';'.$row->name.';'.$row->user.';'.$row->text; }				$dbr->freeResult( $res ); $filename = "Question".$id_question."AnswerLog.txt"; $path = $IP. "/images/". $filename; @ob_start; header('Content-Type: text/plain; name="'.$filename.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); @ob_end_clean; readfile($path); unlink($path); die; }		}		function get_include_contents($filename) { global $wgRequest, $wgScriptPath, $wgOut; if (is_file($filename)) { ob_start; include $filename; $contents = ob_get_contents; ob_end_clean; return $contents; }		   return false; }       function loadMessages { static $messagesLoaded = false; global $wgMessageCache; if ( !$messagesLoaded ) { $messagesLoaded = true; require( dirname( __FILE__ ) . '/VoteSystem.i18n.php' ); foreach ( $messages as $lang => $langMessages ) { $wgMessageCache->addMessages( $langMessages, $lang ); }               }                return true; } }