1
0
Эх сурвалжийг харах

Ticket #3732 - Pre-moderation for group based modules: Premoderation. Core changes.

AntonLV 4 жил өмнө
parent
commit
ee804848cc

+ 1 - 1
modules/base/files/classes/BxBaseModFilesFormUpload.php

@@ -75,7 +75,7 @@ class BxBaseModFilesFormUpload extends BxBaseModTextFormEntry
                     $CNF['FIELD_FOR_STORING_FILE_ID'] => $aFile['id'],
                     $CNF['FIELD_TITLE'] => $this->getCleanValue('title-' . $aFile['id']),
                     $CNF['FIELD_AUTHOR'] => bx_get('profile_id') && $this->_oModule->serviceIsAllowedAddContentToProfile(bx_get('profile_id')) ? bx_get('profile_id') : '',
-                    $CNF['FIELD_STATUS_ADMIN'] => !$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled() ? BX_BASE_MOD_TEXT_STATUS_PENDING : BX_BASE_MOD_TEXT_STATUS_ACTIVE
+                    $CNF['FIELD_STATUS_ADMIN'] => !$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled() ? BX_BASE_MOD_GENERAL_STATUS_PENDING : BX_BASE_MOD_TEXT_STATUS_ACTIVE
                 ), $aFormValues));
             if (!$iContentId)
                 continue;

+ 14 - 1
modules/base/general/classes/BxBaseModGeneralConfig.php

@@ -71,7 +71,20 @@ class BxBaseModGeneralConfig extends BxDolModuleConfig
     {
         return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
     }
-    
+
+    /**
+     * Is Auto Approve mode is available.
+     */
+    public function isAutoApprove()
+    {
+        return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
+    }
+
+    public function isAutoApproveEnabled()
+    {
+        return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
+    }
+
     public function isEqualUrls($sUrl1, $sUrl2)
     {
         $sUrl1 = trim($sUrl1, "/");

+ 3 - 1
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -460,8 +460,10 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
             }
         }
 
+        if(!$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled())
+            $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_GENERAL_STATUS_PENDING;
+
         $bMulticatEnabled = $this->_isMulticatEnabled();
-        
         if ($bMulticatEnabled)
             $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
 

+ 31 - 25
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -230,35 +230,41 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
     }
 
     protected function _enable ($mixedId, $isChecked)
+    {
+        return $this->__enable ($mixedId, $isChecked);
+    }
+
+    protected function __enable ($mixedId, $isChecked)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
         $mixedResult = parent::_enable($mixedId, $isChecked);
-        if((int)$mixedResult > 0) {
-            if(!empty($CNF['FIELD_CHANGED']))
-                $this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_CHANGED'] => time()), array($this->_aOptions['field_id'] => $mixedId));
-
-            $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
-
-            $this->_oModule->alertAfterEdit($aContentInfo);
-            
-            $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
-            $AuditParams = array(
-                'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
-                'context_profile_id' => $iContextId,
-                'content_info_object' =>  isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
-                'data' => $aContentInfo
-            );
-            if ($iContextId > 0)
-                $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
-            
-            bx_audit(
-                $mixedId, 
-                $this->_oModule->getName(), 
-                ($isChecked ? '_sys_audit_action_content_enabled': '_sys_audit_action_content_disabled'), 
-                $AuditParams
-            );
-        }
+        if(!$mixedResult) 
+            return $mixedResult;
+
+        if(!empty($CNF['FIELD_CHANGED']))
+            $this->_oModule->_oDb->updateEntriesBy([$CNF['FIELD_CHANGED'] => time()], [$this->_aOptions['field_id'] => $mixedId]);
+
+        $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
+
+        $this->_oModule->alertAfterEdit($aContentInfo);
+
+        $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
+        $AuditParams = [
+            'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
+            'context_profile_id' => $iContextId,
+            'content_info_object' =>  isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
+            'data' => $aContentInfo
+        ];
+        if ($iContextId > 0)
+            $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
+
+        bx_audit(
+            $mixedId, 
+            $this->_oModule->getName(), 
+            '_sys_audit_action_content_' . ($isChecked ? 'enabled': 'disabled'), 
+            $AuditParams
+        );
 
         return $mixedResult;
     }

