-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSpecialPrefCandidates.php
184 lines (169 loc) · 7.71 KB
/
getSpecialPrefCandidates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
session_start();
require('config.php');
require('languages/hi/lang.hi.php');
require('common/common.php');
require('vendor/autoload.php');
if(!in_array($_SESSION['ulb_region'], Common::TEMP_LOTTERY_ENABLE)) {
header("location: error.php");
die();
}
$sessionProvider = new EasyCSRF\NativeSessionProvider();
$easyCSRF = new EasyCSRF\EasyCSRF($sessionProvider);
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: index.php");
exit;
} else {
if (time()-$_SESSION['timestamp'] > IDLE_TIME) {
header("location: logout.php");
} else{
$_SESSION['timestamp']=time();
}
}
$seedNumber = $specialPreference = '';
$seed_number_err = $special_preference_err = '';
if($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$easyCSRF->check('my_token', $_POST['token']);
}
catch(Exception $e) {
die($e->getMessage());
}
$trimSeedNumber = $_POST["seedNumber"];
if(empty($trimSeedNumber)){
$seed_number_err = "Please enter a seed number.";
} else {
$seedNumber = htmlspecialchars($trimSeedNumber);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo $lang['select_candidates']; ?></title>
</head>
<body>
<?php include 'header.php';?>
<?php include 'lottery_information.php';?>
<div id="get-candidates" class="get_candidates_wrapper">
<div class="row">
<div class="col alert alert-info margin-5x text-align-center">
<a data-toggle="modal" data-target="#lotteryInformation" class="fs4"><?php echo $lang['lottery_msg_1'];?>
<strong class="text-decoration-underline clr-blue"><?php echo $lang['lottery_msg_2'];?></strong>
</a>
</div>
<div class="col alert alert-info margin-5x text-align-center">
<a class="fs4" href="getAllCategoryCandidates.php"><?php echo $lang['lottery_msg_7']; ?></a>
</a>
</div>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<input type="hidden" name="token" value="<?php echo $easyCSRF->generate('my_token'); ?>">
<div class="container">
<div class="row">
<div class="col-sm">
<div class="form-group pull-left">
<label for="seedNumber" class="required"><?php echo $lang['seed_number']; ?></label>
<input type="text" autocomplete="off" name="seedNumber" maxlength="4" class="seed-number form-control <?php echo(!empty($seed_number_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $seedNumber; ?>" pattern="\d{4}" required/>
<span class="invalid-feedback text-align-center"><?php echo $seed_number_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="<?php echo $lang['select_candidates']; ?>">
</div>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(empty($seed_number_err) && empty($special_preference_err)) {
function selectCandidate($criteria, $code, $seedNumber, $mustache, $lang, $print) {
$limit = Common::getCandidateSelectionLimitForSpecialPreferences($criteria);
$data = Common::selectCandidatesForSpecialPrefCategory($criteria, $limit, $code, $seedNumber);
if($print) {
$template = $mustache->loadTemplate('print_button');
echo $template->render();
$template = $mustache->loadTemplate('print_header');
echo $template->render(array('lang'=>$lang));
}
$template = $mustache->loadTemplate('table_body');
echo $template->render(array(
'data'=>$data,
'lang'=>$lang,
'totalSeats'=>$limit,
'totalParticipated'=>Common::getTotalEnteriesBySpecialPreferences($criteria),
'totalSelected'=>sizeof($data),
'selectionFor'=>$criteria,
'seedNumber'=>$seedNumber,
'errorMessage'=>Common::getErrorMessage($limit, sizeof($data)),
'getReceiptNumber' => function($text, Mustache_LambdaHelper $helper) {
return substr($helper->render($text), strpos($helper->render($text), "_") + 1);
},
'getTextInHindi' => function($text, Mustache_LambdaHelper $helper) {
return Common::getTextInHindi(trim($helper->render($text)));
}
));
}
$specialPreferenceArr = ['EXOFFICER', 'SPORTSPERSON', 'DISABLED'];
$print = true;
for($i=0; $i<sizeof($specialPreferenceArr); $i++) {
$criteria = strtoupper($specialPreferenceArr[$i]);
$code = Common::getCodeForSelectionCriteria($criteria);
if(Common::codeAndSeedExistsInDB($code, $seedNumber)) {
$limit = Common::getCandidateSelectionLimitForSpecialPreferences($criteria);
if($print) {
$template = $mustache->loadTemplate('print_button');
echo $template->render();
$template = $mustache->loadTemplate('print_header');
echo $template->render(array('lang'=>$lang));
}
$print = false;
$data = Common::getDataFromDbByCodeAndSeed($code, $seedNumber);
$template = $mustache->loadTemplate('table_body');
echo $template->render(array(
'data'=>$data,
'lang'=>$lang,
'totalSeats'=>Common::getCandidateSelectionLimitForSpecialPreferences($criteria),
'totalParticipated'=>Common::getTotalEnteriesBySpecialPreferences($criteria),
'totalSelected'=>sizeof($data),
'selectionFor'=>$criteria,
'seedNumber'=>$seedNumber,
'errorMessage'=>Common::getErrorMessage($limit, sizeof($data)),
'getReceiptNumber' => function($text, Mustache_LambdaHelper $helper) {
return substr($helper->render($text), strpos($helper->render($text), "_") + 1);
},
'getTextInHindi' => function($text, Mustache_LambdaHelper $helper) {
return Common::getTextInHindi(trim($helper->render($text)));
}
));
} else {
if(Common::existsInDB($code, 'code')) {
Common::showAlert($lang['candidate_already_selected']);
exit();
}
selectCandidate($criteria, $code, $seedNumber, $mustache, $lang, $print);
$print = false;
}
}
mysqli_close($link);
}
}
?>
<script type="text/javascript">
function printpage() {
var printButton = document.getElementById("printbtn");
var content = document.getElementById("get-candidates");
var printHeader = document.getElementById("print-header");
printButton.style.display = 'none';
content.style.display = 'none';
printHeader.style.display = 'block';
window.print();
printButton.style.display = 'block';
content.style.display = 'block';
printHeader.style.display = 'none';
}
</script>