Show sourcecode

The following files exists in this folder. Click to view.

Foogler_blog/pages

PAuthor.php
PCommentProcess.php
PDeleteCommentProcess.php
PDeletePost.php
PDeletePostProcess.php
PEditPost.php
PEditPostProcess.php
PErDiagramme.php
PIndex.php
PInstall.php
PInstallProcess.php
PNewPost.php
PNewPostProcess.php
PRssFeed.php
PShowPost.php
PStatistics.php
PValidate.php
login/

PStatistics.php

78 lines ASCII Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
//----------------------
//PStatistics.php
//
//Shows blog statistics
//----------------------

//Checks that user is logged in
if(!isset($_SESSION['accountUser'])) {
  require_once(
"login/PLogin.php");
  exit;  
}

//-----------------------------------
//Handles DB query
$mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_DATABASE); //New DB object
$tablePost   DB_PREFIX 'Post';
$tableComment   DB_PREFIX 'Comment';

if (
mysqli_connect_error()) {
   echo 
"Connect failed: ".mysqli_connect_error()."<br>";
   exit();
}
$mysqli->set_charset("utf8");

//-----------------
//SQL query
$query = <<<END
--
-- Gets post stats (10, 30, 365 days and total number of posts) 
--
SELECT DISTINCT (
  SELECT COUNT(idPost) 
    FROM 
{$tablePost} 
    WHERE postDate BETWEEN DATE_SUB(NOW(), INTERVAL 10 DAY) AND NOW()
  ) AS 'tenDays',
  (
  SELECT COUNT(idPost) 
    FROM 
{$tablePost} 
    WHERE postDate BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW()
  ) AS 'thirtyDays',
  (
  SELECT COUNT(idPost) 
    FROM 
{$tablePost} 
    WHERE postDate BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW()
  ) AS year,
  COUNT(idPost) AS 'all'
  FROM 
{$tablePost};
END;

//Performs query
$res $mysqli->query($query) or die("Could not query database" $mysqli->errno .":" $mysqli->error); 
$row $res->fetch_object(); //Gets result query

//HTML
$html = <<<END
  <h2>Statistics</h2>
  Number of posts written the last 10 days: <b>
{$row->tenDays}</b><br />
  Number of posts written the last 30 days: <b>
{$row->thirtyDays}</b><br/>
  Number of posts written the last year: <b>
{$row->year}</b><br />
  Total number of posts: <b>
{$row->all}</b>
END;

$res->close();
$mysqli->close(); //Closes DB connection

//-----------------------------------
//Prints HTML
require_once(TP_SOURCEPATH "CHTMLPage.php");

$page = new CHTMLPage();

$page->printHTMLHeader();
$page->printPageHeader();
$page->printPageBody($html);
$page->printTagList();
$page->printRightColumn();