Code

Removed state buttons
[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();
26   var $conflicts             = array("FAIrepositoryServer");
27   var $DisplayName           = "";
28   var $StatusFlag            = "";
31   function servrepository ($config, $dn= NULL)
32   {
33     plugin::plugin ($config, $dn);
35     $this->DisplayName = _("Repository service");
37     $this->repositories = array();
38     if(isset($this->attrs['FAIrepository'])){
39       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
40         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
41         $tmp2 = array();  
42         $tmp3 = array();   
44         if(isset($tmp[1])){
45           $tmp2['ParentServer'] = $tmp[1];
46           if(empty($tmp[1])){
47             $tmp2['ParentServer'] = "none";
48           }
49         }else{
50           $tmp2['ParentServer'] = "none";
51         }
53         if(isset($tmp[0])){
54           $tmp2['Url']          = $tmp[0];
55         }else{
56           $tmp2['Url']          = "";
57         }
58   
59         if(isset($tmp[2])){
60           $tmp2['Release']      = $tmp[2];
61         }else{
62           $tmp2['Release']      = "";
63         }
65         if(isset($tmp[3])){
66           $tmp3 = split(",",$tmp[3]);
67           foreach($tmp3 as $sec){
68             $tmp2['Sections'][$sec]=$sec;
69           }    
70         }else{
71           $tmp['Section']=array();
72         }
74         $this->repositories[$tmp[2]]=$tmp2;      
75       }
76     }
77   }
79   function execute()
80   {
81     /* Call parent execute */
82     plugin::execute();
84     /* Fill templating stuff */
85     $smarty= get_smarty();
86     $display= "";
88     /* Smarty vars*/
89     $smarty->assign("infoimage",    get_template_path('images/info.png'));
90     $smarty->assign("search_image", get_template_path('images/search.png'));
91     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
92     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
93     $smarty->assign("alphabet",     generate_alphabet());
94     $smarty->assign("apply",        apply_filter());
95     $smarty->assign("regex",        $this->regex);
97     /* Show tab dialog headers */
98     /*
99        ADD / EDIT Repository
100        Dialog Handling
101      */
102     $once = false;
103     if(isset($_POST['servRepository'])){
104       foreach($_POST as $name => $value){
106         if(preg_match("/AddRepository/",$name)){
107           $once = true;
108           $this->dialog = new servRepositorySetup($this->config,$this->dn);
109           $this->dialog->acl = $this->acl;
110         }
112         if((preg_match("/^delete_/",$name))&&(!$once)){
113           $once = true;
114           $value = preg_replace("/delete_/","",$name);
115           $value = base64_decode(preg_replace("/_.*$/","",$value));
117           $url = $this->repositories[$value]['Url'];
118           $release = $this->repositories[$value]['Release'];
120           $ldap = $this->config->get_ldap_link();
121           $ldap->cd ($this->config->current['BASE']);
123           $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
125           $found = false;
126           $found_in = " ";
127           while($attrs = $ldap->fetch()){
128             foreach($attrs['FAIclass'] as $class){
129               if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
130                 $found = true;  
131                 $found_in .= $attrs['cn'][0]." ";
132               }
133             }
134           }
136           if($found){
137             print_red(sprintf(_("You can't delete this release, it is still used by these workstations [%s]. Please solve this dependencies first, to keep data base consistency."),$found_in));
138           }else{
139             if(isset($this->repositories[$value])){
140               unset($this->repositories[$value]);
141             }
142           }
143         }
145         if((preg_match("/^edit_/",$name))&&(!$once)){
146           $value = preg_replace("/edit_/","",$name);
147           $value = base64_decode(preg_replace("/_.$/","",$value));
149           if(isset($this->repositories[$value])){
151             $ldap = $this->config->get_ldap_link();
152             $ldap->cd ($this->config->current['BASE']);
154             $url = $this->repositories[$value]['Url'];
155             $release = $this->repositories[$value]['Release'];
157             $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
159             $found = false;
160             $found_in = " ";
161             while($attrs = $ldap->fetch()){
162               foreach($attrs['FAIclass'] as $class){
163                 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
164                   $found = true;
165                   $found_in .= $attrs['cn'][0]." ";
166                 }
167               }
168             }
170             if($found){
171               print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
172             } 
174             if(isset($this->repositories[$value])){
175               $once = true;
176               $obj = $this->repositories[$value];
178               /* to be able to detect if this was renamed */
179               $obj['initialy_was'] = $obj['Release'];
180               $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
181               $this->dialog->acl = $this->acl;
182             }
183           }
184         }
185       }
186     }
187     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
188       $obj = $this->repositories[base64_decode($_GET['id'])];
189       $obj['initialy_was'] = $obj['Release'];
190       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
191       $this->dialog->acl = $this->acl;
192     }
194     /*
195     if(isset($_POST['AddRepository'])){
196       $this->dialog = new servRepositorySetup($this->config,$this->dn);
197       $this->dialog->acl = $this->acl;
198     }
199     */
201     if(isset($_POST['repository_setup_save'])){
202       $this->dialog->save_object();
203       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
204         print_red(_("This name is already in use."));
205       }else
207       if(count($this->dialog->check())!=0){
208         foreach($this->dialog->check() as $msg){
209           print_red($msg);
210         }
211       }else{
212         $obj = $this->dialog->save();
213         if($this->dialog->is_new_name()){
214           $oldname = $this->dialog->initialy_was;
215           $this->repositories[$obj['Release']]=$obj;        
216           unset($this->repositories[$oldname]);
217         }else{ 
218           $this->repositories[$obj['Release']]=$obj;        
219         }
220         $this->dialog = NULL;
221         $this->is_dialog= false;
222       }
223     }
225     if(isset($_POST['repository_setup_cancel'])){
226       $this->dialog=NULL;
227       $this->is_dialog = false;
228     }
229    
230     if($this->dialog != NULL){
231       $this->dialog->save_object();
232       $this->is_dialog = true;
233       return($this->dialog->execute());
234     }
236     /*
237       Repository setup dialog handling /END
238     */
240     $divlist = new divList("repositories");
241     $divlist->SetEntriesPerPage(0);
242     $divlist->setHeight(400);
244     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
245                               array("string"=>_("Sections")),
246                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:55px;'")
247                        )     );
249     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
250     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
251     $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
252   
253     foreach($this->repositories as $name => $reps){
255       $str = " ";
257       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
258     
260       foreach($reps['Sections'] as $sec){
261         $str.=$sec." ";  
262       }    
263   
264       $divlist->AddEntry(array(
265                               array("string"=>sprintf($link,base64_encode($name),$name),"attach"=>"style='width:80px;'"),
266                               array("string"=>sprintf($link,base64_encode($name),_("Sections")." :".$str)),
267                               array("string"=>preg_replace("/%s/",base64_encode($name),$edit.$delete),"attach"=>"style='border-right:0px;width:55px;text-align:right;'")
268                               ));
269       }
270     }
271  
272     $smarty -> assign("Repositories",$divlist->DrawList());
274     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
275     return($display);
276   }
278   function remove_from_parent()
279   {
280     plugin::remove_from_parent();    
281     $ldap= $this->config->get_ldap_link();
282     $ldap->cd ($this->config->current['BASE']);
283     
284     $ldap->cat($this->dn, array('dn'));
285     
286     if($ldap->count()){
287       $ldap->cd($this->dn);
288       $this->cleanup();
289       $ldap->modify ($this->attrs); 
291       $this->handle_post_events("modify");
292     }
293   }
296   /* Save data to object */
297   function save_object()
298   {
299     plugin::save_object();
300     if(isset($_POST['regex'])){
301       $this->regex = $_POST['regex'];
302     }
303   }
306   /* Check supplied data */
307   function check()
308   {
309     /* Call common method to give check the hook */
310     $message= plugin::check();
311         
312     return ($message);
313   }
316   /* Save to LDAP */
317   function save()
318   {
319     plugin::save();
321     $arr = array();
322     foreach($this->repositories as $servername => $conf){
323       $str = "";
324       foreach($conf['Sections'] as $sec){
325         $str.=$sec.",";
326       }
327       $str=preg_replace("/,$/","",$str);
328         
329       if($conf['ParentServer']=="none"){
330         $conf['ParentServer'] ="";
331       }    
332     
333       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
334     }
335     $this->attrs['FAIrepository'] = $arr;
337     $ldap= $this->config->get_ldap_link();
338     $ldap->cd ($this->config->current['BASE']);
339     
340     $ldap->cat($this->dn, array('dn'));
341     
342     if($ldap->count()){
343       $ldap->cd($this->dn);
344       $this->cleanup();
345       $ldap->modify ($this->attrs);       
347       $this->handle_post_events("modify");
348     }else{
349       $ldap->cd ($this->config->current['BASE']);
350       $ldap->create_missing_trees($this->dn);
351       $ldap->cd($this->dn);
352       $ldap->add($this->attrs);
353       $this->handle_post_events("add");
354     }
355   }
357   /* Get updates for status flag */
358   function updateStatusState()
359   {
360     if(empty($this->StatusFlag)) return;
362     $attrs = array();
363     $flag = $this->StatusFlag;
364     $ldap = $this->config->get_ldap_link();
365     $ldap->cd($this->cn);
366     $ldap->cat($this->dn,array($flag));
367     if($ldap->count()){
368       $attrs = $ldap->fetch();
369     }
370     if(isset($attrs[$flag][0])){
371       $this->$flag = $attrs[$flag][0];
372     }
373   }
376   function getListEntry()
377   {
378     $this->updateStatusState();
379     $flag = $this->StatusFlag;
380     if(empty($flag)){
381       $fields['Status']      = "";
382     }else{
383       $fields['Status']      = $this->$flag;
384     }
385     $fields['Message']    = _("Repository service");
386     $fields['AllowStart'] = true;
387     $fields['AllowStop']  = true;
388     $fields['AllowRestart'] = true;
389     $fields['AllowRemove']= true;
390     $fields['AllowEdit']  = true;
391     return($fields);
392   }
395   /* Directly save new status flag */
396   function setStatus($value)
397   {
398     if($value == "none") return;
399     if(!$this->initially_was_account) return;
400     $ldap = $this->config->get_ldap_link();
401     $ldap->cd($this->dn);
402     $ldap->cat($this->dn,array("objectClass"));
403     if($ldap->count()){
405       $tmp = $ldap->fetch();
406       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
407         $attrs['objectClass'][] = $tmp['objectClass'][$i];
408       }
409       $flag = $this->StatusFlag;
410       $attrs[$flag] = $value;
411       $this->$flag = $value;
412       $ldap->modify($attrs);
413       show_ldap_error($ldap->get_error());
414       $this->action_hook();
415     }
416   }
420 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
421 ?>