Cheetah
ChMbpTemplate.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbModuleTemplate');
9 
11 {
15  function __construct(&$oConfig, &$oDb)
16  {
17  parent::__construct($oConfig, $oDb);
18  }
19 
20  function displayCurrentLevel($aUserLevel)
21  {
22  $aLevelInfo = $this->_oDb->getMembershipsBy(array('type' => 'level_id', 'id' => $aUserLevel['ID']));
23  if(isset($aUserLevel['DateExpires']))
24  $sTxtExpiresIn = _t('_membership_txt_expires_in', floor(($aUserLevel['DateExpires'] - time())/86400));
25  else
26  $sTxtExpiresIn = _t('_membership_txt_expires_never');
27 
28  $this->addCss('levels.css');
29  $sContent = $this->parseHtmlByName('current.html', array(
30  'id' => $aLevelInfo['mem_id'],
31  'title' => $aLevelInfo['mem_name'],
32  'icon' => $this->_oConfig->getIconsUrl() . $aLevelInfo['mem_icon'],
33  'description' => str_replace("\$", "&#36;", $aLevelInfo['mem_description']),
34  'expires' => $sTxtExpiresIn
35  )
36  );
37 
38  return array($sContent, array(), array(), false);
39  }
40 
41  function displayAvailableLevels($aValues)
42  {
43  $sCurrencyCode = strtoupper($this->_oConfig->getCurrencyCode());
44  $sCurrencySign = $this->_oConfig->getCurrencySign();
45 
46  ch_import('ChWsbPayments');
47  $oPayment = ChWsbPayments::getInstance();
48 
49  $aMemberships = array();
50  foreach($aValues as $aValue) {
51  list($sJsCode, $sJsMethod) = $oPayment->getAddToCartJs(0, $this->_oConfig->getId(), $aValue['price_id'], 1, true);
52 
53  $aMemberships[] = array(
54  'level' => $this->parseHtmlByName('available_level.html', array(
55  'url_root' => CH_WSB_URL_ROOT,
56  'id' => $aValue['mem_id'],
57  'title' => $aValue['mem_name'],
58  'icon' => $this->_oConfig->getIconsUrl() . $aValue['mem_icon'],
59  'ch_if:show_description' => array(
60  'condition' => strlen($aValue['mem_description']) > 0,
61  'content' => array(
62  'description' => str_replace("\$", "&#36;", $aValue['mem_description']),
63  )
64  ),
65  'days' => $aValue['price_days'] > 0 ? $aValue['price_days'] . ' ' . _t('_membership_txt_days') : _t('_membership_txt_expires_never') ,
66  'price' => $aValue['price_amount'],
67  'currency_code' => $sCurrencyCode,
68  'add_to_cart_js' => $sJsMethod
69  ))
70  );
71  }
72 
73  $this->addCss(array('levels.css', 'levels_tablet.css', 'levels_phone.css'));
74  $sContent = $this->parseHtmlByName('available_levels.html', array(
75  'js_code' => $oPayment->getCartJs(),
76  'ch_repeat:levels' => $aMemberships
77  ));
78 
79  return array($sContent, array(), array(), false);
80  }
81 
82  function displaySelectLevelBlock($aLevels, $bDynamic = false)
83  {
84  $iModuleId = $this->_oConfig->getId();
85  $iSelectedLevel = $iSelectedProvider = 0;
86 
87  $sCurrencyCode = strtoupper($this->_oConfig->getCurrencyCode());
88  $sCurrencySign = $this->_oConfig->getCurrencySign();
89 
90  ch_import('ChWsbPayments');
91  $oPayment = ChWsbPayments::getInstance();
92 
93  $aProviders = $oPayment->getProviders(0);
94  if(empty($aProviders))
95  return array(MsgBox(_t('_membership_err_no_payment_options')));
96 
97  //--- Prepare levels
98  $aTmplVarsLevels = array();
99  foreach($aLevels as $iIndex => $aLevel) {
100  $bPaid = (int)$aLevel['price_amount'] > 0;
101 
102  $iPriceDays = (int)$aLevel['price_days'];
103  $fPriceAmount = (float)$aLevel['price_amount'];
104 
105  $aTmplVarsLevels[] = array(
106  'level' => $this->parseHtmlByName('select_level.html', array(
107  'js_object' => $this->_oConfig->getJsObject('join'),
108  'id' => $aLevel['mem_id'],
109  'descriptor' => (int)$aLevel['mem_id'] == MEMBERSHIP_ID_STANDARD ? $this->_oConfig->getStandardDescriptor() : $oPayment->getCartItemDescriptor(0, $iModuleId, $aLevel['price_id'], 1),
110  'checked' => $iIndex == $iSelectedLevel ? 'checked="checked"' : '',
111  'title' => $aLevel['mem_name'],
112  'icon' => $this->_oConfig->getIconsUrl() . $aLevel['mem_icon'],
113  'ch_if:show_description' => array(
114  'condition' => strlen($aLevel['mem_description']) > 0,
115  'content' => array(
116  'description' => str_replace("\$", "&#36;", $aLevel['mem_description']),
117  )
118  ),
119  'days' => $iPriceDays > 0 ? $iPriceDays . ' ' . _t('_membership_txt_days') : _t('_membership_txt_expires_never'),
120  'price' => $fPriceAmount,
121  'ch_if:show_price_paid' => array(
122  'condition' => $bPaid,
123  'content' => array(
124  'price' => $fPriceAmount,
125  'currency_code' => $sCurrencyCode,
126  )
127  ),
128  'ch_if:show_price_free' => array(
129  'condition' => !$bPaid,
130  'content' => array()
131  )
132  ))
133  );
134  }
135 
136  //--- Prepare providers
137  $aTmplVarsProviders = array();
138  if(!empty($aProviders))
139  foreach($aProviders as $iIndex => $aProvider) {
140  if((int)$aProvider['for_visitor'] != 1)
141  continue;
142 
143  $aTmplVarsProviders[] = array(
144  'name' => $aProvider['name'],
145  'caption' => $aProvider['caption_cart'],
146  'checked' => $iIndex == $iSelectedProvider ? 'checked="checked"' : ''
147  );
148  }
149  if(empty($aTmplVarsProviders))
150  return array(MsgBox(_t('_membership_err_no_payment_options')));
151 
152  $bSelectedLevelPaid = (int)$aLevels[$iSelectedLevel]['price_amount'] > 0;
153 
154  $bSelectedProvider = count($aTmplVarsProviders) == 1;
155  $sSelectedProvider = $bSelectedProvider ? $aTmplVarsProviders[0]['name'] : '';
156 
157  //--- Prepare captcha
158  $sCaptcha = '';
159  $bCaptcha = $this->_oConfig->isCaptchaOnPaidJoin();
160  if($bCaptcha) {
161  ch_import('ChWsbCaptcha');
162  $oCaptcha = ChWsbCaptcha::getObjectInstance();
163  $sCaptcha = $oCaptcha ? $oCaptcha->display($bDynamic) : _t('_sys_txt_captcha_not_available');
164  }
165 
166  $aTmplParams = array(
167  'js_object' => $this->_oConfig->getJsObject('join'),
168  'js_code' => $this->getJsCode('join', true),
169  'submit_url' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'join_submit',
170  'ch_repeat:levels' => $aTmplVarsLevels,
171  'ch_if:show_providers_selector' => array(
172  'condition' => !$bSelectedProvider,
173  'content' => array(
174  'ch_if:show_providers_selector_hidden' => array(
175  'condition' => !$bSelectedLevelPaid,
176  'content' => array()
177  ),
178  'ch_repeat:providers' => $aTmplVarsProviders
179  )
180  ),
181  'ch_if:show_captcha' => array(
182  'condition' => $bCaptcha,
183  'content' => array(
184  'captcha' => $sCaptcha
185  )
186  ),
187  'ch_if:show_selected_provider' => array(
188  'condition' => $bSelectedProvider,
189  'content' => array(
190  'name' => $sSelectedProvider
191  )
192  ),
193  'txt_checkout' => _t($bSelectedLevelPaid ? '_membership_btn_pay' : '_membership_btn_select')
194  );
195 
196  $sCssJs = '';
197  $sCssJs .= $this->addCss(array('levels.css', 'levels_tablet.css', 'levels_phone.css'), $bDynamic);
198  $sCssJs .= $this->addJs('join.js', $bDynamic);
199 
200  $this->addJsTranslation(array('_membership_err_need_select_level', '_membership_err_need_select_provider'));
201  return array(($bDynamic ? $sCssJs : '') . $this->parseHtmlByName('select_level_block.html', $aTmplParams), array(), array(), false);
202  }
203 
204  function getPageCodeAdmin(&$aParams)
205  {
206  global $_page;
208 
209  $iIndex = isset($aParams['index']) ? (int)$aParams['index'] : 9;
210  $_page['name_index'] = $iIndex;
211  $_page['js_name'] = isset($aParams['js']) ? $aParams['js'] : '';
212  $_page['css_name'] = isset($aParams['css']) ? $aParams['css'] : '';
213  $_page['header'] = isset($aParams['title']['page']) ? $aParams['title']['page'] : '';
214 
215  if(isset($aParams['content']))
216  foreach($aParams['content'] as $sKey => $sValue)
217  $_page_cont[$iIndex][$sKey] = $sValue;
218 
219  PageCodeAdmin();
220  }
221 
222  function getPageCode(&$aParams)
223  {
224  global $_page;
226 
227  $iIndex = isset($aParams['index']) ? (int)$aParams['index'] : 0;
228  $_page['name_index'] = $iIndex;
229  $_page['js_name'] = isset($aParams['js']) ? $aParams['js'] : '';
230  $_page['css_name'] = isset($aParams['css']) ? $aParams['css'] : '';
231  $_page['extra_js'] = isset($aParams['extra_js']) ? $aParams['extra_js'] : '';
232 
233  check_logged();
234 
235  if(isset($aParams['content']))
236  foreach($aParams['content'] as $sKey => $sValue)
237  $_page_cont[$iIndex][$sKey] = $sValue;
238 
239  if(isset($aParams['title']['page']))
240  $this->setPageTitle($aParams['title']['page']);
241  if(isset($aParams['title']['block']))
242  $this->setPageMainBoxTitle($aParams['title']['block']);
243 
244  if(isset($aParams['breadcrumb']))
245  $GLOBALS['oTopMenu']->setCustomBreadcrumbs($aParams['breadcrumb']);
246 
247  PageCode($this);
248  }
249 
251  {
252  $aParams = array(
253  'title' => array(
254  'page' => _t('_membership_pcaption_error'),
255  'block' => _t('_membership_bcaption_error')
256  ),
257  'content' => array(
258  'page_main_code' => MsgBox(_t($sMessage))
259  )
260  );
261  $this->getPageCode($aParams);
262  }
263 
264  function getJsCode($sType, $bWrap = false)
265  {
266  $sJsObject = $this->_oConfig->getJsObject($sType);
267  $sJsClass = $this->_oConfig->getJsClass($sType);
268 
269  $aOptions = array(
270  'sActionUrl' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri(),
271  'sObjName' => $sJsObject,
272  'sAnimationEffect' => $this->_oConfig->getAnimationEffect(),
273  'iAnimationSpeed' => $this->_oConfig->getAnimationSpeed(),
274  'sTxtPay' => ch_js_string(_t('_membership_btn_pay')),
275  'sTxtSelect' => ch_js_string(_t('_membership_btn_select')),
276  'sErrSelectLevel' => ch_js_string(_t('_membership_err_need_select_level')),
277  'sErrSelectProvider' => ch_js_string(_t('_membership_err_need_select_provider'))
278  );
279 
280  $sContent .= 'var ' . $sJsObject . ' = new ' . $sJsClass . '(' . json_encode($aOptions) . ');';
281 
282  return $bWrap ? $this->_wrapInTagJsCode($sContent) : $sContent;
283  }
284 }
$sMessage
$sMessage
Definition: actions.inc.php:17
ChMbpTemplate\getPageCode
getPageCode(&$aParams)
Definition: ChMbpTemplate.php:222
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
check_logged
check_logged()
Definition: admin.inc.php:238
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
ChMbpTemplate\getPageCodeError
getPageCodeError($sMessage)
Definition: ChMbpTemplate.php:250
$_page
$_page['name_index']
Definition: about_us.php:13
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$_page_cont
$_page_cont[$_ni]['page_main_code']
Definition: about_us.php:24
ChWsbTemplate\addCss
addCss($mixedFiles, $bDynamic=false)
Definition: ChWsbTemplate.php:1114
ChMbpTemplate\getJsCode
getJsCode($sType, $bWrap=false)
Definition: ChMbpTemplate.php:264
php
MEMBERSHIP_ID_STANDARD
const MEMBERSHIP_ID_STANDARD
Definition: membership_levels.inc.php:49
ChMbpTemplate
Definition: ChMbpTemplate.php:11
ChMbpTemplate\__construct
__construct(&$oConfig, &$oDb)
Definition: ChMbpTemplate.php:15
ChWsbPayments\getInstance
static getInstance()
Definition: ChWsbPayments.php:31
$sType
$sType
Definition: actions.inc.php:11
ChMbpTemplate\displayAvailableLevels
displayAvailableLevels($aValues)
Definition: ChMbpTemplate.php:41
ChWsbTemplate\_wrapInTagJsCode
_wrapInTagJsCode($sCode)
Definition: ChWsbTemplate.php:1102
$iIndex
$iIndex
Definition: bottom_menu_compose.php:142
ChWsbTemplate\addJsTranslation
addJsTranslation($mixedKey)
Definition: ChWsbTemplate.php:447
ChWsbCaptcha\getObjectInstance
static getObjectInstance($sObject=false)
Definition: ChWsbCaptcha.php:74
$oDb
global $oDb
Definition: db.inc.php:39
ChMbpTemplate\displaySelectLevelBlock
displaySelectLevelBlock($aLevels, $bDynamic=false)
Definition: ChMbpTemplate.php:82
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
PageCode
PageCode($oTemplate=null)
Definition: design.inc.php:91
ChWsbTemplate\addJs
addJs($mixedFiles, $bDynamic=false)
Definition: ChWsbTemplate.php:999
ChMbpTemplate\displayCurrentLevel
displayCurrentLevel($aUserLevel)
Definition: ChMbpTemplate.php:20
ChWsbModuleTemplate
Definition: ChWsbModuleTemplate.php:11
ChWsbTemplate\setPageMainBoxTitle
setPageMainBoxTitle($sTitle)
Definition: ChWsbTemplate.php:416
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbTemplate\setPageTitle
setPageTitle($sTitle)
Definition: ChWsbTemplate.php:407
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbTemplate\parseHtmlByName
parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml=null, $sCheckIn=CH_WSB_TEMPLATE_CHECK_IN_BOTH)
Definition: ChWsbTemplate.php:660
ChMbpTemplate\getPageCodeAdmin
getPageCodeAdmin(&$aParams)
Definition: ChMbpTemplate.php:204
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10