Odyssey
appreport_gp_client.prg
1 <?php
2 
3 /*******************************************************
4  *file: appreport_gp_client.prg
5  *notes: this file is used to populate the UI for loading
6  *Creates a HTML/Kendo interface in the tools category of
7  monitor. With this interface one can select/type different
8  credit unions and observe the installation,ratings,and crash
9  statistics. This client file constructs the interface and
10  requests different calls depending on what tab was chosen
11  and what CU was chosen.
12  ********************************************************/
13 
14 $monLibrary = dirname(__FILE__) . "/../library";
15 $datadir = dirname(__FILE__) . "/appreportdata/";
16 require_once("$monLibrary/cu_top.i");
17 require_once("$monLibrary/ck_hticket.i");
18 require_once("$monLibrary/cu_pass.i");
19 require_once("$monLibrary/monitorView.i");
20 
21 if (!CheckPerm($link, $Hu, "appReport", $_SERVER['REMOTE_ADDR'])) {
22  header("Location: /hcuadm/hcu_noperm.prg");
23  exit;
24 }
25 
26 printMonitorPageTop("App Report (Google Play)", $homecuKendoVersion, $cloudfrontDomainName, $bootstrapVersion, $fontawesomeVersion, true);
27 printMonitorPageMiddle("App Report (Google Play)", null);
28 
29 //pulls all credit unions that are labeled as having an android app
30 $sql = "SELECT user_name FROM cuproducts WHERE home_cu_code='MBLADA'";
31 
32 $product_rs = db_query($sql, $link);
33 $productList = array();
34 $row_cnt = 0;
35 while ($product_row = db_fetch_array($product_rs, $row_cnt++)) {
36  array_push($productList, trim($product_row["user_name"]));
37 }
38 ?>
39 <html>
40 <head>
41  <meta name="viewport" content="width=device-width, initial-scale=1">
42  <link rel="stylesheet" type="text/css" href="/monitor/css/gp_main.css">
43  <link rel="shortcut icon" href="">
44 </head>
45 <body>
46  <div id="reportContainer">
47  <h2>Google Play Data</h2>
48  <div id="tabstrip">
49  <ul>
50  <li class="k-state-active">
51  Installs
52  </li>
53  <li>
54  Crashes
55  </li>
56  <li>
57  Ratings
58  </li>
59  </ul>
60  <div>
61  <input id="cuInstallsDrop" class="cuDrop" style="width: 200px;" />
62  <input id="installsDate" class="date" value="0" style="width: 200px;" />
63  <button class="btn" id="downloadInstallsbtn" onclick="downloadInstallData('1')" style="width:150px;">Download</button>
64  <textarea rows="15" cols="65" id="installsView" readonly></textarea>
65  <p></p>
66  </div>
67  <div>
68  <input id="cuCrashesDrop" class="cuDrop" style="width: 200px;" />
69  <input id="crashesDate" class="date" value="0" style="width: 200px;" />
70  <button class="btn" id="downloadCrashesbtn" onclick="downloadCrashesData('2')" style="width:150px;">Download</button>
71  <textarea rows="15" cols="65" id="crashesView" readonly></textarea>
72  <div id="crashes_loader" class="loader"></div>
73  </div>
74  <div>
75  <input id="cuReviewsDrop" class="cuDrop" style="width: 200px;" />
76  <input id="reviewsDate" class="date" value="0" style="width: 200px;" />
77  <button class="btn" id="downloadRatingsbtn" onclick="downloadRatingsData('3')" style="width:150px;">Download</button>
78  <textarea rows="15" cols="65" id="ratingsView" readonly></textarea>
79  <div id="reviews_loader" class="loader"></div>
80  </div>
81  </div>
82  </div>
83  <div id="snackbar"></div>
84  <script></script>
85 
86  <!-- start of script using kendo elementss-->
87  <script type=text/javascript>
88  var gpappreportserverurl="appreport_gp_server.prg"
89  var crashesGrid; var reviewsGrid; /* *Initialization of Kendo UI Elements on start */
90 
91  $(document).ready(function() {
92  hideload(); //initialize tabs
93  $("#tabstrip").kendoTabStrip({ animation: { open: { effects: "fadeIn" } } });
94 
95  //date dropdown data
96  var date_data=getDateDDL();
97  //grab cu dropdown data
98  var cu_kendo_datasource=getCUDDL();
99 
100  $(".cuDrop").kendoAutoComplete({
101  dataSource: cu_kendo_datasource,
102  filter: "startswith",
103  placeholder: "Select CU...",
104  });
105 
106  $(".date").kendoDropDownList({
107  dataTextField: "text" ,
108  dataValueField: "value" ,
109  dataSource: date_data,
110  index: 0,
111  });
112 
113  //make all buttons kendo buttons
114  $(".btn").kendoButton();
115  });
116  /* *gets pre-created list of cu's from db to insert into dropdown */
117  function getCUDDL(){
118  var cu_data=<?php echo json_encode($productList); ?>;
119  var cu_kendo_datasource=[];
120  for(var i=0; i < cu_data.length; i++){
121  cu_kendo_datasource.push(cu_data[i]);
122  }
123  return cu_kendo_datasource;
124  }
125 
126  function getDateDDL(){
127  return [{ text: "Current Month" , value: "0" },
128  { text: "Previous Month" , value: "-1" },
129  { text: "2 Months ago" , value: "-2" },
130  { text: "3 Months ago" , value: "-3" }];
131  }
132  /** * ajax call to grab CU install data from server
133  * * @param option specifies report type
134  */
135  function downloadInstallData(option){
136  disableDownloadButtons();
137  submonth=$("#installsDate").val();
138  cucode=$("#cuInstallsDrop").val();
139  cucode=cucode.toLowerCase();
140  install_data={ "functionname" : "downloadInstalls" , "cucode" : cucode, "submonth" : submonth, "option" : option };
141  if( cucode=="" ){
142  snackybar("Please select Cucode");
143  populateText("installsView", "" );
144  hideload();
145  enableDownloadButtons();
146  return;
147  } // return ajax caller instance
148  $.ajax({
149  type: "POST" ,
150  url: gpappreportserverurl, // sent to appreport_gp_server.prg
151  data: install_data,
152  dataType: "json"
153 
154  }).done(function (response) {
155  if(Object.keys(response["error_message"]).length> 0){
156  snackybar(response["error_message"]);
157  populateText("installsView", "");
158  enableDownloadButtons();
159  return;
160  }
161  populateText("installsView", response["content"]);
162 
163  }).fail(function (response) {
164  populateText("installsView", "");
165  console.log(response);
166  }).always(function (response) {
167  enableDownloadButtons();
168  });
169  }
170 
171  /** * ajax call to grab CU crash data from server
172  * * @param option specifies report type
173  */
174  function downloadCrashesData(option){
175  disableDownloadButtons();
176  submonth=$("#crashesDate").val();
177  cucode=$("#cuCrashesDrop").val();
178  crash_data={ "functionname" : "downloadCrashes" , "cucode" : cucode, "submonth" : submonth, "option" : option };
179  if( cucode=="" ){
180  snackybar("Please select Cucode");
181  populateText("crashesView", "" );
182  hideload();
183  enableDownloadButtons();
184  return;
185  } // return ajax caller instance
186  $.ajax({
187  type: "POST" ,
188  url: gpappreportserverurl, // sent to appreport_gp_server.prg
189  data: crash_data,
190  dataType: "json"
191 
192  }).done(function (response) {
193  if(Object.keys(response["error_message"]).length> 0){
194  snackybar(response["error_message"]);
195  populateText("crashesView", "");
196  enableDownloadButtons();
197  return;
198  }
199  populateText("crashesView", response["content"]);
200 
201  }).fail(function (response) {
202  populateText("crashesView", "");
203  console.log(response);
204  }).always(function (response) {
205  enableDownloadButtons();
206  });
207  }
208 
209  /** * ajax call to grab CU crash data from server
210  * * @param option specifies report type
211  */
212  function downloadRatingsData(option){
213  disableDownloadButtons();
214  submonth=$("#reviewsDate").val();
215  cucode=$("#cuReviewsDrop").val();
216  ratings_data={ "functionname" : "downloadRatings" , "cucode" : cucode, "submonth" : submonth, "option" : option };
217  if( cucode=="" ){
218  snackybar("Please select Cucode");
219  populateText("ratingsView", "" );
220  hideload();
221  enableDownloadButtons();
222  return;
223  } // return ajax caller instance
224  $.ajax({
225  type: "POST" ,
226  url: gpappreportserverurl, // sent to appreport_gp_server.prg
227  data: ratings_data,
228  dataType: "json"
229 
230  }).done(function (response) {
231  if( Object.keys(response["error_message"]).length> 0){
232  snackybar(response["error_message"]);
233  populateText("ratingsView", "");
234  enableDownloadButtons();
235  return;
236  }
237  populateText("ratingsView", response["content"]);
238 
239  }).fail(function (response) {
240  populateText("ratingsView", "");
241  console.log(response);
242  }).always(function (response) {
243  enableDownloadButtons();
244  });
245  }
246 
247 /**
248  * Hides loader animation
249 */
250 function hideload(){
251  document.getElementById("crashes_loader").style.display = "none";
252  document.getElementById("reviews_loader").style.display = "none";
253  //function for pulling date on load
254 }//preloader
255 
256 /**
257  * populates top text area with data specified in parameters
258  *
259  * @param id specifies which text aread to populate
260  * @param data data that will populate text area
261 */
262 function populateText(id, data){
263  document.getElementById(id).innerHTML=data;
264 }
265 
266 /**
267  * shows loading animation
268  *
269  * @param option specifies which tab to show loader
270  */
271 function showloader(option){
272  if(parseInt(option)==2){
273  document.getElementById("crashes_loader").style.display = "block";
274  }else if(parseInt(option)==3){
275  document.getElementById("reviews_loader").style.display = "block";
276  }
277 }
278 
279 /**
280  * shows tab. used for reloading pages // not used anymore since using jquery
281  *
282  * @param option specifies tab
283 */
284 function showTab(option){
285  if(option==1){
286  document.getElementById('installstab').click();
287  }else if(option ==2){
288  document.getElementById('crashestab').click();
289  }else{
290  document.getElementById('reviewstab').click();
291  }
292 }
293 
294 /**
295  * function used for built in alert system
296  *
297  * @param content message to be posted
298 */
299 function snackybar(content){
300  // Get the snackbar DIV
301  var x = document.getElementById("snackbar");
302  x.innerHTML=content;
303  // Add the "show" class to DIV
304  x.className = "show";
305  // After 3 seconds, remove the show class from DIV
306  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
307 }
308  function disableDownloadButtons(){
309  $("#downloadInstallsbtn").data("kendoButton").enable(false);
310  $("#downloadCrashesbtn").data("kendoButton").enable(false);
311  $("#downloadRatingsbtn").data("kendoButton").enable(false);
312  }
313  function enableDownloadButtons(){
314  $("#downloadInstallsbtn").data("kendoButton").enable(true);
315  $("#downloadCrashesbtn").data("kendoButton").enable(true);
316  $("#downloadRatingsbtn").data("kendoButton").enable(true);
317  }
318  </script>
319 </body>
320 </html>