Удобный онлайн генератор паролей

Билеты с QR кодом



Задача: при оплате высылать билеты с QR кодом, в котором будет зашита ссылка на билет. И заодно письмо аффилиату, что его заказ оплачен
1. понадобятся 2 библиотеки, которые положила в папку /tools/
2. обработчики в init.php
const SITE_TICKET = "tc";
const TICKET_INFO_URL = "http://nikaverro.ru/ticket/info/";
const QRCODE_DIR_REL = "http://nikaverro.ru/upload/qrcode/";
const QRCODE_DIR_ABS = "/upload/qrcode/";

AddEventHandler("sale", "OnSalePayOrder", "CustomOnSalePayOrder");
function CustomOnSalePayOrder($id,$bPay){
   //Флаг оплаты (Y - выставление оплаты, N - снятие оплаты)
    
   if(($bPay == "Y")&& CModule::IncludeModule("sale") && CModule::IncludeModule("iblock")){        
        $arTickets = GetTicketsByOrderId($id); //функция, которая возвращает билеты (элементы инфоблока) по заказу
        if(count($arTickets)>0){
            $arFilter = Array(
               "ID" => $id, 
               "CANCELED"=>"N"  
            );
            $arSelect = array("ID","USER_ID",'PROPERTY_VAL_BY_CODE_NAME','PROPERTY_VAL_BY_CODE_EMAIL','PROPERTY_VAL_BY_CODE_PHONE', "AFFILIATE_ID","PRICE");
            $db_sales = CSaleOrder::GetList(array("DATE_INSERT" => "ASC"), $arFilter,false,false,$arSelect);               
            
            if ($arOrder = $db_sales->Fetch()){                                 
                $html = GenerateHTMLTicket($arTickets);                
                SendEmailWithTickets($arOrder["PROPERTY_VAL_BY_CODE_EMAIL"], $html);  
                if(($arOrder["AFFILIATE_ID"]!="") && ($arOrder["PRICE"]>0) ){
                    $dbAffiliate = CSaleAffiliate::GetList(array(), array("ID" => $arOrder["AFFILIATE_ID"]), false, false, array("USER_ID"));
                    if ($arAffiliate = $dbAffiliate->Fetch()) {                        
                        $rsUser = CUser::GetByID($arAffiliate["USER_ID"]);
                        $arUser = $rsUser->Fetch();
                        if($arUser["EMAIL"]!=""){
                            SendEmailToAffiliate($arUser["EMAIL"],$arOrder["PRICE"]);
                        }
                    }
                }                                  
            } 
            //выставляем у билетов статус "действительны"
            foreach ($arTickets as $arTicket) {
                CIBlockElement::SetPropertyValuesEx($arTicket["ID"], false, array(PROPERTY_TICKET_STATUS => TICKET_STATUS_VALID));
            }
        }    
    }
}

function GenerateHTMLTicket($arTickets){ 
    AddMessage2Log('GenerateHTMLTicket');  
    require_once($_SERVER["DOCUMENT_ROOT"].'/tools/phpqrcode/qrlib.php');
   
    ob_start();
    // define some HTML content with style
    ?>
    <table width="600" align="center" cellpadding="0" cellspacing="15" bgcolor="ffffff" style="border: 1px solid #cfcece;">  
        <tbody>
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="0" align="center" bgcolor="#329DC5">  
                       <tbody>
                            <tr>
                                <td></td>  
                               <td width="375" valign="top" colspan="3">  
                                  <h4 style="margin:20px;font-size: 18px;font-family: Arial, Helvetica, sans-serif;color:#fff;float:right;vertical-align:middle;line-height:70px;">Вероника Малышева</h4>  
                               </td>  
                           </tr>  
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>  
                <td>  
                    <table cellpadding="0" cellspacing="0" align="center">  
                        <tbody>
                            <tr>  
                                <td width="570">                                    
                                    <table border="1" cellspacing="0" cellpadding="5" style="width:100%;">
                                        <tbody>
                                            <?
                                            foreach($arTickets as $arTicket):?>                                                                                                
                                                <tr>
                                                   <td>Билет №<?=$arTicket["ID"]?> <?=$arTicket["AGE_NAME"]?><br></td> 
                                                    <td>
                                                        <p style="font-size: 12px;color: #444444 !important;font-family: Arial, Helvetica, sans-serif;line-height: 1.5;">
                                                            <?=$arTicket["PREVIEW_TEXT"]?>
                                                        </p>
                                                    </td>    
                                                    
                                                    <td>
                                                        <?$urlTicket = TICKET_INFO_URL.'?token='.$arTicket["CODE"];
                                                        // save PNG codes to server                                                               
                                                        $fileName = 'file_'.md5($urlTicket).'.png';                                                                
                                                        $pngAbsoluteFilePath = $_SERVER["DOCUMENT_ROOT"].QRCODE_DIR_ABS.$fileName;
                                                        $urlRelativeFilePath = QRCODE_DIR_REL.$fileName;                                                                
                                                        // generating
                                                        if (!file_exists($pngAbsoluteFilePath)) {
                                                            QRcode::png($urlTicket, $pngAbsoluteFilePath);                                                                   
                                                        }

                                                        ?>
                                                        <img src="<?=$urlRelativeFilePath?>" />
                                                    </td>
                                                </tr>
                                            <?endforeach;?>                                                                              
                                        </tbody>
                                    </table> 
                                    <p></p>
                                </td>  
                            </tr>  
                        </tbody>
                    </table>  
                </td>  
            </tr>  
        </tbody>
    </table>      

    <?
    $html = ob_get_clean();
    return $html;
    
}

function SendEmailWithTickets($emailTo,$html){
    if(($emailTo != "") && ($html != "")){
        require_once($_SERVER["DOCUMENT_ROOT"].'/tools/PHPMailer/class.phpmailer.php');
        $email = new PHPMailer();       
        $email->CharSet = 'UTF-8';
        $email->From      = 'order@nikaverro.ru';
        $email->FromName  = 'Вероника Малышева';
        $email->Subject   = 'Электронная билеты';
        $email->Body      = $html;
        $email->IsHTML(true);        
        $email->AddAddress( $emailTo );
        $email->addCC( "nikavero13@mail.ru" );        
        $email->Send();  
    }
}
function SendEmailToAffiliate($emailTo,$sum){
    if(($emailTo != "") && ($sum != "")){
        $text = "Через вас оплачен заказ на сумму: ".$sum;
        require_once($_SERVER["DOCUMENT_ROOT"].'/tools/PHPMailer/class.phpmailer.php');
        $email = new PHPMailer();       
        $email->CharSet = 'UTF-8';
        $email->From      = 'order@nikaverro.ru';
        $email->FromName  = 'Вероника Малышева';
        $email->Subject   = 'Электронная билеты';
        $email->Body      = $html;
        //$email->IsHTML(true);        
        $email->AddAddress( $emailTo );
        $email->addCC( "nikavero13@mail.ru" );        
        $email->Send();  
    }
}

Если блог был полезным, можете угостить меня "чашечкой кофе" :)

Сбер по номеру телефона +7 (953) 585-13-09 Вероника.
Спасибо!