9 $monLibrary = dirname(__FILE__) .
"/../library";
10 $sharedLibrary = dirname(__FILE__) .
"/../../shared/library";
11 $tmpdir =
"/home/homecu/tmp/appreportdata/";
12 $datadir = dirname(__FILE__) .
"/appreportdata/";
15 require_once(
"$monLibrary/cu_top.i");
16 require_once(
"$monLibrary/ck_hticket.i");
17 require_once(
"$sharedLibrary/hcuCommon.i");
18 require_once(
"$sharedLibrary/cu_flagconst.i");
19 require_once(dirname(__FILE__) .
"/appreport_gp_api.prg");
21 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
22 header(
"Location: /hcuadm/hcu_noperm.prg");
30 function ajaxListener()
33 if (isset($_POST[
'functionname'])) {
34 if ($_POST[
'functionname'] ==
'downloadInstalls') {
35 if (isset($_POST[
'submonth']) and isset($_POST[
'cucode'])) {
36 $submonth = $_POST[
'submonth'];
37 $cucode = $_POST[
'cucode'];
38 $date = calculateMonth($submonth);
40 $aResult = downloadInstalls($date, $cucode);
42 throw new exception(
"arguments not set in download installs", 1);
45 elseif ($_POST[
'functionname'] ==
'downloadCrashes') {
46 if (isset($_POST[
'submonth']) and isset($_POST[
'cucode'])) {
47 $submonth = $_POST[
'submonth'];
48 $cucode = $_POST[
'cucode'];
49 $date = calculateMonth($submonth);
51 $aResult = downloadCrashes($date, $cucode);
53 throw new exception(
"arguments not set in download Crashes", 1);
56 elseif ($_POST[
'functionname'] ==
'downloadRatings') {
57 if (isset($_POST[
'submonth']) and isset($_POST[
'cucode'])) {
58 $submonth = $_POST[
'submonth'];
59 $cucode = $_POST[
'cucode'];
60 $date = calculateMonth($submonth);
62 $aResult = downloadRatings($date, $cucode);
64 throw new exception(
"arguments not set in download Ratings", 1);
67 elseif ($_POST[
'functionname'] ==
'view') {
68 if (isset($_POST[
'report_type']) and isset($_POST[
'date']) and isset($_POST[
'cucode'])) {
69 $cucode = $_POST[
'cucode'];
70 $report_type = $_POST[
'report_type'];
71 $date = $_POST[
'date'];
73 $aResult = view($cucode, $report_type, $date);
75 throw new exception(
"arguments not set in view", 1);
79 throw new exception(
"function name not found", 1);
90 function downloadInstalls($date, $cucode)
94 $report_type =
"installs";
95 $file_version =
"_overview.csv";
97 $data_array = downloadCu($cucode, $date, $report_type, $file_version);
98 if ($data_array[
"success"]) {
100 $data_array[
"content"] = getInfo($tmpdir . $report_type . $date, $cucode);
112 function downloadCrashes($date, $cucode)
116 $report_type =
"crashes";
117 $file_version =
"_app_version.csv";
119 $data_array = downloadCu($cucode, $date, $report_type, $file_version);
120 if ($data_array[
"success"]) {
122 $data_array[
"content"] = getInfo($tmpdir . $report_type . $date, $cucode);
134 function downloadRatings($date, $cucode)
138 $report_type =
"ratings";
139 $file_version =
"_app_version.csv";
141 $data_array = downloadCu($cucode, $date, $report_type, $file_version);
142 if ($data_array[
"success"]) {
144 $data_array[
"content"] = getInfo($tmpdir . $report_type . $date, $cucode);
154 function view($cucode, $report_type, $date)
157 $data_array[
"error_message"] =
'';
159 $content = getInfo($tmpdir . $report_type . $date, $cucode);
160 if ($content ==
"no file") {
161 $data_array[
"error_message"] =
'file not found';
163 $data_array[
"content"] = $content;
167 function calculateMonth($submonth){
168 $unformatted_date = strtotime($submonth .
" Months");
169 return date(
"Ym", $unformatted_date);
180 function getInfo($targetdir, $cucode){
182 $handle = fopen ($targetdir .
"/" . $cucode .
".csv",
"r");
183 if($handle ==
false){
return "false";}
184 while ($data = fgetcsv ($handle, 1000,
";")) {
185 $num = count ($data);
186 for ($c=0; $c < $num; $c++) {
188 $content .= mb_convert_encoding($data[$c],
"UTF-8",
"UTF-16") .
"\n";
194 echo HCU_JsonEncode(ajaxListener());