Current File : //etc/zpanel/panel/modules/ipdomain/code/controller.ext.php
<?php

/**
 * @copyright 2014-2015 Sentora Project (http://www.sentora.org/) 
 * Sentora is a GPL fork of the ZPanel Project whose original header follows:
 *
 * ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
 *
 * @package ZPanel
 * @version $Id$
 * @author Bobby Allen - ballen@bobbyallen.me
 * @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
 *
 * This program (ZPanel) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
class module_controller extends ctrl_module
{

    static $ok;
    static $password;
    static $alreadyexists;
    static $validemail;
    static $noaddress;
    static $editmailbox;
    static $update;
    static $delete;
    static $create;
	static $badpassword;
	static $f_quota;
    /**
     * The 'worker' methods.
     */
    static function ListMailboxes($id)
    {
        global $zdbh;
        global $controller;
		
		$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
		include('cnf/db.php');
		$z_db_user = $user;
		$z_db_pass = $pass;
		try {
		$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
		} catch (PDOException $e) {
		echo $e;
		}
		
        $currentuser = ctrl_users::GetUserDetail($id);
        $sql = "SELECT * FROM x_mailboxes WHERE mb_acc_fk=:userid AND mb_deleted_ts IS NULL ORDER BY mb_address_vc ASC";
        //$numrows = $zdbh->query($sql);
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
		$count = $numrows->fetchColumn();
        if ($count > 0) {
            $sql = $zdbh->prepare($sql);
            $sql->bindParam(':userid', $currentuser['userid']);
            $res = array();
            $sql->execute();
            while ($rowmailboxes = $sql->fetch()) {
				
	$m_quota="";
	$m_numrows = $mail_db->prepare("SELECT * FROM mailbox WHERE username=:fulladdress");
    $m_numrows->bindParam(':fulladdress', $rowmailboxes['mb_address_vc']);
    $m_numrows->execute();
    $m_result = $m_numrows->fetch();
    if (!$m_result) {
	$m_quota="";
	}else
	{
	// $m_quota=$m_result['quota']." MB";
		$m_quota=$m_result['quota'];
	}
	
		$mail_input = $rowmailboxes['mb_address_vc'];
		$maill_array = explode( '@', $mail_input ) ;
		$path = "/var/sentora/vmail/";
		$mail_path = $maill_array[0]; 
		$domain_path = $maill_array[1]; 
		$total = $path."".$domain_path."/".$maill_array[0];
		$out = $rowmailboxes['mb_size'];
	
                if ($rowmailboxes['mb_enabled_in'] == 1) {
                    $status = '<img src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/up.gif" alt="Up"/>';
                } else {
                    $status = '<img src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/down.gif" alt="Down"/>';
                }
				if($total != ""){
				
				$m_quota_size = $m_quota * 1024;
				$out_size = sprintf('%.2f',$out /1024);
				
				$dp = sprintf('%.2f',($out / $m_quota_size) * 100);
                $res[] = array('address' => $rowmailboxes['mb_address_vc'],
                    'created' => date(ctrl_options::GetSystemOption('sentora_df'), $rowmailboxes['mb_created_ts']),
                    'status' => $status,
					'quota' => $m_quota,
					'used' => $out_size,
					'progress'=> '<progress value="'.$dp.'" max="100"></progress>',
                    'id' => $rowmailboxes['mb_id_pk']);
					}
					else {
						$res[] = array('address' => $rowmailboxes['mb_address_vc'],
                    'created' => date(ctrl_options::GetSystemOption('sentora_df'), $rowmailboxes['mb_created_ts']),
                    'status' => $status,
					'quota' => $m_quota,
					
					'progress' => '<progress value="0" max="100"></progress>',
                    'id' => $rowmailboxes['mb_id_pk']);
					}
            }
	
            return $res;
		
        } else {
            return false;
        }
    }
 static function gethelpicon()
{
    global $zdbh;
    global $controller;
    $temp=$controller->GetControllerRequest('URL','module') ;
    $val = '/assets/one.txt';
    $val1 = '/modules/';
   $name=file_get_contents("modules/$temp/assets/helpicon.txt");
   return $name;
}
	static function getShowOptionbox()
	{
		global $zdbh;
		global $controller;
	$res="";
	$res.="<select name='inDomain' id='inDomain' >";
	$sql =  "SELECT a.vh_name_vc,a.vh_directory_vc,b.ac_user_vc FROM x_vhosts a, x_accounts b WHERE  a.vh_enabled_in=1 AND b.ac_id_pk=a.vh_acc_fk AND a.vh_deleted_ts IS NULL";
	$num_sql="select count(*) from x_vhosts WHERE vh_enabled_in=1 AND vh_deleted_ts IS NULL";
	$hostded_dir=ctrl_options::GetSystemOption('hosted_dir');      
	$select_dir=ctrl_options::GetSystemOption('ipdomain_dir');
	$default_select="";
	if($select_dir == "/etc/sentora/panel/etc/static/pages/")
		$default_select="selected";
	$res.= "<option value='/etc/sentora/panel/etc/static/pages/' $default_select >Default Page</option>"; 
	$numbrows=$zdbh->prepare($num_sql);
	$numbrows->execute();
	if($numbrows->fetchColumn()<>0){
	$sql= $zdbh->prepare($sql);
	$sql->execute();
	while ($rowdomains = $sql->fetch()) {
		$abs_path=$hostded_dir.$rowdomains['ac_user_vc']."/public_html".$rowdomains['vh_directory_vc'];
		$selected="";
		if( $abs_path ==  $select_dir )
		$selected="selected";
		$res.= "<option value='".$abs_path."'  $selected >".$rowdomains['vh_name_vc']."</option>";
	}
	}
	$res.="</select>";     
	return $res;
	}

