BxInvTemplate.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 Invites Invites
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxInvTemplate extends BxBaseModGeneralTemplate
  12. {
  13. function __construct(&$oConfig, &$oDb)
  14. {
  15. parent::__construct($oConfig, $oDb);
  16. }
  17. public function getCssJs()
  18. {
  19. $this->addCss(array(
  20. 'main.css',
  21. ));
  22. $this->addJs(array(
  23. 'clipboard.min.js',
  24. 'jquery.form.min.js',
  25. 'jquery.anim.js',
  26. 'main.js'
  27. ));
  28. }
  29. public function getInclude()
  30. {
  31. $this->getCssJs();
  32. return $this->getJsCode('main');
  33. }
  34. public function getBlockRequestText($aRequest)
  35. {
  36. return $this->parseHtmlByName('request_text.html', array(
  37. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  38. 'text' => bx_process_output(nl2br($aRequest['text']), BX_DATA_TEXT_MULTILINE),
  39. 'bx_if:show_date_invite' => array(
  40. 'condition' => $aRequest['date_invite'] != '',
  41. 'content' => array(
  42. 'title' => _t('_bx_invites_grid_column_title_date_invite'),
  43. 'value' => bx_time_js($aRequest['date_invite'], BX_FORMAT_DATE_TIME, true)
  44. )
  45. ),
  46. 'bx_if:show_date_seen' => array(
  47. 'condition' => $aRequest['date_seen'] != '',
  48. 'content' => array(
  49. 'title' => _t('_bx_invites_grid_column_title_date_seen'),
  50. 'value' => bx_time_js($aRequest['date_seen'], BX_FORMAT_DATE_TIME, true)
  51. )
  52. ),
  53. 'bx_if:show_date_joined' => array(
  54. 'condition' => $aRequest['date_joined'] != '',
  55. 'content' => array(
  56. 'title' => _t('_bx_invites_grid_column_title_date_joined'),
  57. 'value' => bx_time_js($aRequest['date_joined'], BX_FORMAT_DATE_TIME, true)
  58. )
  59. )
  60. ));
  61. }
  62. public function getBlockInvite($iAccountId, $iProfileId)
  63. {
  64. $sInvitesRemain = '';
  65. if(!isAdmin($iAccountId)) {
  66. $iInvites = $this->_oConfig->getCountPerUser();
  67. $iInvited = $this->_oDb->getInvites(array('type' => 'count_by_account', 'value' => $iAccountId));
  68. $sInvitesRemain = $iInvites - $iInvited;
  69. }
  70. else
  71. $sInvitesRemain = _t('_bx_invites_txt_unlimited');
  72. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_INVITE']);
  73. $this->getCssJs();
  74. return $this->parseHtmlByName('block_invite.html', array(
  75. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  76. 'js_object' => $this->_oConfig->getJsObject('main'),
  77. 'text' => _t('_bx_invites_txt_invite_block_text', $sInvitesRemain),
  78. 'url' => $sUrl,
  79. 'js_code' => $this->getJsCode('main')
  80. ));
  81. }
  82. public function getBlockRequest()
  83. {
  84. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_REQUEST']);
  85. $this->getCssJs();
  86. return $this->parseHtmlByName('block_request.html', array(
  87. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  88. 'text' => _t('_bx_invites_txt_request_block_text'),
  89. 'bx_if:show_button_request' => array(
  90. 'condition' => $this->_oConfig->isRequestInvite(),
  91. 'content' => array(
  92. 'url' => $sUrl
  93. )
  94. )
  95. ));
  96. }
  97. public function getBlockFormRequest()
  98. {
  99. if(!$this->_oConfig->isRequestInvite())
  100. return MsgBox(_t('_bx_invites_err_not_available'));
  101. $mixedAllowed = $this->getModule()->isAllowedRequest(0);
  102. if($mixedAllowed !== true)
  103. return MsgBox($mixedAllowed);
  104. $CNF = &$this->_oConfig->CNF;
  105. $sJsObject = $this->_oConfig->getJsObject('main');
  106. $oPermalink = BxDolPermalinks::getInstance();
  107. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_request'), $this->_oConfig->getObject('form_display_request_send'));
  108. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUEST']);
  109. $sFormId = $oForm->getId();
  110. $sEval = $sJsObject . '.onRequestFormSubmit(oData)';
  111. $oForm->initChecker();
  112. if(!$oForm->isSubmittedAndValid()) {
  113. $sForm = $oForm->getCode();
  114. if(!$oForm->isSubmitted()) {
  115. $this->getCssJs();
  116. return $this->parseHtmlByName('block_request_form.html', array(
  117. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  118. 'js_object' => $sJsObject,
  119. 'js_code' => $this->getJsCode('main'),
  120. 'form' => $sForm,
  121. 'form_id' => $sFormId,
  122. ));
  123. }
  124. if(!$oForm->isValid())
  125. return array('content' => $sForm, 'content_id' => $sFormId, 'eval' => $sEval);
  126. }
  127. $sIp = getVisitorIP();
  128. $iId = (int)$oForm->insert(array('nip' => ip2long($sIp),'date' => time()));
  129. if(!$iId)
  130. return array('content' => MsgBox(_t('_bx_invites_err_cannot_perform')), 'content_id' => $sFormId, 'eval' => $sEval);
  131. $sRequestsEmail = $this->_oConfig->getRequestsEmail();
  132. if(!empty($sRequestsEmail)) {
  133. $sManageUrl = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUESTS']);
  134. $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('bx_invites_request_form_message', array(
  135. 'sender_name' => bx_process_output($oForm->getCleanValue('name')),
  136. 'sender_email' => bx_process_output($oForm->getCleanValue('email')),
  137. 'sender_ip' => $sIp,
  138. 'manage_url' => $sManageUrl
  139. ));
  140. sendMail($sRequestsEmail, $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM);
  141. }
  142. return array('content' => MsgBox(_t('_bx_invites_msg_request_sent')), 'content_id' => $sFormId, 'eval' => $sEval);
  143. }
  144. public function getLinkPopup($sLink)
  145. {
  146. $sId = $this->_oConfig->getHtmlIds('link_popup');
  147. $sTitle = _t('_bx_invites_txt_link_popup_title');
  148. $sContent = $this->parseHtmlByName('popup_link.html', array(
  149. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  150. 'html_id_link' => $this->_oConfig->getHtmlIds('link_input'),
  151. 'link' => $sLink
  152. ));
  153. return BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent, true);
  154. }
  155. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  156. {
  157. $aParams = array_merge(array(
  158. 'aHtmlIds' => $this->_oConfig->getHtmlIds(),
  159. 'sObjNameGrid' => $this->_oConfig->getObject('grid_requests'),
  160. ), $aParams);
  161. return parent::getJsCode($sType, $aParams, $bWrap);
  162. }
  163. }
  164. /** @} */