413410c564bb8673cbd07bd998d97aa1c50de2b1
1 <?php
3 class servRepositorySetup extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array("Release","ParentServer","Url","cn");
8 var $objectclasses = array("whatever");
10 /* Attributes */
11 var $Release = "";
12 var $ParentServer = "";
13 var $Url = "";
14 var $Sections = array();
15 var $ParentServers = "";
16 var $initialy_was = false;
17 var $cn = "";
19 function servRepositorySetup ($config, $dn= NULL,$data = false)
20 {
21 plugin::plugin ($config, $dn);
22 if($data != false){
23 foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
24 if(isset($data[$atr])){
25 $this->$atr = $data[$atr];
26 }
27 }
28 }
29 }
31 function GetName()
32 {
33 return($this->Release);
34 }
36 function is_new_name()
37 {
38 if(!$this->initialy_was){
39 return(true);
40 }else{
41 if($this->Release != $this->initialy_was){
42 return(true);
43 }
44 }
45 return(false);
46 }
50 function execute()
51 {
52 /* Call parent execute */
53 plugin::execute();
55 /* Fill templating stuff */
56 $smarty= get_smarty();
58 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
60 /* Replace multiple spaces with a single, and cut of white spaces (trim)*/
61 $val = preg_replace("/\ \ * /" , " ", trim($_POST['SectionName']));
63 /* check if there are more than one entry given ( "section1 section2 )*/
64 if(preg_match("/ /",$val)){
66 /* Generate list of new section names */
67 $vals = split(" ",$val);
69 /* Add new entries */
70 foreach($vals as $entry){
71 $entry = trim($entry);
72 $this->Sections[$entry]=$entry;
73 }
74 }else{
75 $this->Sections[$val]=$val;
76 }
77 }
79 foreach($_POST as $name => $value){
80 if(preg_match("/^delete_/",$name)){
82 $val = preg_replace("/^delete_/","",$name);
83 $val = base64_decode(preg_replace("/_.*$/","",$val));
85 if(isset($this->Sections[$val])){
86 unset($this->Sections[$val]);
87 }
88 }
89 }
91 $divlist = new divSelectBox("servRepositorySetup");
92 $divlist->setHeight("220");
94 $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
96 foreach($this->Sections as $sec){
97 $divlist->AddEntry(array(
98 array("string"=>$sec),
99 array("string"=>sprintf($dellink,base64_encode($sec),$sec),"attach"=>"style='border-right:0px;width:20px;'")
100 ));
101 }
103 $smarty->assign("Sections",$divlist->DrawList());
105 foreach($this->attributes as $attr){
106 $smarty->assign($attr ,$this->$attr);
107 $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
108 }
110 $tmp = $this->getParentServers();
111 $smarty->assign("ParentServers" ,$tmp);
112 $smarty->assign("ParentServerKeys",array_flip($tmp));
114 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
115 }
117 /* Save data to object */
118 function save_object()
119 {
120 plugin::save_object();
121 }
124 /* Check supplied data */
125 function check()
126 {
127 /* Call common method to give check the hook */
128 $message= plugin::check();
130 if(empty($this->Release)){
131 $message[]=_("Please enter a value for 'release'.");
132 }
134 if(empty($this->Url)){
135 $message[] = _("Please specify a valid value for 'url'.");
136 }
138 return ($message);
139 }
142 /* Save to LDAP */
143 function save()
144 {
145 $tmp = array();
146 $tmp['ParentServer'] = $this->ParentServer;
147 $tmp['Url'] = $this->Url;
148 $tmp['Release'] = $this->Release;
149 $tmp['Sections'] = $this->Sections;
150 return($tmp);
151 }
153 function getParentServers()
154 {
155 $ret = array();
156 $ldap = $this->config->get_ldap_link();
157 $ldap->cd($this->config->current['BASE']);
158 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
159 while($attr = $ldap->fetch()){
160 if($attr['cn'][0] == $this->cn) continue;
161 $ret[$attr['cn'][0]]= $attr['cn'][0];
162 }
164 $ret = array_merge($ret,$this->GetHookElements());
166 $ret['none']= " ";
167 asort($ret);
168 return($ret);
169 }
171 /* this funtions calls a defined hook
172 and parses all additional serverdata
173 */
174 function GetHookElements()
175 {
176 $ret = array();
177 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
178 if(!empty($cmd)){
179 $res = shell_exec($cmd);
180 $res2 = trim($res);
181 if(!$res){
182 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s'. Please check your gosa.conf."),$cmd));
183 }elseif(empty($res2)){
184 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
185 }else{
186 $tmp = split("\n",$res);
187 foreach($tmp as $hook){
188 /* skip empty */
189 if(empty($hook)) continue;
191 if(preg_match("/;/",$hook)){
192 $hookinfo = split(";",$hook);
193 $ret[$hookinfo[0]] = $hookinfo[0];
194 }else{
195 $ret[$hook] = $hook;
196 }
197 }
198 }
199 }
200 return($ret);
201 }
203 }
205 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
206 ?>