1 <?php
3 class goGlpiServer extends plugin{
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("goGlpiServer");
11 var $attributes = array("goGlpiServerStatus","goGlpiAdmin","goGlpiDatabase","goGlpiPassword");
12 var $StatusFlag = "goGlpiServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goGlpiServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $acl;
21 var $goGlpiServerStatus ="";
22 var $goGlpiAdmin ="";
23 var $goGlpiDatabase ="";
24 var $goGlpiPassword ="";
27 function goGlpiServer($config,$dn)
28 {
29 plugin::plugin($config,$dn);
30 $this->DisplayName = _("Glpi database");
31 }
34 function execute()
35 {
36 $smarty = get_smarty();
37 foreach($this->attributes as $attr){
38 $smarty->assign($attr,$this->$attr);
39 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
40 }
41 return($smarty->fetch(get_template_path("goGlpiServer.tpl",TRUE,dirname(__FILE__))));
42 }
45 function getListEntry()
46 {
47 $flag = $this->StatusFlag;
48 $fields['Status'] = $this->$flag;
49 $fields['Message'] = _("Glpi management");
50 $fields['AllowStart'] = true;
51 $fields['AllowStop'] = true;
52 $fields['AllowReset'] = true;
53 $fields['AllowRemove']= true;
54 $fields['AllowEdit'] = true;
55 return($fields);
56 }
59 function remove_from_parent()
60 {
61 plugin::remove_from_parent();
62 /* Check if this is a new entry ... add/modify */
63 $ldap = $this->config->get_ldap_link();
64 $ldap->cat($this->dn,array("objectClass"));
65 if($ldap->count()){
66 $ldap->cd($this->dn);
67 $ldap->modify($this->attrs);
68 }else{
69 $ldap->cd($this->dn);
70 $ldap->add($this->attrs);
71 }
72 show_ldap_error($ldap->get_error());
73 }
76 function save()
77 {
78 plugin::save();
79 /* Check if this is a new entry ... add/modify */
80 $ldap = $this->config->get_ldap_link();
81 $ldap->cat($this->dn,array("objectClass"));
82 if($ldap->count()){
83 $ldap->cd($this->dn);
84 $ldap->modify($this->attrs);
85 }else{
86 $ldap->cd($this->dn);
87 $ldap->add($this->attrs);
88 }
89 show_ldap_error($ldap->get_error());
90 }
93 /* Directly save new status flag */
94 function setStatus($value)
95 {
96 $ldap = $this->config->get_ldap_link();
97 $ldap->cd($this->dn);
98 $ldap->cat($this->dn,array("objectClass","goGlpiAdmin","goGlpiDatabase"));
100 if($ldap->count()){
101 $attrs =array();
102 foreach(array("goGlpiAdmin","goGlpiDatabase") as $req) {
103 if(!isset($attrs[$req])){
104 if(empty($this->$req)){
105 print_red(sprintf(_("The required attribute '%s' is not set."),$req));
106 }else{
107 $attrs[$req] = $this->$req;
108 }
109 }else{
110 $attrs[$req] = $attrs[$req][0];
111 }
112 }
114 $tmp = $ldap->fetch();
115 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
116 $attrs['objectClass'][] = $tmp['objectClass'][$i];
117 }
118 if(!in_array("goGlpiServer",$attrs['objectClass'])){
119 $attrs['objectClass'][] = "goGlpiServer";
120 }
122 $flag = $this->StatusFlag;
123 $attrs[$flag] = $value;
124 $this->$flag = $value;
125 $ldap->modify($attrs);
126 show_ldap_error($ldap->get_error());
127 }
128 }
131 function check()
132 {
133 $message = plugin::check();
134 foreach(array("goGlpiAdmin","goGlpiDatabase") as $attr){
135 if(empty($this->$attr)){
136 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
137 }
138 }
139 return($message);
140 }
143 function save_object()
144 {
145 if(isset($_POST['goLogDBServerPosted'])){
146 plugin::save_object();
147 }
148 }
149 }
150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
151 ?>