1 <?php
2 class macro extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Handling of GOsa's application object";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* application attributes */
10 var $cn= "";
11 var $description= "";
12 var $base= "";
13 var $displayName = "";
14 var $goFonMacroContent;
15 var $goFonMacroVisible=0;
17 /* attribute list for save action */
18 var $attributes= array("cn","base", "description","displayName","goFonMacroContent","goFonMacroVisible");
19 var $objectclasses= array("top", "goFonMacro");
22 /*!
23 Konstructor, load class with attributes of the given dn
24 */
25 function macro ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
29 $ldap= $config->get_ldap_link();
31 $this->dn = $dn;
33 /* This is always an account */
34 $this->is_account= TRUE;
36 /* Edit or new one ?*/
37 if ($this->dn == "new"){
38 $ui= get_userinfo();
39 $this->base= dn2base($ui->dn);
40 } else {
41 $this->base= dn2base($this->dn);
42 }
43 }
45 /*!
46 Execute this plugin
47 */
48 function execute()
49 {
50 /* Variables */
51 $vars = "";
52 $tmp = array();
53 $number = 0;
55 /* Do we represent a valid group? */
56 if (!$this->is_account && $this->parent == NULL){
57 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
58 _("This 'dn' is no phone macro.")."</b>";
59 return ($display);
60 }
62 /* Fill templating stuff */
63 $smarty= get_smarty();
64 $smarty->assign("bases", $this->config->idepartments);
66 /* Assign all vars to Smarty */
67 foreach($this->attributes as $ar){
68 $smarty->assign($ar, $this->$ar);
69 }
70 /* Checkboxes */
71 $smarty->assign("base_select", $this->base);
72 $smarty->assign("vars", $vars);
74 if($this->goFonMacroVisible){
75 $smarty->assign("goFonMacroVisibleChecked"," checked ");
76 }else{
77 $smarty->assign("goFonMacroVisibleChecked","");
78 }
80 if(isset($_POST['goFonMacroVisible'])) {
81 $this->goFonMacroVisible= 1 ;
82 $smarty->assign("goFonMacroVisibleChecked"," checked ");
83 }else {
84 if(isset($_POST['cn'])){
85 $this->goFonMacroVisible= 0 ;
86 $smarty->assign("goFonMacroVisibleChecked","");
87 }
88 }
90 /* Show main page */
91 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
92 }
94 /*!
95 Remove this Object
96 */
97 function remove_from_parent()
98 {
99 $ldap= $this->config->get_ldap_link();
100 $ldap->rmDir($this->dn);
102 /* Optionally execute a command after we're done */
103 $this->handle_post_events("remove");
105 /* Delete references to object groups */
106 $ldap->cd ($this->config->current['BASE']);
107 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
108 while ($ldap->fetch()){
109 $og= new ogroup($this->config, $ldap->getDN());
110 unset($og->member[$this->dn]);
111 $og->save ();
112 }
113 }
116 /*!
117 Save data to object
118 */
119 function save_object()
120 {
121 if (isset($_POST['cn'])){
122 plugin::save_object();
124 }
125 }
128 /*!
129 Check values
130 */
131 function check()
132 {
133 $message = array();
135 if(empty($this->displayName)){
136 $message[] = _("You must specify the 'Display Name' in order to save this macro");
137 }
139 foreach($this->attributes as $attr){
140 if(chkacl($this->acl,$attr)){
141 $str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ;
142 return(array($str));
143 }
144 }
145 if(($this->cn != strtolower($this->cn))||(empty($this->cn))){
146 $message[] = "The attribute 'cn' must be lowercase and a least one char.";
147 }
149 if(count(split("\n",$this->goFonMacroContent))>100){
150 $message[] = _("Makro length must be lower than 100 lines");
151 }
153 return $message;
154 }
157 /*!
158 Save to LDAP
159 */
160 function save()
161 {
162 /* Post checks */
163 $this->execute();
165 plugin::save();
167 unset($this->attrs['base']);
169 /* Write back to ldap */
170 $ldap= $this->config->get_ldap_link();
171 $ldap->cat($this->dn);
172 $a= $ldap->fetch();
174 if (count($a)){
175 $ldap->cd($this->dn);
176 $ldap->modify($this->attrs);
177 $this->handle_post_events("modify");
178 } else {
179 $ldap->cd($this->dn);
180 $ldap->create_missing_trees( $this->dn);
181 $ldap->cd($this->dn);
182 $ldap->add($this->attrs);
183 $this->handle_post_events("add");
184 }
185 show_ldap_error($ldap->get_error());
186 }
188 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>