Code

Udpated JS focus,
[gosa.git] / setup / class_setupStep_Config1.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
23 class Step_Config1 extends setup_step
24 {
26   var $peopleou   = "ou=people";
27   var $groupou    =  "ou=groups";
28   var $peopledn   = "cn";
29   var $uidbase    = 1000;
30   var $krbsasl    = FALSE;
31   var $strict     = TRUE;
33   var $header_image = "images/ldapserver.png";
34   var $account_expiration  =FALSE;
35   var $base_hook         = ""; 
36   var $base_hook_active  = FALSE; 
38   var $encryption = "crypt";
39   var $theme      = "default"; 
41   var $include_personal_title = FALSE;
43   var $pwd_rules  = array("pwminlen" => 6, 
44                           "pwminlen_active" => FALSE,
45                           "pwdiffer" => 5,
46                           "pwdiffer_active" => FALSE,
47                           "externalpwdhook" => "",
48                           "externalpwdhook_active" => FALSE);
50   var $id_settings = array(       "idgen"         => "{%sn}-{%givenName[2-4]}",
51                                   "idgen_active"  => FALSE,
52                                   "minid"         => "100",
53                                   "minid_active"  => FALSE);
55   var $crypt_methods  = array();
57   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","theme","krbsasl",
58                           "base_hook","base_hook_active","account_expiration","strict","include_personal_title");
60   function Step_Config1()
61   {
62     $this->update_strings();
64     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
65     foreach($tmp['name'] as $name){
66       $this->crypt_methods[$name] = $name;
67     }
68   }
71   function update_strings()
72   {
73     $this->s_title      = _("GOsa settings 1/3");
74     $this->s_title_long = _("GOsa settings 1/3");
75     $this->s_info       = _("GOsa generic settings");
76   }
78   
79   function execute()
80   {
81     $smarty = get_smarty();
82     $smarty->assign("peopledns",array("uid","cn"));
83     $smarty->assign("id_settings",$this->id_settings);
84     $smarty->assign("crypt_methods",$this->crypt_methods);
85     $smarty->assign("themes",$this->get_themes());
86     $smarty->assign("pwd_rules",$this->pwd_rules);
87     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
88     foreach($this->attributes as $attr){
89       $smarty->assign($attr,$this->$attr);
90     }
92     /* !!! Attention strict is inverse. If you change this, 
93      *  don't forget to change save_object too 
94      */
95     $smarty->assign("strict",!$this->strict);
96     return($smarty -> fetch (get_template_path("../setup/setup_config1.tpl")));
97   }
100   function get_themes()
101   {
102     $dir = opendir( "../ihtml/themes/");
103     $themes = array();
104     while (($file = readdir($dir)) !== false){
105       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
106         $themes[$file] = $file;
107       }      
108     }
109     return($themes);
110   }
112   function check()
113   {
114     $message = array();
116     if(isset($this->id_settings['minid_active']) && !is_numeric($this->id_settings['minid'])){
117       $message[] = sprintf(_("The specified value for '%s' must be a numeric value"),_("GID / UID min id"));
118     }
120     if(preg_match("/,$/",$this->peopleou)){
121       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("People storage ou"));
122     }
124     if(preg_match("/,$/",$this->groupou)){
125       $message[] =sprintf(_("Don't add a trailing comma to '%s'."),_("Group storage ou"));
126     }
128     if(!is_numeric($this->uidbase)){
129       $message[] = _("Uid base must be numeric");
130     }
132     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
133       $message[] = _("The given password minimum length is not numeric.");
134     }
135     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
136       $message[] = _("The given password differ value is not numeric.");
137     }
138     return($message);
139   }
141   function save_object()
142   {
143     if(isset($_POST['step5_posted'])){
145       /* Get attributes */
146       foreach($this->attributes as $attr){
147         if(isset($_POST[$attr])){
148           $this->$attr = validate(get_post($attr));
149         }
150       }
152       /* !!! Attention strict is inverse. If you change this, 
153        *  don't forget to change the smarty assignment too 
154        */
155       if(isset($_POST['strict'])){
156         if($_POST['strict']){
157           $this->strict = FALSE;
158         }else{
159           $this->strict = TRUE;
160         }
161       }
163       if(isset($_POST['minid_active'])){
164         $this->id_settings['minid_active'] = TRUE;
165         if(isset($_POST['minid'])){
166           $this->id_settings['minid'] = get_post('minid');
167         }
168       }else{
169         $this->id_settings['minid_active'] = FALSE;
170       }
172       /* Generic settings */
173       if(isset($_POST['idgen_active'])){
174         $this->id_settings['idgen_active'] = TRUE;
175         if(isset($_POST['idgen'])){
176           $this->id_settings['idgen'] = get_post('idgen');
177         }
178       }else{
179         $this->id_settings['idgen_active'] = FALSE;
180       }
182       /* Get password settings */ 
183       if(isset($_POST['pwdiffer_active'])){
184         $this->pwd_rules['pwdiffer_active'] = TRUE;
185         if(isset($_POST['pwdiffer'])){
186           $this->pwd_rules['pwdiffer'] = get_post('pwdiffer');
187         }
188       }else{
189         $this->pwd_rules['pwdiffer_active'] = FALSE;
190       }
192       /* Get password minimum length posts */
193       if(isset($_POST['pwminlen_active'])){
194         $this->pwd_rules['pwminlen_active'] = TRUE;
195         if(isset($_POST['pwminlen'])){
196           $this->pwd_rules['pwminlen'] = get_post('pwminlen');
197         }
198       }else{
199         $this->pwd_rules['pwminlen_active'] = FALSE;
200       }
202       /* External pwd settings */
203       if(isset($_POST['externalpwdhook_active'])){
204         $this->pwd_rules['externalpwdhook_active'] = TRUE;
205         if(isset($_POST['externalpwdhook'])){
206           $this->pwd_rules['externalpwdhook'] = get_post('externalpwdhook');
207         }
208       }else{
209         $this->pwd_rules['externalpwdhook_active'] = FALSE;
210       }
212       /* base hook settings */
213       if(isset($_POST['base_hook_active'])){
214         $this->pwd_rules['base_hook_active'] = TRUE;
215         if(isset($_POST['base_hook'])){
216           $this->pwd_rules['base_hook'] = get_post('base_hook');
217         }
218       }else{
219         $this->pwd_rules['base_hook_active'] = FALSE;
220       }
221     }
223     $tmp = $this->check(); 
224     if(count($tmp) == 0){
225       $this->is_completed = TRUE;
226     }else{
227       $this->is_completed = FALSE;
228     }
229   }// if tempalte posted 
232   /* Attributes that are interesting for configuration generation */
233   function get_attributes()
234   {
235     $tmp = setup_step::get_attributes();
236     foreach(array("pwd_rules","id_settings") as $attr){
237       $tmp[$attr]= $this->$attr;
238     }
239     return($tmp);
240   }
241 }// CLass
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>