Explorar o código

Modules updates. Invitations.

AntonLV %!s(int64=2) %!d(string=hai) anos
pai
achega
f1fdd87239

+ 51 - 51
modules/boonex/invites/updates/14.0.0_14.0.1/install/config.php

@@ -1,51 +1,51 @@
-<?php
-/**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- */
-
-$aConfig = array(
-    /**
-     * Main Section.
-     */
-    'title' => 'Invitations',
-    'version_from' => '14.0.0',
-    'version_to' => '14.0.1',
-    'vendor' => 'UNA INC',
-
-    'compatible_with' => array(
-        '14.0.0-A3'
-    ),
-
-    /**
-     * 'home_dir' and 'home_uri' - should be unique. Don't use spaces in 'home_uri' and the other special chars.
-     */
-    'home_dir' => 'boonex/invites/updates/update_14.0.0_14.0.1/',
-    'home_uri' => 'invites_update_1400_1401',
-
-    'module_dir' => 'boonex/invites/',
-    'module_uri' => 'invites',
-
-    'db_prefix' => 'bx_inv_',
-    'class_prefix' => 'BxInv',
-
-    /**
-     * Installation/Uninstallation Section.
-     */
-    'install' => array(
-        'execute_sql' => 0,
-        'update_files' => 1,
-        'update_languages' => 0,
-        'clear_db_cache' => 0,
-    ),
-
-    /**
-     * Category for language keys.
-     */
-    'language_category' => 'Invitations',
-
-    /**
-     * Files Section
-     */
-    'delete_files' => array(),
-);
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ */
+
+$aConfig = array(
+    /**
+     * Main Section.
+     */
+    'title' => 'Invitations',
+    'version_from' => '14.0.0',
+    'version_to' => '14.0.1',
+    'vendor' => 'UNA INC',
+
+    'compatible_with' => array(
+        '14.0.0-A3'
+    ),
+
+    /**
+     * 'home_dir' and 'home_uri' - should be unique. Don't use spaces in 'home_uri' and the other special chars.
+     */
+    'home_dir' => 'boonex/invites/updates/update_14.0.0_14.0.1/',
+    'home_uri' => 'invites_update_1400_1401',
+
+    'module_dir' => 'boonex/invites/',
+    'module_uri' => 'invites',
+
+    'db_prefix' => 'bx_inv_',
+    'class_prefix' => 'BxInv',
+
+    /**
+     * Installation/Uninstallation Section.
+     */
+    'install' => array(
+        'execute_sql' => 0,
+        'update_files' => 1,
+        'update_languages' => 0,
+        'clear_db_cache' => 0,
+    ),
+
+    /**
+     * Category for language keys.
+     */
+    'language_category' => 'Invitations',
+
+    /**
+     * Files Section
+     */
+    'delete_files' => array(),
+);

+ 13 - 13
modules/boonex/invites/updates/14.0.0_14.0.1/install/installer.php

@@ -1,13 +1,13 @@
-<?php
-/**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- */
-
-class BxInvUpdater extends BxDolStudioUpdater
-{
-    function __construct($aConfig)
-    {
-        parent::__construct($aConfig);
-    }
-}
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ */
+
+class BxInvUpdater extends BxDolStudioUpdater
+{
+    function __construct($aConfig)
+    {
+        parent::__construct($aConfig);
+    }
+}

+ 370 - 0
modules/boonex/invites/updates/14.0.0_14.0.1/source/classes/BxInvGridRequests.php

