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