AntonLV 7 лет назад
Родитель
Сommit
4c46406219

+ 6 - 1
inc/classes/BxDolAcl.php

@@ -543,7 +543,11 @@ class BxDolAcl extends BxDolFactory implements iBxDolSingleton
                 return true;
 
             // delete present and future memberships
-            return $this->oDb->deleteLevelByProfileId($iProfileId);
+            $bResult = $this->oDb->deleteLevelByProfileId($iProfileId);
+            if($bResult)
+                $this->oDb->cleanMemory('BxDolAclQuery::getLevelCurrent' . $iProfileId . time());
+
+            return $bResult;
         }
 
         if ((is_numeric($mixedPeriod) && (int)$mixedPeriod < 0) || (is_array($mixedPeriod) && (!isset($mixedPeriod['period']) || $mixedPeriod['period'] < 0)))
@@ -561,6 +565,7 @@ class BxDolAcl extends BxDolFactory implements iBxDolSingleton
             // Delete any profile's membership level and actions traces
             $this->oDb->deleteLevelByProfileId($iProfileId, true); 
             $this->oDb->clearActionsTracksForMember($iProfileId);
+            $this->oDb->cleanMemory('BxDolAclQuery::getLevelCurrent' . $iProfileId . time());
         }
 
         // set lifetime membership if 0 days is used.

+ 19 - 9
inc/js/functions.js

@@ -644,21 +644,31 @@ function bx_menu_show_live_update(oData) {
  * @param iAclLevel - acl level id to assign to a given rofile
  */
 function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
+    var bBulk = !$.isNumeric(iProfileId);
+    var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
 
-    if ('undefined' != typeof(mixedLoadingElement))
+    var bLoading = typeof(mixedLoadingElement) != 'undefined';
+    if(bLoading)
         bx_loading($(mixedLoadingElement), true);
 
-    $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', 'profile_id': iProfileId, 'acl_level_id': iAclLevel}, function(data) {
-
-        if ('undefined' != typeof(mixedLoadingElement))
+    $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, acl_level_id: iAclLevel, acl_card:iAclCard}, function(oData) {
+        if(bLoading)
             bx_loading($(mixedLoadingElement), false);
 
-        if (data.length) {
-            bx_alert(data);
-        } else if ($(mixedLoadingElement).hasClass('bx-popup-applied')) {
-            $(mixedLoadingElement).dolPopupHide().remove();
+        if(oData.msg != undefined && oData.msg.length) {
+            bx_alert(oData.msg);
+            return;
         }
-    });
+
+        if($(mixedLoadingElement).hasClass('bx-popup-applied'))
+            $(mixedLoadingElement).dolPopupHide().remove();
+
+        if(typeof(oData.card) == 'object')
+            for(var iField in oData.card) {
+                var oCard = $(oData.card[iField]);
+                $('#' + oCard.attr('id')).replaceWith(oCard);
+            }
+    }, 'json');
 }
 
 function validateLoginForm(eForm) {

+ 6 - 6
template/acl_membership.html

@@ -1,7 +1,7 @@
-<div class="bx-acl-membeship bx-def-font-align-center">
-	<h3 class="bx-acl-m-title">__level__</h3>
-	<p class="bx-acl-m-thumbnail">__thumbnail__</p>
-	<bx_if:show_private_info>
-		<p class="bx-acl-m-info bx-def-font-small"><bx_text:_sys_acl_start /> <b>__date_start__</b> <bx_text:_sys_acl_expire /> <b>__date_expire__</b></p>
-	</bx_if:show_private_info>
+<div id="__html_id__" class="bx-acl-membeship bx-def-font-align-center">
+    <div class="bx-acl-m-title bx-def-font-h3">__level__</div>
+    <div class="bx-acl-m-thumbnail bx-def-margin-sec-top">__thumbnail__</div>
+    <bx_if:show_private_info>
+        <div class="bx-acl-m-info bx-def-margin-sec-top bx-def-font-small"><bx_text:_sys_acl_start /> <b>__date_start__</b> <bx_text:_sys_acl_expire /> <b>__date_expire__</b></div>
+    </bx_if:show_private_info>
 </div>

+ 22 - 21
template/scripts/BxBaseAcl.php

@@ -18,37 +18,38 @@ class BxBaseAcl extends BxDolAcl
         parent::__construct ();
     }
 
