Code

52bf62b9af0a7a3401f439665cf34279600f8fd9
[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     print_a($_POST);
78     /* Fill templating stuff */
79     $smarty= get_smarty();
80     $display= "";
82     /* Smarty vars*/
83     $smarty->assign("infoimage",    get_template_path('images/info.png'));
84     $smarty->assign("search_image", get_template_path('images/search.png'));
85     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
86     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
87     $smarty->assign("alphabet",     generate_alphabet());
88     $smarty->assign("apply",        apply_filter());
89     $smarty->assign("regex",        $this->regex);
92     /* Do we need to flip is_account state? */
93     if (isset($_POST['modify_state'])){
94       $this->is_account= !$this->is_account;
95     }
97     /* Show tab dialog headers */
98     if ($this->is_account){
99       $display= $this->show_header(_("Remove FAI repository extension."),
100           _("This server has FAI repository features enabled. You can disable them by clicking below."));
101     } else {
102       $display= $this->show_header(_("Add FAI repository extension."),
103           _("This server has FAI repository features disabled. You can enable them by clicking below."));
104       return ($display);
105     }
106  
107     /*
108       ADD / EDIT Repository
109       Dialog Handling
110     */
111     
112     $once = false;
113     foreach($_POST as $name => $value){
115       if((preg_match("/^delete_/",$name))&&(!$once)){
117         $value = preg_replace("/delete_/","",$name);
118         $value = preg_replace("/_.$/","",$value);
120         if(isset($this->repositories[$value])){
121           $once = true;
122           unset($this->repositories[$value]);
123         }
124       }
126       if((preg_match("/^edit_/",$name))&&(!$once)){
127         $value = preg_replace("/edit_/","",$name);
128         $value = preg_replace("/_.$/","",$value);
129         if(isset($this->repositories[$value])){
130           $once = true;
131           $obj = $this->repositories[$value];
132       
133           /* to be able to detect if this was renamed */
134           $obj['initialy_was'] = $obj['Release'];
135           $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
136           $this->dialog->acl = $this->acl;
137         }
138       }
139     }
141     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
142       $obj = $this->repositories[$_GET['id']];
143       $obj['initialy_was'] = $obj['Release'];
144       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
145       $this->dialog->acl = $this->acl;
146     }
147  
148     if(isset($_POST['AddRepository'])){
149       $this->dialog = new servRepositorySetup($this->config,$this->dn);
150       $this->dialog->acl = $this->acl;
151     }
153     if(isset($_POST['repository_setup_save'])){
154       $this->dialog->save_object();
155       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
156         print_red(_("This name is already in use."));
157       }else
159       if(count($this->dialog->check())!=0){
160         foreach($this->dialog->check() as $msg){
161           print_red($msg);
162         }
163       }else{
164         $obj = $this->dialog->save();
165         $this->dialog = NULL;
166         $this->is_dialog= false;
167         $this->repositories[$obj['Release']]=$obj;        
168       }
169     }
171     if(isset($_POST['repository_setup_cancel'])){
172       $this->dialog=NULL;
173       $this->is_dialog = false;
174     }
175    
176     if($this->dialog != NULL){
177       $this->dialog->save_object();
178       $this->is_dialog = true;
179       return($this->dialog->execute());
180     }
182     /*
183       Repository setup dialog handling /END
184     */
186     $divlist = new divList("repositories");
187     $divlist->SetEntriesPerPage(12);
188     $divlist->setHeight(400);
190     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
191                               array("string"=>_("Sections")),
192                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:69px;'")
193                        )     );
195     $link   = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
196     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
197     $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
198   
199     foreach($this->repositories as $name => $reps){
201       $str = " ";
203       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
204     
206       foreach($reps['Sections'] as $sec){
207         $str.=$sec." ";  
208       }    
209   
210       $divlist->AddEntry(array(
211                               array("string"=>preg_replace("/%s/",$name,$link),"attach"=>"style='width:80px;'"),
212                               array("string"=>sprintf($link,$name,_("Sections")." :".$str)),
213                               array("string"=>preg_replace("/%s/",$name,$edit.$delete),"attach"=>"style='border-right:0px;width:50px;text-align:right;'")
214                               ));
215       }
216     }
217  
218     $smarty -> assign("Repositories",$divlist->DrawList());
220     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
221     return($display);
222   }
224   function remove_from_parent()
225   {
226     plugin::remove_from_parent();    
227     $ldap= $this->config->get_ldap_link();
228     $ldap->cd ($this->config->current['BASE']);
229     
230     $ldap->cat($this->dn);
231     
232     if($ldap->count()){
233       $ldap->cd($this->dn);
234       $ldap->modify($this->attrs);      
235       $this->handle_post_events("modify");
236     }
237   }
240   /* Save data to object */
241   function save_object()
242   {
243     plugin::save_object();
244     if(isset($_POST['regex'])){
245       $this->regex = $_POST['regex'];
246     }
247   }
250   /* Check supplied data */
251   function check()
252   {
253     $message= array();
254     return ($message);
255   }
258   /* Save to LDAP */
259   function save()
260   {
261     plugin::save();
263     $arr = array();
264     foreach($this->repositories as $servername => $conf){
265       $str = "";
266       foreach($conf['Sections'] as $sec){
267         $str.=$sec.",";
268       }
269       $str=preg_replace("/,$/","",$str);
270         
271       if($conf['ParentServer']=="none"){
272         $conf['ParentServer'] ="";
273       }    
274     
275       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
276     }
277     $this->attrs['FAIrepository'] = $arr;
279     $ldap= $this->config->get_ldap_link();
280     $ldap->cd ($this->config->current['BASE']);
281     
282     $ldap->cat($this->dn);
283     
284     if($ldap->count()){
285       $ldap->cd($this->dn);
286       $ldap->modify($this->attrs);      
287       $this->handle_post_events("modify");
288     }else{
289       $ldap->cd ($this->config->current['BASE']);
290       $ldap->create_missing_trees($this->dn);
291       $ldap->cd($this->dn);
292       $ldap->add($this->attrs);
293       $this->handle_post_events("add");
294     }
295   }
299 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
300 ?>