!C99Shell v. 1.0 pre-release build #16!

Software: Apache/2.0.54 (Fedora). PHP/5.0.4 

uname -a: Linux mina-info.me 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 

uid=48(apache) gid=48(apache) groups=48(apache)
context=system_u:system_r:httpd_sys_script_t
 

Safe-mode: OFF (not secure)

/home/mnnews/public_html/dwmail/includes/   drwxr-xr-x
Free 3.96 GB of 27.03 GB (14.66%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     db_postgresql.inc.php (49 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 PostgreSQL databases

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;

    function
DB_Connection($dbhost, $dbuser, $dbpassword, $dbdatabase) {
        
$this->_DBUserName=$dbuser;
        
$this->_DBPassword=$dbpassword;
        
$this->_DBHost=$dbhost;
        
$this->_DBDatabase=$dbdatabase;
    }

    function
DBConnect() {
        
$connstr = "host=" . $this->_DBHost . " dbname=" . $this->_DBDatabase . " user=" . $this->_DBUserName . " password=" . $this->_DBPassword;
        
$this->_cn = pg_connect($connstr);
        return
$this->_cn;
    }

    function
DB_MakeConnection() {
        
$this->DBConnect();
        if (
$this->_cn) {
            return
true;
        }
        else {
            return
false;
        }
    }

    function
DB_CloseConnection() {
        
pg_close($this->_cn);
    }

    function
DB_CheckUser($currentemailaddress, $currentpassword) {
        
$this->_currentemailaddress = $currentemailaddress;
        
$this->_currentpassword = $currentpassword;
        
$result = pg_query ("SELECT id, lastlogin as lastdateformat, lastlogin as lasttimeformat, emailclear FROM \"dwm-users\" WHERE emailaddress = MD5('" . $currentemailaddress . "') and \"password\" = MD5('" . $currentpassword . "')");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$db_id = $row["id"];
            
$this->_lastlogindate = $row["lastdateformat"];
            
$this->_lastlogintime = $row["lasttimeformat"];
            if (empty(
$row["emailclear"])) {
                
$result3 = pg_query ("UPDATE \"dwm-users\" SET emailclear = '" . strtolower($currentemailaddress) . "' WHERE \"id\" = $db_id");
            }
        }
        else {
            
$nv = pg_query ("SELECT nextval('seq_dwm_users')");
            if (
$row = pg_fetch_array($nv)) {
                
$res = $row["nextval"];
            }

            
$result2 = pg_query ("INSERT INTO \"dwm-users\" (\"id\", emailaddress, \"password\", lastlogin, emailclear) VALUES ($res, MD5('" . $currentemailaddress . "'), MD5('" . $currentpassword . "'), NOW(), '" . strtolower($currentemailaddress) . "')");
            if (!
$result2) {
                echo
pg_last_error();
            }
            
$db_id = $res;

        }
        if (isset(
$db_id)) {
            
$this->_DBUserID = $db_id;
            return
$this->_DBUserID;
        }
    }

    function
DB_FindProfile($oldemail, $oldpassword) {
        
$result = pg_query ("SELECT id FROM \"dwm-users\" WHERE emailaddress = MD5('" . $oldemail . "') and password = MD5('" . $oldpassword . "')");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$oldid = $row["id"];
        }
        else {
            
$oldid = FALSE;
        }
        return
$oldid;
    }

    function
DB_UpdateLastLogin() {
        
$result = pg_query ("UPDATE \"dwm-users\" SET lastlogin = NOW() WHERE emailaddress = MD5('" . $this->_currentemailaddress . "') and \"password\" = MD5('" . $this->_currentpassword . "')");
        return
$result;
    }

    function
DB_LogAccess($IPLogging) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_stats')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        if (
$IPLogging == 1) {
            
$result = pg_query ("INSERT INTO \"dwm-stats\" (\"id\", logindts, userid, ipaddress) VALUES ($res, NOW(), '" . $this->_DBUserID . "', '" . $_SERVER['REMOTE_ADDR'] . "')");
        }
        else {
            
$result = pg_query ("INSERT INTO \"dwm-stats\" (\"id\", logindts, userid) VALUES ($res, NOW(), '" . $this->_DBUserID . "')");
        }
        return
$result;
    }

    function
DB_LogSend($recipients) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_statscompose')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("INSERT INTO \"dwm-statscompose\" (\"id\", userid, sentdts, recipients) VALUES ($res, '" . $this->_DBUserID . "', NOW(), '$recipients')");
        return
$result;
    }

    function
DB_LoginPeriod($period) {
        if (
$period == 0) {
            
$period = 1;
        }
        if (
$period == 1) {
            
$daycount = "day";
        }
        else {
            
$daycount = "days";
        }
        
$resultcount = pg_query ("SELECT count(id) FROM \"dwm-statscompose\" where (sentdts + interval '$period $daycount') >= NOW()");
        if (
$row = pg_fetch_array($resultcount)) {
            
$result = $row["count"];
        }
        return
$result;
    }

    function
