';
if(!$Cache->isInCache($ID, $DataSet->GetData())){
$graph = SurveyChart::createLine($DataSet, null, 1);
$Cache->WriteToCache($ID,$DataSet->GetData(),$graph);
}
// dobimo ime slike c cache-u
$imgName = $Cache->GetHash($ID,$DataSet->GetData());
$imgPath = 'pChart/Cache/'.$imgName;
$imgUrl = $site_url . 'admin/survey/' . $imgPath;
echo '
';
// dodamo timestamp ker browser shrani sliko v cache in jo v dolocenih primerih ajaxa ne refresha
echo '';
echo '
';
}
/**
* Run querry for action times
* @param type $status - int of status
* @param type $interval - where clause for time interval
* @return type array of results from DB
*/
function graphQuery($status, $interval){
$sql2 = "SELECT min(DATE_FORMAT(st.datetime, '%Y-%m-%d')) as first_date, max(DATE_FORMAT(st.datetime, '%Y-%m-%d')) as last_date"
. " FROM srv_tracking$this->db_table st, users u WHERE st.ank_id='$this->anketa' AND u.id = st.user ".
($status != -1 ? "AND st.status=$status " : "") ."$interval ";
$output2=sisplet_query($sql2, 'obj');
$diff = $this->differDateTimeInDays(new DateTime($output2->first_date), new DateTime($output2->last_date));
$queryDayFormat = '';
$queryDayGroup = '';
if($diff < 32){
$queryDayFormat = '-%d';
$queryDayGroup = ', DAY(st.datetime)';
}
$sql = "SELECT count(*) as cnt, u.email, u.id, DATE_FORMAT(st.datetime, '%Y-%m$queryDayFormat') as date"
. " FROM srv_tracking$this->db_table st, users u WHERE st.ank_id='$this->anketa' AND u.id = st.user ".
($status != -1 ? "AND st.status=$status " : "") ."$interval "
. "GROUP BY u.email, YEAR(st.datetime), MONTH(st.datetime)$queryDayGroup "
. "ORDER BY u.email, date ASC";
$output=sisplet_query($sql, 'array');
$data = array('edits'=>array(), 'first_date'=>$output2->first_date, 'last_date'=>$output2->last_date);
foreach($output as $row){
$data['edits'][$row['email']][$row['date']]=$row['cnt'];
}
return $data;
}
private function differDateTimeInDays($start_date, $end_date){
return $end_date->diff($start_date)->format("%a");
}
// Zgeneriramo ID grafa za hash
private function generateChartId($numerus){
$ID = $this->anketa.'_chart_'.$numerus.'edits_analysis';
return $ID;
}
/**
* Get data to show in table
*
* @param type $status - status or type of edits
* @param type $interval - where statement including interval for SQL
* @return type
*/
function getData($status, $interval){
$data = array();
$data_temp = $this->timeEditsQuery($status, $interval);
if(sizeof($data_temp) == 0)
return array();
else
$data['timeEdits'] = $data_temp;
return $data;
}
/**
* Create interval for SQL query from criteria
*
* @param type $time - time selected from dropdown
* @param type $from - from calendat
* @param type $to - to calendar
* @return type - string WHERE statement
*/
function createInterval($time, $from, $to){
if($time == 'lifetime' || ($time == '99date' && $from == '' && $to == ''))
$interval = "";
else if ($from == '' && $to == '')
$interval = "AND st.datetime > NOW() - INTERVAL $time";
else if ($to == '')
$interval = "AND '$from' <= st.datetime";
else if ($from == '')
$interval = "AND st.datetime <= '$to'";
else
$interval = "AND '$from' <= st.datetime AND st.datetime <= '$to'";
return $interval;
}
/**
* Run querry for action times
* @param type $status - int of status
* @param type $interval - where clause for time interval
* @return type array of results from DB
*/
function timeEditsQuery($status, $interval){
$sql = "SELECT u.email, u.id, st.datetime". ($status == 0 ? ", st.get, st.post" : "") . ($status == -1 ? ", st.status" : "")
. " FROM srv_tracking$this->db_table st, users u WHERE st.ank_id='$this->anketa' AND u.id = st.user ".
($status != -1 ? "AND st.status=$status " : "") ."$interval ORDER BY u.email, st.datetime DESC";
return sisplet_query($sql, 'array');
}
/**
* Draw box of number of edit actions
* @global type $lang
* @param type $data - object data of sums
*/
function drawCountEdits($data){
global $lang;
echo '
';
}
/**
* Run querry for continuous editing
* @param type $status - int of status
* @param type $interval - where clause for time interval
* @param type $interval_criteria - criteria for interval - continued 'day' or 'hour'
* @return type array of results from DB
*/
function continuEditsQuery($status, $interval, $interval_criteria = 'day', $user_criteria = 'all'){
$interval_criteria = ($interval_criteria == 'day') ? '' : ' %H';
$sqlString = "SELECT DATE_FORMAT(st.datetime, '%Y-%m-%d$interval_criteria') AS formatdate, count(*) as cnt FROM srv_tracking$this->db_table st WHERE ank_id = '$this->anketa' ".
($status != -1 ? "AND st.status=$status " : "")."".
($user_criteria != 'all' ? "AND st.user=$user_criteria " : "")."$interval GROUP BY formatdate ORDER BY formatdate desc";
return sisplet_query($sqlString, 'array');
}
/**
* Draw box of continuous editing
* @global type $lang
* @param type $data - object data of continued editing
* @param type $sum_data - object data of sums
* @param type $interval_criteria - criteria for interval - continued 'day' or 'hour'
*/
function drawContinuEdits($data, $sum_data, $interval_criteria = 'day'){
global $lang;
echo '
';
}
/**
* Draw table with bars od continued editing
* @param type $data - object data of continued editing
* @param type $interval_criteria - criteria for interval - continued 'day' or 'hour'
*/
function drawContinuEditsTable($data, $interval_criteria = 'day'){
$maxValue = 0;
$interval_seconds = ($interval_criteria == 'day') ? 86400 : 3600;
$interval_crit = ($interval_criteria == 'day') ? '' : ' H';
echo '
'."\n";
if ($data) {
$temp_time = null;
//units
$zapored = 0;
$results = array();
foreach ($data as $row) {
if($temp_time == null)
$temp_time = DateTime::createFromFormat('Y-m-d'.$interval_crit, $row['formatdate']);
else{
//calculate seconds between actions (rounded on 3600 or 86400)
$interval = $this->calculateTimeBetweenActions($temp_time, DateTime::createFromFormat('Y-m-d'.$interval_crit, $row['formatdate']));
//if interval between actions are 1 unit (1 hour or 1 day), add it to continued editing session
if($interval/$interval_seconds-$zapored < 2){
$zapored++;
//set maxValue, needed for width of bars
$maxValue = max($maxValue, $zapored);
}
//interval is more than 1 unit apart, not in continued editing session
else{
//if there is continued editing session until previous action, store it to array - ignore otherwise
if($zapored > 0)
array_push($results, array('time' => $temp_time, 'zapored' => $zapored));
//restart all
$temp_time = DateTime::createFromFormat('Y-m-d'.$interval_crit, $row['formatdate']);
$zapored = 0;
}
}
}
//if there is continued editing session in last actions, store it to array - ignore otherwise
if($zapored > 0)
//$this->drawContinuRow($temp_time, $zapored, $maxValue, $value);
array_push($results, array('time' => $temp_time, 'zapored' => $zapored));
if(!$results)
$this->echoNoData();
else{
//reduce bars a little
$maxValue *= GRAPH_REDUCE;//najvecje stevilo
//draw all data and bars
foreach ($results as $row) {
$this->drawContinuRow($row['time'], $row['zapored'], $maxValue, $interval_criteria);
}
}
} else
$this->echoNoData();
echo '
'."\n";
}
/**
* Draws a row with bar of continuous editing
* @param type $temp_time - the last edit
* @param type $zapored - hour of continuoed editing
* @param type $maxValue - max value of bars
* @param type $interval_criteria - criteria for interval - continued 'day' or 'hour'
*/
function drawContinuRow($temp_time, $zapored, $maxValue, $interval_criteria){
$time_last = clone $temp_time;
//edit DateTime get starting of continued editting session by subtracting units
$temp_time->modify('- '.$zapored.' '.$interval_criteria);
//if hour criteria
if($interval_criteria == 'hour'){
//add 1 hour because of from to view
$time_last->modify('+ 1 '.$interval_criteria);
$s_time = $temp_time->format('Y-m-d H:00') .' - '. $time_last->format('H:00');
}
else if($interval_criteria == 'day')
$s_time = $temp_time->format('Y-m-d') .' - '. $time_last->format('Y-m-d');
//echo data
echo '
'; //border zaradi printa - css na strani ga povozi
$this->echoTimeTalbeHeader($user_temp, $status, $user_id);
}
//naslednji editor
else if($user_temp != $rowGrupa['email']){
//izrisi se zadnjo vrstico prejsnjega urejevalca
$time_sum += $this -> drawTimeEditsRow($datetime_start, $datetime_last, $st_akcij, $action_type, $user_id.'_'.$row_id);
$this -> echoTimeEditsFootRow($time_sum, $st_akcij_sum, $action_type_sum, $user_id.'_sum');
$sum_data[$user_temp]['time_sum']=$time_sum;
$sum_data[$user_temp]['st_akcij_sum']=$st_akcij_sum;
$sum_data[$user_temp]['st_seans_sum']=$st_seans_sum;
$sum_data[$user_temp]['user_id']=$user_id;
$action_type_sum = $statuses;
//nova tabela - nov urejevalec
$user_temp = $rowGrupa['email'];
$user_id = $rowGrupa['id'];
$this->echoTimeTalbeHeader($user_temp, $status, $user_id);
//ponastavi spremenljivke
$datetime_last = null;
$datetime_start = null;
$st_akcij = 0;
$st_akcij_sum = 0;
$st_seans_sum = 0;
$time_sum = 0;
}
//izpis vrstic
//nov start seanse
if(!isset($datetime_start)){
$datetime_start = new DateTime($rowGrupa['datetime']);
$st_akcij++;
$st_seans_sum++;
$action_type = $statuses;
}
//se ni druge akcije
else if(!isset($datetime_last)){
$temp_time = new DateTime($rowGrupa['datetime']);
$interval = $this->calculateTimeBetweenActions($datetime_start, $temp_time);
//ce je akcija od starta v kriteriju seanse, jo dodaj k seansi
if($interval <= $seansa){
$datetime_last = clone $temp_time;
$st_akcij++;
}
//akcija je izven kriterija seanse, izpisi samo to akcijo
else{
$datetime_last = clone $datetime_start;
$datetime_last->add(new DateInterval('PT5S'));
$time_sum += $this -> drawTimeEditsRow($datetime_start, $datetime_last, $st_akcij, $action_type, $user_id.'_'.$row_id);
$st_akcij = 1;
$st_seans_sum++;
$datetime_start = clone $temp_time;
$datetime_last = null;
$action_type = $statuses;
}
}
//seasna ze ima vsaj dve akciji
else{
$temp_time = new DateTime($rowGrupa['datetime']);
$interval = $this->calculateTimeBetweenActions($datetime_last, $temp_time);
//ce je akcija od prejsnje v kriteriju seanse, jo dodaj k seansi
if($interval <= $seansa){
$datetime_last = clone $temp_time;
$st_akcij++;
}
//akcija je izven kriterija seanse, izpisi vse prejsnje akcije
else{
$time_sum += $this -> drawTimeEditsRow($datetime_start, $datetime_last, $st_akcij, $action_type, $user_id.'_'.$row_id);
$st_akcij = 1;
$st_seans_sum++;
$datetime_start = clone $temp_time;
$datetime_last = null;
$action_type = $statuses;
}
}
$st_akcij_sum++;
$row_id++;
if($status == -1){
$action_type[$akcija]['sum'] ++;
$action_type_sum[$akcija]['sum'] ++;
}
else if($status == 0){
$action_type[$akcija] = isset($action_type[$akcija]) ? $action_type[$akcija]+1 : 1;
$action_type_sum[$akcija] = isset($action_type_sum[$akcija]) ? $action_type_sum[$akcija]+1 : 1;
}
}
//izrisi se zadnjo vrstico, ki jo ni foreach ter footer
if($datetime_last == null){
$datetime_last = clone $datetime_start;
$datetime_last->add(new DateInterval('PT5S'));
}
$time_sum += $this -> drawTimeEditsRow($datetime_start, $datetime_last, $st_akcij, $action_type, $user_id.'_'.$row_id);
$this -> echoTimeEditsFootRow($time_sum, $st_akcij_sum, $action_type_sum, $user_id.'_sum');
$sum_data[$user_temp]['time_sum']=$time_sum;
$sum_data[$user_temp]['st_akcij_sum']=$st_akcij_sum;
$sum_data[$user_temp]['st_seans_sum']=$st_seans_sum;
$sum_data[$user_temp]['user_id']=$user_id;
echo '
';
return $sum_data;
}
/**
* Izrisi header tabele za cas urejanja vsakega urejevalca
* @param type $user_temp - email of user
* @param type $status - status from criteria
* @param type $user_num - int sequence nuber of user (unique, for this site, no need to be ID)
*/
function echoTimeTalbeHeader($user_temp, $status, $user_num){
global $lang;
echo '
'.$user_temp.'
';
echo '
'.$lang['srv_edits_analysis_time_span'].'
'.$lang['srv_edits_analysis_time_time'].
'
'.$lang['srv_edits_analysis_time_actions'].'
'.($status < 1 ? '
'.$lang['srv_edits_analysis_action_type'].'
' : '').'
';
}
/**
* Nastavi in kasneje izrise vrstico urejanja
*
* @param type $datetime_start - datetime start of editing
* @param type $datetime_last - datetime end of editing
* @param type $st_akcij - num ob actions during editing
* @param type $action_type - string of type of action
* @param type $row_id - int sequence nuber of row (unique, for this site, no need to be ID)
* @return type int - calculated second of editing session
*/
function drawTimeEditsRow($datetime_start, $datetime_last, $st_akcij, $action_type = null, $row_id = null){
$seconds = 0;
//create string of actions type
$action_type_string = ($action_type != null) ? $this -> createActionsTypeString($action_type, $row_id) : null;
if(isset($datetime_last)){
$seconds = $this->calculateTimeBetweenActions($datetime_start, $datetime_last);
$this -> echoTimeEditsRow($datetime_last->format('Y-m-d H:i:s') .' - '. $datetime_start->format('Y-m-d H:i:s'),
$this->calculateTimeFromSeconds($seconds), $st_akcij, $action_type_string);
}
//ce je samo ena akcija
else
$this -> echoTimeEditsRow($datetime_start->format('Y-m-d H:i:s'), 0 ,1, $action_type_string);
return $seconds;
}
/**
* Create/convert array of action types to string for table cell
* @param type $action_type - array of action types
* @param type $row_id - int sequence nuber of row (unique user int and row in table)
* @return string - converter array to string to put it in table cell
*/
function createActionsTypeString($action_type, $row_id){
$action_type_string = '';
//urejanje - ali drug specificen status
if(!isset($action_type[0]['sum'])){
global $lang;
$i = 0;
foreach ($action_type as $key => $at){
if($i == 3)
$action_type_string .= '
'.$lang['srv_more'].'
';
if($i < 3)
$action_type_string .= '
'.$key.' ('.$at.')'.'
';
else
$action_type_string .= '
'.$key.' ('.$at.')'.'
';
$i++;
}
if($i > 3)
$action_type_string .= '
'.$lang['srv_less'].'
';
}
//vsi statusi
else{
foreach ($action_type as $at){
if($at['sum'] > 0){
if($action_type_string != '')
$action_type_string .= '';
$action_type_string .= $at['name'].' ('.$at['sum'].')';
}
}
}
return $action_type_string;
}
/**
* Izrise vrstico urejanja
* @param type $datetime - string from to editing
* @param type $cas_seanse - editing time
* @param type $st_akcij - num of editing actions
* @param type $action_type - string of type of action
*/
function echoTimeEditsRow($datetime, $cas_seanse, $st_akcij, $action_type = null){
//casovni razpon urejanja
echo '
'.$datetime.'
';
//cas urejanja
echo '
'.$cas_seanse.'
';
//stevilo akcij
echo '
'.$st_akcij.'
';
if($action_type != null)
//vrsta akcij
echo '
'.$action_type.'
';
echo '
';
}
/**
* Izrise vrstico editor info
* @param type $user - string of editor
* @param type $time_sum - editing time
* @param type $st_akcij - num of sum editing actions
* @param type $st_seans_sum - num of sessions
* @param type $user_num - int sequence nuber of user (unique user int and row in table)
*/
function echoCountEditsRow($user, $time_sum, $st_akcij, $st_seans_sum, $user_num){
//casovni razpon urejanja
echo '
';
}
/**
* Izrise total/footer vrstico urejanja
* @param type $time - seconds of editing
* @param type $st_akcij - num of editing actions
* @param type $action_type - string of type of actions
* @param type $row_id - int sequence nuber of user (unique, for this site, no need to be ID)
*/
function echoTimeEditsFootRow($time, $st_akcij, $action_type = null, $row_id = 0){
global $lang;
//casovni razpon urejanja
echo '
';
}
/**
* Izrise total/footer vrstico urejanja
* @param type $time - seconds of editing
* @param type $st_akcij - num of editing actions
* @param type $st_seans_sum - num of sessions
*/
function echoCounterEditsFootRow($time, $st_akcij, $st_seans_sum){
global $lang;
//casovni razpon urejanja
echo '
'.$lang['srv_edits_analysis_time_total'].'
';
//cas urejanja
echo '
'.$this->calculateTimeFromSeconds($time).'
';
//stevilo seans
echo '
'.$st_seans_sum.'
';
//stevilo akcij
echo '
'.$st_akcij.'
';
echo '
';
}
/**
* Calculate
* @param type $datetime_start - datetime start of editing
* @param type $datetime_last - datetime end of editing
* @return type - float in time in minutes between actions
*/
function calculateTimeBetweenActions($datetime_start, $datetime_last){
return abs($datetime_last ->getTimestamp() - $datetime_start->getTimestamp());
}
/**
* Get readable time from seconds
* @param type $seconds - time in seconds
* @return type string - readable time
*/
function calculateTimeFromSeconds($seconds){
$hours = floor($seconds / 3600);
$mins = floor($seconds / 60 % 60);
$secs = floor($seconds % 60);
return sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
}
/**
* Convert false JSON (with keys without quotes and no stat and end braces)
* from DB to valid JSON
* @param type $toJSON string to convert to JSON (with keys without
* quotes and no stat and end braces)
* @return type valid converted JSON
*/
function convertToJSON($toJSON){
$toJSON = preg_replace('/("(.*?)"|(\w+))(\s*:\s*(".*?"|.))/s', '"$2$3"$4', $toJSON);
$toJSON = '{'.$toJSON.'}';
return json_decode($toJSON, true);
}
/**
* Echo 'no data in DB'
*/
function echoNoData(){
global $lang;
echo '
'.$lang['srv_edits_analysis_no_data'].'
'."\n";
}
function ajax_drawContinuEditsTable(){
if (isset ($_POST['user']))
$user = $_POST['user'];
else
$user = 'all';
if (isset ($_POST['period']))
$period = $_POST['period'];
else
$period = 'day';
if (isset($_POST['time']))
$time = $_POST['time'];
else
$time = '1 month';
if (isset ($_POST['status']))
$status = $_POST['status'];
else
$status = 0;
if (isset ($_POST['from']))
$from = $_POST['from'];
else
$from = '';
if (isset ($_POST['to']))
$to = $_POST['to'];
else
$to = '';
//create iterval - SQL where statement
$interval = $this->createInterval($time, $from, $to);
//get data
$data = $this->continuEditsQuery($status, $interval, $period, $user);
//draw table
$this->drawContinuEditsTable($data, $period);
}
function getList($status, $interval){
$sql = "SELECT st.datetime, u.email, st.post, st.get FROM srv_tracking$this->db_table st, users u WHERE st.ank_id='$this->anketa' AND u.id = st.user ". ($status != -1 ? "AND st.status=$status " : "") ."$interval";
// Loop cez vse vrednosti v vprasanjih na straneh v anketi
$sqlGrupa = sisplet_query($sql);
$vrstic = 0;
while($rowGrupa = mysqli_fetch_array($sqlGrupa)){
$vrstic++;
}
}
}