function module_last_months($arguments) { global $lvc_nb_last_months; global $lvc_site_opening_month; global $lvc_site_opening_year; global $lvm_month, $lvm_archived, $lvm_arr_months; $buffer = ''; $month = date('n'); $year = date('Y'); $finished = false; $buffer .= "<TABLE CELLSPACING=0 BORDER=0>\n"; for ($count = 1; $count <= $lvc_nb_last_months; $count++) { $buffer .= "<TR><TD> "; if ($finished) { $archive = ''; } else { $data = archive_month($month, $year, 'code'); if ($data[0] == NO_ARCHIVE) { $archive = ''; } elseif ($data[0] == DB_ERROR) { $archive = '<A CLASS="archived">[?]</A>'; } else { $archive = '<A CLASS="archived">[' . $lvm_archived . ']</A>'; } } if (!$finished) { $finished = $month == $lvc_site_opening_month && $year == $lvc_site_opening_year; $the_month = $month < 10 ? "0" . $month : $month; $link = "./?view=month&year=" . $year . "&month=" . $the_month; $buffer .= ' ' . html_link($link, html_image('images/' . ICON_PUCE)) . ' '; $buffer .= "<A HREF='" . $link . "'>"; $buffer .= $lvm_arr_months[$month]; $buffer .= " " . $year; $buffer .= "</A>"; $month = $month == 1 ? 12 : $month - 1; $year = $month == 12 ? $year - 1 : $year; } $buffer .= " </TD><TD ALIGN='center'> "; $buffer .= $archive; $buffer .= " </TD></TR>"; } $buffer .= "</TABLE>"; return $buffer; }
function module_img_year_per_day($arguments) { global $lvc_cache_dir; global $lvc_images_format; global $lvc_pattern_per_day; global $lvc_base_img_year_per_day; global $lvc_img_site_name; global $lvc_site_opening_year; global $lvc_site_opening_month; global $lvc_table_visitors; global $lvc_display_cache_delay; global $lvc_color_bg_out; global $lvc_color_bg_in; global $lvc_color_value; global $lvc_color_bar_h; global $lvc_color_title; global $lvc_color_month_0; global $lvc_color_month_1; global $lvc_color_cache; global $lvm_img_arr_months_graph, $lvm_year_per_day; global $gDb; // -------------------------------------------------------------------------- $width = 804; $height = 288; $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '.' . $lvc_images_format; // -------------------------------------------------------------------------- if (!$arguments['generate']) { return "WIDTH='" . $width . "' HEIGHT='" . $height . "'"; } // cache delay $cache_delay = $arguments['cache']; if (is_image_expired($file_name, $cache_delay)) { // image creation $image = imagecreate($width, $height); $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format; $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_per_day . '.' . $lvc_images_format); // colors $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff); $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0); $color_value = create_new_color($image, $lvc_color_value); $color_bar_h = create_new_color($image, $lvc_color_bar_h); $color_bg_in = create_new_color($image, $lvc_color_bg_in); $color_bg_out = create_new_color($image, $lvc_color_bg_out); $color_title = create_new_color($image, $lvc_color_title); $color_cache = create_new_color($image, $lvc_color_cache); $color_month[0] = create_new_color($image, $lvc_color_month_0); $color_month[1] = create_new_color($image, $lvc_color_month_1); imagefill($image, 0, 0, $color_bg_out); imagerectangle($image, 0, 0, 803, 287, $color_white); imagerectangle($image, 30, 20, 773, 267, $color_black); imagefilledrectangle($image, 31, 21, 772, 266, $color_white); imagefilledrectangle($image, 34, 24, 769, 263, $color_bg_in); // title $title = $lvc_img_site_name . ' - ' . $lvm_year_per_day; $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2); if ($start < 0) { $start = 2; } imagestring($image, 3, $start, 5, $title, $color_title); // first month ? $current_year = date('Y'); $current_month = date('n'); $first_year = $current_year; $first_month = $current_month; for ($cnt_month = 1; $cnt_month < 12; $cnt_month++) { $first_month = $first_month == 1 ? 12 : $first_month - 1; $first_year = $first_month == 12 ? $first_year - 1 : $first_year; } $month = $first_month; $year = $first_year; $cnt_day = 0; $finished = false; $today = date('d/m/Y'); for ($cnt = 0; $cnt < 12; $cnt++) { $arr_month[$cnt] = $month; $site_open = $year > $lvc_site_opening_year || $year == $lvc_site_opening_year && $month >= $lvc_site_opening_month; // retrieving archive if exists $data = archive_month($month, $year, 'vpj'); if ($is_archived = $data[0] != NO_ARCHIVE) { $values = explode('+', $data[0]); } for ($day = 1; $day <= 31; $day++) { $val = 0; if (!$finished && $site_open) { $the_day = sprintf('%02d/%02d/%4d', $day, $month, $year); if (checkdate($month, $day, $year)) { if ($is_archived) { $val = $values[$day * 2 - 1]; } else { $query = "SELECT COUNT(*) "; $query .= "FROM " . $lvc_table_visitors . " "; $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/" . sprintf("%02d", $day) . "%'"; $gDb->DbQuery($query); $record = $gDb->DbNextRow(); $val = $record[0]; } } $finished = $the_day == $today; } $arr_values[$cnt_day] = $val; if ($cnt_day == 0) { $max = $arr_values[0]; $min = $arr_values[0]; } if ($val > $max) { $max = $val; } if ($val != 0 && $val < $min) { $min = $val; } $cnt_day++; } $month = $month == 12 ? 1 : $month + 1; $year = $month == 1 ? $year + 1 : $year; } // horizontal bars $level = $lvc_base_img_year_per_day; while ($max > 3.75 * $level) { $level += $lvc_base_img_year_per_day; } for ($cnt = 0; $cnt <= 4; $cnt++) { $start = (int) ((30 - imagefontwidth(1) * strlen($cnt * $level)) / 2); imagestring($image, 1, 2 + $start, $height - 28 - $cnt * 60, $cnt * $level, $color_white); $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60; imageline($image, 35, $y, $width - 35, $y, $color_bar_h); } // histograms $cnt_days = 0; $finished = false; $cnt_day = 0; $month = $first_month; $year = $first_year; for ($cnt = 0; $cnt < 12; $cnt++) { // month $start = (int) ((60 - imagefontwidth(1) * strlen($lvm_img_arr_months_graph[$arr_month[$cnt]])) / 2); imagestring($image, 1, 36 + $cnt_days * 2 + $start, $height - 18, $lvm_img_arr_months_graph[$arr_month[$cnt]], $color_white); for ($day = 1; $day <= 31; $day++) { if (checkdate($month, $day, $year)) { $cnt_days++; } if (!$finished) { $the_day = sprintf("%02d/%02d/%d", $day, $month, $year); $finished = $the_day == $today; } if (($val = $arr_values[$cnt_day]) != 0) { $y = $height - 24 - $val * 60 / $level; imageline($image, 35 + $cnt_days * 2, $y, 35 + $cnt_days * 2, $height - 25, $color_month[$cnt % 2]); } $cnt_day++; } $month = $month == 12 ? 1 : $month + 1; $year = $month == 1 ? $year + 1 : $year; } // cache delay if ($lvc_display_cache_delay) { imagestringup($image, 2, $width - 29, $height - 22, cache_delay($cache_delay), $color_cache); } imageinterlace($image, false); // saving image $fct_image = 'image' . $lvc_images_format; $fct_image($image, $file_name); // sending image header('Content-type: image/' . $lvc_images_format); $fct_image($image); } else { // sending image header('Content-type: image/' . $lvc_images_format); echo fread(fopen($file_name, 'r'), filesize($file_name)); } }
// GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // // ------------------------------------------------------------------------ // configuration file // ------------------------------------------------------------------------ $ignore_messages = false; $lvc_include_dir = 'include/'; $lvc_config_file = 'config.inc.php'; include $lvc_include_dir . $lvc_config_file; // ------------------------------------------------------------------------ // library file // ------------------------------------------------------------------------ include $lvc_include_dir . 'library.inc.php'; $gDb = new Db(); if (!$gDb->DbConnect($lvc_db_host, $lvc_db_user, $lvc_db_password, $lvc_db_database)) { echo connexion_error($lvm_connexion_error); } elseif ($img == 'img_last_months' || $img == 'img_year_per_day' || $img == 'img_day_per_hour') { echo insert_cached_image('<mod-' . $img . ' cache=' . ${'lvc_delay_' . $img} . ' generate=1>'); } else { // calculate cache delay $gData = archive_month((int) $month, $year, 'vph, vpj'); $is_archived = $gData[0] != NO_ARCHIVE; $cache_delay = $is_archived ? $lvc_delay_archive_month : $lvc_delay_current_month; if ($img == 'img_visitors_per_hour' || $img == 'img_visitors_per_day') { echo insert_cached_image('<mod-' . $img . ' cache=' . $cache_delay . ' year=' . $year . ' month=' . $month . ' generate=1 archive=' . $is_archived . '>'); } }
// but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // if ($year < $lvc_site_opening_year || $year == $lvc_site_opening_year && (int) $month < (int) $lvc_site_opening_month || $year > date('Y') || $year == date('Y') && (int) $month > (int) date('m')) { $year = date('Y'); $month = date('m'); } // ------------------------------------------------------------------------ // get archive if exists // ------------------------------------------------------------------------ $gData = archive_month((int) $month, $year, 'topVis,topNavOS,topOS,topNav,topRef,topDom,vpj'); $is_archived = $gData[0] != NO_ARCHIVE && $gData[0] != DB_ERROR; // ------------------------------------------------------------------------ // calculate cache delay // ------------------------------------------------------------------------ $cache_delay = $is_archived ? $lvc_delay_archive_month : $lvc_delay_current_month; // ------------------------------------------------------------------------ // MODULE: month_calendar // ------------------------------------------------------------------------ echo '<A NAME="month_calendar"></A>'; echo insert_cached_module('<mod-month_calendar cache=' . $cache_delay . ' year=' . $year . ' month=' . $month . ' archive=' . $is_archived . '>'); // ------------------------------------------------------------------------ // IMAGE: visitors per day // ------------------------------------------------------------------------ echo '<A NAME="img_per_day"></A>'; echo insert_cached_image('<mod-img_visitors_per_day year=' . $year . ' month=' . $month . ' generate=0>');
function module_calendar($arguments) { global $gDb; global $lvc_nb_months_calendar; global $lvc_site_opening_year; global $lvc_site_opening_month; global $lvc_table_visitors; global $lvc_display_cache_delay; global $lvm_arr_months, $lvm_visitors_per_day, $lvm_month; global $lvm_average, $lvm_total; $buffer = ''; $current_year = date('Y'); $current_month = date('n'); $today = date('Y/m/d'); $first_year = $current_year; $first_month = $current_month; // looking for first month and first year in calendar for ($cnt_month = 1; $cnt_month < $lvc_nb_months_calendar && !($first_year == $lvc_site_opening_year && $first_month == $lvc_site_opening_month); $cnt_month++) { $first_month = $first_month == 1 ? 12 : $first_month - 1; $first_year = $first_month == 12 ? $first_year - 1 : $first_year; } $buffer .= "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n"; $buffer .= "<TR><TD COLSPAN=17 ALIGN='left'><A CLASS='array'>"; $buffer .= str_replace("{NB_LAST_MONTHS}", $cnt_month, $lvm_visitors_per_day) . "</A> "; $buffer .= "</TD><TD COLSPAN=17 ALIGN='right'> "; if ($lvc_display_cache_delay) { $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>"; } $buffer .= "</TD></TR>\n"; $buffer .= "<TR><TH CLASS='vis'>" . $lvm_month . "</TH>"; for ($count = 1; $count <= 31; $count++) { $buffer .= "<TH CLASS='vis'>" . ($count < 10 ? "0" . $count : $count) . "</TH>"; } $buffer .= "<TH CLASS='vis'>" . $lvm_average . "</TH>\n"; $buffer .= "<TH CLASS='vis'>" . $lvm_total . "</TH></TR>\n"; $Month = $first_month; $Year = $first_year; $finished = false; $prev_year = $Year; $big_cnt_values = 0; $big_total = 0; for ($count = 1; $count <= $cnt_month; $count++) { // separation between 2 years if ($Year != $prev_year) { $buffer .= "<TR><TH BGCOLOR='#FFFFAA' COLSPAN='34' HEIGHT='1'>"; $buffer .= html_image("images/nothing.gif"); $buffer .= "</TH></TR>\n"; } // load month archive if exists $data = archive_month($Month, $Year, 'vpj'); // vpj: visitor per day if ($archive = $data[0] != NO_ARCHIVE) { $values = explode('+', $data[0]); } $buffer .= "<TR>\n"; $buffer .= "<TD CLASS='month'> <A CLASS='month' HREF='?view=" . VIEW_MONTH . "&year=" . $Year . "&month=" . sprintf('%02d', $Month) . "'>" . $lvm_arr_months[$Month] . "</A> </TD>"; $the_month = sprintf('%02d', $Month); $total = 0; $cnt_values = 0; for ($count2 = 1; $count2 <= 31; $count2++) { if (checkdate($Month, $count2, $Year)) { $day = date('D', mktime(12, 0, 0, $Month, $count2, $Year)); $color = $day == 'Sat' || $day == 'Sun' ? 'vis3' : 'vis1'; $buffer .= "<TD CLASS='" . $color . "' ALIGN='center'>"; $the_day = $Year . '/' . $the_month . '/' . ($count2 < 10 ? '0' . $count2 : $count2); if (!$finished) { if ($archive) { $val = $values[$count2 * 2 - 1]; } else { $query = "SELECT COUNT(*) AS D FROM " . $lvc_table_visitors . " WHERE DATE LIKE '" . $the_day . "%'"; $gDb->DbQuery($query); $gDb->DbNextRow(); $record = $gDb->Row; $val = $record['D']; } if ($val > 0) { $cnt_values++; } $buffer .= $val == 0 ? ' ' : $val; $total += $val; } else { $buffer .= ' '; } $finished = $finished || $the_day == $today; $buffer .= "</TD>"; } else { $buffer .= "<TD CLASS='vis2' ALIGN='right'> </TD>"; } } if ($cnt_values > 0) { $big_cnt_values += $cnt_values; $big_total += $total; } $buffer .= "<TD CLASS='avg' ALIGN='right' NOWRAP> " . ($cnt_values == 0 ? '' : number_format(round($total / $cnt_values), 0, '', ' ')) . " </TD>\n"; $buffer .= "<TD CLASS='month' ALIGN='right' NOWRAP> " . ($total == 0 ? '' : number_format($total, 0, '', ' ')) . " </TD></TR>\n"; $prev_year = $Year; $Month = $Month == 12 ? 1 : $Month + 1; $Year = $Month == 1 ? $Year + 1 : $Year; } $buffer .= "<TR><TH COLSPAN='32'>"; $buffer .= html_image("images/nothing.gif"); $buffer .= "</TH><TH BGCOLOR='#B8C8FE' COLSPAN='2' HEIGHT='1'>"; $buffer .= html_image("images/nothing.gif"); $buffer .= "</TH></TR>\n"; $buffer .= "<TD COLSPAN='32'> </TD>"; $buffer .= "<TD CLASS='avg' ALIGN='right' NOWRAP> " . ($big_cnt_values == 0 ? '' : number_format(round($big_total / $big_cnt_values), 0, '', ' ')) . " </TD>\n"; $buffer .= "<TD CLASS='month' ALIGN='right' NOWRAP> " . ($big_total == 0 ? '' : number_format($big_total, 0, '', ' ')) . " </TD></TR>\n"; $buffer .= "</TABLE></CENTER><BR>\n"; return $buffer; }
function module_img_last_months($arguments) { global $lvc_cache_dir; global $lvc_images_format; global $lvc_img_site_name; global $lvc_site_opening_month; global $lvc_site_opening_year; global $lvc_base_img_last_months; global $lvc_pattern_last_months; global $lvc_table_visitors; global $lvc_display_cache_delay; global $lvc_color_bg_out; global $lvc_color_bg_in; global $lvc_color_maxvalue; global $lvc_color_minvalue; global $lvc_color_value; global $lvc_color_bar_h; global $lvc_color_title; global $lvc_color_cache; global $lvm_arr_months_abbr, $lvm_img_12_months; global $gDb; // -------------------------------------------------------------------------- $width = 429; $height = 288; $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '.' . $lvc_images_format; // -------------------------------------------------------------------------- if ($arguments['generate'] == 0) { return 'WIDTH="' . $width . '" HEIGHT="' . $height . '"'; } // cache delay $cache_delay = $arguments['cache']; if (is_image_expired($file_name, $cache_delay)) { // image creation $image = imagecreate($width, $height); // image for histograms $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format; $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_last_months . '.' . $lvc_images_format); // colors $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff); $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0); $color_maxvalue = create_new_color($image, $lvc_color_maxvalue); $color_minvalue = create_new_color($image, $lvc_color_minvalue); $color_value = create_new_color($image, $lvc_color_value); $color_bar_h = create_new_color($image, $lvc_color_bar_h); $color_bg_in = create_new_color($image, $lvc_color_bg_in); $color_bg_out = create_new_color($image, $lvc_color_bg_out); $color_title = create_new_color($image, $lvc_color_title); $color_cache = create_new_color($image, $lvc_color_cache); imagefill($image, 0, 0, $color_bg_out); imagerectangle($image, 0, 0, 428, 287, $color_white); imagerectangle($image, 30, 20, 398, 267, $color_black); imagefilledrectangle($image, 31, 21, 397, 266, $color_white); imagefilledrectangle($image, 34, 24, 394, 263, $color_bg_in); // title $title = $lvc_img_site_name . ' - ' . $lvm_img_12_months; $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2); if ($start < 0) { $start = 2; } imagestring($image, 3, $start, 5, $title, $color_title); // looking for 1st month $current_year = date('Y'); $current_month = date('n'); $first_year = $current_year; $first_month = $current_month; for ($cnt_month = 1; $cnt_month < 12; $cnt_month++) { $first_month = $first_month == 1 ? 12 : $first_month - 1; $first_year = $first_month == 12 ? $first_year - 1 : $first_year; } // looking for values $month = $first_month; $year = $first_year; for ($cnt_month = 0; $cnt_month < 12; $cnt_month++) { $arr_months[$cnt_month] = $month; $finished = $year < $lvc_site_opening_year || $year == $lvc_site_opening_year && $month < $lvc_site_opening_month; if ($finished) { $value = 0; } else { $data = archive_month($month, $year, 'vpm'); if ($data[0] != NO_ARCHIVE) { $value = $data[0]; } else { $query = "SELECT COUNT(*) "; $query .= "FROM " . $lvc_table_visitors . " "; $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%'"; $gDb->DbQuery($query); $record = $gDb->DbNextRow(); $value = $record[0]; } } $arr_values[$cnt_month] = $value; if ($cnt_month == 0) { $max = $arr_values[0]; $min = $arr_values[0]; } if ($value > $max) { $max = $value; } if ($min == 0 || $value != 0 && $value < $min) { $min = $value; } $month = $month == 12 ? 1 : $month + 1; $year = $month == 1 ? $year + 1 : $year; } // horizontal bars $level = $lvc_base_img_last_months; while ($max > 3.75 * $level) { $level += $lvc_base_img_last_months; } for ($cnt = 0; $cnt <= 4; $cnt++) { $start = (int) ((30 - imagefontwidth(1) * strlen($cnt * $level)) / 2); imagestring($image, 1, 1 + $start, $height - 28 - $cnt * 60, $level * $cnt, $color_white); $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60; imageline($image, 35, $y, $width - 35, $y, $color_bar_h); } // histograms for ($cnt_month = 0; $cnt_month < 12; $cnt_month++) { // months names imagestring($image, 2, 42 + $cnt_month * 30, $height - 18, $lvm_arr_months_abbr[$arr_months[$cnt_month]], $color_white); $month = sprintf('%02d', $cnt_month + 1); if (($value = $arr_values[$cnt_month]) != 0) { // histograms $y = $height - 24 - $value * 60 / $level; imagecopyresized($image, $pattern, 38 + $cnt_month * 30, $y + 1, 0, 0, 24, $value * 60 / $level - 1, 24, 1); imagerectangle($image, 37 + $cnt_month * 30, $y, 62 + $cnt_month * 30, $height - 25, $color_black); // value $color = $value == $min ? $color_minvalue : $color_value; if ($value == $max) { $color = $color_maxvalue; } $start = (int) ((26 - imagefontwidth(1) * strlen($value)) / 2); imagestring($image, 1, $start + 38 + $cnt_month * 30, $y - 10, $value, $color); } } // cache delay if ($lvc_display_cache_delay) { imagestringup($image, 2, $width - 30, $height - 22, cache_delay($cache_delay), $color_cache); } imageinterlace($image, false); // saving image $fct_image = 'image' . $lvc_images_format; $fct_image($image, $file_name); // sending image header('Content-type: image/' . $lvc_images_format); $fct_image($image); } else { // sending image header('Content-type: image/' . $lvc_images_format); echo fread(fopen($file_name, 'r'), filesize($file_name)); } }