Code

Fixed save_object
[gosa.git] / plugins / admin / systems / class_goLdapServer.inc
1 <?php
3 class goLdapServer extends plugin{
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";
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          = ""; 
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['AllowRestart'] = 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     if(!$this->initially_was_account) return;
95     $ldap = $this->config->get_ldap_link();
96     $ldap->cd($this->dn);
97     $ldap->cat($this->dn,array("objectClass"));
98     if($ldap->count()){
100       $tmp = $ldap->fetch();
101       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
102         $attrs['objectClass'][] = $tmp['objectClass'][$i];
103       }
104       $flag = $this->StatusFlag;
105       $attrs[$flag] = $value;
106       $this->$flag = $value;
107       $ldap->modify($attrs);
108       show_ldap_error($ldap->get_error());
109       $this->action_hook();
110     }
111   }
114   function check()
115   { 
116     $message = plugin::check();
117     if(empty($this->goLdapBase)){
118       $message[] = _("The given base is empty or contains invalid characters.");
119     }
120     return($message);
121   }
124   function save_object()
125   {
126     if(isset($_POST['goLdapServerPosted'])){
127       plugin::save_object();
128     }
129   } 
131   function action_hook($add_attrs= array())
132   {
133     /* Find postcreate entries for this class */
134     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
135     if ($command == "" && isset($this->config->data['TABS'])){
136       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
137     }
138     if ($command != ""){
139       /* Walk through attribute list */
140       foreach ($this->attributes as $attr){
141         if (!is_array($this->$attr)){
142           $command= preg_replace("/%$attr/", $this->$attr, $command);
143         }
144       }
145       $command= preg_replace("/%dn/", $this->dn, $command);
146       /* Additional attributes */
147       foreach ($add_attrs as $name => $value){
148         $command= preg_replace("/%$name/", $value, $command);
149       }
150       if (check_command($command)){
151         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
152             $command, "Execute");
154         exec($command);
155       } else {
156         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
157         print_red ($message);
158       }
159     }
160   }
163 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
164 ?>