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 = "";
23 var $parent = "";
25 function servRepositorySetup (&$config, $dn= NULL,$data = false)
26 {
27 plugin::plugin ($config, $dn);
28 if($data != false){
29 foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
30 if(isset($data[$atr])){
31 $this->$atr = $data[$atr];
32 }
33 }
34 }
35 }
37 function GetName()
38 {
39 return($this->Release);
40 }
42 function is_new_name()
43 {
44 if(!$this->initialy_was){
45 return(true);
46 }else{
47 if($this->Release != $this->initialy_was){
48 return(true);
49 }
50 }
51 return(false);
52 }
56 function execute()
57 {
58 /* Call parent execute */
59 plugin::execute();
61 /* Fill templating stuff */
62 $smarty= get_smarty();
64 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
66 /* Replace multiple spaces with a single, and cut of white spaces (trim)*/
67 $val = preg_replace("/\ \ * /" , " ", trim($_POST['SectionName']));
69 /* check if there are more than one entry given ( "section1 section2 )*/
70 if(preg_match("/ /",$val)){
72 /* Generate list of new section names */
73 $vals = split(" ",$val);
75 /* Add new entries */
76 foreach($vals as $entry){
77 $entry = trim($entry);
78 $this->Sections[$entry]=$entry;
79 }
80 }else{
81 $this->Sections[$val]=$val;
82 }
83 }
85 foreach($_POST as $name => $value){
86 if(preg_match("/^delete_/",$name)){
88 $val = preg_replace("/^delete_/","",$name);
89 $val = base64_decode(preg_replace("/_.*$/","",$val));
91 if(isset($this->Sections[$val])){
92 unset($this->Sections[$val]);
93 }
94 }
95 }
97 $divlist = new divSelectBox("servRepositorySetup");
98 $divlist->setHeight("220");
100 $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
102 foreach($this->Sections as $sec){
103 $divlist->AddEntry(array(
104 array("string"=>$sec),
105 array("string"=>sprintf($dellink,base64_encode($sec),$sec),"attach"=>"style='border-right:0px;width:20px;'")
106 ));
107 }
109 $smarty->assign("Sections",$divlist->DrawList());
111 /* Get && assign acls */
112 $tmp = $this->parent->plInfo();
113 foreach($tmp['plProvidedAcls'] as $name => $translated){
114 $smarty->assign($name."ACL",$this->parent->getacl($name));
115 }
117 /* Assign values */
118 foreach($this->attributes as $attr){
119 $smarty->assign($attr ,$this->$attr);
120 }
122 $tmp = $this->getParentServers();
123 $smarty->assign("ParentServers" ,$tmp);
124 $smarty->assign("ParentServerKeys",array_flip($tmp));
126 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
127 }
129 /* Save data to object */
130 function save_object()
131 {
132 if(isset($_POST['servRepositorySetup_Posted'])) {
134 foreach($this->attributes as $attr){
135 if(($this->parent->acl_is_writeable($attr)) && (isset($_POST[$attr]))){
136 $this->$attr = $_POST[$attr];
137 }
138 }
139 }
140 }
143 /* Check supplied data */
144 function check()
145 {
146 /* Call common method to give check the hook */
147 $message= plugin::check();
149 if(empty($this->Release)){
150 $message[]=_("Please enter a value for 'release'.");
151 }
153 if(empty($this->Url)){
154 $message[] = _("Please specify a valid value for 'url'.");
155 }
157 return ($message);
158 }
161 /* Save to LDAP */
162 function save()
163 {
164 $tmp = array();
165 $tmp['ParentServer'] = $this->ParentServer;
166 $tmp['Url'] = $this->Url;
167 $tmp['Release'] = $this->Release;
168 $tmp['Sections'] = $this->Sections;
169 return($tmp);
170 }
172 function getParentServers()
173 {
174 $ret = array();
175 $ldap = $this->config->get_ldap_link();
176 $ldap->cd($this->config->current['BASE']);
177 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
178 while($attr = $ldap->fetch()){
179 if($attr['cn'][0] == $this->cn) continue;
180 $ret[$attr['cn'][0]]= $attr['cn'][0];
181 }
183 $ret = array_merge($ret,$this->GetHookElements());
185 $ret['none']= " ";
186 asort($ret);
187 return($ret);
188 }
190 /* this funtions calls a defined hook
191 and parses all additional serverdata
192 */
193 function GetHookElements()
194 {
195 $ret = array();
196 $cmd = $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
197 if(!empty($cmd)){
198 $res = shell_exec($cmd);
199 $res2 = trim($res);
200 if(!$res){
201 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s'. Please check your gosa.conf."),$cmd));
202 }elseif(empty($res2)){
203 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
204 }else{
205 $tmp = split("\n",$res);
206 foreach($tmp as $hook){
207 /* skip empty */
208 if(empty($hook)) continue;
210 if(preg_match("/;/",$hook)){
211 $hookinfo = split(";",$hook);
212 $ret[$hookinfo[0]] = $hookinfo[0];
213 }else{
214 $ret[$hook] = $hook;
215 }
216 }
217 }
218 }
219 return($ret);
220 }
222 }
224 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
225 ?>