Code

Added some more setup steps
[gosa.git] / setup / class_setupStep5.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 setup_step_5 extends setup_step
24 {
26   var $peopleou   = "ou=people";
27   var $groupou    =  "ou=groups";
28   var $peopledn   = "cn";
29   var $uidbase    = 1000;
30   var $encryption = "crypt";
31   var $mail       = "none";
32   var $theme      = "default"; 
33   var $errorlvl   = TRUE;
34   var $cyrusunixstyle = FALSE;
36   var $pwd_rules  = array("pwminlen" => 6, 
37                           "pwminlen_active" => FALSE,
38                           "pwdiffer" => 5,
39                           "pwdiffer_active" => FALSE,
40                           "externalpwdhook" => "/usr/bin/sudo myscript",
41                           "externalpwdhook_active" => FALSE);
43   var $mail_settings = array("vacationdir"        => "/etc/gosa/vacation",
44                              "vacationdir_active" => FALSE);
45  
46   var $crypt_methods  = array();
47   var $mail_methods   = array();
50   var $attributes = array("peopleou","groupou","peopledn","uidbase","encryption","mail","theme","errorlvl","cyrusunixstyle");
52   function setup_step_5()
53   {
54     $this->s_title      = _("GOsa settings 1/2");
55     $this->s_title_long = _("GOsa generic settings, page 1/2");
56     $this->s_info       = _("This dialog allows you to setup GOsa behaviour");
58     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
59     foreach($tmp['name'] as $name){
60       $this->crypt_methods[$name] = $name;
61     }
62     $tmp = $this->get_available_mail_classes();
63     foreach($tmp['name'] as $name){
64       $this->mail_methods[$name] = $name;
65     }
66   }
68   
69   function execute()
70   {
71     $smarty = get_smarty();
72     $smarty->assign("peopledns",array("uid","cn"));
73     $smarty->assign("crypt_methods",$this->crypt_methods);
74     $smarty->assign("mail_methods",$this->mail_methods);
75     $smarty->assign("themes",$this->get_themes());
76     $smarty->assign("pwd_rules",$this->pwd_rules);
77     $smarty->assign("mail_settings",$this->mail_settings);
78     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
79     $smarty->assign("warnings" ,$this->check());
80     $smarty->assign("warnings_cnt" ,count($this->check()));
81     foreach($this->attributes as $attr){
82       $smarty->assign($attr,$this->$attr);
83     }
84     return($smarty -> fetch (get_template_path("../setup/setup_step5.tpl")));
85   }
88   /* Returns the classnames auf the mail classes */
89   function get_available_mail_classes()
90   {
91     $dir = opendir( "../include");
92     $methods = array();
93     $suffix = "class_mail-methods-";
94     $lensuf = strlen($suffix);
95     $prefix = ".inc";
96     $lenpre = strlen($prefix);
97     $i = 0;
98     while (($file = readdir($dir)) !== false){
100       if(stristr($file,$suffix)) {
101         $lenfile = strlen($file);
102         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
103         $methods['file'][$i] = $file;
104         $methods[$i]['file'] = $file;
105         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
106         $i++;
107       }
108     }
109     return($methods); 
110   }
112   function get_themes()
113   {
114     $dir = opendir( "../ihtml/themes/");
115     $themes = array();
116     while (($file = readdir($dir)) !== false){
117       if(is_dir("../ihtml/themes/".$file) && !preg_match("/^\./",$file)){
118         $themes[$file] = $file;
119       }      
120     }
121     return($themes);
122   }
124   function check()
125   {
126     $message = array();
127     if(!is_numeric($this->uidbase)){
128       $message[] = _("Uid base must be numeric");
129     }
131     if(($this->pwd_rules['pwminlen_active']) && !is_numeric($this->pwd_rules['pwminlen'])){
132       $message[] = _("The given password minimum length is not numeric.");
133     }
134     if(($this->pwd_rules['pwdiffer_active']) && !is_numeric($this->pwd_rules['pwdiffer'])){
135       $message[] = _("The given password differ value is not numeric.");
136     }
137     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($_POST[$attr]);
149         }
150       }
152       /* Get password settings */ 
153       if(isset($_POST['pwdiffer_active'])){
154         $this->pwd_rules['pwdiffer_active'] = TRUE;
155         if(isset($_POST['pwdiffer'])){
156           $this->pwd_rules['pwdiffer'] = $_POST['pwdiffer'];
157         }
158       }else{
159         $this->pwd_rules['pwdiffer_active'] = FALSE;
160       }
161       if(isset($_POST['pwminlen_active'])){
162         $this->pwd_rules['pwminlen_active'] = TRUE;
163         if(isset($_POST['pwminlen'])){
164           $this->pwd_rules['pwminlen'] = $_POST['pwminlen'];
165         }
166       }else{
167         $this->pwd_rules['pwminlen_active'] = FALSE;
168       }
170       /* Mail settings */
171       if(isset($_POST['vacationdir_active'])){
172         $this->mail_settings['vacationdir_active'] = TRUE;
173         if(isset($_POST['vacationdir'])){
174           $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
175         }
176       }else{
177         $this->mail_settings['vacationdir_active'] = FALSE;
178       }
179     }
181     $tmp = $this->check(); 
182     if(count($tmp) == 0){
183       $this->is_completed = TRUE;
184     }else{
185       $this->is_completed = FALSE;
186     }
187   }// if tempalte posted 
188 }// CLass
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>