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 /* Call common method to give check the hook */
115 $message= plugin::check();
117 if(empty($this->Release)){
118 $message[]=_("Please enter a value for 'release'.");
119 }
121 if(empty($this->Url)){
122 $message[] = _("Please specify a valid value for 'url'.");
123 }
125 return ($message);
126 }
129 /* Save to LDAP */
130 function save()
131 {
132 $tmp = array();
133 $tmp['ParentServer'] = $this->ParentServer;
134 $tmp['Url'] = $this->Url;
135 $tmp['Release'] = $this->Release;
136 $tmp['Sections'] = $this->Sections;
137 return($tmp);
138 }
140 function getParentServers()
141 {
142 $ret = array();
143 $ldap = $this->config->get_ldap_link();
144 $ldap->cd($this->config->current['BASE']);
145 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
146 while($attr = $ldap->fetch()){
147 $ret[$attr['cn'][0]]= $attr['cn'][0];
148 }
150 $ret = array_merge($ret,$this->GetHookElements());
152 $ret['none']= " ";
153 asort($ret);
154 return($ret);
155 }
157 /* this funtions calls a defined hook
158 and parses all additional serverdata
159 */
160 function GetHookElements()
161 {
162 $ret = array();
163 $cmd= search_config($this->config->data['TABS'], "servrepository", "EXTERNAL_HOOK");
164 if(!empty($cmd)){
165 $res = shell_exec($cmd);
166 $res2 = trim($res);
167 if((!$res)){
168 print_red(sprintf(_("Can't execute specified EXTERNAL_HOOK '%s' please check your gosa.conf."),$cmd));
169 }elseif(empty($res2)){
170 print_red(sprintf(_("The specified EXTERNAL_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
171 }else{
172 $tmp = split("\n",$res);
173 foreach($tmp as $hook){
174 /* skip empty */
175 if(empty($hook)) continue;
177 if(preg_match("/\:/",$hook)){
178 $hookinfo = split(":",$hook);
179 $ret[$hookinfo[1]] = $hookinfo[0];
180 }else{
181 $ret[$hook] = $hook;
182 }
183 }
184 }
185 }
186 return($ret);
187 }
189 }
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>