Sidder og førsøger mig med at omsrkrive noget kode til OOP. Er dog rent ind i et problem. Koden er lavet til at sende statistik til den mailman er logget ind med, men der kommer ikke noget.
Sådan her ser den originale kode ud:
<?php
/* receive statistics */
$email = $_SESSION['email'];
/* prepare email */
$headers = "MIME-Version: 1.0\\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\\n";
/* prepare mail */
$subject = "Statistik fra MetroXpressen";
$message = "
<html>
<head>
<style type=\\"text/css\\">
<!--
body {
background-image: url('http://www.systemx.dk/metrox/images/background.jpg');
font-family: verdana;
font-size: 11px;
color: #ffffff;
}
.text {
font-family: verdana;
font-size: 11px;
color: #ffffff;
}
-->
</style>
</head>
<body>
<b>Kategorioversigt - Unikke hits</b>
<br><br>
<table width=220 cellpadding=0 cellspacing=0 border=1 bordercolor=#63A081>
<tr>
<td class=text width=130 align=center><b>Sektion</b></td>
<td class=text width=90 align=center><b>Hits</b></td>
</tr>";
$stat = mysql_query("select * from metro_stats order by totalcount desc") or die(mysql_error());
while ($data = mysql_fetch_array($stat)) {
$message .= "
<tr>
<td class=text width=130 align=center>";
if ($data['id'] == 1) { $message .= "Nyheder"; }
if ($data['id'] == 2) { $message .= "Regional"; }
if ($data['id'] == 3) { $message .= "Sport"; }
if ($data['id'] == 4) { $message .= "Erhverv"; }
if ($data['id'] == 5) { $message .= "112"; }
if ($data['id'] == 6) { $message .= "Underholdning"; }
$message .= "
</td>
<td class=text width=90 align=center>"; $message .= $data['totalcount']; $message .= "</b></td>
</tr>";
}
$message .= "</table>";
$message .= "<br>\\n\\n<b>Referrals til MetroXpressen!</b>\\n\\n<br><br>"; /*
/* retrieve referents from database */
$query = "SELECT * FROM metro_stats_referer ORDER BY times DESC";
$dbstats = mysql_query($query);
$message .= "
<table width=450 cellpadding=0 cellspacing=0 border=1 bordercolor=#63A081>
<tr>
<td class=text width=50 align=center><b>Hits</b></td>
<td class=text width=400 align=center><b>Referent</b></td>
</tr>";
while ($data = mysql_fetch_array($dbstats)) {
$message .= "
<tr>
<td class=text width=50 align=center>"; $message .= $data["times"]; $message .= "</td>
<td class=text width=400 align=center>"; $message .= $data["referer"]; $message .= "</b></td>
</tr>";
}
$message .= "
</table>
</body>
</html>";
mail($email, $subject, $message, $headers);
echo "Statistik e-mail er blevet sendt til "; echo $_SESSION['email'];
?>
Og sådan ser den ud efter jeg har lavet den med OOP
<?php
class stats {
function __construct() {
$this->email = $_SESSION['email'];
}
function genmail() {
$this->headers = "MIME-Version: 1.0\\n";
$this->headers . = "Content-type: text/html; charset=iso-8859-1\\n";
$this->subject = "Statistik fra MetroXpressen";
$this->message = "
<html>
<head>
<style type=\\"text/css\\">
<!--
body {
background-image: url('http://www.systemx.dk/metrox/images/background.jpg');
font-family: verdana;
font-size: 11px;
color: #ffffff;
}
.text {
font-family: verdana;
font-size: 11px;
color: #ffffff;
}
-->
</style>
</head>
<body>
<b>Kategorioversigt - Unikke hits</b>
<br><br>
<table width=220 cellpadding=0 cellspacing=0 border=1 bordercolor=#63A081>
<tr>
<td class=text width=130 align=center><b>Sektion</b></td>
<td class=text width=90 align=center><b>Hits</b></td>
</tr>";
}
function connectmysql() {
mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxxx
$this->stat = mysql_query("select * from metro_stats order by totalcount desc") or die(mysql_error());
while ($data = mysql_fetch_array($stat)) {
$this->message .= "
<tr>
<td class=text width=130 align=center>";
if ($data['id'] == 1) { $this->message .= "Nyheder"; }
if ($data['id'] == 2) { $this->message .= "Regional"; }
if ($data['id'] == 3) { $this->message .= "Sport"; }
if ($data['id'] == 4) { $this->message .= "Erhverv"; }
if ($data['id'] == 5) { $this->message .= "112"; }
if ($data['id'] == 6) { $this->message .= "Underholdning"; }
$this->message .= "
</td>
<td class=text width=90 align=center>"; $this->message .= $data['totalcount']; $this->message .= "</b></td>
</tr>";
}
$this->message .= "</table>";
$this->message .= "<br>\\n\\n<b>Referrals til MetroXpressen!</b>\\n\\n<br><br>";
$query = "SELECT * FROM metro_stats_referer ORDER BY times DESC";
$dbstats = mysql_query($query);
$this->message .= "
<table width=450 cellpadding=0 cellspacing=0 border=1 bordercolor=#63A081>
<tr>
<td class=text width=50 align=center><b>Hits</b></td>
<td class=text width=400 align=center><b>Referent</b></td>
</tr>";
while ($data = mysql_fetch_array($dbstats)) {
$this->message .= "
<tr>
<td class=text width=50 align=center>"; $this->message .= $data["times"]; $this->message .= "</td>
<td class=text width=400 align=center>"; $this->message .= $data["referer"]; $this->message .= "</b></td>
</tr>";
}
$this->message .= "
</table>
</body>
</html>";
}
function sendmail() {
mail($this->email, $this->subject, $this->message, $this->headers);
echo "
Statistik e-mail er blevet sendt til ";
echo $_SESSION['email'];
}
?>
Anders!