Code

Removed br
[gosa.git] / plugins / admin / systems / class_servRepositorySetup.inc
1 <?php
3 class servRepositorySetup  extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage FAI repositories";
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("Release","ParentServer","Url");
13   var $objectclasses    = array("whatever");
15   /* Attributes */
16   var $Release          ="";
17   var $ParentServer     ="";
18   var $Url              ="";   
19   var $Sections         =array();
20   var $ParentServers    ="";
21   var $initialy_was=false;
23   function servRepositorySetup ($config, $dn= NULL,$data = false)
24   {
25     plugin::plugin ($config, $dn);
26     if($data != false){
27       foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
28         if(isset($data[$atr])){
29           $this->$atr = $data[$atr];
30         }
31       }
32     }
33   }
35   function GetName()
36   {
37     return($this->Release);
38   }
39   
40   function is_new_name()
41   {
42     if(!$this->initialy_was){
43       return(true);
44     }else{
45       if($this->Release != $this->initialy_was){
46         return(true);
47       }
48     }
49     return(false);
50   }
52   
54   function execute()
55   {
56     /* Call parent execute */
57     plugin::execute();
59     /* Fill templating stuff */
60     $smarty= get_smarty();
62     if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
63       $this->Sections[$_POST['SectionName']]=$_POST['SectionName'];
64     }
65     
66     foreach($_POST as $name => $value){
67       if(preg_match("/^delete_/",$name)){
69         $val = preg_replace("/^delete_/","",$name);
70         $val = base64_decode(preg_replace("/_.*$/","",$val));
72         if(isset($this->Sections[$val])){
73           unset($this->Sections[$val]);
74         }
75       }
76     }
78     $divlist = new divSelectBox("servRepositorySetup");
79     $divlist->setHeight("220");
81     $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
83     foreach($this->Sections as $sec){
84       $divlist->AddEntry(array(
85                               array("string"=>$sec),
86                               array("string"=>sprintf($dellink,base64_encode($sec),$sec),"attach"=>"style='border-right:0px;width:20px;'")
87                               ));
88     }
89   
90     $smarty->assign("Sections",$divlist->DrawList());
92     foreach($this->attributes as $attr){
93       $smarty->assign($attr       ,$this->$attr);
94       $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
95     }
96   
97     $tmp = $this->getParentServers();
98     $smarty->assign("ParentServers"   ,$tmp);
99     $smarty->assign("ParentServerKeys",array_flip($tmp));
101     return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
102   }
104   /* Save data to object */
105   function save_object()
106   {
107     plugin::save_object();
108   }
111   /* Check supplied data */
112   function check()
113   {
114     $message= array();
116     if(empty($this->Release)){
117       $message[]=_("Please enter a value for 'release'.");
118     }
120     if(empty($this->Url)){
121       $message[] = _("Please specify a valid value for 'url'.");
122     }
124     return ($message);
125   }
128   /* Save to LDAP */
129   function save()
130   {
131     $tmp = array();
132     $tmp['ParentServer']  = $this->ParentServer;
133     $tmp['Url']           = $this->Url;
134     $tmp['Release']       = $this->Release;
135     $tmp['Sections']      = $this->Sections;
136     return($tmp);
137   }
139   function getParentServers()
140   {
141     $ret = array();
142     $ldap = $this->config->get_ldap_link();
143     $ldap->cd($this->config->current['BASE']);
144     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
145     while($attr = $ldap->fetch()){
146       $ret[$attr['cn'][0]]= $attr['cn'][0];   
147     }
149     $ret = array_merge($ret,$this->GetHookElements());
150     
151     $ret['none']= "&nbsp;";
152     return($ret);
153   }
155   /* this funtions calls a defined hook 
156       and parses all additional serverdata 
157    */
158   function GetHookElements()
159   {
160     $ret = array();
161     $cmd= search_config($this->config->data['TABS'], "servrepository", "EXTERNAL_HOOK");
162     if(!empty($cmd)){
163       $res = shell_exec($cmd);
164       $tmp = split("\n",$res);
165       foreach($tmp as $hook){
167         /* skip empty */
168         if((empty($hook)) || (!preg_match("/:/",$hook))) continue;
170         $hookinfo = split(":",$hook);
171         $ret[$hookinfo[1]] = $hookinfo[0];
172       }
173     }
174     return($ret);
175   }
179 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
180 ?>