@@ -0,0 +1,370 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Invites Invites
+ * @ingroup     UnaModules
+ * 
+ * @{
+ */
+
+define('BX_INV_FILTER_STATUS_NEW', 0);
+define('BX_INV_FILTER_STATUS_INVITED', 1);
+define('BX_INV_FILTER_STATUS_SEEN', 2);
+define('BX_INV_FILTER_STATUS_JOINED', 3);
+
+class BxInvGridRequests extends BxTemplGrid
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    protected $_sFilter1Name;
+    protected $_sFilter1Value;
+    protected $_aFilter1Values;
+    protected $_sParamsDivider;
+    
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+        $this->_aQueryReset = array('order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
+        
+        $this->_sModule = 'bx_invites';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+        
+        $this->_sFilter1Name = 'filter1';
+        $this->_aFilter1Values = array(
+            '' => _t('_bx_invites_request_status_for_filter_all'),
+            BX_INV_FILTER_STATUS_NEW => _t('_bx_invites_request_status_for_filter_new'),
+            BX_INV_FILTER_STATUS_INVITED => _t('_bx_invites_request_status_for_filter_invited'),
+            BX_INV_FILTER_STATUS_SEEN => _t('_bx_invites_request_status_for_filter_seen'),
+            BX_INV_FILTER_STATUS_JOINED => _t('_bx_invites_request_status_for_filter_joined')
+        );
+        
+        $sFilter1 = bx_get($this->_sFilter1Name);
+        if(!empty($sFilter1)) {
+            $this->_sFilter1Value = bx_process_input($sFilter1);
+            $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
+        }
+        $this->_sParamsDivider = '#-#';
+    }
+    
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    {
+        $CNF = $this->_oModule->_oConfig->CNF;
+        $sTableRequests = $CNF['TABLE_REQUESTS'];
+        
+        if(strpos($sFilter, $this->_sParamsDivider) !== false)
+            list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
+       
+        $sFilterSql = "";
+        if(isset($this->_sFilter1Value) && $this->_sFilter1Value != ''){
+            if ($this->_sFilter1Value == BX_INV_FILTER_STATUS_INVITED){
+                $sFilterSql = " AND " . $sTableRequests . ".`status` IN (" . BX_INV_FILTER_STATUS_INVITED . ', ' . BX_INV_FILTER_STATUS_SEEN . ', ' . BX_INV_FILTER_STATUS_JOINED . ')';
+            }
+            else{
+                $sFilterSql = " AND " . $sTableRequests . ".`status` = " . $this->_sFilter1Value;
+            }
+        }
+        $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString($sFilterSql);
+        return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+    }
+    
+    protected function _getDataSqlOrderClause ($sOrderByFilter, $sOrderField, $sOrderDir, $bFieldsOnly = false)
+    {
+        return " ORDER BY `status` ASC, `date` DESC";
+    }
+    
+    public function performActionAdd()
+    {
+        $sAction = 'add';
+
+        $oForm = $this->_oModule->getFormObjectInvite();
+        if(!$oForm)
+            return $this->_getActionResult([]);
+
+        $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
+        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
+        $oForm->initChecker();
+
+        $aResult = [];
+        if($oForm->isSubmittedAndValid()) {
+            $aResult = ['msg' => $this->_oModule->processFormObjectInvite($oForm)];
+        }
+        else {
+            if($this->_bIsApi)
+                $aResult = $this->getFormBlockAPI($oForm, $sAction);
+            else
+                $aResult = ['popup' => [
+                    'html' => BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', [
+                        'form_id' => $oForm->id,
+                        'form' => $oForm->getCode(true),
+                        'object' => $this->_sObject,
+                        'action' => $sAction
+                    ])), 
+                    'options' => ['closeOnOuterClick' => true]
+                ]];
+        }
+
+        return $this->_getActionResult($aResult);
+    }
+    
+    public function performActionInfo()
+    {
+        $iId = $this->_getId();
+        if(!$iId)
+            return $this->_getActionResult([]);
+
+        $aRequest = $this->_oModule->_oDb->getRequests(['type' => 'by_id', 'value' => $iId]);
+        if(empty($aRequest) || !is_array($aRequest))
+            return $this->_getActionResult([]);
+
+        $sContent =  $this->_oModule->_oTemplate->getBlockRequestText($aRequest);
+
+        $aResult = [];
+        if($this->_bIsApi)
+            $aResult = [bx_api_get_block('simple_list',  $sContent)];
+        else
+            $aResult = ['popup' => [
+                'html' => BxTemplFunctions::getInstance()->transBox('bx-invites-info-popup', $sContent)
+            ]];
+
+        return $this->_getActionResult($aResult);
+    }
+
+    public function performActionInviteInfo()
+    {
+        $iId = $this->_getId();
+        if(!$iId)
+            return $this->_getActionResult([]);
+
+        $aRequest = $this->_oModule->_oDb->getInvites(['type' => 'all', 'value' => $iId]);
+        if(empty($aRequest) || !is_array($aRequest))
+            return $this->_getActionResult([]);
+
+        $sContent = $this->_oModule->_oTemplate->getBlockInviteInfo($aRequest);
+
+        $aResult = [];
+        if($this->_bIsApi)
+            $aResult = [bx_api_get_block('simple_list',  $sContent)];
+        else
+            $aResult = ['popup' => [
+                'html' => BxTemplFunctions::getInstance()->transBox('bx-invites-info-popup', $sContent)
+            ]];
+
+        return $this->_getActionResult($aResult);
+    }
+    
+    public function performActionInvite($aParams = [])
+    {
+        $iProfileId = $this->_oModule->getProfileId();
+
+        if(($mixedAllowed = $this->_oModule->isAllowedInvite($iProfileId)) !== true)
+            return echoJson(['msg' => $mixedAllowed]);
+
+        $aIds = $this->_getIds();
+        if(!$aIds)
+            return echoJson([]);
+
+        $sText = _t('_bx_invites_msg_invitation');
+
+        $iAffected = 0;
+        $aIdsAffected = [];
+        foreach($aIds as $iId) {
+            $aRequest = $this->_oModule->_oDb->getRequests(['type' => 'by_id', 'value' => $iId]);
+            if(empty($aRequest) || !is_array($aRequest))
+                continue;
+            
+            $mixedResult = $this->_oModule->invite(BX_INV_TYPE_FROM_SYSTEM, [$aRequest['email']], $sText, false);
+            if(empty($mixedResult) || !is_array($mixedResult))
+                continue;
+
+            $this->_oModule->_oDb->attachInviteToRequest($iId, (int)array_shift(array_keys($mixedResult)));
+
+            $aIdsAffected[] = $iId;
+            $iAffected++;
+        }
+        
+        $sResult = $iAffected ? _t('_bx_invites_msg_invitation_sent', $iAffected) : _t('_bx_invites_err_invite');
+
+        $aResult = [];
+        if($this->_bIsApi)
+            $aResult = [bx_api_get_block('simple_list',  [['text' => $sResult]])];
+        else 
+            $aResult = $iAffected ? ['grid' => $this->getCode(false), 'blink' => $aIdsAffected, 'msg' => $sResult] : ['msg' => $sResult];
+
+        return $this->_getActionResult($aResult);
+    }
+
+    public function performActionDelete($aParams = [])
+    {
+        $iProfileId = $this->_oModule->getProfileId();
+
+        if(($mixedAllowed = $this->_oModule->isAllowedDeleteRequest($iProfileId)) !== true)
+            return echoJson(['msg' => $mixedAllowed]);
+
+        $aIds = $this->_getIds();
+        if(!$aIds)
+            return echoJson([]);
+
+        $oForm = BxDolForm::getObjectInstance($this->_oModule->_oConfig->getObject('form_request'), $this->_oModule->_oConfig->getObject('form_display_request_send'));
+
+        $iAffected = 0;
+        $aIdsAffected = [];
+        foreach($aIds as $iId) {
+            if(!$oForm->delete($iId))
+                continue;
+
+            $this->_oModule->isAllowedDeleteRequest($iProfileId, true);
+
+            $aIdsAffected[] = $iId;
+            $iAffected++;
+        }
+
+        $aResult = [];
+        if($iAffected) 
+            $aResult = !$this->_bIsApi ? ['grid' => $this->getCode(false), 'blink' => $aIdsAffected] : [];
+        else
+            $aResult = ['msg' => _t('_bx_invites_err_delete_request')];
+
+        return $this->_getActionResult($aResult);
+    }
+
+    protected function _getFilterControls ()
+    {
+        parent::_getFilterControls();
+        return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
+    }
+
+    protected function _getSearchInput()
+    {
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+        $aInputSearch = array(
+            'type' => 'text',
+            'name' => 'search',
+            'attrs' => array(
+                'id' => 'bx-grid-search-' . $this->_sObject,
+                'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
+                'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
+            )
+        );
+
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInputSearch);
+    }
+    
+    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
+    {
+        if(empty($sFilterName) || empty($aFilterValues))
+            return '';
+
+        $CNF = &$this->_oModule->_oConfig->CNF;
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+
+        foreach($aFilterValues as $sKey => $sValue)
+            $aFilterValues[$sKey] = _t($sValue);
+
+        $aInputModules = array(
+            'type' => 'select',
+            'name' => $sFilterName,
+            'attrs' => array(
+                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
+                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
+            ),
+            'value' => $sFilterValue,
+            'values' => $aFilterValues
+        );
+
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInputModules);
+    }
+
+    protected function _getCellNip($mixedValue, $sKey, $aField, $aRow)
+    {
+        return parent::_getCellDefault(long2ip($mixedValue), $sKey, $aField, $aRow);
+    }
+
+    protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
+    {
+        if($this->_bIsApi)
+            return ['type' => 'time', 'data' => $mixedValue];
+
+        return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
+    }
+    
+    protected function _getCellStatus($mixedValue, $sKey, $aField, $aRow)
+    {
+        $sStatus = _t('_bx_invites_request_status_new');
+        switch ($mixedValue) {
+            case 1:
+            case 2:
+                $sLinkHtml = $this->_oTemplate->parseLink('javascript:void(0)', $this->_oModule->_oDb->getInvites(array('type' => 'count_by_request', 'value' => $aRow['id'])), array(
+                    'title' => _t('_bx_invites_grid_action_title_adm_invite_info'),
+                    'bx_grid_action_single' => 'invite_info',
+                    'bx_grid_action_data' => $aRow['id']
+                ));
+                $sStatus = ($mixedValue == 1 ? _t('_bx_invites_request_status_invited') : _t('_bx_invites_request_status_seen')) . ' (' . $sLinkHtml . ')';
+                break;
+            case 3:
+                $sStatus = _t('_bx_invites_request_status_joined') . ' (' . bx_time_js($this->_oModule->_oDb->getInvites(array('type' => 'date_joined_by_request', 'value' => $aRow['id']))) . ')';
+                break;
+        }
+        return parent::_getCellDefault($sStatus, $sKey, $aField, $aRow);
+    }
+    
+    protected function _getCellJoinedAccount($mixedValue, $sKey, $aField, $aRow)
+    {
+        $sAccountInfo = "";
+        if(isset($aRow["status"]) && $aRow["status"] == 3){
+            $sAccountInfo = $this->_oModule->_oTemplate->getProfilesByAccount($this->_oModule->_oDb->getInvites(array('type' => 'account_by_request', 'value' => $aRow['id'])));
+        }
+        return parent::_getCellDefault($sAccountInfo, $sKey, $aField, $aRow);
+    }
+    
+    protected function _getActionInvite($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if(isset($aRow["status"]) && $aRow["status"] == 3)
+            return '';
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
+    
+    protected function _getActionInviteInfo ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        return '';
+    }
+
+    protected function _getId()
+    {
+        $iId = 0;
+
+        if(($aIds = bx_get('ids')) !== false) {
+            if(!$aIds || !is_array($aIds))
+                return 0;
+
+            $iId = (int)array_shift($aIds);
+        }
+        else if(($iId = bx_get('id')) !== false)
+            $iId = (int)$iId;
+        
+        return $iId;
+    }
+
+    protected function _getIds()
+    {
+        $aIds = [];
+
+        if(($aIds = bx_get('ids')) !== false) {
+            if(!$aIds || !is_array($aIds))
+                return [];
+
+            $aIds = bx_process_input($aIds, BX_DATA_INT);
+        }
+        else if(($iId = bx_get('id')) !== false)
+            $aIds = [(int)$iId];
+
+        return $aIds;
+    }
+}
+
+/** @} */

