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 = "";
44 var $gosa_version = "";
46 var $ldap_server = "";
47 var $object_count = "";
49 var $want_to_see_next = "";
51 var $features_used = array();
52 var $initialized = FALSE;
53 var $feedback_send = FALSE;
54 var $attributes = array("organization","eMail","name","subscribe","use_gosa_announce","get_started","problems_encountered","features_used",
55 "first_use","use_since","distribution","web_server","php_version","ldap_server","object_count","want_to_see_next","gosa_version");
58 function Step_Feedback()
59 {
60 $this->is_enabled = TRUE;
61 $this->is_active = TRUE;
62 $this->update_strings();
63 }
66 function init()
67 {
68 $cv = $this->parent->captured_values;
70 /* Initialize values */
71 $this->use_since = date("Y");
72 $this->organization = preg_replace("/^[^=]*+=(.*),.*$/","\\1",$cv['base']);
73 $this->distribution = "";
74 $this->web_server = $_SERVER['SERVER_SOFTWARE'];
75 $this->php_version = PHP_VERSION;
76 $this->gosa_version = get_gosa_version(FALSE);
78 /* Establish ldap connection */
79 $cv = $this->parent->captured_values;
80 $ldap_l = new LDAP($cv['admin'],
81 $cv['password'],
82 $cv['connection'],
83 FALSE,
84 $cv['tls']);
86 $this->object_count= "";
87 $ldap = new ldapMultiplexer($ldap_l);
88 $ldap->cd($cv['base']);
90 /* Preselect used features */
91 $oc = $ldap->get_objectclasses();
92 $this->features_used = array();
93 $this->features_used['posix'] = array("USED" => isset($oc['posixAccount']) ,
94 "NAME" => _("UNIX accounts/groups"));
95 $this->features_used['samba'] = array("USED" => isset($oc['sambaSamAccount']) || isset($oc['sambaAccount']) ,
96 "NAME" => _("Samba management"));
97 $this->features_used['mail'] = array("USED" => FALSE,
98 "NAME" => _("Mailsystem management"));
99 $this->features_used['fax'] = array("USED" => isset($oc['goFaxAccount']) ,
100 "NAME" => _("FAX system administration"));
101 $this->features_used['asterisk'] = array("USED" => isset($oc['goFonAccount']),
102 "NAME" => _("Asterisk administration"));
103 $this->features_used['inventory'] = array("USED" => isset($oc['glpiAccount']) ,
104 "NAME" => _("System inventory"));
105 $this->features_used['system'] = array("USED" => FALSE ,
106 "NAME" => _("System-/Configmanagement"));
107 $this->features_used['addressbook'] = array("USED" => FALSE ,
108 "NAME" => _("Addressbook"));
109 }
112 function update_strings()
113 {
114 $this->s_title = _("Feedback");
115 $this->s_info = _("Get notifications or send feedback");
116 $this->s_title_long = _("Notification and feedback");
117 }
120 function execute()
121 {
122 if(!$this->initialized){
123 $this->initialized = TRUE;
124 $this->init();
125 }
126 $additional_info ="";
127 if(isset($_POST['send_feedback'])){
129 $msgs = $this->check_feedback();
130 if(count($msgs)){
131 foreach($msgs as $msg){
132 msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
133 }
134 }else{
135 $str = $this->create_serialise_data_string();
136 $feedback_url = $this->feedback_url."?data=".urlencode(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("gosa_version",$this->gosa_version);
168 $smarty->assign("feedback_send",$this->feedback_send);
169 $smarty->assign("years",$years);
170 $smarty->assign("features_used",$this->features_used);
171 $smarty->assign("additional_info", reverse_html_entities($additional_info));
172 $smarty->assign ("must", "<font class=\"must\">*</font>");
173 return($smarty->fetch(get_template_path("setup_feedback.tpl",TRUE,dirname(__FILE__))));
174 }
177 function check_feedback()
178 {
179 $msgs = array();
180 if($this->subscribe && (!tests::is_email($this->eMail) || empty($this->eMail))){
181 $msgs[] = _("Please specify a valid email address.");
182 }
184 if(!$this->subscribe && !$this->use_gosa_announce){
185 $msgs[] = _("You have to select at least one of both options, subscribe or send feedback.");
186 }
188 return($msgs);
189 }
192 function save_object()
193 {
194 if(isset($_POST['step_feedback'])){
195 foreach($this->attributes as $attr){
196 if(isset($_POST[$attr])){
197 $this->$attr = get_post($attr);
198 }
199 }
201 if(isset($_POST['subscribe'])){
202 $this->subscribe = TRUE;
203 }else{
204 $this->subscribe = FALSE;
205 }
207 if(isset($_POST['use_gosa_announce'])){
208 $this->use_gosa_announce = TRUE;
209 }else{
210 $this->use_gosa_announce = FALSE;
211 }
213 foreach($this->features_used as $key => $data){
214 if(isset($_POST['feature_'.$key])){
215 $this->features_used[$key]['USED'] = TRUE;
216 }else{
217 $this->features_used[$key]['USED'] = FALSE;
218 }
219 }
220 }
221 }
224 function create_serialise_data_string()
225 {
226 $str = "#FEEDBACK ".date("H:i:s d:m:Y");
227 if($this->subscribe){
229 $str.= "\n\nSubscribe";
230 $str .= "\nOrganization: ".$this->organization;
231 $str .= "\nName: ".$this->name;
232 $str .= "\neMail: ".$this->eMail;
233 }
235 if($this->use_gosa_announce){
237 $str.= "\n\nFeedback";
239 if($this->get_started) {
240 $str .= "\nGet started: TRUE";
241 }else{
242 $str .= "\nGet started: FALSE";
243 }
244 $str .= "\nProblems : ".($this->problems_encountered);
246 if($this->first_use){
247 $str .= "\nFirst use: TRUE";
248 }else{
249 $str .= "\nFirst use: FALSE";
250 }
251 $str .= "\nUsing GOsa since: ".$this->use_since;
253 $str .="\nDistribution: ".$this->distribution;
254 $str .="\nWeb Server: ".$this->web_server;
255 $str .="\nPHP_Version: ".$this->php_version;
256 $str .="\nGOsa_Version: ".strip_tags($this->gosa_version);
257 $str .="\nLDAP Server: ".$this->ldap_server;
258 $str .="\nObject count: ".$this->object_count;
259 $str .="\nMissing features: ".($this->want_to_see_next);
260 }
262 $str .= "\n\nFeatures used";
263 foreach($this->features_used as $name => $data){
264 $str.="\n".$name.": ";
265 if($data['USED']){
266 $str .= "TRUE";
267 }else{
268 $str .= "FALSE";
269 }
270 }
272 return($str);
273 }
274 }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>