Ejemplo n.º 1
0
 function UseCoupon($coupon)
 {
     global $DB, $USER;
     $ret = false;
     $arFields = false;
     $arLogFields = false;
     $arCoupon = false;
     $curr = ConvertTimeStamp();
     $arFilter = array('LOGIC' => 'AND', 'COUPON' => $coupon, '=ACTIVE' => 'Y', array('LOGIC' => 'OR', 'ACTIVE_FROM' => false, '<=ACTIVE_FROM' => $curr), array('LOGIC' => 'OR', 'ACTIVE_TO' => false, '>=ACTIVE_TO' => $curr));
     $DB->StartTransaction();
     $rs = CSupportSuperCoupon::GetList(false, $arFilter);
     if ($arCoupon = $rs->Fetch()) {
         $countTickets = intval($arCoupon['COUNT_TICKETS']);
         if ($countTickets > 0) {
             $countTickets--;
             $arFields = array('COUNT_TICKETS' => $countTickets, 'TIMESTAMP_X' => $DB->GetNowFunction(), 'COUNT_USED' => 'COUNT_USED + 1');
             if (isset($USER) && is_object($USER)) {
                 $arFields['UPDATED_USER_ID'] = $USER->GetID();
             }
             if ($aff_rows = $DB->Update('b_ticket_supercoupons', $arFields, 'WHERE ID=' . $arCoupon['ID'])) {
                 $ret = true;
             }
         }
         $arLogFields = array('~TIMESTAMP_X' => $DB->GetNowFunction(), 'COUPON_ID' => $arCoupon['ID'], 'USER_ID' => isset($USER) && is_object($USER) ? $USER->GetID() : false, 'SUCCESS' => $ret ? 'Y' : 'N', 'AFTER_COUNT' => $countTickets, 'SESSION_ID' => array_key_exists('SESS_SESSION_ID', $_SESSION) ? $_SESSION['SESS_SESSION_ID'] : false, 'GUEST_ID' => array_key_exists('SESS_GUEST_ID', $_SESSION) ? $_SESSION['SESS_GUEST_ID'] : false, 'AFFECTED_ROWS' => $aff_rows, 'COUPON' => $coupon);
         $arInsert = $DB->PrepareInsert('b_ticket_supercoupons_log', $arLogFields);
         $strSql = "INSERT INTO b_ticket_supercoupons_log (" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
         $DB->Query($strSql, false, 'File: ' . __FILE__ . ' Line: ' . __LINE__);
         $arMail = array('COUPON' => $coupon, 'COUPON_ID' => $arCoupon['ID'], 'DATE' => ConvertTimeStamp(false, 'FULL'), 'USER_ID' => isset($USER) && is_object($USER) ? $USER->GetID() : -1, 'SESSION_ID' => array_key_exists('SESS_SESSION_ID', $_SESSION) ? $_SESSION['SESS_SESSION_ID'] : -1, 'GUEST_ID' => array_key_exists('SESS_GUEST_ID', $_SESSION) ? $_SESSION['SESS_GUEST_ID'] : -1);
         $rsEvents = GetModuleEvents('support', 'OnBeforeSendCouponEMail');
         while ($arEvent = $rsEvents->Fetch()) {
             $arMail = ExecuteModuleEventEx($arEvent, array($arMail));
         }
         if ($arMail) {
             $e = new CEvent();
             $e->Send('TICKET_GENERATE_SUPERCOUPON', SITE_ID, $arMail);
         }
     }
     $DB->Commit();
     $rsEvents = GetModuleEvents('support', 'OnAfterUseCoupon');
     while ($arEvent = $rsEvents->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($coupon, $arCoupon, $arFields, $arLogFields));
     }
     return $ret;
 }