+ 1 - 1
modules/boonex/invites/updates/14.0.0_14.0.1/source/classes/BxInvModule.php

@@ -454,7 +454,7 @@ class BxInvModule extends BxDolModule
 
 
                 $this->onInvite($iProfileId);
                 $this->onInvite($iProfileId);
 
 
-                $aResults[] = $sEmail;
+                $aResults[$iInviteId] = $sEmail;
                 if($mixedLimit !== false)
                 if($mixedLimit !== false)
                     $mixedLimit -= 1;
                     $mixedLimit -= 1;
             }
             }

+ 150 - 0
modules/boonex/invites/updates/14.0.0_14.0.1/source/classes/BxInvResponse.php

@@ -0,0 +1,150 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Invites Invites
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxInvResponse extends BxDolAlertsResponse
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->_sModule = 'bx_invites';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+    }
+
+    /**
+     * Overwtire the method of parent class.
+     *
+     * @param BxDolAlerts $oAlert an instance of alert.
+     */
+    public function response($oAlert)
+    {
+        $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
+        if(!method_exists($this, $sMethod))
+            return;
+
+        return $this->$sMethod($oAlert);
+    }
+
+    protected function _processAccountAddForm($oAlert)
+    {
+        if(!($sCode = $this->_oModule->serviceAccountAddFormCheck())) {
+            $sKeyCode = $this->_oModule->_oConfig->getKeyCode();
+            $sKeyValue = BxDolSession::getInstance()->getValue($sKeyCode);
+
+            $aInvite = $this->_oModule->_oDb->getInvites(['type' => 'by_key', 'key' => $sKeyValue]);
+            if(!empty($aInvite) && is_array($aInvite) && !empty($aInvite['redirect'])) {
+                $oAlert->aExtras['form_object']->aInputs['relocate'] = [
+                    'name' => 'relocate',
+                    'type' => 'hidden',
+                    'value' => BxDolPermalinks::getInstance()->permalink($aInvite['redirect'])
+                ];
+
+                $oAlert->aExtras['form_code'] = $oAlert->aExtras['form_object']->getCode();
+            }
+        }
+        else{
+            $oAlert->aExtras['form_code'] = $sCode;
+            $oAlert->aExtras['form_object'] = false;
+        }
+    }
+
+    protected function _processAccountAdded($oAlert)
+    {
+        $sKeyCode = $this->_oModule->_oConfig->getKeyCode();
+        $sKey = BxDolSession::getInstance()->getUnsetValue($sKeyCode);
+        if($sKey === false)
+            return;
+
+        $this->_oModule->attachAccountIdToInvite($oAlert->iObject, $sKey);
+        
+        $sKeysToRemove = $this->_oModule->_oDb->getInvites(array('type' => 'invites_code_by_single', 'value' => $sKey));
+        $aKeysToRemove = explode(',', $sKeysToRemove);
+        $oKeys = BxDolKey::getInstance();
+        if($oKeys){
+            foreach($aKeysToRemove as $sKeyToRemove) {
+                if($oKeys->isKeyExists($sKeyToRemove))
+                    $oKeys->removeKey($sKeyToRemove);
+            }
+        }
+        
+        return;
+    }
+
+    protected function _processProfileAdd($oAlert)
+    {
+        if (getParam('bx_invites_automatically_befriend') != 'on')
+            return;
+        
+		$bNeedToFriend = true;
+		bx_alert($this->_sModule, 'add_friend', 0, 0, [
+			'profile_id' => $oAlert->iObject,
+			'override_result' => &$bNeedToFriend,
+		]);
+		
+		if ($bNeedToFriend){
+			$oProfile = BxDolProfile::getInstanceMagic($oAlert->iObject);
+			if ($oProfile && $oProfile->isActAsProfile()){
+				$iProfileInvitor = $this->_oModule->_oDb->getInvites(array('type' => 'profile_id_by_joined_account_id', 'value' => $oProfile->getAccountId()));
+				if ($iProfileInvitor){
+					$oConnFrinds = BxDolConnection::getObjectInstance('sys_profiles_friends');
+					$oConnFrinds->addConnection($oAlert->iObject, $iProfileInvitor);
+					$oConnFrinds->addConnection($iProfileInvitor, $oAlert->iObject);
+				}
+			}  
+		}
+    }
+    
+    protected function _processProfileDelete($oAlert)
+    {
+        $this->_oModule->_oDb->deleteInvites(array('profile_id' => $oAlert->iObject));
+    }
+    
+    protected function _processAccountDelete($oAlert)
+    {
+        $this->_oModule->_oDb->deleteInvitesByAccount(array('joined_account_id' => $oAlert->iObject));
+    }
+    
+    protected function _processBxAnalyticsGetModules($oAlert)
+    {
+        $oAlert->aExtras['list'][$this->_oModule->_aModule['name']] = $this->_oModule->_aModule['title'];
+    }
+    
+    protected function _processBxAnalyticsGetReports($oAlert)
+    {
+        if ($this->_oModule->_aModule['name'] == $oAlert->aExtras['module']){
+            $oAlert->aExtras['list'] = array();
+            $oAlert->aExtras['list']['content_total_invited'] = _t('_bx_invites_reports_for_analytics_invited_total');
+            $oAlert->aExtras['list']['content_speed_invited'] = _t('_bx_invites_reports_for_analytics_invited_speed_grows');
+            $oAlert->aExtras['list']['content_total_invitation'] = _t('_bx_invites_reports_for_analytics_invitation_total');
+            $oAlert->aExtras['list']['content_speed_invitation'] = _t('_bx_invites_reports_for_analytics_invitation_speed_grows');
+        }
+    }
+    
+    protected function _processBxAnalyticsGetChartDataLine($oAlert)
+    {
+        if ($this->_oModule->_aModule['name'] == $oAlert->aExtras['module']){
+            $bIsInvited = false; 
+            if (substr_count($oAlert->aExtras['report_name'], '_invited') > 0)
+                $bIsInvited = true; 
+            
+            if (substr_count($oAlert->aExtras['report_name'], '_total_') > 0)
+                $oAlert->aExtras['report_type'] = BX_ANALYTICS_CONTENT_TOTAL;
+            
+            $oAlert->aExtras['data'] = $this->_oModule->_oDb->getDataForCharts($oAlert->aExtras['date_from'], $oAlert->aExtras['date_to'], $bIsInvited);
+            $oAlert->aExtras['prev_value'] = $this->_oModule->_oDb->getInitValueForCharts($oAlert->aExtras['date_from'], $bIsInvited);
+        }
+    }
+}
+
+/** @} */