DB_LoginStats($period) {
        if (
$period == 0) {
            
$period = 1;
        }
        if (
$period == 1) {
            
$daycount = "day";
        }
        else {
            
$daycount = "days";
        }
        
$resultcount = pg_query ("SELECT count(id) FROM \"dwm-stats\" where (logindts + interval '$period $daycount') >= NOW()");
        if (
$row = pg_fetch_array($resultcount)) {
            
$result = $row["count"];
        }
        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) {
            if (
$cleanup == 1) {
                
$daycount = "day";
            }
            else {
                
$daycount = "days";
            }
            
$result = pg_query ("SELECT * FROM \"dwm-users\" WHERE (lastlogin + interval '$cleanup $daycount') <= NOW()");
            if (!
$result) {
                echo
pg_last_error();
            }
            if (
$row = pg_fetch_array($result)) {
                
$db_id = $row["id"];
                
$result11 = pg_query ("DELETE FROM \"dwm-attendees\" WHERE userid = $db_id");
                
$result10 = pg_query ("DELETE FROM \"dwm-alias\" WHERE userid = $db_id");
                
$result3 = pg_query ("DELETE FROM \"dwm-addressbook\" WHERE userid = $db_id");
                
$result2 = pg_query ("DELETE FROM \"dwm-calendar\" WHERE userid = $db_id");
                
$result4 = pg_query ("DELETE FROM \"dwm-prefs\" WHERE userid = $db_id");
                
$result6 = pg_query ("DELETE FROM \"dwm-filters\" WHERE userid = $db_id");
                
$result7 = pg_query ("DELETE FROM \"dwm-pop3\" WHERE userid = $db_id");
                
$result8 = pg_query ("DELETE FROM \"dwm-groups\" WHERE userid = $db_id");
                
$result9 = pg_query ("DELETE FROM \"dwm-groupmembers\" WHERE userid = $db_id");
                
$result5 = pg_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 substr(UPPER(lastname), 0 , 1) = '0' OR substr(UPPER(lastname), 0 , 1) = '1' OR substr(UPPER(lastname), 0 , 1) = '2' OR substr(UPPER(lastname), 0 , 1) = '3' OR substr(UPPER(lastname), 0 , 1) = '4' OR substr(UPPER(lastname), 0 , 1) = '5' OR substr(UPPER(lastname), 0 , 1) = '6' OR substr(UPPER(lastname), 0 , 1) = '7' OR substr(UPPER(lastname), 0 , 1) = '8' OR substr(UPPER(lastname), 0 , 1) = '9'  ORDER BY lastname";
        }
        else {
            
$SQLStatement = "SELECT * FROM \"dwm-addressbook\" WHERE (userid = " . $this->_DBUserID . " OR userid = 0) AND substr(UPPER(lastname), 0, 1) = '" . $LetterView . "'  ORDER BY lastname";
        }
        
$result = pg_query ($SQLStatement);
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_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('"', "&quot;", stripslashes($row["title"]));
                
$ab_entry[$entryid]['homephone'] = str_replace('"', "&quot;", stripslashes($row["homephone"]));
                
$ab_entry[$entryid]['workphone'] = str_replace('"', "&quot;", stripslashes($row["workphone"]));
                
$ab_entry[$entryid]['cellphone'] = str_replace('"', "&quot;", stripslashes($row["cellphone"]));
                
$ab_entry[$entryid]['fax'] = str_replace('"', "&quot;", 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 = pg_fetch_array($result));
        }
        return
$ab_entry;
    }

    function
DB_SearchList($searchparam) {

        
$SQLStatement = "SELECT * FROM \"dwm-addressbook\" WHERE (userid = '" . $this->_DBUserID . "' or userid = 0) AND (UPPER(lastname) LIKE '" . $searchparam . "%' OR UPPER(firstname) LIKE '" . $searchparam . "%' OR UPPER(email) LIKE '" . $searchparam . "%') ORDER BY lastname";
        
$result = pg_query ($SQLStatement);
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_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 = pg_fetch_array($result));
        }
        return
$ab_entry;
    }

    function
DB_GetGroupList() {

        
$SQLStatement = "SELECT * FROM \"dwm-groups\" WHERE userid = " . $this->_DBUserID . " ORDER BY \"name\"";

        
$result = pg_query ($SQLStatement);
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["id"];
                
$ab_entry[$entryid]['groupname'] = $row["name"];
                
$nv = pg_query ("SELECT COUNT(addressbookid) FROM \"dwm-groupmembers\" WHERE userid = " . $this->_DBUserID . " AND groupid = " . $entryid);
                if (
$row2 = pg_fetch_array($nv)) {
                    
$NumberofMembers = $row2["count"];
                }
                
$ab_entry[$entryid]['count'] = $NumberofMembers;
                
$ab_entry[$entryid]['id'] = $entryid;
            } while(
$row = pg_fetch_array($result));
        }
        return
$ab_entry;
    }


    function
