1 <?php
3 class faiVariableEntry extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes = array("cn","description","FAIvariableContent");
8 var $objectclasses= array();
10 var $orig_cn = "";
11 var $dn = "";
12 var $cn = "";
13 var $FAIvariableContent = "";
14 var $description = "";
15 var $status = "new";
16 var $parent = NULL;
17 var $FAIstate = "";
19 function faiVariableEntry (&$config, $dn= NULL,$object=false)
20 {
21 plugin::plugin ($config, $dn);
22 if((isset($object['cn'])) && (!empty($object['cn']))){
23 $this->orig_cn= $object['cn'];
24 $this->dn=$object['dn'];
25 foreach($object as $name=>$value){
26 $oname = $name;
27 $this->$oname=addslashes($value);
28 }
29 }else{
30 $this->status = "new";
31 $this->orig_cn = false;
32 }
33 }
35 function execute()
36 {
37 /* Call parent execute */
38 plugin::execute();
40 /* Fill templating stuff */
41 $smarty = get_smarty();
42 $display = "";
44 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
45 * If we post the escaped strings they will be escaped again
46 */
47 foreach($this->attributes as $attrs){
48 if(get_magic_quotes_gpc()){
49 $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs))));
50 }else{
51 $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs)));
52 }
53 }
55 $tmp = $this->plInfo();
56 foreach($tmp['plProvidedAcls'] as $name => $translated){
57 $acl = $this->getacl($name, preg_match("/freeze/",$this->FAIstate));
58 $smarty->assign($name."ACL",$acl);
59 }
61 $smarty->assign("freeze",preg_match("/freeze/",$this->FAIstate));
62 $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
63 return($display);
64 }
67 /* Save data to object */
68 function save_object()
69 {
70 if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
71 foreach($this->attributes as $attrs){
72 if($this->acl_is_writeable($attrs)){
73 if(isset($_POST[$attrs])){
74 $this->$attrs = $_POST[$attrs];
75 }else{
76 $this->$attrs = "";
77 }
78 }
79 }
80 }
81 }
83 /* Check supplied data */
84 function check()
85 {
86 /* Call common method to give check the hook */
87 $message= plugin::check();
89 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
90 $message[] = msgPool::duplicated(_("Name"));
91 }
93 if(empty($this->FAIvariableContent)) {
94 $message[]= msgPool::required(_("Content"));
95 }
97 if(empty($this->cn)){
98 $message[] = msgPool::required(_("Name"));
99 }
101 return ($message);
102 }
104 function save()
105 {
106 $tmp=array();
107 foreach($this->attributes as $attrs){
108 $tmp[$attrs] = stripslashes( $this->$attrs);
109 }
111 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
112 $tmp['remove']['from'] = $this->orig_cn;
113 $tmp['remove']['to'] = $tmp['cn'];
114 }
116 $tmp['dn'] = $this->dn;
117 $tmp['status'] = $this->status;
118 return($tmp);
119 }
121 /* Return plugin informations for acl handling */
122 static function plInfo()
123 {
124 return (array(
125 "plShortName" => _("Variable entry"),
126 "plDescription" => _("FAI variable entry "),
127 "plSelfModify" => FALSE,
128 "plDepends" => array(),
129 "plPriority" => 23,
130 "plSection" => array("administration"),
131 "plCategory" => array("fai"),
132 "plProvidedAcls" => array(
133 "cn" => _("Name"),
134 "description" => _("Description"),
135 "FAIvariableContent"=> _("Variable content") )
136 ));
137 }
140 }
141 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
142 ?>