Code

updated
[gosa.git] / plugins / gofon / macro / class_gofonMacro.inc
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\">&nbsp;<b>".
51         _("This 'dn' is no application.")."</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();
120     
121     foreach($this->attributes as $attr){
122       if(chkacl($this->acl,$attr)){
123         $str =  sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ;
124         return(array($str));
125         }
126       }
127     if(($this->cn != strtolower($this->cn))||(empty($this->cn))){
128       $message[] = "The attribute 'cn' must be lowercase and a least one char.";
129     }
130     
131     if(count(split("\n",$this->goFonMacroContent))>100){
132       $message[] = _("Makro length must be lower than 100 lines");
133     }
134     
135     return $message;
136   }
139   /* Save to LDAP */
140   function save()
141   {
142     /* Post checks */
143     $this->execute();
145     plugin::save();
147     unset($this->attrs['base']);
149     /* Write back to ldap */
150     $ldap= $this->config->get_ldap_link();
151     $ldap->cat($this->dn);
152     $a= $ldap->fetch();
154     if (count($a)){
155       $ldap->cd($this->dn);
156       $ldap->modify($this->attrs);
157       $this->handle_post_events("modify");
158     } else {
159       $ldap->cd($this->dn);
160       $ldap->create_missing_trees( $this->dn);
161       $ldap->cd($this->dn);
162       $ldap->add($this->attrs);
163       $this->handle_post_events("add");
164     }
165     show_ldap_error($ldap->get_error());
166   }
169 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
170 ?>