Code

Template update .
[gosa.git] / gosa-plugins / goto / admin / systems / services / repository / class_servRepository.inc
1 <?php
3 class servrepository extends goService
4 {
5   /* attribute list for save action */
6   //  var $ignore_account         = TRUE;
7   var $attributes             = array("FAIrepository");
8   var $objectclasses          = array("FAIrepositoryServer");
9   
10   /* Repositories */
11   var $repositories          = array();
12   var $FAIrepository         = array();
13   var $conflicts             = array("FAIrepositoryServer");
14   var $DisplayName           = "";
15   var $StatusFlag            = "";
16   
17   var $view_logged            = FALSE;
18   var $fai_activated          = FALSE;
20   var $divlist = NULL;
22   function servrepository (&$config, $dn= NULL, $parent= NULL)
23   {
24     plugin::plugin ($config, $dn, $parent);
26     $this->DisplayName = _("Repository service");
28     /* Skip this if fai is deactivated */
29     $tmp= $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
30     if(!empty($tmp)){
31       $this->fai_activated = TRUE;    
32     }else{
33       return;
34     }
36     $this->repositories = array();
37     if(isset($this->attrs['FAIrepository'])){
38       for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
39         $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
40         $tmp2 = array();  
41         $tmp3 = array();   
43         if(isset($tmp[1])){
44           $tmp2['ParentServer'] = $tmp[1];
45           if(empty($tmp[1])){
46             $tmp2['ParentServer'] = "none";
47           }
48         }else{
49           $tmp2['ParentServer'] = "none";
50         }
52         if(isset($tmp[0])){
53           $tmp2['Url']          = $tmp[0];
54         }else{
55           $tmp2['Url']          = "";
56         }
57   
58         if(isset($tmp[2])){
59           $tmp2['Release']      = $tmp[2];
60         }else{
61           $tmp2['Release']      = "";
62         }
64         if(isset($tmp[3])){
65           $tmp3 = split(",",$tmp[3]);
66           foreach($tmp3 as $sec){
67             $tmp2['Sections'][$sec]=$sec;
68           }    
69         }else{
70           $tmp['Section']=array();
71         }
73         $this->repositories[$tmp[2]]=$tmp2;      
74       }
75     }
78     /* Create divlist */
79     $this->divlist = new divListRepository($this->config,$this);
80   }
82   function execute()
83   {
84     /* Call parent execute */
85     plugin::execute();
87     if($this->is_account && !$this->view_logged){
88       $this->view_logged = TRUE;
89       new log("view","server/".get_class($this),$this->dn);
90     }
92     if(!$this->fai_activated){
93       $str = "<h2>"._("You can't use this plugin until FAI is activated.")."</h2>";
94       return $str;
95     }
97     /* Fill templating stuff */
98     $smarty= get_smarty();
99     $smarty->assign("is_createable",$this->acl_is_createable());
100     $display= "";
102     /* Show tab dialog headers */
103     /*
104        ADD / EDIT Repository
105        Dialog Handling
106      */
107     $once = false;
108     if(isset($_POST['servRepository'])){
109       foreach($_POST as $name => $value){
111         if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
112           $once = true;
113           $this->dialog = new servRepositorySetup($this->config,$this->dn);
114           $this->dialog->parent = $this;
115         }
117         if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
118           $once = true;
119           $value = preg_replace("/delete_/","",$name);
120           $value = base64_decode(preg_replace("/_.*$/","",$value));
122           $url = $this->repositories[$value]['Url'];
123           $release = $this->repositories[$value]['Release'];
125           $ldap = $this->config->get_ldap_link();
126           $ldap->cd ($this->config->current['BASE']);
128           $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
130           $found = false;
131           $found_in = " ";
132           while($attrs = $ldap->fetch()){
133             foreach($attrs['FAIclass'] as $class){
134               if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
135                 $found = true;  
136                 $found_in .= $attrs['cn'][0]." ";
137               }
138             }
139           }
141           if($found){
142             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));
143           }else{
144             if(isset($this->repositories[$value])){
145               unset($this->repositories[$value]);
146             }
147           }
148         }
150         if((preg_match("/^edit_/",$name))&&(!$once)){
151           $value = preg_replace("/edit_/","",$name);
152           $value = base64_decode(preg_replace("/_.$/","",$value));
154           if(isset($this->repositories[$value])){
156             $ldap = $this->config->get_ldap_link();
157             $ldap->cd ($this->config->current['BASE']);
159             $url = $this->repositories[$value]['Url'];
160             $release = $this->repositories[$value]['Release'];
162             $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
164             $found = false;
165             $found_in = " ";
166             while($attrs = $ldap->fetch()){
167               foreach($attrs['FAIclass'] as $class){
168                 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
169                   $found = true;
170                   $found_in .= $attrs['cn'][0]." ";
171                 }
172               }
173             }
175             if($found){
176               print_red(sprintf(_("Be careful editing this release, it is still used by these workstations [%s]."),$found_in));
177             } 
179             if(isset($this->repositories[$value])){
180               $once = true;
181               $obj = $this->repositories[$value];
183               /* to be able to detect if this was renamed */
184               $obj['initialy_was'] = $obj['Release'];
185               $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
186               $this->dialog->parent = $this;
187             }
188           }
189         }
190       }
191     }
192     if((isset($_GET['act']))&&($_GET['act']=="open_repository")&&(isset($_GET['id']))){
193       $obj = $this->repositories[base64_decode($_GET['id'])];
194       $obj['initialy_was'] = $obj['Release'];
195       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
196       $this->dialog->parent = $this;
197     }
199     if(isset($_POST['repository_setup_save']) && is_object($this->dialog)){
200       $this->dialog->save_object();
201       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
202         print_red(_("This name is already in use."));
203       }else
205       if(count($this->dialog->check())!=0){
206         foreach($this->dialog->check() as $msg){
207           print_red($msg);
208         }
209       }else{
210         $obj = $this->dialog->save();
211         if($this->dialog->is_new_name()){
212           $oldname = $this->dialog->initialy_was;
213           $this->repositories[$obj['Release']]=$obj;        
214           unset($this->repositories[$oldname]);
215         }else{ 
216           $this->repositories[$obj['Release']]=$obj;        
217         }
218         $this->dialog = FALSE;
219         $this->is_dialog= false;
220       }
221     }
223     if(isset($_POST['repository_setup_cancel'])){
224       $this->dialog=FALSE;
225       $this->is_dialog = false;
226     }
227    
228     if(is_object($this->dialog)){
229       $this->dialog->save_object();
230       $this->is_dialog = true;
231       return($this->dialog->execute());
232     }
234     /*
235       Repository setup dialog handling /END
236     */
239     $link   = "<a href='?plug=".$_GET['plug']."&amp;act=open_repository&amp;id=%s'>%s</a>";
240     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
241    
242     /* Hide delete icon, if delete is not allowed */ 
243     if($this->acl_is_removeable()){
244       $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
245     }else{
246       $delete = "<img src='images/empty.png' alt='&nbsp;'>";
247     }
249     $this->divlist->execute(); 
250     $this->divlist->setEntries($this->repositories);
251     $smarty->assign("Repositories",$this->divlist->Draw());
252     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE,dirname(__FILE__)));
253     return($display);
254   }
257   /* Save data to object */
258   function save_object()
259   {
260     plugin::save_object();
261     if(is_object($this->divlist)){
262       $this->divlist->save_object();
263     }
264   }
267   /* Check supplied data */
268   function check()
269   {
270     /* Call common method to give check the hook */
271     $message= plugin::check();
272     return ($message);
273   }
276   /* Save to LDAP */
277   function save()
278   {
279     if(!$this->fai_activated) return;
281     plugin::save();
283     $arr = array();
284     foreach($this->repositories as $servername => $conf){
285       $str = "";
286       foreach($conf['Sections'] as $sec){
287         $str.=$sec.",";
288       }
289       $str=preg_replace("/,$/","",$str);
290         
291       if($conf['ParentServer']=="none"){
292         $conf['ParentServer'] ="";
293       }    
294     
295       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
296     }
297     $this->attrs['FAIrepository'] = $arr;
299     $ldap= $this->config->get_ldap_link();
300     $ldap->cd ($this->config->current['BASE']);
301     
302     $ldap->cat($this->dn, array('dn'));
303     
304     if($ldap->count()){
305       $ldap->cd($this->dn);
306       $this->cleanup();
307       $ldap->modify ($this->attrs);       
309       $this->handle_post_events("modify");
310     }else{
311       $ldap->cd ($this->config->current['BASE']);
312       $ldap->create_missing_trees($this->dn);
313       $ldap->cd($this->dn);
314       $ldap->add($this->attrs);
315       $this->handle_post_events("add");
316     }
318     if($this->initially_was_account){
319       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
320     }else{
321       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
322     }
323   }
326   function getListEntry()
327   {
328     $fields = goService::getListEntry();
329     $fields['Message']    = _("Repository service");
330     $fields['AllowEdit']  = true;
331     $fields['AllowStart'] = $fields['AllowStop'] = $fields['AllowRestart'] = false;
332     return($fields);
333   }
335   /* Return plugin informations for acl handling */
336   static function plInfo()
337   {
338     return (array(
339           "plShortName"   => _("Repository"),
340           "plDescription" => _("Repository service")." ("._("Services").")",
341           "plSelfModify"  => FALSE,
342           "plDepends"     => array(),
343           "plPriority"    => 84,
344           "plSection"     => array("administration"),
345           "plCategory"    => array("server"),
347           "plProvidedAcls"=> array(
348               "cn"            => _("Name"),
349               "start"         => _("Start"),
350               "stop"          => _("Stop"),
351               "restart"       => _("Restart"),
352               "Release"       => _("Releases"),
353               "Section"       => _("Sections"),
354               "ParentServer"  => _("Parent server"),
355               "Url"           => _("Url"))
356             ));
357   }
360 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
361 ?>