Should fix bug when using email editor see #5356

skala
Julio Montoya 13 years ago
parent d99c309fcf
commit c7580f24f9
  1. 91
      main/inc/email_editor.php
  2. 25
      main/inc/lib/template.lib.php
  3. 64
      main/template/default/mail_editor/email_link.js.tpl

@ -6,91 +6,66 @@
* It can be called from the JavaScript library email_links.lib.php which * It can be called from the JavaScript library email_links.lib.php which
* overtakes the mailto: links to use the internal interface instead. * overtakes the mailto: links to use the internal interface instead.
* @author Yannick Warnier <ywarnier@beeznest.org> * @author Yannick Warnier <ywarnier@beeznest.org>
* @author Julio Montoya <gugli100@gmail.com> Updating form with formvalidator
*/ */
// name of the language file that needs to be included // name of the language file that needs to be included
use \ChamiloSession as Session; use \ChamiloSession as Session;
$language_file = "index"; $language_file = array('index', 'admin', 'registration');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
if (empty($_user['user_id'])) { if (empty($_user['user_id'])) {
api_not_allowed(true); api_not_allowed(true);
} }
//api_protect_course_script(); //not a course script, so no protection
if (empty($_SESSION['origin_url'])) { if (empty($_SESSION['origin_url'])) {
$origin_url = $_SERVER['HTTP_REFERER']; $origin_url = $_SERVER['HTTP_REFERER'];
Session::write('origin_url',$origin_url); Session::write('origin_url',$origin_url);
} }
/* Process the form and redirect to origin */ $form = new FormValidator('email_editor', 'post');
if (!empty($_POST['submit_email']) && !empty($_POST['email_title']) && !empty($_POST['email_text'])) { $form->addElement('hidden', 'dest');
$text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromDokeos')." ".api_get_path(WEB_PATH); $form->addElement('text', 'email_address', get_lang('EmailDestination'));
$form->addElement('text', 'email_title', get_lang('EmailTitle'));
$form->freeze('email_address');
$form->addElement('textarea', 'email_text', get_lang('EmailText'));
$form->addRule('email_address', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('email_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('email_text', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('email_address', get_lang('EmailWrong'), 'email');
$form->addElement('button', 'submit', get_lang('SendMail'));
$defaults = array( 'dest' => Security::remove_XSS($_REQUEST['dest']),
'email_address' => Security::remove_XSS($_REQUEST['dest']),
'email_title' => Security::remove_XSS($_POST['email_title']),
'email_text' => Security::remove_XSS($_POST['email_text'])
);
$form->setDefaults($defaults);
if ($form->validate()) {
$text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromDokeos')." ".api_get_path(WEB_PATH);
$email_administrator=Security::remove_XSS($_POST['dest']); $email_administrator=Security::remove_XSS($_POST['dest']);
$user_id=api_get_user_id(); $user_id=api_get_user_id();
$title=Security::remove_XSS($_POST['email_title']); $title=Security::remove_XSS($_POST['email_title']);
$content=Security::remove_XSS($_POST['email_text']); $content=Security::remove_XSS($_POST['email_text']);
if (!empty($_user['mail'])) { if (!empty($_user['mail'])) {
api_mail('',$email_administrator,$title,$text,api_get_person_name($_user['firstname'],$_user['lastname']), $_user['mail']); api_mail_html('',$email_administrator,$title,$text,api_get_person_name($_user['firstname'],$_user['lastname']), $_user['mail']);
UserManager::send_message_in_outbox ($email_administrator,$user_id,$title, $content); UserManager::send_message_in_outbox ($email_administrator,$user_id,$title, $content);
} else { } else {
api_mail('',$email_administrator,$title,$text,get_lang('Anonymous')); api_mail_html('',$email_administrator,$title,$text,get_lang('Anonymous'));
} }
$orig = $_SESSION['origin_url']; $orig = $_SESSION['origin_url'];
Session::erase('origin_url'); Session::erase('origin_url');
header('location:'.$orig); header('location:'.$orig);
exit;
} }
/* Header */
Display::display_header(get_lang('SendEmail')); Display::display_header(get_lang('SendEmail'));
$form->display();
?> Display::display_footer();
<table border="0">
<form action="" method="POST">
<input type="hidden" name="dest" value="<?php echo Security::remove_XSS($_REQUEST['dest']);?>" />
<tr>
<td>
<label for="email_address"><?php echo get_lang('EmailDestination');?></label>
</td>
<td>
<span id="email_address"><?php echo Security::remove_XSS($_REQUEST['dest']); ?></span>
</td>
</tr>
<tr>
<td>
<label for="email_title"><?php echo get_lang('EmailTitle');?></label>
</td>
<td>
<input name="email_title" id="email_title" value="<?php echo Security::remove_XSS($_POST['email_title']);?>" size="60"></input>
</td>
</tr>
<tr>
<td valign="top">
<label for="email_text"><?php echo get_lang('EmailText');?></label>
</td>
<td>
<?php
echo '<textarea id="email_text" name="email_text" rows="10" cols="80">'.Security::remove_XSS($_POST['email_text']).'</textarea>';
//htmlarea is not used otherwise we have to deal with HTML e-mail and all the related probs
//api_disp_html_area('email_text',$_POST['email_text'],'250px');
?>
</td>
</tr>
<tr>
<td colspan="2">
<button class="save" type="submit" name="submit_email" value="<?php echo get_lang('SendMail');?>"><?php echo get_lang('SendMail');?></button>
</td>
</tr>
</form>
</table>
<?php
/* Footer */
Display::display_footer();
?>

@ -332,7 +332,7 @@ class Template {
private function set_system_parameters() { private function set_system_parameters() {
global $_configuration; global $_configuration;
//Setting app paths //Setting app paths/URLs
$_p = array('web' => api_get_path(WEB_PATH), $_p = array('web' => api_get_path(WEB_PATH),
'web_course' => api_get_path(WEB_COURSE_PATH), 'web_course' => api_get_path(WEB_COURSE_PATH),
'web_main' => api_get_path(WEB_CODE_PATH), 'web_main' => api_get_path(WEB_CODE_PATH),
@ -449,18 +449,16 @@ class Template {
$this->set_theme(); $this->set_theme();
//Extra JS files //Extra JS files
$js_files = array( $js_files = array(
'modernizr.js', 'modernizr.js',
'jquery.min.js', 'jquery.min.js',
'chosen/chosen.jquery.min.js', 'chosen/chosen.jquery.min.js',
'thickbox.js', 'thickbox.js',
//'dtree/dtree.js',
'email_links.lib.js.php',
'bootstrap/bootstrap.js', 'bootstrap/bootstrap.js',
); );
if (api_is_global_chat_enabled()) { if (api_is_global_chat_enabled()) {
//Do not include the global chat in LP //Do not include the global chat in LP
if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) { if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
@ -475,18 +473,19 @@ class Template {
if (api_get_setting('include_asciimathml_script') == 'true') { if (api_get_setting('include_asciimathml_script') == 'true') {
$js_files[] = 'asciimath/ASCIIMathML.js'; $js_files[] = 'asciimath/ASCIIMathML.js';
} }
$js_file_to_string = '';
$js_file_to_string = '';
foreach ($js_files as $js_file) { foreach ($js_files as $js_file) {
$js_file_to_string .= api_get_js($js_file); $js_file_to_string .= api_get_js($js_file);
} }
//Loading email_editor js
if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
$js_file_to_string .= $this->fetch('default/mail_editor/email_link.js.tpl');
}
//Extra CSS files //Extra CSS files
$css_files = array( $css_files = array(
api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css', api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css',
api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css' api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css'
@ -500,13 +499,11 @@ class Template {
if (api_is_global_chat_enabled()) { if (api_is_global_chat_enabled()) {
$css_files[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css'; $css_files[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
} }
$css_file_to_string = ''; $css_file_to_string = '';
foreach ($css_files as $css_file) { foreach ($css_files as $css_file) {
$css_file_to_string .= api_get_css($css_file); $css_file_to_string .= api_get_css($css_file);
} }
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) { if (SHOW_TEXT_NEAR_ICONS == true) {

@ -1,28 +1,23 @@
<?php <script>
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /*
* Pseudo JavaScript library to deal with event handlers. * JS library to deal with event handlers.
* This script needs to be included from a script where the global include file has already been loaded. * This script needs to be included from a script where the global include file has already been loaded.
* @package chamilo.inc.lib.javascript * @package chamilo.inc.lib.javascript
* @author Yannick Warnier <ywarnier@beeznest.org> * @author Yannick Warnier
* @author Julio Montoya - Adding twig support
*/ */
/**
* If the user is not logged in, don't define anything, so the normal /*
* handling of mailto link can proceed
*/
if(!empty($_user['user_id']) AND string_2_boolean(api_get_setting('allow_email_editor'))){
?>
<script type="text/javascript">
/**
* Assigns any event handler to any element * Assigns any event handler to any element
* @param object Element on which the event is added * @param object Element on which the event is added
* @param string Name of event * @param string Name of event
* @param string Function to trigger on event * @param string Function to trigger on event
* @param boolean Capture the event and prevent * @param boolean Capture the event and prevent
*/ */
function addEvent(elm, evType, fn, useCapture)
{ //by Scott Andrew function addEvent(elm, evType, fn, useCapture) {
if(elm.addEventListener){ if (elm.addEventListener){
elm.addEventListener(evType, fn, useCapture); elm.addEventListener(evType, fn, useCapture);
return true; return true;
} else if(elm.attachEvent) { } else if(elm.attachEvent) {
@ -32,47 +27,46 @@ function addEvent(elm, evType, fn, useCapture)
elm['on' + evType] = fn; elm['on' + evType] = fn;
} }
} }
/**
/*
* Adds the event listener * Adds the event listener
*/ */
function addListeners(e) { function addListeners(e) {
var my_links = document.getElementsById('clickable_email_link'); var my_links = $('.clickable_email_link');
for(var i=0;i < my_links.length;i++) console.log(my_links);
{ for(var i=0;i < my_links.length;i++) {
addEvent(my_links[i],'click',loadEmailEditor,false); addEvent(my_links[i],'click',loadEmailEditor,false);
} }
} }
/**
/*
* Loads a specific page on event triggering * Loads a specific page on event triggering
*/ */
function loadEmailEditor(e) function loadEmailEditor(e) {
{
var el; var el;
if(window.event && window.event.srcElement) if(window.event && window.event.srcElement) {
{
el = window.event.srcElement; el = window.event.srcElement;
} }
if (e && e.target) if (e && e.target) {
{
el = e.target; el = e.target;
} }
if(!el) if(!el) {
{
return; return;
} }
//el is now my link object, so I can get el.href here to load the new window //el is now my link object, so I can get el.href here to load the new window
var link = el.href.replace('mailto:',''); var link = el.href.replace('mailto:','');
document.location = "<?php echo api_get_path(WEB_CODE_PATH);?>inc/email_editor.php?dest=" + link; document.location = "{{ _p.web_main }}inc/email_editor.php?dest=" + link;
//cancel default link action //cancel default link action
if(window.event && window.event.returnValue){ if (window.event && window.event.returnValue){
window.event.returnValue = false; window.event.returnValue = false;
} }
if(e && e.preventDefault){ if(e && e.preventDefault){
e.preventDefault(); e.preventDefault();
} }
} }
addEvent(window,'load',addListeners,false);
</script> $(document).ready(function() {
<?php addEvent(window,'load',addListeners,false);
} });
?>
</script>
Loading…
Cancel
Save