Code

Quick review for new service handling
[gosa.git] / plugins / admin / systems / class_goLdapServer.inc
1 <?php
3 class goLdapServer extends plugin{
4         
5   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server has goLdapServer defined.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goLdapServer");
11   var $attributes       = array("goLdapServerStatus","goLdapBase");
12   var $StatusFlag       = "goLdapServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goLdapServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
21   var $goLdapServerStatus  = "";
22   var $goLdapBase          = ""; 
23  
24   function goLdapServer($config,$dn)
25   {
26     plugin::plugin($config,$dn);
27     $this->DisplayName = _("LDAP service");
28   }
31   function execute()
32   { 
33     $smarty = get_smarty(); 
34     foreach($this->attributes as $attr){
35       $smarty->assign($attr,$this->$attr);
36       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
37     }
38     return($smarty->fetch(get_template_path("goLdapServer.tpl",TRUE,dirname(__FILE__))));
39   }
42   function getListEntry()
43   {
44     $flag = $this->StatusFlag;
45     $fields['Status']     = $this->$flag;
46     $fields['Message']    = _("LDAP Service");
47     $fields['AllowStart'] = true;
48     $fields['AllowStop']  = true;
49     $fields['AllowReset'] = true;
50     $fields['AllowRemove']= true;
51     $fields['AllowEdit']  = true;
52     return($fields);
53   }
56   function remove_from_parent()
57   {
58     plugin::remove_from_parent();
59     /* Check if this is a new entry ... add/modify */
60     $ldap = $this->config->get_ldap_link();
61     $ldap->cat($this->dn,array("objectClass"));
62     if($ldap->count()){
63       $ldap->cd($this->dn);
64       $ldap->modify($this->attrs);
65     }else{
66       $ldap->cd($this->dn);
67       $ldap->add($this->attrs);
68     }
69     show_ldap_error($ldap->get_error());
70   }
73   function save()
74   {
75     plugin::save();
76     /* Check if this is a new entry ... add/modify */
77     $ldap = $this->config->get_ldap_link();
78     $ldap->cat($this->dn,array("objectClass"));
79     if($ldap->count()){
80       $ldap->cd($this->dn);
81       $ldap->modify($this->attrs);
82     }else{
83       $ldap->cd($this->dn);
84       $ldap->add($this->attrs);
85     }
86     show_ldap_error($ldap->get_error());
87   }
90   /* Directly save new status flag */
91   function setStatus($value)
92   {
93     if($value == "none") return;
94     $ldap = $this->config->get_ldap_link();
95     $ldap->cd($this->dn);
96     $ldap->cat($this->dn,array("objectClass","goLdapBase"));
97       
98     if($ldap->count()){
99       $attrs =array();
100       foreach(array("goLdapBase") as $req) {
101         if(!isset($attrs[$req])){
102           if(empty($this->$req)){
103             print_red(sprintf(_("The required attribute '%s' is not set."),$req));
104           }else{
105             $attrs[$req] = $this->$req;
106           }
107         }else{
108           $attrs[$req] = $attrs[$req][0];
109         }
110       }
112       $tmp = $ldap->fetch();
113       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
114         $attrs['objectClass'][] = $tmp['objectClass'][$i];
115       }    
116       if(!in_array("goLdapServer",$attrs['objectClass'])){
117         $attrs['objectClass'][] = "goLdapServer";
118       }
120       $flag = $this->StatusFlag;
121       $attrs[$flag] = $value;
122       $this->$flag = $value;
123       $ldap->modify($attrs);
124       show_ldap_error($ldap->get_error());
125     }    
126   }
128   
129   function check()
130   { 
131     $message = plugin::check();
132     return($message);
133   }
134   
136   function save_object()
137   {
138     if(isset($_POST['goLdapServerPosted'])){
139       plugin::save_object();
140     }
141   }  
143 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
144 ?>