summaryrefslogtreecommitdiffstats
path: root/admin/exportclases/class.xlsIzvozTextAnalysis.php
blob: bf6e65cd8d49be951e04a5dd37e3023d2742ce98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php		

global $site_path;
	
	include_once('../../function.php');
	include_once('../survey/definition.php');
	include_once('../exportclases/class.xls.php');	
	
class XlsIzvozTextAnalysis {		

	var $anketa;							// trenutna anketa
	var $pi = array('canCreate'=>false); 	// za shrambo parametrov in sporocil
	
	
	/**
    * @desc konstruktor
    */
	function __construct ($anketa = null){
		global $site_path;
		global $global_user_id;
		global $output;

		// preverimo ali imamo stevilko ankete
		if ( is_numeric($anketa) ){
			
			$this->anketa['id'] = $anketa;
			
			// create new XLS document
			$this->xls = new xls();
						
			$_POST['podstran'] = 'text_analysis';
		}
		else{
			$this->pi['msg'] = "Anketa ni izbrana!";
			$this->pi['canCreate'] = false;
			return false;
		}
		
		if (SurveyInfo::getInstance()->SurveyInit($this->anketa['id'])){
			$this->anketa['uid'] = $global_user_id;
		}
		else
			return false;
		// ce smo prisli do tu je vse ok
		$this->pi['canCreate'] = true;

		return true;
	}

	function getAnketa(){
		return $this->anketa['id']; 
	}

	function checkCreate(){
		return $this->pi['canCreate'];
	}

	function getFile($fileName){
		$output = $this->createXls();
		$this->xls->display($fileName, $output);
	}


	function createXls(){
		global $site_path;
		global $lang;
		global $output;
		
		$convertTypes = array('charSet'	=> "windows-1250",
						 'delimit'	=> ";",
						 'newLine'	=> "\n",
						 'BOMchar'	=> "\xEF\xBB\xBF");
		
		$output = $convertTypes['BOMchar'];
		
		// Dobimo podatke
		$STA = new SurveyTextAnalysis($this->anketa['id']);
		$data = $STA->getData();
		
		// Tabela vsot znakov po straneh
		$output .= '<table border="0"><tr><td colspan="10"><font size="3"><b>'.$lang['srv_text_analysis_title1'].'</b></font></td></tr></table>';						
		$this->displayGrupaTable($data);	

		$output .= '<table border="0"><tr><td></td></tr></table>';
		$output .= '<table border="0"><tr><td colspan="10"><font size="3"><b>'.$lang['srv_text_analysis_title2'].'</b></font></td></tr></table>';	
		
		// Tabela znakov po vprasanjih in vrednostih
		$this->displaySprTable($data);		
		
		return $output;
	}
	
	function  displayGrupaTable($data){
		global $site_path;
		global $lang;
		global $output;		
		
		$output .= '<table border="1" cellpadding="0" cellspacing="0">';
		
		// Header row
		$output .= '<tr>';
		
		$output .= '<th style="width:120px;">'.$lang['srv_text_analysis_page'].'</th>';
		$output .= '<th style="width:120px;">'.$lang['srv_text_analysis_question'].'</th>';
		
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCount'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCountBlank'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCountHTML'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_wordCount'].'</th>';
	
		$output .= '</tr>';	

