[gosa.git] / gosa-plugins / goto / 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("FAIrepositoryServer");
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 if(count($this->attrs)){
285 $this->trigger_si_fai_server_reload();
286 }
287 }else{
288 $ldap->cd ($this->config->current['BASE']);
289 $ldap->create_missing_trees($this->dn);
290 $ldap->cd($this->dn);
291 $ldap->add($this->attrs);
292 $this->handle_post_events("add");
293 if(count($this->attrs)){
294 $this->trigger_si_fai_server_reload();
295 }
296 }
298 if($this->initially_was_account){
299 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
300 }else{
301 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
302 }
303 }
306 function getListEntry()
307 {
308 $fields = goService::getListEntry();
309 $fields['Message'] = _("Repository service");
310 $fields['AllowEdit'] = true;
311 $fields['AllowStart'] = $fields['AllowStop'] = $fields['AllowRestart'] = false;
312 return($fields);
313 }
316 function trigger_si_fai_server_reload()
317 {
318 /* Reload GOsa si FAI DB/cache
319 */
320 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
321 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
322 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_server_db'])){
323 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_server_db'];
324 $tmp = new $evt['CLASS_NAME']($this->config);
325 $tmp->set_type(TRIGGERED_EVENT);
326 $tmp->add_targets(array("GOsa"));
327 $o_queue = new gosaSupportDaemon();
328 if(!$o_queue->append($tmp)){
329 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
330 }
331 }
332 }
333 }
336 function remove_from_parent()
337 {
338 goService::remove_from_parent();
339 $this->trigger_si_fai_server_reload();
340 }
342 /* Return plugin informations for acl handling */
343 static function plInfo()
344 {
345 return (array(
346 "plShortName" => _("Repository"),
347 "plDescription" => _("Repository service")." ("._("Services").")",
348 "plSelfModify" => FALSE,
349 "plDepends" => array(),
350 "plPriority" => 84,
351 "plSection" => array("administration"),
352 "plCategory" => array("server"),
354 "plProvidedAcls"=> array(
355 "cn" => _("Name"),
356 "start" => _("Start"),
357 "stop" => _("Stop"),
358 "restart" => _("Restart"),
359 "Release" => _("Releases"),
360 "Section" => _("Sections"),
361 "ParentServer" => _("Parent server"),
362 "Url" => _("Url"))
363 ));
364 }
365 }
367 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
368 ?>