function Add($arFields) { global $DB; if (!CCatalogProductGroups::CheckFields("ADD", $arFields, 0)) { return False; } $arInsert = $DB->PrepareInsert("b_catalog_product2group", $arFields); $strSql = "INSERT INTO b_catalog_product2group(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = intval($DB->LastID()); return $ID; }
foreach ($fieldsClear as &$oneValue) { if (isset($arOldAvailContentGroups[$oneValue])) unset($arOldAvailContentGroups[$oneValue]); } if (isset($oneValue)) unset($oneValue); } Option::set('catalog', 'avail_content_groups', implode(',', $fieldsClear), ''); if (!empty($arOldAvailContentGroups)) { $arOldAvailContentGroups = array_keys($arOldAvailContentGroups); foreach ($arOldAvailContentGroups as &$oneValue) { CCatalogProductGroups::DeleteByGroup($oneValue); } unset($oneValue); } } $checkboxFields = array( 'save_product_without_price', 'show_catalog_tab_with_offers', 'default_quantity_trace', 'default_can_buy_zero', 'default_subscribe', 'product_form_show_offers_iblock', 'product_form_simple_search' );
<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; }
} continue; } if (isset($arCurProductGroups[$arGroup["ID"]])) { if (isset(${"CAT_USER_GROUP_ID_" . $arGroup["ID"]}) && ${"CAT_USER_GROUP_ID_" . $arGroup["ID"]} == "Y") { if (IntVal(${"CAT_ACCESS_LENGTH_" . $arGroup["ID"]}) != IntVal($arCurProductGroups[$arGroup["ID"]]["ACCESS_LENGTH"]) || ${"CAT_ACCESS_LENGTH_TYPE_" . $arGroup["ID"]} != $arCurProductGroups[$arGroup["ID"]]["ACCESS_LENGTH_TYPE"]) { $arCatalogFields = array("ACCESS_LENGTH" => IntVal(${"CAT_ACCESS_LENGTH_" . $arGroup["ID"]}), "ACCESS_LENGTH_TYPE" => ${"CAT_ACCESS_LENGTH_TYPE_" . $arGroup["ID"]}); CCatalogProductGroups::Update($arCurProductGroups[$arGroup["ID"]]["ID"], $arCatalogFields); } } else { CCatalogProductGroups::Delete($arCurProductGroups[$arGroup["ID"]]["ID"]); } } else { if (isset(${"CAT_USER_GROUP_ID_" . $arGroup["ID"]}) && ${"CAT_USER_GROUP_ID_" . $arGroup["ID"]} == "Y") { $arCatalogFields = array("PRODUCT_ID" => $ID, "GROUP_ID" => $arGroup["ID"], "ACCESS_LENGTH" => IntVal(${"CAT_ACCESS_LENGTH_" . $arGroup["ID"]}), "ACCESS_LENGTH_TYPE" => ${"CAT_ACCESS_LENGTH_TYPE_" . $arGroup["ID"]}); CCatalogProductGroups::Add($arCatalogFields); } } } } if ($USER->CanDoOperation('catalog_store')) { $rsStores = CCatalogStore::GetList(array(), array('ACTIVE' => 'Y'), false, false, array('ID')); while ($arStore = $rsStores->Fetch()) { if (isset($_POST['AR_AMOUNT'][$arStore['ID']])) { $arStoreProductFields = array("PRODUCT_ID" => $ID, "STORE_ID" => $arStore['ID'], "AMOUNT" => $_POST['AR_AMOUNT'][$arStore['ID']]); if (!CCatalogStoreProduct::UpdateFromForm($arStoreProductFields)) { $bVarsFromForm = true; } } } }
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; }
function OnGroupDelete($ID) { CCatalogProductGroups::DeleteByGroup($ID); }