Commit d8bb874e63eb77690f9017f65c8b63ba720b6cad

Authored by Neil Blakey-Milner
1 parent 36270c6d

If an email server isn't specified, don't send email, and show a dashlet

saying that email is disabled.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5372 c91229c3-7414-0410-bfa2-8a42b809f60b
config/config.ini
... ... @@ -111,11 +111,9 @@ browseToUnitFolder = default
111 111  
112 112 [email]
113 113 ; email settings
114   -emailServer = localhost
115   -emailFrom = kt@${serverName}
  114 +emailServer = none
  115 +emailFrom = kt@example.org
116 116 emailFromName = KnowledgeTree Document Management System
117   -emailAdmin = kt@${serverName}
118   -emailAdminName = DMS Administrator
119 117 ; Set to true to allow users to send attachments from the document
120 118 ; management system
121 119 allowAttachment = default
... ...
lib/email/Email.inc
... ... @@ -52,6 +52,15 @@ class Email {
52 52 $this->oMailer->WordWrap = 100;
53 53 $this->oMailer->IsHTML(true);
54 54 $this->oMailer->SetLanguage('en', KT_DIR . '/phpmailer/language/');
  55 + $this->bEmailDisabled = false;
  56 + $oConfig =& KTConfig::getSingleton();
  57 + $sEmailServer = $oConfig->get('email/emailServer');
  58 + if ($sEmailServer == 'none') {
  59 + $this->bEmailDisabled = true;
  60 + }
  61 + if (empty($sEmailServer)) {
  62 + $this->bEmailDisabled = true;
  63 + }
55 64 }
56 65  
57 66 /**
... ... @@ -65,6 +74,9 @@ class Email {
65 74 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
66 75 */
67 76 function send($mToEmail, $sSubject, $sBody) {
  77 + if ($this->bEmailDisabled) {
  78 + return PEAR::raiseError(_kt("Email is not configured."));
  79 + }
68 80 global $default;
69 81  
70 82 if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) ||
... ... @@ -116,6 +128,9 @@ class Email {
116 128 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
117 129 */
118 130 function sendAttachment($mToEmail, $sSubject, $sBody, $sDocumentPath, $sDocumentName) {
  131 + if ($this->bEmailDisabled) {
  132 + return PEAR::raiseError(_kt("Email is not configured."));
  133 + }
119 134 global $default;
120 135  
121 136 if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) ||
... ... @@ -173,6 +188,9 @@ class Email {
173 188 * @todo need to test this on multiple mail clients, not just Outlook
174 189 */
175 190 function sendHyperLink($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) {
  191 + if ($this->bEmailDisabled) {
  192 + return PEAR::raiseError(_kt("Email is not configured."));
  193 + }
176 194 global $default;
177 195  
178 196 //get info from relevant fields.
... ... @@ -205,6 +223,9 @@ class Email {
205 223 * @todo need to test this on multiple mail clients, not just Outlook
206 224 */
207 225 function sendHelpEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) {
  226 + if ($this->bEmailDisabled) {
  227 + return PEAR::raiseError(_kt("Email is not configured."));
  228 + }
208 229 global $default;
209 230  
210 231 //get info from relevant fields.
... ... @@ -223,6 +244,9 @@ class Email {
223 244 }
224 245  
225 246 function sendEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody) {
  247 + if ($this->bEmailDisabled) {
  248 + return PEAR::raiseError(_kt("Email is not configured."));
  249 + }
226 250 global $default;
227 251  
228 252 //get info from relevant fields.
... ...
plugins/ktcore/KTCorePlugin.php
... ... @@ -73,6 +73,7 @@ class KTCorePlugin extends KTPlugin {
73 73 $this->registerDashlet('KTNotificationDashlet', 'ktcore.dashlet.notifications', 'KTDashlets.php');
74 74 $this->registerDashlet('KTCheckoutDashlet', 'ktcore.dashlet.checkout', 'KTDashlets.php');
75 75 $this->registerDashlet('KTIndexerStatusDashlet', 'ktcore.dashlet.indexer_status', 'KTDashlets.php');
  76 + $this->registerDashlet('KTMailServerDashlet', 'ktcore.dashlet.mail_server', 'KTDashlets.php');
76 77  
77 78 $this->registerAdminPage('authentication', 'KTAuthenticationAdminPage', 'principals', _kt('Authentication'), _kt('By default, KnowledgeTree controls its own users and groups and stores all information about them inside the database. In many situations, an organisation will already have a list of users and groups, and needs to use that existing information to allow access to the DMS. These <strong>Authentication Sources</strong> allow the system administrator to specify additional sources of authentication data.'), 'authentication/authenticationadminpage.inc.php');
78 79  
... ...
plugins/ktcore/KTDashlets.php
... ... @@ -229,4 +229,29 @@ class KTIndexerStatusDashlet extends KTBaseDashlet {
229 229 }
230 230 }
231 231  
  232 +// replace the old checked-out docs.
  233 +class KTMailServerDashlet extends KTBaseDashlet {
  234 +
  235 + function is_active($oUser) {
  236 + $oConfig =& KTConfig::getSingleton();
  237 + $sEmailServer = $oConfig->get('email/emailServer');
  238 + if ($sEmailServer == 'none') {
  239 + return true;
  240 + }
  241 + if (empty($sEmailServer)) {
  242 + return true;
  243 + }
  244 + return false;
  245 + }
  246 +
  247 + function render() {
  248 + $oTemplating =& KTTemplating::getSingleton();
  249 + $oTemplate = $oTemplating->loadTemplate("ktcore/dashlets/mailserver");
  250 + $aTemplateData = array(
  251 + "context" => $this,
  252 + );
  253 + return $oTemplate->render($aTemplateData);
  254 + }
  255 +}
  256 +
232 257 ?>
... ...
templates/ktcore/dashlets/mailserver.smarty 0 → 100644
  1 +<h2>{i18n}Mail server status{/i18n}</h2>
  2 +
  3 +<div class="ktError">
  4 +
  5 +<p>{i18n}Email has not been configured on this server. Emailing of
  6 +documents and sending of notifications are disabled.{/i18n}</p>
  7 +
  8 +{if $admin}
  9 +<p>{i18n}Edit the [email] section of the config.ini file to set your email
  10 +server and the sending address of the KnowledgeTree server.{/i18n}</p>
  11 +{/if}
  12 +</div>
... ...