DB_GetEntryDetails($entryid) {
        
$result = pg_query ("SELECT * FROM \"dwm-addressbook\" WHERE (userid = " . $this->_DBUserID . " OR userid = 0) AND entryid = $entryid ORDER BY lastname");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$entrydetails['userid'] = $row["userid"];
            
$entrydetails['firstname'] = str_replace('"', "&quot;", stripslashes($row["firstname"]));
            
$entrydetails['lastname'] = str_replace('"', "&quot;", stripslashes($row["lastname"]));
            
$entrydetails['email'] = str_replace('"', "&quot;", stripslashes($row["email"]));
            
$entrydetails['title'] = str_replace('"', "&quot;", stripslashes($row["title"]));
            
$entrydetails['homephone'] = str_replace('"', "&quot;", stripslashes($row["homephone"]));
            
$entrydetails['workphone'] = str_replace('"', "&quot;", stripslashes($row["workphone"]));
            
$entrydetails['cellphone'] = str_replace('"', "&quot;", stripslashes($row["cellphone"]));
            
$entrydetails['fax'] = str_replace('"', "&quot;", 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 = pg_query ("SELECT * FROM \"dwm-groups\" WHERE userid = " . $this->_DBUserID . " AND \"id\" = $entryid ORDER BY \"name\"");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$entrydetails['name'] = str_replace('"', "&quot;", stripslashes($row["name"]));
        }
        else {
            
$entrydetails['name'] = "Invalid ID";
        }
        return
$entrydetails;
    }

    function
DB_FindGroup($searchname) {
        
$nv = pg_query ("SELECT COUNT(\"id\") FROM \"dwm-groups\" WHERE \"name\" = '" . trim(strip_tags(addslashes($searchname))) . "' AND userid = " . $this->_DBUserID);
        if (
$row = pg_fetch_array($nv)) {
            
$NumberofResults = $row["count"];
        }

        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 = pg_query ("SELECT * FROM \"dwm-groups\" WHERE \"name\" = '" . trim(strip_tags(addslashes($searchname))) . "' AND userid = " . $this->_DBUserID);
            if (!
$result) {
                echo
pg_last_error();
            }
            if (
$row = pg_fetch_array($result)) {
                
$groupid = $row["id"];
                
$result2 = pg_query ("SELECT * FROM \"dwm-groupmembers\" WHERE userid = " . $this->_DBUserID . " AND groupid = " . $groupid);
                if (
$row2 = pg_fetch_array($result2)) {
                    do {
                        
$lookupid = $row2["addressbookid"];
                        
$result3 = pg_query ("SELECT * FROM \"dwm-addressbook\" WHERE userid = " . $this->_DBUserID . " AND entryid = " . $lookupid);
                        if (
$row3 = pg_fetch_array($result3)) {
                            
$entrydetails[$lookupid]['firstname'] = stripslashes($row3["firstname"]);
                            
$entrydetails[$lookupid]['lastname'] = stripslashes($row3["lastname"]);
                            
$entrydetails[$lookupid]['email'] = stripslashes($row3["email"]);
                        }
                    } while(
$row2 = pg_fetch_array($result2));
                }
                
            }
            return
$entrydetails;
        }
    }

    function
DB_GetGroupMembers($entryid = 0) {
        
$result = pg_query ("SELECT * FROM \"dwm-addressbook\" WHERE userid = " . $this->_DBUserID . " ORDER BY lastname");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$addressbookid = $row["entryid"];
                if (
$entryid > 0) {
                    
$nv = pg_query ("SELECT COUNT(addressbookid) FROM \"dwm-groupmembers\" WHERE userid = " . $this->_DBUserID . " AND groupid = " . $entryid . " AND addressbookid = " . $addressbookid);
                    if (
$row2 = pg_fetch_array($nv)) {
                        
$ismember = $row2["count"];
                    }
                }
                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 = pg_fetch_array($result));
        }
        return
$ab_entry;
    }

    function
DB_NewEntry($submitteddetails) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_addressbook')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("INSERT INTO \"dwm-addressbook\" (entryid, userid, lastname, firstname, email, title, homephone, workphone, cellphone, fax, homeaddress, workaddress, url, notes) VALUES ($res, " . $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
pg_last_error();
        }
        return
$result;
    }

    function
DB_NewGroup($submitteddetails) {
        
$nv = pg_query ("SELECT COUNT(\"id\") FROM \"dwm-groups\" WHERE userid = " . $this->_DBUserID . " AND \"name\" = '" . addslashes($submitteddetails['name']) . "'");
        if (
$row = pg_fetch_array($nv)) {
            
$checkexist = $row["count"];
        }
        if (
$checkexist == 0) {
            
$nv = pg_query ("SELECT nextval('seq_dwm_groups')");
            if (
$row = pg_fetch_array($nv)) {
                
$newgroupid = $row["nextval"];
            }
            
$result = pg_query ("INSERT INTO \"dwm-groups\" (\"id\", userid, \"name\") VALUES ($newgroupid, " . $this->_DBUserID . ", '" . addslashes($submitteddetails['name']) . "')");
            if (!
$result) {
                echo
pg_last_error();
            }
            if (
is_array($submitteddetails['members'])) {
                while(list(
$key, $value) = each($submitteddetails['members'])) {
                    
$result2 = pg_query ("INSERT INTO \"dwm-groupmembers\" (userid, groupid, addressbookid) VALUES (" . $this->_DBUserID . ", " . $newgroupid . ", " . $submitteddetails['members'][$key] . ")");
                    if (!
$result2) {
                        echo
pg_last_error();
                    }
                }
            }
            return
$result;
        }
        else {
            return
FALSE;
        }
    }

    function
