Go to the documentation of this file.00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00009
00010 class contest implements module, fileuploadable {
00011 private $moduleComponentId;
00012 private $userId;
00013 private $action;
00014
00015 public function getHtml($userId, $moduleComponentId, $action) {
00016 $tihs->userId = $userId;
00017 $this->moduleComponentId = $moduleComponentId;
00018 $this->action = $action;
00019
00020 if ($action == 'view') {
00021 return $this->actionView();
00022 }
00023 else if ($action == 'edit') {
00024 return $this->actionEdit();
00025 }
00026 }
00027
00028 public function actionView() {
00029 $cid = $this->moduleComponentId;
00030 $uid = $this->userId;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 $subaction = '';
00043 if (isset($_GET['subaction']))
00044 $subaction = $_GET['subaction'];
00045
00046 if ($subaction == 'showproblem')
00047 return $this->getProblemPage($cid);
00048 else if ($subaction == 'showranklist')
00049 return $this->getRanklist($cid);
00050 else if ($subaction == 'showstatus')
00051 return $this->getStatus($cid);
00052 else if ($subaction == 'submit')
00053 return $this->getSubmitPage($cid);
00054
00055 return $this->getContestPage($cid);
00056 }
00057
00058 public function actionEdit() {
00059 }
00060
00061 private function getContestPage($contestId) {
00062 $problemQuery = "SELECT * FROM `contest_problem` WHERE `cid` = $contestId AND `testable` = 1 ORDER BY `pid`";
00063 $problemResult = mysql_query($problemQuery);
00064
00065 $html = '<table border="0">';
00066
00067 $className = array('even', 'odd');
00068 $parity = 0;
00069
00070 while ($problemRow = mysql_fetch_assoc($problemResult)) {
00071 $pcode = $problemRow['pcode'];
00072 $ptitle = $problemRow['pname'];
00073 $html .= "<tr class=\"{$className[$parity]}\"><td><a href=\"./+view&subaction=showproblem&pcode=$pcode\">{$problemRow['pcode']}</a></td><td><a href=\"./+view&subaction=showproblem&pcode=$pcode\">{$problemRow['ptitle']}</a></td></tr>\n";
00074 $parity = 1 - $parity;
00075 }
00076 $html .= '</table>';
00077
00078 return $html;
00079 }
00080
00081 private function getProblemId($contestId, $pcode) {
00082 $idQuery = "SELECT `pid` FROM `contest_problem` WHERE `cid` = $contestId AND `pcode` = '$pcode'";
00083 $idResult = mysql_query($idQuery);
00084 if (!$idResult) {
00085 displayerror('MySQL error while attempting to fetch problem id, on line ' . __LINE__ . ', ' . __FILE__);
00086 return -1;
00087 }
00088 $idRow = mysql_fetch_row($idResult);
00089 if ($idRow) return $idRow[0];
00090 else return -1;
00091 }
00092
00093 private function getProblemPage($contestId) {
00094 $pcode = '';
00095 if (isset($_GET['pcode']))
00096 $pcode = $_GET['pcode'];
00097 else {
00098 displayerror('Error. Problem code not specified.');
00099 return '';
00100 }
00101
00102 $problemId = $this->getProblemId($contestId, $pcode);
00103 if ($problemId < 0) {
00104 displayerror('Error. Invalid problem code specified. Could not find a problem in the current contest with the given problem code.');
00105 return '';
00106 }
00107
00108 global $sourceFolder, $moduleFolder;
00109
00110 $problemPageHtml = file_get_contents("$sourceFolder/$moduleFolder/contest/problems/$contestId/$pcode.html");
00111 $problemPageHtml .= $this->getSubmitForm($contestId, $problemId);
00112 return $problemPageHtml;
00113 }
00114
00115 private function getRanklist($contestId) {
00116 }
00117
00118 private function getStatus($contestId) {
00119
00120 }
00121
00122 function getPaginatedContent($selectQuery, $countQuery, $itemsPerPage, &$pageNumber, $sortField, $sortDirection, &$pageCount) {
00123 $startItem = 0;
00124 if ($itemsPerPage <= 0) $itemsPerPage = 20;
00125
00126 $itemCountResult = mysql_query($countQuery);
00127 if (!$itemCountResult) return false;
00128 $itemCount = mysql_fetch_row($itemCountResult);
00129 $itemCount = $itemCount[0];
00130
00131 $pageCount = ceil($itemCount / $itemsPerPage);
00132
00133 if ($pageNumber <= 0) $pageNumber = 1;
00134 else if ($pageNumber > $pageCount) $pageNumber = $pageCount;
00135
00136 $startItem = ($pageNumber - 1) * $itemsPerPage;
00137
00138 if ($sortField != '' && ($sortDirection == 'ASC' || $sortDirection == 'DESC')) $selectQuery .= " ORDER BY `$sortField` $sortDirection";
00139
00140 $selectQuery .= " LIMIT $startItem, $itemsPerPage";
00141 $selectResult = mysql_query($selectQuery);
00142 if (!$selectResult) {
00143 log_error(__FILE__, __LINE__, 'MySQL Error in query ' . $selectQuery . ': ' . mysql_error());
00144 return false;
00145 }
00146
00147 $results = array();
00148 while ($selectRow = mysql_fetch_array($selectResult)) {
00149 $results[] = $selectRow;
00150 }
00151 mysql_free_result($selectResult);
00152
00153 return $results;
00154 }
00155
00156 function getSortableTableHeading($headings, $orderBy, $orderDir, $getData) {
00157 $html = '<tr>';
00158 for ($i = 0; $i < count($headings); ++$i) {
00159 $html .= '<th><a href="./&orderby=' . $headings[$i][0] . '&orderdir=';
00160 if ($headings[$i][0] == $orderBy)
00161 $html .= ($orderDir == 'ASC' ? 'desc' : 'asc');
00162 else
00163 $html .= 'asc';
00164 $html .= $getData . '">' . $headings[$i][1] . '</a></th>';
00165 }
00166 $html .= "</tr>\n";
00167 return $html;
00168 }
00169
00170 function getPageNumberList($pageNumber, $pageCount, $getData) {
00171 $ret = '<ul class="pagenumbers">';
00172 for ($i = 1; $i <= $pageCount; ++$i)
00173 $ret .= '<li><a href="./&page=' . $i . $getData . '">' . "$i</a></li>\n";
00174 $ret .= "</ul>\n";
00175 return $ret;
00176 }
00177
00178 }
00179 ?>