/** * @param CSubscription $oSubscription * * @return bool */ public function updateSubscription($oSubscription) { $bResult = false; try { if ($oSubscription->validate()) { $bResult = $this->oStorage->createSubscription($oSubscription); } } catch (CApiBaseException $oException) { $this->setLastException($oException); } return $bResult; }
/** * @param int $iSubscriptionID * * @return string */ public function getSubscriptionById($iSubscriptionID) { $aMap = api_AContainer::DbReadKeys(CSubscription::getStaticMap()); $aMap = array_map(array($this, 'escapeColumn'), $aMap); $sSql = 'SELECT %s FROM %sawm_subscriptions WHERE %s = %d'; return sprintf($sSql, implode(', ', $aMap), $this->prefix(), $this->escapeColumn('id_subscription'), $iSubscriptionID); }
/** * @param CSubscription $oSubscription * * @return bool */ public function UpdateSubscription($oSubscription) { $bResult = false; try { if ($oSubscription->Validate()) { $bResult = $this->oStorage->CreateSubscription($oSubscription); } } catch (CApiBaseException $oException) { $this->setLastException($oException); } // if ($bResult) // { // $oTenant = $this->TenantManager(); // if ($oTenant) // { // $oTenant->UpdateTenantMainCapa($oSubscription->IdTenant); // } // } return $bResult; }
public function DeleteByLogin($login) { if (!$login) { throw new \Exception("Unexpected login", 1); } else { $user = \CUser::GetByLogin($login)->Fetch(); $subscriber = \CSubscription::GetByEmail($user["EMAIL"])->Fetch(); \CSubscription::Delete($subscriber["ID"]); return True; } }
public function Add() { \ChromePhp::log("Subscr CRUD Add"); if ($subscriber = $this->getSubscriber()) { $this->user = \CUser::GetByID($subscriber)->Fetch(); \CUser::Authorize($this->user["ID"]); if ($subscribe = \CSubscription::GetList(False, array("ACTIVE" => "Y", "USER_ID" => $this->user["ID"]))->Fetch()) { return $subscribe["ID"]; } else { try { return $this->addSubscribe(); } catch (SubscribeException $e) { prentExpection($e->getMessage()); } } } else { throw new SubscribeUserException("No user for add to subscribers" . ". Line: " . __LINE__); } }
$aEmail[$addr] = true; } $addr = strtok(", \r\n\t"); } //check for duplicate emails $addr = CSubscription::GetList(); while ($addr_arr = $addr->Fetch()) { if (isset($aEmail[$addr_arr["EMAIL"]])) { unset($aEmail[$addr_arr["EMAIL"]]); } } //************************************* //add users and subscribers //************************************* //constant part of the subscriber $subscr = new CSubscription(); $arFields = array("ACTIVE" => "Y", "FORMAT" => $FORMAT != "html" ? "text" : "html", "CONFIRMED" => $CONFIRMED != "Y" ? "N" : "Y", "SEND_CONFIRM" => $SEND_CONFIRM != "Y" ? "N" : "Y", "ALL_SITES" => "Y", "RUB_ID" => $RUB_ID); //constant part of the user if ($USER_TYPE == "U") { $user = new CUser(); } $nError = 0; $nSuccess = 0; foreach ($aEmail as $email => $temp) { $USER_ID = false; if ($USER_TYPE == "U") { //add user $sPassw = randString(6); $arUserFields = array("LOGIN" => randString(50), "CHECKWORD" => randString(8), "PASSWORD" => $sPassw, "CONFIRM_PASSWORD" => $sPassw, "EMAIL" => $email, "ACTIVE" => "Y", "GROUP_ID" => $USER->IsAdmin() ? $USER_GROUP_ID : array(COption::GetOptionString("main", "new_user_registration_def_group"))); if ($USER_ID = $user->Add($arUserFields)) { $user->Update($USER_ID, array("LOGIN" => "user" . $USER_ID));
'" onclick="if (this.value=='<?php echo GetMessage("CT_BSE_CONFIRMATION"); ?> ')this.value=''" /> <input type="submit" name="confirm" value="<?php echo GetMessage("CT_BSE_BTN_CONF"); ?> " /> </div> <?php } ?> </form> <?php if (!CSubscription::IsAuthorized($arResult["ID"])) { ?> <form action="<?php echo $arResult["FORM_ACTION"]; ?> " method="post"> <?php echo bitrix_sessid_post(); ?> <input type="hidden" name="action" value="sendcode" /> <div class="subscription-utility"> <p><?php echo GetMessage("CT_BSE_SEND_NOTE"); ?> </p>
$arParams = array('JS_KEY' => md5(LICENSE_KEY)); } $post = $_POST; if ($post['asd_subscribe'] == 'Y' && strlen(trim($post['asd_email'])) && $post['asd_key'] == md5($arParams['JS_KEY'] . $post['asd_rubrics'] . (isset($post['asd_show_rubrics']) ? $post['asd_show_rubrics'] : '') . (isset($post['asd_not_confirm']) ? $post['asd_not_confirm'] : '')) && check_bitrix_sessid()) { $arReturn = array(); CComponentUtil::__IncludeLang(substr(__FILE__, strpos(__FILE__, '/bitrix/components'), -strlen(basename(__FILE__))), basename(__FILE__)); if (CModule::IncludeModule('subscribe')) { $arRubrics = strlen($post['asd_rubrics']) ? explode('|', $post['asd_rubrics']) : array(); $arRubricsUser = isset($post['asd_rub']) && is_array($post['asd_rub']) ? $post['asd_rub'] : array(); $arRubricsUser = array_intersect($arRubrics, $arRubricsUser); $arRubricsUser = empty($arRubricsUser) ? $arRubrics : $arRubricsUser; $email = trim($post['asd_email']); $charset = $post['charset']; $bShowRubrics = $post['asd_show_rubrics'] == 'Y'; $arFields = array('USER_ID' => $USER->GetID(), 'SEND_CONFIRM' => $post['asd_not_confirm'] == 'Y' ? 'N' : 'Y', 'EMAIL' => $email, 'ACTIVE' => 'Y', 'RUB_ID' => $bShowRubrics ? $arRubricsUser : $arRubrics, 'CONFIRMED' => $post['asd_not_confirm'] == 'Y' ? 'Y' : 'N'); $subscr = new CSubscription(); if ($newID = $subscr->Add($arFields)) { $arReturn = array('message' => GetMessage('ASD_CMP_SUCCESS' . ($post['asd_not_confirm'] == 'Y' ? '_NC' : '')), 'status' => 'ok'); } elseif ($ex = $APPLICATION->GetException()) { $arReturn = array('message' => $ex->GetString(), 'status' => 'error'); } } else { $arReturn = array('message' => GetMessage('ASD_CMP_NOT_INSTALLED'), 'status' => 'error'); } if (defined('PUBLIC_AJAX_MODE') && PUBLIC_AJAX_MODE === true) { $arReturn['message'] = $APPLICATION->ConvertCharset(strip_tags($arReturn['message']), $charset, 'UTF-8'); header('Content-type: application/json'); echo json_encode($arReturn); } else { return $arReturn; }
"ROOT_MENU_TYPE" => $menu_type, "MAX_LEVEL" => "1", "CHILD_MENU_TYPE" => $menu_type, "USE_EXT" => "N", "DELAY" => "N", "ALLOW_MULTI_SELECT" => "N", "MENU_CACHE_TYPE" => "N", "MENU_CACHE_TIME" => "", "MENU_CACHE_USE_GROUPS" => "N", "MENU_CACHE_GET_VARS" => array() ) );?> </div> <? CModule::IncludeModule("subscribe"); $resSubscribe = CSubscription::GetUserSubscription(); //echo "<pre>";print_r($resSubscribe);echo "</pre>"; ?> <?if ($resSubscribe["ID"] <= 0 || $resSubscribe["ACTIVE"] == "N"):?> <p class="news-feed-header">Новостная рассылка</p> <a class="btn important js-subscribe-trigger" href="#" data-email="<?=CUser::GetEmail()?>" data-action="add">Подписаться</a> <?else:?> <p class="news-feed-header">Новостная рассылка</p> <a class="btn important js-subscribe-trigger" href="#" data-email="<?=CUser::GetEmail()?>" data-action="remove">Отписаться</a> <?endif?> <?if ($dis === false):?> <div class="lk-designer-invitation text-content"> <?$APPLICATION->IncludeComponent( "bitrix:news.list", "text_menu_lk", Array(
function Authorize($ID, $CONFIRM_CODE = false) { global $USER; $subscr = CSubscription::GetByID($ID); if ($subscr_arr = $subscr->Fetch()) { //unconditional auth if ($CONFIRM_CODE === false) { $_SESSION["SESS_SUBSCR_AUTH"][$ID] = "YES"; return true; } //anonymous subscription if ($subscr_arr["CONFIRM_CODE"] == $CONFIRM_CODE) { $_SESSION["SESS_SUBSCR_AUTH"][$ID] = "YES"; return true; } //user account subscription if (intval($subscr_arr["USER_ID"]) > 0) { if ($USER->IsAuthorized()) { //user is already authorized if ($USER->GetID() == $subscr_arr["USER_ID"]) { $_SESSION["SESS_SUBSCR_AUTH"][$ID] = "YES"; return true; } } } } $_SESSION["SESS_SUBSCR_AUTH"][$ID] = "NO"; return false; }
?> "> <input type="reset" name="Reset" value="<?php echo GetMessage("post_reset"); ?> "> <input type="hidden" name="search" value="search"> <input type="hidden" name="lang" value="<?php echo LANG; ?> "> <?php $tabControl->End(); $aEmail = array(); /*subscribers*/ $subscr = CSubscription::GetList(array("ID" => "ASC"), array("RUBRIC_MULTI" => $RUB_ID, "CONFIRMED" => "Y", "ACTIVE" => "Y", "FORMAT" => $SUBSCR_FORMAT, "EMAIL" => $EMAIL_FILTER)); while ($subscr_arr = $subscr->Fetch()) { $aEmail[$subscr_arr["EMAIL"]] = 1; } /*users by groups*/ if (is_array($GROUP_ID) && count($GROUP_ID) > 0) { $arFilter = array("ACTIVE" => "Y", "EMAIL" => $EMAIL_FILTER); if (!in_array(2, $GROUP_ID)) { $arFilter["GROUP_MULTI"] = $GROUP_ID; } $user = CUser::GetList($b = "id", $o = "asc", $arFilter); while ($user_arr = $user->Fetch()) { if (strlen($user_arr["EMAIL"]) > 0) { $aEmail[$user_arr["EMAIL"]] = 1; } }
<?php $s =& CSubscription::getInstance(); $subscriptions = $s->getSubscriptions($_USER_ID); $fv = new CFormValidator(); $fv->setForm('_subscriptionsForm'); $fv->addElement('email_1', 'Email', ' - Please enter at least one email address.', 'email'); $fv->setMaxElementsToDisplay(5); $fv->setDebugOutput(false); $fv->setFunctionName('_val_registration'); $fv->validate(); if (isset($_GET['message'])) { switch ($_GET['message']) { case 'added': $message = '<img src="images/icons/checkmark_16x16.png" class="png" width="16" height="16" hspace="5" align="absmiddle" />Email addresses have been added'; break; case 'deleted': $message = '<img src="images/icons/delete_16x16.png" class="png" width="16" height="16" hspace="5" align="absmiddle" />Email address has been deleted.'; break; } if ($message != '') { echo '<div class="confirm">' . $message . '</div>'; } } ?> <div class="f_12 bold"><img src="images/icons/network-wireless_22x22.png" class="png" width="22" height="22" align="absmiddle" /> Let others know when you add photos or create a slideshow</div> <div style="margin-left:25px; margin-top:25px;"> <div style="margin-bottom:5px;">When you add a photo or slideshow to your personal page the following people will receive an email.</div>
<?php if (isset($_REQUEST['SITE_ID'])) { define('SITE_ID', !empty($_REQUEST['SITE_ID']) ? $_REQUEST['SITE_ID'] : 's1'); } define("STOP_STATISTICS", true); define('NO_AGENT_CHECK', true); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; use Bitrix\Main\Localization\Loc; use RBCC\Helpers\Common\JS; Loc::loadMessages(__FILE__); $response = array('result' => false, 'title' => GetMessage('SUBSCRIBE_ERROR_TITLE'), 'message' => ''); global $USER; CModule::IncludeModule('subscribe'); if (!isset($_REQUEST['EMAIL']) || empty($_REQUEST['EMAIL'])) { $response['message'] = GetMessage('SUBSCRIBE_EMAIL_IS_EMPTY'); JS::ajax($response); } $subscription = new CSubscription(); $subId = $subscription->Add(array('USER_ID' => $USER->IsAuthorized() ? $USER->GetID() : false, 'EMAIL' => $_REQUEST['EMAIL'])); if ($subId) { @CSubscription::Authorize($subId); $response['result'] = true; $response['title'] = GetMessage('SUBSCRIBE_MESSAGE_TITLE'); $response['message'] = GetMessage('SUBSCRIBE_MESSAGE_TEXT', array('#EMAIL#' => $_REQUEST['EMAIL'])); JS::ajax($response); } else { $response['message'] = strip_tags($subscription->LAST_ERROR); JS::ajax($response); }
function GetEmails($post_arr) { $aEmail = array(); //send to categories $aPostRub = array(); $post_rub = CPostingGeneral::GetRubricList($post_arr["ID"]); while ($post_rub_arr = $post_rub->Fetch()) { $aPostRub[] = $post_rub_arr["ID"]; } $subscr = CSubscription::GetList(array("ID" => "ASC"), array("RUBRIC_MULTI" => $aPostRub, "CONFIRMED" => "Y", "ACTIVE" => "Y", "FORMAT" => $post_arr["SUBSCR_FORMAT"], "EMAIL" => $post_arr["EMAIL_FILTER"])); while ($subscr_arr = $subscr->Fetch()) { $aEmail[] = $subscr_arr["EMAIL"]; } //send to user groups $aPostGrp = array(); $post_grp = CPostingGeneral::GetGroupList($post_arr["ID"]); while ($post_grp_arr = $post_grp->Fetch()) { $aPostGrp[] = $post_grp_arr["ID"]; } if (count($aPostGrp) > 0) { $user = CUser::GetList($b = "id", $o = "asc", array("GROUP_MULTI" => $aPostGrp, "ACTIVE" => "Y", "EMAIL" => $post_arr["EMAIL_FILTER"])); while ($user_arr = $user->Fetch()) { $aEmail[] = $user_arr["EMAIL"]; } } //from additional emails $BCC = $post_arr["BCC_FIELD"]; if ($post_arr["DIRECT_SEND"] == "Y") { $BCC .= ($BCC != "" ? "," : "") . $post_arr["TO_FIELD"]; } if ($BCC != "") { $BCC = str_replace("\r\n", "\n", $BCC); $BCC = str_replace("\n", ",", Trim($BCC)); $aBcc = explode(",", $BCC); for ($i = 0; $i < count($aBcc); $i++) { if (Trim($aBcc[$i]) != "") { $aEmail[] = Trim($aBcc[$i]); } } } $aEmail = array_unique($aEmail); return $aEmail; }
} ?> ><label for="FORMAT_2">HTML</label></td> </tr> <tr> <td width="40%" class="adm-detail-valign-top"><?php echo GetMessage("subscr_rub"); ?> </td> <td width="60%"> <div class="adm-list"> <?php if ($bVarsFromForm) { $aSubscrRub = is_array($RUB_ID) ? $RUB_ID : array(); } else { $aSubscrRub = CSubscription::GetRubricArray($ID); } $rsRubrics = CRubric::GetList(array("LID" => "ASC", "SORT" => "ASC", "NAME" => "ASC"), array("ACTIVE" => "Y")); while ($arRubric = $rsRubrics->GetNext()) { ?> <div class="adm-list-item"> <div class="adm-list-control"><input type="checkbox" id="RUB_ID_<?php echo $arRubric["ID"]; ?> " name="RUB_ID[]" value="<?php echo $arRubric["ID"]; ?> "<?php if (in_array($arRubric["ID"], $aSubscrRub)) { echo " checked"; }
/** * @param int $iSubscriptionID * * @return array|bool */ public function getSubscriptionById($iSubscriptionID) { $mResult = false; if ($this->oConnection->Execute($this->oCommandCreator->getSubscriptionById($iSubscriptionID))) { $oRow = $this->oConnection->GetNextRecord(); if ($oRow && isset($oRow->id_tenant) && 0 < (int) $oRow->id_tenant) { $oSubscription = new CSubscription((int) $oRow->id_tenant); $oSubscription->InitByDbRow($oRow); $mResult = $oSubscription; } $this->oConnection->FreeResult(); } $this->throwDbExceptionIfExist(); return $mResult; }
<?php require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; CModule::IncludeModule('subscribe'); $rsRubric = CRubric::GetList(false, array('ACTIVE' => 'Y')); while ($rubric = $rsRubric->Fetch()) { $rubrics[] = $rubric['ID']; } $error = false; if (isset($_GET['email'])) { if (!check_email($_GET['email'])) { $error = 'Введен неверый Email адрес.'; } else { $fields = array('FORMAT' => 'html', 'EMAIL' => trim($_GET['email']), 'ACTIVE' => 'Y', 'CONFIRMED' => 'Y', 'RUB_ID' => $rubrics); } } else { if ($USER->isAuthorized()) { $fields = array('USER_ID' => $USER->GetId(), 'FORMAT' => 'html', 'EMAIL' => $USER->GetEmail(), 'ACTIVE' => 'Y', 'CONFIRMED' => 'Y', 'RUB_ID' => $rubrics); } } if (false === $error) { $subscr = new CSubscription(); $subscr->Add($fields); $error = !$subscr->LAST_ERROR ? 0 : $subscr->LAST_ERROR; } echo json_encode($error);
$rubSelect = array("SORT" => "ASC", "NAME" => "ASC"); $rubFilter = array("ACTIVE" => "Y", "VISIBLE" => "Y", 'NAME' => 'Акции'); $dbRub = CRubric::GetList($rubSelect, $rubFilter); while ($arRubric = $dbRub->GetNext()) { echo $rbkIDs[] = $arRubric["ID"]; } $RUB_ID = $rbkIDs; } $email = $_REQUEST["EMAIL"]; $ID = $USER->IsAuthorized() ? $USER->GetID() : false; //echo "DATACHECK ID=$ID, EMAIL=$email<br/>"; if ($ID || !empty($email)) { //echo "DATA_VALID<br/>"; if (empty($email)) { $email = $USER->GetEmail(); } $subscr = new CSubscription(); //echo "SEARCH SUBSCRIPTION<br/>"; $arSFields = array("USER_ID" => $ID, "FORMAT" => "html", "ACTIVE" => "Y", "EMAIL" => $email, "SEND_CONFIRM" => "N", "CONFIRMED" => "Y", "DATE_CONFIRM" => ConvertTimeStamp(time(), "SHORT", "ru"), "RUB_ID" => $RUB_ID, "SEND_CONFIRM" => "N"); $dbSubscr = CSubscription::GetByEmail($email); if ($arSubscr = $dbSubscr->GetNext()) { // echo "FOUND.UPDATE<br/>"; $result = $subscr->Update($arSubscr["ID"], $arSFields, "s1"); } else { // echo "NOT FOUND.ADD<br/>"; $result = $subscr->Add($arSFields, "s1"); // echo $subscr->LAST_ERROR; } } } // LocalRedirect($backUrl);
} else { /* определим рубрики активные рубрики подписок */ $RUB_ID = array(); $rub = CRubric::GetList(array(), array("ACTIVE" => "Y")); while ($rub->ExtractFields("r_")) { $RUB_ID = array($r_ID); } $RUB_ID = array('0' => '2'); /* создадим массив на подписку */ $subscr = new CSubscription(); $arFields = array("USER_ID" => $USER, "FORMAT" => "html/text", "EMAIL" => $EMAIL, "ACTIVE" => "Y", "RUB_ID" => $RUB_ID, "SEND_CONFIRM" => "Y", "CONFIRMED" => "Y"); if ($idsubrscr = $subscr->Add($arFields)) { $result = json_encode(array("result" => true, "value" => "Спасибо, вы подписались на рассылку", "action" => "subscribe")); } else { $result = json_encode(array("result" => false, "value" => "Данный адрес уже был подписан на рассылку", "action" => "subscribe")); } } } elseif ($_POST["email"] && $_POST["action"] == "remove") { $subscription = CSubscription::GetByEmail($_POST["email"]); if ($subscription->ExtractFields("str_")) { $ID = (int) $str_ID; } $subscr = new CSubscription(); if ($subscr->Update($ID, array("ACTIVE" => "N"))) { $result = json_encode(array("result" => true, "value" => "Вы отписались на рассылки", "action" => "unsubscribe")); } else { $result = json_encode(array("result" => false, "value" => "Произошла ошибка. ПОпробуйте позже", "action" => "unsubscribe")); } } echo $result; }
$arFields = array("ACTIVE" => $_REQUEST['action'] == "activate" ? "Y" : "N"); if (!$ob->Update($ID, $arFields)) { $lAdmin->AddGroupError(GetMessage("subscr_save_error") . $ob->LAST_ERROR, $ID); } break; case "confirm": $ob = new CSubscription(); $arFields = array("CONFIRMED" => "Y"); if (!$ob->Update($ID, $arFields)) { $lAdmin->AddGroupError(GetMessage("subscr_save_error") . $ob->LAST_ERROR, $ID); } break; } } } $cData = new CSubscription(); $rsData = $cData->GetList(array($by => $order), $arFilter, array("nPageSize" => CAdminResult::GetNavSize($sTableID))); $rsData = new CAdminResult($rsData, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("subscr_nav"))); $lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "id", "align" => "right", "default" => true), array("id" => "DATE_INSERT", "content" => GetMessage("POST_DATE_INSERT"), "sort" => "date_insert", "default" => true), array("id" => "EMAIL", "content" => GetMessage("subscr_addr"), "sort" => "email", "default" => true), array("id" => "USER_ID", "content" => GetMessage("subscr_user"), "sort" => "user", "default" => true), array("id" => "CONFIRMED", "content" => GetMessage("subscr_conf"), "sort" => "conf", "default" => true), array("id" => "ACTIVE", "content" => GetMessage("subscr_act"), "sort" => "act", "default" => true), array("id" => "FORMAT", "content" => GetMessage("subscr_fmt"), "sort" => "fmt", "default" => true), array("id" => "DATE_UPDATE", "content" => GetMessage("subscr_updated"), "sort" => "date_update", "default" => false), array("id" => "DATE_CONFIRM", "content" => GetMessage("subscr_conf_time"), "sort" => "date_confirm", "default" => false), array("id" => "CONFIRM_CODE", "content" => GetMessage("subscr_conf_code"), "sort" => "confirm_code", "default" => false))); while ($arRes = $rsData->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_ID, $arRes); if ($f_USER_ID > 0) { $strUser = "******"/bitrix/admin/user_edit.php?ID=" . $f_USER_ID . "&lang=" . LANG . "\" title=\"" . GetMessage("subscr_user_edit_title") . "\">" . $f_USER_ID . "</a>] (" . $f_USER_LOGIN . ") " . $f_USER_NAME . " " . $f_USER_LAST_NAME; } else { $strUser = GetMessage("subscr_adm_anon"); } $row->AddViewField("USER_ID", $strUser); $row->AddCheckField("ACTIVE"); $row->AddInputField("EMAIL", array("size" => 20));
ShowError(GetMessage("SUBSCR_NO_RUBRIC_FOUND")); return; } $arResult["FORM_ACTION"] = htmlspecialcharsbx(str_replace("#SITE_DIR#", LANG_DIR, $arParams["PAGE"])); $arResult["SHOW_COUNT"] = $arParams["SHOW_COUNT"]; if (strlen($arSubscription["EMAIL"]) > 0) { $arResult["EMAIL"] = htmlspecialcharsbx($arSubscription["EMAIL"]); } else { $arResult["EMAIL"] = htmlspecialcharsbx($USER->GetParam("EMAIL")); } //check whether already authorized $arResult["SHOW_PASS"] = true; if ($arSubscription["ID"] > 0) { //try to authorize user account's subscription if ($arSubscription["USER_ID"] > 0 && !CSubscription::IsAuthorized($arSubscription["ID"])) { CSubscription::Authorize($arSubscription["ID"], ""); } //check authorization if (CSubscription::IsAuthorized($arSubscription["ID"])) { $arResult["SHOW_PASS"] = false; } } $arResult["RUBRICS"] = array(); foreach ($arRubrics as $arRubric) { $bChecked = !is_array($_REQUEST["sf_RUB_ID"]) && in_array($arRubric["ID"], $arSubscriptionRubrics) || !is_array($_REQUEST["sf_RUB_ID"]) && intval($arSubscription["ID"]) == 0 || is_array($_REQUEST["sf_RUB_ID"]) && in_array($arRubric["ID"], $_REQUEST["sf_RUB_ID"]); $arResult["RUBRICS"][] = array("ID" => $arRubric["ID"], "NAME" => $arRubric["NAME"], "DESCRIPTION" => $arRubric["DESCRIPTION"], "CHECKED" => $bChecked, "SUBSCRIBER_COUNT" => $arRubric["SUBSCRIBER_COUNT"]); } if ($arParams["SET_TITLE"] == "Y") { $APPLICATION->SetTitle(GetMessage("SUBSCR_PAGE_TITLE"), array('COMPONENT_NAME' => $this->GetName())); } $this->IncludeComponentTemplate();
/** * [subscribeRegUser description] * @param str $email * @return bool */ function subscribeRegUser($email){ //require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); CModule::IncludeModule("subscribe"); $EMAIL = $email; global $USER; /* получим значение пользователя */ if ($USER->IsAuthorized()): $USER = $USER->GetID(); else: $USER = NULL ; endif; /* определим рубрики активные рубрики подписок */ $RUB_ID = array(); $rub = CRubric::GetList(array(), array("ACTIVE"=>"Y")); while($rub->ExtractFields("r_")): $RUB_ID = array($r_ID) ; endwhile; $RUB_ID = array('0' => '2'); /* создадим массив на подписку */ $subscr = new CSubscription; $arFields = Array( "USER_ID" => $USER, "FORMAT" => "html/text", "EMAIL" => $EMAIL, "ACTIVE" => "Y", "RUB_ID" => $RUB_ID, "SEND_CONFIRM" => "Y", "CONFIRMED" => "Y" ); if ($subscr->Add($arFields)) return true; return false; }
public function actionSubscribe() { $val = CRequest::getString("value"); // сначала удаляем if (!is_null(CSession::getCurrentUser()->getSubscription())) { CSession::getCurrentUser()->getSubscription()->remove(); } // теперь создадим, если нужно if ($val == "true") { $s = new CSubscription(); $s->user_id = CSession::getCurrentUser()->getId(); $s->save(); } }
$rubSelect = array("SORT" => "ASC", "NAME" => "ASC"); $rubFilter = array("ACTIVE" => "Y", "VISIBLE" => "Y", 'NAME' => 'Акции'); $dbRub = CRubric::GetList($rubSelect, $rubFilter); while ($arRubric = $dbRub->GetNext()) { echo $rbkIDs[] = $arRubric["ID"]; } $RUB_ID = $rbkIDs; } $email = $_REQUEST["EMAIL"]; $ID = $USER->IsAuthorized() ? $USER->GetID() : false; //echo "DATACHECK ID=$ID, EMAIL=$email<br/>"; if ($ID || !empty($email)) { //echo "DATA_VALID<br/>"; if (empty($email)) { $email = $USER->GetEmail(); } $subscr = new CSubscription(); //echo "SEARCH SUBSCRIPTION<br/>"; $arSFields = array("USER_ID" => $ID, "FORMAT" => "html", "ACTIVE" => "Y", "EMAIL" => $email, "SEND_CONFIRM" => "N", "CONFIRMED" => "Y", "DATE_CONFIRM" => ConvertTimeStamp(time(), "SHORT", "ru"), "RUB_ID" => $RUB_ID, "SEND_CONFIRM" => "N"); $dbSubscr = CSubscription::GetByEmail($email); if ($arSubscr = $dbSubscr->GetNext()) { // echo "FOUND.UPDATE<br/>"; $result = $subscr->Update($arSubscr["ID"], $arSFields, "#SITE_ID#"); } else { // echo "NOT FOUND.ADD<br/>"; $result = $subscr->Add($arSFields, "#SITE_ID#"); // echo $subscr->LAST_ERROR; } } } // LocalRedirect($backUrl);
$arParams["CACHE_TIME"] = 0; } if (!isset($arParams["PAGE"]) || strlen($arParams["PAGE"]) <= 0) { $arParams["PAGE"] = COption::GetOptionString("subscribe", "subscribe_section") . "subscr_edit.php"; } $arParams["SHOW_HIDDEN"] = $arParams["SHOW_HIDDEN"] == "Y"; $arParams["USE_PERSONALIZATION"] = $arParams["USE_PERSONALIZATION"] != "N"; if ($arParams["USE_PERSONALIZATION"]) { if (!CModule::IncludeModule("subscribe")) { ShowError(GetMessage("SUBSCR_MODULE_NOT_INSTALLED")); return; } //get current user subscription from cookies $arSubscription = CSubscription::GetUserSubscription(); //get user's newsletter categories $arSubscriptionRubrics = CSubscription::GetRubricArray(intval($arSubscription["ID"])); } else { $arSubscription = array("ID" => 0, "EMAIL" => ""); $arSubscriptionRubrics = array(); } //get site's newsletter categories $obCache = new CPHPCache(); $strCacheID = LANG . $arParams["SHOW_HIDDEN"]; if ($obCache->StartDataCache($arParams["CACHE_TIME"], $strCacheID, "/" . SITE_ID . $this->GetRelativePath())) { if (!CModule::IncludeModule("subscribe")) { $obCache->AbortDataCache(); ShowError(GetMessage("SUBSCR_MODULE_NOT_INSTALLED")); return; } $arFilter = array("ACTIVE" => "Y", "LID" => LANG); if (!$arParams["SHOW_HIDDEN"]) {
$arParams["SET_TITLE"] = "Y"; } $_REQUEST["CONFIRM_CODE"] = trim($_REQUEST["CONFIRM_CODE"]); //options $bAllowRegister = COption::GetOptionString("main", "new_user_registration") == "Y"; $sLastLogin = ${COption::GetOptionString("main", "cookie_name", "BITRIX_SM") . "_LOGIN"}; $ID = intval($_REQUEST["ID"]); // Id of the subscription //onscreen messages about actions $aMsg = array("UPD" => GetMessage("adm_upd_mess"), "SENT" => GetMessage("adm_sent_mess"), "SENTPASS" => GetMessage("subscr_pass_mess"), "CONF" => GetMessage("adm_conf_mess"), "UNSUBSCR" => GetMessage("adm_unsubscr_mess"), "ACTIVE" => GetMessage("subscr_active_mess")); if (array_key_exists($_REQUEST["mess_code"], $aMsg)) { $iMsg = $_REQUEST["mess_code"]; } else { $iMsg = ""; } $obSubscription = new CSubscription(); //************************* //settings form processing //************************* $arWarning = array(); $bVarsFromForm = false; if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_REQUEST["PostAction"]) && check_bitrix_sessid()) { $bDoSubscribe = true; $bVarsFromForm = true; if (!empty($_REQUEST["LOGIN"])) { //authorize the user $res = $USER->Login($_REQUEST["LOGIN"], $_REQUEST["PASSWORD"]); if ($res["TYPE"] == "ERROR") { $arWarning[] = $res["MESSAGE"]; } else { $bDoSubscribe = false;
die; } if (!CModule::IncludeModule("subscribe")) { ShowError(GetMessage("CC_BSS_MODULE_NOT_INSTALLED")); return; } if (!isset($arParams["CACHE_TIME"])) { $arParams["CACHE_TIME"] = 3600; } if ($arParams["SHOW_HIDDEN"] != "Y") { $arParams["SHOW_HIDDEN"] = "N"; } if ($arParams["SET_TITLE"] != "N") { $arParams["SET_TITLE"] = "Y"; } $obSubscription = new CSubscription(); $arResult["ERRORS"] = array(); $bVarsFromForm = false; if (is_object($USER) && $USER->GetID() > 0) { $USER_ID = $USER->GetID(); } else { ShowError(GetMessage("CC_BSS_NOT_AUTHORIZED")); return; } if ($USER_ID && $_SERVER["REQUEST_METHOD"] == "POST" && array_key_exists("Update", $_POST) && check_bitrix_sessid()) { //Find out what rubrics was chosen by the user $arNewRubrics = array(); if (is_array($_POST["RUB_ID"])) { foreach ($_POST["RUB_ID"] as $rub_id) { $rub_id = intval($rub_id); if ($rub_id > 0) {
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } ?> <div class="subscribe-edit"> <?php foreach ($arResult["MESSAGE"] as $itemID => $itemValue) { echo ShowMessage(array("MESSAGE" => $itemValue, "TYPE" => "OK")); } foreach ($arResult["ERROR"] as $itemID => $itemValue) { echo ShowMessage(array("MESSAGE" => $itemValue, "TYPE" => "ERROR")); } //whether to show the forms if ($arResult["ID"] == 0 && empty($_REQUEST["action"]) || CSubscription::IsAuthorized($arResult["ID"])) { //show confirmation form if ($arResult["ID"] > 0 && $arResult["SUBSCRIPTION"]["CONFIRMED"] != "Y") { include "confirmation.php"; } //show current authorization section if ($USER->IsAuthorized() && ($arResult["ID"] == 0 || $arResult["SUBSCRIPTION"]["USER_ID"] == 0)) { include "authorization.php"; } //show authorization section for new subscription /*if($arResult["ID"]==0 && !$USER->IsAuthorized()) { if($arResult["ALLOW_ANONYMOUS"]=="N" || ($arResult["ALLOW_ANONYMOUS"]=="Y" && $arResult["SHOW_AUTH_LINKS"]=="Y")) { include("authorization_new.php"); }
/** * Subscribe user by email * * @global object $APPLICATION * @param string $email * @return array */ public static function subscribe($email, $subscribeID, $siteID) { global $APPLICATION; $arResult["SUCCESS"] = true; $arFields = array("EMAIL" => $email, "FORMAT" => "html", "ACTIVE" => "Y", "RUB" => $subscribeID, "SEND_CONFIRM" => "Y", "CONFIRM_CODE" => self::GenerateConfirmCode(8)); if (!CModule::IncludeModule("subscribe")) { $arResult["SUCCESS"] = false; $arResult["MESSAGE"] = "Модуль подписок не установлен на сайте"; } $subscription = new CSubscription(); $sId = $subscription->Add($arFields, $siteID); $sId = intval($sId); if ($sId > 0) { $arResult["ID"] = $sId; $arResult["MESSAGE"] = "На указанный e-mail отправлено письмо для потверждения подписки"; } else { $arResult["SUCCESS"] = false; $arResult["MESSAGE"] = strip_tags($subscription->LAST_ERROR); } return $arResult; }
/** * Returns subscribers depended on side filter fields. * * @return \CDBResult */ public function getData() { $filter = array(); $rubric = $this->getFieldValue('RUBRIC', null); if ($rubric) { $filter['RUBRIC'] = $rubric; } $active = $this->getFieldValue('ACTIVE', null); if ($active) { $filter['ACTIVE'] = $active; } $confirmed = $this->getFieldValue('CONFIRMED', null); if ($confirmed) { $filter['CONFIRMED'] = $confirmed; } $dateInsertFrom = $this->getFieldValue('DATE_INSERT_FROM', null); if ($dateInsertFrom) { $filter['INSERT_1'] = $dateInsertFrom; } $dateInsertTo = $this->getFieldValue('DATE_INSERT_TO', null); if ($dateInsertTo) { $filter['INSERT_2'] = $dateInsertTo; } $subscriberList = \CSubscription::GetList(array('ID' => 'ASC'), $filter); return $subscriberList; }