PHP-Code:
<?php
//next_birthday_advanced Module//
/**
* Content code
* @package next_birthday_advanced
* @Copyright (C) 2005 Michael Schläpfer
* @ All rights reserved
* @ next_birthday_advanced is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.4
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $database;
global $style, $nbdlogo, $displayrealname, $showage, $numberofusers, $nameofbirthdayfield, $nameofprefix, $linktoprofile, $linktopms, $today, $tomorrow, $in, $days;
$style = $params->get( 'style' );
$nbdlogo = $params->get( 'nbdlogo' );
$displayrealname = $params->get( 'displayrealname' );
$showage = $params->get( 'showage' );
$numberofusers = $params->get( 'numberofusers' );
$nameofbirthdayfield = $params->get( 'nameofbirthdayfield' );
$nameofprefix = $params->get( 'nameofprefix' );
$linktoprofile = $params->get( 'linktoprofile' );
$linktopms = $params->get( 'linktopms' );
$today = $params->get( 'today' );
$tomorrow = $params->get( 'tomorrow' );
$in = $params->get( 'in' );
$days = $params->get( 'days' );
//Datenbanktabellen mit prefix verknüpfen
$nameofcbdb = $nameofprefix."comprofiler";
$nameofuserdb = $nameofprefix."users";
//Abfrage erstellen mit Sortierung nach Geburtstagen
$query = "SELECT DISTINCT a.user_id, a.banned, a.$nameofbirthdayfield, b.username, b.name, b.block, MONTH(a.$nameofbirthdayfield) as mymonth, DAYOFMONTH(a.$nameofbirthdayfield) as myday, (YEAR( now( ) ) - YEAR( a.$nameofbirthdayfield ) ) AS age FROM $nameofcbdb AS a, $nameofuserdb AS b WHERE a.user_id = b.id ORDER BY mymonth, myday";
//Datenbankabfrage
$database->setQuery( $query );
//Laden der DB Results
$rows = $database->loadObjectList();
//Initialisieren der Ausgabe
$content = "<table border=\"0\" width=\"100%\">\n";
//Anzeigen des Next Birthday Logos
if($nbdlogo == 1){
$content .= "<tr><td colspan=\"2\">\n<img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/nbdlogo.gif\" border=\"0\">\n</td></tr>\n";
}
//Initalisieren der gefundenen Geburtstage
$numberoffound = 0;
//Abfrage aller Userdaten
for($i = 0; $i < count($rows) && $numberoffound < $numberofusers; $i++){
//Abfangen aller Usereinträge, in denen ein Geburtstag definiert wurde
if($rows[$i]->$nameofbirthdayfield != "0000-00-00" && $rows[$i]->$nameofbirthdayfield != null && $rows[$i]->banned == 0 && $rows[$i]->block == 0){//v1.3: Bedingung wurde erweitert für leere Eingabe, bei erfassen neuer User
//Ermitteln der Differenz in Tagen
$differenz = (int)(diff($rows[$i]->$nameofbirthdayfield, date("Y-m-d")));
//Behandeln aller Geburtstage von jetzt bis Ende Jahr ---------------------------------------------------------
if($differenz >= 0){
//Neue Zeile initalisieren
$content.= "<tr><td rowspan=\"2\">";
//Heute
if($differenz == 0){
if($style == 2 || $style == 3){
$content .= "<img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/birthday1.gif\" border=\"0\" height=\"22\">";
}
$content .= "</td><td><b>".$today.":</b></td></tr>\n<tr><td>";
}
//Morgen
elseif($differenz == 1){
if($style == 2 || $style == 3){
$content .= "<img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/birthday2.gif\" border=\"0\" height=\"22\">";
}
$content .= "</td><td><b>".$tomorrow.":</b></td></tr>\n<tr><td>";
}
//Sonst
elseif($differenz > 1){
if($style == 2 || $style == 3){
$content .= "<img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/birthday3.gif\" border=\"0\" height=\"22\">";
}
$content .= "</td><td><b>".$in." ".$differenz." ".$days.":</b></td></tr>\n<tr><td>";
}
//Anzuzeigenden Namen definieren
if($displayrealname == 1){
$nametoshow = $rows[$i]->name;
}
else{
$nametoshow = $rows[$i]->username;
}
//Anzuzeigendes Alter definieren
if($showage == 1){
$age = $rows[$i]->age;
//Geburtstag erst im nächsten Jahr
if($rows[$i]->mymonth < date("m") AND $rows[$i]->myday < date("d")) {
$age++;
}
$agetoshow = "(".$age.")";
}
//Namen verlinken und anfügen
if($linktoprofile == 1){
$content .= "<a href=\"". sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='. $rows[$i]->user_id)."\">".$nametoshow." ".$agetoshow."</a>";
}
else{
$content .= $nametoshow." (".$age.")";
}
//PMS Link einfügen
if ($linktopms == 1) {
$content .= " <a href=\"". sefRelToAbs('index.php?option=com_pms&page=new&id='. $rows[$i]->username)."\"><img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/maillogo.png\" border=\"0\" height=\"14\"></a>\n";
}
//Zeile abschliessen
$content .= "</td></tr>\n";
//Trennstrich einfügen
if($style == 1 || $style == 3){
$content .= "<tr><td colspan=\"2\"><hr></td></tr>";
}
//Gefundene Geburtstage um eins erhöhen
$numberoffound++;
}
}
}
//Geburtstage im nächsten Jahr, falls noch nicht genügend User in diesem Jahr -------------------------------------------------
if($numberoffound < $numberofusers){
for($i = 0; $i < count($rows) && $numberoffound < $numberofusers; $i++){
if($rows[$i]->$nameofbirthdayfield != "0000-00-00" && $rows[$i]->$nameofbirthdayfield != null && $rows[$i]->banned == 0 && $rows[$i]->block == 0){//v1.3: Bedingung wurde erweitert für leere Eingabe, bei erfassen neuer User
//Differenz ermitteln bis Ende Jahr
$differenz = (int)(diff(date("Y-m-d", mktime(0, 0, 0, 12, 31, date("Y"))), date("Y-m-d")) + 0.5);
//Differenz ermitteln ab Anfang nächsten Jahres und addieren
$differenz += (int)(diff($rows[$i]->$nameofbirthdayfield, date("Y-m-d", mktime(0, 0, 0, 1, 1, date("Y")+1))) + 0.5) + 1;
//Zeile initialisieren
$content .= "<tr><td rowspan=\"2\">";
if($style == 2 || $style == 3){
$content .= "<img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/birthday3.gif\" border=\"0\" height=\"22\">";
}
//Anzuzeigenden Namen definieren
if($displayrealname == 1){
$nametoshow = $rows[$i]->name;
}
else{
$nametoshow = $rows[$i]->username;
}
//Anzuzeigendes Alter definieren
if($showage == 1){
$age = $rows[$i]->age + 1;
$agetoshow = "(".$age.")";
}
$content .= "</td><td><b>".$in." ".$differenz." ".$days.":</b></td></tr>\n<tr><td>";
//Name verlinken und anfügen
if($linktoprofile == 1){
$content .= "<a href=\"". sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='. $rows[$i]->user_id)."\">".$nametoshow." ".$agetoshow."</a>";
}
else{
$content .= $nametoshow." (".$age.")";;
}
//PMS Link einfügen
if ($linktopms == 1) {
$content .= " <a href=\"". sefRelToAbs('index.php?option=com_pms&page=new&id='. $rows[$i]->username)."\"><img src=\"".$mosConfig_live_site."/modules/mod_nextbd_advanced/icons/maillogo.png\" border=\"0\" height=\"14\"></a>\n";
}
//Zeile abschliessen
$content .= "</td></tr>\n";
//Trennlinie einfügen
if($style == 1 || $style == 3){
$content .= "<tr><td colspan=\"2\"><hr></td></tr>";
}
//Gefundene Geburtstage um eins erhöhen
$numberoffound++;
}
}
}
//Ausgabe abschliessen
$content .= "</table>\n";
//Berechnung der Differenz -----------------------------------------------------
function diff($date1, $date2){
$date1_ex = explode("-",$date1); /* Das Datum nach - auflösen */
$date2_ex = explode("-",$date2); /* Das Datum nach - auflösen */
$unix1 = mktime(0,0,0, $date1_ex[1] , $date1_ex[2] , $date2_ex[0]); /* UNIX-Zeitstempel erstellen */
$unix2 = mktime(0,0,0, $date2_ex[1] , $date2_ex[2] , $date2_ex[0]); /* UNIX-Zeitstempel erstellen */
$diff = $unix1-$unix2; // Differenz errechnen
$min = $diff/60; // Durch 60 Teilen um Minuten zu erhalten
$hours = $min/60; // Durch 60 Teilen um Stunden zu erhalten
$days = $hours/24; // Durch 24 Teilen um Tage zu erhalten
$res = $days; // Standard für Ergebnis
return $res; // Ergebnis zurückgeben
}
?>
Lesezeichen