538fed150ed2b7748e4c5ce1542a7ff6cbcc2d6d
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 }
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 }
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 }
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 }
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 $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());
151 $ret['none']= " ";
152 asort($ret);
153 return($ret);
154 }
156 /* this funtions calls a defined hook
157 and parses all additional serverdata
158 */
159 function GetHookElements()
160 {
161 $ret = array();
162 $cmd= search_config($this->config->data['TABS'], "servrepository", "EXTERNAL_HOOK");
163 if(!empty($cmd)){
164 $res = shell_exec($cmd);
165 if(!$res){
166 print_red(sprintf(_("Can't execute specified '%s' please check your gosa.conf."),$cmd));
167 }else{
168 $tmp = split("\n",$res);
169 foreach($tmp as $hook){
170 /* skip empty */
171 if((empty($hook)) || (!preg_match("/:/",$hook))) continue;
173 $hookinfo = split(":",$hook);
174 $ret[$hookinfo[1]] = $hookinfo[0];
175 }
176 }
177 }
178 return($ret);
179 }
181 }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>