BxBaseAcl.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 UnaCoreBaseRepresentation UNA Core 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. $iUserId = bx_get_logged_profile_id();
  25. $aLevelInfo = $this->getMembershipInfo($aLevel['id']);
  26. $aTmplVarsPrivateInfo = array();
  27. $bTmplVarsPrivateInfo = $iProfileId == $iUserId && !empty($aLevel['date_starts']);
  28. if($bTmplVarsPrivateInfo)
  29. $aTmplVarsPrivateInfo = array(
  30. 'date_start' => bx_time_js($aLevel['date_starts']),
  31. 'date_expire' => (int)$aLevel['date_expires'] > 0 ? bx_time_js($aLevel['date_expires']) : _t('_sys_acl_expire_never')
  32. );
  33. $oTemplate = BxDolTemplate::getInstance();
  34. $sContent = $oTemplate->parseHtmlByName('acl_membership.html', array(
  35. 'level' => _t($aLevel['name']),
  36. 'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail bx-def-border')),
  37. 'bx_if:show_private_info' => array(
  38. 'condition' => $bTmplVarsPrivateInfo,
  39. 'content' => $aTmplVarsPrivateInfo
  40. )
  41. ));
  42. bx_alert('system', 'page_output_block_acl_level', 0, false, array(
  43. 'block_owner' => $iProfileId,
  44. 'block_code' => &$sContent
  45. ));
  46. $oTemplate->addCss(array('acl.css'));
  47. return $sContent;
  48. }
  49. /**
  50. * Print code for membership status
  51. * $iProfileId - ID of profile
  52. * $offer_upgrade - will this code be printed at [c]ontrol [p]anel
  53. */
  54. function GetMembershipStatus($iProfileId, $bOfferUpgrade = true)
  55. {
  56. $aMembershipInfo = $this->getMemberMembershipInfo($iProfileId);
  57. $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 />";
  58. // Show colored membership name
  59. $ret = '';
  60. if ( $aMembershipInfo['ID'] == MEMBERSHIP_ID_STANDARD || $aMembershipInfo['ID'] == MEMBERSHIP_ID_AUTHENTICATED) {
  61. $ret .= _t( "_MEMBERSHIP_STANDARD" ). $sViewMembershipActions;
  62. if ( $bOfferUpgrade )
  63. $ret .= " ". _t( "_MEMBERSHIP_UPGRADE_FROM_STANDARD" );
  64. } else {
  65. $ret .= "<font color=\"red\">{$aMembershipInfo['Name']}</font>$sViewMembershipActions";
  66. $days_left = (int)( ($aMembershipInfo['DateExpires'] - time()) / (24 * 3600) );
  67. if(!is_null($aMembershipInfo['DateExpires'])) {
  68. $ret .= ( $days_left > 0 ) ? _t( "_MEMBERSHIP_EXPIRES_IN_DAYS", $days_left ) : _t( "_MEMBERSHIP_EXPIRES_TODAY", date( "H:i", $aMembershipInfo['DateExpires'] ), date( "H:i" ) );
  69. } else {
  70. $ret.= _t("_MEMBERSHIP_EXPIRES_NEVER");
  71. }
  72. }
  73. return $ret;
  74. }
  75. }
  76. /** @} */