Statistics
| Branch: | Revision:

root / evote / data / printRoundsRes.php @ f52a1778

History | View | Annotate | Download (7.5 kB)

1
<?php
2
/**************************************************************************************************
3
???????? ???? ??? ????????? ??? ??????? ? ??????? ???? ????????? ??? ?????????.
4
(?????????????? ??????????, ????? ?????????, ????????????? ???????? ??????????? ??? ???
5
?? ?????????? ?????????) ??? ??? ????????????? ??? ?????????? ?????????
6
**************************************************************************************************/
7

    
8
include_once("check_tools.php");
9
include_once("../tools.php");
10
include_once("db_tools.php");
11
include_once("pdf_tools.php");
12
require_once('../tcpdf/config/lang/eng.php');
13
require_once('../tcpdf/tcpdf.php');
14
include_once("data_tools.php");
15

    
16
$myElection = $_SESSION['EVOT_ElectionCode'];
17
$conn=db_connect();
18

    
19
//??????? ??? ?? ?? ???? ????? ? ?????????        
20
$isFinished = checkElectionFinished($myElection, $conn);
21
db_disconnect($conn);
22

    
23
if(!$isFinished){
24
        echo "???????: ? ????????? ??? ???? ???????????, ???????? ??? ?????? ?? ????? ???????? ????????????? ??? ????!";
25
        exit();
26
}
27

    
28

    
29
//global variable -> the current date/time
30
global $today;
31
$today = strftime("%Y-%m-%d, %H:%M:%S");
32

    
33
//---------------?????????? ????????----------------------------------------------
34
// Extend the TCPDF class to create custom Header and Footer
35
class MYPDF extends TCPDF {
36

    
37
        //Page header
38
        public function Header() {
39
                // Logo
40
                $image_file = '../images/logo.png';
41
                $this->Image($image_file, 10, 10, 40, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
42
                // Set font
43
                $this->SetFont('dejavusans', 'B', 20);
44
                // Title
45
                $this->Cell(0, 0, 'e-Counting', 0, 0, 'C', false, '', 0, false, 'T', 'C');
46
        }
47

    
48
        // Page footer
49
        public function Footer() {
50
                // Position at 15 mm from bottom
51
                $this->SetY(-15);
52
                // Set font
53
                $this->SetFont('dejavusans', 'I', 8);
54
                //current date
55
                //setlocale(LC_CTYPE, 'greek');
56
                //setlocale(LC_TIME, 'greek');
57
                $this->Cell(80, 0, $GLOBALS['today'], 0, 0, 'L', false, '', 0, false, 'T', 'C');
58
                // Page number
59
                $this->SetX(-65);
60
                $pageNums = '?????? '. $this->getAliasNumPage().'/'.$this->getAliasNbPages();
61
                $this->Cell(0, 0, $pageNums, 0, 0, 'R', false, '', 0, false, 'T', 'C');
62
        }
63
}
64
//---????? ?????????? ????????---------------------------------------------------
65
//-------------------------------------------------------------------------------
66

    
67

    
68
//-------?????? ?????????------------------------------------------------------
69
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
70

    
71
// set document information
72
/*$pdf->SetCreator('????????? ????????');
73
$pdf->SetAuthor('e-Election');
74
$pdf->SetTitle('???????? ??????? ????????????? ??????????');
75
$pdf->SetSubject('bla bla bla');
76
*/
77

    
78
$pdf->SetCreator(PDF_CREATOR);
79

    
80
// set default header data
81
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
82

    
83
// set header and footer fonts
84
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
85
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
86

    
87
// set default monospaced font
88
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
89

    
90
//set margins
91
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
92
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
93
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
94

    
95
//set auto page breaks
96
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
97

    
98
//set image scale factor
99
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
100

    
101
//set some language-dependent strings
102
$pdf->setLanguageArray($l);
103

    
104
// set font
105
$pdf->SetFont('dejavusans', '', 12);
106

    
107
// add a page
108
$pdf->AddPage();
109

    
110
//?????? ??? ???????? ?? ?????????????? ??? ??????????
111
$eRows = selMyElection($myElection);
112
//$cRows = selMyCandidates($myElection);
113
//$bRows = selMyBallots($myElection);
114

    
115
//??????? ???? ?????? ?? ?????????? ???? ????? ?? ????? ?????? ? ??????? ??? ????????? ??? ????? ?? ?????????? ???
116
/*$listCands = array();
117
foreach($cRows as $can){
118
        $myId=$can["canCode"];
119
        $listCands[$myId] = array($can["canLastName"], $can["canFirstName"]);
120
}
121
*/
122
//????????? ??? ?????? ??? ???? ?? ?? ????????
123
$html = '<h2><u><center>???????? ????????????? ??? ???? ????????????</u></h2></center><br>';
124
$html = $html . printElection($eRows);
125

    
126
//??? ?? ???????? ?? ???????? ?????
127
$html = $html . printThreshold($myElection);
128

    
129
//?????? ?? ?????? ????? ??? ???? ??? ??? ????????
130
//$html = $html . '<br><b>2. ?????????? ??? ???? ????????????</b><br>';
131
$pdf->writeHTML($html,true,false,true,false,'');
132
$html = "";
133

    
134
//set the greek locale for the correct representation of numbers
135
setlocale(LC_NUMERIC, 'greek');
136

    
137
$scoreRows = getRoundResults($myElection);
138
$actionRows = getRoundActions($myElection);
139
$randomRows = getRandoms($myElection);
140
$rsize = count($randomRows);
141
$asize = count($actionRows);
142

    
143
$i=1; //??????? ???? ??????
144
$j=0; //??????? ??? ???????? ????????? ???? ??? ????
145
$k=0; //??????? ?? ?????? ??? ????????? ???? ?????? ?????????
146
foreach($scoreRows as $sRow){
147
        if(($i != $sRow["round"])||($j == 0)){
148
                if($sRow["round"] > 1){ //?? ??? ????? ???? 1? ????, ?????? ??? ??????????? ??????
149
                        $html = $html . '</table><br><br>';
150
                }
151
                $j=1;
152
                $i = $sRow["round"];
153
                $html = $html . '<b>????? ??.' . $i . '</b><br>'; 
154
                $html = $html . '<table name="sumVotes" cellpadding="1" cellspacing="1" border="1">';
155
                $html = $html . '<tr><td colspan="2" width="50%">?????????</td><td width="13%">?????? ?????</td><td width="10%">???????</td><td width="27%">??????????</td></tr>';
156
        }
157
        
158
        $html = $html . '<tr><td width="30%">' . $sRow["canLast"] . '</td><td width="20%">' . $sRow["canFirst"] . '</td><td width="13%">'; // . $sRow["counting"] . '</td><td width="10%">';
159
        $str=sprintf("%.4f", $sRow["counting"]);
160
        $html=$html . $str . '</td><td width="10%">';
161
        
162
        //??? ?? ??? ?? ????? ?????? ??????? ??? ???? ???? ??? ?? ???????? ??? ???????????? ????????
163
        //echo "s=" . $rsize . " k=" . $k . " ran=" . $randomRows[$k]["round"];
164
        if($k < $rsize){
165
                if($sRow["round"] == $randomRows[$k]["round"]){
166
                        if($sRow["canCode"] == $randomRows[$k]["canCode"]){
167
                                $html = $html . '???';
168
                                $k++;
169
                        }
170
                }
171
        }
172
        $html = $html . '</td><td width="27%">';
173
        //??? ?? ??? ?? ? ????????? ??????? ? ???????????? ??? ???? ????
174
        if($sRow["round"] == $actionRows[$i - 1]["round"]){
175
                if($sRow["canCode"] == $actionRows[$i - 1]["canCode"])
176
                        $html = $html . $actionRows[$i - 1]["action"];
177
        }
178
//        $html = $html . 'r='.$rsize . ' a='. $asize;
179
    $html = $html . '</td></tr>';
180
        $j++;
181
}
182
$html = $html . '</table>';
183
//echo $html;
184

    
185
$pdf->writeHTML($html,true,false,true,false,'');
186
//$pdf->Ln();
187

    
188

    
189
$filename = 'RoundResults' . $myElection . '.pdf';
190
$pdf->Output($filename, 'D');
191

    
192

    
193
?>