BxInvTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. $mInvitesRemain = $this->_oConfig->getCountPerUser();
  59. if ($mInvitesRemain === true)
  60. $mInvitesRemain = _t('_bx_invites_txt_unlimited');
  61. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_INVITE']);
  62. $this->getCssJs();
  63. return $this->parseHtmlByName('block_invite.html', array(
  64. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  65. 'js_object' => $this->_oConfig->getJsObject('main'),
  66. 'text' => _t('_bx_invites_txt_invite_block_text', $mInvitesRemain),
  67. 'url' => $sUrl,
  68. 'js_code' => $this->getJsCode('main')
  69. ));
  70. }
  71. public function getBlockRequest()
  72. {
  73. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_REQUEST']);
  74. $this->getCssJs();
  75. return $this->parseHtmlByName('block_request.html', array(
  76. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  77. 'text' => _t('_bx_invites_txt_request_block_text'),
  78. 'bx_if:show_button_request' => array(
  79. 'condition' => $this->_oConfig->isRequestInvite(),
  80. 'content' => array(
  81. 'url' => $sUrl
  82. )
  83. )
  84. ));
  85. }
  86. public function getBlockFormRequest()
  87. {
  88. if(!$this->_oConfig->isRequestInvite())
  89. return MsgBox(_t('_bx_invites_err_not_available'));
  90. $mixedAllowed = $this->getModule()->isAllowedRequest(0);
  91. if($mixedAllowed !== true)
  92. return MsgBox($mixedAllowed);
  93. $CNF = &$this->_oConfig->CNF;
  94. $sJsObject = $this->_oConfig->getJsObject('main');
  95. $oPermalink = BxDolPermalinks::getInstance();
  96. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_request'), $this->_oConfig->getObject('form_display_request_send'));
  97. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUEST']);
  98. $sFormId = $oForm->getId();
  99. $sEval = $sJsObject . '.onRequestFormSubmit(oData)';
  100. $oForm->initChecker();
  101. if(!$oForm->isSubmittedAndValid()) {
  102. $sForm = $oForm->getCode();
  103. if(!$oForm->isSubmitted()) {
  104. $this->getCssJs();
  105. return $this->parseHtmlByName('block_request_form.html', array(
  106. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  107. 'js_object' => $sJsObject,
  108. 'js_code' => $this->getJsCode('main'),
  109. 'form' => $sForm,
  110. 'form_id' => $sFormId,
  111. ));
  112. }
  113. if(!$oForm->isValid())
  114. return array('content' => $sForm, 'content_id' => $sFormId, 'eval' => $sEval);
  115. }
  116. $sEmail = $oForm->getCleanValue('email');
  117. $oAccountQuery = BxDolAccountQuery::getInstance();
  118. $iAccount = $oAccountQuery->getIdByEmail($sEmail);
  119. if ($iAccount > 0)
  120. return array('content' => MsgBox(_t('_bx_invites_err_already_registed', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password'))), 'content_id' => $sFormId, 'eval' => $sEval);
  121. $iCountByEmail = $this->_oDb->getRequests(array('type' => 'count_by_email', 'value' => $sEmail));
  122. if ($iCountByEmail > 0)
  123. return array('content' => MsgBox(_t('_bx_invites_err_already_send')), 'content_id' => $sFormId, 'eval' => $sEval);
  124. $sIp = getVisitorIP();
  125. $iId = (int)$oForm->insert(array('nip' => ip2long($sIp),'date' => time()));
  126. if(!$iId)
  127. return array('content' => MsgBox(_t('_bx_invites_err_cannot_perform')), 'content_id' => $sFormId, 'eval' => $sEval);
  128. $this->getModule()->onRequest($iId);
  129. $sRequestsEmail = $this->_oConfig->getRequestsEmail();
  130. if(!empty($sRequestsEmail)) {
  131. $sManageUrl = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUESTS']);
  132. $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('bx_invites_request_form_message', array(
  133. 'sender_name' => bx_process_output($oForm->getCleanValue('name')),
  134. 'sender_email' => bx_process_output($oForm->getCleanValue('email')),
  135. 'sender_ip' => $sIp,
  136. 'manage_url' => $sManageUrl
  137. ));
  138. $aRequestsEmails = explode(',', $sRequestsEmail);
  139. foreach ($aRequestsEmails as $s) {
  140. sendMail(trim($s), $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM);
  141. }
  142. }
  143. return array('content' => MsgBox(_t('_bx_invites_msg_request_sent')), 'content_id' => $sFormId, 'eval' => $sEval);
  144. }
  145. public function getLinkPopup($sLink)
  146. {
  147. $sId = $this->_oConfig->getHtmlIds('link_popup');
  148. $sTitle = _t('_bx_invites_txt_link_popup_title');
  149. $sContent = $this->parseHtmlByName('popup_link.html', array(
  150. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  151. 'html_id_link' => $this->_oConfig->getHtmlIds('link_input'),
  152. 'link' => $sLink
  153. ));
  154. return BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent, true);
  155. }
  156. public function getJsCode($sType, $aParams = array(), $mixedWrap = true)
  157. {
  158. $sGrid = 'requests';
  159. if(!empty($aParams['grid'])) {
  160. $sGrid = $aParams['grid'];
  161. unset($aParams['grid']);
  162. }
  163. $aParams = array_merge(array(
  164. 'aHtmlIds' => $this->_oConfig->getHtmlIds(),
  165. 'sObjNameGrid' => $this->_oConfig->getObject('grid_' . $sGrid),
  166. ), $aParams);
  167. return parent::getJsCode($sType, $aParams);
  168. }
  169. public function getMenuForManageBlocks($sType)
  170. {
  171. $CNF = &$this->_oConfig->CNF;
  172. $sMenu = '';
  173. $oPermalink = BxDolPermalinks::getInstance();
  174. $aMenuItems = array();
  175. $aMenuItems[] = array('id' => 'invites-requests', 'name' => 'invites-requests', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_REQUESTS']), 'target' => '_self', 'title' => _t('_bx_invites_menu_item_title_manage_requests'), 'active' => 1);
  176. $aMenuItems[] = array('id' => 'invites-invites', 'name' => 'invites-invites', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_INVITES']), 'target' => '_self', 'title' => _t('_bx_invites_menu_item_title_manage_invites'), 'active' => 1);
  177. if(count($aMenuItems) > 1) {
  178. $oMenu = new BxTemplMenu(array(
  179. 'template' => 'menu_vertical.html',
  180. 'menu_items' => $aMenuItems
  181. ), $this);
  182. $oMenu->setSelected($this->getModule()->_aModule['name'], 'invites-' . $sType);
  183. $sMenu = $oMenu->getCode();
  184. }
  185. return $sMenu;
  186. }
  187. public function getProfilesByAccount($iAccountId, $iMaxVisible = 2)
  188. {
  189. $aProfiles = BxDolAccount::getInstance($iAccountId)->getProfiles();
  190. $iProfiles = count($aProfiles);
  191. $aTmplVars = array (
  192. 'class_cnt' => '',
  193. 'bx_repeat:profiles' => array(),
  194. 'bx_if:profiles_more' => array(
  195. 'condition' => $iProfiles > $iMaxVisible,
  196. 'content' => array(
  197. 'html_id' => $this->_oConfig->getHtmlIds('profile_more_popup') . $iAccountId,
  198. 'more' => _t('_bx_accnt_txt_more', $iProfiles - $iMaxVisible),
  199. 'more_attr' => bx_html_attribute(_t('_bx_accnt_txt_see_more')),
  200. 'popup' => '',
  201. ),
  202. ),
  203. );
  204. $aTmplVarsPopup = array (
  205. 'class_cnt' => ' bx-def-padding',
  206. 'bx_repeat:profiles' => array(),
  207. 'bx_if:profiles_more' => array(
  208. 'condition' => false,
  209. 'content' => array(),
  210. ),
  211. );
  212. $i = 0;
  213. foreach ($aProfiles as $iProfileId => $aProfile) {
  214. $oProfile = BxDolProfile::getInstance($iProfileId);
  215. if(!$oProfile)
  216. continue;
  217. $sName = $oProfile->getDisplayName();
  218. $aTmplVarsProfile = array (
  219. 'html_id' => $this->_oConfig->getHtmlIds('profile') . $aProfile['id'],
  220. 'id' => $oProfile->id(),
  221. 'url' => $oProfile->getUrl(),
  222. 'name' => $sName,
  223. 'name_attr' => bx_html_attribute($sName)
  224. );
  225. if($i < $iMaxVisible)
  226. $aTmplVars['bx_repeat:profiles'][] = $aTmplVarsProfile;
  227. if($i >= $iMaxVisible)
  228. $aTmplVarsPopup['bx_repeat:profiles'][] = $aTmplVarsProfile;
  229. ++$i;
  230. }
  231. if($aTmplVarsPopup['bx_repeat:profiles']) {
  232. $aTmplVars['bx_if:profiles_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', $this->parseHtmlByName('profiles.html', $aTmplVarsPopup));
  233. }
  234. return $this->parseHtmlByName('profiles.html', $aTmplVars);
  235. }
  236. }
  237. /** @} */