bug 1010: Implement new gui for org client cert
[cacert-devel.git] / pages / account / 18.php
1 <? /*
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=0;
20 if(array_key_exists('orgfilterid',$_REQUEST)) $orgfilterid=intval($_REQUEST['orgfilterid']);
21 $sorting=0;
22 if(array_key_exists('sorting',$_REQUEST)) $sorting=intval($_REQUEST['sorting']);
23 $status=0;
24 if(array_key_exists('status',$_REQUEST)) $status=intval($_REQUEST['status']);
25 ?>
26 <form method="post" action="account.php">
27 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
28 <tr>
29 <td colspan="9" class="title"><?=_("Organisation Client Certificates")?> </td>
30 </tr>
31 <tr>
32 <td colspan="9" class="title"><?=_("Filter/Sorting")?></td>
33 </tr>
34 <tr>
35 <td class="DataTD"><?=_("Organisation")?></td>
36 <td colspan="8" class="DataTD" >
37 <select name="orgfilterid">
38 <option value="0"<?
39 if (0==$orgfilterid) {
40 ?> selected <?
41 }
42 ?>><?=_("All")?></option> <?
43 $query = "select `orginfo`.`O`, `orginfo`.`id`
44 from `org`, `orginfo`
45 where `org`.`memid`='".intval($_SESSION['profile']['id'])."' `orginfo`.`id` = `org`.`orgid`
46 ORDER BY `oemail`.`modified` desc";
47 $reso = mysql_query($query);
48 if(mysql_num_rows($reso) >= 1){
49 while($row = mysql_fetch_assoc($res)){
50 ?><option <?if ($row['id']==$orgfilterid) {
51 ?> selected <?
52 }?> value="><?=$row['id']?>"><?=$row['O']?></option>
53 <?}
54 }?>
55 </select>
56 </td>
57 </tr>
58 <tr>
59 <td class="DataTD"><?=_("Sorting")?></td>
60 <td colspan="8" class="DataTD" >
61 <select name="sorting">
62 <option <?if (0==$sorting) {
63 ?> selected <?
64 }?>value="0"><?=_("expire date (desc)")?></option>
65 <option <?if (1==$sorting) {
66 ?> selected <?
67 }?>value="1"><?=_("OU, expire date (desc)")?></option>
68 <option <?if (2==$sorting) {
69 ?> selected <?
70 }?>value="2"><?=_("Common name, expire date (desc)")?></option>
71 </select>
72 </td>
73 </tr>
74 <tr>
75 <td class="DataTD"><?=_("Certificate status")?></td>
76 <td colspan="8" class="DataTD" >
77 <select name="status">
78 <option <?if (0==$status) {
79 ?> selected <?
80 }?>value="0"><?=_("Actual")?></option>
81 <option <?if (0==$status) {
82 ?> selected <?
83 }?>value="1"><?=_("All")?></option>
84 </select>
85 </td>
86 </tr>
87 <tr>
88 <td class="DataTD" colspan="9"><input type="submit" name="reset" value="<?=_("Reset")?>" />&#160;&#160;&#160;&#160;
89 <input type="submit" name="filter" value="<?=_("Apply filter/sort")?>" /></td>
90 </tr>
91 <td colspan="9" class="DataTD"> </td>
92 </tr>
93
94 //rebuild query
95 <?
96 $query = "select UNIX_TIMESTAMP(`oemail`.`created`) as `created`,
97 UNIX_TIMESTAMP(`oemail`.`expire`) - UNIX_TIMESTAMP() as `timeleft`,
98 UNIX_TIMESTAMP(`oemail`.`expire`) as `expired`,
99 `oemail`.`expire` as `expires`, `oemail`.`revoked` as `revoke`,
100 UNIX_TIMESTAMP(`oemail`.`revoked`) as `revoked`,
101 `oemail`.`CN`, `oemail`.`serial`, `oemail`.`id`,
102 `oemail`.`description`, `oemail`.`ou`, `orginfo`.`O`
103 from `orgemailcerts` as `oemail`, `org`, `orginfo`
104 where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
105 `org`.`orgid`=`oemail`.`orgid` and `orginfo`.`id` = `org`.`orgid`";
106 if($orgfilterid>0)
107 {
108 $query .= "AND `org`.`orgid`=$orgfilterid ";
109 }
110
111 if(1==$status)
112 {
113 $query .= "AND `oemail`.`revoked`=0 AND `oemail`.`renewed`=0 ";
114 $query .= "HAVING `timeleft` > 0 AND `revoked`=0 ";
115 }
116 switch ($sorting){
117 case 0:
118 $query .= "ORDER BY `oemail`.`expire` desc";
119 break;
120 case 1:
121 $query .= "ORDER BY `oemail`.`ou`, `oemail`.`expire` desc";
122 break;
123 case 2:
124 $query .= "ORDER BY `oemail`.`CN`, `oemail`.`expire` desc";
125 break;
126 }
127 $res = mysql_query($query);
128 if(mysql_num_rows($res) <= 0)
129 {
130 ?>
131
132 <tr>
133 <td colspan="9" class="DataTD"><?=_("No client certificates are currently listed.")?></td>
134 </tr>
135 <? } else {
136 $orgname='';
137 while($row = mysql_fetch_assoc($res))
138 {
139 if ($row['O']<>$orgname) {
140 $orgname=$row['O'];?>
141 <tr>
142 <td colspan="9" class="title"></td>
143 </tr>
144 <tr>
145 <td colspan="9" class="title"><?=_("Certificates for ").$orgname?> </td>
146 </tr>
147 <tr>
148 <td class="DataTD"><?=_("OU/Department")?></td>
149 <td class="DataTD"><?=_("Renew/Revoke/Delete")?></td>
150 <td class="DataTD"><?=_("Status")?></td>
151 <td class="DataTD"><?=_("CommonName")?></td>
152 <td class="DataTD"><?=_("SerialNumber")?></td>
153 <td class="DataTD"><?=_("Revoked")?></td>
154 <td class="DataTD"><?=_("Expires")?></td>
155 <td colspan="2" class="DataTD"><?=_("Comment *")?></td>
156 </tr>
157 <?
158 }
159 if($row['timeleft'] > 0)
160 $verified = _("Valid");
161 if($row['timeleft'] < 0)
162 $verified = _("Expired");
163 if($row['expired'] == 0)
164 $verified = _("Pending");
165 if($row['revoked'] > 0)
166 $verified = _("Revoked");
167 if($row['revoked'] == 0)
168 $row['revoke'] = _("Not Revoked");
169 ?>
170 <tr>
171 <td class="DataTD"><?=$row['ou']?></td>
172 <? if($verified == _("Valid") || $verified == _("Expired")) { ?>
173 <td class="DataTD"><input type="checkbox" name="revokeid[]" value="<?=$row['id']?>"></td>
174 <td class="DataTD"><?=$verified?></td>
175 <td class="DataTD"><a href="account.php?id=19&cert=<?=$row['id']?>"><?=$row['CN']?></a></td>
176 <? } else if($verified == _("Pending")) { ?>
177 <td class="DataTD"><input type="checkbox" name="delid[]" value="<?=$row['id']?>"></td>
178 <td class="DataTD"><?=$verified?></td>
179 <td class="DataTD"><?=$row['CN']?></td>
180 <? } else { ?>
181 <td class="DataTD">&nbsp;</td>
182 <td class="DataTD"><?=$verified?></td>
183 <td class="DataTD"><a href="account.php?id=19&cert=<?=$row['id']?>"><?=$row['CN']?></a></td>
184 <? } ?>
185 <td class="DataTD"><?=$row['serial']?></td>
186 <td class="DataTD"><?=$row['revoke']?></td>
187 <td class="DataTD"><?=$row['expires']?></td>
188 <td class="DataTD"><input name="comment_<?=$row['id']?>" type="text" value="<?=htmlspecialchars($row['description'])?>" /></td>
189 <td class="DataTD"><input type="checkbox" name="check_comment_<?=$row['id']?>" /></td>
190 </tr>
191 <? } ?>
192 <tr>
193 <td class="DataTD" colspan="9">
194 <?=_('* 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".')?>
195 </td>
196 </tr>
197 <tr>
198 <td class="DataTD" colspan="6"><input type="submit" name="renew" value="<?=_("Renew")?>">&#160;&#160;&#160;&#160;
199 <input type="submit" name="revoke" value="<?=_("Revoke/Delete")?>"></td>
200 <td class="DataTD" colspan="2"><input type="submit" name="change" value="<?=_("Change settings")?>"> </td>
201 </tr>
202 <tr>
203 <td class="DataTD" colspan="9"><?=_("From here you can delete pending requests, or revoke valid certificates.")?></td>
204 </tr>
205 <? } ?>
206 </table>
207 <input type="hidden" name="oldid" value="<?=$id?>">
208 <input type="hidden" name="csrf" value="<?=make_csrf('clicerchange')?>" />
209 </form>