+ 148 - 1
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -9,6 +9,10 @@
  * @{
  */
 
+define('BX_BASE_MOD_GENERAL_STATUS_ACTIVE', 'active');
+define('BX_BASE_MOD_GENERAL_STATUS_HIDDEN', 'hidden');
+define('BX_BASE_MOD_GENERAL_STATUS_PENDING', 'pending');
+
 bx_import('BxDolAcl');
 
 /**
@@ -42,6 +46,75 @@ class BxBaseModGeneralModule extends BxDolModule
 
     // ====== ACTIONS METHODS
 
+    public function isEntryActive($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
+            return true;
+
+        if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
+            return false;
+
+        if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
+            return false;
+
+        return true;        
+    }
+
+    public function actionApprove()
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!isset($CNF['FIELD_STATUS_ADMIN']))
+            return echoJson([]);
+
+        $iContentId = (int)bx_get('content_id');
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
+            return echoJson([]);
+
+        if(($mixedCheckResult = $this->checkAllowedApprove($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
+            return echoJson(['msg' => $mixedCheckResult]);
+
+        $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
+        $oForm->initChecker();
+
+        if(!$oForm->isSubmitted() || !$oForm->isValid()) {
+            $sPopupId = $this->getName() . '_approve_' . $iContentId;
+            $sPopupTitle = '_sys_manage_popup_approve_title';
+            if(!empty($CNF['T']['txt_approve_popup_title'])) 
+                $sPopupTitle = $CNF['T']['txt_approve_popup_title'];
+
+            return echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))]);
+        }
+
+        if($oForm->getCleanValue('do_send')) {
+            $aResult = [];
+            if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
+                $aResult = ['msg' => _t('_sys_manage_txt_sent')];
+            else
+                $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
+
+            return echoJson($aResult);
+        }
+
+        if($oForm->getCleanValue('do_submit')) {
+            $aResult = [];
+            if($this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_GENERAL_STATUS_ACTIVE], [$CNF['FIELD_ID'] => $iContentId])) {
+                $this->checkAllowedApprove($aContentInfo, true);
+
+                $this->onApprove($aContentInfo);
+
+                $aResult = ['msg' => _t('_sys_manage_txt_approved'), 'reload' => 1];
+            }
+            else
+                $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
+
+            return echoJson($aResult);
+        }
+    }
+
     public function actionRss ()
     {
         $aArgs = func_get_args();
@@ -120,7 +193,7 @@ class BxBaseModGeneralModule extends BxDolModule
         $oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate) . $sAddCode);
     }
    
-	public function subactionDelete()
+    public function subactionDelete()
     {
         header('Content-type: text/html; charset=utf-8');
 
@@ -2670,10 +2743,32 @@ class BxBaseModGeneralModule extends BxDolModule
         bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
     }
 
+    public function onApprove($mixedContent)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!is_array($mixedContent))
+            $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
+
+        $this->alertAfterApprove($mixedContent);
+
+        $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
+    }
+
     public function alertAfterAdd($aContentInfo) {}
     
     public function alertAfterEdit($aContentInfo) {}
 
+    public function alertAfterApprove($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
+
+        $aParams = $this->_alertParams($aContentInfo);
+        bx_alert($this->getName(), 'approved', $iId, false, $aParams);
+    }
+
     /**
      * Get array of params to be passed in Add/Edit Alert.
      */
@@ -2978,6 +3073,58 @@ class BxBaseModGeneralModule extends BxDolModule
             return $this->_oTemplate->$sFunc($aContentInfo);
     }
 
