Code

Udpated JS focus,
[gosa.git] / setup / class_setupStep_Feedback.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_Feedback  extends setup_step
24 {
25   var $languages      = array();
26   var $header_image   = "images/welcome.png";
28   var $organization       = "";
29   var $eMail              = "";
30   var $name               = "";
31   var $subscribe          = FALSE;
32   var $use_gosa_announce  = FALSE;
34   var $feedback_url         = "http://oss.gonicus.de/gosa-feedback/";
35   var $get_started          = TRUE;
36   var $problems_encountered = "";
37   
38   var $first_use            = TRUE;
39   var $use_since            = "";
41   var $distribution         = "";
42   var $web_server           = "";
43   var $php_version          = "";
45   var $ldap_server          = "";
46   var $object_count         = "";
47     
48   var $want_to_see_next     = "";
50   var $features_used        = array();  
51   var $initialized          = FALSE; 
53   var $attributes = array("organization","eMail","name","subscribe","use_gosa_announce","get_started","problems_encountered","features_used",
54                           "first_use","use_since","distribution","web_server","php_version","ldap_server","object_count","want_to_see_next");
55   
57   function Step_Feedback()
58   {
59     $this->is_enabled     = TRUE;
60     $this->is_active      = TRUE;
61     $this->update_strings(); 
62   }
65   function init()
66   {
67     $cv = $this->parent->captured_values;
69     /* Initialize values */
70     $this->use_since      = date("Y");
71     $this->organization   = preg_replace("/^[^=]*+=(.*),.*$/","\\1",$cv['base']);
72     $this->distribution   = "";
73     $this->web_server     = $_SERVER['SERVER_SOFTWARE'];
74     $this->php_version    = PHP_VERSION;
76     /* On first call check for rid/sid base */
77     $cv = $this->parent->captured_values;
78     $ldap = new LDAP($cv['admin'],
79         $cv['password'],
80         $cv['connection'],
81         FALSE,
82         $cv['tls']);
83     $ldap->cd($cv['base']);
84     $ldap->search("(objectClass=*)",array("dn"));
85     $this->object_count=$ldap->count();
87     /* Preselect used features */
88     $oc = $ldap->get_objectclasses();
89     $this->features_used                = array();
90     $this->features_used['posix']       = array("USED" => isset($oc['posixAccount']) , 
91                                                 "NAME" => _("UNIX accounts/groups"));
92     $this->features_used['samba']       = array("USED" => isset($oc['sambaSamAccount']) || isset($oc['sambaAccount']) , 
93                                                 "NAME" => _("Samba management"));
94     $this->features_used['mail']        = array("USED" => $cv['mail']  != "none", 
95                                                 "NAME" => _("Mailsystem management"));
96     $this->features_used['fax']         = array("USED" => isset($oc['goFaxAccount']) , 
97                                                 "NAME" => _("FAX system administration"));
98     $this->features_used['asterisk']    = array("USED" => isset($oc['goFonAccount']), 
99                                                 "NAME" => _("Asterisk administration"));
100     $this->features_used['inventory']   = array("USED" => isset($oc['glpiAccount']) , 
101                                                 "NAME" => _("System inventory"));
102     $this->features_used['system']      = array("USED" => FALSE , 
103                                                 "NAME" => _("System / Config management"));
104     $this->features_used['addressbook'] = array("USED" => FALSE , 
105                                                 "NAME" => _("Addressbook"));
106   }
109   function update_strings()
110   {
111     $this->s_title      = _("Notification and feedback");
112     $this->s_info       = _("Get notifications or send feedback");
113     $this->s_title_long = _("Notification and feedback");
114   }
116   
117   function execute()
118   {
119     if(!$this->initialized){
120       $this->initialized = TRUE;
121       $this->init();
122     }
124     $additional_info ="";
126     if(isset($_POST['send_feedback'])){
128       $msgs = $this->check_feedback();
129       if(count($msgs)){
130         foreach($msgs as $msg){
131           print_red($msg);
132         }
133       }else{
134         $str = $this->create_serialise_data_string(); 
135         $feedback_url = $this->feedback_url."?data=".base64_encode($str);
137         $ret = @fopen($feedback_url,"r");
139         if(!$ret){
140           print_red(sprintf(_("Could not connect to feedback server (%s). There is possibly no connection to the internet."),$this->feedback_url));
141         }else{
142           $ret_value="";
143           while($ret && !feof($ret)){
144             $ret_value.= fgets($ret,256);
145           }
146           if(!preg_match("/successful/i",$ret_value)){
147             print_red(_("Error while sending your feedback. The service is possible temporary unavailable"));
148           }else{
149             $additional_info = "<font color='green'>"._("Feedback sucessfully send")."</font>";
150           }
151         }
152         @fclose($ret);
153       }
154     }
156     $years = array();
157     for($i = date("Y") ; $i >= 2001; $i--){
158       $years[$i] = $i;
159     }
161     $this->is_completed=TRUE;
162     $smarty = get_smarty();
164     foreach($this->attributes as $attr){
165       $smarty->assign($attr, $this->$attr);
166     }
167     $smarty->assign("years",$years);
168     $smarty->assign("features_used",$this->features_used);
169     $smarty->assign("additional_info",$additional_info);
170     $smarty->assign ("must", "<font class=\"must\">*</font>");
171     return($smarty->fetch(get_template_path("setup_feedback.tpl",TRUE,dirname(__FILE__))));
172   }
175   function check_feedback()
176   {
177     $msgs = array();
178     if(!is_email($this->eMail) || empty($this->eMail)){
179       $msgs[] = _("Please specify a valid email address.");
180     }
182     if(!$this->subscribe && !$this->use_gosa_announce){
183       $msgs[] = _("You should have enabled at least one option, to subscribe or send your feedback.");
184     }
186     return($msgs);
187   }
188   
190   function save_object()
191   {
192     if(isset($_POST['step_feedback'])){
193       foreach($this->attributes as $attr){
194         if(isset($_POST[$attr])){
195           $this->$attr = get_post($attr);
196         }
197       }
199       if(isset($_POST['subscribe'])){
200         $this->subscribe = TRUE;
201       }else{
202         $this->subscribe = FALSE;
203       }
205       if(isset($_POST['use_gosa_announce'])){
206         $this->use_gosa_announce = TRUE;
207       }else{
208         $this->use_gosa_announce = FALSE;
209       }
210     
211       foreach($this->features_used as $key => $data){
212         if(isset($_POST['feature_'.$key])){
213           $this->features_used[$key]['USED'] = TRUE;
214         }else{
215           $this->features_used[$key]['USED'] = FALSE;
216         }
217       }
218     }
219   }
222   function create_serialise_data_string()
223   {
224     $str = "#FEEDBACK ".date("H:i:s d:m:Y");
225     if($this->subscribe){
227       $str.= "\n\nSubscribe";
228       $str .= "\nOrganization: ".$this->organization; 
229       $str .= "\nName: ".$this->name;
230       $str .= "\neMail: ".$this->eMail;
231     }
232   
233     if($this->use_gosa_announce){
235       $str.= "\n\nFeedback";    
236   
237       if($this->get_started) {
238         $str .= "\nGet started: TRUE";
239       }else{
240         $str .= "\nGet started: FALSE";
241       }
242       $str .= "\nProblems : ".base64_encode($this->problems_encountered);
244       if($this->first_use){
245         $str .= "\nFirst use: TRUE";
246       }else{
247         $str .= "\nFirst use: FALSE";
248       }
249       $str .= "\nUsing GOsa since: ".$this->use_since;
251       $str .="\nDistribution: ".$this->distribution;
252       $str .="\nWeb Server: ".$this->web_server;
253       $str .="\nPHP_Version: ".$this->php_version;
254       $str .="\nLDAP Server: ".$this->ldap_server;
255       $str .="\nObject count: ".$this->object_count;
256       $str .="\nMissing features: ".base64_encode($this->want_to_see_next);
257     }
259     $str .= "\n\nFeatures used";
260     foreach($this->features_used as $name => $data){
261       $str.="\n".$name.": ";
262       if($data['USED']){
263         $str .= "TRUE";
264       }else{
265         $str .= "FALSE";
266       }
267     }
269     return($str);  
270   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>