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 = "";
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;
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 $ldap = new ldapMultiplexer($ldap_l);
85 $ldap->cd($cv['base']);
86 $ldap->search("(objectClass=*)",array("dn"));
87 $this->object_count=$ldap->count();
89 /* Preselect used features */
90 $oc = $ldap->get_objectclasses();
91 $this->features_used = array();
92 $this->features_used['posix'] = array("USED" => isset($oc['posixAccount']) ,
93 "NAME" => _("UNIX accounts/groups"));
94 $this->features_used['samba'] = array("USED" => isset($oc['sambaSamAccount']) || isset($oc['sambaAccount']) ,
95 "NAME" => _("Samba management"));
96 $this->features_used['mail'] = array("USED" => $cv['mail'] != "none",
97 "NAME" => _("Mailsystem management"));
98 $this->features_used['fax'] = array("USED" => isset($oc['goFaxAccount']) ,
99 "NAME" => _("FAX system administration"));
100 $this->features_used['asterisk'] = array("USED" => isset($oc['goFonAccount']),
101 "NAME" => _("Asterisk administration"));
102 $this->features_used['inventory'] = array("USED" => isset($oc['glpiAccount']) ,
103 "NAME" => _("System inventory"));
104 $this->features_used['system'] = array("USED" => FALSE ,
105 "NAME" => _("System-/Configmanagement"));
106 $this->features_used['addressbook'] = array("USED" => FALSE ,
107 "NAME" => _("Addressbook"));
108 }
111 function update_strings()
112 {
113 $this->s_title = _("Notification and feedback");
114 $this->s_info = _("Get notifications or send feedback");
115 $this->s_title_long = _("Notification and feedback");
116 }
119 function execute()
120 {
121 if(!$this->initialized){
122 $this->initialized = TRUE;
123 $this->init();
124 }
126 $additional_info ="";
128 if(isset($_POST['send_feedback'])){
130 $msgs = $this->check_feedback();
131 if(count($msgs)){
132 foreach($msgs as $msg){
133 msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
134 }
135 }else{
136 $str = $this->create_serialise_data_string();
137 $feedback_url = $this->feedback_url."?data=".base64_encode($str);
139 $ret = @fopen($feedback_url,"r");
141 if(!$ret){
142 msg_dialog::display(_("Feedback error"), sprintf(_("Cannot send feedback to '%s': %s"), $this->feedback_url, $ret), ERROR_DIALOG);
143 }else{
144 $ret_value="";
145 while($ret && !feof($ret)){
146 $ret_value.= fgets($ret,256);
147 }
148 if(!preg_match("/successful/i",$ret_value)){
149 msg_dialog::display(_("Feedback error"), _("Cannot send feedback: service temporarily unavailable"), ERROR_DIALOG);
150 }else{
151 $additional_info = "<font color='green'>"._("Feedback sucessfully send")."</font>";
152 }
153 }
154 @fclose($ret);
155 }
156 }
158 $years = array();
159 for($i = date("Y") ; $i >= 2001; $i--){
160 $years[$i] = $i;
161 }
163 $this->is_completed=TRUE;
164 $smarty = get_smarty();
166 foreach($this->attributes as $attr){
167 $smarty->assign($attr, $this->$attr);
168 }
169 $smarty->assign("years",$years);
170 $smarty->assign("features_used",$this->features_used);
171 $smarty->assign("additional_info",$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(!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 .="\nLDAP Server: ".$this->ldap_server;
257 $str .="\nObject count: ".$this->object_count;
258 $str .="\nMissing features: ".($this->want_to_see_next);
259 }
261 $str .= "\n\nFeatures used";
262 foreach($this->features_used as $name => $data){
263 $str.="\n".$name.": ";
264 if($data['USED']){
265 $str .= "TRUE";
266 }else{
267 $str .= "FALSE";
268 }
269 }
271 return($str);
272 }
273 }
275 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
276 ?>