+    protected function _getApproveForm($iContentId, $aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $sForm = 'sys_manage';
+        if(!empty($CNF['OBJECT_FORM_MANAGE']))
+            $sForm = $CNF['OBJECT_FORM_MANAGE'];
+
+        $sFormDisplay = 'sys_manage_approve';
+        if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
+            $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
+
+        $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
+        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
+        $oForm->aInputs['content_id']['value'] = $iContentId;
+        foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
+            if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
+                $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
+
+        bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
+            'content_id' => $iContentId,
+            'content_info' => $aContentInfo,
+            'override_result' => &$oForm
+        ));
+
+        return $oForm;
+    }
+
+    protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $sETemplate = 't_ManageApprove';
+        if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
+            $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
+
+        $aEParams = array(
+            'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
+            'notes' => $oForm->getCleanValue('notes'),
+        );
+
+        bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
+            'content_id' => $iContentId,
+            'content_info' => $aContentInfo,
+            'form' => $oForm,
+            'email_template' => &$sETemplate,
+            'email_params' => &$aEParams
+        ));
+
+        return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
+    }
+
     protected function _rss ($aArgs, $sClass = 'SearchResult')
     {
         $sMode = array_shift($aArgs);

+ 53 - 3
modules/base/groups/classes/BxBaseModGroupsGridAdministration.php

@@ -19,9 +19,24 @@ class BxBaseModGroupsGridAdministration extends BxBaseModProfileGridAdministrati
     public function __construct ($aOptions, $oTemplate = false)
     {
         parent::__construct ($aOptions, $oTemplate);
-        
+
         $CNF = &$this->_oModule->_oConfig->CNF;
 
+        $this->_sStatusField = $CNF['FIELD_STATUS_ADMIN'];
+        $this->_aStatusValues = [
+            BX_BASE_MOD_GENERAL_STATUS_ACTIVE, 
+            BX_BASE_MOD_GENERAL_STATUS_HIDDEN, 
+            BX_BASE_MOD_GENERAL_STATUS_PENDING
+        ];
+
+        $this->_sFilter1Name = 'filter1';
+        $this->_aFilter1Values = [
+            BX_BASE_MOD_GENERAL_STATUS_ACTIVE => $CNF['T']['filter_item_active'],
+            BX_BASE_MOD_GENERAL_STATUS_HIDDEN => $CNF['T']['filter_item_hidden'],
+        ];
+        if($this->_oModule->_oConfig->isAutoApprove())
+            $this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
+
         if(($this->_bContentFilter = !empty($CNF['FIELD_CF'])) !== false) {
             $this->_sFilter2Name = 'filter2';
             $this->_aFilter2Values = BxDolFormQuery::getDataItems('sys_content_filter');
@@ -33,6 +48,41 @@ class BxBaseModGroupsGridAdministration extends BxBaseModProfileGridAdministrati
         }
     }
 
+    protected function _switcherChecked2State($isChecked)
+    {
+        return $isChecked ? BX_BASE_MOD_GENERAL_STATUS_ACTIVE : BX_BASE_MOD_GENERAL_STATUS_HIDDEN;
+    }
+
+    protected function _switcherState2Checked($mixedState)
+    {
+        return BX_BASE_MOD_GENERAL_STATUS_ACTIVE == $mixedState ? true : false;
+    }
+
+    protected function _enable ($mixedId, $isChecked)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $bStatusAdmin = $this->_sStatusField == $CNF['FIELD_STATUS_ADMIN'];
+
+        $sStatusBefore = '';
+        if($bStatusAdmin) {
+            $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
+            if(!empty($aContentInfo) && is_array($aContentInfo))
+                $sStatusBefore = $aContentInfo[$this->_sStatusField];
+        }
+
+        $mixedResult = parent::__enable($mixedId, $isChecked);
+        if((int)$mixedResult > 0) {
+            if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
+                $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
+                if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
+                    $this->_oModule->onApprove($aContentInfo);
+            }
+        }
+
+        return $mixedResult;
+    }
+
     protected function _getActionAuditContext($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')
@@ -47,7 +97,7 @@ class BxBaseModGroupsGridAdministration extends BxBaseModProfileGridAdministrati
         $sUrl = BX_DOL_URL_ROOT . 'page/audit-administration?context_id=' . $oProfile->id();
 
     	$a['attr'] = array_merge($a['attr'], array(
-    		"onclick" => "window.open('" . $sUrl . "','_audit');"
+            "onclick" => "window.open('" . $sUrl . "','_audit');"
     	));
 
     	return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
@@ -85,7 +135,7 @@ class BxBaseModGroupsGridAdministration extends BxBaseModProfileGridAdministrati
         }
 
     	if(!empty($this->_sFilter1Value))
-            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`status`=?", $this->_sFilter1Value);
+            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
 
         if(!empty($this->_sFilter2Value))
             $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);

+ 12 - 1
modules/base/groups/classes/BxBaseModGroupsGridCommon.php

@@ -15,12 +15,23 @@ class BxBaseModGroupsGridCommon extends BxBaseModGroupsGridAdministration
     {
         parent::__construct ($aOptions, $oTemplate);
 
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $this->_sStatusField = $CNF['FIELD_STATUS'];
+        $this->_aStatusValues = [
+            BX_BASE_MOD_GENERAL_STATUS_ACTIVE, 
+            BX_BASE_MOD_GENERAL_STATUS_HIDDEN
+        ];
+
+        if($this->_oModule->_oConfig->isAutoApprove() && isset($this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING]))
+            unset($this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING]);
+
         $this->_sManageType = BX_DOL_MANAGE_TOOLS_COMMON;
     }
 
     protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
     {
-		$this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`account_id`=?", getLoggedId());
+        $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`account_id`=?", getLoggedId());
 
         return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
     }

+ 23 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1488,6 +1488,29 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return $aParams;
     }
 