Ejemplo n.º 2
0
 public static function GetSLA($siteID, $userID, $categoryID = null, $coupon = "")
 {
     global $DB;
     $err_mess = CAllTicketSLA::err_mess() . "<br>Function: GetSLA<br>Line: ";
     $userID = intval($userID);
     if (strlen($coupon) > 0) {
         $rsCoupon = CSupportSuperCoupon::GetList(false, array('COUPON' => $coupon));
         if ($arCoupon = $rsCoupon->Fetch()) {
             if (intval($arCoupon['SLA_ID']) > 0) {
                 return intval($arCoupon['SLA_ID']);
             }
         }
     }
     $slaID = COption::GetOptionString("support", "SUPPORT_DEFAULT_SLA_ID");
     $OLD_FUNCTIONALITY = COption::GetOptionString("support", "SUPPORT_OLD_FUNCTIONALITY", "Y");
     if ($OLD_FUNCTIONALITY == "Y") {
         $categoryID = null;
     }
     $JOIN = "";
     $fields = "1";
     if ($categoryID != null) {
         $categoryID = intval($categoryID);
         $fields = "CASE\n\t\t\t\t\t\tWHEN SC.SLA_ID IS NOT NULL THEN 1\n\t\t\t\t\t\tELSE 0\n\t\t\t\t\tEND";
         $JOIN .= "\t\n\t\t\t\t\tLEFT JOIN b_ticket_sla_2_category SC\n\t\t\t\t\t\tON S.ID = SC.SLA_ID\n\t\t\t\t\t\t\tAND ( SC.CATEGORY_ID = 0 OR SC.CATEGORY_ID = {$categoryID} )";
     }
     if ($userID === 0) {
         // guest: default site sla for usergroup #2
         $groupJoin = "UG.GROUP_ID = 2";
     } else {
         // sla for this user
         $groupJoin = "((UG.USER_ID = {$userID} ";
         $groupJoin .= " AND ((UG.DATE_ACTIVE_FROM IS NULL) OR (UG.DATE_ACTIVE_FROM <= " . $DB->CurrentTimeFunction() . ")) ";
         $groupJoin .= " AND ((UG.DATE_ACTIVE_TO IS NULL) OR (UG.DATE_ACTIVE_TO >= " . $DB->CurrentTimeFunction() . ")) ";
         $groupJoin .= ") OR UG.GROUP_ID = 2)";
     }
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tPZ.SLA_ID\n\t\t\tFROM\n\t\t\t(\n\t\t\t\tSELECT\n\t\t\t\t\tSG.SLA_ID SLA_ID,\n\t\t\t\t\t{$fields} PRIORITY1,\n\t\t\t\t\tS.PRIORITY PRIORITY2\n\t\t\t\tFROM\n\t\t\t\t\tb_ticket_sla S\n\t\t\t\t\tINNER JOIN b_ticket_sla_2_site SS\n\t\t\t\t\t\tON S.ID = SS.SLA_ID\n\t\t\t\t\t\t\tAND ( SS.SITE_ID = 'ALL' OR SS.SITE_ID = '{$siteID}' ) \n\t\t\t\t\tINNER JOIN b_ticket_sla_2_user_group SG\n\t\t\t\t\t\tON S.ID = SG.SLA_ID\n\t\t\t\t\tINNER JOIN b_user_group UG\n\t\t\t\t\t\tON SG.GROUP_ID = UG.GROUP_ID\n\t\t\t\t\t\t\tAND {$groupJoin}\n\t\t\t\t\t{$JOIN}\n\t\t\t) PZ\n\t\t\tGROUP BY\n\t\t\t\tPZ.SLA_ID, PZ.PRIORITY1, PZ.PRIORITY2\n\t\t\tORDER BY\n\t\t\t\tPZ.PRIORITY1 DESC, PZ.PRIORITY2 DESC\n\t\t\t\t\t\t\t\n\t\t";
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     if ($ar = $rs->Fetch()) {
         if (is_array($ar) && array_key_exists("SLA_ID", $ar)) {
             $slaID = $ar["SLA_ID"];
         }
     }
     return $slaID;
 }
