Esempio n. 1
0
		<td><?php 
        echo GetMessage("C2IT_VKL");
        ?>
</td>
		<td><?php 
        echo GetMessage("C2IT_USERS_GROUP");
        ?>
</td>
		<td><?php 
        echo GetMessage("C2IT_ACTIVE_TIME");
        ?>
 <sup>1)</sup></td>
	</tr>
	<?php 
        $arCurProductGroups = array();
        $dbProductGroups = CCatalogProductGroups::GetList(array(), array("PRODUCT_ID" => $ID), false, false, array("ID", "GROUP_ID", "ACCESS_LENGTH", "ACCESS_LENGTH_TYPE"));
        while ($arProductGroup = $dbProductGroups->Fetch()) {
            $arCurProductGroups[intval($arProductGroup["GROUP_ID"])] = array(intval($arProductGroup["ACCESS_LENGTH"]), $arProductGroup["ACCESS_LENGTH_TYPE"]);
        }
        $arAvailContentGroups = array();
        $availContentGroups = COption::GetOptionString("catalog", "avail_content_groups");
        if (strlen($availContentGroups) > 0) {
            $arAvailContentGroups = explode(",", $availContentGroups);
        }
        $bNoAvailGroups = true;
        $dbGroups = CGroup::GetList($b = "c_sort", $o = "asc", array("ANONYMOUS" => "N"));
        while ($arGroup = $dbGroups->Fetch()) {
            $arGroup["ID"] = intval($arGroup["ID"]);
            if ($arGroup["ID"] == 2 || !in_array($arGroup["ID"], $arAvailContentGroups)) {
                continue;
            }
Esempio n. 2
0
function CatalogPayOrderCallback($productID, $userID, $bPaid, $orderID)
{
    global $DB;
    global $USER;
    $productID = intval($productID);
    $userID = intval($userID);
    $bPaid = $bPaid ? true : false;
    $orderID = intval($orderID);
    if ($userID <= 0) {
        return false;
    }
    $dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $productID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "N"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
    if ($arIBlockElement = $dbIBlockElement->GetNext()) {
        $arCatalog = CCatalog::GetByID($arIBlockElement["IBLOCK_ID"]);
        if ($arCatalog["SUBSCRIPTION"] == "Y") {
            $arProduct = CCatalogProduct::GetByID($productID);
            if ($bPaid) {
                if ('E' == CIBlock::GetArrayByID($arIBlockElement['IBLOCK_ID'], "RIGHTS_MODE")) {
                    $arUserRights = CIBlockElementRights::GetUserOperations($productID, $userID);
                    if (empty($arUserRights)) {
                        return false;
                    } elseif (!is_array($arUserRights) || !array_key_exists('element_read', $arUserRights)) {
                        return false;
                    }
                } else {
                    if ('R' > CIBlock::GetPermission($arIBlockElement['IBLOCK_ID'], $userID)) {
                        return false;
                    }
                }
                $arUserGroups = array();
                $arTmp = array();
                $ind = -1;
                $curTime = time();
                $dbProductGroups = CCatalogProductGroups::GetList(array(), array("PRODUCT_ID" => $productID), false, false, array("GROUP_ID", "ACCESS_LENGTH", "ACCESS_LENGTH_TYPE"));
                while ($arProductGroups = $dbProductGroups->Fetch()) {
                    $ind++;
                    $arProductGroups['GROUP_ID'] = intval($arProductGroups['GROUP_ID']);
                    $accessType = $arProductGroups["ACCESS_LENGTH_TYPE"];
                    $accessLength = intval($arProductGroups["ACCESS_LENGTH"]);
                    $accessVal = 0;
                    if (0 < $accessLength) {
                        if ($accessType == CCatalogProduct::TIME_PERIOD_HOUR) {
                            $accessVal = mktime(date("H") + $accessLength, date("i"), date("s"), date("m"), date("d"), date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_DAY) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $accessLength, date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_WEEK) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 7 * $accessLength, date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_MONTH) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m") + $accessLength, date("d"), date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_QUART) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m") + 3 * $accessLength, date("d"), date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_SEMIYEAR) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m") + 6 * $accessLength, date("d"), date("Y"));
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_YEAR) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + $accessLength);
                        } elseif ($accessType == CCatalogProduct::TIME_PERIOD_DOUBLE_YEAR) {
                            $accessVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + 2 * $accessLength);
                        }
                    }
                    $arUserGroups[$ind] = array("GROUP_ID" => $arProductGroups["GROUP_ID"], "DATE_ACTIVE_FROM" => date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), $curTime), "DATE_ACTIVE_TO" => 0 < $accessLength ? date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), $accessVal) : false);
                    $arTmp[$arProductGroups["GROUP_ID"]] = $ind;
                }
                if (!empty($arUserGroups)) {
                    $dbOldGroups = CUser::GetUserGroupEx($userID);
                    while ($arOldGroups = $dbOldGroups->Fetch()) {
                        $arOldGroups["GROUP_ID"] = intval($arOldGroups["GROUP_ID"]);
                        if (array_key_exists($arOldGroups["GROUP_ID"], $arTmp)) {
                            if (strlen($arOldGroups["DATE_ACTIVE_FROM"]) <= 0) {
                                $arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_FROM"] = false;
                            } else {
                                $oldDate = CDatabase::FormatDate($arOldGroups["DATE_ACTIVE_FROM"], CSite::GetDateFormat("SHORT", SITE_ID), "YYYYMMDDHHMISS");
                                $newDate = CDatabase::FormatDate($arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_FROM"], CSite::GetDateFormat("SHORT", SITE_ID), "YYYYMMDDHHMISS");
                                if ($oldDate > $newDate) {
                                    $arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_FROM"] = $arOldGroups["DATE_ACTIVE_FROM"];
                                }
                            }
                            if (strlen($arOldGroups["DATE_ACTIVE_TO"]) <= 0) {
                                $arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_TO"] = false;
                            } elseif (false !== $arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_TO"]) {
                                $oldDate = CDatabase::FormatDate($arOldGroups["DATE_ACTIVE_TO"], CSite::GetDateFormat("SHORT", SITE_ID), "YYYYMMDDHHMISS");
                                $newDate = CDatabase::FormatDate($arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_TO"], CSite::GetDateFormat("SHORT", SITE_ID), "YYYYMMDDHHMISS");
                                if ($oldDate > $newDate) {
                                    $arUserGroups[$arTmp[$arOldGroups["GROUP_ID"]]]["DATE_ACTIVE_TO"] = $arOldGroups["DATE_ACTIVE_TO"];
                                }
                            }
                        } else {
                            $ind++;
                            $arUserGroups[$ind] = array("GROUP_ID" => $arOldGroups["GROUP_ID"], "DATE_ACTIVE_FROM" => $arOldGroups["DATE_ACTIVE_FROM"], "DATE_ACTIVE_TO" => $arOldGroups["DATE_ACTIVE_TO"]);
                        }
                    }
                    CUser::SetUserGroup($userID, $arUserGroups);
                    if (CCatalog::IsUserExists()) {
                        if (intval($USER->GetID()) == $userID) {
                            $arUserGroupsTmp = array();
                            foreach ($arUserGroups as &$arOneGroup) {
                                $arUserGroupsTmp[] = $arOneGroup["GROUP_ID"];
                            }
                            if (isset($arOneGroup)) {
                                unset($arOneGroup);
                            }
                            $USER->SetUserGroupArray($arUserGroupsTmp);
                        }
                    }
                }
            } else {
                $arUserGroups = array();
                $ind = -1;
                $arTmp = array();
                $dbOldGroups = CUser::GetUserGroupEx($userID);
                while ($arOldGroups = $dbOldGroups->Fetch()) {
                    $ind++;
                    $arOldGroups["GROUP_ID"] = intval($arOldGroups["GROUP_ID"]);
                    $arUserGroups[$ind] = array("GROUP_ID" => $arOldGroups["GROUP_ID"], "DATE_ACTIVE_FROM" => $arOldGroups["DATE_ACTIVE_FROM"], "DATE_ACTIVE_TO" => $arOldGroups["DATE_ACTIVE_FROM"]);
                    $arTmp[$arOldGroups["GROUP_ID"]] = $ind;
                }
                $bNeedUpdate = false;
                $dbProductGroups = CCatalogProductGroups::GetList(array(), array("PRODUCT_ID" => $productID), false, false, array("GROUP_ID"));
                while ($arProductGroups = $dbProductGroups->Fetch()) {
                    $arProductGroups["GROUP_ID"] = intval($arProductGroups["GROUP_ID"]);
                    if (array_key_exists($arProductGroups["GROUP_ID"], $arTmp)) {
                        unset($arUserGroups[$arProductGroups["GROUP_ID"]]);
                        $bNeedUpdate = true;
                    }
                }
                if ($bNeedUpdate) {
                    CUser::SetUserGroup($userID, $arUserGroups);
                    if (CCatalog::IsUserExists()) {
                        if (intval($USER->GetID()) == $userID) {
                            $arUserGroupsTmp = array();
                            foreach ($arUserGroups as &$arOneGroup) {
                                $arUserGroupsTmp[] = $arOneGroup["GROUP_ID"];
                            }
                            if (isset($arOneGroup)) {
                                unset($arOneGroup);
                            }
                            $USER->SetUserGroupArray($arUserGroupsTmp);
                        }
                    }
                }
            }
            if ($arProduct["PRICE_TYPE"] != "S") {
                if ($bPaid) {
                    $recurType = $arProduct["RECUR_SCHEME_TYPE"];
                    $recurLength = intval($arProduct["RECUR_SCHEME_LENGTH"]);
                    $recurSchemeVal = 0;
                    if ($recurType == CCatalogProduct::TIME_PERIOD_HOUR) {
                        $recurSchemeVal = mktime(date("H") + $recurLength, date("i"), date("s"), date("m"), date("d"), date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_DAY) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $recurLength, date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_WEEK) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 7 * $recurLength, date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_MONTH) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + $recurLength, date("d"), date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_QUART) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 3 * $recurLength, date("d"), date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_SEMIYEAR) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 6 * $recurLength, date("d"), date("Y"));
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_YEAR) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + $recurLength);
                    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_DOUBLE_YEAR) {
                        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + 2 * $recurLength);
                    }
                    $arFields = array("USER_ID" => $userID, "MODULE" => "catalog", "PRODUCT_ID" => $productID, "PRODUCT_NAME" => $arIBlockElement["~NAME"], "PRODUCT_URL" => $arIBlockElement["~DETAIL_PAGE_URL"], "PRODUCT_PRICE_ID" => false, "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_TYPE" => $recurType, "RECUR_SCHEME_LENGTH" => $recurLength, "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "PRICE" => false, "CURRENCY" => false, "CANCELED" => "N", "CANCELED_REASON" => false, "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "DESCRIPTION" => false, "PRIOR_DATE" => false, "NEXT_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), $recurSchemeVal));
                    return $arFields;
                }
            }
        }
        return true;
    }
    return false;
}