From 4547c173adfe2811eafca9b5b65b261b4b2f6656 Mon Sep 17 00:00:00 2001 From: "shiyangyangwork@yahoo.cn" Date: Sat, 8 Oct 2011 02:53:18 +0000 Subject: [PATCH] * finish the task #555 --- module/common/lang/en.php | 3 + module/common/lang/zh-cn.php | 3 + module/mail/control.php | 106 ++++++++++++++++++++++++++ module/mail/js/set.js | 54 ++++++++++++++ module/mail/lang/en.php | 52 +++++++++++++ module/mail/lang/zh-cn.php | 52 +++++++++++++ module/mail/view/save.html.php | 25 +++++++ module/mail/view/set.html.php | 132 +++++++++++++++++++++++++++++++++ 8 files changed, 427 insertions(+) create mode 100755 module/mail/control.php create mode 100755 module/mail/js/set.js create mode 100755 module/mail/lang/en.php create mode 100755 module/mail/lang/zh-cn.php create mode 100755 module/mail/view/save.html.php create mode 100755 module/mail/view/set.html.php diff --git a/module/common/lang/en.php b/module/common/lang/en.php index 3576722313..41bb8b8d9b 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -210,11 +210,13 @@ $lang->admin->menu->trashes = array('link' => 'Trash|action|trash', 'subModule $lang->admin->menu->convert = array('link' => 'Import|convert|index', 'subModule' => 'convert'); $lang->admin->menu->extension = array('link' => 'Extension|extension|browse', 'subModule' => 'extension'); $lang->admin->menu->editor = array('link' => 'Extension editor|editor|index', 'subModule' => 'editor'); +$lang->admin->menu->email = array('link' => 'ConfigEmail|mail|set', 'subModule' => 'mail'); $lang->convert->menu = $lang->admin->menu; $lang->upgrade->menu = $lang->admin->menu; $lang->action->menu = $lang->admin->menu; $lang->extension->menu = $lang->admin->menu; $lang->editor->menu = $lang->admin->menu; +$lang->mail->menu = $lang->admin->menu; /* Groups. */ $lang->menugroup->release = 'product'; @@ -235,6 +237,7 @@ $lang->menugroup->todo = 'my'; $lang->menugroup->action = 'admin'; $lang->menugroup->extension = 'admin'; $lang->menugroup->editor = 'admin'; +$lang->menugroup->mail = 'admin'; /* Error info. */ $lang->error->companyNotFound = "The domain %s does not exist."; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 4208f49ed7..63fd85c06e 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -210,11 +210,13 @@ $lang->admin->menu->trashes = array('link' => '回收站|action|trash', 'subMo $lang->admin->menu->convert = array('link' => '从其他系统导入|convert|index', 'subModule' => 'convert'); $lang->admin->menu->extension = array('link' => '插件管理|extension|browse', 'subModule' => 'extension'); $lang->admin->menu->editor = array('link' => '扩展编辑器|editor|index', 'subModule' => 'editor'); +$lang->admin->menu->mail = array('link' => 'Email配置|mail|set', 'subModule' => 'mail'); $lang->convert->menu = $lang->admin->menu; $lang->upgrade->menu = $lang->admin->menu; $lang->action->menu = $lang->admin->menu; $lang->extension->menu = $lang->admin->menu; $lang->editor->menu = $lang->admin->menu; +$lang->mail->menu = $lang->admin->menu; /*菜单设置:分组设置。*/ $lang->menugroup->release = 'product'; @@ -235,6 +237,7 @@ $lang->menugroup->todo = 'my'; $lang->menugroup->action = 'admin'; $lang->menugroup->extension = 'admin'; $lang->menugroup->editor = 'admin'; +$lang->menugroup->mail = 'admin'; /* 错误提示信息。*/ $lang->error->companyNotFound = "您访问的域名 %s 没有对应的公司。"; diff --git a/module/mail/control.php b/module/mail/control.php new file mode 100755 index 0000000000..5df6226480 --- /dev/null +++ b/module/mail/control.php @@ -0,0 +1,106 @@ + + * @package mail + * @version $Id$ + * @link http://www.zentao.net + */ +class mail extends control +{ + /** + * Config email. + * + * @access public + * @return void + */ + public function set() + { + $this->view->mailConfig = $this->app->loadConfig('mail')->mail; + $this->display(); + } + + /** + * Save the email config. + * + * @access public + * @return void + */ + public function save() + { + if(!empty($_POST)) + { + if('gmail' == $this->post->mta) + { + $config = <<mail->turnon = {$this->post->turnon}; +\$config->mail->fromAddress = "{$this->post->fromAddress}"; +\$config->mail->mta = "gmail"; +\$config->mail->fromName = "{$this->post->fromName}"; +\$config->mail->gmail->debug = {$this->post->gmailDebug}; +\$config->mail->gmail->username = "{$this->post->gmailUsername}"; +\$config->mail->gmail->password = "{$this->post->gmailPassword}"; +EOT; + } + elseif('smtp' == $this->post->mta) + { + $position = strpos($this->post->fromAddress, '@'); + $host = 'smtp.' . substr($this->post->fromAddress, $position + 1); + + $config = <<mail->turnon = {$this->post->turnon}; +\$config->mail->fromAddress = "{$this->post->fromAddress}"; +\$config->mail->mta = "{$this->post->mta}"; +\$config->mail->fromName = "{$this->post->fromName}"; +\$config->mail->smtp->debug = {$this->post->smtpDebug}; +\$config->mail->smtp->username = "{$this->post->smtpUsername}"; +\$config->mail->smtp->password = "{$this->post->smtpPassword}"; +\$config->mail->smtp->auth = {$this->post->smtpAuth}; +\$config->mail->smtp->host = "$host"; +\$config->mail->smtp->secure = "{$this->post->smtpSecure}"; +\$config->mail->smtp->port = "{$this->post->smtpPort}"; +EOT; + } + elseif('phpmail' == $this->post->mta or 'sendmail' == $this->post->mta) + { + $config = <<mail->turnon = {$this->post->turnon}; +\$config->mail->fromAddress = "{$this->post->fromAddress}"; +\$config->mail->mta = "{$this->post->mta}"; +\$config->mail->fromName = "{$this->post->fromName}"; +EOT; + } + + /* Output config to the extconfig file of mail */ + $configPath = $this->app->getModuleExtPath('mail', 'config'); + if(is_writable($configPath)) + { + if(file_put_contents($configPath . 'zzzmail.php', $config)) + { + /* Send test mail */ + $this->mail->send($this->app->user->account, $this->lang->mail->subject, $this->lang->mail->content,""); + if($this->mail->isError()) echo js::error($this->mail->getError()); + echo js::confirm($this->lang->mail->confirmSave,$this->createLink('mail', 'set')); + } + else + { + $this->view->config = $config; + $this->view->configPath = $configPath; + $this->display(); + } + } + else + { + $this->view->config = $config; + $this->view->configPath = $configPath; + $this->display(); + } + } + } +} diff --git a/module/mail/js/set.js b/module/mail/js/set.js new file mode 100755 index 0000000000..e23b0197e8 --- /dev/null +++ b/module/mail/js/set.js @@ -0,0 +1,54 @@ +function setMtaType(type) +{ + if(type == 'gmail') + { + $('#gmailUsername').show(); + $('#gmailPassword').show(); + $('#gmailDebug').show(); + $('#smtpDebug').hide(); + $('#smtpUsername').hide(); + $('#smtpPassword').hide(); + $('#smtpAuth').hide(); + $('#smtpSecure').hide(); + $('#smtpPort').hide(); + } + else if(type == 'smtp') + { + $('#gmailUsername').hide(); + $('#gmailPassword').hide(); + $('#gmailDebug').hide(); + $('#smtpDebug').show(); + $('#smtpUsername').show(); + $('#smtpPassword').show(); + $('#smtpAuth').show(); + $('#smtpSecure').show(); + $('#smtpPort').show(); + } + else if(type == 'phpmail' || type == 'sendmail') + { + $('#gmailUsername').hide(); + $('#gmailPassword').hide(); + $('#gmailDebug').hide(); + $('#smtpDebug').hide(); + $('#smtpUsername').hide(); + $('#smtpPassword').hide(); + $('#smtpAuth').hide(); + $('#smtpSecure').hide(); + $('#smtpPort').hide(); + } +} +function setVerificationType(type) +{ + if(type == 'true') + { + $('#smtpUsername').show(); + $('#smtpPassword').show(); + } + else if(type == 'false') + { + $('#smtpUsername').hide(); + $('#smtpPassword').hide(); + } +} +type = document.getElementById("mta") +setMtaType(type.value); diff --git a/module/mail/lang/en.php b/module/mail/lang/en.php new file mode 100755 index 0000000000..9a9613cb41 --- /dev/null +++ b/module/mail/lang/en.php @@ -0,0 +1,52 @@ +mail->setParam = 'Please input param of Email'; + +$lang->mail->turnon = 'trun on email feature or not'; +$lang->mail->fromAddress = 'The from address'; +$lang->mail->fromName = 'The from name'; +$lang->mail->mta = 'The style of send email'; +$lang->mail->debugExample = '0:close,1 and 2 :open,2 is more infomation than 1'; + +$lang->mail->mtaList[''] = ''; +$lang->mail->mtaList['gmail'] = 'gmail'; +$lang->mail->mtaList['smtp'] = 'smtp'; +$lang->mail->mtaList['phpmail'] = 'phpmail'; +$lang->mail->mtaList['sendmail'] = 'sendmail'; + +/* Trun on email feature or not */ +$lang->mail->turnonList['true'] = 'open'; +$lang->mail->turnonList['false'] = 'close'; + +$lang->mail->debugList[0] = '0'; +$lang->mail->debugList[1] = '1'; +$lang->mail->debugList[2] = '2'; + +$lang->mail->smtp->authList['true'] = 'yes'; +$lang->mail->smtp->authList['false'] = 'no'; + +$lang->mail->smtp->secureList[''] = 'not encode'; +$lang->mail->smtp->secureList['ssl'] = 'ssl'; +$lang->mail->smtp->secureList['tls'] = 'tls'; + +/* Set SMTP */ +$lang->mail->smtp->fromName = 'The from name'; +$lang->mail->smtp->auth = 'Need auth or not'; +$lang->mail->smtp->debug = 'Debug level'; +$lang->mail->smtp->secure = 'The type to encode datas'; +$lang->mail->smtp->username = 'The smtp user'; +$lang->mail->smtp->password = "The smtp user's password"; +$lang->mail->smtp->port = 'The smtp server host port'; +$lang->mail->smtp->portInfo = 'ssl: default port is 465, tls: default port is 587, not encode: default port is empty'; +/* Set gmail */ +$lang->mail->gmail->username = 'The gmail user'; +$lang->mail->gmail->password = "The gmail user'password"; +$lang->mail->gmail->debug = 'Debug level'; + +$lang->mail->confirmSave = 'Save successful.Please login your email to view the test mail'; +$lang->mail->subject = 'The test mail'; +$lang->mail->content = "The email's param is setted"; + +/* Save config information */ +$lang->mail->configInfo = 'Config information'; +$lang->mail->saveConfig = 'Please save Config information to:'; +$lang->mail->createFile = 'If the zzz.php is not exist, please create it.'; diff --git a/module/mail/lang/zh-cn.php b/module/mail/lang/zh-cn.php new file mode 100755 index 0000000000..440bb8aea1 --- /dev/null +++ b/module/mail/lang/zh-cn.php @@ -0,0 +1,52 @@ +mail->setParam = '请设置下面的配置参数'; + +$lang->mail->turnon = '是否打开发信功能'; +$lang->mail->fromAddress = '发信人邮箱'; +$lang->mail->fromName = '发信人名称'; +$lang->mail->mta = '请选择发信方式'; +$lang->mail->debugExample = '0表示关闭调试信息,1和2表示打开调试信息,但2比1调试信息显示更详细'; + +$lang->mail->mtaList[''] = ''; +$lang->mail->mtaList['gmail'] = 'gmail'; +$lang->mail->mtaList['smtp'] = 'smtp'; +$lang->mail->mtaList['phpmail'] = 'phpmail'; +$lang->mail->mtaList['sendmail'] = 'sendmail'; + +/* Trun on email feature or not */ +$lang->mail->turnonList['true'] = '打开'; +$lang->mail->turnonList['false'] = '关闭'; + +$lang->mail->debugList[0] = '0'; +$lang->mail->debugList[1] = '1'; +$lang->mail->debugList[2] = '2'; + +$lang->mail->smtp->authList['true'] = '是'; +$lang->mail->smtp->authList['false'] = '否'; + +$lang->mail->smtp->secureList[''] = '不加密'; +$lang->mail->smtp->secureList['ssl'] = 'ssl'; +$lang->mail->smtp->secureList['tls'] = 'tls'; + +/* Set SMTP */ +$lang->mail->smtp->fromName = '发信人姓名'; +$lang->mail->smtp->auth = '是否需要验证'; +$lang->mail->smtp->debug = '请选择调试等级'; +$lang->mail->smtp->secure = '请选择SMTP加密方式'; +$lang->mail->smtp->username = '发信邮箱用户名'; +$lang->mail->smtp->password = '请输入密码'; +$lang->mail->smtp->port = '请输入端口号'; +$lang->mail->smtp->portInfo = 'ssl加密方式默认端口号为465,tls加密方式默认端口号为587,不加密端口号一般为空'; +/* Set gmail */ +$lang->mail->gmail->username = '请输入发信邮箱用户名'; +$lang->mail->gmail->password = '请输入发信邮箱密码'; +$lang->mail->gmail->debug = '请选择调试等级'; + +$lang->mail->confirmSave = '保存成功, 请到您的邮箱中查看测试邮件是否发送成功。'; +$lang->mail->subject = '测试邮件'; +$lang->mail->content = '邮箱设置成功'; + +/* Save config information */ +$lang->mail->configInfo = '配置信息'; +$lang->mail->saveConfig = '请将该配置信息保存到: '; +$lang->mail->createFile = '如果zzz.php文件不存在,请手动创建该文件,将以上配置保存即可。'; diff --git a/module/mail/view/save.html.php b/module/mail/view/save.html.php new file mode 100755 index 0000000000..ce8e9d26b7 --- /dev/null +++ b/module/mail/view/save.html.php @@ -0,0 +1,25 @@ + + * @package mail + * @version $Id$ + * @link http://www.zentao.net + */ +include '../../common/view/header.html.php'; +?> + + + + + + + + + + +
mail->configInfo ?>
+
mail->saveConfig . $configPath . 'config.php' ?>
mail->createFile ?>
diff --git a/module/mail/view/set.html.php b/module/mail/view/set.html.php new file mode 100755 index 0000000000..96fd4d6341 --- /dev/null +++ b/module/mail/view/set.html.php @@ -0,0 +1,132 @@ + + * @package mail + * @version $Id$ + * @link http://www.zentao.net + */ +include '../../common/view/header.html.php'; +include '../../common/view/tablesorter.html.php';?> +gmail->username)) +{ + $gmailUsername = $mailConfig->gmail->username; +} +else +{ + $gmailUsername = ''; +} +if(!empty($mailConfig->gmail->password)) +{ + $gmailPassword = $mailConfig->gmail->password; +} +else +{ + $gmailPassword = ''; +} +if(!empty($mailConfig->smtp->username)) +{ + $smtpUsername = $mailConfig->smtp->username; +} +else +{ + $smtpUsername = ''; +} +if(!empty($mailConfig->smtp->password)) +{ + $smtpPassword = $mailConfig->smtp->password; +} +else +{ + $smtpPassword = ''; +} +if(!empty($mailConfig->smtp->secure)) +{ + $smtpSecure = $mailConfig->smtp->secure; +} +else +{ + $smtpSecure = ''; +} +if(!empty($mailConfig->smtp->auth)) +{ + $smtpAuth = $mailConfig->smtp->auth; +} +else +{ + $smtpAuth = ''; +} +if(!empty($mailConfig->smtp->port)) +{ + $smtpPort = $mailConfig->smtp->port; +} +else +{ + $smtpPort = ''; +} +?> +
'> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mail->setParam; ?>
mail->turnon; ?>mail->turnonList, $mailConfig->turnon); ?>
mail->mta; ?>mail->mtaList, $mailConfig->mta, 'class=select-3 onchange=setMtaType(this.value)'); ?>
mail->fromAddress; ?>fromAddress) ?>
mail->fromName; ?>fromName) ?>
+
+