Code

Updated partition handling
[gosa.git] / gosa-plugins / goto / admin / systems / ppd / class_printerPPDSelectionDialog.inc
1 <?php
3 class printerPPDSelectionDialog extends plugin
4 {
5     /* attribute list for save action */
6     var $ignore_account       = FALSE;
7     var $attributes           = array();
8     var $objectclasses        = array("whatever");
10     var $list                 =array();
11     var $header               =array();
12     var $current_del_id       = "";
13     var $Vendor               = "";
14     var $selectedPPD = "";
16     function printerPPDSelectionDialog (&$config, $dn= NULL,$list=false,$headers=false,$ppd=false)
17     {
18         plugin::plugin ($config, $dn);
19         $this->list       = $list;
20         $this->header     = $headers;
21         $this->depselect  = $this->config->current['BASE'];
23         // Prepare lists
24         $this->ppdList = new sortableListing();
25         $this->ppdList->setDeleteable(true);
26         $this->ppdList->setInstantDelete(false);
27         $this->ppdList->setEditable(true);
28         $this->ppdList->setWidth("100%");
29         $this->ppdList->setColspecs(array('*','20px'));
30         $this->ppdList->setHeight("200px");
31         $this->ppdList->setHeader(array(_("PPD")));
32         $this->ppdList->setDefaultSortColumn(0);
33     }
35     function isSelected(){
36         return(!empty($this->selectedPPD));
37     }
39     function execute()
40     {
41         /* Call parent execute */
42         plugin::execute();
44         /* Fill templating stuff */
45         $smarty= get_smarty();
46         $display= "";
49         $this->ppdList->save_object();
50         $action = $this->ppdList->getAction();
51         if($action['action'] == "delete"){
52             $data = $this->ppdList->getData($action['targets'][0]);
53             if($data['TYPE'] == 'PPD'){
54                 $found = "";
55                 foreach($this->list[$this->Vendor] as $key => $ppd){
56                     if($ppd['link'] == $data['ID']){
57                         $found = $key;
58                         break;
59                     }
60                 }
61                 if(!empty($found)){
62                     $this->current_del_id = $ppd['link'];
63                     $smarty->assign("warning", sprintf(msgPool::deleteInfo($found)));
64                     return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE, dirname(__FILE__))));
65                 }else{
66                     msg_dialog::display(_("PPD error"), 
67                             msgPool::fileDoesNotExist($this->current_del_id), ERROR_DIALOG);
68                 }
69             }
70         }
72         /* Deletion confirmed */
73         if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
74             $is_ok = false;
75             if(is_writeable($this->current_del_id)){
76                 $is_ok = @unlink($this->current_del_id);
78                 /* Update ppd list */
79                 if($is_ok){
80                     foreach($this->list as $vendor => $ppds){
81                         foreach($ppds as $ppd => $data){
82                             if($data['link'] == $this->current_del_id){
83                                 unset($this->list[$vendor][$ppd]);
84                             }
85                         }
86                     }
87                 }
88             }
89             if(!$is_ok){
90                 msg_dialog::display(_("PPD error"), 
91                         msgPool::cannotDeleteFile($this->current_del_id), ERROR_DIALOG);
92             }
93         }
94         // Build up ppd 
95         $list = array();
96         foreach($this->list as $cat => $ppds){
97             foreach($ppds as $ppd){
98                 $name = $ppd['ppd']['name'];
99                 $list[$ppd['link']] = $ppd;
100             }
101         }
104         $data = $lData = array();
105         if(empty($this->Vendor)){
106             
107             $this->ppdList->setDeleteable(false);
108             foreach($this->header as $key => $entry){
109                 $data[$key] = array('TYPE' => 'VENDOR' , 'ID' => $key);
110                 $lData[$key] = array('data'=>array($key));
111             } 
113         }else{
114             $data[] = array('TYPE' => 'VENDOR' , 'ID' => '..');
115             $lData[] = array('data'=>array(".. ["._("back")."]"));
117             $this->ppdList->setDeleteable(true);
118             foreach($list as $key => $ppd){
119                 $name = $ppd['ppd']['name'];
120                 if(preg_match("/^".$this->Vendor."/", $name)){
121                     $data[$key] = array('TYPE' => 'PPD' , 'ID' => $key);
122                     $lData[$key] = array('data'=>array($name));
123                 }
124             }
125         }
127         $this->ppdList->setAcl('rwcdm');
128         $this->ppdList->setListData($data,$lData);
129         $this->ppdList->update();
131         $smarty->assign("List", $this->ppdList->render());
133         $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
134         return($display);
135     }
137     function save_object()
138     {
139         $this->ppdList->save_object();
140         $action = $this->ppdList->getAction();
141         if($action['action'] == "edit"){
142             $data = $this->ppdList->getData($action['targets'][0]);
143             if($data['TYPE'] == "VENDOR"){
144                 $this->Vendor = $data['ID'];
145                 if($this->Vendor == "..") $this->Vendor = "";
146             }
147             if($data['TYPE'] == "PPD"){
148                 $this->selectedPPD = $data['ID'];
149             }
150         } 
152     } 
154     function check(){
155     }
157     /* Save to LDAP */
158     function save()
159     {
160         return $this->selectedPPD;
161     }
163 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
164 ?>