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");
21 function macro ($config, $dn= NULL)
22 {
23 plugin::plugin ($config, $dn);
25 $ldap= $config->get_ldap_link();
27 $this->dn = $dn;
29 /* This is always an account */
30 $this->is_account= TRUE;
32 /* Edit or new one ?*/
33 if ($this->dn == "new"){
34 $ui= get_userinfo();
35 $this->base= dn2base($ui->dn);
36 } else {
37 $this->base= dn2base($this->dn);
38 }
39 }
41 function execute()
42 {
43 /* Variables */
44 $vars = "";
45 $tmp = array();
46 $number = 0;
48 /* Do we represent a valid group? */
49 if (!$this->is_account && $this->parent == NULL){
50 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
51 _("This 'dn' is no phone macro.")."</b>";
52 return ($display);
53 }
55 /* Fill templating stuff */
56 $smarty= get_smarty();
57 $smarty->assign("bases", $this->config->idepartments);
59 /* Assign all vars to Smarty */
60 foreach($this->attributes as $ar){
61 $smarty->assign($ar, $this->$ar);
62 }
63 /* Checkboxes */
64 $smarty->assign("base_select", $this->base);
65 $smarty->assign("vars", $vars);
67 if($this->goFonMacroVisible){
68 $smarty->assign("goFonMacroVisibleChecked"," checked ");
69 }else{
70 $smarty->assign("goFonMacroVisibleChecked","");
71 }
73 if(isset($_POST['goFonMacroVisible'])) {
74 $this->goFonMacroVisible= 1 ;
75 $smarty->assign("goFonMacroVisibleChecked"," checked ");
76 }else {
77 if(isset($_POST['cn'])){
78 $this->goFonMacroVisible= 0 ;
79 $smarty->assign("goFonMacroVisibleChecked","");
80 }
81 }
83 /* Show main page */
84 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
85 }
87 function remove_from_parent()
88 {
89 $ldap= $this->config->get_ldap_link();
90 $ldap->rmDir($this->dn);
92 /* Optionally execute a command after we're done */
93 $this->handle_post_events("remove");
95 /* Delete references to object groups */
96 $ldap->cd ($this->config->current['BASE']);
97 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
98 while ($ldap->fetch()){
99 $og= new ogroup($this->config, $ldap->getDN());
100 unset($og->member[$this->dn]);
101 $og->save ();
102 }
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 if (isset($_POST['cn'])){
110 plugin::save_object();
112 }
113 }
116 /* Check values */
117 function check()
118 {
119 $message = array();
121 if(empty($this->displayName)){
122 $message[] = _("You must specify the 'Display Name' in order to save this macro");
123 }
125 foreach($this->attributes as $attr){
126 if(chkacl($this->acl,$attr)){
127 $str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ;
128 return(array($str));
129 }
130 }
131 if(($this->cn != strtolower($this->cn))||(empty($this->cn))){
132 $message[] = "The attribute 'cn' must be lowercase and a least one char.";
133 }
135 if(count(split("\n",$this->goFonMacroContent))>100){
136 $message[] = _("Makro length must be lower than 100 lines");
137 }
139 return $message;
140 }
143 /* Save to LDAP */
144 function save()
145 {
146 /* Post checks */
147 $this->execute();
149 plugin::save();
151 unset($this->attrs['base']);
153 /* Write back to ldap */
154 $ldap= $this->config->get_ldap_link();
155 $ldap->cat($this->dn);
156 $a= $ldap->fetch();
158 if (count($a)){
159 $ldap->cd($this->dn);
160 $ldap->modify($this->attrs);
161 $this->handle_post_events("modify");
162 } else {
163 $ldap->cd($this->dn);
164 $ldap->create_missing_trees( $this->dn);
165 $ldap->cd($this->dn);
166 $ldap->add($this->attrs);
167 $this->handle_post_events("add");
168 }
169 show_ldap_error($ldap->get_error());
170 }
172 }
173 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
174 ?>