1 <?php
3 //! The Phone Macro Class: Handles Macro Contents, and some attributes.
4 /*!
5 This class handles the basic information about phone macros, like
6 cn base description displayName goFonMacroContent goFonMacroVisible
8 This is not the only Class that manages phone Macros, there ist also the class_goFonMacroParameter.
9 */
10 class macro extends plugin
11 {
12 /*! CLI vars */
13 var $cli_summary= "Handling of GOsa's macro object";
14 /*! CLI vars */
15 var $cli_description= "Some longer text\nfor help";
16 /*! CLI vars */
17 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
19 /*! Macro attributes, */
21 /*! The name of the Macro in the openldap drirectory */
22 var $cn = "";
24 /*! This ist the variable that contains the description of the macro*/
25 var $description = "";
27 /*! The base of the macro, is used to save the macro in the correct directory tree */
28 var $base = "";
30 /*! This is the name of the macro which the enduser will see, instead of the cn */
31 var $displayName = "";
33 /*! Here is the macro content, the real macroscript */
34 var $goFonMacroContent= "";
36 /*! To allow user to use this macro this var must be true, else false * /
37 var $goFonMacroVisible= 0;
39 /*! attribute list for save action */
40 var $attributes = array("cn","base", "description","displayName","goFonMacroContent","goFonMacroVisible");
42 /*! Objectclasses that this calls handles */
43 var $objectclasses = array("top", "goFonMacro");
45 //! The Konstructor
46 /*! Konstructor, load class with attributes of the given dn*/
47 function macro ($config, $dn= NULL)
48 {
49 plugin::plugin ($config, $dn);
51 $ldap= $config->get_ldap_link();
53 $this->dn = $dn;
55 /* This is always an account */
56 $this->is_account= TRUE;
59 /* Edit or new one ?*/
60 if ($this->dn == "new"){
61 $ui= get_userinfo();
62 $this->base= dn2base($ui->dn);
63 } else {
64 $this->orig_cn=$this->cn;
65 $this->base= dn2base($this->dn);
66 }
67 }
69 /*! Execute this plugin */
70 function execute()
71 {
72 /* Variables */
73 $vars = "";
74 $tmp = array();
75 $number = 0;
77 /* Do we represent a valid group? */
78 if (!$this->is_account && $this->parent == NULL){
79 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
80 _("This 'dn' is no phone macro.")."</b>";
81 return ($display);
82 }
84 /* Fill templating stuff */
85 $smarty= get_smarty();
86 $smarty->assign("bases", $this->config->idepartments);
88 /* Assign all vars to Smarty */
89 foreach($this->attributes as $ar){
90 $smarty->assign($ar, $this->$ar);
91 }
92 /* Checkboxes */
93 $smarty->assign("base_select", $this->base);
94 $smarty->assign("vars", $vars);
96 if($this->goFonMacroVisible){
97 $smarty->assign("goFonMacroVisibleChecked"," checked ");
98 }else{
99 $smarty->assign("goFonMacroVisibleChecked","");
100 }
102 if(isset($_POST['goFonMacroVisible'])) {
103 $this->goFonMacroVisible= 1 ;
104 $smarty->assign("goFonMacroVisibleChecked"," checked ");
105 }else {
106 if(isset($_POST['cn'])){
107 $this->goFonMacroVisible= 0 ;
108 $smarty->assign("goFonMacroVisibleChecked","");
109 }
110 }
112 /* Show main page */
113 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
114 }
116 /*!
117 Remove this Object
118 */
119 function remove_from_parent()
120 {
121 $ldap= $this->config->get_ldap_link();
122 $ldap->rmDir($this->dn);
124 /* Optionally execute a command after we're done */
125 $this->handle_post_events("remove");
127 /* Delete references to object groups */
128 $ldap->cd ($this->config->current['BASE']);
129 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
130 while ($ldap->fetch()){
131 $og= new ogroup($this->config, $ldap->getDN());
132 unset($og->member[$this->dn]);
133 $og->save ();
134 }
135 }
138 /*!
139 Save data to object
140 */
141 function save_object()
142 {
143 if (isset($_POST['cn'])){
144 plugin::save_object();
146 }
147 }
150 /*!
151 Check values
152 */
153 function check()
154 {
155 $message = array();
157 if(($this->dn=="new")||($this->orig_cn!=$this->cn)){
158 $ldap = $this->config->get_ldap_link();
159 $ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn"));
160 if($ldap->count()>0){
161 $message[]=sprintf(_("The given cn '%s' already exists."),$this->cn);
162 }
163 }
165 if(empty($this->displayName)){
166 $message[] = _("You must specify the 'Display Name' in order to save this macro");
167 }
169 foreach($this->attributes as $attr){
170 if(chkacl($this->acl,$attr)){
171 $str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ;
172 return(array($str));
173 }
174 }
175 if(($this->cn != strtolower($this->cn))||(empty($this->cn))){
176 $message[] = "The attribute 'cn' must be lowercase and a least one char.";
177 }
179 if(count(split("\n",$this->goFonMacroContent))>100){
180 $message[] = _("Makro length must be lower than 100 lines");
181 }
183 return $message;
184 }
187 /*!
188 Save to LDAP
189 */
190 function save()
191 {
192 /* Post checks */
193 $this->execute();
195 plugin::save();
196 unset($this->attrs['base']);
198 /* Write back to ldap */
199 $ldap= $this->config->get_ldap_link();
200 $ldap->cat($this->dn);
201 $a= $ldap->fetch();
203 if (count($a)){
204 $ldap->cd($this->dn);
205 $ldap->modify($this->attrs);
206 $this->handle_post_events("modify");
207 } else {
208 $ldap->cd($this->dn);
209 $ldap->create_missing_trees( $this->dn);
210 $ldap->cd($this->dn);
211 $ldap->add($this->attrs);
212 $this->handle_post_events("add");
213 }
214 show_ldap_error($ldap->get_error());
215 }
217 }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>