DB_UpdateEntry($entryid, $submitteddetails) {
        
$result = pg_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
pg_last_error();
        }
        return
$result;
    }

    function
DB_UpdateGroup($entryid, $submitteddetails) {
        
$result = pg_query ("UPDATE \"dwm-groups\" SET \"name\" = '" . $submitteddetails['name'] . "' WHERE userid = " . $this->_DBUserID . " AND \"id\" = " . $entryid);
        if (!
$result) {
            echo
pg_last_error();
        }
        
$result2 = pg_query ("DELETE FROM \"dwm-groupmembers\" WHERE userid = " . $this->_DBUserID . " AND groupid = " . $entryid);
        if (!
$result2) {
            echo
pg_last_error();
        }
        if (
is_array($submitteddetails['members'])) {
            while(list(
$key, $value) = each($submitteddetails['members'])) {
                
$result3 = pg_query ("INSERT INTO \"dwm-groupmembers\" (userid, groupid, addressbookid) VALUES (" . $this->_DBUserID . ", " . $entryid . ", " . $submitteddetails['members'][$key] . ")");
                if (!
$result3) {
                    echo
pg_last_error();
                }
            }
        }
        return
$result;
    }

    function
DB_DeleteEntry($entryid) {
        
$result = pg_query ("DELETE FROM \"dwm-addressbook\" WHERE userid = " . $this->_DBUserID . " AND entryid = " . $entryid);
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_DeleteGroup($entryid) {
        
$result = pg_query ("DELETE FROM \"dwm-groupmembers\" WHERE userid = " . $this->_DBUserID . " AND groupid = " . $entryid);
        
$result2 = pg_query ("DELETE FROM \"dwm-groups\" WHERE userid = " . $this->_DBUserID . " AND \"id\" = " . $entryid);
        return
$result2;
    }

    function
DB_EntryExist($emailcheck) {
        
$nv = pg_query ("SELECT COUNT(entryid) FROM \"dwm-addressbook\" WHERE userid = " . $this->_DBUserID . " AND email = '" . trim($emailcheck) . "'");
        if (
$row = pg_fetch_array($nv)) {
            
$emailexist = $row["count"];
        }
        if (
$emailexist >= 1) {
            return
TRUE;
        }
        else {
            return
FALSE;
        }
    }

    function
DB_CopyContacts($oldid) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_addressbook')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("SELECT * FROM \"dwm-addressbook\" WHERE userid = $oldid");
        if (!
$result) {
            
$errors .= pg_last_error();
        }
        if (
$row = pg_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 = pg_query ("INSERT INTO \"dwm-addressbook\" (entryid, userid, lastname, firstname, email, title, homephone, workphone, cellphone, fax, homeaddress, workaddress, url, notes) VALUES ($res, " . $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 .= pg_last_error();
                }

            } while(
$row = pg_fetch_array($result));
        }
        return
$errors;
    }

    
/*
        CALENDAR FUNCTIONS
        ------------------
    */

    
function DB_CalDateCheck($currentdate) {
        
// Not sure this first one is used anymore
        // $this->_daycount = pg_exec($this->_cn, "SELECT COUNT(`entryid`) FROM `dwm-calendar` WHERE `userid` = " . $this->_DBUserID . " AND '" . $currentdate . "' BETWEEN  `starttime`  AND  `endtime`");
        
$result = pg_query ("SELECT entryid, EXTRACT(HOUR FROM starttime) AS starthour, EXTRACT(MINUTE FROM starttime) AS startminute, EXTRACT(HOUR FROM endtime) AS endhour, EXTRACT(MINUTE FROM endtime) AS endminute, starttime as startdate, endtime as enddate, subject, recur FROM \"dwm-calendar\" WHERE userid = " . $this->_DBUserID . " AND ((DATE '" . $currentdate . "', INTERVAL '1 day') OVERLAPS (starttime, endtime))");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$cal_entry[$entryid]['starthour'] = $row["starthour"];
                
$cal_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$cal_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$cal_entry[$entryid]['endhour'] = $row["endhour"];
                
$cal_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$cal_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$cal_entry[$entryid]['recur'] = $row["recur"];

                
$cal_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$cal_entry[$entryid]['id'] = $entryid;
            } while(
$row = pg_fetch_array($result));
        }
        return
$cal_entry;
    }

    function