Ejemplo n.º 3
0
 function Set_getCOUPONandSLA($v, $f, $arFields)
 {
     global $APPLICATION;
     $slaID = 0;
     if (isset($arFields['SLA_ID']) && intval($arFields['SLA_ID']) > 0) {
         $slaID = $arFields['SLA_ID'];
     }
     // получение купона
     if (array_key_exists('COUPON', $arFields) && strlen($arFields['COUPON']) > 0) {
         $v->bActiveCoupon = CSupportSuperCoupon::UseCoupon($arFields['COUPON']);
         if ($v->bActiveCoupon) {
             $v->V_COUPON = $arFields['COUPON'];
             $rsCoupon = CSupportSuperCoupon::GetList(false, array('COUPON' => $arFields['COUPON']));
             //if($arCoupon = $rsCoupon->Fetch() && intval($arCoupon['SLA_ID']) > 0) $arFields['SLA_ID'] = intval($arCoupon['SLA_ID']);
             if ($arCoupon = $rsCoupon->Fetch()) {
                 if (intval($arCoupon['SLA_ID']) > 0) {
                     $slaID = intval($arCoupon['SLA_ID']);
                 }
             }
         } else {
             $APPLICATION->ThrowException(GetMessage('SUP_ERROR_INVALID_COUPON'));
             return false;
         }
     }
     // получаем SLA
     if ($slaID > 0) {
         //$f->FromArray($arFields, "SLA_ID", array(CSupportTableFields::MORE0));
         $f->SLA_ID = $slaID;
     } else {
         $f->SLA_ID = CTicketSLA::GetSLA($f->SITE_ID, $f->OWNER_USER_ID, $f->CATEGORY_ID, $v->bActiveCoupon ? $v->V_COUPON : "");
     }
     //elseif(intval($arFields["SLA_ID"]) <= 0) $f->SLA_ID = CTicketSLA::GetForUser($f->SITE_ID, $f->OWNER_USER_ID);
     return true;
 }