+    public function alertAfterAdd($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
+        $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
+
+        $sAction = 'added';
+        if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
+            $sAction = 'deferred';        
+
+        $sModule = $this->getName();
+        $aParams = $this->_alertParams($aContentInfo);
+        bx_alert('system', 'prepare_alert_params', 0, 0, [
+            'unit'=> $sModule, 
+            'action' => &$sAction, 
+            'object_id' => &$iId, 
+            'sender_id' => &$iAuthorId, 
+            'extras' => &$aParams
+        ]);
+        bx_alert($sModule, $sAction, $iId, false, $aParams);
+    }
+
     public function addFollower ($iProfileId1, $iProfileId2)
     {
         $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');

+ 14 - 0
modules/base/groups/classes/BxBaseModGroupsPageEntry.php

@@ -37,6 +37,15 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
         $oInformer = BxDolInformer::getInstance($this->_oTemplate);
         if($oInformer && ($bLoggedOwner || $bLoggedModerator)) {
             $sStatus = isset($CNF['FIELD_STATUS']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS']] : '';
+            $sStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']] : '';
+
+            //--- Display 'approving' informer.
+            if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
+                if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
+                    $aInformer = $CNF['INFORMERS']['approving'];
+                    $aInformers[] = ['name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']];
+                }
+            }
 
             //--- Display 'scheduled' informer if an item wasn't published yet.
             if(isset($CNF['FIELD_PUBLISHED'])) {
@@ -113,6 +122,11 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
         return $sCode;
     }
 
+    public function isActive()
+    {
+        return $this->_oModule->isEntryActive($this->_aContentInfo);
+    }
+
     public function getCode ()
     {
         return $this->_getInvitationCode() . parent::getCode();

+ 0 - 13
modules/base/text/classes/BxBaseModTextConfig.php

@@ -114,19 +114,6 @@ class BxBaseModTextConfig extends BxBaseModGeneralConfig
     {
         return $this->_bAttachmentsInTimeline;
     }
-
-    /**
-     * Is Auto Approve mode is available.
-     */
-    public function isAutoApprove()
-    {
-        return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
-    }
-
-    public function isAutoApproveEnabled()
-    {
-        return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
-    }
     
     public function getPregPattern($sType)
     {

+ 0 - 10
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -94,17 +94,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         
         parent::initChecker ($aValues, $aSpecificValues);
     }
-    
-    public function insert ($aValsToAdd = array(), $isIgnore = false)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
 
-        if(!$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled())
-            $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_TEXT_STATUS_PENDING;
-
-        return parent::insert($aValsToAdd, $isIgnore);
-    }
-    
     function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
     {
        return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);

+ 3 - 3
modules/base/text/classes/BxBaseModTextGridAdministration.php

@@ -34,7 +34,7 @@ class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
             BX_BASE_MOD_TEXT_STATUS_HIDDEN => $CNF['T']['filter_item_hidden'],
         );
         if($this->_oModule->_oConfig->isAutoApprove())
-            $this->_aFilter1Values[BX_BASE_MOD_TEXT_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
+            $this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
 
     	$sFilter1 = bx_get($this->_sFilter1Name);
         if(!empty($sFilter1)) {
@@ -78,9 +78,9 @@ class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
 
         $mixedResult = parent::_enable($mixedId, $isChecked);
         if((int)$mixedResult > 0) {
-            if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_TEXT_STATUS_PENDING) {
+            if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
                 $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
-                if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_TEXT_STATUS_ACTIVE)
+                if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
                     $this->_oModule->onApprove($aContentInfo);
             }
         }

+ 2 - 2
modules/base/text/classes/BxBaseModTextGridCommon.php

@@ -20,8 +20,8 @@ class BxBaseModTextGridCommon extends BxBaseModTextGridAdministration
         $this->_sStatusField = $CNF['FIELD_STATUS'];
         $this->_aStatusValues = array('active', 'hidden');
 
-        if($this->_oModule->_oConfig->isAutoApprove() && isset($this->_aFilter1Values[BX_BASE_MOD_TEXT_STATUS_PENDING]))
-            unset($this->_aFilter1Values[BX_BASE_MOD_TEXT_STATUS_PENDING]);
+        if($this->_oModule->_oConfig->isAutoApprove() && isset($this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING]))
+            unset($this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING]);
 
         $this->_sManageType = BX_DOL_MANAGE_TOOLS_COMMON;
     }

+ 6 - 125
modules/base/text/classes/BxBaseModTextModule.php

@@ -12,6 +12,10 @@
 define('BX_BASE_MOD_TEXT_STATUS_ACTIVE', 'active');
 define('BX_BASE_MOD_TEXT_STATUS_HIDDEN', 'hidden');
 define('BX_BASE_MOD_TEXT_STATUS_AWAITING', 'awaiting');
