Вход Регистрация
Файл: billing/cron.php
Строк: 264
<?php
 
require_once( "./_rootconfig.php" );
mconnect( );
@
set_time_limit( 0 );
if ( !( 
$orders = @mysql_query( "select * from orders where startdate <> '0000-00-00' AND TO_DAYS(todate)-TO_DAYS(NOW())=-1" ) ) )
{
    exit( 
mysql_error( ) );
}
if ( 
0 < mysql_num_rows( $orders ) )
{
    while ( 
$order = mysql_fetch_object( $orders ) )
    {
        
$user = getuserbyid( $order->uid );
        
$tarif = gettarifbyid( $order->tarif );
        
$template = gettpl( "notify_manager_end" );
        
$company_name = getsetting( "company_name" );
        
$company_url = getsetting( "company_url" );
        
$manager_email = getsetting( "manager_email" );
        
$template = str_replace( "{company_name}", $company_name, $template );
        
$template = str_replace( "{company_url}", $company_url, $template );
        
$template = str_replace( "{login}", $user->login, $template );
        
$template = str_replace( "{tarif}", $tarif->name, $template );
        
$template = str_replace( "{domain}", $order->domain, $template );
        
sendmail( $manager_email, $manager_email, "Уведомление об окончании оплаченного периода", $template );
        if ( 
$order->dalogin )
        {
            if ( 
$tarif->autosuspend )
            {
                if ( 
dasuspenduser( $order->id, 1, 1 ) )
                {
                    
$error = $error."Аккаунт {$order->dalogin} автоматически остановлен в DA.rn";
                }
                else
                {
                    
$error = $error."Аккаунт {$order->dalogin} не остановлен в DA. Сделайте это вручную.rn";
                }
            }
            else
            {
                
$error = $error."Аккаунт {$order->dalogin} не остановлен в DA, т.к. эта возможность отключена для тарифного плана.rn";
            }
        }
        else if ( 
$order->cpanellogin )
        {
            if ( 
$tarif->autosuspendcpanel )
            {
                if ( 
cpanelsuspenduser( $order->id, 1, 1 ) )
                {
                    
$error = $error."Аккаунт {$order->cpanellogin} автоматически остановлен в cPanel.rn";
                }
                else
                {
                    
$error = $error."Аккаунт {$order->cpanellogin} не остановлен в cPanel. Сделайте это вручную.rn";
                }
            }
            else
            {
                
$error = $error."Аккаунт {$order->dalogin} не остановлен в cPanel, т.к. эта возможность отключена для тарифного плана.rn";
            }
        }
        else
        {
            
$error = $error."Аккаунт для заказа ID #{$order->id} ({$order->domain}) не остановлен автоматически, т.к. не указан логин в DA/cPanel.rn";
        }
    }
    if ( 
$error )
    {
        
$errormsg = "Внимание! Аккаунты, не остановленные автоматически в DA/cPanel, необходимо остановить вручную.rnrn".$error;
        
$manager_email = getsetting( "manager_email" );
        
sendmail( $manager_email, $manager_email, "Cron: отчет о остановке аккаунтов (окончание оплаченного периода)", $errormsg );
    }
}
if ( !( 
$orders = @mysql_query( "select * from orders_domains where startdate <> '0000-00-00' AND TO_DAYS(todate)-TO_DAYS(NOW())=0" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $orders ) ) || !( $order = mysql_fetch_object( $orders ) ) )
{
    
$user = getuserbyid( $order->uid );
    
$template = gettpl( "notify_manager_end_domain" );
    
$company_name = getsetting( "company_name" );
    
$company_url = getsetting( "company_url" );
    
$manager_email = getsetting( "manager_email" );
    
$template = str_replace( "{company_name}", $company_name, $template );
    
$template = str_replace( "{company_url}", $company_url, $template );
    
$template = str_replace( "{login}", $user->login, $template );
    
$template = str_replace( "{domain}", $order->domain, $template );
    
sendmail( $manager_email, $manager_email, "Уведомление об окончании оплаченного периода (домен)", $template );
}
if ( !( 
$bills = @mysql_query( "select * from bills where payed='0000-00-00' AND status='0' AND ((TO_DAYS(NOW())-TO_DAYS(created)=3) OR (TO_DAYS(NOW())-TO_DAYS(created)=5) OR (TO_DAYS(NOW())-TO_DAYS(created)=10))" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $bills ) ) || !( $bill = mysql_fetch_object( $bills ) ) )
{
    
$user = getuserbyid( $bill->uid );
    
$template = gettpl( "remind_notpayed_bill" );
    
$company_name = getsetting( "company_name" );
    
$company_url = getsetting( "company_url" );
    
$billing_url = getsetting( "billing_url" );
    
$support_url = getsetting( "support_url" );
    
$manager_email = getsetting( "manager_email" );
    
$template = str_replace( "{company_name}", $company_name, $template );
    
$template = str_replace( "{company_url}", $company_url, $template );
    
$template = str_replace( "{billing_url}", $billing_url, $template );
    
$template = str_replace( "{support_url}", $support_url, $template );
    
$template = str_replace( "{bill_date}", mydate( $bill->created ), $template );
    
$template = str_replace( "{login}", $user->login, $template );
    
$template = str_replace( "{password}", "******", $template );
    
$template = str_replace( "{schet}", sprintf( "%04d", $bill->id ), $template );
    
$template = str_replace( "{hostcost}", $bill->money_host, $template );
    
$template = str_replace( "{domaincost}", $bill->money_domain, $template );
    
$template = str_replace( "{addonscost}", $bill->money_addons, $template );
    
$template = str_replace( "{cost}", $bill->money_host + $bill->money_domain + $bill->money_addons, $template );
    
sendmail( $user->email, $manager_email, "Неоплаченный счет №".sprintf( "%04d", $bill->id )." от ".mydate( $bill->created ), $template );
}
if ( !( 
$orders = @mysql_query( "select *,TO_DAYS(todate)-TO_DAYS(NOW()) as leftdays from orders where startdate <> '0000-00-00' AND ((TO_DAYS(todate)-TO_DAYS(NOW())=1) OR (TO_DAYS(todate)-TO_DAYS(NOW())=3) OR (TO_DAYS(todate)-TO_DAYS(NOW())=5))" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $orders ) ) || !( $order = mysql_fetch_object( $orders ) ) )
{
    
$user = getuserbyid( $order->uid );
    
$tarif = gettarifbyid( $order->tarif );
    
$template = gettpl( "remind_end" );
    
$company_name = getsetting( "company_name" );
    
$company_url = getsetting( "company_url" );
    
$billing_url = getsetting( "billing_url" );
    
$manager_email = getsetting( "manager_email" );
    
$template = str_replace( "{company_name}", $company_name, $template );
    
$template = str_replace( "{company_url}", $company_url, $template );
    
$template = str_replace( "{billing_url}", $billing_url, $template );
    
$template = str_replace( "{login}", $user->login, $template );
    
$template = str_replace( "{password}", "******", $template );
    
$template = str_replace( "{tarif}", $tarif->name, $template );
    
$template = str_replace( "{domain}", $order->domain, $template );
    
$template = str_replace( "{days}", $order->leftdays, $template );
    
sendmail( $user->email, $manager_email, "Напоминание об окончании оплаченного периода", $template );
}
if ( !( 
$orders = @mysql_query( "select *,TO_DAYS(todate)-TO_DAYS(NOW()) as leftdays from orders_domains where startdate <> '0000-00-00' AND ((TO_DAYS(todate)-TO_DAYS(NOW())=1) OR (TO_DAYS(todate)-TO_DAYS(NOW())=5) OR (TO_DAYS(todate)-TO_DAYS(NOW())=10) or (TO_DAYS(todate)-TO_DAYS(NOW())=30))" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $orders ) ) || !( $order = mysql_fetch_object( $orders ) ) )
{
    
$user = getuserbyid( $order->uid );
    
$tarif = gettarifbyid( $order->tarif );
    
$template = gettpl( "remind_end_domain" );
    
$company_name = getsetting( "company_name" );
    
$company_url = getsetting( "company_url" );
    
$billing_url = getsetting( "billing_url" );
    
$manager_email = getsetting( "manager_email" );
    
$template = str_replace( "{company_name}", $company_name, $template );
    
$template = str_replace( "{company_url}", $company_url, $template );
    
$template = str_replace( "{billing_url}", $billing_url, $template );
    
$template = str_replace( "{login}", $user->login, $template );
    
$template = str_replace( "{password}", "******", $template );
    
$template = str_replace( "{domain}", $order->domain, $template );
    
$template = str_replace( "{days}", $order->leftdays, $template );
    
sendmail( $user->email, $manager_email, "Напоминание об окончании оплаченного периода", $template );
}
if ( !( 
$bills = @mysql_query( "select * from bills where payed='0000-00-00' AND status='0' AND TO_DAYS(NOW())-TO_DAYS(created)>20" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $bills ) ) || !( $bill = mysql_fetch_object( $bills ) ) )
{
    if ( !@
mysql_query( @"delete from bills where id='{$bill->id}'" ) )
    {
        exit( 
mysql_error( ) );
    }
}
if ( !( 
$orders = @mysql_query( "select * from orders where startdate='0000-00-00' and status='0'" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $orders ) ) || !( $order = mysql_fetch_object( $orders ) ) )
{
    if ( !( 
$bills = @mysql_query( @"select * from bills where host_id='{$order->id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( !@
mysql_query( @"delete from orders where id='{$order->id}'" ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( !@
mysql_query( @"delete from orders_domains where host_id='{$order->id}'" ) )
    {
        exit( 
mysql_error( ) );
    }
}
if ( !( 
$orders = @mysql_query( "select * from orders_domains where startdate='0000-00-00' and status='0'" ) ) )
{
    exit( 
mysql_error( ) );
}
while ( !( 
0 < mysql_num_rows( $orders ) ) || !( $order = mysql_fetch_object( $orders ) ) )
{
    if ( !( 
$bills = @mysql_query( @"select * from bills where domain_id='{$order->id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( !@
mysql_query( @"delete from orders_domains where id='{$order->id}'" ) )
    {
        exit( 
mysql_error( ) );
    }
}
if ( !( 
$orders = @mysql_query( "select * from orders where startdate <> '0000-00-00' AND (TO_DAYS(todate)-TO_DAYS(NOW())<=-60)" ) ) )
{
    exit( 
mysql_error( ) );
}
if ( 
0 < mysql_num_rows( $orders ) )
{
    while ( 
$order = mysql_fetch_object( $orders ) )
    {
        if ( 
$order->domain_reg )
        {
            
$domain = getdomainbydomain( "{$order->domain}" );
            if ( !@
mysql_query( @"update orders_domains set host_id='0' where host_id='{$order->id}'" ) )
            {
                exit( 
mysql_error( ) );
            }
            if ( !@
mysql_query( @"update bills set host_id='0', host_srok='0', money_host='0', money_addons='0' where host_id='{$order->id}' and domain_id='{$domain->id}'" ) )
            {
                exit( 
mysql_error( ) );
            }
        }
        if ( 
$order->dalogin )
        {
            
$tarif = gettarifbyid( $order->tarif );
            if ( 
$tarif->autodelete )
            {
                if ( 
dadeleteuser( $order->id, 0 ) )
                {
                    
$error = $error."Аккаунт {$order->dalogin} автоматически удален в DA.";
                }
                else
                {
                    
$error = $error."Аккаунт {$order->dalogin} не удален в DA. Сделайте это вручную.";
                }
            }
            else
            {
                
$error = $error."Аккаунт {$order->dalogin} не  удалён в DA, т.к. эта возможность отключена для тарифного плана.";
            }
        }
        else if ( 
$order->cpanellogin )
        {
            
$tarif = gettarifbyid( $order->tarif );
            if ( 
$tarif->autodeletecpanel )
            {
                if ( 
cpaneldeleteuser( $order->id, 0 ) )
                {
                    
$error = $error."Аккаунт {$order->cpanellogin} автоматически удален в cPanel.";
                }
                else
                {
                    
$error = $error."Аккаунт {$order->cpanellogin} не удален в cPanel. Сделайте это вручную.";
                }
            }
            else
            {
                
$error = $error."Аккаунт {$order->cpanellogin} не  удалён в cPanel, т.к. эта возможность отключена для тарифного плана.";
            }
        }
        else
        {
            
$error = $error."Аккаунт для заказа ID #{$order->id} ({$order->domain}) не был удалён автоматически, т.к. не указан логин в DA/cPanel.";
        }
        
$error = $error." Заказ и все счета, относящиеся к нему, удалены. n";
        if ( !@
mysql_query( @"delete from bills where host_id='{$order->id}'" ) )
        {
            exit( 
mysql_error( ) );
        }
        if ( !@
mysql_query( @"delete from orders where id='{$order->id}'" ) )
        {
            exit( 
mysql_error( ) );
        }
    }
    if ( 
$error )
    {
        
$errormsg = "Внимание! Аккаунты, не удаленные автоматически в DA/cPanel, необходимо удалить вручную.nn".$error;
        
$manager_email = getsetting( "manager_email" );
        
sendmail( $manager_email, $manager_email, "Cron: отчет о удалении заказов, истекших 60 дней назад", $errormsg );
    }
}
mclose( );
?>
Онлайн: 3
Реклама