BxInvTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. $sEmail = $oForm->getCleanValue('email');
  122. $oAccountQuery = BxDolAccountQuery::getInstance();
  123. $iAccount = $oAccountQuery->getIdByEmail($sEmail);
  124. if ($iAccount > 0)
  125. 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);
  126. $iCountByEmail = $this->_oDb->getRequests(array('type' => 'count_by_email', 'value' => $sEmail));
  127. if ($iCountByEmail > 0)
  128. return array('content' => MsgBox(_t('_bx_invites_err_already_send')), 'content_id' => $sFormId, 'eval' => $sEval);
  129. $sIp = getVisitorIP();
  130. $iId = (int)$oForm->insert(array('nip' => ip2long($sIp),'date' => time()));
  131. if(!$iId)
  132. return array('content' => MsgBox(_t('_bx_invites_err_cannot_perform')), 'content_id' => $sFormId, 'eval' => $sEval);
  133. $this->getModule()->onRequest($iId);
  134. $sRequestsEmail = $this->_oConfig->getRequestsEmail();
  135. if(!empty($sRequestsEmail)) {
  136. $sManageUrl = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_REQUESTS']);
  137. $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('bx_invites_request_form_message', array(
  138. 'sender_name' => bx_process_output($oForm->getCleanValue('name')),
  139. 'sender_email' => bx_process_output($oForm->getCleanValue('email')),
  140. 'sender_ip' => $sIp,
  141. 'manage_url' => $sManageUrl
  142. ));
  143. $aRequestsEmails = explode(',', $sRequestsEmail);
  144. foreach ($aRequestsEmails as $s) {
  145. sendMail(trim($s), $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM);
  146. }
  147. }
  148. return array('content' => MsgBox(_t('_bx_invites_msg_request_sent')), 'content_id' => $sFormId, 'eval' => $sEval);
  149. }
  150. public function getLinkPopup($sLink)
  151. {
  152. $sId = $this->_oConfig->getHtmlIds('link_popup');
  153. $sTitle = _t('_bx_invites_txt_link_popup_title');
  154. $sContent = $this->parseHtmlByName('popup_link.html', array(
  155. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  156. 'html_id_link' => $this->_oConfig->getHtmlIds('link_input'),
  157. 'link' => $sLink
  158. ));
  159. return BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent, true);
  160. }
  161. public function getJsCode2($sType, $sGridType)
  162. {
  163. $aParams = array();
  164. $aParams = array_merge(array(
  165. 'aHtmlIds' => $this->_oConfig->getHtmlIds(),
  166. 'sObjNameGrid' => $this->_oConfig->getObject('grid_' . $sGridType),
  167. ), $aParams);
  168. return parent::getJsCode($sType, $aParams);
  169. }
  170. public function getMenuForManageBlocks($sType)
  171. {
  172. $CNF = &$this->_oConfig->CNF;
  173. $sMenu = '';
  174. $oPermalink = BxDolPermalinks::getInstance();
  175. $aMenuItems = array();
  176. $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);
  177. $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);
  178. if(count($aMenuItems) > 1) {
  179. $oMenu = new BxTemplMenu(array(
  180. 'template' => 'menu_vertical.html',
  181. 'menu_items' => $aMenuItems
  182. ), $this);
  183. $oMenu->setSelected($this->getModule()->_aModule['name'], 'invites-' . $sType);
  184. $sMenu = $oMenu->getCode();
  185. }
  186. return $sMenu;
  187. }
  188. public function getProfilesByAccount($iAccountId, $iMaxVisible = 2)
  189. {
  190. $aProfiles = BxDolAccount::getInstance($iAccountId)->getProfiles();
  191. $iProfiles = count($aProfiles);
  192. $aTmplVars = array (
  193. 'class_cnt' => '',
  194. 'bx_repeat:profiles' => array(),
  195. 'bx_if:profiles_more' => array(
  196. 'condition' => $iProfiles > $iMaxVisible,
  197. 'content' => array(
  198. 'html_id' => $this->_oConfig->getHtmlIds('profile_more_popup') . $iAccountId,
  199. 'more' => _t('_bx_accnt_txt_more', $iProfiles - $iMaxVisible),
  200. 'more_attr' => bx_html_attribute(_t('_bx_accnt_txt_see_more')),
  201. 'popup' => '',
  202. ),
  203. ),
  204. );
  205. $aTmplVarsPopup = array (
  206. 'class_cnt' => ' bx-def-padding',
  207. 'bx_repeat:profiles' => array(),
  208. 'bx_if:profiles_more' => array(
  209. 'condition' => false,
  210. 'content' => array(),
  211. ),
  212. );
  213. $i = 0;
  214. foreach ($aProfiles as $iProfileId => $aProfile) {
  215. $oProfile = BxDolProfile::getInstance($iProfileId);
  216. if(!$oProfile)
  217. continue;
  218. $sName = $oProfile->getDisplayName();
  219. $aTmplVarsProfile = array (
  220. 'html_id' => $this->_oConfig->getHtmlIds('profile') . $aProfile['id'],
  221. 'id' => $oProfile->id(),
  222. 'url' => $oProfile->getUrl(),
  223. 'name' => $sName,
  224. 'name_attr' => bx_html_attribute($sName)
  225. );
  226. if($i < $iMaxVisible)
  227. $aTmplVars['bx_repeat:profiles'][] = $aTmplVarsProfile;
  228. if($i >= $iMaxVisible)
  229. $aTmplVarsPopup['bx_repeat:profiles'][] = $aTmplVarsProfile;
  230. ++$i;
  231. }
  232. if($aTmplVarsPopup['bx_repeat:profiles']) {
  233. $aTmplVars['bx_if:profiles_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', $this->parseHtmlByName('profiles.html', $aTmplVarsPopup));
  234. }
  235. return $this->parseHtmlByName('profiles.html', $aTmplVars);
  236. }
  237. }
  238. /** @} */