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;
37 /* Edit or new one ?*/
38 if ($this->dn == "new"){
39 $ui= get_userinfo();
40 $this->base= dn2base($ui->dn);
41 } else {
42 $this->base= dn2base($this->dn);
43 }
44 }
46 /*!
47 Execute this plugin
48 */
49 function execute()
50 {
51 /* Variables */
52 $vars = "";
53 $tmp = array();
54 $number = 0;
56 /* Do we represent a valid group? */
57 if (!$this->is_account && $this->parent == NULL){
58 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
59 _("This 'dn' is no phone macro.")."</b>";
60 return ($display);
61 }
63 /* Fill templating stuff */
64 $smarty= get_smarty();
65 $smarty->assign("bases", $this->config->idepartments);
67 /* Assign all vars to Smarty */
68 foreach($this->attributes as $ar){
69 $smarty->assign($ar, $this->$ar);
70 }
71 /* Checkboxes */
72 $smarty->assign("base_select", $this->base);
73 $smarty->assign("vars", $vars);
75 if($this->goFonMacroVisible){
76 $smarty->assign("goFonMacroVisibleChecked"," checked ");
77 }else{
78 $smarty->assign("goFonMacroVisibleChecked","");
79 }
81 if(isset($_POST['goFonMacroVisible'])) {
82 $this->goFonMacroVisible= 1 ;
83 $smarty->assign("goFonMacroVisibleChecked"," checked ");
84 }else {
85 if(isset($_POST['cn'])){
86 $this->goFonMacroVisible= 0 ;
87 $smarty->assign("goFonMacroVisibleChecked","");
88 }
89 }
91 /* Show main page */
92 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
93 }
95 /*!
96 Remove this Object
97 */
98 function remove_from_parent()
99 {
100 $ldap= $this->config->get_ldap_link();
101 $ldap->rmDir($this->dn);
103 /* Optionally execute a command after we're done */
104 $this->handle_post_events("remove");
106 /* Delete references to object groups */
107 $ldap->cd ($this->config->current['BASE']);
108 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
109 while ($ldap->fetch()){
110 $og= new ogroup($this->config, $ldap->getDN());
111 unset($og->member[$this->dn]);
112 $og->save ();
113 }
114 }
117 /*!
118 Save data to object
119 */
120 function save_object()
121 {
122 if (isset($_POST['cn'])){
123 plugin::save_object();
125 }
126 }
129 /*!
130 Check values
131 */
132 function check()
133 {
134 $message = array();
136 if($this->dn=="new"){
137 $ldap = $this->config->get_ldap_link();
138 $ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn"));
139 if($ldap->count()>0){
140 $message[]=sprintf(_("The given cn '%s' already exists."),$this->cn);
141 }
142 }
144 if(empty($this->displayName)){
145 $message[] = _("You must specify the 'Display Name' in order to save this macro");
146 }
148 foreach($this->attributes as $attr){
149 if(chkacl($this->acl,$attr)){
150 $str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ;
151 return(array($str));
152 }
153 }
154 if(($this->cn != strtolower($this->cn))||(empty($this->cn))){
155 $message[] = "The attribute 'cn' must be lowercase and a least one char.";
156 }
158 if(count(split("\n",$this->goFonMacroContent))>100){
159 $message[] = _("Makro length must be lower than 100 lines");
160 }
162 return $message;
163 }
166 /*!
167 Save to LDAP
168 */
169 function save()
170 {
171 /* Post checks */
172 $this->execute();
174 plugin::save();
175 unset($this->attrs['base']);
177 /* Write back to ldap */
178 $ldap= $this->config->get_ldap_link();
179 $ldap->cat($this->dn);
180 $a= $ldap->fetch();
182 if (count($a)){
183 $ldap->cd($this->dn);
184 $ldap->modify($this->attrs);
185 $this->handle_post_events("modify");
186 } else {
187 $ldap->cd($this->dn);
188 $ldap->create_missing_trees( $this->dn);
189 $ldap->cd($this->dn);
190 $ldap->add($this->attrs);
191 $this->handle_post_events("add");
192 }
193 show_ldap_error($ldap->get_error());
194 }
196 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>