Ejemplo n.º 4
0
if (file_exists($langfile)) {
    __IncludeLang($langfile);
}
if ($arResult['CURRENT_STEP'] == 1) {
    $arResult['FIELDS'] = array_merge(array(array('NAME' => GetMessage('WZ_MESS_TITLE'), 'FIELD_ID' => 'wz_title', 'FIELD_VALUE' => htmlspecialcharsbx($_REQUEST['wizard']['wz_title']), 'FIELD_TYPE' => 'text')), $arResult['FIELDS']);
    if ($arParams['SHOW_COUPON_FIELD'] == 'Y') {
        $arResult['FIELDS'][] = array('NAME' => GetMessage('WZ_COUPON'), 'PREVIEW_TEXT' => GetMessage('WZ_MESS_PREVIEW'), 'DETAIL_TEXT' => GetMessage('WZ_MESS_DETAIL'), 'FIELD_ID' => 'wz_coupon', 'FIELD_VALUE' => htmlspecialcharsbx($_REQUEST['wizard']['wz_coupon']), 'FIELD_TYPE' => 'text');
    }
} else {
    $arResult['HIDDEN'][] = array('wz_title', htmlspecialcharsbx($_REQUEST['wizard']['wz_title']));
    if ($arParams['SHOW_COUPON_FIELD'] == 'Y') {
        $arResult['HIDDEN'][] = array('wz_coupon', htmlspecialcharsbx($_REQUEST['wizard']['wz_coupon']));
        if ($arResult['CURRENT_STEP'] == 2 && $_REQUEST['wizard']['wz_coupon']) {
            CModule::IncludeModule('support');
            CTimeZone::Disable();
            $rs = CSupportSuperCoupon::GetList(false, array('ACTIVE' => 'Y', 'COUPON' => $_REQUEST['wizard']['wz_coupon']));
            CTimeZone::Enable();
            if ($f = $rs->Fetch()) {
                if (date('Ymd', time()) > date('Ymd', MakeTimeStamp($f['ACTIVE_TO']))) {
                    $arResult['ERROR'] = str_replace("#DATE_ACTIVE#", $f['ACTIVE_TO'], GetMessage('WZ_COUPON_ERR1'));
                } elseif ($f['COUNT_TICKETS'] < 1) {
                    $arResult['ERROR'] = GetMessage('WZ_COUPON_ERR2');
                } else {
                    $arResult['MESSAGE'] = GetMessage('WZ_ACCEPTED') . ($f['COUNT_TICKETS'] - 1);
                }
            } else {
                $arResult['ERROR'] = GetMessage('WZ_COUPON_ERR0');
            }
        }
    }
}
Ejemplo n.º 5
0
if (array_key_exists('GENERATE', $_POST) && $_POST['GENERATE'] == 'Y' && $bAdmin && check_bitrix_sessid()) {
    $COUPON = CSupportSuperCoupon::Generate();
    if ($COUPON !== false) {
        $_SESSION['BX_LAST_COUPON'] = $COUPON;
        LocalRedirect($APPLICATION->GetCurPage() . '?SHOW_COUPON=Y&lang=' . LANG);
    } else {
        if ($e = $APPLICATION->GetException()) {
            $message = new CAdminMessage(GetMessage('SUP_CL_GENERATE_ERROR'), $e);
        }
    }
}
if (array_key_exists('SHOW_COUPON', $_GET) && $_GET['SHOW_COUPON'] == 'Y' && array_key_exists('BX_LAST_COUPON', $_SESSION)) {
    $message = new CAdminMessage(array('MESSAGE' => GetMessage('SUP_CL_GENERATE_MESS_OK', array('%COUPON%' => $_SESSION['BX_LAST_COUPON'])), 'TYPE' => 'OK'));
}
if ($bAdmin && $lAdmin->EditAction()) {
    $obSSC = new CSupportSuperCoupon();
    foreach ($FIELDS as $ID => $arFields) {
        $ID = intval($ID);
        if (!$lAdmin->IsUpdated($ID)) {
            continue;
        }
        $arUpdate = array('COUNT_TICKETS' => $arFields['COUNT_TICKETS'], 'ACTIVE' => $arFields['ACTIVE']);
        if (!$obSSC->Update($ID, $arUpdate)) {
            $ex = $APPLICATION->GetException();
            $lAdmin->AddUpdateError($ex->GetString(), $ID);
        }
    }
}
if ($bAdmin && ($arID = $lAdmin->GroupAction())) {
    if ($_REQUEST['action_target'] == 'selected') {
        $rsData = CSupportSuperCoupon::GetList(array($by => $order), $arFilter);
Ejemplo n.º 6
0
	function GetSLA( $siteID, $userID, $categoryID = null, $coupon = ""  )
	{
		global $DB;
		$err_mess = (CAllTicketSLA::err_mess())."<br>Function: GetSLA<br>Line: ";

		$userID = intval($userID);
			
		if( strlen( $coupon ) > 0 )
		{
			$rsCoupon = CSupportSuperCoupon::GetList( false, array( 'COUPON' => $coupon ) );
			if($arCoupon = $rsCoupon->Fetch())
			{
				if(intval($arCoupon['SLA_ID'] ) > 0)
				{
					return intval( $arCoupon['SLA_ID'] );
				}
			}
		}
		
		$slaID = COption::GetOptionString( "support", "SUPPORT_DEFAULT_SLA_ID" );

		$OLD_FUNCTIONALITY = COption::GetOptionString( "support", "SUPPORT_OLD_FUNCTIONALITY", "Y" );
		if( $OLD_FUNCTIONALITY == "Y" )
		{
			$categoryID = null;
		}
		
		$JOIN = "";
		$fields = "1";
		if( $categoryID != null )
		{
			$categoryID = intval( $categoryID );
			$fields = "CASE
						WHEN SC.SLA_ID IS NOT NULL THEN 1
						ELSE 0
					END";
			$JOIN .= "	
					LEFT JOIN b_ticket_sla_2_category SC
						ON S.ID = SC.SLA_ID
							AND ( SC.CATEGORY_ID = 0 OR SC.CATEGORY_ID = $categoryID )";
		}

		if ($userID === 0)
		{
			// guest: default site sla for usergroup #2
			$groupJoin = "UG.GROUP_ID = 2";
		}
		else
		{
			// sla for this user
			$groupJoin = "(UG.USER_ID = $userID OR UG.GROUP_ID = 2)";
		}

		$strSql = "
			SELECT
				PZ.SLA_ID
			FROM
			(
				SELECT
					SG.SLA_ID SLA_ID,
					$fields PRIORITY1,
					S.PRIORITY PRIORITY2
				FROM
					b_ticket_sla S
					INNER JOIN b_ticket_sla_2_site SS
						ON S.ID = SS.SLA_ID
							AND ( SS.SITE_ID = 'ALL' OR SS.SITE_ID = '$siteID' ) 
					INNER JOIN b_ticket_sla_2_user_group SG
						ON S.ID = SG.SLA_ID
					INNER JOIN b_user_group UG
						ON SG.GROUP_ID = UG.GROUP_ID
							AND $groupJoin
					$JOIN
			) PZ
			GROUP BY
				PZ.SLA_ID, PZ.PRIORITY1, PZ.PRIORITY2
			ORDER BY
				PZ.PRIORITY1 DESC, PZ.PRIORITY2 DESC
							
		";
		
		$rs = $DB->Query($strSql, false, $err_mess.__LINE__);
		if( $ar = $rs->Fetch() )
		{
			if( is_array( $ar ) && array_key_exists( "SLA_ID", $ar ) )
			{
				$slaID = $ar["SLA_ID"];
			}
		}

		return $slaID;
	}
Ejemplo n.º 7
0
        continue;
    }
    if (array_key_exists($key . '_EXACT_MATCH', $_REQUEST) && $_REQUEST[$key . '_EXACT_MATCH'] == 'Y') {
        $op = '=';
    } else {
        $op = '%';
    }
    if (array_key_exists($key, $_REQUEST) && strlen($_REQUEST[$key]) > 0) {
        if (in_array($key . '_EXACT_MATCH', $arFilterFields)) {
            $arFilter[$op . substr($key, 5)] = $_REQUEST[$key];
        } else {
            $arFilter[substr($key, 5)] = $_REQUEST[$key];
        }
    }
}
$rsData = CSupportSuperCoupon::GetLogList(array($by => $order), $arFilter);
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart(50);
$lAdmin->NavText($rsData->GetNavPrint(GetMessage('SUP_CL_PAGES')));
$arHeaders = array();
$arHeaders[] = array('id' => 'COUPON_ID', 'content' => GetMessage('SUP_CL_COUPON_ID'), 'default' => false, 'sort' => 'COUPON_ID');
$arHeaders[] = array('id' => 'COUPON', 'content' => GetMessage('SUP_CL_COUPON'), 'default' => true, 'sort' => 'COUPON');
$arHeaders[] = array('id' => 'TIMESTAMP_X', 'content' => GetMessage('SUP_CL_TIMESTAMP_X'), 'default' => true, 'sort' => 'TIMESTAMP_X');
$arHeaders[] = array('id' => 'USER_ID', 'content' => GetMessage('SUP_CL_USER_ID'), 'default' => true, 'sort' => 'USER_ID');
$arHeaders[] = array('id' => 'LOGIN', 'content' => GetMessage('SUP_CL_LOGIN'), 'default' => true, 'sort' => 'LOGIN');
$arHeaders[] = array('id' => 'FIRST_NAME', 'content' => GetMessage('SUP_CL_FIRST_NAME'), 'default' => false, 'sort' => 'FIRST_NAME');
$arHeaders[] = array('id' => 'LAST_NAME', 'content' => GetMessage('SUP_CL_LAST_NAME'), 'default' => false, 'sort' => 'LAST_NAME');
$arHeaders[] = array('id' => 'SESSION_ID', 'content' => GetMessage('SUP_CL_SESSION_ID'), 'default' => false, 'sort' => 'SESSION_ID');
$arHeaders[] = array('id' => 'GUEST_ID', 'content' => GetMessage('SUP_CL_GUEST_ID'), 'default' => false, 'sort' => 'GUEST_ID');
$bStatIncluded = CModule::IncludeModule('statistic');
$lAdmin->AddHeaders($arHeaders);
Ejemplo n.º 8
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/support/prolog.php";
CModule::IncludeModule('support');
IncludeModuleLangFile(__FILE__);
$bDemo = CTicket::IsDemo();
$bAdmin = CTicket::IsAdmin();
if (!$bAdmin && !$bDemo) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$LIST_URL = '/bitrix/admin/ticket_coupon_list.php';
$ID = intval($ID);
$message = false;
if ((strlen($save) > 0 || strlen($apply) > 0) && $REQUEST_METHOD == 'POST' && $bAdmin && check_bitrix_sessid()) {
    $obSSC = new CSupportSuperCoupon();
    $bOK = false;
    $new = false;
    $arFields = array("ACTIVE_FROM" => $_POST['ACTIVE_FROM'], "ACTIVE_TO" => $_POST['ACTIVE_TO'], "ACTIVE" => $_POST['ACTIVE'], "COUNT_TICKETS" => IntVal($_POST['COUNT_TICKETS']), "SLA_ID" => IntVal($_POST['SLA_ID']));
    if ($ID > 0) {
        $bOK = $obSSC->Update($ID, $arFields);
    } else {
        if ($COUPON = $obSSC->Generate($arFields)) {
            if ($COUPON !== false) {
                $_SESSION['BX_LAST_COUPON'] = $COUPON;
                $rsCoupons = $obSSC->GetList(false, array('COUPON' => $COUPON));
                $arCoupon = $rsCoupons->Fetch();
                $ID = intval($arCoupon['ID']);
                $bOK = true;
                $new = true;
            } else {