-	public function getProfileMembership ($iProfileId)
+    public function getProfileMembership ($iProfileId)
     {
     	$aLevel = $this->getMemberMembershipInfo($iProfileId);
     	if(empty($aLevel) || !is_array($aLevel))
-    		return '';
+            return '';
 
-		$iUserId = bx_get_logged_profile_id();
-		$aLevelInfo = $this->getMembershipInfo($aLevel['id']);
+        $iUserId = bx_get_logged_profile_id();
+        $aLevelInfo = $this->getMembershipInfo($aLevel['id']);
 
-		$aTmplVarsPrivateInfo = array();
-		$bTmplVarsPrivateInfo = $iProfileId == $iUserId && !empty($aLevel['date_starts']);
-		if($bTmplVarsPrivateInfo)
-			$aTmplVarsPrivateInfo = array(
-				'date_start' => bx_time_js($aLevel['date_starts']),
-				'date_expire' => (int)$aLevel['date_expires'] > 0 ? bx_time_js($aLevel['date_expires']) : _t('_sys_acl_expire_never')
-			);
+        $aTmplVarsPrivateInfo = array();
+        $bTmplVarsPrivateInfo = $iProfileId == $iUserId && !empty($aLevel['date_starts']);
+        if($bTmplVarsPrivateInfo)
+            $aTmplVarsPrivateInfo = array(
+                'date_start' => bx_time_js($aLevel['date_starts']),
+                'date_expire' => (int)$aLevel['date_expires'] > 0 ? bx_time_js($aLevel['date_expires']) : _t('_sys_acl_expire_never')
+            );
 
-   		$oTemplate = BxDolTemplate::getInstance();
+        $oTemplate = BxDolTemplate::getInstance();
         $sContent = $oTemplate->parseHtmlByName('acl_membership.html', array(
-    		'level' => _t($aLevel['name']),
-    		'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail bx-def-border')),
-    		'bx_if:show_private_info' => array(
-    			'condition' => $bTmplVarsPrivateInfo,
-    			'content' => $aTmplVarsPrivateInfo
-    		)
+            'html_id' => 'sys-acl-profile-' . $iProfileId,
+            'level' => _t($aLevel['name']),
+            'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail bx-def-border')),
+            'bx_if:show_private_info' => array(
+                'condition' => $bTmplVarsPrivateInfo,
+                'content' => $aTmplVarsPrivateInfo
+            )
     	));
 
         bx_alert('system', 'page_output_block_acl_level', 0, false, array(
-        	'block_owner' => $iProfileId,
-			'block_code' => &$sContent
-		));
+            'block_owner' => $iProfileId,
+            'block_code' => &$sContent
+        ));
 
         $oTemplate->addCss(array('acl.css'));
     	return $sContent;

+ 29 - 18
template/scripts/BxBaseMenuSetAclLevel.php

@@ -24,12 +24,11 @@ class BxBaseMenuSetAclLevel extends BxTemplMenu
     	$this->mixedProfileId = $mixedProfileId;
 
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && ($mixedProfileId = bx_get('profile_id', 'post')) && ($iAclLevelId = bx_get('acl_level_id', 'post'))) {
-			$mixedProfileId = urldecode($mixedProfileId);
-			if(!is_numeric($mixedProfileId))
-				$mixedProfileId = unserialize($mixedProfileId);
+            $mixedProfileId = urldecode($mixedProfileId);
+            if(!is_numeric($mixedProfileId))
+                $mixedProfileId = unserialize($mixedProfileId);
 
-            header('Content-type: text/html; charset=utf-8');
-            echo $this->setMembership($mixedProfileId, $iAclLevelId);
+            echoJson($this->setMembership($mixedProfileId, $iAclLevelId, (int)bx_get('acl_card', 'post') > 0));
             exit;
         }
 
@@ -71,36 +70,48 @@ class BxBaseMenuSetAclLevel extends BxTemplMenu
                 'title' => $sTitle,
                 'icon' => '',
                 'link' => 'javascript:void(0);',
-                'onclick' => "bx_set_acl_level(" . (!$bBulk ? $mixedProfileId : "'" . urlencode(serialize($mixedProfileId)) . "'") . ", {$iId}, '.bx-popup-applied');"
+                'onclick' => "bx_set_acl_level(" . (!$bBulk ? $mixedProfileId : "'" . urlencode(serialize($mixedProfileId)) . "'") . ", {$iId}, " . bx_js_string("$(this).parents('.bx-popup-applied:first')") . ");"
             );
         }
 
         $this->_aObject['menu_items'] = $aItems;
     }
 
-    protected function setMembership($mixedProfileId, $iAclLevelId)
+    protected function setMembership($mixedProfileId, $iAclLevelId, $bAclCard = false)
     {
         bx_import('BxDolAcl');
 
         if(!is_array($mixedProfileId))
-        	$mixedProfileId = array($mixedProfileId);
+            $mixedProfileId = array($mixedProfileId);
 
 		$iPerformerId = bx_get_logged_profile_id();
         $aCheck = checkActionModule($iPerformerId, 'set acl level', 'system', false);
         if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
-			return $aCheck[CHECK_ACTION_MESSAGE];
+            return array('code' => 1, 'msg' => $aCheck[CHECK_ACTION_MESSAGE]);
 
-		$iSet = 0;
-		$oAcl = BxDolAcl::getInstance();
-		foreach($mixedProfileId as $iProfileId) {
-        	if(!$oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
-        		continue;
+        $iSet = 0;
+        $aCards = array();
+        $oAcl = BxDolAcl::getInstance();
+        foreach($mixedProfileId as $iProfileId) {
+            if(!$oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
+                continue;
 
-			$iSet += 1;
-			checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
-		}
+            $iSet += 1;
+            if($bAclCard)
+                $aCards[$iProfileId] = $oAcl->getProfileMembership($iProfileId);
+
+            checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
+        }
+
+        if(count($mixedProfileId) != $iSet)
+            return array('code' => 2, 'msg' => _t('_error occured'));
+        
+        
+        $aResult = array('code' => 0);
+        if($bAclCard)
+            $aResult['card'] = $aCards;
 
-		return count($mixedProfileId) != $iSet ? _t('_error occured') : '';
+        return $aResult;
     }
 }