Code

Updated dak keyring. Added remove key functionality. But seems not to work, si is...
[gosa.git] / gosa-plugins / dak / addons / dak / class_dak_keyring.inc
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 {
25   
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     $divlist = new divlist("DAK_keyring");
66     $divlist->SetWidth("100%");
67     $divlist->SetEntriesPerPage(0);
68     $divlist->SetPluginMode(TRUE) ;
70     /* Set default col styles 
71      */
72     $s1 = "style='width:100px;'";
73     $s2 = "style='width:100px;'";
74     $s3 = "style='width:100px;'";
75     $s4 = "";
76     $s5 = "style='width:100px; border-right:0px;'";
78     /* Add header 
79      */
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);
85     $divlist->SetHeader(array($h1,$h2,$h3,$h4,$h5));
87     /* Add entries 
88      */
89     foreach($this->list as $key => $entry){
91       /* Check if all attributes are given
92        */
93       if(!is_array($entry['UID'])){
94         $entry['UID'] = array($entry['UID']);
95       }
96       $key_id = $length = $valid = "";
98       if(isset($entry['ATTRIBUTES']['UID'])){
99         $key_id = $entry['ATTRIBUTES']['UID'];
100       }
101       if(isset($entry['ATTRIBUTES']['LENGTH'])){
102         $length = $entry['ATTRIBUTES']['LENGTH'];
103       }
104       if(isset($entry['ATTRIBUTES']['VALID'])){
105         $valid  = $entry['ATTRIBUTES']['VALID'];
106       }
108       /* Create detail icon 
109        */  
110       $hide = "<input type='image' name='details_".$key."' src='images/forward-arrow.png' alt='+' class='center'>&nbsp;";
111       $down = "<input type='image' name='details_".$key."' src='images/down-arrow.png' alt='+' class='center'>&nbsp;";
113       $actions = "<input type='image' class='center' alt='".msgPool::delButton()."' 
114                     src='images/lists/trash.png' name='remove_key_".$key."'>";
116       /* Add detailed entry 
117           (All UIDs are listed, each in a single column)
118        */
119       if(isset($entry['DETAILS']) && $entry['DETAILS'] == TRUE){
120         $first = TRUE;
121         foreach($entry['UID'] as $val){
123           $f1 = array("string" => "","attach" => $s1);
124           $f2 = array("string" => "","attach" => $s2);
125           $f3 = array("string" => "","attach" => $s3);
126           $f4 = array("string" => htmlentities($val) ,"attach" => $s4);
127           $f5 = array("string" => "","attach" => $s5);
129           if($first){
130             $first = FALSE;
131             $f1 = array("string" => $key_id ,"attach" => $s1);
132             $f2 = array("string" => $length       ,"attach" => $s2);
133             $f3 = array("string" => $valid        ,"attach" => $s3);
134             $f4 = array("string" => $hide.htmlentities($val) ,"attach" => $s4);
135             $f5 = array("string" => $actions      ,"attach" => $s5);
136           }
137           $divlist->AddEntry(array($f1,$f2,$f3,$f4,$f5));
138         }
139       }else{
141         /* Add non detailed entries, just the first uid is displayed.
142          */
143         $f1 = array("string" => $key_id, "attach" => $s1);
144         $f2 = array("string" => $length,       "attach" => $s2);
145         $f3 = array("string" => $valid,        "attach" => $s3);
146         $f4 = array("string" => $down.htmlentities($entry['UID'][0]), "attach" => $s4);
147         $f5 = array("string" => $actions,"attach" => $s5);
148         $divlist->AddEntry(array($f1,$f2,$f3,$f4,$f5));
150       }
151     }
152     return($divlist->DrawList());
153   }
156   public function save_object()
157   {
158     plugin::save_object();
160     /* Save html posts, like the selected repository server 
161      */
162     foreach($this->attributes as $attr){
163       if(isset($_POST[$attr])){
164         $this->$attr = get_post($attr);
165       }
166       }
167   
168     /* Display details icon was clicked
169      */
170     foreach($_POST as $name => $value){
171       if(preg_match("/^remove_key_/",$name)){
172         $id = preg_replace("/^remove_key_([0-9]*)_.*$/","\\1",$name);
173         $this->remove_key($id);
174         break;
175       }
177       if(preg_match("/^details_/",$name)){
178         $id = preg_replace("/^details_([0-9]*)_.*$/","\\1",$name);
179         if(isset($this->list[$id])){
180           if(!isset($this->list[$id]['DETAILS']) || !$this->list[$id]['DETAILS']){
181             $this->list[$id]['DETAILS'] = TRUE;
182           }else{
183             $this->list[$id]['DETAILS'] = FALSE;
184           }
185           break;
186         }
187       }
188     }
190     /* Import new keys 
191      */
192     if(isset($_POST['import_key']) && isset($_FILES['import'])){
193       if($_FILES['import']['size'] != 0){
194         $key = file_get_contents($_FILES['import']['tmp_name']);
195         if($this->import_key($key)){
196           $this->refresh_list();
197         }
198       }
199     }
200   }
202     
203   private function remove_key($key)
204   {
205     if($this->list[$key]){
206       $mac = $this->Servers[$this->selected_Server]['MAC'];
207       return(DAK::remove_key($mac,$this->list[$key]['ATTRIBUTES']['UID']));
208     }
209   }
210   
212   private function import_key($key)
213   {
214     $mac = $this->Servers[$this->selected_Server]['MAC'];
215     return(DAK::import_key($mac,$key));
216   }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>