Code

Fixed headpage
[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     }
97     $smarty->assign("ParentServers"   ,$this->getParentServers());
98     $smarty->assign("ParentServerKeys",array_flip($this->getParentServers()));
100     return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
101   }
103   /* Save data to object */
104   function save_object()
105   {
106     plugin::save_object();
107   }
110   /* Check supplied data */
111   function check()
112   {
113     $message= array();
115     if(empty($this->Release)){
116       $message[]=_("Please enter a value for 'release'.");
117     }
119     if(empty($this->Url)){
120       $message[] = _("Please specify a valid value for 'url'.");
121     }
123     return ($message);
124   }
127   /* Save to LDAP */
128   function save()
129   {
130     $tmp = array();
131     $tmp['ParentServer']  = $this->ParentServer;
132     $tmp['Url']           = $this->Url;
133     $tmp['Release']       = $this->Release;
134     $tmp['Sections']      = $this->Sections;
135     return($tmp);
136   }
138   function getParentServers()
139   {
140     $ret = array();
141     $ldap = $this->config->get_ldap_link();
142     $ldap->cd($this->config->current['BASE']);
143     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
144     while($attr = $ldap->fetch()){
145       $ret[$attr['cn'][0]]= $attr['cn'][0];   
146     }
147     $ret['none']= "&nbsp;";
148     return($ret);
149   }
153 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
154 ?>