1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_gotomasses.inc 10967 2008-05-20 13:18:12Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class dak_keyring extends plugin
24 {
26 private $Servers = array();
27 private $selected_Server = array();
29 private $list = array();
30 public $attributes = array("selected_Server");
32 public function __construct($config)
33 {
34 plugin::plugin($config,NULL);
36 /* Collect release servers and store them
37 */
38 $this->Servers = DAK::get_repositories_by_server($this->config);
39 if(count($this->Servers)){
40 $this->selected_Server = key($this->Servers);
41 }
42 }
44 public function execute()
45 {
46 if(isset($_POST['search'])){
47 $this->refresh_list();
48 }
50 $smarty= get_smarty();
51 $smarty->assign("Servers" , $this->Servers);
52 $smarty->assign("selected_Server" , $this->selected_Server);
53 $smarty->assign("list",$this->CreateList());
54 return($smarty->fetch (get_template_path('dak_keyring.tpl', TRUE, dirname(__FILE__))));
55 }
58 private function refresh_list()
59 {
60 $this->list = DAK::get_queue_entries_for_servers($this->Servers[$this->selected_Server]['MAC']);
61 }
63 private function CreateList()
64 {
65 /* Get ring entries for the currently selected repository
66 */
68 $divlist = new divlist("DAK_keyring");
70 $divlist->SetWidth("100%");
71 $divlist->SetEntriesPerPage(0);
72 $divlist->SetPluginMode(TRUE) ;
74 $s1 = "style='width:100px;'";
75 $s2 = "style='width:100px;'";
76 $s3 = "style='width:100px;'";
77 $s4 = "";
78 $s5 = "style='width:100px; border-right:0px;'";
80 $h1 = array("string" => _("Key ID"), "attach" => $s1);
81 $h2 = array("string" => _("Length"), "attach" => $s2);
82 $h3 = array("string" => _("Validity"), "attach" => $s2);
83 $h4 = array("string" => _("UID"), "attach" => $s4);
84 $h5 = array("string" => _("Action"), "attach" => $s5);
86 $divlist->SetHeader(array($h1,$h2,$h3,$h4,$h5));
88 foreach($this->list as $key => $entry){
90 if(!is_array($entry['UID'])){
91 $entry['UID'] = array($entry['UID']);
92 }
93 $key_id = $length = $valid = "";
95 if(isset($entry['ATTRIBUTES']['UID'])){
96 $key_id = $entry['ATTRIBUTES']['UID'];
97 }
98 if(isset($entry['ATTRIBUTES']['LENGTH'])){
99 $length = $entry['ATTRIBUTES']['LENGTH'];
100 }
101 if(isset($entry['ATTRIBUTES']['VALID'])){
102 $valid = $entry['ATTRIBUTES']['VALID'];
103 }
105 $hide = "<input type='image' name='details_".$key."' src='images/forward-arrow.png' alt='+' class='center'> ";
106 $down = "<input type='image' name='details_".$key."' src='images/down-arrow.png' alt='+' class='center'> ";
108 if(isset($entry['DETAILS']) && $entry['DETAILS'] == TRUE){
109 $first = TRUE;
110 foreach($entry['UID'] as $val){
112 $f1 = array("string" => "","attach" => $s1);
113 $f2 = array("string" => "","attach" => $s2);
114 $f3 = array("string" => "","attach" => $s3);
115 $f4 = array("string" => htmlentities($val) ,"attach" => $s4);
116 $f5 = array("string" => "","attach" => $s5);
118 if($first){
119 $first = FALSE;
120 $f1 = array("string" => $key_id ,"attach" => $s1);
121 $f2 = array("string" => $length ,"attach" => $s2);
122 $f3 = array("string" => $valid ,"attach" => $s3);
123 $f4 = array("string" => $hide.htmlentities($val) ,"attach" => $s4);
124 $f5 = array("string" => "Actions" ,"attach" => $s5);
125 }
126 $divlist->AddEntry(array($f1,$f2,$f3,$f4,$f5));
127 }
128 }else{
129 $f1 = array("string" => $key_id, "attach" => $s1);
130 $f2 = array("string" => $length, "attach" => $s2);
131 $f3 = array("string" => $valid, "attach" => $s3);
132 $f4 = array("string" => $down.htmlentities($entry['UID'][0]), "attach" => $s4);
133 $f5 = array("string" => "Actions","attach" => $s5);
134 $divlist->AddEntry(array($f1,$f2,$f3,$f4,$f5));
136 }
137 }
138 return($divlist->DrawList());
139 }
142 public function save_object()
143 {
144 plugin::save_object();
146 /* Save html posts, like the selected repository server
147 */
148 foreach($this->attributes as $attr){
149 if(isset($_POST[$attr])){
150 $this->$attr = get_post($attr);
151 }
152 }
154 /* Display details icon was clicked
155 */
156 foreach($_POST as $name => $value){
157 if(preg_match("/^details_/",$name)){
158 $id = preg_replace("/^details_([0-9]*)_.*$/","\\1",$name);
159 if(isset($this->list[$id])){
160 if(!isset($this->list[$id]['DETAILS']) || !$this->list[$id]['DETAILS']){
161 $this->list[$id]['DETAILS'] = TRUE;
162 }else{
163 $this->list[$id]['DETAILS'] = FALSE;
164 }
165 break;
166 }
167 }
168 }
170 /* Import new keys
171 */
172 if(isset($_POST['import_key']) && isset($_FILES['import'])){
173 if($_FILES['import']['size'] != 0){
174 $key = file_get_contents($_FILES['import']['tmp_name']);
175 if($this->import_key($key)){
176 $this->refresh_list();
177 }
178 }
179 }
180 }
182 private function import_key($key)
183 {
184 $mac = $this->Servers[$this->selected_Server]['MAC'];
185 return(DAK::import($mac,$key));
186 }
187 }
188 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
189 ?>