Вход Регистрация
Файл: billing/_rootbill/_renew.inc.php
Строк: 438
<?
    $hostMonths
=@intval($hostMonths);
    
$host_id=@intval($host_id);
    
$domainMonths=@intval($domainMonths);

    if (
$sub == 'renew') {
        if (!
$hostMonths) {$error=$_lang[RenewErrorNoSrok];}
        else {
            
$order=@mysql_query("select * from orders where id='$host_id' and uid='".$_SESSION["userId"]."'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
            if (
mysql_num_rows($order) == 0) {$error=$_lang[ErrorBadId];}
            else {
                
$order=mysql_fetch_object($order);
                
$orderAddons=split(":x:"$order->addons);

                
$addonsCost=0;
                
$addonsToSave="";
                
$addonsToSaveText="";
                while (list(
$k,$v) = @each($orderAddons)) {
                    if (
$v) {
                        
$oneAddon GetAddonById($v);
                        if (
$oneAddon->id) {
                            
$addonSpecCost GetSpecialCost($_SESSION['userId'],"addon",$oneAddon->id);

                            if (
$addonsToSaveText) {
                                
$addonsToSaveText $addonsToSaveText.", ".$oneAddon->name;
                            } else {
                                
$addonsToSaveText $oneAddon->name;
                            }

                            if (
$addonSpecCost) {
                                
$addonsCost += $addonSpecCost["cost2"]*$hostMonths;
                            } else {
                                
$addonsCost += $oneAddon->cost_monthly*$hostMonths;
                            }
                        }
                    }
                }
                if (!
$addonsToSaveText) { $addonsToSaveText=$_yes[0]; }
                
$addonsCost=round($addonsCost,2);

                
$tarif=@mysql_query("select * from tarifs where id='$order->tarif'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
                
$tarif=mysql_fetch_object($tarif);

                
$tarifSpecCost GetSpecialCost($_SESSION['userId'],"tarif",$tarif->id);
                if (
$tarifSpecCost) {
                    
$hostCost=$tarifSpecCost["cost2"]*$hostMonths;
                } else {
                    
$hostCost=$tarif->cost*$hostMonths;
                }

                
$tsroki=@mysql_query("select discount from tarifs_sroki where tarif_id='$order->tarif' and months='$hostMonths'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
                
$tsroki=mysql_fetch_object($tsroki);
                
$srokDiscount=$tsroki->discount;
                
$orderDiscount=$order->discount;
                
$host=$hostCost-($hostCost/100)*($srokDiscount+$orderDiscount);
                if (
$orderDiscount == '100') {$host 0;}
                
$host=round($host,2);

                
$domainCost=0;
                
$domain_renew=0;
                if (
$order->domain_reg == "1" and $domainMonths) {
                    
$domain_renew=1;

                    
$order_domain=GetDomainByDomain($order->domain);
                    
$zone=GetZoneById($order_domain->zone_id);

                    
$domSpecCost GetSpecialCost($_SESSION['userId'],"zone",$zone->id);
                    if (
$domSpecCost) {
                        
$domainCost=$domSpecCost["cost2"] * ($domainMonths/12);
                    } else {
                        
$domainCost=$zone->renew_if_host * ($domainMonths/12);
                    }

                    
$domainDiscount $order_domain->discount;
                    
$domainCost $domainCost - ($domainCost/100)*$domainDiscount;
                    if (
$domainDiscount == '100') {$domainCost 0;}

#                    $tfreedomains=@mysql_query("select * from tarifs_freedomains where tarif_id='$order->tarif' and zone='$zone->zone' and hostmonths='$hostMonths'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
#                    if (mysql_num_rows($tfreedomains) > 0) {$domainFree=1;} else {$domainFree=0;}
#                    if ($domainFree) {$domainCost=0;}
                
} else {
                    
$domainMonths 0;
                }

                if (
$order->domain_reg == "1") {
                    
$newreg=$_renew[$domain_renew];
                } else {
                    
$newreg='-';
                }
                
$domainCost=round($domainCost,2);

                if (
$promocode) {
                    
$coupon GetCoupon("promo",$promocode);
                    if (
IsCanUseCoupon($coupon->id,$_SESSION["userId"])) {
                        
$promoId $coupon->id;
                        
$promoSkidka $coupon->value;
                        
$promoTXT ", promo-code $promocode";
                    }
                }

                if (
$promoSkidka) {
                    if (
$host 0) { $host round($host-$host/100*$promoSkidka,2); }
                    if (
$domainCost 0) { $domainCost round($domainCost-$domainCost/100*$promoSkidka,2); }
                    if (
$addonsCost 0) { $addonsCost round($addonsCost-$addonsCost/100*$promoSkidka,2); }
                }
                
                @
mysql_query("insert into bills (uid,host_id,domain_id,host_srok,domain_srok,money_host,money_domain,money_addons,created,renew) values('".$_SESSION['userId']."','$order->id','$order_domain->id','$hostMonths','$domainMonths','$host','$domainCost','$addonsCost',NOW(),'1')") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
                
$bill_id=mysql_insert_id();
                
$sid=sprintf("%04d"$bill_id);

                
$tpl=GetTpl("email_touser_".$tarif->vid."_renew"$_SESSION["userLang"]);
                
$subject $tpl[subject]; $template $tpl[template];

                     
addUserLog($_SESSION['userId'], "renew""$tarif->name$hostMonths ".$_lang[OrderSokraschenieMonth].", $order->domain [$newreg (".($domainMonths/12)." ".$_lang[OrderSokraschenieGod].")]$promoTXT");
                
AddUsedByToCoupon($promoId,$_SESSION["userId"],$bill_id);

                if (
$subject and $template) {
                    
$attachPDFtoBill GetSetting("attachPDFtoBill");
                    if ((
$attachPDFtoBill and $_SESSION["userAttachPDFtoBill"] != "2") or (!$attachPDFtoBill and $_SESSION["userAttachPDFtoBill"] == "1")) {
                        
$profile=GetUserProfileByUserId($_SESSION['userId']);

                        if (
$profile->org == "3" and $profile->firma and $profile->phone) {
                            
$attachFile createFaktura(''$bill_id2);
                        } else if (
$profile->org == "2" and $profile->name and $profile->surname and $profile->phone) {
                            
$attachFile createFaktura(''$bill_id2);
                        } else if (
$profile->org == "1") {
                            
$attachFile createKvitanciya(''$bill_id2);
                        }
                        if (!
$attachFile) {$attachFile="";}
                    }

                    
$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('{tarif}',$tarif->name,$template);
                         
$template str_replace('{srok}',$hostMonths,$template);
                         
$template str_replace('{domain}',$order->domain,$template);
                         
$template str_replace('{addons}',$addonsToSaveText,$template);
                         
$template str_replace('{newreg}',$newreg,$template);
                         
$template str_replace('{login}',$_SESSION["userLogin"],$template);
                         
$template str_replace('{password}',"******",$template);
                         
$template str_replace('{schet}',$sid,$template);
                         
$template str_replace('{hostcost}',round($host*CURK,2)." ".CURS,$template);
                         
$template str_replace('{domaincost}',round($domainCost*CURK,2)." ".CURS,$template);
                         
$template str_replace('{addonscost}',round($addonsCost*CURK,2)." ".CURS,$template);
                         
$template str_replace('{cost}',round(($host+$domainCost+$addonsCost)*CURK,2)." ".CURS,$template);
                         
$template str_replace('{userid}',$_SESSION['userId'],$template);

                    
WriteMailLog($subject,$template,$_SESSION["userId"]);
                    
sendmail($_SESSION["userEmail"],$company_name,$manager_email,$subject,$template,$attachFile);
                    
sendmail($_SESSION["userEmail2"],$company_name,$manager_email,$subject,$template,$attachFile);

                    
$admEmails=GetAdminEmailsWhereTrueParam("sendneworder");
                    if (
count($admEmails) > 0) {
                        
WriteMailLog("Duplicate: ".$subject,$template);
                    }
                    
sendmail($manager_email,'',$manager_email,"Duplicate: ".$subject,$template,$attachFile);

                    @
unlink($attachFile);
                }

                
Header("Location: billing.php?do=pay&fromreg=1&id=$bill_id");

                
mclose();
                exit;
            }
        }
    }

    
$r=@mysql_query("select * from orders where id='$host_id'") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
    if (
mysql_num_rows($r) == 0) {$error=$_lang[ErrorBadId];}

    
_head('utf-8',$_lang[RenewTitle]);
    if (
$error) {print $_lang[Error].": $error<BR><BR>";}

    if (
mysql_num_rows($r) > 0) {
        
$r=mysql_fetch_object($r);
        
$tarif=GetTarifById($r->tarif);
        
$tarif_sroki=@mysql_query("select * from tarifs_sroki where tarif_id='$tarif->id' order by months") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());

        
?>
        <center>
        <form method=post>
        <input type=hidden name=do value=<?=$do?>>
        <input type=hidden name=sub value=renew>
        <input type=hidden name=host_id value=<?=$host_id?>>

        <table class='rpTableBlank' border=1>
        <tr><th align=right><?=$_lang[RenewDomain]?>:&nbsp;</th><td><input class=input type=text name=domain value="<?=$r->domain?>" readonly></td></tr>
        <?
        
if ($r->domain_reg == "1") {
            
$minsrok=@mysql_query("select t1.minsrok_renew from zones as t1, orders_domains as t2, orders as t3 where t1.id=t2.zone_id and t2.domain=t3.domain") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
            
$minsrok=mysql_fetch_object($minsrok);
            
$minsrok=$minsrok->minsrok_renew;
            
?>
            <tr><th align=right><?=$_lang[RenewNaSrok]?>:<BR><BR></th><Td><select class=input name=domainMonths><option value=0><?=$_lang[DomainWithoutRenewMin]?></option><option value=<?=$minsrok?>><?=($minsrok/12)?> <?=$_lang[RenewYear]?></option>
            </select><BR><BR></td></tr>
            <?
        
}

        
$tarifSpecCost GetSpecialCost($_SESSION['userId'],"tarif",$tarif->id);
        if (
$tarifSpecCost) {
            
$tarif->cost=$tarifSpecCost["cost2"];
        }

        
?>
        <tr><th align=right><?=$_lang[RenewTarif]?>:&nbsp;</th><td><input class=input type=radio name=tarif_id value=<?=$tarif->id?> checked><?=$tarif->name?> (<?=round($tarif->cost*CURK,2)?> <?=CURS?>/<?=$_lang[OrderSokraschenieMonth]?>)</td></tr>
        <tr><th align=right><?=$_lang[RenewNaSrok]?>:&nbsp;</th><td><select class=input name=hostMonths><option></option>
        <?
        
if (mysql_num_rows($tarif_sroki) > 0) {
            while (
$srok mysql_fetch_object($tarif_sroki)) {
                if (
$srok->months == $hostMonths) {$selected='selected';} else {$selected='';}
                if (
$srok->discount) {$skidka=" (скидка $srok->discount%)";} else {$skidka="";}
                print 
"<option value=$srok->months $selected>$srok->months ".$_lang[OrderSokraschenieMonth].$skidka."</option>";
            }
        }
        
?>
        </select></td></tr>
        <tr><th align=right valign=top><?=$_lang[RenewAddons]?>:&nbsp;</th><td>
        <?
                $orderAddons 
split(":x:"$r->addons);
                while (list(
$k,$v) = @each($orderAddons)) {
                        if (
$v) {
                                
$oneAddon=GetAddonById($v);
                if (
$oneAddon->id) {
#                if ($oneAddon->cost_monthly > 0 or $oneAddon->isOs or $oneAddon->isPanel) {
                    
$addonSpecCost GetSpecialCost($_SESSION['userId'],"addon",$oneAddon->id);
                    if (
$addonSpecCost) {
                        
$oneAddon->cost_monthly $addonSpecCost["cost2"];
                    }

                                    if (
$lastaddon) {$orderAddonsTxt .= "<BR>";}
                                    
$orderAddonsTxt .= "$oneAddon->name (".round($oneAddon->cost_monthly*CURK,2)." ".CURS."/".$_lang[OrderSokraschenieMonth].")";
                                    
$lastaddon=$oneAddon->textid;
#                }
                
}
                        }
                }
        if (!
$orderAddonsTxt) {$orderAddonsTxt=$_yes[0];}
        print 
$orderAddonsTxt;
        
?>
        </td></tr>
        <? if (GetCouponActiveCount("promo") > 0) { ?>
        <tr><th align=right><?=$_lang[OrderPromoCode]?>:&nbsp;</th><td><input class=input type=text name=promocode value="<?=$promocode?>"></td></tr>
        <? ?>
    
        <tr><th colspan=2 align=center><input class=button type=submit value="<?=$_lang[RenewRenew]?>"></th></tr>
        </table>
        </center>
        <?
    
}
    
_foot('utf-8');
?>
Онлайн: 1
Реклама