Current File : //etc/zpanel/panel/modules/database_settings/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 function getResult()
    {
         if (!fs_director::CheckForEmptyValue(self::$ok)) {
                 return ui_sysmessage::shout(ui_language::translate("Changes has been saved successfully "), "zannounceok");
            }
            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;
}





    static function doUpdateDatabase()
    {
        global $controller;
        runtime_csfr::Protect();
        $currentuser = ctrl_users::GetUserDetail();
        $formvars = $controller->GetAllControllerRequests('FORM');
        if (self::ExecuteUpdateDatabase($formvars['inEnabled'], $currentuser['userid']))
          {
		self::$ok = TRUE;
            	return true;
          } else {
           	 return false;
        }
	 	return;  
           
    }

    static function ExecuteUpdateDatabase($enabled,$uid)
    {
        global $zdbh;
	global $controller;
        $datasql = $zdbh->prepare("SELECT * FROM  x_database_settings WHERE ds_user_vc='$uid'");
        $datasql->execute();
	$result = $datasql->fetch();
        $id = $result['ds_id_pk'];
        if($result != '')
        {       
        $sql = $zdbh->prepare("UPDATE x_database_settings SET ds_enabled_in=:enabled,ds_updated_vc=:date WHERE ds_id_pk=:id");
        $time = time();
        $sql->bindParam(':enabled', $enabled);
        $sql->bindParam(':id', $id);
        $sql->bindParam(':date',$time);
        $sql->execute();
	return true;
        }
        else
        {
        $sql = $zdbh->prepare("INSERT INTO x_database_settings (ds_enabled_in,ds_user_vc,ds_updated_vc) VALUES (:enabled,:userid,:date)");
        $time = time();
        $sql->bindParam(':enabled', $enabled);
        $sql->bindParam(':userid', $uid);
        $sql->bindParam(':date', $time);
        $sql->execute();
	return true;
        }
        
    }


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


    static function CheckEnabled()
    {
	global $zdbh;
        global $controller;
        $currentuser = ctrl_users::GetUserDetail();
	$uid = $currentuser['userid'];
        $res = array();
        $datasql = $zdbh->prepare("SELECT * FROM  x_database_settings WHERE ds_user_vc='$uid'");
        $datasql->execute();
        $result = $datasql->fetch();
        $enabled = $result['ds_enabled_in'];
        if ($enabled == 1) {
            $echecked = "CHECKED";
            $dchecked = "";
        } else {
            $echecked = "";
            $dchecked = "CHECKED";
        }
        array_push($res, array('echecked' => $echecked,
            'dchecked' => $dchecked,'status' => $enabled));
        return $res;
    }

}