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