Code

e2148014f10384477609556c510980887142ac0d
[gosa.git] / plugins / admin / fai / class_faiScriptEntry.inc
1 <?php
3 class faiScriptEntry 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","FAIpriority","FAIscript");
13   var $objectclasses= array("FAIscriptEntry");
15   var $orig_cn          = "";
16   var $dn               = "";
17   var $cn               = "";
18   var $FAIpriority      = "";
19   var $FAIscript        = "";
20   var $description      = "";
21   var $status           = "new";
22   var $parent           = false;
23   var $is_parent_saved  = false;
24   
25   function faiScriptEntry ($config, $dn)
26   {
27     /* Dn is dn currently assigned to this object 
28         'new' if object wasn't saved yet
29      */
30     plugin::plugin ($config, $dn);
31     if($dn != "new"){
32       $this->orig_cn         = $this->cn;
33     }else{
34       $this->status          = "new";
35       $this->orig_cn         = false;
36     }
37   }
39   function execute()
40   {
41     /* Fill templating stuff */
42     $smarty     = get_smarty();
43     $display = "";
44   
45     if(isset($_POST['ImportUpload'])){
46       if(($_FILES['ImportFile']['error']!=0)){
47         print_red(_("Please select a valid file."));
48       }else
49       if(($_FILES['ImportFile']['size']==0)){
50         print_red(_("Selected file is empty."));
51       }else{
52         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
53         $this->FAIscript = $str;
54       }
55     }
56   
57     foreach($this->attributes as $attrs){
58       if(get_magic_quotes_gpc()){
59        $smarty->assign($attrs,stripslashes($this->$attrs));
60       }else{
61        $smarty->assign($attrs,($this->$attrs));
62       } 
63     }
65     for($i =0 ; $i < 100 ; $i++){
66       $FAIprioritys[$i]=$i;
67     }
68     $smarty->assign("FAIprioritys",$FAIprioritys);
69     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
70     return($display);
71   }
73   /* Delete me, and all my subtrees
74   */
75   function remove_from_parent()
76   {
77     $ldap = $this->config->get_ldap_link();
78     $ldap->cd ($this->dn);
79     $ldap->rmdir_recursive($this->dn);
80     show_ldap_error($ldap->get_error());
81     $this->handle_post_events("remove");
82   }
85   /* Save data to object */
86   function save_object()
87   {
88     if(isset($_POST['SubObjectFormSubmitted'])){
89       foreach($this->attributes as $attrs){
90         if(isset($_POST[$attrs])){
91           $this->$attrs = $_POST[$attrs];
92         }else{
93           $this->$attrs = "";
94         }
95       }
96     }
97   }
99   /* Check supplied data */
100   function check()
101   {
102     $message= array();
103   
104     if(empty($this->cn)){
105       $message[] = _("Please enter a name.");
106     }
108     if(preg_match("/[^0-9a-z]/i",$this->cn)){
109       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
110     }
111  
112     return ($message);
113   }
114  
115   function save()
116   {
117     plugin::save();
119     /* Get ldap connection */
120     $ldap = $this->config->get_ldap_link();
121     $ldap->cd ($this->config->current['BASE']);
123     /* First : Check if parent was already saved ... */
124     $ldap->cd($this->parent->dn);
125     $ldap->cat($this->parent->dn);
126     
127     /* no entry was found. So save our base object first */
128     if($ldap->count()==0){
129       $this->parent->save();
130     } 
132     /* Generate this->dn */ 
133       /* if !orig_dn -> This is a new object */
134     if($this->orig_cn == false){
135       $this->dn = "cn=".$this->cn.",".$this->parent->dn;
136       $mode = "add";
137     }else{
138       /* This is an already existing entry, check if cn was changed */
139       if($this->orig_cn != $this->cn ){
140         /* rename */
141         $ldap->cd($this->dn);
142         $ldap->rmdir($this->dn);
143         $this->dn = "cn=".$this->cn.",".$this->parent->dn;
144         $mode = "add";
145       }else{
146         /* modify */
147         $mode = "modify";
148       }
149     }
151     $ldap->cd($this->config->current['BASE']);
152     $ldap->create_missing_trees($this->parent->dn);
153     $ldap->cd ($this->dn);
154     $ldap->$mode($this->attrs);
155     show_ldap_error($ldap->get_error());
156   }
158 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
159 ?>