Viewing file: db_mysql.inc.php (46 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/*
############################################################################
# DWmail
# - version 4.0
# - Copyright (c) 2003-2006 Dominion Web Design
# - http://www.dominion-web.com/products/dwmail/
############################################################################
#
# The contents of this file are subject to the DWmail License version
# 2.2 ('License'). You may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.dominion-web.com/products/dwmail/license.php
# Software distributed under the License is distributed on an "AS IS" basis,
# without warranty of any kind, either express or implied.
#
# This code is Copyright (c) 2003-2006 Dominion Web Design.
# All rights reserved.
#
# This software may not be redistributed outside the terms of the
# license agreement.
#
############################################################################
*/
// #############################################################################
// This class is for standard MySQL extensions.
// If you are using PHP 5+ AND MySQL 4.1+ you should use the mysqli library
class DB_Connection {
var $_DBUserName;
var $_DBPassword;
var $_DBDatabase;
var $_DBHost;
var $_cn;
var $_db;
var $_DBUserID;
var $_daycount;
var $_lastlogindate;
var $_lastlogintime;
var $_currentemailaddress;
var $_currentpassword;
var $_externallist;
var $_dayrecur;
var $_weekdayrecur;
var $_weekrecur;
var $_monthrecur;
var $_yearrecur;
function DB_Connection($dbhost, $dbuser, $dbpassword, $dbdatabase) {
$this->_DBUserName=$dbuser;
$this->_DBPassword=$dbpassword;
$this->_DBHost=$dbhost;
$this->_DBDatabase=$dbdatabase;
}
function DBConnect() {
$this->_cn = mysql_connect($this->_DBHost, $this->_DBUserName, $this->_DBPassword);
return $this->_cn;
}
function TableSelect() {
$this->_db = mysql_select_db($this->_DBDatabase, $this->_cn);
return $this->_db;
}
function DB_MakeConnection() {
$this->DBConnect();
if ($this->_cn) {
$this->TableSelect();
if ($this->_db) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
function DB_CloseConnection() {
mysql_close($this->_cn);
}
function DB_CheckUser($currentemailaddress, $currentpassword) {
$this->_currentemailaddress = $currentemailaddress;
$this->_currentpassword = $currentpassword;
$result = mysql_query ("SELECT `id`, DATE_FORMAT(`lastlogin`, '%D %M %Y') as lastdateformat, DATE_FORMAT(`lastlogin`, '%T') as lasttimeformat, emailclear FROM `dwm-users` WHERE `emailaddress` = MD5('" . $currentemailaddress . "') and `password` = MD5('" . $currentpassword . "') LIMIT 0,1");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$db_id = $row["id"];
$this->_lastlogindate = $row["lastdateformat"];
$this->_lastlogintime = $row["lasttimeformat"];
if (empty($row["emailclear"])) {
$result3 = mysql_query ("UPDATE `dwm-users` SET `emailclear` = '" . strtolower($currentemailaddress) . "' WHERE `id` = '" . $db_id . "'");
}
}
else {
$result2 = mysql_query ("INSERT INTO `dwm-users` (`emailaddress`, `password`, `lastlogin`, `emailclear`) VALUES (MD5('" . $currentemailaddress . "'), MD5('" . $currentpassword . "'), NOW(), '" . strtolower($currentemailaddress) . "')");
if (!$result2) {
echo mysql_error();
}
$db_id = mysql_insert_id();
}
if (isset($db_id)) {
$this->_DBUserID = $db_id;
return $this->_DBUserID;
}
}
function DB_FindProfile($oldemail, $oldpassword) {
$result = mysql_query ("SELECT `id` FROM `dwm-users` WHERE `emailaddress` = MD5('" . $oldemail . "') and `password` = MD5('" . $oldpassword . "') LIMIT 0,1");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$oldid = $row["id"];
}
else {
$oldid = FALSE;
}
return $oldid;
}
function DB_UpdateLastLogin() {
$result = mysql_query ("UPDATE `dwm-users` SET lastlogin = NOW() WHERE `emailaddress` = MD5('" . $this->_currentemailaddress . "') and `password` = MD5('" . $this->_currentpassword . "')");
return $result;
}
function DB_LogAccess($IPLogging) {
if ($IPLogging == 1) {
$result = mysql_query ("INSERT INTO `dwm-stats` (`logindts`, `userid`, `ipaddress`) VALUES (NOW(), '" . $this->_DBUserID . "', '" . $_SERVER['REMOTE_ADDR'] . "')");
}
else {
$result = mysql_query ("INSERT INTO `dwm-stats` (`logindts`, `userid`) VALUES (NOW(), '" . $this->_DBUserID . "')");
}
return $result;
}
function DB_LogSend($recipients) {
$result = mysql_query ("INSERT INTO `dwm-statscompose` (`userid`, `sentdts`, `recipients`) VALUES ('" . $this->_DBUserID . "', NOW(), '$recipients')");
return $result;
}
function DB_LoginPeriod($period) {
$result = mysql_result(mysql_query("SELECT count(`id`) FROM `dwm-stats` WHERE TO_DAYS(NOW()) - TO_DAYS(`logindts`) <= $period"),0);
return $result;
}
function DB_LoginStats($period) {
// Sent emails
$result = mysql_result(mysql_query("SELECT count(`id`) FROM `dwm-statscompose` WHERE TO_DAYS(NOW()) - TO_DAYS(`sentdts`) <= $period"),0);
return $result;
}
function DB_CleanUp($cleanup) {
// Delete all users and user data where we have a) a number of days set and
// b) haven't logged in in that number of days
if ($cleanup > 0) {
$result = mysql_query ("SELECT * FROM `dwm-users` WHERE TO_DAYS(NOW()) - TO_DAYS(`lastlogin`) >= $cleanup");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$db_id = $row["id"];
$result11 = mysql_query ("DELETE FROM `dwm-attendees` WHERE `userid` = '$db_id'");
$result10 = mysql_query ("DELETE FROM `dwm-alias` WHERE `userid` = '$db_id'");
$result3 = mysql_query ("DELETE FROM `dwm-addressbook` WHERE `userid` = '$db_id'");
$result2 = mysql_query ("DELETE FROM `dwm-calendar` WHERE `userid` = '$db_id'");
$result4 = mysql_query ("DELETE FROM `dwm-prefs` WHERE `userid` = '$db_id'");
$result6 = mysql_query ("DELETE FROM `dwm-filters` WHERE `userid` = '$db_id'");
$result7 = mysql_query ("DELETE FROM `dwm-pop3` WHERE `userid` = '$db_id'");
$result8 = mysql_query ("DELETE FROM `dwm-groups` WHERE `userid` = '$db_id'");
$result9 = mysql_query ("DELETE FROM `dwm-groupmembers` WHERE `userid` = '$db_id'");
$result5 = mysql_query ("DELETE FROM `dwm-users` WHERE `id` = '$db_id'");
}
}
}
/*
ADDRESS BOOK FUNCTIONS
----------------------
*/
function DB_GetEmailList($LetterView = 'all') {
if ($LetterView == 'all') {
$SQLStatement = "SELECT * FROM `dwm-addressbook` WHERE (`userid` = '" . $this->_DBUserID . "' or `userid` = 0) ORDER BY `lastname`";
}
elseif ($LetterView == 'num') {
$SQLStatement = "SELECT * FROM `dwm-addressbook` WHERE (`userid` = '" . $this->_DBUserID . "' or `userid` = 0) AND LEFT(UCASE(`lastname`), 1) = '0' OR LEFT(UCASE(`lastname`), 1) = '1' OR LEFT(UCASE(`lastname`), 1) = '2' OR LEFT(UCASE(`lastname`), 1) = '3' OR LEFT(UCASE(`lastname`), 1) = '4' OR LEFT(UCASE(`lastname`), 1) = '5' OR LEFT(UCASE(`lastname`), 1) = '6' OR LEFT(UCASE(`lastname`), 1) = '7' OR LEFT(UCASE(`lastname`), 1) = '8' OR LEFT(UCASE(`lastname`), 1) = '9' ORDER BY `lastname`";
}
else {
$SQLStatement = "SELECT * FROM `dwm-addressbook` WHERE (`userid` = '" . $this->_DBUserID . "' or `userid` = 0) AND LEFT(UCASE(`lastname`), 1) = '" . $LetterView . "' ORDER BY `lastname`";
}
$result = mysql_query ($SQLStatement);
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$ab_entry[$entryid]['userid'] = $row["userid"];
$ab_entry[$entryid]['firstname'] = $row["firstname"];
$ab_entry[$entryid]['lastname'] = $row["lastname"];
$ab_entry[$entryid]['email'] = $row["email"];
$ab_entry[$entryid]['id'] = $entryid;
$ab_entry[$entryid]['title'] = str_replace('"', """, stripslashes($row["title"]));
$ab_entry[$entryid]['homephone'] = str_replace('"', """, stripslashes($row["homephone"]));
$ab_entry[$entryid]['workphone'] = str_replace('"', """, stripslashes($row["workphone"]));
$ab_entry[$entryid]['cellphone'] = str_replace('"', """, stripslashes($row["cellphone"]));
$ab_entry[$entryid]['fax'] = str_replace('"', """, stripslashes($row["fax"]));
$ab_entry[$entryid]['homeaddress'] = stripslashes($row["homeaddress"]);
$ab_entry[$entryid]['workaddress'] = stripslashes($row["workaddress"]);
$ab_entry[$entryid]['url'] = stripslashes($row["url"]);
$ab_entry[$entryid]['notes'] = stripslashes($row["notes"]);
} while($row = mysql_fetch_array($result));
}
return $ab_entry;
}
function DB_SearchList($searchparam) {
$SQLStatement = "SELECT * FROM `dwm-addressbook` WHERE (`userid` = '" . $this->_DBUserID . "' or `userid` = 0) AND (UCASE(`lastname`) LIKE '" . $searchparam . "%' OR UCASE(`firstname`) LIKE '" . $searchparam . "%' OR UCASE(`email`) LIKE '" . $searchparam . "%') ORDER BY `lastname`";
$result = mysql_query ($SQLStatement);
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$ab_entry[$entryid]['userid'] = $row["userid"];
$ab_entry[$entryid]['firstname'] = $row["firstname"];
$ab_entry[$entryid]['lastname'] = $row["lastname"];
$ab_entry[$entryid]['email'] = $row["email"];
$ab_entry[$entryid]['id'] = $entryid;
} while($row = mysql_fetch_array($result));
}
return $ab_entry;
}
function DB_GetGroupList() {
$SQLStatement = "SELECT * FROM `dwm-groups` WHERE `userid` = '" . $this->_DBUserID . "' ORDER BY `name`";
$result = mysql_query ($SQLStatement);
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["id"];
$ab_entry[$entryid]['groupname'] = $row["name"];
$NumberofMembers = mysql_result(mysql_query("SELECT COUNT(`addressbookid`) FROM `dwm-groupmembers` WHERE `userid` = '" . $this->_DBUserID . "' AND `groupid` = '" . $entryid . "'"),0);
$ab_entry[$entryid]['count'] = $NumberofMembers;
$ab_entry[$entryid]['id'] = $entryid;
} while($row = mysql_fetch_array($result));
}
return $ab_entry;
}
function DB_GetEntryDetails($entryid) {
$result = mysql_query ("SELECT * FROM `dwm-addressbook` WHERE (`userid` = '" . $this->_DBUserID . "' OR `userid` = 0) AND `entryid` = $entryid ORDER BY `lastname` LIMIT 0,1");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$entrydetails['userid'] = $row["userid"];
$entrydetails['firstname'] = str_replace('"', """, stripslashes($row["firstname"]));
$entrydetails['lastname'] = str_replace('"', """, stripslashes($row["lastname"]));
$entrydetails['email'] = str_replace('"', """, stripslashes($row["email"]));
$entrydetails['title'] = str_replace('"', """, stripslashes($row["title"]));
$entrydetails['homephone'] = str_replace('"', """, stripslashes($row["homephone"]));
$entrydetails['workphone'] = str_replace('"', """, stripslashes($row["workphone"]));
$entrydetails['cellphone'] = str_replace('"', """, stripslashes($row["cellphone"]));
$entrydetails['fax'] = str_replace('"', """, stripslashes($row["fax"]));
$entrydetails['homeaddress'] = stripslashes($row["homeaddress"]);
$entrydetails['workaddress'] = stripslashes($row["workaddress"]);
$entrydetails['url'] = stripslashes($row["url"]);
$entrydetails['notes'] = stripslashes($row["notes"]);
}
else {
$entrydetails['lastname'] = "Invalid ID";
}
return $entrydetails;
}
function DB_GetGroupDetails($entryid) {
$result = mysql_query ("SELECT * FROM `dwm-groups` WHERE `userid` = '" . $this->_DBUserID . "' AND `id` = $entryid ORDER BY `name` LIMIT 0,1");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$entrydetails['name'] = str_replace('"', """, stripslashes($row["name"]));
}
else {
$entrydetails['name'] = "Invalid ID";
}
return $entrydetails;
}
function DB_FindGroup($searchname) {
$NumberofResults = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `dwm-groups` WHERE `name` = '" . trim(strip_tags(addslashes($searchname))) . "' AND `userid` = '" . $this->_DBUserID . "'"),0);
if ($NumberofResults > 1) {
// Oops we have found too many groups, to be safe we are going to drop this and return false
return FALSE;
}
elseif ($NumberofResults == 0) {
// Oops we have found too many groups, to be safe we are going to drop this and return false
return FALSE;
}
else {
// Good we have only found one group matching the request
$result = mysql_query ("SELECT * FROM `dwm-groups` WHERE `name` = '" . trim(strip_tags(addslashes($searchname))) . "' AND `userid` = '" . $this->_DBUserID . "' LIMIT 0,1");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$groupid = $row["id"];
$result2 = mysql_query ("SELECT * FROM `dwm-groupmembers` WHERE `userid` = '" . $this->_DBUserID . "' AND `groupid` = " . $groupid);
if ($row2 = mysql_fetch_array($result2)) {
do {
$lookupid = $row2["addressbookid"];
$result3 = mysql_query ("SELECT * FROM `dwm-addressbook` WHERE `userid` = '" . $this->_DBUserID . "' AND `entryid` = " . $lookupid);
if ($row3 = mysql_fetch_array($result3)) {
$entrydetails[$lookupid]['firstname'] = stripslashes($row3["firstname"]);
$entrydetails[$lookupid]['lastname'] = stripslashes($row3["lastname"]);
$entrydetails[$lookupid]['email'] = stripslashes($row3["email"]);
}
} while($row2 = mysql_fetch_array($result2));
}
}
return $entrydetails;
}
}
function DB_GetGroupMembers($entryid = 0) {
$result = mysql_query ("SELECT * FROM `dwm-addressbook` WHERE `userid` = '" . $this->_DBUserID . "' ORDER BY `lastname`");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$addressbookid = $row["entryid"];
if ($entryid > 0) {
$ismember = mysql_result(mysql_query("SELECT COUNT(`addressbookid`) FROM `dwm-groupmembers` WHERE `userid` = '" . $this->_DBUserID . "' AND `groupid` = " . $entryid . " AND `addressbookid` = " . $addressbookid),0);
}
else {
$ismember = 0;
}
$ab_entry[$addressbookid]['firstname'] = $row["firstname"];
$ab_entry[$addressbookid]['lastname'] = $row["lastname"];
$ab_entry[$addressbookid]['email'] = $row["email"];
$ab_entry[$addressbookid]['id'] = $entryid;
$ab_entry[$addressbookid]['ismember'] = $ismember;
} while($row = mysql_fetch_array($result));
}
return $ab_entry;
}
function DB_NewEntry($submitteddetails) {
$result = mysql_query ("INSERT INTO `dwm-addressbook` (`userid`, `lastname`, `firstname`, `email`, `title`, `homephone`, `workphone`, `cellphone`, `fax`, `homeaddress`, `workaddress`, `url`, `notes`) VALUES ('" . $this->_DBUserID . "', '" . $submitteddetails['lastname'] . "', '" . $submitteddetails['firstname'] . "', '" . $submitteddetails['email'] . "', '" . $submitteddetails['title'] . "', '" . $submitteddetails['homephone'] . "', '" . $submitteddetails['workphone'] . "', '" . $submitteddetails['cellphone'] . "', '" . $submitteddetails['fax'] . "', '" . $submitteddetails['homeaddress'] . "', '" . $submitteddetails['workaddress'] . "', '" . $submitteddetails['url'] . "', '" . $submitteddetails['notes'] . "')");
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_NewGroup($submitteddetails) {
$checkexist = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `dwm-groups` WHERE `userid` = '" . $this->_DBUserID . "' AND `name` = '" . addslashes($submitteddetails['name']) . "'"),0);
if ($checkexist == 0) {
$result = mysql_query ("INSERT INTO `dwm-groups` (`userid`, `name`) VALUES ('" . $this->_DBUserID . "', '" . addslashes($submitteddetails['name']) . "')");
if (!$result) {
echo mysql_error();
}
$newgroupid = mysql_insert_id();
if (is_array($submitteddetails['members'])) {
while(list($key, $value) = each($submitteddetails['members'])) {
$result2 = mysql_query ("INSERT INTO `dwm-groupmembers` (`userid`, `groupid`, `addressbookid`) VALUES ('" . $this->_DBUserID . "', " . $newgroupid . ", " . $submitteddetails['members'][$key] . ")");
if (!$result2) {
echo mysql_error();
}
}
}
return $result;
}
else {
return FALSE;
}
}
function DB_UpdateEntry($entryid, $submitteddetails) {
$result = mysql_query ("UPDATE `dwm-addressbook` SET `lastname` = '" . $submitteddetails['lastname'] . "', `firstname` = '" . $submitteddetails['firstname'] . "', `email` = '" . $submitteddetails['email'] . "', `title` = '" . $submitteddetails['title'] . "', `homephone` = '" . $submitteddetails['homephone'] . "', `workphone` = '" . $submitteddetails['workphone'] . "', `cellphone` = '" . $submitteddetails['cellphone'] . "', `fax` = '" . $submitteddetails['fax'] . "', `homeaddress` = '" . $submitteddetails['homeaddress'] . "', `workaddress` = '" . $submitteddetails['workaddress'] . "', `url` = '" . $submitteddetails['url'] . "', `notes` = '" . $submitteddetails['notes'] . "' WHERE userid = '" . $this->_DBUserID . "' AND entryid = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_UpdateGroup($entryid, $submitteddetails) {
$result = mysql_query ("UPDATE `dwm-groups` SET `name` = '" . $submitteddetails['name'] . "' WHERE userid = '" . $this->_DBUserID . "' AND `id` = " . $entryid);
if (!$result) {
echo mysql_error();
}
$result2 = mysql_query ("DELETE FROM `dwm-groupmembers` WHERE `userid` = '" . $this->_DBUserID . "' AND `groupid` = " . $entryid);
if (!$result2) {
echo mysql_error();
}
if (is_array($submitteddetails['members'])) {
while(list($key, $value) = each($submitteddetails['members'])) {
$result3 = mysql_query ("INSERT INTO `dwm-groupmembers` (`userid`, `groupid`, `addressbookid`) VALUES ('" . $this->_DBUserID . "', " . $entryid . ", " . $submitteddetails['members'][$key] . ")");
if (!$result3) {
echo mysql_error();
}
}
}
return $result;
}
function DB_DeleteEntry($entryid) {
$result = mysql_query ("DELETE FROM `dwm-addressbook` WHERE userid = '" . $this->_DBUserID . "' AND entryid = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_DeleteGroup($entryid) {
$result = mysql_query ("DELETE FROM `dwm-groupmembers` WHERE userid = '" . $this->_DBUserID . "' AND groupid = " . $entryid);
$result2 = mysql_query ("DELETE FROM `dwm-groups` WHERE userid = '" . $this->_DBUserID . "' AND id = " . $entryid);
return $result2;
}
function DB_EntryExist($emailcheck) {
$emailexist = mysql_result(mysql_query("SELECT COUNT(`entryid`) FROM `dwm-addressbook` WHERE `userid` = '" . $this->_DBUserID . "' AND `email` = '" . trim($emailcheck) . "'"),0);
if ($emailexist >= 1) {
return TRUE;
}
else {
return FALSE;
}
}
function DB_CopyContacts($oldid) {
$result = mysql_query ("SELECT * FROM `dwm-addressbook` WHERE `userid` = $oldid");
if (!$result) {
$errors .= mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$lastname = stripslashes($row["lastname"]);
$firstname = stripslashes($row["firstname"]);
$email = stripslashes($row["email"]);
$title = stripslashes($row["title"]);
$homephone = stripslashes($row["homephone"]);
$workphone = stripslashes($row["workphone"]);
$cellphone = stripslashes($row["cellphone"]);
$fax = stripslashes($row["fax"]);
$homeaddress = stripslashes($row["homeaddress"]);
$workaddress = stripslashes($row["workaddress"]);
$url = stripslashes($row["url"]);
$notes = stripslashes($row["notes"]);
$result2 = mysql_query ("INSERT INTO `dwm-addressbook` (`userid`, `lastname`, `firstname`, `email`, `title`, `homephone`, `workphone`, `cellphone`, `fax`, `homeaddress`, `workaddress`, `url`, `notes`) VALUES ('" . $this->_DBUserID . "', '" . addslashes($lastname) . "', '" . addslashes($firstname) . "', '" . addslashes($email) . "', '" . addslashes($title) . "', '" . addslashes($homephone) . "', '" . addslashes($workphone) . "', '" . addslashes($cellphone) . "', '" . addslashes($fax) . "', '" . addslashes($homeaddress) . "', '" . addslashes($workaddress) . "', '" . addslashes($url) . "', '" . addslashes($notes) . "')");
if (!$result2) {
$errors .= mysql_error();
}
} while($row = mysql_fetch_array($result));
}
return $errors;
}
/*
CALENDAR FUNCTIONS
------------------
*/
function DB_CalDateCheck($currentdate) {
$this->_daycount = mysql_result(mysql_query("SELECT COUNT(`entryid`) FROM `dwm-calendar` WHERE `userid` = '" . $this->_DBUserID . "' AND '" . $currentdate . "' BETWEEN `starttime` AND `endtime`"),0);
$result = mysql_query ("SELECT `entryid`, HOUR(`starttime`) AS starthour, MINUTE(`starttime`) AS startminute, HOUR(`endtime`) AS endhour, MINUTE(`endtime`) AS endminute, DATE_FORMAT(`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(`endtime`, '%d/%m/%y') as enddate, `subject`, `recur` FROM `dwm-calendar` WHERE `userid` = '" . $this->_DBUserID . "' AND '" . $currentdate . "' BETWEEN DATE_FORMAT(`starttime`, '%Y-%m-%d') AND DATE_FORMAT(`endtime`, '%Y-%m-%d')");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$cal_entry[$entryid]['starthour'] = $row["starthour"];
$cal_entry[$entryid]['startminute'] = $row["startminute"];
$cal_entry[$entryid]['startdate'] = $row["startdate"];
$cal_entry[$entryid]['endhour'] = $row["endhour"];
$cal_entry[$entryid]['endminute'] = $row["endminute"];
$cal_entry[$entryid]['enddate'] = $row["enddate"];
$cal_entry[$entryid]['recur'] = $row["recur"];
$cal_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$cal_entry[$entryid]['id'] = $entryid;
} while($row = mysql_fetch_array($result));
}
return $cal_entry;
}
function DB_CalRecurCheck($currentdate, $day, $month, $year, $dow) {
$ReturnStatus = FALSE;
// Check every day events
$result = mysql_query ("SELECT a.`entryid`, b.`type`, b.`extras`, HOUR(a.`starttime`) AS starthour, MINUTE(a.`starttime`) AS startminute, HOUR(a.`endtime`) AS endhour, MINUTE(a.`endtime`) AS endminute, DATE_FORMAT(a.`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(a.`endtime`, '%d/%m/%y') as enddate, a.`subject` FROM `dwm-calendar` a, `dwm-recurring` b WHERE a.`recur` = '1' AND a.`entryid` = b.`calendarid` AND b.`type` = '1' AND b.`extras` = '1' AND a.`userid` = '" . $this->_DBUserID . "' AND DATE_FORMAT(a.`starttime`, '%Y-%m-%d') < '$currentdate' AND DATE_FORMAT(b.`dtsuntil`, '%Y-%m-%d') > '$currentdate'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$day_entry[$entryid]['starthour'] = $row["starthour"];
$day_entry[$entryid]['startminute'] = $row["startminute"];
$day_entry[$entryid]['startdate'] = $row["startdate"];
$day_entry[$entryid]['endhour'] = $row["endhour"];
$day_entry[$entryid]['endminute'] = $row["endminute"];
$day_entry[$entryid]['enddate'] = $row["enddate"];
$day_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$day_entry[$entryid]['id'] = $entryid;
$ReturnStatus = TRUE;
} while($row = mysql_fetch_array($result));
}
// Check week day events
$result = mysql_query ("SELECT a.`entryid`, b.`type`, b.`extras`, HOUR(a.`starttime`) AS starthour, MINUTE(a.`starttime`) AS startminute, HOUR(a.`endtime`) AS endhour, MINUTE(a.`endtime`) AS endminute, DATE_FORMAT(a.`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(a.`endtime`, '%d/%m/%y') as enddate, a.`subject` FROM `dwm-calendar` a, `dwm-recurring` b WHERE a.`recur` = '1' AND a.`entryid` = b.`calendarid` AND b.`type` = '1' AND b.`extras` = '2' AND a.`userid` = '" . $this->_DBUserID . "' AND DATE_FORMAT(a.`starttime`, '%Y-%m-%d') < '$currentdate' AND DATE_FORMAT(b.`dtsuntil`, '%Y-%m-%d') > '$currentdate' AND DAYOFWEEK('$currentdate') > 1 AND DAYOFWEEK('$currentdate') < 7");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$weekday_entry[$entryid]['starthour'] = $row["starthour"];
$weekday_entry[$entryid]['startminute'] = $row["startminute"];
$weekday_entry[$entryid]['startdate'] = $row["startdate"];
$weekday_entry[$entryid]['endhour'] = $row["endhour"];
$weekday_entry[$entryid]['endminute'] = $row["endminute"];
$weekday_entry[$entryid]['enddate'] = $row["enddate"];
$weekday_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$weekday_entry[$entryid]['id'] = $entryid;
$ReturnStatus = TRUE;
} while($row = mysql_fetch_array($result));
}
// Check weekly events
$result = mysql_query ("SELECT a.`entryid`, b.`type`, b.`extras`, HOUR(a.`starttime`) AS starthour, MINUTE(a.`starttime`) AS startminute, HOUR(a.`endtime`) AS endhour, MINUTE(a.`endtime`) AS endminute, DATE_FORMAT(a.`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(a.`endtime`, '%d/%m/%y') as enddate, a.`subject` FROM `dwm-calendar` a, `dwm-recurring` b WHERE a.`recur` = '1' AND a.`entryid` = b.`calendarid` AND b.`type` = '2' AND a.`userid` = '" . $this->_DBUserID . "' AND DAYOFWEEK(a.`starttime`) = '$dow' AND DATE_FORMAT(a.`starttime`, '%Y-%m-%d') < '$currentdate' AND DATE_FORMAT(b.`dtsuntil`, '%Y-%m-%d') > '$currentdate'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$week_entry[$entryid]['starthour'] = $row["starthour"];
$week_entry[$entryid]['startminute'] = $row["startminute"];
$week_entry[$entryid]['startdate'] = $row["startdate"];
$week_entry[$entryid]['endhour'] = $row["endhour"];
$week_entry[$entryid]['endminute'] = $row["endminute"];
$week_entry[$entryid]['enddate'] = $row["enddate"];
$week_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$week_entry[$entryid]['id'] = $entryid;
$ReturnStatus = TRUE;
} while($row = mysql_fetch_array($result));
}
// Check monthly events
$result = mysql_query ("SELECT a.`entryid`, b.`type`, b.`extras`, HOUR(a.`starttime`) AS starthour, MINUTE(a.`starttime`) AS startminute, HOUR(a.`endtime`) AS endhour, MINUTE(a.`endtime`) AS endminute, DATE_FORMAT(a.`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(a.`endtime`, '%d/%m/%y') as enddate, a.`subject` FROM `dwm-calendar` a, `dwm-recurring` b WHERE a.`recur` = '1' AND a.`entryid` = b.`calendarid` AND b.`type` = '3' AND a.`userid` = '" . $this->_DBUserID . "' AND DAYOFMONTH(a.`starttime`) = '$day' AND DATE_FORMAT(a.`starttime`, '%Y-%m-%d') < '$currentdate' AND DATE_FORMAT(b.`dtsuntil`, '%Y-%m-%d') > '$currentdate'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$month_entry[$entryid]['starthour'] = $row["starthour"];
$month_entry[$entryid]['startminute'] = $row["startminute"];
$month_entry[$entryid]['startdate'] = $row["startdate"];
$month_entry[$entryid]['endhour'] = $row["endhour"];
$month_entry[$entryid]['endminute'] = $row["endminute"];
$month_entry[$entryid]['enddate'] = $row["enddate"];
$month_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$month_entry[$entryid]['id'] = $entryid;
$ReturnStatus = TRUE;
} while($row = mysql_fetch_array($result));
}
// Check yearly events
$tzcurrdate = strtotime("$year-$month-$day");
$dayofyear = (date("z", $tzcurrdate) + 1);
$result = mysql_query ("SELECT a.`entryid`, b.`type`, b.`extras`, HOUR(a.`starttime`) AS starthour, MINUTE(a.`starttime`) AS startminute, HOUR(a.`endtime`) AS endhour, MINUTE(a.`endtime`) AS endminute, DATE_FORMAT(a.`starttime`, '%d/%m/%y') as startdate, DATE_FORMAT(a.`endtime`, '%d/%m/%y') as enddate, a.`subject` FROM `dwm-calendar` a, `dwm-recurring` b WHERE a.`recur` = '1' AND a.`entryid` = b.`calendarid` AND b.`type` = '4' AND a.`userid` = '" . $this->_DBUserID . "' AND DAYOFYEAR(a.`starttime`) = '$dayofyear' AND DATE_FORMAT(a.`starttime`, '%Y-%m-%d') < '$currentdate' AND DATE_FORMAT(b.`dtsuntil`, '%Y-%m-%d') > '$currentdate'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$entryid = $row["entryid"];
$year_entry[$entryid]['starthour'] = $row["starthour"];
$year_entry[$entryid]['startminute'] = $row["startminute"];
$year_entry[$entryid]['startdate'] = $row["startdate"];
$year_entry[$entryid]['endhour'] = $row["endhour"];
$year_entry[$entryid]['endminute'] = $row["endminute"];
$year_entry[$entryid]['enddate'] = $row["enddate"];
$year_entry[$entryid]['subject'] = stripslashes($row["subject"]);
$year_entry[$entryid]['id'] = $entryid;
$ReturnStatus = TRUE;
} while($row = mysql_fetch_array($result));
}
$this->_dayrecur = $day_entry;
unset ($day_entry);
$this->_weekdayrecur = $weekday_entry;
unset ($weekday_entry);
$this->_weekrecur = $week_entry;
unset ($week_entry);
$this->_monthrecur = $month_entry;
unset ($month_entry);
$this->_yearrecur = $year_entry;
unset ($year_entry);
return $ReturnStatus;
}
function DB_GetCalDetails($entryid) {
$result = mysql_query ("SELECT `entryid`, `url`, `uid`, HOUR(`starttime`) AS starthour, MINUTE(`starttime`) AS startminute, HOUR(`endtime`) AS endhour, MINUTE(`endtime`) AS endminute, DATE_FORMAT(`starttime`, '%d') as startday, DATE_FORMAT(`starttime`, '%m') as startmonth, DATE_FORMAT(`starttime`, '%Y') as startyear, DATE_FORMAT(`endtime`, '%d') as endday, DATE_FORMAT(`endtime`, '%m') as endmonth, DATE_FORMAT(`endtime`, '%Y') as endyear, `subject`, `location`, `description`, `recur` FROM `dwm-calendar` WHERE `userid` = '" . $this->_DBUserID . "' AND entryid = '" . $entryid . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$entryid = $row["entryid"];
$cal_entry['starthour'] = $row["starthour"];
$cal_entry['startminute'] = $row["startminute"];
$cal_entry['startday'] = $row["startday"];
$cal_entry['startmonth'] = $row["startmonth"];
$cal_entry['startyear'] = $row["startyear"];
$cal_entry['endhour'] = $row["endhour"];
$cal_entry['endminute'] = $row["endminute"];
$cal_entry['endday'] = $row["endday"];
$cal_entry['endmonth'] = $row["endmonth"];
$cal_entry['endyear'] = $row["endyear"];
$cal_entry['uid'] = $row["uid"];
$cal_entry['recur']['set'] = $row["recur"];
$cal_entry['subject'] = str_replace('"', """, stripslashes($row["subject"]));
$cal_entry['description'] = stripslashes($row["description"]);
$cal_entry['location'] = str_replace('"', """, stripslashes($row["location"]));
$cal_entry['url'] = str_replace('"', """, stripslashes($row["url"]));
$cal_entry['id'] = $entryid;
$i=0;
$result2 = mysql_query ("SELECT `name`, `email`, `status` FROM `dwm-attendees` WHERE `userid` = '" . $this->_DBUserID . "' AND calendarid = '" . $entryid . "' ORDER BY `name` DESC, `email` DESC");
if (!$result2) {
echo mysql_error();
}
if ($row2 = mysql_fetch_array($result2)) {
do {
$cal_entry['attendees'][$i]['name'] = stripslashes($row2["name"]);
$cal_entry['attendees'][$i]['email'] = stripslashes($row2["email"]);
$cal_entry['attendees'][$i]['status'] = stripslashes($row2["status"]);
$i++;
} while($row2 = mysql_fetch_array($result2));
}
}
return $cal_entry;
}
function DB_GetCalRecurDetails($entryid) {
$result = mysql_query ("SELECT `entryid`, `type`, `dtsuntil`, `numrecurrences`, `extras` FROM `dwm-recurring` WHERE `calendarid` = '" . $entryid . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$entryid = $row["entryid"];
$datetimesplit = explode(" ", $row["dtsuntil"]);
$datesplit = explode("-", $datetimesplit[0]);
$recur_entry['datetime'] = $datesplit[0] . $datesplit[1] . $datesplit[2] . 'T000000Z';
$recur_entry['year'] = $datesplit[0];
$recur_entry['month'] = $datesplit[1];
$recur_entry['day'] = $datesplit[2];
$recur_entry['type'] = $row["type"];
$recur_entry['numrecurrences'] = $row["numrecurrences"];
$recur_entry['extras'] = $row["extras"];
$recur_entry['id'] = $entryid;
}
return $recur_entry;
}
function DB_CalNewRecipients($users, $cal_addentry) {
for ($i=0;$i<sizeof($users);$i++) {
$result = mysql_query ("INSERT INTO `dwm-attendees` (`userid`, `calendarid`, `name`, `email`, `status`) VALUES ('" . $this->_DBUserID . "', " . $cal_addentry . ", '" . addslashes($users[$i]['name']) . "', '" . addslashes($users[$i]['email']) . "', 'not responded')");
if (!$result) {
echo mysql_error();
}
}
return true;
}
function DB_CalNewEntry($submitteddetails) {
$result = mysql_query ("INSERT INTO `dwm-calendar` (`userid`, `subject`, `location`, `description`, `starttime`, `endtime`, `url`, `uid`, `recur`) VALUES ('" . $this->_DBUserID . "', '" . $submitteddetails['subject'] . "', '" . $submitteddetails['location'] . "', '" . $submitteddetails['description'] . "', '" . $submitteddetails['starttime'] . "', '" . $submitteddetails['endtime'] . "', '" . $submitteddetails['url'] . "', '" . $submitteddetails['uid'] . "', '" . $submitteddetails['recur']['set'] . "')");
if (!$result) {
echo mysql_error();
}
$returnid = mysql_insert_id();
if ($submitteddetails['recur']['set'] == 1) {
$result = mysql_query ("INSERT INTO `dwm-recurring` (`calendarid`, `type`, `extras`, `dtsuntil`) VALUES ('" . $returnid . "', '" . $submitteddetails['recur']['type'] . "', '" . $submitteddetails['recur']['extras'] . "', '" . $submitteddetails['recur']['date'] . "')");
if (!$result) {
echo mysql_error();
}
}
return $returnid;
}
function DB_CalUpdateEntry($entryid, $submitteddetails) {
$result = mysql_query ("UPDATE `dwm-calendar` SET `subject` = '" . $submitteddetails['subject'] . "', `location` = '" . $submitteddetails['location'] . "', `description` = '" . $submitteddetails['description'] . "', `starttime` = '" . $submitteddetails['starttime'] . "', `endtime` = '" . $submitteddetails['endtime'] . "', `url` = '" . $submitteddetails['url'] . "', `recur` = '" . $submitteddetails['recur']['set'] . "' WHERE `userid` = '" . $this->_DBUserID . "' AND `entryid` = " . $entryid);
if (!$result) {
echo mysql_error();
}
if ($submitteddetails['recur']['set'] == 1) {
$result = mysql_query ("UPDATE `dwm-recurring` SET `type` = '" . $submitteddetails['recur']['type'] . "', `extras` = '" . $submitteddetails['recur']['extras'] . "', `dtsuntil` = '" . $submitteddetails['recur']['date'] . "' WHERE `calendarid` = '" . $entryid . "'");
if (!$result) {
echo mysql_error();
}
}
return $result;
}
function DB_AddUID($uid, $entryid) {
$result = mysql_query ("UPDATE `dwm-calendar` SET `uid` = '" . $uid . "' WHERE `userid` = '" . $this->_DBUserID . "' AND `entryid` = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_AttendeeStatus($entryid, $address, $status) {
if (strtoupper($status) == 'ACCEPTED') {
$statussave = 'accepted';
}
else {
$statussave = 'declined';
}
if (isset($statussave)) {
$result = mysql_query ("UPDATE `dwm-attendees` SET `status` = '" . $statussave . "' WHERE `userid` = '" . $this->_DBUserID . "' AND `email` = '" . $address . "' AND `calendarid` = " . $entryid);
if (!$result) {
echo mysql_error();
}
}
return $result;
}
function DB_CheckUID($uid) {
$result = mysql_query ("SELECT * FROM `dwm-calendar` WHERE `userid` = '" . $this->_DBUserID . "' AND `uid` = '" . $uid . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$entryid = $row["entryid"];
}
return $entryid;
}
function DB_CalDeleteEntry($entryid) {
$result = mysql_query ("DELETE FROM `dwm-calendar` WHERE `userid` = '" . $this->_DBUserID . "' AND `entryid` = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_CopyCalendar($oldid) {
$result = mysql_query ("SELECT * FROM `dwm-calendar` WHERE `userid` = $oldid");
if (!$result) {
$errors .= mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$starttime = $row["starttime"];
$endtime = $row["endtime"];
$subject = stripslashes($row["subject"]);
$description = stripslashes($row["description"]);
$location = stripslashes($row["location"]);
$url = stripslashes($row["url"]);
$uid = stripslashes($row["uid"]);
$result2 = mysql_query ("INSERT INTO `dwm-calendar` (`userid`, `subject`, `location`, `description`, `starttime`, `endtime`, `url`, `uid`) VALUES ('" . $this->_DBUserID . "', '" . addslashes($subject) . "', '" . addslashes($location) . "', '" . addslashes($description) . "', '" . $starttime . "', '" . $endtime . "', '" . addslashes($url) . "', '" . addslashes($uid) . "')");
if (!$result2) {
$errors .= mysql_error();
}
} while($row = mysql_fetch_array($result));
}
$result = mysql_query ("SELECT * FROM `dwm-attendees` WHERE `userid` = $oldid");
if (!$result) {
$errors .= mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$calendarid = $row["calendarid"];
$name = stripslashes($row["name"]);
$email = stripslashes($row["email"]);
$status = stripslashes($row["status"]);
$result2 = mysql_query ("INSERT INTO `dwm-attendees` (`userid`, `calendarid`, `name`, `email`, `status`) VALUES ('" . $this->_DBUserID . "', " . $calendarid . ", '" . addslashes($name) . "', '" . addslashes($email) . "', '" . addslashes($status) . "')");
if (!$result2) {
$errors .= mysql_error();
}
} while($row = mysql_fetch_array($result));
}
return $errors;
}
/*
PREFERENCES FUNCTIONS
---------------------
*/
function DB_GetPrefs($type, $oldid = '') {
if ($type == "") {
$type = 'standard';
}
if ($oldid <> '') {
$result = mysql_query ("SELECT * FROM `dwm-prefs` WHERE `userid` = $oldid AND `type` = '" . $type . "'");
}
else {
$result = mysql_query ("SELECT * FROM `dwm-prefs` WHERE `userid` = '" . $this->_DBUserID . "' AND `type` = '" . $type . "'");
}
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$prefs = stripslashes($row["setting"]);
return $prefs;
}
else {
return FALSE;
}
}
function DB_UpdatePrefs($newprefs, $type) {
$newprefs = addslashes($newprefs);
if ($type == "") {
$type = 'standard';
}
$alreadyexists = mysql_result(mysql_query("SELECT COUNT(`userid`) FROM `dwm-prefs` WHERE `userid` = '" . $this->_DBUserID . "' AND `type` = '" . $type . "'"),0);
if ($alreadyexists > 0) {
$result = mysql_query ("UPDATE `dwm-prefs` SET `setting` = '" . $newprefs . "' WHERE `userid` = '" . $this->_DBUserID . "' AND `type` = '" . $type . "'");
if (!$result) {
echo mysql_error();
}
}
else {
$result = mysql_query ("INSERT INTO `dwm-prefs` (`userid`, `type`, `setting`) VALUES ('" . $this->_DBUserID . "', '" . $type . "', '" . $newprefs . "')");
if (!$result) {
echo mysql_error();
}
}
return $result;
}
function DB_DeletePrefs($type) {
if ($type == 'all') {
$result = mysql_query ("DELETE FROM `dwm-prefs` WHERE `userid` = '" . $this->_DBUserID . "'");
}
else {
$result = mysql_query ("DELETE FROM `dwm-prefs` WHERE `userid` = '" . $this->_DBUserID . "' AND `type` = '" . $type . "'");
}
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_GetHash($hash, $lookupid = 0, $forcereset = 0) {
if ($lookupid == 0) {
if ($forcereset == 0) {
$result = mysql_query ("SELECT * FROM `dwm-users` WHERE `id` = '" . $this->_DBUserID . "' AND `hash` <> ''");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$hash = stripslashes($row["hash"]);
return $hash;
}
else {
$result = mysql_query ("UPDATE `dwm-users` SET `hash` = '" . $hash . "' WHERE `id` = '" . $this->_DBUserID . "'");
return $hash;
}
}
else {
$result = mysql_query ("UPDATE `dwm-users` SET `hash` = '" . $hash . "' WHERE `id` = '" . $this->_DBUserID . "'");
return $hash;
}
}
else {
$result = mysql_query ("SELECT * FROM `dwm-users` WHERE `id` = '" . $lookupid . "' AND `hash` = '" . $hash . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
return TRUE;
}
else {
return FALSE;
}
}
}
/*
FILTERS FUNCTIONS
-----------------
*/
function DB_SaveFilter($needle, $haystack, $action, $folder) {
$needle = addslashes($needle);
$result = mysql_query ("INSERT INTO `dwm-filters` (`userid`, `needle`, `haystack-to`, `haystack-cc`, `haystack-from`, `haystack-subject`, `haystack-body`, `action`, `dest`) VALUES ('" . $this->_DBUserID . "', '" . $needle . "', '" . $haystack['to'] . "', '" . $haystack['cc'] . "', '" . $haystack['from'] . "', '" . $haystack['subject'] . "', '" . $haystack['body'] . "', '" . $action . "', '" . $folder . "')");
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_GetFilters() {
$result = mysql_query ("SELECT * FROM `dwm-filters` WHERE `userid` = '" . $this->_DBUserID . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$filterid = $row["id"];
$filterdetails[$filterid]['needle'] = stripslashes($row["needle"]);
$filterdetails[$filterid]['to'] = $row["haystack-to"];
$filterdetails[$filterid]['cc'] = $row["haystack-cc"];
$filterdetails[$filterid]['from'] = $row["haystack-from"];
$filterdetails[$filterid]['subject'] = $row["haystack-subject"];
$filterdetails[$filterid]['body'] = $row["haystack-body"];
$filterdetails[$filterid]['action'] = $row["action"];
$filterdetails[$filterid]['folder'] = stripslashes($row["dest"]);
} while($row = mysql_fetch_array($result));
}
return $filterdetails;
}
function DB_DeleteFilter($entryid) {
$result = mysql_query ("DELETE FROM `dwm-filters` WHERE `userid` = '" . $this->_DBUserID . "' AND `id` = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_GetAliasList() {
$result = mysql_query ("SELECT * FROM `dwm-alias` WHERE `userid` = '" . $this->_DBUserID . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
do {
$aliasid = $row["id"];
$aliasdetails[$aliasid]['email'] = stripslashes($row["email"]);
$aliasdetails[$aliasid]['name'] = $row["name"];
} while($row = mysql_fetch_array($result));
}
return $aliasdetails;
}
function DB_SaveAlias($email, $name, $id = '') {
$name = addslashes($name);
if ($id <> '' && $id <> 'new') {
$result = mysql_query ("UPDATE `dwm-alias` SET `email` = '$email', `name` = '$name' WHERE `userid` = '" . $this->_DBUserID . "' AND `id` = '$id'");
}
else {
$result = mysql_query ("INSERT INTO `dwm-alias` (`userid`, `email`, `name`) VALUES ('" . $this->_DBUserID . "', '" . $email . "', '" . $name . "')");
}
if (!$result) {
echo mysql_error();
}
return $result;
}
function DB_DeleteAlias($entryid) {
$result = mysql_query ("DELETE FROM `dwm-alias` WHERE `userid` = '" . $this->_DBUserID . "' AND `id` = " . $entryid);
if (!$result) {
echo mysql_error();
}
return $result;
}
/*
EXTERNAL ACCOUNT FUNCTIONS
--------------------------
*/
function DB_GetExternalList() {
$result = mysql_query ("SELECT * FROM `dwm-pop3` WHERE `userid` = '" . $this->_DBUserID . "' ORDER BY `popid` ASC");
if (!$result) {
echo mysql_error();
}
$i = 0;
if ($row = mysql_fetch_array($result)) {
do {
$this->_externallist[$i]['id'] = $row["id"];
$this->_externallist[$i]['sess_u'] = stripslashes($row["username"]);
$this->_externallist[$i]['sess_p'] = stripslashes($row["password"]);
if ($row["servertype"] == '') {
$this->_externallist[$i]['servertype'] = 'pop3';
}
else {
$this->_externallist[$i]['servertype'] = stripslashes($row["servertype"]);
}
$this->_externallist[$i]['mailserver'] = stripslashes($row["server"]);
$this->_externallist[$i]['portnumber'] = $row["port"];
$this->_externallist[$i]['leave'] = $row["leaveonserver"];
$this->_externallist[$i]['folder'] = $row["folder"];
$this->_externallist[$i]['email'] = $row["email"];
$i++;
} while($row = mysql_fetch_array($result));
}
return $this->_externallist;
}
function DB_UpdateExternalList($list) {
$resultdel = mysql_query ("DELETE FROM `dwm-pop3` WHERE `userid` = '" . $this->_DBUserID . "'");
for ($i=0; $i<count($list); $i++) {
// Create new entry
if ($list[$i]['sess_u'] <> "" && $list[$i]['sess_p'] <> "") {
$result2 = mysql_query ("INSERT INTO `dwm-pop3` (`popid`, `userid`, `username`, `password`, `server`, `servertype`, `port`, `leaveonserver`, `folder`, `email`) VALUES ($i, '" . $this->_DBUserID . "', '" . $list[$i]['sess_u'] . "', '" . $list[$i]['sess_p'] . "', '" . $list[$i]['mailserver'] . "', '" . $list[$i]['servertype'] . "', " . $list[$i]['portnumber'] . ", " . $list[$i]['leave'] . ", '" . $list[$i]['folder'] . "', '" . $list[$i]['email'] . "')");
if (!$result2) {
echo mysql_error();
}
}
}
}
/*
GET BLOCKED DOMAINS
-------------------
*/
function DB_CheckBlocked($mailserver) {
$result = mysql_query ("SELECT * FROM `dwm-block` WHERE `domain` = '" . $mailserver . "'");
if (!$result) {
echo mysql_error();
}
if ($row = mysql_fetch_array($result)) {
$rowid = $row["id"];
return $rowid;
}
else {
return 0;
}
}
}
?>
|