-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_letter.php
118 lines (111 loc) · 4.7 KB
/
print_letter.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
<?php include 'db_connect.php' ?>
<div class="col-md-12">
<div class="card card-outline card-success">
<div class="card-header">
<b>Letter Progress</b>
</div>
<div class="card-body p-0">
<div class="table-responsive" id="printable">
<table class="table m-0 table-bordered">
<colgroup>
<col width="7%">
<col width="31%">
<col width="31%">
<col width="10%">
<col width="21%">
</colgroup>
<thead>
<th>#</th>
<th>Letter </th>
<th>Progress</th>
<th>Status</th>
<th>Print</th>
</thead>
<tbody>
<?php
$i = 1;
$stat = array("Teacher","Hod","Lipik","Principal", "Done");
$where = "";
if($_SESSION['login_user_type_id'] == 2){
$where = " WHERE letter_creator_user_id = '{$_SESSION['login_user_id']}'";
}
elseif($_SESSION['login_user_type_id'] == 3){
$where = " WHERE letter_creator_user_id = '{$_SESSION['login_user_id']}' OR letter_creator_user_id IN ( SELECT user_id FROM gpd_teacher WHERE department_id = ( SELECT department_id FROM gpd_hod WHERE user_id = '{$_SESSION['login_user_id']}' ))";
}
elseif($_SESSION['login_user_type_id'] == 4){
$where = " WHERE letter_status = '3'";
}
elseif($_SESSION['login_user_type_id'] == 5){
$where = " WHERE letter_status = '4'";
}
$qry = $conn->query("SELECT * FROM gpd_letters $where order by letter_creator_user_id asc");
while($row = $qry->fetch_assoc()):
$status = $row['letter_status'];
$prog = ($status == 4) ? 100 : ($status * 20); // Assuming Done is 100%
?>
<tr>
<td>
<?php echo $i++ ?>
</td>
<td>
<a>
<?php echo ucwords($row['letter_title']) ?>
</a>
<br>
<small>
Due: <?php echo date("Y-m-d",strtotime($row['letter_created_date'])) ?>
</small>
</td>
<td class="project_progress">
<div class="progress progress-sm">
<div class="progress-bar bg-green" role="progressbar" aria-valuenow="57" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $prog ?>%">
</div>
</div>
<small>
<?php echo $prog ?>% Complete
</small>
</td>
<td class="project-state">
<?php
echo "<span class='badge badge-success'>{$stat[$row['letter_status'] -1 ]}</span>";
?>
</td>
<td>
<div class="card-tools">
<button class="btn print-btn mysersonal btn-flat btn-sm bg-gradient-success btn-success" data-id="<?php echo $row['letter_id']?>" id="<?php echo "data".$i ?>"><i class="fa fa-print"></i> Print</button>
</div>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('.print-btn').click(function() {
var letter_id = $(this).data('id');
$.ajax({
url: 'ajax.php?action=print_letter',
method: 'POST',
data: { letter_id: letter_id },
success: function(response) {
console.log("printing it");
var newWindow = window.open("","","width=900,height=600")
newWindow.document.open();
newWindow.document.write(response);
newWindow.document.close();
newWindow.onload = function() {
newWindow.print();
};
setTimeout(function(){
newWindow.close()
end_load()
},1000)
},
});
});
});
</script>