static function SetCallDaemon()
    {
    
	$service_port = 4445 ;
    $address = gethostbyname('localhost');
	$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
		if ($socket === false)
		{
		/* 
		echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
		self::$tryagain=true;
		return false;
		*/
		} 
       //  echo "Attempting to connect to '$address' on port '$service_port'...";
        $result = socket_connect($socket, $address, $service_port);
        if ($result === false) 
		{
        /* 
		echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
		self::$tryagain=true;
		return false;
		*/
		}
		socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
		$in="command DaemonCall ";
		socket_write($socket, $in, strlen($in));		
		socket_close($socket);
  
    }

    static function ListCurrentMailboxes($mid)
    {
        global $zdbh;
		global $controller;
		$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
		include('cnf/db.php');
		$z_db_user = $user;
		$z_db_pass = $pass;
		try {
		$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
		} catch (PDOException $e) {
		echo $e;
		}

		
        $sql = "SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid AND mb_deleted_ts IS NULL ORDER BY mb_address_vc ASC";
        //$numrows = $zdbh->query($sql);
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':mid', $mid);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            $sql = $zdbh->prepare($sql);
            $sql->bindParam(':mid', $mid);
            $res = array();
            $sql->execute();
            while ($rowmailboxes = $sql->fetch()) {
                if ($rowmailboxes['mb_enabled_in'] == 1) {
                    $ischeck = "CHECKED";
                } else {
                    $ischeck = NULL;
                }
	$m_quota="";
	$m_numrows = $mail_db->prepare("SELECT * FROM mailbox WHERE username=:fulladdress");
    $m_numrows->bindParam(':fulladdress', $rowmailboxes['mb_address_vc']);
    $m_numrows->execute();
    $m_result = $m_numrows->fetch();
    if (!$m_result) {
	$m_quota="";
	}else
	{
	$m_quota=$m_result['quota'];
	}
                $res[] = array('address' => $rowmailboxes['mb_address_vc'],
                    'created' => date(ctrl_options::GetSystemOption('sentora_df'), $rowmailboxes['mb_created_ts']),
                    'ischeck' => $ischeck,
					'quota' => $m_quota,
                    'id' => $rowmailboxes['mb_id_pk']);
            }
            return $res;
        } else {
            return false;
        }
    }

    static function ListDomains()
    {
        global $zdbh;
        $sql = "SELECT * FROM x_vhosts WHERE  vh_enabled_in=1 AND vh_deleted_ts IS NULL ORDER BY vh_name_vc ASC";
        //$numrows = $zdbh->query($sql);
        $numrows = $zdbh->prepare($sql);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            $sql = $zdbh->prepare($sql);
            $res = array();
            $sql->execute();
            while ($rowdomains = $sql->fetch()) {
                $res[] = array('domain' => ui_language::translate($rowdomains['vh_name_vc']));
            }
            return $res;
        } else {
            return false;
        }
    }

    static function ExecuteAddMailbox($uid, $address, $domain, $password,$quota)
    {
        global $zdbh;
        global $controller;
        $currentuser = ctrl_users::GetUserDetail($uid);
        if (fs_director::CheckForEmptyValue(self::CheckCreateForErrors($address, $domain, $password,$quota))) {
            return false;
        }
        runtime_hook::Execute('OnBeforeCreateMailbox');
	   if(!preg_match_all('$\S*(?=\S{9,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $password))
	   {
    	self::$badpassword = true;
	   }
        else
        {
        $address = strtolower(str_replace(' ', '', $address));
        $fulladdress = strtolower(str_replace(' ', '', $address . "@" . $domain));
        self::$create = true;
        // Include mail server specific file here.
        $MailServerFile = 'modules/' . $controller->GetControllerRequest('URL', 'module') . '/code/' . ctrl_options::GetSystemOption('mailserver_php');
        if (file_exists($MailServerFile))
            include($MailServerFile);

        $sql = "INSERT INTO x_mailboxes (mb_acc_fk,
											 mb_address_vc,
											 mb_created_ts) VALUES (
											 :userid,
											 :fulladdress,
											 :time)";
        $time = time();
        $sql = $zdbh->prepare($sql);
        $sql->bindParam(':time', $time);
        $sql->bindParam(':userid', $currentuser['userid']);
        $sql->bindParam(':fulladdress', $fulladdress);
        $sql->execute();
        runtime_hook::Execute('OnAfterCreateMailbox');
        self::$ok = true;
        return true;
		}
    }

    static function ExecuteDeleteMailbox($mid)
    {
        global $zdbh;
        global $controller;
        runtime_hook::Execute('OnBeforeDeleteMailbox');
        self::$delete = true;

        //$rowmailbox = $zdbh->query("SELECT * FROM x_mailboxes WHERE mb_id_pk=" . $mid . "")->Fetch();
        $numrows = $zdbh->prepare("SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid");
        $numrows->bindParam(':mid', $mid);
        $numrows->execute();
        $row_count2 = $numrows->rowCount();
        if($row_count2 >0)
        {
            $rowmailbox = $numrows->fetch();
        // Include mail server specific file here.
        
            $MailServerFile = 'modules/' . $controller->GetControllerRequest('URL', 'module') . '/code/' . ctrl_options::GetSystemOption('mailserver_php');
            if (file_exists($MailServerFile)) {
                include($MailServerFile);
            }
            $time = time();
            $sql = "UPDATE x_mailboxes SET mb_deleted_ts=:time WHERE mb_id_pk=:mid";
            $sql = $zdbh->prepare($sql);
            $sql->bindParam(':time', $time);
            $sql->bindParam(':mid', $mid);
            $sql->execute();
                
                $auto_email = $rowmailbox['mb_address_vc'];
                $auto_file_path = "/var/spool/autoresponse/responses/".$auto_email;
                if (file_exists($auto_file_path)) 
                {

                    $currentuser = ctrl_users::GetUserDetail();
                    $suid = $currentuser['userid'];
                    if(unlink($auto_file_path))
                    {
                        date_default_timezone_set("UTC");
                        $current_time = date("Y-m-d H:i:s");
                        $current_str_time =  strtotime($current_time);
                        $stmt4 =$zdbh->prepare("update x_autorespond set vh_deleted =:str_time  where  vh_mail =:vhid  and vh_acc_fk =:sid ");
                        $stmt4->bindParam(':str_time',$current_str_time);
                        $stmt4->bindParam(':sid',$suid);
                        $stmt4->bindParam(':vhid',$auto_email);
                        $stmt4->execute();   
                        /*********$affected_rows = $stmt4->rowCount(); *************/
                        
                    }
                    
                }
            
        }
        runtime_hook::Execute('OnAfterDeleteMailbox');
        self::$ok = true;
    }
    static function ExecuteUpdateMailbox($mid, $password, $enabled,$quota,$flag)
    {
        global $zdbh;
        global $controller;
		if($flag=="quota")
		{
						if (fs_director::CheckForEmptyValue($quota)) {
						self::$f_quota = true;
						return false;
						}
						$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
						include('cnf/db.php');
						$z_db_user = $user;
						$z_db_pass = $pass;
						try {
						$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
						} catch (PDOException $e) {
						echo $e;
						}
						$numrows = $zdbh->prepare("SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid");
						$numrows->bindParam(':mid', $mid);
						$numrows->execute();

						$rowmailbox = $numrows->fetch();
						$m_numrows = $mail_db->prepare("update mailbox set quota=:quota WHERE username=:fulladdress");
						$m_numrows->bindParam(':quota', $quota);
						$m_numrows->bindParam(':fulladdress', $rowmailbox['mb_address_vc']);
						$m_numrows->execute();
						self::$ok = true;
		}else
		{
					runtime_hook::Execute('OnBeforeUpdateMailbox');
					$numrows = $zdbh->prepare("SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid");
					$numrows->bindParam(':mid', $mid);
					$numrows->execute();

					$rowmailbox = $numrows->fetch();


					if ($enabled <> 0) {
					self::ExecuteEnableMailbox($mid);
					} else {
					self::ExecuteDisableMailbox($mid);
					}
					self::$update = true;
					// Include mail server specific file here.
					$MailServerFile = 'modules/' . $controller->GetControllerRequest('URL', 'module') . '/code/' . ctrl_options::GetSystemOption('mailserver_php');
					if (file_exists($MailServerFile)) {
					include($MailServerFile);
					}
					runtime_hook::Execute('OnAfterUpdateMailbox');
					self::$ok = true;
		}
		 

       
        return;
    }

    static function ExecuteEnableMailbox($mid)
    {
        global $zdbh;
        runtime_hook::Execute('OnBeforeEnableMailbox');
        $sql = $zdbh->prepare("UPDATE x_mailboxes SET mb_enabled_in=1 WHERE mb_id_pk=:mid");
        $sql->bindParam(':mid', $mid);
        $sql->execute();
        $retval = true;
        runtime_hook::Execute('OnAfterEnableMailbox');
        return $retval;
    }

    static function ExecuteDisableMailbox($mid)
    {
        global $zdbh;
        runtime_hook::Execute('OnBeforeDisableMailbox');
        $sql = $zdbh->prepare("UPDATE x_mailboxes SET mb_enabled_in=0 WHERE mb_id_pk=:mid");
        $sql->bindParam(':mid', $mid);
        $sql->execute();
        $retval = true;
        runtime_hook::Execute('OnAfterDisableMailbox');
        return $retval;
    }

    static function CheckCreateForErrors($address, $domain, $password,$quota)
    {
        global $zdbh;
        $fulladdress = strtolower(str_replace(' ', '', $address . '@' . $domain));
        if (fs_director::CheckForEmptyValue($address)) {
            self::$noaddress = true;
            return false;
        }
        if (fs_director::CheckForEmptyValue($password)) {
            self::$password = true;
            return false;
        }
        if (!self::IsValidEmail($fulladdress)) {
            self::$validemail = true;
            return false;
        }
        $sql = "SELECT * FROM x_mailboxes WHERE mb_address_vc=:fulladdress AND mb_deleted_ts IS NULL";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':fulladdress', $fulladdress);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            self::$alreadyexists = true;
            return false;
        }
        $sql = "SELECT * FROM x_forwarders WHERE fw_address_vc=:fulladdress AND fw_deleted_ts IS NULL";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':fulladdress', $fulladdress);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            self::$alreadyexists = true;
            return false;
        }
        $sql = "SELECT * FROM x_distlists WHERE dl_address_vc=:fulladdress AND dl_deleted_ts IS NULL";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':fulladdress', $fulladdress);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            self::$alreadyexists = true;
            return false;
        }
        $sql = "SELECT * FROM x_aliases WHERE al_address_vc=:fulladdress AND al_deleted_ts IS NULL";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':fulladdress', $fulladdress);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            self::$alreadyexists = true;
            return false;
        }
		
		 if (fs_director::CheckForEmptyValue($quota)) {
            self::$f_quota = true;
            return false;
        }
		
        return true;
    }

    static function IsValidEmail($email)
    {
        return preg_match('/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i', $email) == 1;
    }

    /**
     * End 'worker' methods.
     */

    /**
     * Webinterface sudo methods.
     */
    static function doAddMailbox()
    {
        global $zdbh;
	global $controller;
        runtime_csfr::Protect();
        $currentuser = ctrl_users::GetUserDetail();
        $formvars = $controller->GetAllControllerRequests('FORM');
        /* if (self::ExecuteAddMailbox($currentuser['userid'], $formvars['inAddress'], $formvars['inDomain'], $formvars['inPassword'],$formvars['inQuota']))
            self::$ok = true; */
	  $sql = $zdbh->prepare("UPDATE x_settings
                                SET so_value_tx='true'
                                WHERE so_name_vc='apache_changed'");
          $sql->execute();
 $sql = $zdbh->prepare("UPDATE x_settings
                                SET so_value_tx='".$formvars['inDomain']."'
                                WHERE so_name_vc='ipdomain_dir'");
          $sql->execute();
	self::SetCallDaemon();
   self::$ok = true;
        return true;
    }

    static function doEditMailbox()
    {
        global $controller;
        runtime_csfr::Protect();
        $currentuser = ctrl_users::GetUserDetail();
        $formvars = $controller->GetAllControllerRequests('FORM');
        foreach (self::ListMailboxes($currentuser['userid']) as $row) {
            if (isset($formvars['inDelete_' . $row['id']])) {
                header("location: ./?module=" . $controller->GetCurrentModule() . '&show=Delete&other=' . $row['id']);
                exit;
            }
            if (isset($formvars['inEdit_' . $row['id']])) {
                header('location: ./?module=' . $controller->GetCurrentModule() . '&show=Edit&other=' . $row['id']);
                exit;
            }
			if (isset($formvars['inquotaEdit_' . $row['id']])) {
                header('location: ./?module=' . $controller->GetCurrentModule() . '&show=quotaEdit&other=' . $row['id']);
                exit;
            }
        }
        return true;
    }

    static function doUpdateMailbox()
    {
        global $controller;
        runtime_csfr::Protect();
        $currentuser = ctrl_users::GetUserDetail();
        $formvars = $controller->GetAllControllerRequests('FORM');
        $enabled = (isset($formvars['inEnabled'])) ? fs_director::GetCheckboxValue($formvars['inEnabled']) : 0;
        if (self::ExecuteUpdateMailbox($formvars['inSave'], $formvars['inPassword'],$enabled,$formvars['inQuota'],$formvars['flag']))
            self::$ok = true;
        return true;
    }

    static function doConfirmDeleteMailbox()
    {
        global $controller;
        runtime_csfr::Protect();
        $formvars = $controller->GetAllControllerRequests('FORM');
        return self::ExecuteDeleteMailbox($formvars['inDelete']);
    }

    static function getMailboxList()
    {
        $currentuser = ctrl_users::GetUserDetail();
        return self::ListMailboxes($currentuser['userid']);
    }

    static function getDomainList()
    {
        $currentuser = ctrl_users::GetUserDetail();
        return self::ListDomains();
    }

    static function getCurrentMailboxList()
    {
        global $controller;
        return self::ListCurrentMailboxes($controller->GetControllerRequest('URL', 'other'));
    }

    static function GetMailOption($name)
    {
        global $zdbh;
        $numrows = $zdbh->prepare("SELECT mbs_value_tx FROM x_mail_settings WHERE mbs_name_vc = :name");
        $numrows->bindParam(':name', $name);
        $numrows->execute();
        $result = $numrows->fetch();
        return ($result) ? $result['mbs_value_tx'] : false;
    }

    static function getisCreateMailbox()
    {
        global $controller;
        $urlvars = $controller->GetAllControllerRequests('URL');
        return !isset($urlvars['show']);
    }

    static function getisDeleteMailbox()
    {
        global $controller;
        $urlvars = $controller->GetAllControllerRequests('URL');
        return (isset($urlvars['show'])) && ($urlvars['show'] == "Delete");
    }

    static function getisEditMailbox()
    {
        global $controller;
        $urlvars = $controller->GetAllControllerRequests('URL');
        return (isset($urlvars['show'])) && ($urlvars['show'] == "Edit");
    }

	 static function getisquotaEditMailbox()
    {
        global $controller;
        $urlvars = $controller->GetAllControllerRequests('URL');
        return (isset($urlvars['show'])) && ($urlvars['show'] == "quotaEdit");
    }
	
    static function getEditCurrentMailboxName()
    {
        global $controller;
        if ($controller->GetControllerRequest('URL', 'other')) {
            $current = self::ListCurrentMailboxes($controller->GetControllerRequest('URL', 'other'));
            return $current[0]['address'];
        } else {
            return '';
        }
    }

    static function getEditCurrentMailboxID()
    {
        global $controller;
        if ($controller->GetControllerRequest('URL', 'other')) {
            $current = self::ListCurrentMailboxes($controller->GetControllerRequest('URL', 'other'));
            return $current[0]['id'];
        } else {
            return "";
        }
    }

    static function getQuotaLimit()
    {
        $currentuser = ctrl_users::GetUserDetail();
        return ($currentuser['mailboxquota'] < 0) or //-1 = unlimited
                ($currentuser['mailboxquota'] > ctrl_users::GetQuotaUsages('mailboxes', $currentuser['userid']));
    }

    static function getEmailUsagepChart()
    {
        $currentuser = ctrl_users::GetUserDetail();
        $maximum = $currentuser['mailboxquota'];
        if ($maximum < 0) { //-1 = unlimited
            return '<img src="' . ui_tpl_assetfolderpath::Template() . 'img/misc/unlimited.png" alt="' . ui_language::translate('Unlimited') . '"/>';
        } else {
            $used = ctrl_users::GetQuotaUsages('mailboxes', $currentuser['userid']);
            $free = max($maximum - $used, 0);
            return '<img src="etc/lib/pChart2/sentora/z3DPie.php?score=' . $free . '::' . $used
                    . '&labels=Free: ' . $free . '::Used: ' . $used
                    . '&legendfont=verdana&legendfontsize=8&imagesize=240::190&chartsize=120::90&radius=100&legendsize=150::160"'
                    . ' alt="' . ui_language::translate('Pie chart') . '"/>';
        }
    }

    static function getResult()
    {
        if (!fs_director::CheckForEmptyValue(self::$alreadyexists)) {
            return ui_sysmessage::shout(ui_language::translate('A mailbox, alias, forwarder or distribution list already exists with that name.'), "zannounceerror");
        }
        if (!fs_director::CheckForEmptyValue(self::$validemail)) {
            return ui_sysmessage::shout(ui_language::translate("Your email address is not valid."), "zannounceerror");
        }
        if (!fs_director::CheckForEmptyValue(self::$password)) {
            return ui_sysmessage::shout(ui_language::translate("Your password cannot be blank."), "zannounceerror");
        }
        if (!fs_director::CheckForEmptyValue(self::$noaddress)) {
            return ui_sysmessage::shout(ui_language::translate("Your email address cannot be blank."), "zannounceerror");
        }
		if (!fs_director::CheckForEmptyValue(self::$f_quota)) {
            return ui_sysmessage::shout(ui_language::translate("Mailbox quota cannot be blank."), "zannounceerror");
        }
        if (!fs_director::CheckForEmptyValue(self::$ok)) {
            return ui_sysmessage::shout(ui_language::translate("Updated successfully!"), "zannounceok");
        }
		if (!fs_director::CheckForEmptyValue(self::$badpassword)) {
            return ui_sysmessage::shout(ui_language::translate("Your password did not meet the minimun length requirements.Characters needed for password length : 9 with atleast 1 uppercase,lowercase,special character"), "Error");
			}
        return;
    }

    /**
     * Webinterface sudo methods.
     */
}