BxBaseAcl.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Acl representation.
  11. * @see BxDolAcl
  12. */
  13. class BxBaseAcl extends BxDolAcl
  14. {
  15. public function __construct ()
  16. {
  17. parent::__construct ();
  18. }
  19. public function getProfileMembership ($iProfileId)
  20. {
  21. $aLevel = $this->getMemberMembershipInfo($iProfileId);
  22. if(empty($aLevel) || !is_array($aLevel))
  23. return '';
  24. $iLoggedProfileId = bx_get_logged_profile_id();
  25. $aLevelInfo = $this->getMembershipInfo($aLevel['id']);
  26. $aCheck = checkActionModule($iLoggedProfileId, 'show membership private info', 'system', false);
  27. $aTmplVarsPrivateInfo = array();
  28. $bTmplVarsPrivateInfo = ((BxDolProfile::getInstance($iProfileId)->getAccountId() == BxDolProfile::getInstance($iLoggedProfileId)->getAccountId() || $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) && !empty($aLevel['date_starts']));
  29. if($bTmplVarsPrivateInfo)
  30. $aTmplVarsPrivateInfo = array(
  31. 'date_start' => bx_time_js($aLevel['date_starts']),
  32. 'date_expire' => (int)$aLevel['date_expires'] > 0 ? bx_time_js($aLevel['date_expires']) : _t('_sys_acl_expire_never')
  33. );
  34. $oTemplate = BxDolTemplate::getInstance();
  35. $sContent = $oTemplate->parseHtmlByName('acl_membership.html', array(
  36. 'html_id' => 'sys-acl-profile-' . $iProfileId,
  37. 'level' => _t($aLevel['name']),
  38. 'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail bx-def-border')),
  39. 'bx_if:show_private_info' => array(
  40. 'condition' => $bTmplVarsPrivateInfo,
  41. 'content' => $aTmplVarsPrivateInfo
  42. )
  43. ));
  44. bx_alert('system', 'page_output_block_acl_level', 0, false, array(
  45. 'block_owner' => $iProfileId,
  46. 'block_code' => &$sContent
  47. ));
  48. $oTemplate->addCss(array('acl.css'));
  49. return $sContent;
  50. }
  51. /**
  52. * Print code for membership status
  53. * $iProfileId - ID of profile
  54. * $offer_upgrade - will this code be printed at [c]ontrol [p]anel
  55. */
  56. function GetMembershipStatus($iProfileId, $bOfferUpgrade = true)
  57. {
  58. $aMembershipInfo = $this->getMemberMembershipInfo($iProfileId);
  59. $sViewMembershipActions = "<br />(<a onclick=\"javascript:window.open('explanation.php?explain=membership&amp;type=".$aMembershipInfo['ID']."', '', 'width=660, height=500, menubar=no, status=no, resizable=no, scrollbars=yes, toolbar=no, location=no');\" href=\"javascript:void(0);\">"._t("_VIEW_MEMBERSHIP_ACTIONS")."</a>)<br />";
  60. // Show colored membership name
  61. $ret = '';
  62. if ( $aMembershipInfo['ID'] == MEMBERSHIP_ID_STANDARD || $aMembershipInfo['ID'] == MEMBERSHIP_ID_AUTHENTICATED) {
  63. $ret .= _t( "_MEMBERSHIP_STANDARD" ). $sViewMembershipActions;
  64. if ( $bOfferUpgrade )
  65. $ret .= " ". _t( "_MEMBERSHIP_UPGRADE_FROM_STANDARD" );
  66. } else {
  67. $ret .= "<font color=\"red\">{$aMembershipInfo['Name']}</font>$sViewMembershipActions";
  68. $days_left = (int)( ($aMembershipInfo['DateExpires'] - time()) / (24 * 3600) );
  69. if(!is_null($aMembershipInfo['DateExpires'])) {
  70. $ret .= ( $days_left > 0 ) ? _t( "_MEMBERSHIP_EXPIRES_IN_DAYS", $days_left ) : _t( "_MEMBERSHIP_EXPIRES_TODAY", date( "H:i", $aMembershipInfo['DateExpires'] ), date( "H:i" ) );
  71. } else {
  72. $ret.= _t("_MEMBERSHIP_EXPIRES_NEVER");
  73. }
  74. }
  75. return $ret;
  76. }
  77. }
  78. /** @} */