DB_CalRecurCheck($currentdate, $day, $month, $year, $dow) {
        
$ReturnStatus = FALSE;

        
// Check every day events
        
$result = pg_query ("SELECT a.entryid, b.type, b.extras, EXTRACT(HOUR FROM a.starttime) AS starthour, EXTRACT(MINUTE FROM a.starttime) AS startminute, EXTRACT(HOUR FROM a.endtime) AS endhour, EXTRACT(MINUTE FROM a.endtime) AS endminute, a.starttime as startdate, a.endtime 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 a.starttime <  DATE '$currentdate' AND b.dtsuntil > DATE '$currentdate'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$day_entry[$entryid]['starthour'] = $row["starthour"];
                
$day_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$day_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$day_entry[$entryid]['endhour'] = $row["endhour"];
                
$day_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$day_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$day_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$day_entry[$entryid]['id'] = $entryid;
                
$ReturnStatus = TRUE;
            } while(
$row = pg_fetch_array($result));
        }

        
// Check week day events
        
$result = pg_query ("SELECT a.entryid, b.type, b.extras, EXTRACT(HOUR FROM a.starttime) AS starthour, EXTRACT(MINUTE FROM a.starttime) AS startminute, EXTRACT(HOUR FROM a.endtime) AS endhour, EXTRACT(MINUTE FROM a.endtime) AS endminute, a.starttime as startdate, a.endtime 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 a.starttime <  DATE '$currentdate' AND b.dtsuntil > DATE '$currentdate' AND DATE_PART('DOW', TIMESTAMP '$currentdate') > 1 AND DATE_PART('DOW', TIMESTAMP '$currentdate') < 7");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$weekday_entry[$entryid]['starthour'] = $row["starthour"];
                
$weekday_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$weekday_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$weekday_entry[$entryid]['endhour'] = $row["endhour"];
                
$weekday_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$weekday_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$weekday_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$weekday_entry[$entryid]['id'] = $entryid;
                
$ReturnStatus = TRUE;
            } while(
$row = pg_fetch_array($result));
        }

        
// Check weekly events
        
$result = pg_query ("SELECT a.entryid, b.type, b.extras, EXTRACT(HOUR FROM a.starttime) AS starthour, EXTRACT(MINUTE FROM a.starttime) AS startminute, EXTRACT(HOUR FROM a.endtime) AS endhour, EXTRACT(MINUTE FROM a.endtime) AS endminute, a.starttime as startdate, a.endtime 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 a.starttime <  DATE '$currentdate' AND b.dtsuntil > DATE '$currentdate' AND DATE_PART('DOW', a.starttime::timestamp) = '$dow'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$week_entry[$entryid]['starthour'] = $row["starthour"];
                
$week_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$week_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$week_entry[$entryid]['endhour'] = $row["endhour"];
                
$week_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$week_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$week_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$week_entry[$entryid]['id'] = $entryid;
                
$ReturnStatus = TRUE;
            } while(
$row = pg_fetch_array($result));
        }

        
// Check monthly events
        
$result = pg_query ("SELECT a.entryid, b.type, b.extras, EXTRACT(HOUR FROM a.starttime) AS starthour, EXTRACT(MINUTE FROM a.starttime) AS startminute, EXTRACT(HOUR FROM a.endtime) AS endhour, EXTRACT(MINUTE FROM a.endtime) AS endminute, a.starttime as startdate, a.endtime 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 a.starttime <  DATE '$currentdate' AND b.dtsuntil > DATE '$currentdate' AND DATE_PART('DAY', a.starttime::timestamp) = '$day'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$month_entry[$entryid]['starthour'] = $row["starthour"];
                
$month_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$month_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$month_entry[$entryid]['endhour'] = $row["endhour"];
                
$month_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$month_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$month_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$month_entry[$entryid]['id'] = $entryid;
                
$ReturnStatus = TRUE;
            } while(
$row = pg_fetch_array($result));
        }

        
// Check yearly events
        
$tzcurrdate = strtotime("$year-$month-$day");
        
$dayofyear = (date("z", $tzcurrdate) + 1);
        
