Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }
Exemplo 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');
            }
        }
    }
}
Exemplo n.º 5
0
        }
    }
    foreach ($arID as $ID) {
        if (strlen($ID) <= 0) {
            continue;
        }
        $ID = intval($ID);
        switch ($_REQUEST['action']) {
            case 'delete':
                @set_time_limit(0);
                CSupportSuperCoupon::Delete($ID);
                break;
        }
    }
}
$rsData = CSupportSuperCoupon::GetList(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' => 'ID', 'content' => 'ID', 'default' => true, 'sort' => 'ID');
$arHeaders[] = array('id' => 'COUPON', 'content' => GetMessage('SUP_CL_COUPON'), 'default' => true, 'sort' => 'COUPON');
$arHeaders[] = array('id' => 'COUNT_TICKETS', 'content' => GetMessage('SUP_CL_COUNT_TICKETS'), 'default' => true, 'sort' => 'COUNT_TICKETS');
$arHeaders[] = array('id' => 'COUNT_USED', 'content' => GetMessage('SUP_CL_COUNT_USED'), 'default' => true, 'sort' => 'COUNT_USED');
$arHeaders[] = array('id' => 'TIMESTAMP_X', 'content' => GetMessage('SUP_CL_TIMESTAMP_X'), 'default' => false, 'sort' => 'TIMESTAMP_X');
$arHeaders[] = array('id' => 'DATE_CREATE', 'content' => GetMessage('SUP_CL_DATE_CREATE'), 'default' => false, 'sort' => 'DATE_CREATE');
$arHeaders[] = array('id' => 'ACTIVE', 'content' => GetMessage('SUP_CL_ACTIVE'), 'default' => true, 'sort' => 'ACTIVE');
$arHeaders[] = array('id' => 'ACTIVE_FROM', 'content' => GetMessage('SUP_CL_ACTIVE_FROM'), 'default' => true, 'sort' => 'ACTIVE_FROM');
$arHeaders[] = array('id' => 'ACTIVE_TO', 'content' => GetMessage('SUP_CL_ACTIVE_TO'), 'default' => true, 'sort' => 'ACTIVE_TO');
$arHeaders[] = array('id' => 'CREATED_USER_ID', 'content' => GetMessage('SUP_CL_CREATED_USER_ID'), 'default' => false, 'sort' => 'CREATED_USER_ID');
$arHeaders[] = array('id' => 'CREATED_LOGIN', 'content' => GetMessage('SUP_CL_CREATED_LOGIN'), 'default' => false, 'sort' => 'CREATED_LOGIN');
Exemplo 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;
	}
Exemplo n.º 7
0
}
$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 {
                $bOK = false;
            }
        }
    }
    if ($bOK) {
        if (strlen($save) > 0) {
            LocalRedirect($LIST_URL . '?lang=' . LANG . ($new ? '&SHOW_COUPON=Y' : ''));
        } elseif ($new) {
            LocalRedirect($APPLICATION->GetCurPage() . '?ID=' . $ID . '&lang=' . LANG . '&tabControl_active_tab=' . urlencode($tabControl_active_tab));
        }