+/**
+ * Saved for backward compatibility.
+ * Can be removed in future releases of UNA 13.
+ */
 define('BX_BASE_MOD_TEXT_STATUS_PENDING', 'pending');
 
 /**
@@ -175,51 +179,6 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         $this->_oTemplate->embedSound($iFileId);
     }
 
-    public function actionApprove()
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        if(!isset($CNF['FIELD_STATUS_ADMIN']))
-            return echoJson(array());
-
-        $iContentId = (int)bx_get('content_id');
-        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
-        if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
-            return echoJson(array());
-
-        $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
-        $oForm->initChecker();
-
-        if(!$oForm->isSubmitted() || !$oForm->isValid()) {
-            $sPopupId = $this->getName() . '_approve_' . $iContentId;
-            $sPopupTitle = !empty($CNF['T']['txt_approve_popup_title']) ? $CNF['T']['txt_approve_popup_title'] : '_sys_manage_popup_approve_title';
-            return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))));
-        }
-
-        if($oForm->getCleanValue('do_send')) {
-            $aResult = array();
-            if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
-                $aResult = array('msg' => _t('_sys_manage_txt_sent'));
-            else
-                $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
-
-            return echoJson($aResult);
-        }
-
-        if($oForm->getCleanValue('do_submit')) {
-            $aResult = array();
-            if($this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $iContentId))) {
-                $this->onApprove($aContentInfo);
-
-                $aResult = array('msg' => _t('_sys_manage_txt_approved'), 'reload' => 1);
-            }
-            else
-                $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
-
-            return echoJson($aResult);
-        }
-    }
-
 
     // ====== SERVICE METHODS
 
@@ -646,7 +605,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         if(empty($mixedContent) || !is_array($mixedContent))
             return _t($sTxtError);
         
-        if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
+        if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
             return _t($sTxtError);
 
         if($this->_isModerator())
@@ -793,7 +752,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         $sAction = 'added';
         if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
             $sAction = 'deferred';
-        else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_TEXT_STATUS_PENDING)
+        else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
             $sAction = 'deferred';
 
         $aParams = $this->_alertParamsAdd($aContentInfo);
@@ -810,16 +769,6 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         $aParams = $this->_alertParams($aContentInfo);
         bx_alert($this->getName(), 'edited', $iId, false, $aParams);
     }
-    
-    public function alertAfterApprove($aContentInfo)
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
-
-        $aParams = $this->_alertParams($aContentInfo);
-        bx_alert($this->getName(), 'approved', $iId, false, $aParams);
-    }
 
     /**
      * Get array of params to be passed in Add/Edit Alert.
@@ -854,22 +803,6 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         return $aParams;
     }
 
-    public function isEntryActive($aContentInfo)
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
-            return true;
-
-        if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
-            return false;
-
-        if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
-            return false;
-
-        return true;        
-    }
-
     public function getPollForm()
     {
         $CNF = &$this->_oConfig->CNF;
@@ -921,58 +854,6 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
 
     // ====== PROTECTED METHODS
 
-    protected function _getApproveForm($iContentId, $aContentInfo)
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        $sForm = 'sys_manage';
-        if(!empty($CNF['OBJECT_FORM_MANAGE']))
-            $sForm = $CNF['OBJECT_FORM_MANAGE'];
-
-        $sFormDisplay = 'sys_manage_approve';
-        if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
-            $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
-
-        $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
-        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
-        $oForm->aInputs['content_id']['value'] = $iContentId;
-        foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
-            if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
-                $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
-
-        bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
-            'content_id' => $iContentId,
-            'content_info' => $aContentInfo,
-            'override_result' => &$oForm
-        ));
-
-        return $oForm;
-    }
-
-    protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        $sETemplate = 't_ManageApprove';
-        if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
-            $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
-
-        $aEParams = array(
-            'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
-            'notes' => $oForm->getCleanValue('notes'),
-        );
-
-        bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
-            'content_id' => $iContentId,
-            'content_info' => $aContentInfo,
-            'form' => $oForm,
-            'email_template' => &$sETemplate,
-            'email_params' => &$aEParams
-        ));
-
-        return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
-    }
-
     protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
     {
         $CNF = &$this->_oConfig->CNF;

+ 1 - 1
modules/base/text/classes/BxBaseModTextPageEntry.php

@@ -57,7 +57,7 @@ class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
             $sStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']] : '';
 
             //--- Display 'approving' informer.
-            if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_TEXT_STATUS_ACTIVE) {
+            if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
                 if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
                     $aInformer = $CNF['INFORMERS']['approving'];
                     $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']);