Code

fixed texts
[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         $tmp2['ParentServer'] = $tmp[1];
37         if(empty($tmp[1])){
38           $tmp2['ParentServer'] = "none";
39         }
40         $tmp2['Url']          = $tmp[0];
41         $tmp2['Release']      = $tmp[2];
43         $tmp3 = split(",",$tmp[3]);
45         foreach($tmp3 as $sec){
46           $tmp2['Sections'][$sec]=$sec;
47         }    
48         $this->repositories[$tmp[2]]=$tmp2;      
49       }
50     }
51   }
53   function execute()
54   {
55     /* Call parent execute */
56     plugin::execute();
58     /* Fill templating stuff */
59     $smarty= get_smarty();
60     $display= "";
62     /* Smarty vars*/
63     $smarty->assign("infoimage",    get_template_path('images/info.png'));
64     $smarty->assign("search_image", get_template_path('images/search.png'));
65     $smarty->assign("launchimage",  get_template_path('images/launch.png'));
66     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
67     $smarty->assign("alphabet",     generate_alphabet());
68     $smarty->assign("apply",        apply_filter());
69     $smarty->assign("regex",        $this->regex);
72     /* Do we need to flip is_account state? */
73     if (isset($_POST['modify_state'])){
74       $this->is_account= !$this->is_account;
75     }
77     /* Show tab dialog headers */
78     if ($this->is_account){
79       $display= $this->show_header(_("Remove FAI repository extension."),
80           _("This server has FAI repository features enabled. You can disable them by clicking below."));
81     } else {
82       $display= $this->show_header(_("Add FAI repository extension."),
83           _("This server has FAI repository features disabled. You can enable them by clicking below."));
84       return ($display);
85     }
86  
87     /*
88       ADD / EDIT Repository
89       Dialog Handling
90     */
91     
92     $once = false;
93     foreach($_POST as $name => $value){
94       if((preg_match("/^delete_/",$name))&&(!$once)){
95         if(isset($this->repositories[$value])){
96           $once = true;
97           unset($this->repositories[$value]);
98         }
99       }
101       if((preg_match("/^edit_/",$name))&&(!$once)){
102         if(isset($this->repositories[$value])){
103           $once = true;
104           $obj = $this->repositories[$value];
105       
106           /* to be able to detect if this was renamed */
107           $obj['initialy_was'] = $obj['Release'];
108           $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
109           $this->dialog->acl = $this->acl;
110         }
111       }
112     }
114     if((isset($_GET['act']))&&($_GET['act']=="open")&&(isset($_GET['id']))){
115       $obj = $this->repositories[$_GET['id']];
116       $obj['initialy_was'] = $obj['Release'];
117       $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
118       $this->dialog->acl = $this->acl;
119     }
120  
121     if(isset($_POST['AddRepository'])){
122       $this->dialog = new servRepositorySetup($this->config,$this->dn);
123       $this->dialog->acl = $this->acl;
124     }
126     if(isset($_POST['repository_setup_save'])){
127       $this->dialog->save_object();
128       if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
129         print_red(_("This name is already in use."));
130       }else
132       if(count($this->dialog->check())!=0){
133         foreach($this->dialog->check() as $msg){
134           print_red($msg);
135         }
136       }else{
137         $obj = $this->dialog->save();
138         $this->dialog = NULL;
139         $this->is_dialog= false;
140         $this->repositories[$obj['Release']]=$obj;        
141       }
142     }
144     if(isset($_POST['repository_setup_cancel'])){
145       $this->dialog=NULL;
146       $this->is_dialog = false;
147     }
148    
149     if($this->dialog != NULL){
150       $this->dialog->save_object();
151       $this->is_dialog = true;
152       return($this->dialog->execute());
153     }
155     /*
156       Repository setup dialog handling /END
157     */
159     $divlist = new divList("repositories");
160     $divlist->SetEntriesPerPage(12);
161     $divlist->setHeight(400);
163     $divlist->setHeader(array(array("string"=>_("Release"),"attach"=>"style='width:80px;'"),
164                               array("string"=>_("Sections")),
165                               array("string"=>_("Options"),"attach"=>"style='border-right:0px;width:69px;'")
166                        )     );
168     $link   = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
169     $edit   = "<input type='image' value='%s' name='edit_%s'   src='images/edit.png'>&nbsp;";
170     $delete = "<input type='image' value='%s' name='delete_%s' src='images/edittrash.png'>";
171    
172     foreach($this->repositories as $name => $reps){
174       $str = " ";
176       if(preg_match("/".str_replace("*",".*",$this->regex)."/",$reps['Release'])){
177     
179       foreach($reps['Sections'] as $sec){
180         $str.=$sec." ";  
181       }    
182   
183       $divlist->AddEntry(array(
184                               array("string"=>preg_replace("/%s/",$name,$link),"attach"=>"style='width:80px;'"),
185                               array("string"=>sprintf($link,$name,_("Sections")." :".$str)),
186                               array("string"=>preg_replace("/%s/",$name,$edit.$delete),"attach"=>"style='border-right:0px;width:50px;text-align:right;'")
187                               ));
188       }
189     }
190  
191     $smarty -> assign("Repositories",$divlist->DrawList());
193     $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
194     return($display);
195   }
197   function remove_from_parent()
198   {
199     plugin::remove_from_parent();    
200     $ldap= $this->config->get_ldap_link();
201     $ldap->cd ($this->config->current['BASE']);
202     
203     $ldap->cat($this->dn);
204     
205     if($ldap->count()){
206       $ldap->cd($this->dn);
207       $ldap->modify($this->attrs);      
208       $this->handle_post_events("modify");
209     }
210   }
213   /* Save data to object */
214   function save_object()
215   {
216     plugin::save_object();
217     if(isset($_POST['regex'])){
218       $this->regex = $_POST['regex'];
219     }
220   }
223   /* Check supplied data */
224   function check()
225   {
226     $message= array();
227     return ($message);
228   }
231   /* Save to LDAP */
232   function save()
233   {
234     plugin::save();
236     $arr = array();
237     foreach($this->repositories as $servername => $conf){
238       $str = "";
239       foreach($conf['Sections'] as $sec){
240         $str.=$sec.",";
241       }
242       $str=preg_replace("/,$/","",$str);
243         
244       if($conf['ParentServer']=="none"){
245         $conf['ParentServer'] ="";
246       }    
247     
248       $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
249     }
250     $this->attrs['FAIrepository'] = $arr;
252     $ldap= $this->config->get_ldap_link();
253     $ldap->cd ($this->config->current['BASE']);
254     
255     $ldap->cat($this->dn);
256     
257     if($ldap->count()){
258       $ldap->cd($this->dn);
259       $ldap->modify($this->attrs);      
260       $this->handle_post_events("modify");
261     }else{
262       $ldap->cd ($this->config->current['BASE']);
263       $ldap->create_missing_trees($this->dn);
264       $ldap->cd($this->dn);
265       $ldap->add($this->attrs);
266       $this->handle_post_events("add");
267     }
268   }
272 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
273 ?>