Esempio n. 1
0
require_once 'inc/header.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'utils.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'design.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'languages.inc.php';
require_once BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php';
bx_import('BxDolSubscription');
$oSubscription = new BxDolSubscription();
$aResult = array();
if (isset($_POST['direction'])) {
    $sUnit = process_db_input($_POST['unit']);
    $sAction = process_db_input($_POST['action']);
    $iObjectId = (int) $_POST['object_id'];
    switch ($_POST['direction']) {
        case 'subscribe':
            if (isset($_POST['user_id']) && (int) $_POST['user_id'] != 0) {
                $aResult = $oSubscription->subscribeMember((int) $_POST['user_id'], $sUnit, $sAction, $iObjectId);
            } else {
                if (isset($_POST['user_name']) && isset($_POST['user_email'])) {
                    $aResult = $oSubscription->subscribeVisitor($_POST['user_name'], $_POST['user_email'], $sUnit, $sAction, $iObjectId);
                }
            }
            break;
        case 'unsubscribe':
            if (isset($_POST['user_id']) && (int) $_POST['user_id'] != 0) {
                $aResult = $oSubscription->unsubscribeMember((int) $_POST['user_id'], $sUnit, $sAction, $iObjectId);
            } else {
                if (isset($_POST['user_name']) && isset($_POST['user_email'])) {
                    $aResult = $oSubscription->unsubscribeVisitor($_POST['user_name'], $_POST['user_email'], $sUnit, $sAction, $iObjectId);
                }
            }
            break;