[gosa.git] / gosa-plugins / fai / 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(preg_match("/w/",$this->parent->getacl("Section"))){
60 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
62 /* Replace multiple spaces with a single, and cut of white spaces (trim)*/
63 $val = preg_replace("/\ \ * /" , " ", trim($_POST['SectionName']));
65 /* check if there are more than one entry given ( "section1 section2 )*/
66 if(preg_match("/ /",$val)){
68 /* Generate list of new section names */
69 $vals = split(" ",$val);
71 /* Add new entries */
72 foreach($vals as $entry){
73 $entry = trim($entry);
74 if(!empty($entry)){
75 $this->Sections[$entry]=$entry;
76 }
77 }
78 }else{
79 $this->Sections[$val]=$val;
80 }
81 }
83 foreach($_POST as $name => $value){
84 if(preg_match("/^delete_/",$name)){
86 $val = preg_replace("/^delete_/","",$name);
87 $val = base64_decode(preg_replace("/_.*$/","",$val));
89 if(isset($this->Sections[$val])){
90 unset($this->Sections[$val]);
91 }
92 }
93 }
94 }
96 $divlist = new divSelectBox("servRepositorySetup");
97 $divlist->setHeight("220");
98 if(preg_match("/w/",$this->parent->getacl("Section"))){
99 $dellink = "<input type='image' src='images/lists/trash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
100 }else{
101 $dellink = "";
102 }
104 foreach($this->Sections as $sec){
105 $divlist->AddEntry(array(
106 array("string"=>$sec),
107 array("string"=>sprintf($dellink,base64_encode($sec),$sec),
108 "attach"=>"style='border-right:0px;width:20px;'")
109 ));
110 }
112 $smarty->assign("Sections",$divlist->DrawList());
114 /* Get && assign acls */
115 $tmp = $this->parent->plInfo();
116 foreach($tmp['plProvidedAcls'] as $name => $translated){
117 $smarty->assign($name."ACL",$this->parent->getacl($name));
118 }
120 /* Assign values */
121 foreach($this->attributes as $attr){
122 $smarty->assign($attr ,$this->$attr);
123 }
125 $tmp = $this->getParentServers();
126 $smarty->assign("ParentServers" ,$tmp);
127 $smarty->assign("ParentServerKeys",array_flip($tmp));
129 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE,dirname(__FILE__))));
130 }
132 /* Save data to object */
133 function save_object()
134 {
135 if(isset($_POST['servRepositorySetup_Posted'])) {
137 foreach($this->attributes as $attr){
138 if(($this->parent->acl_is_writeable($attr)) && (isset($_POST[$attr]))){
139 $this->$attr = $_POST[$attr];
140 }
141 }
142 }
143 }
146 /* Check supplied data */
147 function check()
148 {
149 /* Call common method to give check the hook */
150 $message= plugin::check();
152 if(empty($this->Release)){
153 $message[]= msgPool::required(_("Release"));
154 }
156 if(empty($this->Url)){
157 $message[] = msgPool::required(_("Url"));
158 }
160 return ($message);
161 }
164 /* Save to LDAP */
165 function save()
166 {
167 $tmp = array();
168 $tmp['ParentServer'] = $this->ParentServer;
169 $tmp['Url'] = $this->Url;
170 $tmp['Release'] = $this->Release;
171 $tmp['Sections'] = $this->Sections;
172 return($tmp);
173 }
175 function getParentServers()
176 {
177 $ret = array();
178 $ldap = $this->config->get_ldap_link();
179 $ldap->cd($this->config->current['BASE']);
180 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
181 while($attr = $ldap->fetch()){
182 if($attr['cn'][0] == $this->cn) continue;
183 $ret[$attr['cn'][0]]= $attr['cn'][0];
184 }
186 $ret = array_merge($ret,$this->GetHookElements());
188 $ret['none']= " ";
189 asort($ret);
190 return($ret);
191 }
193 /* this funtions calls a defined hook
194 and parses all additional serverdata
195 */
196 function GetHookElements()
197 {
198 $ret = array();
199 $cmd = $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
200 if(!empty($cmd)){
201 $res = shell_exec($cmd);
202 $res2 = trim($res);
203 if(!$res || empty($res2)){
204 msg_dialog::display(_("Error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd, _("Repository service")), ERROR_DIALOG);
205 }else{
206 $tmp = split("\n",$res);
207 foreach($tmp as $hook){
208 /* skip empty */
209 if(empty($hook)) continue;
211 if(preg_match("/;/",$hook)){
212 $hookinfo = split(";",$hook);
213 $ret[$hookinfo[0]] = $hookinfo[0];
214 }else{
215 $ret[$hook] = $hook;
216 }
217 }
218 }
219 }
220 return($ret);
221 }
223 }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>