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 = TRUE;
32 var $use_gosa_announce = TRUE;
34 var $feedback_url = "https://oss.gonicus.de/feedback/send.php";
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 /* 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 invetory"));
102 $this->features_used['system'] = array("USED" => FALSE ,
103 "NAME" => _("System-/Configmanagement"));
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 }
117 function execute()
118 {
119 if(!$this->initialized){
120 $this->initialized = TRUE;
121 $this->init();
122 }
124 if(isset($_POST['send_feedback'])){
126 $msgs = $this->check();
127 if(count($msgs)){
128 foreach($msgs as $msg){
129 print_red($msg);
130 }
131 }else{
132 $str = $this->create_serialise_data_string();
133 $feedback_url = $this->feedback_url."?data=".base64_encode($str);
135 $ret = @fopen($feedback_url,"r");
137 if(!$ret){
138 print_red(sprintf(_("Could not connect to feedback server (%s). There is possibly no connection to the internet."),$this->feedback_url));
139 }else{
140 $ret_value="";
141 while($ret && !feof($ret)){
142 $ret_value.= fgets($ret,256);
143 }
144 if(!preg_match("/successfully/i",$ret_value)){
145 print_red(sprintf(_("Could not send feedback. Script said '%s'."),$ret_value));
146 }
147 }
148 @fclose($ret);
149 }
150 }
152 $years = array();
153 for($i = date("Y") ; $i >= 2001; $i--){
154 $years[$i] = $i;
155 }
157 $this->is_completed=TRUE;
158 $smarty = get_smarty();
160 foreach($this->attributes as $attr){
161 $smarty->assign($attr, $this->$attr);
162 }
163 $smarty->assign("years",$years);
164 $smarty->assign("features_used",$this->features_used);
165 $smarty->assign ("must", "<font class=\"must\">*</font>");
166 return($smarty->fetch(get_template_path("setup_feedback.tpl",TRUE,dirname(__FILE__))));
167 }
170 function check()
171 {
172 $msgs = array();
173 if(!is_email($this->eMail) || empty($this->eMail)){
174 $msgs[] = _("Please specify a valid email address.");
175 }
176 return($msgs);
177 }
180 function save_object()
181 {
182 if(isset($_POST['step_feedback'])){
183 foreach($this->attributes as $attr){
184 if(isset($_POST[$attr])){
185 $this->$attr = get_post($attr);
186 }
187 }
189 if(isset($_POST['subscribe'])){
190 $this->subscribe = TRUE;
191 }else{
192 $this->subscribe = FALSE;
193 }
195 if(isset($_POST['use_gosa_announce'])){
196 $this->use_gosa_announce = TRUE;
197 }else{
198 $this->use_gosa_announce = FALSE;
199 }
201 foreach($this->features_used as $key => $data){
202 if(isset($_POST['feature_'.$key])){
203 $this->features_used[$key]['USED'] = TRUE;
204 }else{
205 $this->features_used[$key]['USED'] = FALSE;
206 }
207 }
208 }
209 }
212 function create_serialise_data_string()
213 {
214 $str = "#FEEDBACK ".date("H:i:s d:m:Y");
215 if($this->subscribe){
217 $str.= "\n\nSubscribe";
218 $str .= "\nOrganization: ".$this->organization;
219 $str .= "\nName: ".$this->name;
220 $str .= "\neMail: ".$this->eMail;
221 }
223 if($this->use_gosa_announce){
225 $str.= "\n\nFeedback";
227 if($this->get_started) {
228 $str .= "\nGet started: TRUE";
229 }else{
230 $str .= "\nGet started: FALSE";
231 }
232 $str .= "\nProblems : ".base64_encode($this->problems_encountered);
234 if($this->first_use){
235 $str .= "\nFirst use: TRUE";
236 }else{
237 $str .= "\nFirst use: FALSE";
238 }
239 $str .= "\nUsing GOsa since: ".$this->use_since;
241 $str .="\nDistribution: ".$this->distribution;
242 $str .="\nWeb Server: ".$this->web_server;
243 $str .="\nPHP_Version: ".$this->php_version;
244 $str .="\nLDAP Server: ".$this->ldap_server;
245 $str .="\nObject count: ".$this->object_count;
246 $str .="\nMissing features: ".base64_encode($this->want_to_see_next);
247 }
249 $str .= "\n\nFeatures used";
250 foreach($this->features_used as $name => $data){
251 $str.="\n".$name.": ";
252 if($data['USED']){
253 $str .= "TRUE";
254 }else{
255 $str .= "FALSE";
256 }
257 }
259 return($str);
260 }
261 }
263 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
264 ?>