+ 302 - 0
modules/boonex/invites/updates/14.0.0_14.0.1/source/classes/BxInvTemplate.php

@@ -0,0 +1,302 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Invites Invites
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxInvTemplate extends BxBaseModGeneralTemplate
+{
+    function __construct(&$oConfig, &$oDb)
+    {
+        parent::__construct($oConfig, $oDb);
+    }
+
+    public function getCssJs()
+    {
+        $this->addCss(array(
+            'main.css',
+        ));
+
+        $this->addJs(array(
+            'clipboard.min.js',
+            'jquery.form.min.js',
+            'jquery.anim.js',
+            'main.js'
+        ));
+    }
+
+    public function getInclude()
+    {
+        $this->getCssJs();
+        return $this->getJsCode('main');
+    }
+
+    public function getBlockRequestText($aRequest)
+    {
+        $sText = bx_process_output(nl2br($aRequest['text']), BX_DATA_TEXT_MULTILINE);
+        if($this->_bIsApi)
+            return [['text' => $sText]];
+
+        return $this->parseHtmlByName('request_text.html', array(
+            'style_prefix' => $this->_oConfig->getPrefix('style'),
+            'text' => $sText
+        ));
+    }
+    
+    public function getBlockInviteInfo($aRequest)
+    {
+        $aVars = array(
+            'date_sent_title' => _t('_bx_invites_title_date_invite_sent'),
+            'date_seen_title' => _t('_bx_invites_title_date_invite_seen'),
+            'bx_repeat:items' => array()
+        );
+        foreach ($aRequest as $r) {
+            $aVars['bx_repeat:items'][] = array (
+                 'date_sent' => bx_time_js($r['date'], BX_FORMAT_DATE_TIME, true),
+                 'date_seen' => ($r['date_seen'] != '' ? bx_time_js($r['date_seen'], BX_FORMAT_DATE_TIME, true) : ' - ')
+            );
+        }
+        return $this->parseHtmlByName('invite_info.html', $aVars);
+    }
+    
+    public function getBlockInvite($iAccountId, $iProfileId, $bRedirect = false)
+    {
+        $mInvitesRemain = $this->_oConfig->getCountPerUser();
+        if($mInvitesRemain === true)
+            $mInvitesRemain = _t('_bx_invites_txt_unlimited');
+        
+        $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_INVITE']));
+
+        if($bRedirect) {
+            $sRedirectCode = $this->_oConfig->getRedirectCode();
+
+            list($sPageLink, $aPageParams) = bx_get_base_url_inline();
+            $sRedirectValue = bx_append_url_params($sPageLink, $aPageParams);
+            if($this->_bIsApi){
+                $sRedirectValue = $aPageParams['params'][0];
+            }
+
+            $oSession = BxDolSession::getInstance();
+            if($oSession->isValue($sRedirectCode))
+                $oSession->unsetValue($sRedirectCode);
+            $oSession->setValue($sRedirectCode, $sRedirectValue);
+        }
+        
+        if($this->_bIsApi){
+            return [bx_api_get_block('invite', ['remain' => $mInvitesRemain, 'request_url' => 'bx_invites/get_link/'])];
+        }
+
+        $this->getCssJs();
+        return $this->parseHtmlByName('block_invite.html', [
+            'style_prefix' => $this->_oConfig->getPrefix('style'),
+            'js_object' => $this->_oConfig->getJsObject('main'),
+            'text' => _t('_bx_invites_txt_invite_block_text', $mInvitesRemain),
+            'url' => $sUrl,
+            'js_code' => $this->getJsCode('main')
+        ]);
+    }
+
+    public function getBlockRequest()
+    {
+        $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_REQUEST']));
+
+        $this->getCssJs();
+        return $this->parseHtmlByName('block_request.html', array(
+            'style_prefix' => $this->_oConfig->getPrefix('style'),
+            'text' => _t('_bx_invites_txt_request_block_text'),
+            'bx_if:show_button_request' => array(
+                'condition' => $this->_oConfig->isRequestInvite(),
+                'content' => array(
+                    'url' => $sUrl
+                )
+            )
+        ));
+    }
+    public function getBlockFormRequest()
+    {
+        if(!$this->_oConfig->isRequestInvite())
+            return $this->_bIsApi ? [bx_api_get_msg(_t('_bx_invites_err_not_available'))] : MsgBox(_t('_bx_invites_err_not_available'));
+
+        $mixedAllowed = $this->getModule()->isAllowedRequest(0);
+        if($mixedAllowed !== true)
+            return $this->_bIsApi ? [bx_api_get_msg($mixedAllowed)] : MsgBox($mixedAllowed);
+
+        $CNF = &$this->_oConfig->CNF;
+
+        $sJsObject = $this->_oConfig->getJsObject('main');
+        $oPermalink = BxDolPermalinks::getInstance();
+
+        $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_request'), $this->_oConfig->getObject('form_display_request_send'));
+        $oForm->aFormAttrs['action'] = bx_absolute_url($oPermalink->permalink($CNF['URL_REQUEST']));
+
+        $sFormId = $oForm->getId();
+        $sEval = $sJsObject . '.onRequestFormSubmit(oData)';
+
+        $oForm->initChecker();
+        if(!$oForm->isSubmittedAndValid()) {
+            $sForm = $oForm->getCode();
+            if(!$oForm->isSubmitted()) {
+                $this->getCssJs();
+                return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/get_block_form_request', 'immutable' => true]]])] : $this->parseHtmlByName('block_request_form.html', array(
+                    'style_prefix' => $this->_oConfig->getPrefix('style'),
+                    'js_object' => $sJsObject,
+                    'js_code' => $this->getJsCode('main'),
+                    'form' => $sForm,
+                    'form_id' => $sFormId,
+                ));
+            }
+
+            if(!$oForm->isValid())
+                return $this->_bIsApi ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_oModule->getName() . '/get_block_form_request', 'immutable' => true]]])] : array('content' => $sForm, 'content_id' => $sFormId, 'eval' => $sEval);
+        }
+        
+        $sEmail = $oForm->getCleanValue('email');
+        $oAccountQuery = BxDolAccountQuery::getInstance();
+        $iAccount = $oAccountQuery->getIdByEmail($sEmail);
+        if ($iAccount > 0)
+            return $this->_bIsApi ? [bx_api_get_msg(_t('_bx_invites_err_already_registed', bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password'))))] : array('content' => MsgBox(_t('_bx_invites_err_already_registed', bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password')))), 'content_id' => $sFormId, 'eval' => $sEval);
+        $iCountByEmail = $this->_oDb->getRequests(array('type' => 'count_by_email', 'value' => $sEmail));
+        if ($iCountByEmail > 0)
+            return  $this->_bIsApi ? [bx_api_get_msg(_t('_bx_invites_err_already_send'))] : array('content' => MsgBox(_t('_bx_invites_err_already_send')), 'content_id' => $sFormId, 'eval' => $sEval);
+       
+        $sIp = getVisitorIP();
+        $iId = (int)$oForm->insert(array('nip' => ip2long($sIp),'date' => time()));
+        if(!$iId)
+            return $this->_bIsApi ? [bx_api_get_msg(_t('_bx_invites_err_cannot_perform'))] : array('content' => MsgBox(_t('_bx_invites_err_cannot_perform')), 'content_id' => $sFormId, 'eval' => $sEval);
+        $this->getModule()->onRequest($iId);
+        $sRequestsEmail = $this->_oConfig->getRequestsEmail();
+        if(!empty($sRequestsEmail)) {
+            $sManageUrl = bx_absolute_url($oPermalink->permalink($CNF['URL_REQUESTS']));
+
+            $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('bx_invites_request_form_message', array(
+                'sender_name' => bx_process_output($oForm->getCleanValue('name')),
+                'sender_email' => bx_process_output($oForm->getCleanValue('email')),
+                'sender_ip' => $sIp,
+                'manage_url' => $sManageUrl
+            ));
+            
+            $aRequestsEmails = explode(',', $sRequestsEmail);
+            foreach ($aRequestsEmails as $s) {
+                sendMail(trim($s), $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM);
+            }
+        }
+
+        return $this->_bIsApi ? [bx_api_get_msg(_t('_bx_invites_msg_request_sent'))] : array('content' => MsgBox(_t('_bx_invites_msg_request_sent')), 'content_id' => $sFormId, 'eval' => $sEval);
+    }
+
+    public function getLinkPopup($sLink)
+    {
+        $sId = $this->_oConfig->getHtmlIds('link_popup');
+        $sTitle = _t('_bx_invites_txt_link_popup_title');
+        $sContent = $this->parseHtmlByName('popup_link.html', array(
+            'style_prefix' => $this->_oConfig->getPrefix('style'),
+            'html_id_link' => $this->_oConfig->getHtmlIds('link_input'),
+            'link' => $sLink
+        ));
+
+        return BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent, true);
+    }
+    
+    public function getJsCode($sType, $aParams = array(), $mixedWrap = true)
+    {
+        $sGrid = 'requests';
+        if(!empty($aParams['grid'])) {
+            $sGrid = $aParams['grid'];
+            unset($aParams['grid']);
+        }
+
+        $aParams = array_merge(array(
+            'aHtmlIds' => $this->_oConfig->getHtmlIds(),
+            'sObjNameGrid' => $this->_oConfig->getObject('grid_' . $sGrid),
+        ), $aParams);
+
+        return parent::getJsCode($sType, $aParams);
+    }
+
+    public function getMenuForManageBlocks($sType)
+    {
+        $CNF = &$this->_oConfig->CNF;
+        
+        $sMenu = '';
+		$oPermalink = BxDolPermalinks::getInstance();
+
+		$aMenuItems = array();
+		$aMenuItems[] = array('id' => 'invites-requests', 'name' => 'invites-requests', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_REQUESTS']), 'target' => '_self', 'title' => _t('_bx_invites_menu_item_title_manage_requests'), 'active' => 1);
+		$aMenuItems[] = array('id' => 'invites-invites', 'name' => 'invites-invites', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_INVITES']), 'target' => '_self', 'title' => _t('_bx_invites_menu_item_title_manage_invites'), 'active' => 1);
+
+		if(count($aMenuItems) > 1) {
+	        $oMenu = new BxTemplMenu(array(
+	            'template' => 'menu_vertical.html', 
+	            'menu_items' => $aMenuItems
+	        ), $this);
+	        $oMenu->setSelected($this->getModule()->_aModule['name'], 'invites-' . $sType);
+	        $sMenu = $oMenu->getCode();
+		}
+        return $sMenu;
+    }
+    
+    public function getProfilesByAccount($iAccountId, $iMaxVisible = 2)
+    {
+        $aProfiles = BxDolAccount::getInstance($iAccountId)->getProfiles();
+        $iProfiles = count($aProfiles);
+
+        $aTmplVars = array (
+            'class_cnt' => '',
+            'bx_repeat:profiles' => array(),
+            'bx_if:profiles_more' => array(
+                'condition' => $iProfiles > $iMaxVisible,
+                'content' => array(
+                    'html_id' => $this->_oConfig->getHtmlIds('profile_more_popup') . $iAccountId,
+                    'more' => _t('_bx_accnt_txt_more', $iProfiles - $iMaxVisible),
+                    'more_attr' => bx_html_attribute(_t('_bx_accnt_txt_see_more')),
+                    'popup' => '',
+                ),
+            ),
+        );
+
+        $aTmplVarsPopup = array (
+            'class_cnt' => ' bx-def-padding',
+            'bx_repeat:profiles' => array(),
+            'bx_if:profiles_more' => array(
+                'condition' => false,
+                'content' => array(),
+            ),
+        );
+
+        $i = 0;
+        foreach ($aProfiles as $iProfileId => $aProfile) {
+            $oProfile = BxDolProfile::getInstance($iProfileId);
+            if(!$oProfile)
+                continue;
+
+            $sName = $oProfile->getDisplayName();
+            $aTmplVarsProfile = array (
+                'html_id' => $this->_oConfig->getHtmlIds('profile') . $aProfile['id'],
+                'id' => $oProfile->id(),
+                'url' => $oProfile->getUrl(),
+                'name' => $sName,
+                'name_attr' => bx_html_attribute($sName)
+            );
+
+            if($i < $iMaxVisible)
+                $aTmplVars['bx_repeat:profiles'][] = $aTmplVarsProfile;
+            if($i >= $iMaxVisible)
+                $aTmplVarsPopup['bx_repeat:profiles'][] = $aTmplVarsProfile;
+
+            ++$i;
+        }
+
+        if($aTmplVarsPopup['bx_repeat:profiles']) {
+            $aTmplVars['bx_if:profiles_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', $this->parseHtmlByName('profiles.html', $aTmplVarsPopup));
+        }
+
+        return $this->parseHtmlByName('profiles.html', $aTmplVars);
+    }
+}
+
+/** @} */

+ 16 - 0
modules/boonex/invites/updates/14.0.0_14.0.1/source/template/invite_info.html

@@ -0,0 +1,16 @@
+<div class="bx-popup-width">
+    <div class="bx-def-padding">
+        <table style="width:100%;" >
+            <tr>
+                <td>__date_sent_title__</td>
+                <td>__date_seen_title__</td>
+            </tr>
+            <bx_repeat:items>
+                <tr>
+                    <td>__date_sent__</td>
+                    <td>__date_seen__</td>
+                </tr>
+            </bx_repeat:items>
+        </table>
+    </div>
+</div>