source: trunk/inc/classes/BxDolEmailTemplates.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 4.9 KB
Line 
1<?php
2
3/***************************************************************************
4* Dolphin Smart Community Builder
5* -----------------
6* begin : Mon Mar 23 2006
7* copyright : (C) 2006 BoonEx Group
8* website : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21bx_import('BxDolPaginate');
22
23class BxDolEmailTemplates {
24 var $iDefaultLangId;
25 var $aDefaultKeys;
26
27 /**
28 * Class constructor.
29 */
30 function BxDolEmailTemplates() {
31 $this->iDefaultLangId = $GLOBALS['MySQL']->getOne("SELECT `ID` FROM `sys_localization_languages` WHERE `Name`='" . process_db_input($GLOBALS['sCurrentLanguage']) . "' LIMIT 1");
32 $this->aDefaultKeys = array(
33 'Domain' => $GLOBALS['site']['url'],
34 'SiteName' => $GLOBALS['site']['title'],
35 );
36 }
37
38 /**
39 * Update existing or create new template ;
40 *
41 * @param $sTemplateName (string) - name of template ;
42 * @param $sTemplateSubj (string) - subject of template ;
43 * @param $sTemplateBody (string) - text of template ;
44 * @param $iLangID (integer) - needed language's ID;
45 * @return HTML presentation data ;
46 */
47 function setTemplate( $sTemplateName, $sTemplateSubj, $sTemplateBody, $iLangID )
48 {
49 if ( !db_value("SELECT `ID` FROM `sys_email_templates` WHERE `Name` = '" . process_db_input($sTemplateName) . "' AND `LangID` = '{$iLangID}'") )
50 {
51 $sQuery =
52 "
53 INSERT INTO
54 `sys_email_templates` (`Name`, `Subject`, `Body`, `LangID`)
55 VALUES
56 (
57 '" . process_db_input($sTemplateName) . "',
58 '" . process_db_input($sTemplateSubj) . "',
59 '" . process_db_input($sTemplateBody) . "',
60 '" . (int) $iLangID . "'
61 )
62 ";
63
64 $sMessage = 'Template was created';
65 }
66 else
67 {
68 $sQuery =
69 "
70 UPDATE
71 `sys_email_templates`
72 SET
73 `Subject` = '" . process_db_input($sTemplateSubj) . "',
74 `Body` = '" . process_db_input($sTemplateBody) . "'
75 WHERE
76 `Name` = '" . process_db_input($sTemplateName) . "'
77 AND
78 `LangID` = '" . (int) $iLangID . "'
79 LIMIT 1
80 ";
81
82 $sMessage = 'Template was updated';
83 }
84
85 db_res($sQuery);
86 return $this -> genTemplatesForm( $sTemplateName, $iLangID, $sMessage ) ;
87 }
88
89 /**
90 * Function will return array of needed template ;
91 *
92 * @param string $sTemplateName - name of necessary template.
93 * @param integer $iMemberId - ID of registered member.
94 * @return array with template subject and its body.
95 */
96 function getTemplate($sTemplateName, $iMemberId = 0 ) {
97 if($iMemberId != 0) {
98 $aProfile = getProfileInfo($iMemberId);
99 $iUseLang = $aProfile['LangID'] ? $aProfile['LangID'] : $this->iDefaultLangId;
100 }
101 else {
102 $iUseLang = $this->iDefaultLangId;
103 }
104
105 $sSql = "SELECT `Subject`, `Body` FROM `sys_email_templates` WHERE `Name`='" . process_db_input($sTemplateName) . "' AND (`LangID` = '" . (int) $iUseLang . "' OR `LangID` = '0') ORDER BY `LangID` DESC LIMIT 1";
106 return $GLOBALS['MySQL']->getRow($sSql);
107 }
108
109 function parseTemplate($sTemplateName, $aTemplateKeys, $iMemberId = 0) {
110 $aTemplate = $this->getTemplate($sTemplateName, $iMemberId);
111
112 return array(
113 'subject' => $this->parseContent($aTemplate['Subject'], $aTemplateKeys, $iMemberId),
114 'body' => $this->parseContent($aTemplate['Body'], $aTemplateKeys, $iMemberId)
115 );
116 }
117 function parseContent($sContent, $aKeys, $iMemberId = 0) {
118 $aResultKeys = $this->aDefaultKeys;
119 if($iMemberId != 0) {
120 $aProfile = getProfileInfo($iMemberId);
121
122 $aResultKeys = array_merge($aResultKeys, array(
123 'recipientID' => $aProfile['ID'],
124 'RealName' => $aProfile['NickName'],
125 'NickName' => $aProfile['NickName'],
126 'Email' => $aProfile['Email'],
127 'Password' => $aProfile['Password'],
128 'SiteName' => getParam('site_title'),
129 ));
130 }
131 if(is_array($aKeys))
132 $aResultKeys = array_merge($aResultKeys, $aKeys);
133
134 return $GLOBALS['oSysTemplate']->parseHtmlByContent($sContent, $aResultKeys, array('<', '>'));
135 }
136}
137?>
Note: See TracBrowser for help on using the repository browser.