diff --git a/main/inc/email_editor.php b/main/inc/email_editor.php index f1f27ba9af..66358eeeae 100644 --- a/main/inc/email_editor.php +++ b/main/inc/email_editor.php @@ -6,91 +6,66 @@ * It can be called from the JavaScript library email_links.lib.php which * overtakes the mailto: links to use the internal interface instead. * @author Yannick Warnier + * @author Julio Montoya Updating form with formvalidator */ // name of the language file that needs to be included use \ChamiloSession as Session; -$language_file = "index"; +$language_file = array('index', 'admin', 'registration'); 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'; + if (empty($_user['user_id'])) { api_not_allowed(true); } -//api_protect_course_script(); //not a course script, so no protection - if (empty($_SESSION['origin_url'])) { $origin_url = $_SERVER['HTTP_REFERER']; Session::write('origin_url',$origin_url); } -/* Process the form and redirect to origin */ -if (!empty($_POST['submit_email']) && !empty($_POST['email_title']) && !empty($_POST['email_text'])) { - $text = Security::remove_XSS($_POST['email_text'])."\n\n---\n".get_lang('EmailSentFromDokeos')." ".api_get_path(WEB_PATH); +$form = new FormValidator('email_editor', 'post'); +$form->addElement('hidden', 'dest'); +$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']); $user_id=api_get_user_id(); $title=Security::remove_XSS($_POST['email_title']); $content=Security::remove_XSS($_POST['email_text']); - if (!empty($_user['mail'])) { - api_mail('',$email_administrator,$title,$text,api_get_person_name($_user['firstname'],$_user['lastname']), $_user['mail']); + if (!empty($_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); } else { - api_mail('',$email_administrator,$title,$text,get_lang('Anonymous')); + api_mail_html('',$email_administrator,$title,$text,get_lang('Anonymous')); } $orig = $_SESSION['origin_url']; Session::erase('origin_url'); header('location:'.$orig); + exit; } - -/* Header */ Display::display_header(get_lang('SendEmail')); - -?> - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - '.Security::remove_XSS($_POST['email_text']).''; - //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'); - ?> -
- -
- - +$form->display(); +Display::display_footer(); \ No newline at end of file diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index e111b1b984..a252501ba4 100644 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -332,7 +332,7 @@ class Template { private function set_system_parameters() { global $_configuration; - //Setting app paths + //Setting app paths/URLs $_p = array('web' => api_get_path(WEB_PATH), 'web_course' => api_get_path(WEB_COURSE_PATH), 'web_main' => api_get_path(WEB_CODE_PATH), @@ -449,18 +449,16 @@ class Template { $this->set_theme(); //Extra JS files - + $js_files = array( 'modernizr.js', 'jquery.min.js', 'chosen/chosen.jquery.min.js', - 'thickbox.js', - //'dtree/dtree.js', - 'email_links.lib.js.php', + 'thickbox.js', 'bootstrap/bootstrap.js', ); - + if (api_is_global_chat_enabled()) { //Do not include the global chat in LP 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') { $js_files[] = 'asciimath/ASCIIMathML.js'; } - - $js_file_to_string = ''; - + $js_file_to_string = ''; foreach ($js_files as $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 - $css_files = array( api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css', api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css' @@ -500,13 +499,11 @@ class Template { if (api_is_global_chat_enabled()) { $css_files[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css'; } - $css_file_to_string = ''; foreach ($css_files as $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 if (SHOW_TEXT_NEAR_ICONS == true) { diff --git a/main/inc/lib/javascript/email_links.lib.js.php b/main/template/default/mail_editor/email_link.js.tpl similarity index 55% rename from main/inc/lib/javascript/email_links.lib.js.php rename to main/template/default/mail_editor/email_link.js.tpl index 3eb7f86ee0..c565ce9f11 100644 --- a/main/inc/lib/javascript/email_links.lib.js.php +++ b/main/template/default/mail_editor/email_link.js.tpl @@ -1,28 +1,23 @@ - /* 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. * @package chamilo.inc.lib.javascript - * @author Yannick Warnier + * @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'))){ -?> - - \ No newline at end of file + +$(document).ready(function() { + addEvent(window,'load',addListeners,false); +}); + + \ No newline at end of file