Code

Added new service
[gosa.git] / plugins / admin / systems / class_goFonServer.inc
1 <?php
3 class goFonServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports asterisk management.";
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("goFonServer");
11   var $attributes       = array("goFonServerStatus","goFonAdmin", "goFonPassword","goFonAreaCode", "goFonCountryCode");
12   var $StatusFlag       = "goFonServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goFonServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
21   var $goFonServerStatus  = "";
22   var $goFonPassword      = "";
23   var $goFonAdmin         = "";
24   var $goFonAreaCode      = "";
25   var $goFonCountryCode   = "";
26    
27  
28   function goFonServer($config,$dn)
29   {
30     plugin::plugin($config,$dn);
31     $this->DisplayName = _("Asterisk management");
32   }
35   function execute()
36   { 
37     $smarty = get_smarty(); 
38     foreach($this->attributes as $attr){
39       $smarty->assign($attr,$this->$attr);
40       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
41     }
42     return($smarty->fetch(get_template_path("goFonServer.tpl",TRUE,dirname(__FILE__))));
43   }
46   function getListEntry()
47   {
48     $flag = $this->StatusFlag;
49     $fields['Status']     = $this->$flag;
50     $fields['Message']    = _("Asterisk management");
51     $fields['AllowStart'] = true;
52     $fields['AllowStop']  = true;
53     $fields['AllowReset'] = true;
54     $fields['AllowRemove']= true;
55     $fields['AllowEdit']  = true;
56     return($fields);
57   }
60   function remove_from_parent()
61   {
62     plugin::remove_from_parent();
63     /* Check if this is a new entry ... add/modify */
64     $ldap = $this->config->get_ldap_link();
65     $ldap->cat($this->dn,array("objectClass"));
66     if($ldap->count()){
67       $ldap->cd($this->dn);
68       $ldap->modify($this->attrs);
69     }else{
70       $ldap->cd($this->dn);
71       $ldap->add($this->attrs);
72     }
73     show_ldap_error($ldap->get_error());
74   }
77   function save()
78   {
79     plugin::save();
80     /* Check if this is a new entry ... add/modify */
81     $ldap = $this->config->get_ldap_link();
82     $ldap->cat($this->dn,array("objectClass"));
83     if($ldap->count()){
84       $ldap->cd($this->dn);
85       $ldap->modify($this->attrs);
86     }else{
87       $ldap->cd($this->dn);
88       $ldap->add($this->attrs);
89     }
90     show_ldap_error($ldap->get_error());
91   }
94   /* Directly save new status flag */
95   function setStatus($value)
96   {
97     $ldap = $this->config->get_ldap_link();
98     $ldap->cd($this->dn);
99     $ldap->cat($this->dn,array("objectClass","goFonAdmin", "goFonAreaCode", "goFonCountryCode","goFonPassword"));
100       
101     if($ldap->count()){
102       $attrs =array();
103       foreach(array("goFonAdmin", "goFonAreaCode", "goFonCountryCode","goFonPassword") as $req) {
104         if(!isset($attrs[$req])){
105           if(empty($this->$req)){
106             print_red(sprintf(_("The required attribute '%s' is not set."),$req));
107           }else{
108             $attrs[$req] = $this->$req;
109           }
110         }else{
111           $attrs[$req] = $attrs[$req][0];
112         }
113       }
115       $tmp = $ldap->fetch();
116       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
117         $attrs['objectClass'][] = $tmp['objectClass'][$i];
118       }    
119       if(!in_array("goFonServer",$attrs['objectClass'])){
120         $attrs['objectClass'][] = "goFonServer";
121       }
123       $flag = $this->StatusFlag;
124       $attrs[$flag] = $value;
125       $this->$flag = $value;
126       $ldap->modify($attrs);
127       show_ldap_error($ldap->get_error());
128     }    
129   }
131   
132   function check()
133   { 
134     $message = plugin::check();
135     foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
136       if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
137         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
138       }
139     }
140     return($message);
141   }
142   
144   function save_object()
145   {
146     if(isset($_POST['goFonServerPosted'])){
147       plugin::save_object();
148     }
149   }  
151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
152 ?>