Файл: billing/_rootbill/_renewshop.inc.php
Строк: 160
<?
    $shop_id=@intval($shop_id);
    $shopMonths=@intval($shopMonths);
    if ($sub == "renew") {
        $r=GetOrderShopById($shop_id,$_SESSION["userId"]);
        if ($r->id) {
            $shopItem=GetShopItemById($r->item);
            $shopCost = $shopItem->cost;
            $shopSpecCost = GetSpecialCost($_SESSION['userId'],"shop",$shopItem->id);
            if ($shopSpecCost) {
                $shopCost = $shopSpecCost["cost1"];
            }
            if ($shopItem->costtype == "month") { $shopCost=$shopCost * $shopMonths; }
            else if ($shopItem->costtype == "year") { $shopCost=$shopCost * ($shopMonths/12); }
            $shopDiscount = $r->discount;
            $shopCost = $shopCost - ($shopCost/100)*$shopDiscount;
            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 ($shopCost > 0) { $shopCost = round($shopCost-$shopCost/100*$promoSkidka,2); }
            }
            @mysql_query("insert into bills (uid,shop_id,shop_srok,money_shop,created,renew) values('".$_SESSION['userId']."','$shop_id','$shopMonths','$shopCost',NOW(),'1')") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
            $bill_id=mysql_insert_id();
            $sid=sprintf("%04d", $bill_id);
                 addUserLog($_SESSION['userId'], "renewshop", "$shopItem->name, ".$shopMonths." ".$_lang[OrderSokraschenieMonth].$promoTXT);
            AddUsedByToCoupon($promoId,$_SESSION["userId"],$bill_id);
            $tpl=GetTpl('email_touser_shop_renew', $_SESSION["userLang"]);
            $subject = $tpl[subject]; $template = $tpl[template];
            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_id, 2);
                    } else if ($profile->org == "2" and $profile->name and $profile->surname and $profile->phone) {
                        $attachFile = createFaktura('', $bill_id, 2);
                    } else if ($profile->org == "1") {
                        $attachFile = createKvitanciya('', $bill_id, 2);
                    }
                    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('{item}',$shopItem->name,$template);
                     $template = str_replace('{srok}',$shopMonths,$template);
                     $template = str_replace('{login}',$_SESSION["userLogin"],$template);
                     $template = str_replace('{password}',"******",$template);
                     $template = str_replace('{schet}',$sid,$template);
                     $template = str_replace('{itemcost}',round($shopCost*CURK,2)." ".CURS,$template);
                     $template = str_replace('{cost}',round($shopCost*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);
            }
            mclose();
            Header("Location: billing.php?do=pay&fromreg=1&id=$bill_id");
            exit;
        }
    }
    $r=GetOrderShopById($shop_id,$_SESSION["userId"]);
    if (!$r->id) {$error=$_lang[ErrorBadId];}
    _head('utf-8',$_lang[RenewTitleShop]);
    print "<H1 class=pagetitle>".$_lang[RenewTitleShop]."</H1><hr class=hr>";
    if ($error) {print $_lang[Error].": $error<BR><BR>";}
    if ($r->id) {
        $shopItem=GetShopItemById($r->item);
        ?>
        <form method=post>
        <input type=hidden name=do value=<?=$do?>>
        <input type=hidden name=sub value=renew>
        <input type=hidden name=shop_id value=<?=$shop_id?>>
        <table class='rpTableBlank' border=0>
        <tr><td align=right><?=$_lang[RenewShop]?>: </td><td><?=$shopItem->name?></td></tr>
        <tr><td align=right><?=$_lang[RenewNaSrok]?>:</td><Td><select class=input name=shopMonths>
        <?
        $m = $shopItem->minsrok;
        while ($m <= $shopItem->maxsrok) {
            if ($shopMonths == $m) {$monthCheck='selected';} else {$monthCheck='';}
            if ($shopItem->costtype == "month") {$msrok = $m." ".$_lang[OrderSokraschenieMonth]; }
            else if ($shopItem->costtype == "year") {$msrok = ($m/12)." ".$_lang[OrderSokraschenieGod];}
            print "<option value=$m $monthCheck> $msrok</option>";
            if ($shopItem->costtype == "month") {$m = $m+1;}
            else if ($shopItem->costtype == "year") {$m = $m+12;}
        }
        ?>
        </select></td></tr>
        <? if (GetCouponActiveCount("promo") > 0) { ?>
        <tr><td align=right><?=$_lang[OrderPromoCode]?>: </td><td><input class=input type=text name=promocode value="<?=$promocode?>"></td></tr>
        <? } ?>
        <tr><td colspan=2 align=center><BR><input class=button type=submit value=<?=$_lang[RenewRenew]?>></td></tr>
        </table>
        <?
    }
    _foot('utf-8');
?>