Code

Fixed ppd selection
[gosa.git] / plugins / admin / systems / class_servRepository.inc
1 <?php
3 class servrepository extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   //  var $ignore_account         = TRUE;
12   var $attributes             = array("FAIrepository");
13   var $objectclasses          = array("FAIrepositoryServer");
14   
15   /* Search filter */
16   var $regex                  = "*";
18   /* Configurationdialog for repositories */
19   var $dialog                 = NULL;
21   /* Repositories */
22   var $repositories           = array();
23   var $FAIrepository           = array();
25   function servrepository ($config, $dn= NULL)
26   {
27     plugin::plugin ($config, $dn);
29     $this->repositories = array();
30     if(isset($this->attrs['FAIrepository'])){
31       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
32         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
33         $tmp2 = array();  
34         $tmp3 = array();   
36         if(isset($tmp[1])){
37           $tmp2['ParentServer'] = $tmp[1];
38           if(empty($tmp[1])){
39             $tmp2['ParentServer'] = "none";
40           }
41         }else{
42           $tmp2['ParentServer'] = "none";
43         }
45         if(isset($tmp[0])){
46           $tmp2['Url']          = $tmp[0];
47         }else{
48           $tmp2['Url']          = "";
49         }
50   
51         if(isset($tmp[2])){
52           $tmp2['Release']      = $tmp[2];
53         }else{
54           $tmp2['Release']      = "";
55         }
57         if(isset($tmp[3])){
58           $tmp3 = split(",",$tmp[3]);
59           foreach($tmp3 as $sec){
60             $tmp2['Sections'][$sec]=$sec;
61           }    
62         }else{
63           $tmp['Section']=array();
64         }
66         $this->repositories[$tmp[2]]=$tmp2;      
67       }
68     }
69   }
71   function execute()
72   {
73     /* Call parent execute */
74     plugin::execute();
76     /* Fill templating stuff */
77     $smarty= get_smarty();
78     $display= "";
80     /* Smarty vars*/
81     $smarty->assign("infoimage",    get_template_path('images/info.png'));
82     $smarty->assign("search_image", get_template_path('images/search.png'));
83     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
84     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
85     $smarty->assign("alphabet",     generate_alphabet());
86     $smarty->assign("apply",        apply_filter());
87     $smarty->assign("regex",        $this->regex);
90     /* Do we need to flip is_account state? */
91     if (isset($_POST['modify_state'])){
92       $this->is_account= !$this->is_account;
93     }
95     /* Show tab dialog headers */
96     if ($this->is_account){
97       $display= $this->show_header(_("Remove FAI repository extension."),
98           _("This server has FAI repository features enabled. You can disable them by clicking below."));
99     } else {
100       $display= $this->show_header(_("Add FAI repository extension."),
101           _("This server has FAI repository features disabled. You can enable them by clicking below."));
102       return ($display);
103     }
104  
105     /*
106       ADD / EDIT Repository
107       Dialog Handling
108     */
109     
110     $once = false;
111     foreach($_POST as $name => $value){
113       if((preg_match("/^delete_/",$name))&&(!$once)){
115         $value = preg_replace("/delete_/","",$name);
116         $value = preg_replace("/_.$/","",$value);
118         if(isset($this->repositories[$value])){
119           $once = true;
120           unset($this->repositories[$value]);
121         }
122       }
124       if((preg_match("/^edit_/",$name))&&(!$once)){
125         $value = preg_replace("/edit_/","",$name);
126         $value = preg_replace("/_.$/","",$value);
127         if(isset($this->repositories[$value])){
128           $once = true;
129           $obj = $this->repositories[$value];
130       
131           /* to be able to detect if this was renamed */
132           $obj['initialy_was'] = $obj['Release'];
133           $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
134           $this->dialog->acl = $this->acl;
135         }
136       }
137     }
139     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
140       $obj = $this->repositories[$_GET['id']];
141       $obj['initialy_was'] = $obj['Release'];
142       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
143       $this->dialog->acl = $this->acl;
144     }
145  
146     if(isset($_POST['AddRepository'])){
147       $this->dialog = new servRepositorySetup($this->config,$this->dn);
148       $this->dialog->acl = $this->acl;
149     }
151     if(isset($_POST['repository_setup_save'])){
152       $this->dialog->save_object();
153       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
154         print_red(_("This name is already in use."));
155       }else
157       if(count($this->dialog->check())!=0){
158         foreach($this->dialog->check() as $msg){
159           print_red($msg);
160         }
161       }else{
162         $obj = $this->dialog->save();
163         $this->dialog = NULL;
164         $this->is_dialog= false;
165         $this->repositories[$obj['Release']]=$obj;        
166       }
167     }
169     if(isset($_POST['repository_setup_cancel'])){
170       $this->dialog=NULL;
171       $this->is_dialog = false;
172     }
173    
174     if($this->dialog != NULL){
175       $this->dialog->save_object();
176       $this->is_dialog = true;
177       return($this->dialog->execute());
178     }
180     /*
181       Repository setup dialog handling /END
182     */
184     $divlist = new divList("repositories");
185     $divlist->SetEntriesPerPage(0);
186     $divlist->setHeight(400);
188     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
189                               array("string"=>_("Sections")),
190                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
191                        )     );
193     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
194     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
195     $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
196   
197     foreach($this->repositories as $name => $reps){
199       $str = " ";
201       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
202     
204       foreach($reps['Sections'] as $sec){
205         $str.=$sec." ";  
206       }    
207   
208       $divlist->AddEntry(array(
209                               array("string"=>preg_replace("/%s/",$name,$link),"attach"=>"style='width:80px;'"),
210                               array("string"=>sprintf($link,$name,_("Sections")." :".$str)),
211                               array("string"=>preg_replace("/%s/",$name,$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
212                               ));
213       }
214     }
215  
216     $smarty -> assign("Repositories",$divlist->DrawList());
218     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
219     return($display);
220   }
222   function remove_from_parent()
223   {
224     plugin::remove_from_parent();    
225     $ldap= $this->config->get_ldap_link();
226     $ldap->cd ($this->config->current['BASE']);
227     
228     $ldap->cat($this->dn);
229     
230     if($ldap->count()){
231       $ldap->cd($this->dn);
232       $ldap->modify($this->attrs);      
233       $this->handle_post_events("modify");
234     }
235   }
238   /* Save data to object */
239   function save_object()
240   {
241     plugin::save_object();
242     if(isset($_POST['regex'])){
243       $this->regex = $_POST['regex'];
244     }
245   }
248   /* Check supplied data */
249   function check()
250   {
251     $message= array();
252     return ($message);
253   }
256   /* Save to LDAP */
257   function save()
258   {
259     plugin::save();
261     $arr = array();
262     foreach($this->repositories as $servername => $conf){
263       $str = "";
264       foreach($conf['Sections'] as $sec){
265         $str.=$sec.",";
266       }
267       $str=preg_replace("/,$/","",$str);
268         
269       if($conf['ParentServer']=="none"){
270         $conf['ParentServer'] ="";
271       }    
272     
273       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
274     }
275     $this->attrs['FAIrepository'] = $arr;
277     $ldap= $this->config->get_ldap_link();
278     $ldap->cd ($this->config->current['BASE']);
279     
280     $ldap->cat($this->dn);
281     
282     if($ldap->count()){
283       $ldap->cd($this->dn);
284       $ldap->modify($this->attrs);      
285       $this->handle_post_events("modify");
286     }else{
287       $ldap->cd ($this->config->current['BASE']);
288       $ldap->create_missing_trees($this->dn);
289       $ldap->cd($this->dn);
290       $ldap->add($this->attrs);
291       $this->handle_post_events("add");
292     }
293   }
297 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
298 ?>