1 <?php
3 class faiVariableEntry extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account= TRUE;
12 var $attributes = array("cn","description","FAIvariableContent");
13 var $objectclasses= array();
15 var $orig_cn = "";
16 var $dn = "";
17 var $cn = "";
18 var $FAIvariableContent = "";
19 var $description = "";
20 var $status = "new";
22 var $FAIstate = "";
24 function faiVariableEntry ($config, $dn= NULL,$object=false)
25 {
26 plugin::plugin ($config, $dn);
27 if((isset($object['cn'])) && (!empty($object['cn']))){
28 $this->orig_cn= $object['cn'];
29 $this->dn=$object['dn'];
30 foreach($object as $name=>$value){
31 $oname = $name;
32 $this->$oname=addslashes($value);
33 }
35 if(isset($this->attrs['FAIstate'][0])){
36 $this->FAIstate = $this->attrs['FAIstate'][0];
37 }
39 }else{
40 $this->status = "new";
41 $this->orig_cn = false;
42 }
43 }
45 function execute()
46 {
47 /* Call parent execute */
48 plugin::execute();
50 /* Fill templating stuff */
51 $smarty = get_smarty();
52 $display = "";
54 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
55 * If we post the escaped strings they will be escaped again
56 */
57 foreach($this->attributes as $attrs){
58 if(get_magic_quotes_gpc()){
59 $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs))));
60 }else{
61 $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs)));
62 }
63 }
65 $tmp = $this->plInfo();
66 foreach($tmp['plProvidedAcls'] as $name => $translated){
67 $acl = $this->getacl($name);
68 if($this->FAIstate == "freezed"){
69 $acl = preg_replace("/w/","",$acl);
70 }
71 $smarty->assign($name."ACL",$acl);
72 }
76 $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
77 return($display);
78 }
80 /* Save data to object */
81 function save_object()
82 {
83 if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
84 foreach($this->attributes as $attrs){
85 if($this->acl_is_writeable($attrs)){
86 if(isset($_POST[$attrs])){
87 $this->$attrs = $_POST[$attrs];
88 }else{
89 $this->$attrs = "";
90 }
91 }
92 }
93 }
94 }
96 /* Check supplied data */
97 function check()
98 {
99 /* Call common method to give check the hook */
100 $message= plugin::check();
102 if(empty($this->FAIvariableContent)) {
103 $message[]=_("Please specify a value for the attribute 'content'.");
104 }
106 if(empty($this->cn)){
107 $message[] = _("Please enter a name.");
108 }
110 return ($message);
111 }
113 function save()
114 {
115 $tmp=array();
116 foreach($this->attributes as $attrs){
117 $tmp[$attrs] = stripslashes( $this->$attrs);
118 }
120 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
121 $tmp['remove']['from'] = $this->orig_cn;
122 $tmp['remove']['to'] = $tmp['cn'];
123 }
125 $tmp['dn'] = $this->dn;
126 $tmp['status'] = $this->status;
127 return($tmp);
128 }
130 /* Return plugin informations for acl handling */
131 function plInfo()
132 {
133 return (array(
134 "plShortName" => _("Variable entry"),
135 "plDescription" => _("FAI variable entry "),
136 "plSelfModify" => FALSE,
137 "plDepends" => array(),
138 "plPriority" => 23,
139 "plSection" => array("administration"),
140 "plCategory" => array("fai"),
141 "plProvidedAcls" => array(
142 "cn" => _("Name"),
143 "description" => _("Description"),
144 "FAIvariableContent"=> _("Variable content") )
145 ));
146 }
149 }
150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
151 ?>