$max_id) { $max_id = $row['max_id']; } if ($is_first) { $is_first = false; $first_time_key = $time_keys[3]; } } // Only the oldest time_key might be already summarized, so we have to // update the 4 corresponding lines instead of simply inserting them. // // For example, if the oldest unsummarized is 2005.08.25.21, the 4 lines // that can be updated are: // // +---------------+----------+ // | id | nb_pages | // +---------------+----------+ // | 2005 | 241109 | // | 2005.08 | 20133 | // | 2005.08.25 | 620 | // | 2005.08.25.21 | 151 | // +---------------+----------+ $existing_time_keys = array(); if (isset($first_time_key)) { list($year, $month, $day, $hour) = explode('.', $first_time_key); $time_keys = array( sprintf('%4u', $year), sprintf('%4u.%02u', $year, $month), sprintf('%4u.%02u.%02u', $year, $month, $day), sprintf('%4u.%02u.%02u.%02u', $year, $month, $day, $hour), ); $query = ' SELECT id, nb_pages FROM '.HISTORY_SUMMARY_TABLE.' WHERE id IN (\''.implode("', '", $time_keys).'\') ;'; $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { $existing_time_keys[ $row['id'] ] = $row['nb_pages']; } } $updates = array(); $inserts = array(); foreach (array_keys($need_update) as $time_key) { $time_tokens = explode('.', $time_key); if (isset($existing_time_keys[$time_key])) { array_push( $updates, array( 'id' => $time_key, 'nb_pages' => $existing_time_keys[$time_key] + $need_update[$time_key], ) ); } else { array_push( $inserts, array( 'id' => $time_key, 'year' => $time_tokens[0], 'month' => @$time_tokens[1], 'day' => @$time_tokens[2], 'hour' => @$time_tokens[3], 'nb_pages' => $need_update[$time_key], ) ); } } if (count($updates) > 0) { mass_updates( HISTORY_SUMMARY_TABLE, array( 'primary' => array('id'), 'update' => array('nb_pages'), ), $updates ); } if (count($inserts) > 0) { mass_inserts( HISTORY_SUMMARY_TABLE, array_keys($inserts[0]), $inserts ); } if ($max_id != 0) { $query = ' UPDATE '.HISTORY_TABLE.' SET summarized = \'true\' WHERE summarized = \'false\' AND id <= '.$max_id.' ;'; pwg_query($query); } // +-----------------------------------------------------------------------+ // | Page parameters check | // +-----------------------------------------------------------------------+ foreach (array('day', 'month', 'year') as $key) { if (isset($_GET[$key])) { $page[$key] = (int)$_GET[$key]; } } if (isset($page['day'])) { if (!isset($page['month'])) { die('month is missing in URL'); } } if (isset($page['month'])) { if (!isset($page['year'])) { die('year is missing in URL'); } } $url_img = PHPWG_ROOT_PATH.'admin/images/stats.img.php'; if (isset($page['year'])) { $url_img.= '?year='.$page['year']; } if (isset($page['month'])) { $url_img.= '&month='.$page['month']; } if (isset($page['day'])) { $url_img.= '&day='.$page['day']; } $summary_lines = get_summary( @$page['year'], @$page['month'], @$page['day'] ); // +-----------------------------------------------------------------------+ // | Display statistics header | // +-----------------------------------------------------------------------+ // page title creation $title_parts = array(); $url = PHPWG_ROOT_PATH.'admin.php?page=stats'; array_push( $title_parts, ''.l10n('Overall').'' ); $period_label = l10n('Year'); if (isset($page['year'])) { $url.= '&year='.$page['year']; array_push( $title_parts, ''.sprintf(l10n('Year %d'), $page['year']).'' ); $period_label = l10n('Month'); } if (isset($page['month'])) { $url.= '&month='.$page['month']; array_push( $title_parts, ''.$lang['month'][$page['month']].'' ); $period_label = l10n('Day'); } if (isset($page['day'])) { $url.= '&day='.$page['day']; $time = mktime(12, 0, 0, $page['month'], $page['day'], $page['year']); $day_title = sprintf( '%u (%s)', $page['day'], $lang['day'][date('w', $time)] ); array_push( $title_parts, ''.$day_title.'' ); $period_label = l10n('Hour'); } $template->set_filenames(array('stats'=>'admin/stats.tpl')); $template->assign_vars( array( 'L_STAT_TITLE' => implode($conf['level_separator'], $title_parts), 'SRC_REPORT' => $url_img, 'PERIOD_LABEL' => $period_label, ) ); // +-----------------------------------------------------------------------+ // | Display statistic rows | // +-----------------------------------------------------------------------+ $i = 1; foreach ($summary_lines as $line) { // echo '
'; print_r($line); echo '
'; $value = ''; if (isset($line['hour'])) { $value.= $line['hour'].' '.l10n('hour'); } else if (isset($line['day'])) { $url = PHPWG_ROOT_PATH.'admin.php' .'?page=stats' .'&year='.$line['year'] .'&month='.$line['month'] .'&day='.$line['day'] ; $time = mktime(12, 0, 0, $line['month'], $line['day'], $line['year']); $value = ''; $value.= $line['day'].' ('.$lang['day'][date('w', $time)].')'; $value.= ""; } else if (isset($line['month'])) { $url = PHPWG_ROOT_PATH.'admin.php' .'?page=stats' .'&year='.$line['year'] .'&month='.$line['month'] ; $value = ''; $value.= $lang['month'][$line['month']]; $value.= ""; } else { // at least the year is defined $url = PHPWG_ROOT_PATH.'admin.php' .'?page=stats' .'&year='.$line['year'] ; $value = ''; $value.= $line['year']; $value.= ""; } $template->assign_block_vars( 'statrow', array( 'VALUE' => $value, 'PAGES' => $line['nb_pages'], 'T_CLASS' => ($i++ % 2) ? 'row1' : 'row2' ) ); } // +-----------------------------------------------------------------------+ // | Sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'stats'); ?>