		// Loop po straneh v anketi
		foreach($data['grupe'] as $gru_id => $grupa){
			
			// Loop po vprasanjih na strani
			foreach($grupa['spremenljivke'] as $spr_id => $spremenljivka){
			
				$output .= '<tr>';

				$output .= '<td align="center">'.$grupa['naslov'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['variable'].'</td>';
				
				$output .= '<td align="center">'.$spremenljivka['sum_char_count'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['sum_char_count_noBlank'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['sum_char_count_html'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['sum_word_count'].'</td>';

				$output .= '</tr>';
			}		
			
			// Vsota znakov na strani
			$output .= '<tr class="sum">';

			$output .= '<td align="center">'.$grupa['naslov'].'</td>';
			$output .= '<td align="center">'.$lang['srv_text_analysis_sum'].'</td>';
			
			$output .= '<td align="center">'.$grupa['sum_char_count'].'</td>';
			$output .= '<td align="center">'.$grupa['sum_char_count_noBlank'].'</td>';
			$output .= '<td align="center">'.$grupa['sum_char_count_html'].'</td>';
			$output .= '<td align="center">'.$grupa['sum_word_count'].'</td>';

			$output .= '</tr>';
		}
		
		// Vsota znakov v anketi
		$output .= '<tr class="sum">';

		$output .= '<td align="center"></td>';
		$output .= '<td align="center">'.$lang['srv_text_analysis_sumSurvey'].'</td>';
		
		$output .= '<td align="center">'.$data['sum_char_count'].'</td>';
		$output .= '<td align="center">'.$data['sum_char_count_noBlank'].'</td>';
		$output .= '<td align="center">'.$data['sum_char_count_html'].'</td>';
		$output .= '<td align="center">'.$data['sum_word_count'].'</td>';

		$output .= '</tr>';
			
		$output .= '</table>';
	}
	
	function  displaySprTable($data){
		global $site_path;
		global $lang;
		global $output;						
		
		$output .= '<table border="1" cellpadding="0" cellspacing="0">';
		
		// Header row
		$output .= '<tr>';
		
		$output .= '<th style="width:120px;">'.$lang['srv_text_analysis_page'].'</th>';
		$output .= '<th style="width:120px;">'.$lang['srv_text_analysis_question'].'</th>';
		$output .= '<th style="width:120px;">'.$lang['srv_text_analysis_value'].'</th>';
		$output .= '<th>'.$lang['srv_text_analysis_text'].'</th>';
		
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCount'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCountBlank'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_charCountHTML'].'</th>';
		$output .= '<th style="width:130px;">'.$lang['srv_text_analysis_wordCount'].'</th>';
	
		$output .= '</tr>';	

		// Loop po straneh v anketi
		foreach($data['grupe'] as $gru_id => $grupa){
			
			// Loop po vprasanjih na strani
			foreach($grupa['spremenljivke'] as $spr_id => $spremenljivka){
			
				$output .= '<tr class="colored">';

				$output .= '<td align="center">'.$grupa['naslov'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['variable'].'</td>';
				$output .= '<td></td>';
				
				$naslov = strip_tags($spremenljivka['naslov']);
				$naslov = ($spremenljivka['char_count'] > 50) ? substr($naslov, 0, 47).'...' : $naslov; 
				$output .= '<td>'.$naslov.'</td>';
				
				$output .= '<td align="center">'.$spremenljivka['char_count'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['char_count_noBlank'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['char_count_html'].'</td>';
				$output .= '<td align="center">'.$spremenljivka['word_count'].'</td>';

				$output .= '</tr>';
			
				// Loop po vrednostih v vprasanju
				foreach($spremenljivka['vrednosti'] as $vre_id => $vrednost){
					
					$output .= '<tr>';
					
					$output .= '<td align="center">'.$grupa['naslov'].'</td>';
					$output .= '<td align="center">'.$spremenljivka['variable'].'</td>';
					$output .= '<td align="center">'.$vrednost['variable'].'</td>';
					
					$naslov = strip_tags($vrednost['naslov']);
					$naslov = ($vrednost['char_count'] > 50) ? substr($naslov, 0, 47).'...' : $naslov; 
					$output .= '<td>'.$naslov.'</td>';
					
					$output .= '<td align="center">'.$vrednost['char_count'].'</td>';
					$output .= '<td align="center">'.$vrednost['char_count_noBlank'].'</td>';
					$output .= '<td align="center">'.$vrednost['char_count_html'].'</td>';
					$output .= '<td align="center">'.$vrednost['word_count'].'</td>';
					
					$output .= '</tr>';
				}
			}		
		}
			
		$output .= '</table>';	
	}
	
	
	function encodeText($text)
	{ 
		// popravimo sumnike ce je potrebno
		$stringIn = array("&#269;","&#353;","&#273;","&#263;","&#382;","&#268;","&#352;","&#272;","&#262;","&#381;","&nbsp;");
		$stringOut = array("č","š","đ","ć","ž","Č","Š","Đ","Ć","Ž"," ");
	
		//$text = html_entity_decode($text, ENT_NOQUOTES, 'UTF-8');
		$text = str_replace($stringIn, $stringOut, $text);
		return $text;
	}
	
	function enkaEncode($text)
	{ // popravimo sumnike ce je potrebno
		$text = html_entity_decode($text, ENT_NOQUOTES, 'UTF-8');
		return strip_tags($text);
	}	
	
	function formatNumber ($value, $digit = 0, $sufix = "") {
		if ($value <> 0 && $value != null)
			$result = round($value, $digit);
		else
			$result = "0";
		//$result = number_format($result, $digit, '.', ',') . $sufix;
		$result = number_format($result, $digit, ',', '') . $sufix;

		return $result;
	}
	
}

?>