$result = pg_query ("SELECT a.entryid, b.type, b.extras, EXTRACT(HOUR FROM a.starttime) AS starthour, EXTRACT(MINUTE FROM a.starttime) AS startminute, EXTRACT(HOUR FROM a.endtime) AS endhour, EXTRACT(MINUTE FROM a.endtime) AS endminute, a.starttime as startdate, a.endtime 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 a.starttime <  DATE '$currentdate' AND b.dtsuntil > DATE '$currentdate' AND DATE_PART('DOY', a.starttime::timestamp) = '$dayofyear'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$entryid = $row["entryid"];
                
$year_entry[$entryid]['starthour'] = $row["starthour"];
                
$year_entry[$entryid]['startminute'] = $row["startminute"];
                
$startdex = explode(" ", $row["startdate"]);
                
$splitsd = explode("-", $startdex[0]);
                
$year_entry[$entryid]['startdate'] = $splitsd[2] . "/" . $splitsd[1] . "/" . substr($splitsd[0], 2);

                
$year_entry[$entryid]['endhour'] = $row["endhour"];
                
$year_entry[$entryid]['endminute'] = $row["endminute"];
                
$endex = explode(" ", $row["enddate"]);
                
$splited = explode("-", $endex[0]);
                
$year_entry[$entryid]['enddate'] = $splited[2] . "/" . $splited[1] . "/" . substr($splited[0], 2);

                
$year_entry[$entryid]['subject'] = stripslashes($row["subject"]);

                
$year_entry[$entryid]['id'] = $entryid;
                
$ReturnStatus = TRUE;
            } while(
$row = pg_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 = pg_query ("SELECT entryid, url, uid, EXTRACT(HOUR FROM starttime) AS starthour, EXTRACT(MINUTE FROM starttime) AS startminute, EXTRACT(HOUR FROM endtime) AS endhour, EXTRACT(MINUTE FROM endtime) AS endminute, EXTRACT(DAY FROM starttime) as startday, EXTRACT(MONTH FROM starttime) as startmonth, EXTRACT(YEAR FROM starttime) as startyear, EXTRACT(DAY FROM endtime) as endday, EXTRACT(MONTH FROM endtime) as endmonth, EXTRACT(YEAR FROM endtime) as endyear, subject, location, description, recur FROM \"dwm-calendar\" WHERE userid = " . $this->_DBUserID . " AND entryid = '" . $entryid . "'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_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('"', "&quot;", stripslashes($row["subject"]));
            
$cal_entry['description'] = stripslashes($row["description"]);
            
$cal_entry['location'] = str_replace('"', "&quot;", stripslashes($row["location"]));
            
$cal_entry['url'] = str_replace('"', "&quot;", stripslashes($row["url"]));

            
$cal_entry['id'] = $entryid;
            
$i=0;
            
$result2 = pg_query ("SELECT name, email, status FROM \"dwm-attendees\" WHERE userid = " . $this->_DBUserID . " AND calendarid = '" . $entryid . "'");
            if (!
$result2) {
                echo
pg_last_error();
            }
            if (
$row2 = pg_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 = pg_fetch_array($result2));
            }
        }
        return
$cal_entry;
    }

    function
