CHips L MINI SHELL

CHips L pro

Current Path : /opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/tryout/classes/
Upload File :
Current File : //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/tryout/classes/Api.php

<?php

require_once 'Date/TimeZone.php';
require_once 'DB/DataObject.php';
require_once(SGL_MOD_DIR . '/../lib/RVSGL/SitebuilderDao/DbWrapper.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/SitebuilderDao/TryoutDao.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/SitebuilderDao/UsrDao.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/SitebuilderDao/ProjectDao.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/rvsLibs/String.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/rvsLibs/Config.php');
require_once(SGL_MOD_DIR . '/../lib/RVSGL/DaoFactory.php');
//require_once( SGL_MOD_DIR . '/tryout/classes/SgSitebuilderDao/SitebuilderDao.php');
define('PREFIXTRYOUT', 'rvstryout');

class TryoutApi
{
    function TryoutApi()
    {
        
    }

    function InitialiseDbDataObject() {
        //  init DB_DataObject
        $oTask = new SGL_Task_InitialiseDbDataObject();
        $ok = $oTask->run($conf);
    }
    
    function verifyAccount()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $dbh = SGL_DB::singleton();
        // รับค่า config
        $c = SGL_Config::singleton();
        $conf = $c->getAll();
        // รับค่า input
        $req = SGL_Request::singleton();
        $frm = $req->getAll();
        $sglUserName = SGL_Session::getUsername();      
        //test
        //$res =  $this->verifyUserExistInRVS('duangdao.k');
       $res =  $this->verifyUserExistInRVS(PREFIXTRYOUT . $sglUserName);
        if (count($res) < 1) {
            $this->InitialiseDbDataObject();
            $oUser = DB_DataObject::factory($conf['table']['user']);
            $oUser->get(SGL_Session::getUid());
            $input->username = $oUser->username;
            $this->registerUser($input);
        } 
            return true;
        }

        function verifyUserExistInRVS($username)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
           $oSitebuilder = $this->_connectSitebuilder();
            $res = $oSitebuilder->isRvsUsrNameDuplicate($username);
            return $res;
        }

        function addUser($input)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
         $res =  $this->verifyUserExistInRVS($input->user->username);
            if (count($res) < 1) {
                $input->username = $input->user->username;
                $this->registerUser($input);
            }
            return true;
        }


        function registerUser($input)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oSitebuilder = $this->_connectSitebuilder();
            $res = $oSitebuilder->addRvsUsrId(PREFIXTRYOUT. $input->username);
            $this->_tryoutCreateUserFolder(PREFIXTRYOUT. $input->username);
            return true;
        }
        
        function _connectSitebuilder()
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oSitebuilder = TryoutDao::singleton($autoload = false);
            $aSitebuilderConfig = $oSitebuilder->getSitebuilderConfig();
            $dbh = $oSitebuilder->rvsConnectDb();
            $oSitebuilder->registRvsConf($aSitebuilderConfig, $dbh);
            // Initialise Db DataObject
            $oSitebuilder->rvsInitialiseDbDataObject();
            return $oSitebuilder;
        }

        function login($password)
        {
            return true;
        }



        function logout()
        {
            return true;
        }


        function changePassword($password, $relogin = true)
        {
            return true;
        }


        function _resetPassword($username, $password)
        {
            return true;
        }

        function _getAuthorIdByUsername($username)
        {

        }

        function changeUserAccountProfile($currentUsername, $newUsername, $firstName, $email)
        {
            return true;
        }

        function changeAdminConfiguration($firstName, $email)
        {
            return true;

        }

        function deleteUser($aUserId)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            //database seagull
            $this->InitialiseDbDataObject();
            $dbhSg = SGL_DB::singleton();
            $c = SGL_Config::singleton();
            $conf = $c->getAll();
            
             if (!is_array($aUserId)) {
                $aUserId = array($aUserId);
            } else {
                $aUserId = array_unique($aUserId);
            }
            $userIdQuery = implode(',', $aUserId);

            $query = "
            SELECT username
            FROM " . $conf['table']['user'] . "
            WHERE usr_id IN (" . $userIdQuery . ")
                ";

            $aSglUserName = $dbhSg->getCol($query);
             SGL::logMessage('query=======' .$query, PEAR_LOG_DEBUG);
             SGL::logMessage('$aSglUserName=======' .$aSglUserName, PEAR_LOG_DEBUG);

             //delete file or project
           $deleteFileAndFolder = $this->deleteFileAndFolder($aSglUserName);
             //delete user in rvsitebuilder
           $res = $this->deleteRvsUser($aSglUserName);
           SGL::logMessage('after--------$res--' . $res, PEAR_LOG_DEBUG); 
            //database sitebuilder
            
            //TODO call function_deleteFileAndFolder
            return $res;

        }
        
        function deleteRvsUser($SglUserName)
        {
             SGL::logMessage('==== deleteRvsUser == 1', PEAR_LOG_DEBUG); 
             $oSitebuilder = $this->_connectSitebuilder();
            if (count($SglUserName) && is_array($SglUserName)) {
                  SGL::logMessage('==== deleteRvsUser**********count====$sglUserName' . $SglUserName, PEAR_LOG_DEBUG); 
                foreach ($SglUserName as $username) {
                     SGL::logMessage('==== delete**********if====' . $username, PEAR_LOG_DEBUG); 
                    $res =  $oSitebuilder->deleteRvsUserId(PREFIXTRYOUT. $username);
                }
            } elseif(isset($SglUserName) && !is_array($SglUserName)) {
                 SGL::logMessage('==== deleteRvsUser**********else====' . $SglUserName, PEAR_LOG_DEBUG); 
                 $res = $oSitebuilder->deleteRvsUserId(PREFIXTRYOUT. $SglUserName);
            }
            return $res;
        }
        
        
        function deleteFileAndFolder($SglUserName)
        {
             SGL::logMessage('==== deleteFileAndFolder in', PEAR_LOG_DEBUG); 
             $oSitebuilder = $this->_connectSitebuilder();
            if (count($SglUserName) && is_array($SglUserName)) {
                  SGL::logMessage('====deleteFileAndFolder**********count====$sglUserName' . $SglUserName, PEAR_LOG_DEBUG); 
                foreach ($SglUserName as $username) {
                     SGL::logMessage('==== deleteFileAndFolder**********if====' . $username, PEAR_LOG_DEBUG); 
                    $resDeleteProject = $oSitebuilder->deleteProject(PREFIXTRYOUT. $username);
                }
            } elseif(isset($SglUserName) && !is_array($SglUserName)) {
                 SGL::logMessage('====deleteFileAndFolder**********else====' . $SglUserName, PEAR_LOG_DEBUG); 
                 $resDeleteProject = $oSitebuilder->deleteProject(PREFIXTRYOUT. $SglUserName);
            }
            return $resDeleteProject;
        }
        
        function _tryoutCreateUserFolder($username)
        {
            SGL::logMessage(' ++++++++++++ ADD USER' . $username, PEAR_LOG_DEBUG);
            $c = SGL_Config::singleton();
            $conf = $c->getAll();
            $tryout = $conf['tryoutlogin']['subdomain_path'];
            $userFolder = $tryout . '/users/' . $username;
            if (!file_exists($userFolder) && $username) {
                mkdir($userFolder, 0755);
                mkdir($userFolder . '/.rvsitebuilder', 0755);
                mkdir($userFolder . '/.rvsitebuilder/projects', 0755);
                mkdir($userFolder . '/.rvsitebuilder/upload', 0755);
                mkdir($userFolder . '/.rvsitebuilder/upload/template', 0755);
            }
        }
        
        function changeUserPreference($input)
        {

        }

        function changeDefaultPreference($input)
        {


        }

}
?>

Copyright 2K16 - 2K18 Indonesian Hacker Rulez