Code

REmoved self from server->repository parent url
[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","cn");
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;
22   var $cn               = "";
24   function servRepositorySetup ($config, $dn= NULL,$data = false)
25   {
26     plugin::plugin ($config, $dn);
27     if($data != false){
28       foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
29         if(isset($data[$atr])){
30           $this->$atr = $data[$atr];
31         }
32       }
33     }
34   }
36   function GetName()
37   {
38     return($this->Release);
39   }
40   
41   function is_new_name()
42   {
43     if(!$this->initialy_was){
44       return(true);
45     }else{
46       if($this->Release != $this->initialy_was){
47         return(true);
48       }
49     }
50     return(false);
51   }
53   
55   function execute()
56   {
57     /* Call parent execute */
58     plugin::execute();
60     /* Fill templating stuff */
61     $smarty= get_smarty();
63     if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
64       $this->Sections[$_POST['SectionName']]=$_POST['SectionName'];
65     }
66     
67     foreach($_POST as $name => $value){
68       if(preg_match("/^delete_/",$name)){
70         $val = preg_replace("/^delete_/","",$name);
71         $val = base64_decode(preg_replace("/_.*$/","",$val));
73         if(isset($this->Sections[$val])){
74           unset($this->Sections[$val]);
75         }
76       }
77     }
79     $divlist = new divSelectBox("servRepositorySetup");
80     $divlist->setHeight("220");
82     $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
84     foreach($this->Sections as $sec){
85       $divlist->AddEntry(array(
86                               array("string"=>$sec),
87                               array("string"=>sprintf($dellink,base64_encode($sec),$sec),"attach"=>"style='border-right:0px;width:20px;'")
88                               ));
89     }
90   
91     $smarty->assign("Sections",$divlist->DrawList());
93     foreach($this->attributes as $attr){
94       $smarty->assign($attr       ,$this->$attr);
95       $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
96     }
97   
98     $tmp = $this->getParentServers();
99     $smarty->assign("ParentServers"   ,$tmp);
100     $smarty->assign("ParentServerKeys",array_flip($tmp));
102     return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
103   }
105   /* Save data to object */
106   function save_object()
107   {
108     plugin::save_object();
109   }
112   /* Check supplied data */
113   function check()
114   {
115     /* Call common method to give check the hook */
116     $message= plugin::check();
118     if(empty($this->Release)){
119       $message[]=_("Please enter a value for 'release'.");
120     }
122     if(empty($this->Url)){
123       $message[] = _("Please specify a valid value for 'url'.");
124     }
126     return ($message);
127   }
130   /* Save to LDAP */
131   function save()
132   {
133     $tmp = array();
134     $tmp['ParentServer']  = $this->ParentServer;
135     $tmp['Url']           = $this->Url;
136     $tmp['Release']       = $this->Release;
137     $tmp['Sections']      = $this->Sections;
138     return($tmp);
139   }
141   function getParentServers()
142   {
143     $ret = array();
144     $ldap = $this->config->get_ldap_link();
145     $ldap->cd($this->config->current['BASE']);
146     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
147     while($attr = $ldap->fetch()){
148       if($attr['cn'][0] == $this->cn) continue;
149       $ret[$attr['cn'][0]]= $attr['cn'][0];   
150     }
152     $ret = array_merge($ret,$this->GetHookElements());
153     
154     $ret['none']= "&nbsp;";
155     asort($ret);
156     return($ret);
157   }
159   /* this funtions calls a defined hook 
160       and parses all additional serverdata 
161    */
162   function GetHookElements()
163   {
164     $ret = array();
165     $cmd= search_config($this->config->data['TABS'], "servrepository", "EXTERNAL_HOOK");
166     if(!empty($cmd)){
167       $res = shell_exec($cmd);
168       $res2 = trim($res);
169       if((!$res)){
170         print_red(sprintf(_("Can't execute specified EXTERNAL_HOOK '%s' please check your gosa.conf."),$cmd));
171       }elseif(empty($res2)){
172         print_red(sprintf(_("The specified EXTERNAL_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
173       }else{  
174         $tmp = split("\n",$res);
175         foreach($tmp as $hook){
176           /* skip empty */
177           if(empty($hook)) continue;
179           if(preg_match("/\:/",$hook)){ 
180             $hookinfo = split(":",$hook);
181             $ret[$hookinfo[1]] = $hookinfo[0];
182           }else{
183             $ret[$hook] = $hook;
184           }
185         }
186       }
187     }
188     return($ret);
189   }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>