d655c2e5e79d756cc72786eff4b9e6db1af16df8
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/setup/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 = "";
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 = "";
48 var $want_to_see_next = "";
50 var $features_used = array();
51 var $initialized = FALSE;
52 var $feedback_send = 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");
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 /* Establish ldap connection */
77 $cv = $this->parent->captured_values;
78 $ldap_l = new LDAP($cv['admin'],
79 $cv['password'],
80 $cv['connection'],
81 FALSE,
82 $cv['tls']);
84 $this->object_count= "";
85 $ldap = new ldapMultiplexer($ldap_l);
86 $ldap->cd($cv['base']);
88 /* Preselect used features */
89 $oc = $ldap->get_objectclasses();
90 $this->features_used = array();
91 $this->features_used['posix'] = array("USED" => isset($oc['posixAccount']) ,
92 "NAME" => _("UNIX accounts/groups"));
93 $this->features_used['samba'] = array("USED" => isset($oc['sambaSamAccount']) || isset($oc['sambaAccount']) ,
94 "NAME" => _("Samba management"));
95 $this->features_used['mail'] = array("USED" => $cv['mail'] != "none",
96 "NAME" => _("Mailsystem management"));
97 $this->features_used['fax'] = array("USED" => isset($oc['goFaxAccount']) ,
98 "NAME" => _("FAX system administration"));
99 $this->features_used['asterisk'] = array("USED" => isset($oc['goFonAccount']),
100 "NAME" => _("Asterisk administration"));
101 $this->features_used['inventory'] = array("USED" => isset($oc['glpiAccount']) ,
102 "NAME" => _("System inventory"));
103 $this->features_used['system'] = array("USED" => FALSE ,
104 "NAME" => _("System-/Configmanagement"));
105 $this->features_used['addressbook'] = array("USED" => FALSE ,
106 "NAME" => _("Addressbook"));
107 }
110 function update_strings()
111 {
112 $this->s_title = _("Feedback");
113 $this->s_info = _("Get notifications or send feedback");
114 $this->s_title_long = _("Notification and feedback");
115 }
118 function execute()
119 {
120 if(!$this->initialized){
121 $this->initialized = TRUE;
122 $this->init();
123 }
125 $additional_info ="";
126 if(isset($_POST['send_feedback'])){
128 $msgs = $this->check_feedback();
129 if(count($msgs)){
130 foreach($msgs as $msg){
131 msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
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 msg_dialog::display(_("Feedback error"), sprintf(_("Cannot send feedback to '%s': %s"), $this->feedback_url, $ret), ERROR_DIALOG);
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 msg_dialog::display(_("Feedback error"), _("Cannot send feedback: service temporarily unavailable"), ERROR_DIALOG);
148 }else{
149 $this->feedback_send = TRUE;
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, reverse_html_entities($this->$attr));
166 }
167 $smarty->assign("feedback_send",$this->feedback_send);
168 $smarty->assign("years",$years);
169 $smarty->assign("features_used",$this->features_used);
170 $smarty->assign("additional_info", reverse_html_entities($additional_info));
171 $smarty->assign ("must", "<font class=\"must\">*</font>");
172 return($smarty->fetch(get_template_path("setup_feedback.tpl",TRUE,dirname(__FILE__))));
173 }
176 function check_feedback()
177 {
178 $msgs = array();
179 if($this->subscribe && (!tests::is_email($this->eMail) || empty($this->eMail))){
180 $msgs[] = _("Please specify a valid email address.");
181 }
183 if(!$this->subscribe && !$this->use_gosa_announce){
184 $msgs[] = _("You have to select at least one of both options, subscribe or send feedback.");
185 }
187 return($msgs);
188 }
191 function save_object()
192 {
193 if(isset($_POST['step_feedback'])){
194 foreach($this->attributes as $attr){
195 if(isset($_POST[$attr])){
196 $this->$attr = get_post($attr);
197 }
198 }
200 if(isset($_POST['subscribe'])){
201 $this->subscribe = TRUE;
202 }else{
203 $this->subscribe = FALSE;
204 }
206 if(isset($_POST['use_gosa_announce'])){
207 $this->use_gosa_announce = TRUE;
208 }else{
209 $this->use_gosa_announce = FALSE;
210 }
212 foreach($this->features_used as $key => $data){
213 if(isset($_POST['feature_'.$key])){
214 $this->features_used[$key]['USED'] = TRUE;
215 }else{
216 $this->features_used[$key]['USED'] = FALSE;
217 }
218 }
219 }
220 }
223 function create_serialise_data_string()
224 {
225 $str = "#FEEDBACK ".date("H:i:s d:m:Y");
226 if($this->subscribe){
228 $str.= "\n\nSubscribe";
229 $str .= "\nOrganization: ".$this->organization;
230 $str .= "\nName: ".$this->name;
231 $str .= "\neMail: ".$this->eMail;
232 }
234 if($this->use_gosa_announce){
236 $str.= "\n\nFeedback";
238 if($this->get_started) {
239 $str .= "\nGet started: TRUE";
240 }else{
241 $str .= "\nGet started: FALSE";
242 }
243 $str .= "\nProblems : ".($this->problems_encountered);
245 if($this->first_use){
246 $str .= "\nFirst use: TRUE";
247 }else{
248 $str .= "\nFirst use: FALSE";
249 }
250 $str .= "\nUsing GOsa since: ".$this->use_since;
252 $str .="\nDistribution: ".$this->distribution;
253 $str .="\nWeb Server: ".$this->web_server;
254 $str .="\nPHP_Version: ".$this->php_version;
255 $str .="\nLDAP Server: ".$this->ldap_server;
256 $str .="\nObject count: ".$this->object_count;
257 $str .="\nMissing features: ".($this->want_to_see_next);
258 }
260 $str .= "\n\nFeatures used";
261 foreach($this->features_used as $name => $data){
262 $str.="\n".$name.": ";
263 if($data['USED']){
264 $str .= "TRUE";
265 }else{
266 $str .= "FALSE";
267 }
268 }
270 return($str);
271 }
272 }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>