t('Statistika'), 'page callback' => 'statistics_view_page', 'page arguments' => array('statistics_view_form', 1), 'access arguments' => array('view statistics'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function statistics_view_page() { //statistics table global $user; $output = ''; $output .= ''; $range = ''; switch(arg(1)) { case 'all': $res = db_fetch_array(db_query("SELECT date FROM {statistics_view} ORDER BY date ASC LIMIT 0, 1;")); $stime = $res['date']; $etime = mktime(); break; case 'day': $stime = mktime(0,0,0, date('m'),date('d')-1,date('Y')); $etime = mktime(0,0,-1, date('m'), date('d'), date('Y')); $range = "AND date BETWEEN $stime AND $etime"; break; case 'week': $weekday = date('N'); $stime = mktime(); while($weekday != 1) { $stime = mktime(0,0,0,date('m', $stime), date('d', $stime)-1, date('Y', $stime)); $weekday = date('N', $stime); } $etime = mktime(); $range = "AND date BETWEEN $stime AND $etime"; break; case 'month': $stime = mktime(0,0,0,date('m'), 1, date('Y')); $etime = mktime(); $range = "AND date BETWEEN $stime AND $etime"; break; default: if($_SESSION['filter']['start_date']) { $stime = strtotime($_SESSION['filter']['start_date']); $etime = strtotime($_SESSION['filter']['end_date']); $range = "AND date BETWEEN $stime AND $etime"; } } $_SESSION['filter']['start_date'] = date('d.m.Y', $stime); $_SESSION['filter']['end_date'] = date('d.m.Y', $etime); /* //DIFFERENCE if(arg(1) == 'month') { //Month $previous_month_stime = mktime(1,0,0, date('m', mktime())-1, 1, date('Y')); //fetch previous month first day TS $previous_month_etime = mktime(23,59,59, date('m', $etime), 0, date('Y')); //fetch privous month last day TS $output .= "Võrdlus aegaga " . format_date($previous_month_stime, 'long') . " kuni " . format_date($previous_month_etime, 'long') . "
"; //debug $previous_range = "AND {accesslog}.timestamp BETWEEN $previous_month_stime AND $previous_month_etime"; } //Week if(arg(1) == 'week') { $previous_week_stime = mktime(0,0,0, date('m', $stime), date('d', $stime)-7, date('Y', $stime)); //fetch previous week first day TS $previous_week_etime = mktime(23,59,59, date('m', $etime), date('d', $stime)-1, date('Y', $etime)); //fetch previous week last day TS $output .= "Võrdlus aegaga " . format_date($previous_week_stime, 'long') . " kuni " . format_date($previous_week_etime, 'long') . "
"; //debug $previous_range = "AND {accesslog}.timestamp BETWEEN $previous_week_stime AND $previous_week_etime"; } //DIFFERENCE END */ if(user_access('admin statistics')) { $output .= drupal_get_form('statistics_admin_form'); } $output .= drupal_get_form('statistics_view_form'); $output .= ''; $output .= ""; $output .= ""; $user_to_list = $user->uid; if($_SESSION['filter']['user'] && user_access('admin statistics')) $user_to_list = $_SESSION['filter']['user']; //$sql_data = "SELECT {node}.nid, {accesslog}.path, count({accesslog}.hostname) as total, count(distinct {accesslog}.hostname) as visits FROM {node}, {accesslog} WHERE {node}.uid=$user_to_list AND {node}.type='raamat' AND {accesslog}.path = CONCAT('node/', {node}.nid) $range GROUP BY {node.nid} ORDER BY count({accesslog}.hostname) DESC"; $sql_data = "SELECT {node}.nid as nid, SUM({statistics_view}.total) as total, SUM({statistics_view}.`unique`) as visits, {node}.nid FROM {statistics_view}, {node} WHERE {node}.type = 'raamat' AND {statistics_view}.nid = node.nid AND {node}.uid=$user_to_list $range GROUP BY {node}.nid"; $result_fetch_books = pager_query($sql_data, 30, 0, "SELECT count(nid) FROM {node} WHERE uid=$user_to_list AND type='raamat'"); while($obj = db_fetch_object($result_fetch_books)) { //Raamatu Pealkiri $one_long_sql = "SELECT {term_data}.name, {content_field_raamatu_pealkiri}.field_raamatu_pealkiri_value FROM {content_field_raamatu_pealkiri}, {term_data} WHERE {content_field_raamatu_pealkiri}.field_raamatu_pealkiri_value = {term_data}.tid AND {content_field_raamatu_pealkiri}.nid = %d"; $fetch_name = db_fetch_array(db_query($one_long_sql, $obj->nid)); if(strlen($fetch_name['name']) > 23) $fetch_name['name'] = substr($fetch_name['name'], 0, 20)."..."; //Raamatu Pealkiri end if($previous_range) $result_visits_diff = db_fetch_array(db_query("SELECT count(hostname), count(distinct hostname) FROM {accesslog} WHERE path REGEXP 'node/%d$' $previous_range", $obj->nid)); $result_kirjastus = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE source=%d AND type='kirjastus' $range", $obj->nid)); $result_apollo = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE source=%d AND type='apollo' $range", $obj->nid)); $result_rahva = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE source=%d AND type='rahvaraamat' $range", $obj->nid)); $result_raamatukoja = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE source=%d AND type='raamatukoi' $range", $obj->nid)); $result_lehitsenud = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE source=%d AND type='lehitse' $range", $obj->nid)); $result_top_right_banner = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE target='node/%d$' AND type='banner-top-right' $range", $obj->nid)); $result_flash_banner = db_fetch_array(db_query("SELECT count(source) FROM {statistics_track} WHERE target='node/%d' AND type='flash-banner' $range", $obj->nid)); if($previous_range) { if($result_visits['count(distinct hostname)'] > $result_visits_diff['count(distinct hostname)']) { $uniq_class = "class='increased'"; } else { $uniq_class = "class='decreased'"; } } if($previous_range) { if($result_visits['count(hostname)'] > $result_visits_diff['count(hostname)']) { $total = "class='increased'"; } else { $total = "class='decreased'"; } } $output .= ""; } $output .= "
Raamatu pealkiriKokkuUnikaalseidLehitsetudKirjastuse e-poeleApolloleRahva RaamatuleRaamatukoileTLBannerFlash Banner
" . l($fetch_name['name'], "node/$obj->nid") . "" . $obj->total; $output .= "" . $obj->visits; $output .= "" .$result_lehitsenud['count(source)']. "" . $result_kirjastus['count(source)'] . "" . $result_apollo['count(source)'] . "" . $result_rahva['count(source)'] . "" . $result_raamatukoja['count(source)'] . "". $result_top_right_banner['count(source)'] . "" . $result_flash_banner['count(source)'] . "
"; //Pager $output .= theme('pager', NULL, 30, 0); //Pager end $output .= " - Külastused on tõusnud eelmise perioodiga võrreldes.
"; $output .= " - Külastused on langenud eelmise perioodiga võrreldes."; /* if($user->uid == 1) { if($_GET['fill'] == 'yes') { print "DEBUG:
"; build_fill_array(); } } */ return $output; } function statistic($type, $nid, $range) { } function statistics_view_form($form_state) { $form['#action'] = url('raamatu_statistika'); $form['#attributes'] = array('name' => 'date'); $suffix = ''; $suffix .= ''; $form['date'] = array( '#type' => "textfield", '#title' => t('Date'), '#size' => 10, '#default_value' => $_SESSION['filter']['start_date'], '#required' => TRUE, '#field_suffix' => $suffix, ); $suffi2x = ''; $suffi2x .= ''; $form['enddate'] = array( '#type' => "textfield", '#title' => t('Date'), '#size' => 10, '#default_value' => $_SESSION['filter']['end_date'], '#required' => TRUE, '#field_suffix' => $suffi2x, ); $form['submit'] = array('#type' => 'submit', '#value' => t('Show')); return $form; } function statistics_admin_form($form_state) { $sql = db_query("SELECT {users}.name, {profile_values}.value, {users_roles}.rid, {users_roles}.uid FROM {profile_values}, {users_roles}, {users} WHERE {users_roles}.rid = 4 AND {users_roles}.uid = {profile_values}.uid AND {profile_values}.fid = 4 AND {users}.uid = {users_roles}.uid ORDER BY {profile_values}.value ASC"); while($roles = db_fetch_array($sql)) { if($roles['value'] == '') $roles['value'] = '? ('.$roles['name'].')'; $user_array[$roles['uid']] = $roles['value']; } $user_array[$roles[1]] = "admin"; $form['select_user'] = array( '#type' => "select", '#title' => t("Kirjastaja"), '#options' => $user_array, '#description' => t("Vali Kirjastaja"), '#default_value' => $_SESSION['filter']['user'], ); $form['submit'] = array('#type' => 'submit', '#value' => t('Show')); return $form; } function statistics_view_form_submit($form, &$form_state) { $_SESSION['filter']['start_date'] = $form_state['values']['date']; $_SESSION['filter']['end_date'] = $form_state['values']['enddate']; } function statistics_admin_form_submit($form, &$form_state) { $_SESSION['filter']['user'] = $form_state['values']['select_user']; } function build_fill_array() { $nids = db_query("SELECT nid FROM {node} WHERE type='raamat'"); while($nid_array = db_fetch_array($nids)) { $nid[] = $nid_array['nid']; } $start_ts = mktime(0,0,0, 12, 10, date('Y')); $end_ts = mktime(0,0,0, 12, 13, date('Y')); while($start_ts <= $end_ts) { $day = mktime(12,0,0, date('m', $start_ts), date('d', $start_ts), date('Y', $start_ts)); $range_from = mktime(0,0,0, date('m', $start_ts), date('d', $start_ts), date('Y', $start_ts)); $range_to = mktime(23,59,59, date('m', $start_ts), date('d', $start_ts), date('Y', $start_ts)); foreach($nid as $n) { $results = db_fetch_object(db_query("SELECT count(hostname) as total, count(distinct hostname) as visits FROM {accesslog} WHERE timestamp BETWEEN %d AND %d AND path = 'node/%d'", $range_from, $range_to, $n)); $sql_insert = "INSERT INTO {statistics_view} (`id`, `nid`, `total`, `unique`, `timestamp`, `date`) VALUES (NULL, $n, $results->total, $results->visits, ".mktime().", '$day');"; db_query($sql_insert); } $start_ts = mktime(0,0,0, date('m', $start_ts), date('d', $start_ts)+1, date('Y', $start_ts)); } } function statistics_view_cron() { $day_start = mktime(0,0,0,date('m'), date('d')-1, date('Y')); $day_end = mktime(23,59,59, date('m'), date('d')-1, date('Y')); $range = "AND timestamp BETWEEN $day_start AND $day_end"; $nids = db_query("SELECT nid FROM {node} WHERE type='raamat'"); while($db = db_fetch_object($nids)) { $sql = db_query("SELECT count(hostname) as total, count(distinct hostname) as visits FROM {accesslog} WHERE path = 'node/%d' $range ", $db->nid); $db_array = db_fetch_object($sql); $sql_insert = "INSERT INTO {statistics_view} (`id`, `nid`, `total`, `unique`, `timestamp`, `date`) VALUES (NULL, $db->nid, $db_array->total, $db_array->visits, ".mktime().", ".mktime(12,0,0, date('m', $day_start), date('d', $day_start), date('Y', $day_start)).");"; db_query($sql_insert); } }