ce47af952a3d6623b1aeea4f53dacce9df55d310
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";
21 var $parent = NULL;
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(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
103 $message[] =_("There is already a variable with the given name.");
104 }
106 if(empty($this->FAIvariableContent)) {
107 $message[]=_("Please specify a value for the attribute 'content'.");
108 }
110 if(empty($this->cn)){
111 $message[] = _("Please enter a name.");
112 }
114 return ($message);
115 }
117 function save()
118 {
119 $tmp=array();
120 foreach($this->attributes as $attrs){
121 $tmp[$attrs] = stripslashes( $this->$attrs);
122 }
124 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
125 $tmp['remove']['from'] = $this->orig_cn;
126 $tmp['remove']['to'] = $tmp['cn'];
127 }
129 $tmp['dn'] = $this->dn;
130 $tmp['status'] = $this->status;
131 return($tmp);
132 }
134 /* Return plugin informations for acl handling */
135 function plInfo()
136 {
137 return (array(
138 "plShortName" => _("Variable entry"),
139 "plDescription" => _("FAI variable entry "),
140 "plSelfModify" => FALSE,
141 "plDepends" => array(),
142 "plPriority" => 23,
143 "plSection" => array("administration"),
144 "plCategory" => array("fai"),
145 "plProvidedAcls" => array(
146 "cn" => _("Name"),
147 "description" => _("Description"),
148 "FAIvariableContent"=> _("Variable content") )
149 ));
150 }
153 }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>