DB_GetCalRecurDetails($entryid) {
        
$result = pg_query ("SELECT entryid, \"type\", dtsuntil, numrecurrences, extras FROM \"dwm-recurring\" WHERE calendarid = '" . $entryid . "'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_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++) {
            
$nv = pg_query ("SELECT nextval('seq_dwm_attendees')");
            if (
$row = pg_fetch_array($nv)) {
                
$res = $row["nextval"];
            }
            
$result = pg_query ("INSERT INTO \"dwm-attendees\" (id, userid, calendarid, name, email, status) VALUES ($res, " . $this->_DBUserID . ", " . $cal_addentry . ", '" . addslashes($users[$i]['name']) . "', '" . addslashes($users[$i]['email']) . "', 'not responded')");
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        return
true;
    }

    function
DB_CalNewEntry($submitteddetails) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_calendar')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("INSERT INTO \"dwm-calendar\" (entryid, userid, subject, location, description, starttime, endtime, url, recur) VALUES ($res, " . $this->_DBUserID . ", '" . $submitteddetails['subject'] . "', '" . $submitteddetails['location'] . "', '" . $submitteddetails['description'] . "', '" . $submitteddetails['starttime'] . "', '" . $submitteddetails['endtime'] . "', '" . $submitteddetails['url'] . "', '" . $submitteddetails['recur']['set'] . "')");
        if (!
$result) {
            echo
pg_last_error();
        }
        
$nv = pg_query ("SELECT currval('seq_dwm_calendar')");
        if (
$row = pg_fetch_array($nv)) {
            
$returnid = $row["currval"];
        }
        if (
$submitteddetails['recur']['set'] == 1) {
            
$nv = pg_query ("SELECT nextval('seq_dwm_recurring')");
            if (
$row = pg_fetch_array($nv)) {
                
$res = $row["nextval"];
            }
            
$result = pg_query ("INSERT INTO \"dwm-recurring\" (entryid, calendarid, \"type\", extras, dtsuntil) VALUES ($res, '" . $returnid . "', '" . $submitteddetails['recur']['type'] . "', '" . $submitteddetails['recur']['extras'] . "', '" . $submitteddetails['recur']['date'] . "')");
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        return
$returnid;
    }

    function
DB_CalUpdateEntry($entryid, $submitteddetails) {
        
$result = pg_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
pg_last_error();
        }
        if (
$submitteddetails['recur']['set'] == 1) {
            
$result = pg_query ("UPDATE \"dwm-recurring\" SET \"type\" = '" . $submitteddetails['recur']['type'] . "', extras = '" . $submitteddetails['recur']['extras'] . "', dtsuntil = '" . $submitteddetails['recur']['date'] . "' WHERE calendarid = '" . $entryid . "'");
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        return
$result;
    }

    function
DB_AddUID($uid, $entryid) {
        
$result = pg_query ("UPDATE \"dwm-calendar\" SET uid = '" . $uid . "' WHERE userid = " . $this->_DBUserID . " AND entryid = " . $entryid);
        if (!
$result) {
            echo  
pg_last_error($this->_cn);
        }
        return
$result;
    }

    function
DB_AttendeeStatus($entryid, $address, $status) {
        if (
strtoupper($status) == 'ACCEPTED') {
            
$statussave = 'accepted';
        }
        else {
            
$statussave = 'declined';
        }
        if (isset(
$statussave)) {
            
$result = pg_query ("UPDATE \"dwm-attendees\" SET status = '" . $statussave . "' WHERE userid = " . $this->_DBUserID . " AND email = '" . $address . "' AND calendarid = " . $entryid);
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        return
$result;
    }

    function
DB_CheckUID($uid) {
        
$result = pg_query ("SELECT * FROM \"dwm-calendar\" WHERE userid = " . $this->_DBUserID . " AND uid = '" . $uid . "'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$entryid = $row["entryid"];
        }
        return
$entryid;
    }

    function
DB_CalDeleteEntry($entryid) {
        
$result = pg_query ("DELETE FROM \"dwm-calendar\" WHERE userid = " . $this->_DBUserID . " AND entryid = " . $entryid);
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_CopyCalendar($oldid) {
        
$nv = pg_query ("SELECT nextval('seq_dwm_calendar')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("SELECT * FROM \"dwm-calendar\" WHERE userid = $oldid");
        if (!
$result) {
            
$errors .= pg_last_error();
        }
        if (
$row = pg_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 = pg_query ("INSERT INTO \"dwm-calendar\" (entryid, userid, subject, location, description, starttime, endtime, url, uid) VALUES ($res, " . $this->_DBUserID . ", '" . addslashes($subject) . "', '" . addslashes($location) . "', '" . addslashes($description) . "', '" . $starttime . "', '" . $endtime . "', '" . addslashes($url) . "', '" . addslashes($uid) . "')");
                if (!
$result2) {
                    
$errors .= pg_last_error();
                }

            } while(
$row = pg_fetch_array($result));
        }

        
$nv = pg_query ("SELECT nextval('seq_dwm_attendees')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }

        
$result = pg_query ("SELECT * FROM \"dwm-attendees\" WHERE userid = $oldid");
        if (!
$result) {
            
$errors .= pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$calendarid = $row["calendarid"];
                
$name = stripslashes($row["name"]);
                
$email = stripslashes($row["email"]);
                
$status = stripslashes($row["status"]);
                
$result2 = pg_query ("INSERT INTO \"dwm-attendees\" (id, userid, calendarid, name, email, status) VALUES ($res, " . $this->_DBUserID . ", " . $calendarid . ", '" . addslashes($name) . "', '" . addslashes($email) . "', '" . addslashes($status) . "')");
                if (!
$result2) {
                    
$errors .= pg_last_error();
                }

            } while(
$row = pg_fetch_array($result));
        }

        return
$errors;
    }

    
/*
        PREFERENCES FUNCTIONS
        ---------------------
    */

    
function DB_GetPrefs($type, $oldid = '') {
        if (
$type == "") {
            
$type = 'standard';
        }
        if (
$oldid <> '') {
            
$result = pg_query ("SELECT * FROM \"dwm-prefs\" WHERE userid = $oldid AND type = '" . $type . "'");
        }
        else {
            
$result = pg_query ("SELECT * FROM \"dwm-prefs\" WHERE userid = " . $this->_DBUserID . " AND type = '" . $type . "'");
        }
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$prefs = stripslashes($row["setting"]);
            return
$prefs;
        }
        else {
            return
FALSE;
        }
    }

    function
DB_UpdatePrefs($newprefs, $type) {
        
$newprefs = addslashes($newprefs);
        if (
$type == "") {
            
$type = 'standard';
        }
        
$nv = pg_query ("SELECT COUNT(userid) FROM \"dwm-prefs\" WHERE \"userid\" = " . $this->_DBUserID . " AND \"type\" = '" . $type . "'");
        if (
$row = pg_fetch_array($nv)) {
            
$alreadyexists = $row["count"];
        }
        if (
$alreadyexists > 0) {
            
$result = pg_query ("UPDATE \"dwm-prefs\" SET \"setting\" = '" . $newprefs . "' WHERE userid = " . $this->_DBUserID . " AND \"type\" = '" . $type . "'");
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        else {
            
$result = pg_query ("INSERT INTO \"dwm-prefs\" (userid, \"type\", setting) VALUES (" . $this->_DBUserID . ", '" . $type . "', '" . $newprefs . "')");
            if (!
$result) {
                echo
pg_last_error();
            }
        }
        return
$result;
    }

    function
DB_DeletePrefs($type) {
        if (
$type == "all") {
            
$result = pg_query ("DELETE FROM \"dwm-prefs\" WHERE userid = " . $this->_DBUserID);
        }
        else {
            
$result = pg_query ("DELETE FROM \"dwm-prefs\" WHERE userid = " . $this->_DBUserID . " AND \"type\" = '" . $type . "'");
        }
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_GetHash($hash, $lookupid = 0, $forcereset = 0) {
        if (
$lookupid == 0) {
            if (
$forcereset == 0) {
                
$result = pg_query ("SELECT * FROM \"dwm-users\" WHERE id = '" . $this->_DBUserID . "' AND hash <> ''");
                if (!
$result) {
                    echo
pg_last_error();
                }
                if (
$row = pg_fetch_array($result)) {
                    
$hash = stripslashes($row["hash"]);
                    return
$hash;
                }
                else {
                    
$result = pg_query ("UPDATE \"dwm-users\" SET hash = '" . $hash . "' WHERE id = '" . $this->_DBUserID . "'");
                    return
$hash;
                }
            }
            else {
                
$result = pg_query ("UPDATE \"dwm-users\" SET hash = '" . $hash . "' WHERE id = '" . $this->_DBUserID . "'");
                return
$hash;
            }
        }
        else {
            
$result = pg_query ("SELECT * FROM \"dwm-users\" WHERE id = '" . $lookupid . "' AND hash = '" . $hash . "'");
            if (!
$result) {
                echo
pg_last_error();
            }
            if (
$row = pg_fetch_array($result)) {
                return
TRUE;
            }
            else {
                return
FALSE;
            }
        }
    }

    
/*
        FILTERS FUNCTIONS
        -----------------
    */

    
function DB_SaveFilter($needle, $haystack, $action, $folder) {
        
$needle = addslashes($needle);
        
$nv = pg_query ("SELECT nextval('seq_dwm_filters')");
        if (
$row = pg_fetch_array($nv)) {
            
$res = $row["nextval"];
        }
        
$result = pg_query ("INSERT INTO \"dwm-filters\" (\"id\", userid, needle, \"haystack-to\", \"haystack-cc\", \"haystack-from\", \"haystack-subject\", \"haystack-body\", action, dest) VALUES ($res, " . $this->_DBUserID . ", '" . $needle . "', '" . $haystack['to'] . "', '" . $haystack['cc'] . "', '" . $haystack['from'] . "', '" . $haystack['subject'] . "', '" . $haystack['body'] . "', '" . $action . "', '" . $folder . "')");
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_GetFilters() {
        
$result = pg_query ("SELECT * FROM \"dwm-filters\" WHERE userid = " . $this->_DBUserID);
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_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 = pg_fetch_array($result));
        }
        return
$filterdetails;
    }

    function
DB_DeleteFilter($entryid) {
        
$result = pg_query ("DELETE FROM \"dwm-filters\" WHERE userid = " . $this->_DBUserID . " AND \"id\" = " . $entryid);
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_GetAliasList() {
        
$result = pg_query ("SELECT * FROM \"dwm-alias\" WHERE userid = " . $this->_DBUserID);
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            do {
                
$aliasid = $row["id"];
                
$aliasdetails[$aliasid]['email'] = stripslashes($row["email"]);
                
$aliasdetails[$aliasid]['name'] = $row["name"];
            } while(
$row = pg_fetch_array($result));
        }
        return
$aliasdetails;
    }

    function
DB_SaveAlias($email, $name, $id = '') {
        
$name = addslashes($name);
        if (
$id <> '' && $id <> 'new') {
            
$result = pg_query ("UPDATE \"dwm-alias\" SET email = '$email', \"name\" = '$name' WHERE userid = " . $this->_DBUserID . " AND \"id\" = '$id'");
        }
        else {
            
$nv = pg_query ("SELECT nextval('seq_dwm_alias')");
            if (
$row = pg_fetch_array($nv)) {
                
$res = $row["nextval"];
            }
            
$result = pg_query ("INSERT INTO \"dwm-alias\" (\"id\", userid, email, \"name\") VALUES ($res, " . $this->_DBUserID . ", '" . $email . "', '" . $name . "')");
        }
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    function
DB_DeleteAlias($entryid) {
        
$result = pg_query ("DELETE FROM \"dwm-alias\" WHERE userid = " . $this->_DBUserID . " AND \"id\" = " . $entryid);
        if (!
$result) {
            echo
pg_last_error();
        }
        return
$result;
    }

    
/*
        EXTERNAL ACCOUNT FUNCTIONS
        --------------------------
    */

    
function DB_GetExternalList() {
        
$result = pg_query ("SELECT * FROM \"dwm-pop3\" WHERE userid = " . $this->_DBUserID . " ORDER BY popid ASC");
        if (!
$result) {
            echo
pg_last_error();
        }
        
$i = 0;
        if (
$row = pg_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 = pg_fetch_array($result));
        }
        return
$this->_externallist;
    }

    function
DB_UpdateExternalList($list) {
        
$resultdel = pg_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 = pg_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
pg_last_error();
                }
            }
        }
    }

    
/*
        GET BLOCKED DOMAINS
        -------------------
    */

    
function DB_CheckBlocked($mailserver) {
        
$result = pg_query ("SELECT * FROM \"dwm-block\" WHERE domain = '" . $mailserver . "'");
        if (!
$result) {
            echo
pg_last_error();
        }
        if (
$row = pg_fetch_array($result)) {
            
$rowid = $row["id"];
            return
$rowid;
        }
        else {
            return
0;
        }    
    }

}
?>

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 1.0 pre-release build #16 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0084 ]--