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