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
|
<?php
function generate_pdf()
{
$mpath = drupal_get_path('module', 'om_pssp');
require($mpath.'/pdf/fpdf/fpdf.php');
require($mpath.'/pdf/phpqrcode/qrlib.php');
global $user;
$x = $user->uid;
$proposal_id = arg(4);
$query3 = db_query("SELECT * FROM om_pssp_proposal WHERE approval_status=3 AND uid= :uid AND id=:proposal_id", array(
':uid' => $user->uid,
':proposal_id'=>$proposal_id
));
$data3 = $query3->fetchObject();
if($data3){
if($data3->uid != $x){
drupal_set_message('Certificate is not available','error');
return;
}
}
$gender = array(
'salutation' => 'Mr. /Ms.',
'gender' => 'He/She'
);
if ($data3->gender) {
if ($data3->gender == 'M') {
$gender = array(
'salutation' => 'Mr.',
'gender' => 'He'
);
} //$data3->gender == 'M'
else {
$gender = array(
'salutation' => 'Ms.',
'gender' => 'She'
);
}
} //$data3->gender
$pdf = new FPDF('L', 'mm', 'Letter');
if (!$pdf) {
echo "Error!";
} //!$pdf
$pdf->AddPage();
$image_bg = $mpath . "/pdf/images/bg_cert.png";
$pdf->Image($image_bg, 0, 0, $pdf->w, $pdf->h);
$pdf->SetMargins(18, 1, 18);
$path = drupal_get_path('module', 'om_pssp');
$pdf->Ln(50);
$pdf->SetFont('Times', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(240, 8, 'This is to certify that', '0', '1', 'C');
$pdf->Ln(0);
$pdf->SetFont('Times', 'I', 16);
$pdf->SetTextColor(37, 22, 247);
$contributor_name = WordWrap($data3->contributor_name,70);
$pdf->MultiCell(240, 8, $data3->name_title . '. ' . $contributor_name, '0', 'C');
$pdf->Ln(0);
$pdf->SetFont('Times', '', 14);
$title = WordWrap($data3->project_title,160);
$university = WordWrap('from ' . $data3->university . ' has successfully contributed under the ', 160);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(240, 8, $university . 'OpenModelica Power Systems Simulation Project.', '0','C');
$pdf->Ln(0);
$pdf->Cell(240, 8, 'He/She has created the following simulation', '0', '1', 'C');
$pdf->SetTextColor(37, 22, 247);
$pdf->SetFont('Times','I',16);
$pdf->MultiCell(240, 8, $title, '0', 'C');
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont('Times','',14);
$pdf->Cell(240, 8, 'using OpenModelica. The code is available at ', '0', '', 'C');
$pdf->SetTextColor(0, 0, 0);
$pdf->Ln(8);
$pdf->SetX(94);
$pdf->SetFont('Times', 'I', 'U');
$pdf->SetTextColor(37, 22, 247);
$pdf->write(8, 'https://om.fossee.in/powersystems/pssp', 'https://om.fossee.in/powersystems/pssp');
$pdf->Ln(0);
$proposal_get_id = 0;
$UniqueString = "";
$tempDir = $path . "/pdf/temp_prcode/";
$query = db_select('om_pssp_qr_code');
$query->fields('om_pssp_qr_code');
$query->condition('proposal_id', $proposal_id);
$result = $query->execute();
$data = $result->fetchObject();
$DBString = $data->qr_code;
$proposal_get_id = $data->proposal_id;
if ($DBString == "" || $DBString == "null") {
$UniqueString = generateRandomString();
$query = "
INSERT INTO om_pssp_qr_code
(proposal_id,qr_code)
VALUES
(:proposal_id,:qr_code)
";
$args = array(
":proposal_id" => $proposal_id,
":qr_code" => $UniqueString
);
$result = db_query($query, $args, array(
'return' => Database::RETURN_INSERT_ID
));
} //$DBString == "" || $DBString == "null"
else {
$UniqueString = $DBString;
}
$codeContents = "https://om.fossee.in/powersystems/pssp/certificates/verify/" . $UniqueString;
$fileName = 'generated_qrcode.png';
$pngAbsoluteFilePath = $tempDir . $fileName;
$urlRelativeFilePath = $path . "/pdf/temp_prcode/" . $fileName;
QRcode::png($codeContents, $pngAbsoluteFilePath);
$pdf->SetY(80);
$pdf->SetX(300);
$pdf->Ln(30);
$pdf->Image($pngAbsoluteFilePath, $pdf->GetX()+70 , $pdf->GetY() + 55, 24,24, 0);
$pdf->SetFont('Times', '', 14);
$pdf->Ln(48);
$pdf->SetX(95);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(200, 8, $UniqueString, '0', '1' , 'L');
$pdf->SetY(150);
$pdf->SetX(800);
$pdf->SetFont('Arial', 'I', 8);
$pdf->SetTextColor(0, 0, 0);
$filename = str_replace(' ', '-', $data3->contributor_name) . '-OpenModelica-PSSP-Certificate.pdf';
$file = $path . '/pdf/temp_certificate/' . $proposal_id . '_' . $filename;
$pdf->Output($file, 'F');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush();
$fp = fopen($file, "r");
while (!feof($fp)) {
echo fread($fp, 65536);
flush();
} //!feof($fp)
fclose($fp);
unlink($file);
//drupal_goto('flowsheeting-project/certificate');
return;
}
function generateRandomString($length = 5)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
} //$i = 0; $i < $length; $i++
return $randomString;
}
|