BxInvTemplate.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. ));
  40. }
  41. public function getBlockInviteInfo($aRequest)
  42. {
  43. $aVars = array(
  44. 'date_sent_title' => _t('_bx_invites_title_date_invite_sent'),
  45. 'date_seen_title' => _t('_bx_invites_title_date_invite_seen'),
  46. 'bx_repeat:items' => array()
  47. );
  48. foreach ($aRequest as $r) {
  49. $aVars['bx_repeat:items'][] = array (
  50. 'date_sent' => bx_time_js($r['date'], BX_FORMAT_DATE_TIME, true),
  51. 'date_seen' => ($r['date_seen'] != '' ? bx_time_js($r['date_seen'], BX_FORMAT_DATE_TIME, true) : ' - ')
  52. );
  53. }
  54. return $this->parseHtmlByName('invite_info.html', $aVars);
  55. }
  56. public function getBlockInvite($iAccountId, $iProfileId)
  57. {
  58. $sInvitesRemain = '';
  59. if(!isAdmin($iAccountId)) {
  60. $iInvites = $this->_oConfig->getCountPerUser();
  61. $iInvited = $this->_oDb->getInvites(array('type' => 'count_by_account', 'value' => $iAccountId));
  62. $sInvitesRemain = $iInvites - $iInvited;
  63. }
  64. else
  65. $sInvitesRemain = _t('_bx_invites_txt_unlimited');
  66. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_INVITE']);
  67. $this->getCssJs();
  68. return $this->parseHtmlByName('block_invite.html', array(
  69. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  70. 'js_object' => $this->_oConfig->getJsObject('main'),
  71. 'text' => _t('_bx_invites_txt_invite_block_text', $sInvitesRemain),
  72. 'url' => $sUrl,
  73. 'js_code' => $this->getJsCode('main')
  74. ));
  75. }
  76. public function getBlockRequest()
  77. {
  78. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_REQUEST']);
  79. $this->getCssJs();
  80. return $this->parseHtmlByName('block_request.html', array(
  81. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  82. 'text' => _t('_bx_invites_txt_request_block_text'),
  83. 'bx_if:show_button_request' => array(
  84. 'condition' => $this->_oConfig->isRequestInvite(),
  85. 'content' => array(
  86. 'url' => $sUrl
  87. )
  88. )
  89. ));
  90. }
  91. public function getBlockFormRequest()
  92. {
  93. if(!$this->_oConfig->isRequestInvite())
  94. return MsgBox(_t('_bx_invites_err_not_available'));
  95. $mixedAllowed = $this->getModule()->isAllowedRequest(0);
  96. if($mixedAllowed !== true)
  97. return MsgBox($mixedAllowed);
  98. $CNF = &$this->_oConfig->CNF;
  99. $sJsObject = $this->_oConfig->getJsObject('main');
  100. $oPermalink = BxDolPermalinks::getInstance();
  101. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_request'), $this->_oConfig->getObject('form_display_request_send'));
  102. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUEST']);
  103. $sFormId = $oForm->getId();
  104. $sEval = $sJsObject . '.onRequestFormSubmit(oData)';
  105. $oForm->initChecker();
  106. if(!$oForm->isSubmittedAndValid()) {
  107. $sForm = $oForm->getCode();
  108. if(!$oForm->isSubmitted()) {
  109. $this->getCssJs();
  110. return $this->parseHtmlByName('block_request_form.html', array(
  111. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  112. 'js_object' => $sJsObject,
  113. 'js_code' => $this->getJsCode('main'),
  114. 'form' => $sForm,
  115. 'form_id' => $sFormId,
  116. ));
  117. }
  118. if(!$oForm->isValid())
  119. return array('content' => $sForm, 'content_id' => $sFormId, 'eval' => $sEval);
  120. }
  121. $sIp = getVisitorIP();
  122. $iId = (int)$oForm->insert(array('nip' => ip2long($sIp),'date' => time()));
  123. if(!$iId)
  124. return array('content' => MsgBox(_t('_bx_invites_err_cannot_perform')), 'content_id' => $sFormId, 'eval' => $sEval);
  125. $sRequestsEmail = $this->_oConfig->getRequestsEmail();
  126. if(!empty($sRequestsEmail)) {
  127. $sManageUrl = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUESTS']);
  128. $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('bx_invites_request_form_message', array(
  129. 'sender_name' => bx_process_output($oForm->getCleanValue('name')),
  130. 'sender_email' => bx_process_output($oForm->getCleanValue('email')),
  131. 'sender_ip' => $sIp,
  132. 'manage_url' => $sManageUrl
  133. ));
  134. sendMail($sRequestsEmail, $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM);
  135. }
  136. return array('content' => MsgBox(_t('_bx_invites_msg_request_sent')), 'content_id' => $sFormId, 'eval' => $sEval);
  137. }
  138. public function getLinkPopup($sLink)
  139. {
  140. $sId = $this->_oConfig->getHtmlIds('link_popup');
  141. $sTitle = _t('_bx_invites_txt_link_popup_title');
  142. $sContent = $this->parseHtmlByName('popup_link.html', array(
  143. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  144. 'html_id_link' => $this->_oConfig->getHtmlIds('link_input'),
  145. 'link' => $sLink
  146. ));
  147. return BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent, true);
  148. }
  149. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  150. {
  151. $aParams = array_merge(array(
  152. 'aHtmlIds' => $this->_oConfig->getHtmlIds(),
  153. 'sObjNameGrid' => $this->_oConfig->getObject('grid_requests'),
  154. ), $aParams);
  155. return parent::getJsCode($sType, $aParams, $bWrap);
  156. }
  157. public function getProfilesByAccount($iAccountId, $iMaxVisible = 2)
  158. {
  159. $aProfiles = BxDolAccount::getInstance($iAccountId)->getProfiles();
  160. $iProfiles = count($aProfiles);
  161. $aTmplVars = array (
  162. 'class_cnt' => '',
  163. 'bx_repeat:profiles' => array(),
  164. 'bx_if:profiles_more' => array(
  165. 'condition' => $iProfiles > $iMaxVisible,
  166. 'content' => array(
  167. 'html_id' => $this->_oConfig->getHtmlIds('profile_more_popup') . $iAccountId,
  168. 'more' => _t('_bx_accnt_txt_more', $iProfiles - $iMaxVisible),
  169. 'more_attr' => bx_html_attribute(_t('_bx_accnt_txt_see_more')),
  170. 'popup' => '',
  171. ),
  172. ),
  173. );
  174. $aTmplVarsPopup = array (
  175. 'class_cnt' => ' bx-def-padding',
  176. 'bx_repeat:profiles' => array(),
  177. 'bx_if:profiles_more' => array(
  178. 'condition' => false,
  179. 'content' => array(),
  180. ),
  181. );
  182. $i = 0;
  183. foreach ($aProfiles as $iProfileId => $aProfile) {
  184. $oProfile = BxDolProfile::getInstance($iProfileId);
  185. if(!$oProfile)
  186. continue;
  187. $sName = $oProfile->getDisplayName();
  188. $aTmplVarsProfile = array (
  189. 'html_id' => $this->_oConfig->getHtmlIds('profile') . $aProfile['id'],
  190. 'id' => $oProfile->id(),
  191. 'url' => $oProfile->getUrl(),
  192. 'name' => $sName,
  193. 'name_attr' => bx_html_attribute($sName)
  194. );
  195. if($i < $iMaxVisible)
  196. $aTmplVars['bx_repeat:profiles'][] = $aTmplVarsProfile;
  197. if($i >= $iMaxVisible)
  198. $aTmplVarsPopup['bx_repeat:profiles'][] = $aTmplVarsProfile;
  199. ++$i;
  200. }
  201. if($aTmplVarsPopup['bx_repeat:profiles']) {
  202. $aTmplVars['bx_if:profiles_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', $this->parseHtmlByName('profiles.html', $aTmplVarsPopup));
  203. }
  204. return $this->parseHtmlByName('profiles.html', $aTmplVars);
  205. }
  206. }
  207. /** @} */