First commit of tag changes. bug-1444
[cacert-devel.git] / pages / account / 18.php
1 <?php /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 $orgfilterid = array_key_exists('orgfilterid',$_SESSION['_config']) ? intval($_SESSION['_config']['orgfilterid']) : 0;
20 $sorting = array_key_exists('sorting',$_SESSION['_config']) ? intval($_SESSION['_config']['sorting']) : 0;
21 $status = array_key_exists('status',$_SESSION['_config']) ? intval($_SESSION['_config']['status']) : 0;
22 ?>
23 <form method="post" action="account.php">
24 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
25 <tr>
26 <td colspan="9" class="title"><?php echo _("Organisation Client Certificates")?> </td>
27 </tr>
28 <tr>
29 <td colspan="9" class="title"><?php echo _("Filter/Sorting")?></td>
30 </tr>
31 <tr>
32 <td class="DataTD"><?php echo _("Organisation")?></td>
33 <td colspan="8" class="DataTD" >
34 <select name="orgfilterid">
35 <?php echo sprintf('<option value="%d"%s>%s</option>',0, 0 == $orgfilterid ? " selected" : "" ,_("All")) ?>
36 <?php $query = "select `orginfo`.`O`, `orginfo`.`id`
37 from `org`, `orginfo`
38 where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and `orginfo`.`id` = `org`.`orgid`
39 ORDER BY `orginfo`.`O` ";
40 $reso = mysql_query($query);
41 if(mysql_num_rows($reso) >= 1){
42 while($row = mysql_fetch_assoc($reso)){
43 printf('<option value="%d"%s>%s</option>',$row['id'], $row['id'] == $orgfilterid ? " selected" : "" , $row['O']);
44 }
45 }?>
46 </select>
47 </td>
48 </tr>
49 <tr>
50 <td class="DataTD"><?php echo _("Sorting")?></td>
51 <td colspan="8" class="DataTD" >
52 <select name="sorting">
53 <?php echo sprintf('<option value="%d"%s>%s</option>',0, 0 == $sorting ? " selected" : "" ,_("expire date (desc)")) ?>
54 <?php echo sprintf('<option value="%d"%s>%s</option>',1, 1 == $sorting ? " selected" : "" ,_("OU, expire date (desc)")) ?>
55 <?php echo sprintf('<option value="%d"%s>%s</option>',2, 2 == $sorting ? " selected" : "" ,_("Common name, expire date (desc)")) ?>
56 </select>
57 </td>
58 </tr>
59 <tr>
60 <td class="DataTD"><?php echo _("Certificate status")?></td>
61 <td colspan="8" class="DataTD" >
62 <select name="status">
63 <?php echo sprintf('<option value="%d"%s>%s</option>',0, 0 == $status ? " selected" : "" ,_("Current/Active")) ?>
64 <?php echo sprintf('<option value="%d"%s>%s</option>',1, 1 == $status ? " selected" : "" ,_("All")) ?>
65 </select>
66 </td>
67 </tr>
68 <tr>
69 <td class="DataTD" colspan="9"><input type="submit" name="reset" value="<?php echo _("Reset")?>" />&nbsp;&nbsp;&nbsp;&nbsp;
70 <input type="submit" name="filter" value="<?php echo _("Apply filter/sort")?>" /></td>
71 </tr>
72 <tr>
73 <td colspan="9" class="DataTD"> </td>
74 </tr>
75
76 <?php $query = "select UNIX_TIMESTAMP(`oemail`.`created`) as `created`,
77 UNIX_TIMESTAMP(`oemail`.`expire`) - UNIX_TIMESTAMP() as `timeleft`,
78 UNIX_TIMESTAMP(`oemail`.`expire`) as `expired`,
79 `oemail`.`expire` as `expires`, `oemail`.`revoked` as `revoke`,
80 UNIX_TIMESTAMP(`oemail`.`revoked`) as `revoked`,
81 if (`oemail`.`expire`=0,CURRENT_TIMESTAMP(),`oemail`.`modified`) as `modified`,
82 `oemail`.`CN`, `oemail`.`serial`, `oemail`.`id`,
83 `oemail`.`description`, `oemail`.`ou`, `orginfo`.`O`
84 from `orgemailcerts` as `oemail`, `org`, `orginfo`
85 where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
86 `org`.`orgid`=`oemail`.`orgid` and `orginfo`.`id` = `org`.`orgid`";
87 if($orgfilterid>0)
88 {
89 $query .= "AND `org`.`orgid`=$orgfilterid ";
90 }
91
92 if(0==$status)
93 {
94 $query .= "AND `oemail`.`revoked`=0 AND `oemail`.`renewed`=0 ";
95 $query .= "HAVING `timeleft` > 0 AND `revoked`=0 or `expires` = 0 ";
96 }
97 switch ($sorting){
98 case 0:
99 $query .= "ORDER BY `orginfo`.`O`, `modified` desc";
100 break;
101 case 1:
102 $query .= "ORDER BY `orginfo`.`O`, `oemail`.`ou`, `modified` desc";
103 break;
104 case 2:
105 $query .= "ORDER BY `orginfo`.`O`, `oemail`.`CN`, `modified` desc";
106 break;
107 }
108 $res = mysql_query($query);
109 if(mysql_num_rows($res) <= 0)
110 {
111 ?>
112
113 <tr>
114 <td colspan="9" class="DataTD"><?php echo _("No client certificates are currently listed.")?></td>
115 </tr>
116 <?php } else {
117 $orgname='';
118 while($row = mysql_fetch_assoc($res))
119 {
120 if ($row['O']<>$orgname) {
121 $orgname=$row['O'];?>
122 <tr>
123 <td colspan="9" class="title"></td>
124 </tr>
125 <tr>
126 <td colspan="9" class="title"><?php printf(_("Certificates for %s"), $orgname)?> </td>
127 </tr>
128 <tr>
129 <td class="DataTD"><?php echo _("OU/Department")?></td>
130 <td class="DataTD"><?php echo _("Renew/Revoke/Delete")?></td>
131 <td class="DataTD"><?php echo _("Status")?></td>
132 <td class="DataTD"><?php echo _("CommonName")?></td>
133 <td class="DataTD"><?php echo _("SerialNumber")?></td>
134 <td class="DataTD"><?php echo _("Revoked")?></td>
135 <td class="DataTD"><?php echo _("Expires")?></td>
136 <td colspan="2" class="DataTD"><?php echo _("Comment *")?></td>
137 </tr>
138 <?php }
139 if($row['timeleft'] > 0)
140 $verified = _("Valid");
141 if($row['timeleft'] < 0)
142 $verified = _("Expired");
143 if($row['expired'] == 0)
144 $verified = _("Pending");
145 if($row['revoked'] > 0)
146 $verified = _("Revoked");
147 if($row['revoked'] == 0)
148 $row['revoke'] = _("Not Revoked");
149 ?>
150 <tr>
151 <td class="DataTD"><?php echo $row['ou']?></td>
152 <?php if($verified == _("Valid") || $verified == _("Expired")) { ?>
153 <td class="DataTD"><input type="checkbox" name="revokeid[]" value="<?php echo $row['id']?>"></td>
154 <td class="DataTD"><?php echo $verified?></td>
155 <td class="DataTD"><a href="account.php?id=19&cert=<?php echo $row['id']?>"><?php echo $row['CN']?></a></td>
156 <?php } else if($verified == _("Pending")) { ?>
157 <td class="DataTD"><input type="checkbox" name="delid[]" value="<?php echo $row['id']?>"></td>
158 <td class="DataTD"><?php echo $verified?></td>
159 <td class="DataTD"><?php echo $row['CN']?></td>
160 <?php } else { ?>
161 <td class="DataTD">&nbsp;</td>
162 <td class="DataTD"><?php echo $verified?></td>
163 <td class="DataTD"><a href="account.php?id=19&cert=<?php echo $row['id']?>"><?php echo $row['CN']?></a></td>
164 <?php } ?>
165 <td class="DataTD"><?php echo $row['serial']?></td>
166 <td class="DataTD"><?php echo $row['revoke']?></td>
167 <td class="DataTD"><?php echo $row['expires']?></td>
168 <td class="DataTD"><input name="comment_<?php echo $row['id']?>" type="text" value="<?php echo htmlspecialchars($row['description'])?>" /></td>
169 <td class="DataTD"><input type="checkbox" name="check_comment_<?php echo $row['id']?>" /></td>
170 </tr>
171 <?php } ?>
172 <tr>
173 <td class="DataTD" colspan="9">
174 <?php echo _('* Comment is NOT included in the certificate as it is intended for your personal reference only. To change the comment tick the checkbox and hit "Change Settings".')?>
175 </td>
176 </tr>
177 <tr>
178 <td class="DataTD" colspan="6"><input type="submit" name="renew" value="<?php echo _("Renew")?>">&#160;&#160;&#160;&#160;
179 <input type="submit" name="revoke" value="<?php echo _("Revoke/Delete")?>"></td>
180 <td class="DataTD" colspan="2"><input type="submit" name="change" value="<?php echo _("Change settings")?>"> </td>
181 </tr>
182 <tr>
183 <td class="DataTD" colspan="9"><?php echo _("From here you can delete pending requests, or revoke valid certificates.")?></td>
184 </tr>
185 <?php } ?>
186 </table>
187 <input type="hidden" name="oldid" value="<?php echo $id?>">
188 <input type="hidden" name="csrf" value="<?php echo make_csrf('clicerchange')?>" />
189 </form>