Ckeditor - Using Formvalidator instead of form BT#8968

1.10.x
Julio Montoya 10 years ago
parent 5a53fc6761
commit 10e6b4ae33
  1. 1
      main/inc/lib/formvalidator/FormValidator.class.php
  2. 3
      main/inc/lib/pear/HTML/Common.php
  3. 72
      main/newscorm/lp_add_item.php
  4. 32
      main/newscorm/lp_edit_item.php
  5. 12
      main/social/group_topics.php
  6. 4
      main/social/groups.php
  7. 136
      main/social/message_for_group_form.inc.php
  8. 15
      main/template/default/layout/head.tpl

@ -294,6 +294,7 @@ EOT;
*/
public function addButton($name, $label, $attributes = array())
{
//$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'btn btn-default';
$this->addElement('button', $name, $label, $attributes);
}

@ -143,9 +143,10 @@ class HTML_Common
foreach ($attributes as $key => $value) {
// Modified by Ivan Tcholakov, 16-MAR-2010
$value = @htmlspecialchars($value, ENT_COMPAT, $charset);
$strAttr .= ' ' . $key . '="' . $value. '"';
$strAttr .= ' ' . $key . ' = "' . $value. '"';
}
}
return $strAttr;
} // end func _getAttrString

@ -24,75 +24,7 @@ $learnPath = $_SESSION['oLP'];
$language_file = 'learnpath';
$htmlHeadXtra[] = '
<script>
var temp = false;
var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
function FCKeditor_OnComplete( editorInstance ) {
editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title) ;
document.getElementById(\'frmModel\').innerHTML = "<iframe id=\'frame_template\' name=\'my_frame_template\' height=890px width=220px; frameborder=0 src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
loaded = true;
}
function check_for_title() {
if (temp) {
// This functions shows that you can interact directly with the editor area
// DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance(\'content_lp\') ;
// Get the Editor Area DOM (Document object).
var oDOM = oEditor.EditorDocument ;
var iLength ;
var contentText ;
var contentTextArray;
var bestandsnaamNieuw = "";
var bestandsnaamOud = "";
// The are two diffent ways to get the text (without HTML markups).
// It is browser specific.
if( document.all ) // If Internet Explorer.
{
contentText = oDOM.body.innerText ;
}
else // If Gecko.
{
var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
contentText = r.toString() ;
}
var index=contentText.indexOf("/*<![CDATA");
contentText=contentText.substr(0,index);
// Compose title if there is none
contentTextArray = contentText.split(\' \') ;
var x=0;
for(x=0; (x<5 && x<contentTextArray.length); x++) {
if(x < 4) {
bestandsnaamNieuw += contentTextArray[x] + \' \';
} else {
bestandsnaamNieuw += contentTextArray[x];
}
}
}
temp=true;
}
function InnerDialogLoaded() {
if (document.all) {
// if is iexplorer
var B=new window.frames.content_lp___Frame.FCKToolbarButton(\'Templates\',window.content_lp___Frame.FCKLang.Templates);
} else {
var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
}
return B.ClickFrame();
};'."\n".
$htmlHeadXtra[] = '<script>'.
$learnPath->get_js_dropdown_array() .
@ -128,7 +60,7 @@ $(function() {
$(document).on("ready", function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates();
showTemplates("content_lp");
});
});
</script>';

@ -11,9 +11,6 @@
* @author Julio Montoya - Improving the list of templates
* @package chamilo.learnpath
*/
/**
* INIT SECTION
*/
$this_section = SECTION_COURSES;
@ -31,25 +28,11 @@ $language_file = 'learnpath';
/* Header and action code */
$htmlHeadXtra[] = '
<script>
function FCKeditor_OnComplete( editorInstance ) {
document.getElementById(\'frmModel\').innerHTML = "<iframe height=890px; width=230px; frameborder=0 src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
}
function InnerDialogLoaded() {
if (document.all) {
// if is iexplorer
var B=new window.frames.content_lp___Frame.FCKToolbarButton(\'Templates\',window.content_lp___Frame.FCKLang.Templates);
} else {
var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
}
return B.ClickFrame();
$};'.$_SESSION['oLP']->get_js_dropdown_array().'
<script>'.$_SESSION['oLP']->get_js_dropdown_array().'
$(document).on("ready", function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates();
showTemplates("content_lp");
});
});
</script>';
@ -57,12 +40,11 @@ $(document).on("ready", function() {
/* Constants and variables */
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$isStudentView = (int) $_REQUEST['isStudentView'];
$learnpath_id = (int) $_REQUEST['lp_id'];
$submit = $_POST['submit_button'];
$isStudentView = isset($_REQUEST['isStudentView']) ? intval($_REQUEST['isStudentView']) : null;
$learnpath_id = (int) $_REQUEST['lp_id'];
$submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
/* MAIN CODE */
@ -151,9 +133,7 @@ if (Database::num_rows($res_doc) > 0 && $path_parts['extension'] == 'html') {
echo $_SESSION['oLP']->return_new_tree();
// Show the template list
echo '<p style="border-bottom:1px solid #999999; margin:0; padding:2px;"></p>';
echo '<br />';
echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';
echo '<div id="frmModel" class="lp-add-item"></div>';
} else {
echo $_SESSION['oLP']->return_new_tree();
}

@ -16,8 +16,8 @@ if (api_get_setting('allow_social_tool') != 'true') {
}
$group_id = intval($_GET['id']);
$topic_id = intval($_GET['topic_id']);
$message_id = intval($_GET['msg_id']);
$topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
$message_id = isset($_GET['msg_id']) ? intval($_GET['msg_id']) : null;
//todo @this validation could be in a function in group_portal_manager
if (empty($group_id)) {
@ -101,7 +101,7 @@ if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
'error'
);
}
$topic_id = intval($_GET['topic_id']);
$topic_id = isset($_GET['topic_id']) ? intval($_GET['topic_id']) : null;
if ($_POST['action'] == 'add_message_group') {
$topic_id = $res;
}
@ -242,13 +242,13 @@ $social_right_content .= MessageManager::display_message_for_group(
$social_right_content = '<div class="span9">' . $social_right_content . '</div>';
$tpl = new Template($tool_name);
$tpl = new Template(null);
$tpl->set_help('Groups');
$tpl->assign('social_avatar_block', $social_avatar_block);
$tpl->assign('social_menu_block', $social_menu_block);
$tpl->assign('social_right_content', $social_right_content);
$tpl->assign('actions', $actions);
$tpl->assign('message', $show_message);
//$tpl->assign('actions', $actions);
//$tpl->assign('message', $show_message);
$tpl->assign('content', $content);
$social_layout = $tpl->get_template('layout/social_layout.tpl');
$tpl->display($social_layout);

@ -59,11 +59,11 @@ function add_image_form() {
counter_image = counter_image;
}
var elem1 = document.createElement("div");
elem1.setAttribute("id","filepath_"+counter_image);
elem1.setAttribute("id", "filepath_"+counter_image);
filepaths.appendChild(elem1);
id_elem1 = "filepath_"+counter_image;
id_elem1 = "\'"+id_elem1+"\'";
document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"' . api_get_path(WEB_CODE_PATH) . 'img/delete.gif\"></a>";
document.getElementById("filepath_"+counter_image).innerHTML = "<div class=\"control-group\"><div class=\"controls\"><input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"' . api_get_path(WEB_CODE_PATH) . 'img/delete.gif\"></a></div></div>";
if (filepaths.childNodes.length == 3) {
var link_attach = document.getElementById("link-more-attach");
if (link_attach) {

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Form for group message
* @package chamilo.social
@ -68,80 +69,70 @@ if (!empty($group_id) && $allowed_action) {
$page_item = !empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1;
$param_item_page = isset($_GET['items_page_nr']) && isset($_GET['topic_id']) ? ('&items_' . intval($_GET['topic_id']) . '_page_nr=' . (!empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1)) : '';
$param_item_page .= '&topic_id=' . intval($_GET['topic_id']);
$param_item_page .= isset($_GET['topic_id']) ? '&topic_id=' . intval($_GET['topic_id']) : null;
$page_topic = !empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1;
$anchor = isset($_GET['anchor_topic']) ? Security::remove_XSS($_GET['anchor_topic']) : null;
?>
<form name="form"
action="group_topics.php?id=<?php echo $group_id ?>&anchor_topic=<?php echo $anchor; ?>&topics_page_nr=<?php echo $page_topic . $param_item_page ?>"
method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="<?php echo $allowed_action ?>"/>
<input type="hidden" name="group_id" value="<?php echo $group_id ?>"/>
<input type="hidden" name="parent_id" value="<?php echo $message_id ?>"/>
<input type="hidden" name="message_id" value="<?php echo $message_id ?>"/>
<input type="hidden" name="token" value="<?php echo $tok ?>"/>
<table width="500px" border="0" height="220px">
<tr height="180">
<td align="left">
<div id="id_content_panel_init">
<dl>
<?php
if (api_get_setting('allow_message_tool') == 'true') {
//normal message
$user_info = api_get_user_info($userfriend_id);
//echo api_xml_http_response_encode(get_lang('To')).":&nbsp;&nbsp;".api_xml_http_response_encode($to_group);
$height = 180;
if ($allowed_action == 'add_message_group') {
$height = 140;
echo '<span style="color:red">*</span> ' . api_xml_http_response_encode(
get_lang('Title')
) . ' :<br />';
echo '<input id="txt_subject_id" name="title" type="text" style="width:450px;" value="' . $subject . '"><br /><br />';
}
//echo api_xml_http_response_encode(get_lang('Description')).' :<br />';
//@todo use formvalidator
$oFCKeditor = new CKeditor();
$oFCKeditor->ToolbarSet = 'messages';
$oFCKeditor->Width = '95%';
$oFCKeditor->Height = $height;
$oFCKeditor->Value = $message;
//$return = $oFCKeditor->CreateHtml();
$return = $oFCKeditor->editor('content');
echo $return;
if ($allowed_action == 'add_message_group') {
echo '<div><span style="color:red"> * </span>' . get_lang(
'FieldRequired'
) . '</div>';
}
?>
<br/><br/>
<?php echo api_xml_http_response_encode(
get_lang('AttachmentFiles')
); ?> :<br/>
<span id="filepaths"><div id="filepath_1"><input
type="file" name="attach_1" size="20"/>
</div></span>
<div id="link-more-attach">
<a href="javascript://"
onclick="return add_image_form()">
<?php echo get_lang('AddOneMoreFile') ?></a>
</div>
(<?php echo api_xml_http_response_encode(
sprintf(
get_lang('MaximunFileSizeX'),
format_file_size(
api_get_setting(
'message_max_upload_filesize'
)
)
)
) ?>)
<br/>
<br/>
<?php if ($allowed_action == 'add_message_group') { ?>
$form = new FormValidator(
'add_post',
'post',
api_get_path(WEB_CODE_PATH)."social/group_topics.php?id=$group_id&anchor_topic=$anchor&topics_page_nr=$page_topic"."$param_item_page",
null,
array('enctype' => 'multipart/form-data')
);
$form->addHidden('action', $allowed_action);
$form->addHidden('group_id', $group_id);
$form->addHidden('parent_id', $message_id);
$form->addHidden('message_id',$message_id );
$form->addHidden('token', $tok);
if (api_get_setting('allow_message_tool') == 'true') {
//normal message
$user_info = api_get_user_info($userfriend_id);
$height = 180;
if ($allowed_action == 'add_message_group') {
$form->add_textfield('title', get_lang('Title'));
$height = 140;
}
$config = array();
$config['ToolbarSet'] = 'Messages';
$form->add_html_editor(
'content',
get_lang('Content'),
false,
false,
$config
);
$form->add_html('<span id="filepaths"><div id="filepath_1">');
$form->add_file('attach_1', get_lang('AttachmentFiles'));
$form->add_html('</div></span>');
$form->add_label(null,
' <div id="link-more-attach">
<a href="javascript://" onclick="return add_image_form()">
' . get_lang('AddOneMoreFile') . '</a>
</div>'
);
$form->add_label(null,
api_xml_http_response_encode(
sprintf(
get_lang('MaximunFileSizeX'),
format_file_size(
api_get_setting('message_max_upload_filesize')
)
)
)
);
$form->addElement('style_submit_button', 'submit', get_lang('SendMessage'));
Display::display_no_header();
//Display::display_reduced_header();
$form->display();
}
/*
?>
<button class="btn save"
onclick="if(validate_text_empty(this.form.title.value,'<?php echo get_lang(
'YouShouldWriteASubject'
@ -166,3 +157,4 @@ $anchor = isset($_GET['anchor_topic']) ? Security::remove_XSS($_GET['anchor_topi
</div>
</table>
</form>
*/

@ -39,7 +39,11 @@ plugins.forEach(function(plugin) {
/**
* Function use to load templates in a div
**/
var showTemplates = function () {
var showTemplates = function (ckeditorName) {
var editorName = 'content';
if (ckeditorName.length > 0) {
editorName = ckeditorName;
}
CKEDITOR.editorConfig(CKEDITOR.config);
CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a){
var templatesConfig = CKEDITOR.getTemplates("default");
@ -64,10 +68,11 @@ var showTemplates = function () {
html: templateHTML,
click: function (e) {
e.preventDefault();
CKEDITOR.instances.content.setData(template.html, function () {
this.checkDirty();
});
if (CKEDITOR.instances[editorName]) {
CKEDITOR.instances[editorName].setData(template.html, function () {
this.checkDirty();
});
}
}
}).appendTo($templateLi);

Loading…
Cancel
Save