Current File : //etc/zpanel/panel/modules/email_routing/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 $editdomain;
    static $showform;
    static $ResultOk;
    static $ResultErr;

    private function SetError($ErrorText)
    {
        if (empty(self::$ResultErr))
            self::$ResultErr = $ErrorText;
    }

    /* Load DNS CSS and JS files */

    static function getInit()
    {
        global $controller;
        $line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/dns.css">';
		$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/sentora.js"></script>';  
 	    $line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/bootstrap-tab.js"></script>';		
		$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/dns.js"></script>';
	
		return $line;
    }

    /*
     * Determine which DNS page to show
     * Domain List or DNS Records
     */

    static function getRecordAction()
    {
        global $zdbh;
        global $controller;
        $currentuser = ctrl_users::GetUserDetail();
		$display = "";
		$display .= "<form action=\"./?module=email_routing&show=EmailRouting\" method=\"post\">";
		$display .= "<table class=\"zform\">";
        $display .= "<tr>";
        $display .= "<td>";
		$display .='<select name="inDomain">';
		$numrows = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_deleted_ts IS NULL");
        $numrows->execute();
		$display .="<option>Select Domain</option>";
		while ($domain = $numrows->fetch()) {
		$display .="<option ".$domain['vh_id_pk'].">".$domain['vh_name_vc']."</option>";
		}
		$display .='</select>';
		$display .= "</td>";
        $display .= "<td>";
		$display .= '<button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i> ' . ui_language::translate("Edit") . '</button>';
        $display .= "</tr>";
		$display .= "</table>";
		$display .= self::getCSFR_Tag();
		$display .= '</form>';
		//$display = self::EmailRouting();
        return $display;
    }
	
	static function getisEmailRouting()
	{
		global $controller;
		$currentuser = ctrl_users::GetUserDetail();
        $urlvars = $controller->GetAllControllerRequests('URL');
        if (isset($urlvars['show']) && $urlvars['show']=="EmailRouting")
        return true;
		else 
		return false;
	}
	static function getisnotEmailRouting()
	{
		global $controller;
		$currentuser = ctrl_users::GetUserDetail();
        $urlvars = $controller->GetAllControllerRequests('URL');
        if(self::$ResultErr)
		return true;
		if (isset($urlvars['show']) && $urlvars['show']=="EmailRouting")
        return false;
		else 
		return true;
	}
	
	static function getEmailRouting()
    {
		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;
		}
		
		$domain = $controller->GetControllerRequest('FORM', 'inDomain');
		if($domain == "Select Domain"){
			self::$ResultErr= true;
			return false;
		}
        $sql = $mail_db->prepare("SELECT * FROM domain WHERE domain='".$domain."' AND active=1");
        $sql->execute();
		$doma = $sql->fetch();
		//print_r($doma);
        $currentuser = ctrl_users::GetUserDetail();
        $line = "";
        $line .= "<div class=\"zgrid_wrapper\">";
		$line .= "<div id=\"dnsTitle\" class=\"account accountTitle\">";
        $line .= "<div class=\"content\"><h2>" . ui_language::translate("Email Routing for ".$domain) . "</h2>";
        $line .= '</div>';
        $line .= "<form action=\"./?module=email_routing&action=EditEmailRouting\" method=\"post\">";
        $line .= "<table class=\"zform\">";
        $line .= "<tr>";
        $line .= "<td>";
		if($doma['backupmx'] == 0){
		$line .= '<input type="radio" name="Remote" checked="checked" value="0">Local Mail Exchanger';
		}
		else {
		$line .= '<input type="radio" name="Remote" value="0">Local Mail Exchanger';
		}
		$line .= "</td>";
		$line .= "</tr>";
		$line .= "<tr>";
        $line .= "<td>";
		if($doma['backupmx'] == 1){
		$line .= '<input type="radio" name="Remote" checked="checked" value="1">Remote Mail Exchanger';
		}
		else {
		$line .= '<input type="radio" name="Remote" value="1">Remote Mail Exchanger';
		}
		$line .= "</td>";
		$line .= "</tr>";
		$line .= "<tr>";
        $line .= "<td>";
        $line .= '<button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i> ' . ui_language::translate("Update") . '</button>';
        $line .= "</td>";
        $line .= "</tr>";
        $line .= "</table>";
        $line .= "<input type=\"hidden\" name=\"inDomain\" value =\"" . $domain. "\" />";
        $line .= self::getCSFR_Tag();
        $line .= '</form>';
        $line .= '</div>';
        return $line;
    

		exit;
	}
	
	static function doEditEmailRouting()
    {
		global $zdbh;
        global $controller;
		$domain = $controller->GetControllerRequest('FORM', 'inDomain');
		$backupmx = $controller->GetControllerRequest('FORM', 'Remote');
		
		$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 = $mail_db->prepare("UPDATE domain SET backupmx=".$backupmx." WHERE domain='".$domain."' AND active=1");
        $sql->execute();
		self::$ResultOk= true;
		return true;
	}

    static function getResult()
    {
        if (self::$ResultOk) {
			return ui_sysmessage::shout(ui_language::translate("Email Routing Updated."), "zannouncesuccess","Success");
    
        } 
		if (self::$ResultErr) {
			return ui_sysmessage::shout(ui_language::translate("Please Select a Domain."), "zannounceerror","Failed");
        }
        return;
    }


  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;
    }    


}