349f28ef38ad32772f10583374c7161a6616979e
[gosa.git] / gosa-plugins / fai / admin / systems / services / repository / class_servRepository.inc
1 <?php
3 class servrepository extends goService
4 {
5 /* attribute list for save action */
6 // var $ignore_account = TRUE;
7 var $attributes = array("FAIrepository");
8 var $objectclasses = array("FAIrepositoryServer");
10 /* Repositories */
11 var $repositories = array();
12 var $FAIrepository = array();
13 var $conflicts = array("goKioskService");
14 var $DisplayName = "";
15 var $StatusFlag = "";
17 var $view_logged = FALSE;
18 var $fai_activated = FALSE;
20 var $divlist = NULL;
22 function servrepository (&$config, $dn= NULL, $parent= NULL)
23 {
24 plugin::plugin ($config, $dn,$parent);
26 $this->DisplayName = _("Repository service");
28 /* Skip this if fai is deactivated */
29 $tmp= $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
30 if(!empty($tmp)){
31 $this->fai_activated = TRUE;
32 }else{
33 return;
34 }
36 $this->repositories = array();
37 if(isset($this->attrs['FAIrepository'])){
38 for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
39 $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
40 $tmp2 = array();
41 $tmp3 = array();
43 if(isset($tmp[1])){
44 $tmp2['ParentServer'] = $tmp[1];
45 if(empty($tmp[1])){
46 $tmp2['ParentServer'] = "none";
47 }
48 }else{
49 $tmp2['ParentServer'] = "none";
50 }
52 if(isset($tmp[0])){
53 $tmp2['Url'] = $tmp[0];
54 }else{
55 $tmp2['Url'] = "";
56 }
58 if(isset($tmp[2])){
59 $tmp2['Release'] = $tmp[2];
60 }else{
61 $tmp2['Release'] = "";
62 }
64 if(isset($tmp[3])){
65 $tmp3 = split(",",$tmp[3]);
66 foreach($tmp3 as $sec){
67 $tmp2['Sections'][$sec]=$sec;
68 }
69 }else{
70 $tmp['Section']=array();
71 }
73 $this->repositories[$tmp[2]]=$tmp2;
74 }
75 }
78 /* Create divlist */
79 $this->divlist = new divListRepository($this->config,$this);
80 }
82 function execute()
83 {
84 /* Call parent execute */
85 plugin::execute();
87 if($this->is_account && !$this->view_logged){
88 $this->view_logged = TRUE;
89 new log("view","server/".get_class($this),$this->dn);
90 }
92 if(!$this->fai_activated){
93 $str = "<h2>"._("You can't use this plugin until FAI is activated.")."</h2>";
94 return $str;
95 }
97 /* Fill templating stuff */
98 $smarty= get_smarty();
99 $smarty->assign("is_createable",$this->acl_is_createable());
100 $display= "";
102 /* Show tab dialog headers */
103 /*
104 ADD / EDIT Repository
105 Dialog Handling
106 */
107 $once = false;
108 if(isset($_POST['servRepository'])){
109 foreach($_POST as $name => $value){
111 if(preg_match("/AddRepository/",$name) && $this->acl_is_createable()){
112 $once = true;
113 $this->dialog = new servRepositorySetup($this->config,$this->dn);
114 $this->dialog->parent = $this;
115 }
117 if((preg_match("/^delete_/",$name)) && (!$once) && $this->acl_is_removeable()){
118 $once = true;
119 $value = preg_replace("/delete_/","",$name);
120 $value = base64_decode(preg_replace("/_.*$/","",$value));
122 $url = $this->repositories[$value]['Url'];
123 $release = $this->repositories[$value]['Release'];
125 $ldap = $this->config->get_ldap_link();
126 $ldap->cd ($this->config->current['BASE']);
128 $ldap->search("(&(objectClass=gotoWorkstation)(objectClass=FAIobject)(FAIdebianMirror=".$url."))",array("cn","FAIclass"));
129 if ($ldap->count() != 0){
130 $obj= array();
131 $found= false;
132 while($attrs = $ldap->fetch()){
133 foreach($attrs['FAIclass'] as $class){
134 if(preg_match("/".str_replace("/","\/",$release)."$/i",$class)){
135 $obj[$ldap->getDN()]= $attrs['cn'][0];
136 $found= true;
137 }
138 }
139 }
141 if ($found){
142 msg_dialog::display(_("Error"), msgPool::stillInUse(_("FAI release"), msgPool::buildList($obj)), ERROR_DIALOG);
143 }
144 }else{
145 if(isset($this->repositories[$value])){
146 unset($this->repositories[$value]);
147 }
148 }
149 }
151 if((preg_match("/^edit_/",$name))&&(!$once)){
152 $value = preg_replace("/edit_/","",$name);
153 $value = base64_decode(preg_replace("/_.$/","",$value));
155 if(isset($this->repositories[$value])){
156 $once = true;
157 $obj = $this->repositories[$value];
159 /* to be able to detect if this was renamed */
160 $obj['initialy_was'] = $obj['Release'];
161 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
162 $this->dialog->parent = $this;
163 }
164 }
165 }
166 }
167 if((isset($_GET['act']))&&($_GET['act']=="open_repository")&&(isset($_GET['id']))){
168 $obj = $this->repositories[base64_decode($_GET['id'])];
169 $obj['initialy_was'] = $obj['Release'];
170 $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
171 $this->dialog->parent = $this;
172 }
174 if(isset($_POST['repository_setup_save']) && is_object($this->dialog)){
175 $this->dialog->save_object();
176 if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
177 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
178 }else
180 if(count($this->dialog->check())!=0){
181 foreach($this->dialog->check() as $msg){
182 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
183 }
184 }else{
185 $obj = $this->dialog->save();
186 if($this->dialog->is_new_name()){
187 $oldname = $this->dialog->initialy_was;
188 $this->repositories[$obj['Release']]=$obj;
189 unset($this->repositories[$oldname]);
190 }else{
191 $this->repositories[$obj['Release']]=$obj;
192 }
193 $this->dialog = FALSE;
194 $this->is_dialog= false;
195 }
196 }
198 if(isset($_POST['repository_setup_cancel'])){
199 $this->dialog=FALSE;
200 $this->is_dialog = false;
201 }
203 if(is_object($this->dialog)){
204 $this->dialog->save_object();
205 $this->is_dialog = true;
206 return($this->dialog->execute());
207 }
209 /*
210 Repository setup dialog handling /END
211 */
214 $link = "<a href='?plug=".$_GET['plug']."&act=open_repository&id=%s'>%s</a>";
215 $edit = "<input type='image' value='%s' name='edit_%s' src='images/lists/edit.png'> ";
217 /* Hide delete icon, if delete is not allowed */
218 if($this->acl_is_removeable()){
219 $delete = "<input type='image' value='%s' name='delete_%s' src='images/lists/trash.png'>";
220 }else{
221 $delete = "<img src='images/empty.png' alt=' '>";
222 }
224 $this->divlist->execute();
225 $this->divlist->setEntries($this->repositories);
226 $smarty->assign("Repositories",$this->divlist->Draw());
227 $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE,dirname(__FILE__)));
228 return($display);
229 }
232 /* Save data to object */
233 function save_object()
234 {
235 plugin::save_object();
236 if(is_object($this->divlist)){
237 $this->divlist->save_object();
238 }
239 }
242 /* Check supplied data */
243 function check()
244 {
245 /* Call common method to give check the hook */
246 $message= plugin::check();
247 return ($message);
248 }
251 /* Save to LDAP */
252 function save()
253 {
254 if(!$this->fai_activated) return;
256 plugin::save();
258 $arr = array();
259 foreach($this->repositories as $servername => $conf){
260 $str = "";
261 foreach($conf['Sections'] as $sec){
262 $str.=$sec.",";
263 }
264 $str=preg_replace("/,$/","",$str);
266 if($conf['ParentServer']=="none"){
267 $conf['ParentServer'] ="";
268 }
270 $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
271 }
272 $this->attrs['FAIrepository'] = $arr;
274 $ldap= $this->config->get_ldap_link();
275 $ldap->cd ($this->config->current['BASE']);
277 $ldap->cat($this->dn, array('dn'));
279 if($ldap->count()){
280 $ldap->cd($this->dn);
281 $this->cleanup();
282 $ldap->modify ($this->attrs);
283 $this->handle_post_events("modify");
284 }else{
285 $ldap->cd ($this->config->current['BASE']);
286 $ldap->create_missing_trees($this->dn);
287 $ldap->cd($this->dn);
288 $ldap->add($this->attrs);
289 $this->handle_post_events("add");
290 }
292 # If there were changes, just tell the server to reload information
293 if(count($this->attrs)){
294 $this->trigger_si_fai_server_reload();
295 }
297 if($this->initially_was_account){
298 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
299 }else{
300 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
301 }
302 }
305 function getListEntry()
306 {
307 $fields = goService::getListEntry();
308 $fields['Message'] = _("Repository service");
309 return($fields);
310 }
313 function trigger_si_fai_server_reload()
314 {
315 /* Reload GOsa si FAI DB/cache
316 */
317 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
318 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
319 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_server_db'])){
320 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_server_db'];
321 $tmp = new $evt['CLASS_NAME']($this->config);
322 $tmp->set_type(TRIGGERED_EVENT);
323 $tmp->add_targets(array("GOsa"));
324 $o_queue = new gosaSupportDaemon();
325 if(!$o_queue->append($tmp)){
326 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
327 }
328 }
329 }
330 }
333 function remove_from_parent()
334 {
335 goService::remove_from_parent();
336 $this->trigger_si_fai_server_reload();
337 }
339 /* Return plugin informations for acl handling */
340 static function plInfo()
341 {
342 return (array(
343 "plShortName" => _("Repository"),
344 "plDescription" => _("Repository service")." ("._("Services").")",
345 "plSelfModify" => FALSE,
346 "plDepends" => array(),
347 "plPriority" => 84,
348 "plSection" => array("administration"),
349 "plCategory" => array("server"),
351 "plProvidedAcls"=> array(
352 # "start" => _("Service start"), // Remove this to hide the start button at all.
353 # "stop" => _("Service stop"), // Remove this to hide the stop button at all.
354 # "restart" => _("Service restart"),// Remove this to hide the restart button at all.
356 "cn" => _("Name"),
357 "Release" => _("Releases"),
358 "Section" => _("Sections"),
359 "ParentServer" => _("Parent server"),
360 "Url" => _("Url"))
361 ));
362 }
363 }
365 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
366 ?>