File: //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/tryout/classes/Main2.php
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// WebSite: http://www.rvglobalsoft.com
// Unauthorized copying is strictly forbidden and may result in severe legal action.
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
//
// =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
// This Agreement is a legal contract, which specifies the terms of the license
// and warranty limitation between you and RV Global Soft Co.,Ltd. and RV Site Builder.
// You should carefully read the following terms and conditions before
// installing or using this software. Unless you have a different license
// agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
// indicates your acceptance of the license and warranty limitation terms
// contained in this Agreement. If you do not agree to the terms of this
// Agreement, promptly delete and destroy all copies of the Software.
//
// ===== Grant of License =======
// The Software may only be installed and used on a single host machine.
//
// ===== Disclaimer of Warranty =======
// THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
// WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
// WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE
// AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
// FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE
// ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
// LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
// IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
// CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
// OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
// BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
// NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
// RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
// RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
// BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
// +---------------------------------------------------------------------------+
// | Main.php |
// +---------------------------------------------------------------------------+
// | Author: Apiruk Boonruksa <apiruk@rvglobalsoft.com> |
// | Thiraphat Somcharit <thiraphat@rvglobalsoft.com> |
// +---------------------------------------------------------------------------+
// $Id: Main.php,v 1.1 2006/07/20 02:15:02 thiraphat Exp $
class Main2 extends SGL_Manager
{
/**
* Deletes all files and all path in dest.
*
* @param <string> $dest
* @package rvglobalsoft
* @author Apiruk Boonruksa - 20060629
*/
function unlinkFiles($dest)
{
if ( is_file($dest) ) {
unlink($dest);
} elseif ( is_dir($dest) ) {
$folder = opendir($dest);
while ( $file = readdir($folder) ) {
if ( $file == '.' || $file == '..' ) {
continue;
}
if ( is_dir($dest . '/' . $file) ) {
$this->unlinkFiles($dest . '/' . $file);
rmdir($dest . '/' . $file);
} elseif ( is_link($dest . '/' . $file) ) {
unlink($dest . '/' . $file);
} else {
unlink($dest . '/' . $file);
}
}
closedir($folder);
}
return 1;
}
function isUserExpired(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//$this->oUser = new DA_User();
//$this->resUserLogin = $this->oUser->getUserById($input->usr_id);
//$this->resUserLogin->date_expired
if (!$input->oUserData->date_expired) {
return false;
} elseif ($input->timenow >= strtotime($input->oUserData->date_expired) && trim($input->oUserData->date_expired) != "0000-00-00 00:00:00") {
return true;
} else {
return false;
}
}
function isAutoDeleteExpired(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if ($this->conf['tryoutlogin']['isAutoDeleteExpiredUser'] != 0 && SGL_Session::getRoleId() != SGL_ADMIN) {
return true;
} else {
return false;
}
}
function isWaitingForApproval()
{
if ($this->conf['tryoutlogin']['isAutoApproval'] == 0 || $this->conf['tryoutlogin']['isAutoApproval'] == '') {
return true;
} else {
return false;
}
}
function deleteExpiredAccount(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aExpired = array();
$query = "
SELECT
usr_id
, username
, date_expired
FROM
usr
WHERE
role_id != 0
AND role_id != 1
";
$res = $this->dbh->getAll($query);
foreach ($res as $k => $v) {
if (!$res[$k]->date_expired) {
continue;
} elseif ($input->timenow >= strtotime($res[$k]->date_expired)) {
$aExpired[$res[$k]->usr_id] = $res[$k]->usr_id;
}
}
// over 5 person to delete
if (count($aExpired) >= 5) {
$input->aDelete = $aExpired;
$input->conf = $this->conf;
require_once SGL_MOD_DIR . '/user/classes/UserMgr.php';
$oUser = new UserMgr();
// delete user folder ����� _cmd_delete ����
$input->action = "delete";
$oUser->_cmd_delete($input, $output);
}
}
function dbAddUserExpiredDate($oUser)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$expiredDate = $this->getExpiredDate($oUser);
$userName = $oUser->username;
$query = "UPDATE {$this->conf['table']['user']}
SET `date_expired` = '{$expiredDate}'
WHERE `username` = '{$userName}' ";
$this->dbh->query($query);
return $expiredDate;
}
function updateAccountStatus($usrId, $status)
{
$query = "
UPDATE
{$this->conf['table']['user']}
SET
is_acct_active = '$status'
WHERE
usr_id = '$usrId'
";
$res = $this->dbh->query($query);
}
function getExpiredDate($oUser)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$dateCreated = $oUser->date_created;
$trialDay = $this->conf['tryoutlogin']['expiry_day'];
// ���������˹��ѹ expired �� default ��� 15 �ѹ
if ( trim($trialDay) == "") {
$trialDay = 15;
}
//get Create Date timestamp
$timestampCreate = strtotime($dateCreated);
//get Expired Date timestamp
$timestampExpired = $timestampCreate + (($trialDay) * 86400); //90000); //
// Transform Date Time Format
//$expiredDate = date("Y-m-d G:i:s" , $timestampExpired);
$expiredDate = @strftime("%G-%m-%d %T" , $timestampExpired);
return $expiredDate;
}
function tryoutRenameUserFolder($oldName, $newName)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$homeDir = $this->conf['tryoutlogin']['subdomain_path'];
$oldName = $this->getUniqueNameFromEmail($oldName);
$newName = $this->getUniqueNameFromEmail($newName);
$originalUserFolder = $homeDir . '/users/' . $oldName;
$editUserFolder = $homeDir . '/users/' . $newName;
if ($originalUserFolder != $homeDir && $editUserFolder != $homeDir) {
// User Folder is Exist
if (file_exists($originalUserFolder)) {
if (is_writable($originalUserFolder)) {
return rename($originalUserFolder , $editUserFolder);
} else {
return SGL_String::translate('Please change folder Permission.');
}
} else {
// User Folder is not Exist
mkdir($editUserFolder);
if (file_exists($editUserFolder)) {
return true;
} else {
return $originalUserFolder . SGL_String::translate(' is not exist.');
}
}
}
return false;
}
function tryoutDeleteUserFolder($username)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$uniqueName = $this->getUniqueNameFromEmail($username);
$usrFolderPath = $this->conf['tryoutlogin']['subdomain_path'] . '/users/' . $uniqueName;
if (file_exists($usrFolderPath) && $uniqueName && $usrFolderPath != SGL_MOD_DIR) {
return $this->deleteDir($usrFolderPath);
}
}
function deleteDir($dir)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if (substr($dir, strlen($dir) - 1, 1) != '/') {
$dir .= '/';
if ($handle = opendir($dir)) {
while ($obj = readdir($handle)) {
if ($obj != '.' && $obj != '..') {
if (is_dir($dir . $obj)) {
if (!$this->deleteDir($dir . $obj)) {
return false;
}
} elseif (is_file($dir . $obj)) {
if (!unlink($dir . $obj)) {
return false;
}
}
}
}
closedir($handle);
if (!@rmdir($dir)) {
return false;
}
return true;
}
return false;
}
}
function tryoutCreateUserFolder($username)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$tryout = $this->conf['tryoutlogin']['subdomain_path'];
$uniqueName = $this->getUniqueNameFromEmail($username);
$userFolder = $tryout . '/users/' . $uniqueName;
if (!file_exists($userFolder) && $uniqueName) {
mkdir($userFolder, 0755);
mkdir($userFolder . '/.rvsitebuilder', 0755);
mkdir($userFolder . '/.rvsitebuilder/projects', 0755);
mkdir($userFolder . '/.rvsitebuilder/upload', 0755);
mkdir($userFolder . '/.rvsitebuilder/upload/template', 0755);
}
}
function getUniqueNameFromEmail($email)
{
return $userName = str_replace('@', '-AT-', $email);
}
function billingUrl()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
// Get User Information
$query = "SELECT * FROM {$this->conf['table']['user']} WHERE usr_id = {$_SESSION['uid']} ";
$aUserInfo = $this->dbh->getAll($query);
$aMapField = array('billing_username' => 'username' ,
'billing_firstname' => 'first_name' ,
'billing_lastname' => 'last_name' ,
'billing_address1' => 'addr_1' ,
'billing_address2' => 'addr_2' ,
'billing_address3' => 'addr_3' ,
'billing_city' => 'city' ,
'billing_country_state_province' => 'region' ,
'billing_zipcode' => 'post_code' ,
'billing_country' => 'country' ,
'billing_contact' => 'email' ,
'billing_telephone' => 'telephone' ,
'billing_mobile' => 'mobile' ,
);
$aCountries = SGL::loadRegionList('countries');
$aStates = SGL::loadRegionList('states');
$aUserInfo[0]->country = $aCountries[$aUserInfo[0]->country];
$aUserInfo[0]->region = $aStates[$aUserInfo[0]->region];
$aTryoutConfig = parse_ini_file(SGL_MOD_DIR . '/tryout/tryout_config.ini.php', true);
// Generate Billing Url
if (!empty($aTryoutConfig['billing_url'])) {
$billingUrl = $aTryoutConfig['billing_url'];
$getData = '';
// generate $getData
foreach ($aTryoutConfig as $key=>$value) {
preg_match('/billing_/', $key, $matches, PREG_OFFSET_CAPTURE);
$infoKey = (isset($aMapField[$key])) ? $aMapField[$key] : false;
if ($infoKey) {
// invalid, because $aUserInfo[0]->$infoKey becomes $aUserInfo[0]->""
$info = (isset($aUserInfo[0]->$infoKey)) ? $aUserInfo[0]->$infoKey : false;
}
if (isset($aTryoutConfig['field_' . $key]) && $aTryoutConfig['field_' . $key] == true && $aTryoutConfig[$key] != '' && $info != '') {
if ($getData != '') {
$getData .= '&';
}
$getData .= $aTryoutConfig[$key] . '=' . $info;
}
}
// fixed usr_id demo = 999999999
if ( trim($_SESSION['uid']) == 999999999 ) {
return $this->conf['site']['baseUrl'] . '?demoClickBuyAccount=1';
}
// return $billingUrl + $getData
if ($getData != '') {
$billingUrl = $billingUrl . '?' . $getData;
} else {
// remove end '/' (slash)
if (preg_match("/\/$/", $billingUrl, $match)) {
$billingUrl = substr($billingUrl , 0 , (strlen($billingUrl) - 1));
}
}
return $billingUrl;
}
}
function validateTryoutVersion()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aTryoutConfig = parse_ini_file(SGL_MOD_DIR . '/tryout/tryout_config.ini.php');
if ( trim($aTryoutConfig['owner']) == "root") {
$ownerName = (isset($aTryoutConfig['tryout_root_acc'])) ? $aTryoutConfig['tryout_root_acc'] : "";
} else {
$ownerName = $aTryoutConfig['owner'];
}
if (is_file(SGL_PATH . '/var/tryout_version.txt')) {
$resellerVersion = file(SGL_PATH . '/var/tryout_version.txt');
$resellerVersion[0] = preg_replace('/\r|\n/','',$resellerVersion[0]);
$updateVersion = @file($aTryoutConfig['root_home'] . '/rvsitebuilder/scripts/tryoutlogin/var/tryout_version.txt');
$updateVersion[0] = preg_replace('/\r|\n/','',$updateVersion[0]);
if ($updateVersion != $resellerVersion) {
$input->tryout_update = '<a href="' . $aTryoutConfig['program_url'] . '/whm' . '">';
$input->tryout_update .= SGL_String::translate('You must update Tryout to new versions') . '</a>';
//$input->tryout_update .= $aTryoutConfig['user'] . '</b>';
$input->tryout_update .= ' ' . SGL_String::translate('with user') . " <b>'" . $ownerName . "'</b> " . SGL_String::translate('(no quotes).');
SGL::raiseMsg($input->tryout_update, false, SGL_MESSAGE_ERROR);
}
} else {
$input->tryout_update = '<a href="' . $aTryoutConfig['program_url'] . '/whm' . '">';
$input->tryout_update .= SGL_String::translate('You must update Tryout to new versions') . '</a>';
//$input->tryout_update .= $aTryoutConfig['user'] . '</b>';
$input->tryout_update .= ' ' . SGL_String::translate('with user') . " <b>'" . $ownerName . "'</b> " . SGL_String::translate('(no quotes).');
SGL::raiseMsg($input->tryout_update, false, SGL_MESSAGE_ERROR);
}
}
/**
* replace "\\\\" , %5C , %22 to ""
* replace <a href="{?????}%OUTPUTCONSTAN"> to <a href="%OUTPUTCONSTAN">
* @param unknown_type $value
* @return unknown
*/
function stripContentEmailTemplate($value)
{
//replace all content
$value = str_replace("\\" , "", $value);
$value = str_replace("%5C" , "", $value);
$value = str_replace("%22" , "", $value);
//echo "2value:: " . htmlspecialchars($value) . "<hr>";
//make pattern
$backSlashValue = str_replace("/" , "\/", $value);
$backSlashValue = str_replace("%" , "\%", $backSlashValue);
if (preg_match_all("/\s*href\s*=\s*\"(.*)\%activateUrl\s*\"\s*>/", $backSlashValue, $match)) {
$str = str_replace("\\" , "", $match[1][0]);
$value = str_replace($str , "", $value);
} elseif (preg_match_all("/\s*href\s*=\s*\"(.*)\%siteUrl\s*\"\s*>/", $backSlashValue, $match)) {
$strPattern = str_replace("\\" , "", $match[1][0]);
$value = str_replace($strPattern , "", $value);
}
//echo "3value:: " . htmlspecialchars($value) . "<hr>";
return $value;
}
/**
* update admin user , admin password to file SGL_VAR_DIR/autosetting.ini.php
*
* @param <string> $userName
* @param <string> $userPassword
*/
function tryoutUpdateAdminUserPassWord($userName = '', $userPassword = '')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$dest = SGL_VAR_DIR . '/autosetting.ini.php';
if( is_file($dest) && is_writable($dest)) {
$aConfig = parse_ini_file($dest, true);
//reset user to write
if ($userName != '') {
$aConfig['adminEmail'] = $userName;
$aConfig['adminUserName'] = $userName;
}
//reset password to write
if ($userPassword != '') {
$aConfig['adminPassword'] = $userPassword;
}
require_once 'Config.php';
$c = new Config();
$c->parseConfig($aConfig, 'phparray');
$result = $c->writeConfig($dest, 'inifile');
SGL_Util::makeIniUnreadable($dest);
}
return true;
}
}
?>