Removing fckeditor calls. Using formvalidator see #5875

1.10.x
Julio Montoya 12 years ago
parent 5ce22b6c7a
commit afc6e2e5e6
  1. 545
      main/inc/lib/blog.lib.php
  2. 116
      main/inc/lib/career.lib.php
  3. 260
      main/inc/lib/fck_course_document.inc.php
  4. 2
      main/inc/lib/formvalidator/Element/html_editor.php
  5. 205
      main/inc/lib/promotion.lib.php
  6. 1
      main/newscorm/lp_controller.php
  7. 133
      main/social/message_for_group_form.inc.php

@ -44,7 +44,6 @@ class Blog
}
}
/**
* Get the description of a blog
* @author Toon Keppens
@ -105,17 +104,14 @@ class Blog
*/
public static function create_blog($title, $subtitle)
{
global $_user;
$course_id = api_get_course_int_id();
$current_date = date('Y-m-d H:i:s', time());
$session_id = api_get_session_id();
// Tabel definitions
// Table definitions
$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
//verified if exist blog
$sql = 'SELECT COUNT(*) as count FROM '.$tbl_blogs.' WHERE c_id = '.$course_id.' AND blog_name="'.Database::escape_string(
@ -148,20 +144,16 @@ class Blog
$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
VALUES ($course_id, '".get_lang("Welcome")."', '".get_lang(
'FirstPostText'
)."','".$current_date."', '".Database::escape_string((int)$this_blog_id)."', '".Database::escape_string(
(int)$_user['user_id']
)."');";
)."','".$current_date."', '".Database::escape_string((int)$this_blog_id)."', '".api_get_user_id()."');";
Database::query($sql);
// Put it on course homepage
$sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id)
VALUES ($course_id, '".Database::escape_string(
$title
)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id')";
VALUES ($course_id, '".Database::escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0,'$session_id')";
Database::query($sql);
// Subscribe the teacher to this blog
Blog::set_user_subscribed((int)$this_blog_id, (int)$_user['user_id']);
Blog::set_user_subscribed($this_blog_id, api_get_user_id());
}
}
@ -174,7 +166,6 @@ class Blog
*/
public static function edit_blog($blog_id, $title, $subtitle)
{
global $_user;
// Table definitions
$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
@ -267,72 +258,68 @@ class Blog
* Creates a new post in a given blog
* @author Toon Keppens
* @param String $title
* @param String $full_text
* @param String $text
* @param Integer $blog_id
*/
public static function create_post($title, $full_text, $file_comment, $blog_id)
public static function create_post($title, $text, $file_comment, $blog_id)
{
global $_user;
$_course = api_get_course_info();
// Table Definitions
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$upload_ok = true;
$has_attachment = false;
$current_date = date('Y-m-d H:i:s', time());
$course_id = api_get_course_int_id();
// Create the post
$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id)
VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string($text)."','".$current_date."', '".(int)$blog_id."', '".api_get_user_id()."');";
Database::query($sql);
$last_post_id = Database::insert_id();
if (!empty($_FILES['user_upload']['name'])) {
$upload_ok = FileManager::process_uploaded_file($_FILES['user_upload']);
$has_attachment = true;
}
if ($upload_ok) {
// Table Definitions
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
// Create the post
$sql = "INSERT INTO $tbl_blogs_posts (c_id, title, full_text, date_creation, blog_id, author_id )
VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string(
$full_text
)."','".$current_date."', '".(int)$blog_id."', '".(int)$_user['user_id']."');";
if ($last_post_id) {
if (!empty($_FILES['user_upload']['name'])) {
$upload_ok = FileManager::process_uploaded_file($_FILES['user_upload']);
$has_attachment = true;
}
Database::query($sql);
$last_post_id = Database::insert_id();
if ($upload_ok) {
if ($has_attachment) {
$courseDir = $_course['path'].'/upload/blog';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
if ($has_attachment) {
$courseDir = $_course['path'].'/upload/blog';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
// Try to add an extension to the file if it hasn't one
$new_file_name = FileManager::add_ext_on_mime(
stripslashes($_FILES['user_upload']['name']),
$_FILES['user_upload']['type']
);
// Try to add an extension to the file if it hasn't one
$new_file_name = FileManager::add_ext_on_mime(
stripslashes($_FILES['user_upload']['name']),
$_FILES['user_upload']['type']
);
// user's file name
$file_name = $_FILES['user_upload']['name'];
// user's file name
$file_name = $_FILES['user_upload']['name'];
if (!FileManager::filter_extension($new_file_name)) {
Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
} else {
$new_file_name = uniqid('');
$new_path = $updir.'/'.$new_file_name;
$result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
$comment = Database::escape_string($file_comment);
// Storing the attachments if any
if ($result) {
$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
"VALUES ($course_id, '".Database::escape_string($file_name)."', '".Database::escape_string(
$comment
)."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval(
$_FILES['user_upload']['size']
)."', '".$blog_id."', '0' )";
$result = Database::query($sql);
$message .= ' / '.get_lang('AttachmentUpload');
if (!FileManager::filter_extension($new_file_name)) {
Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
} else {
$new_file_name = uniqid('');
$new_path = $updir.'/'.$new_file_name;
$result = move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
$comment = Database::escape_string($file_comment);
// Storing the attachments if any
if ($result) {
$sql = 'INSERT INTO '.$blog_table_attachment.'(c_id, filename,comment, path, post_id,size, blog_id,comment_id) '.
"VALUES ($course_id, '".Database::escape_string($file_name)."', '".Database::escape_string(
$comment
)."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".intval(
$_FILES['user_upload']['size']
)."', '".$blog_id."', '0' )";
Database::query($sql);
$message .= ' / '.get_lang('AttachmentUpload');
}
}
}
}
@ -349,16 +336,16 @@ class Blog
* @param String $full_text
* @param Integer $blog_id
*/
public static function edit_post($post_id, $title, $full_text, $blog_id)
public static function edit_post($post_id, $title, $text, $blog_id)
{
// Init
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$course_id = api_get_course_int_id();
// Create the post
$sql = "UPDATE $tbl_blogs_posts SET title = '".Database::escape_string(
$title
)."', full_text = '".Database::escape_string($full_text)."'
$sql = "UPDATE $tbl_blogs_posts SET
title = '".Database::escape_string($title)."',
full_text = '".Database::escape_string($text)."'
WHERE c_id = $course_id AND post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."' LIMIT 1 ;";
Database::query($sql);
}
@ -412,8 +399,8 @@ class Blog
$parent_id,
$task_id = 'NULL'
) {
global $_user;
$_course = api_get_course_info();
$userId = api_get_user_id();
global $blog_table_attachment;
$upload_ok = true;
@ -434,7 +421,7 @@ class Blog
$sql = "INSERT INTO $tbl_blogs_comments (c_id, title, comment, author_id, date_creation, blog_id, post_id, parent_comment_id, task_id )
VALUES ($course_id, '".Database::escape_string($title)."', '".Database::escape_string(
$full_text
)."', '".(int)$_user['user_id']."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
)."', '".$userId."','".$current_date."', '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
Database::query($sql);
// Empty post values, or they are shown on the page again
@ -543,9 +530,7 @@ class Blog
// Create the task
$sql = "INSERT INTO $tbl_blogs_tasks (c_id, blog_id, title, description, color, system_task )
VALUES ($course_id , '".(int)$blog_id."', '".Database::escape_string(
$title
)."', '".Database::escape_string($description)."', '".Database::escape_string($color)."', '0');";
VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($title)."', '".Database::escape_string($description)."', '".Database::escape_string($color)."', '0');";
Database::query($sql);
$task_id = Database::insert_id();
@ -692,7 +677,7 @@ class Blog
*/
public static function get_personal_task_list()
{
global $_user;
$userId = api_get_user_id();
// Init
$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
@ -701,7 +686,7 @@ class Blog
$course_id = api_get_course_int_id();
if ($_user['user_id']) {
if ($userId) {
$sql = "SELECT task_rel_user.*, task.title, blog.blog_name FROM $tbl_blogs_tasks_rel_user task_rel_user
INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
@ -710,7 +695,7 @@ class Blog
task.c_id = $course_id AND
blog.c_id = $course_id AND
task_rel_user.c_id = $course_id AND
task_rel_user.user_id = ".(int)$_user['user_id']."
task_rel_user.user_id = ".$userId."
ORDER BY target_date ASC";
$result = Database::query($sql);
@ -788,7 +773,6 @@ class Blog
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
global $dateFormatLong;
$course_id = api_get_course_int_id();
@ -1044,7 +1028,7 @@ class Blog
*/
public static function add_rating($type, $blog_id, $item_id, $rating)
{
global $_user;
$userId = api_get_user_id();
// Init
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
@ -1056,20 +1040,16 @@ class Blog
blog_id = '".(int)$blog_id."'
AND item_id = '".(int)$item_id."'
AND rating_type = '".Database::escape_string($type)."'
AND user_id = '".(int)$_user['user_id']."'";
AND user_id = '".$userId."'";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) // Add rating
{
// Add rating
if (Database::num_rows($result) == 0) {
$sql = "INSERT INTO $tbl_blogs_rating (c_id, blog_id, rating_type, item_id, user_id, rating )
VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string(
$type
)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".Database::escape_string($rating)."')";
$result = Database::query($sql);
VALUES ($course_id, '".(int)$blog_id."', '".Database::escape_string($type)."', '".(int)$item_id."', '".$userId."', '".Database::escape_string($rating)."')";
Database::query($sql);
return true;
} else // Return
{
} else {
return false;
}
}
@ -1089,9 +1069,13 @@ class Blog
$course_id = api_get_course_int_id();
// Calculate rating
$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."' AND item_id = '".(int)$item_id."' AND rating_type = '".Database::escape_string(
$type
)."' ";
$sql = "SELECT AVG(rating) as rating
FROM $tbl_blogs_rating
WHERE
c_id = $course_id AND
blog_id = '".(int)$blog_id."' AND
item_id = '".(int)$item_id."' AND
rating_type = '".Database::escape_string($type)."'";
$result = Database::query($sql);
$result = Database::fetch_array($result);
@ -1110,7 +1094,7 @@ class Blog
*/
public static function display_rating_form($type, $blog_id, $post_id, $comment_id = null)
{
global $_user;
$userId = api_get_user_id();
$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
$course_id = api_get_course_int_id();
@ -1121,35 +1105,30 @@ class Blog
blog_id = '".(int)$blog_id."'
AND item_id = '".(int)$post_id."'
AND rating_type = '".Database::escape_string($type)."'
AND user_id = '".(int)$_user['user_id']."'";
AND user_id = '".$userId."'";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) // Add rating
{
return ' - '.get_lang(
'RateThis'
).': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$post_id.'" name="frm_rating_'.$type.'_'.$post_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$post_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /></form>';
} else // Return
{
// Add rating
if (Database::num_rows($result) == 0) {
return ' - '.get_lang('RateThis').': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$post_id.'" name="frm_rating_'.$type.'_'.$post_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$post_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /></form>';
} else {
// Return
return '';
}
}
if ($type = 'comment') {
// Check if the user has already rated this comment
$sql = "SELECT rating_id FROM $tbl_blogs_rating
WHERE c_id = $course_id AND blog_id = '".(int)$blog_id."'
AND item_id = '".(int)$comment_id."'
AND rating_type = '".Database::escape_string($type)."'
AND user_id = '".(int)$_user['user_id']."'";
AND user_id = '".$userId."'";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) // Add rating
{
return ' - '.get_lang(
'RateThis'
).': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$comment_id.'" name="frm_rating_'.$type.'_'.$comment_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$comment_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /><input type="hidden" name="comment_id" value="'.$comment_id.'" /></form>';
} else // Return
{
// Add rating
if (Database::num_rows($result) == 0) {
return ' - '.get_lang('RateThis').': <form method="get" action="blog.php" style="display: inline" id="frm_rating_'.$type.'_'.$comment_id.'" name="frm_rating_'.$type.'_'.$comment_id.'"><select name="rating" onchange="document.forms[\'frm_rating_'.$type.'_'.$comment_id.'\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="'.$type.'" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="'.$blog_id.'" /><input type="hidden" name="post_id" value="'.$post_id.'" /><input type="hidden" name="comment_id" value="'.$comment_id.'" /></form>';
} else {
// Return
return '';
}
}
@ -1162,6 +1141,7 @@ class Blog
* @param Integer $current_level
* @param Integer $blog_id
* @param Integer $post_id
* @param int $task_id
*/
public static function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
{
@ -1271,146 +1251,42 @@ class Blog
public static function display_form_new_post($blog_id)
{
if (api_is_allowed('BLOG_'.$blog_id, 'article_add')) {
echo '<script type="text/javascript">
function FCKeditor_OnComplete( editorInstance )
{
editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
}
function check_for_title()
{
// 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(\'post_full_text\') ;
// 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() ;
}
// 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] + \'...\';
}
}
if(document.getElementById(\'post_title_edited\').value == "false")
{
document.getElementById(\'post_title\').value = bestandsnaamNieuw;
}
}
function trim(s) {
while(s.substring(0,1) == \' \') {
s = s.substring(1,s.length);
}
while(s.substring(s.length-1,s.length) == \' \') {
s = s.substring(0,s.length-1);
}
return s;
}
function check_if_still_empty()
{
if(trim(document.getElementById(\'post_title\').value) != "")
{
document.getElementById(\'post_title_edited\').value = "true";
}
}
</script>';
echo '<form name="add_post" enctype="multipart/form-data" method="post" action="blog.php?action=new_post&blog_id='.$blog_id.'">';
echo '<input type="hidden" name="post_title_edited" id="post_title_edited" value="false" />';
// form title
echo '<legend>'.get_lang('NewPost').'</legend>';
// article title
echo '<div><span class="form_required">*</span>'.get_lang(
'Title'
).': <input name="post_title" id="post_title" type="text" size="60" onblur="check_if_still_empty()" /></div><br />';
// article text
$oFCKeditor = new FCKeditor('post_full_text');
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '200';
if (!api_is_allowed_to_edit()) {
$oFCKeditor->ToolbarSet = 'ProjectStudent';
} else {
$oFCKeditor->ToolbarSet = 'Project';
}
$oFCKeditor->Value = isset($_POST['post_full_text']) ? stripslashes($_POST['post_full_text']) : '';
echo '<div class="control-group">';
$oFCKeditor->Create();
echo '</div>';
$url = api_get_path(WEB_PUBLIC_PATH).'main/blog/blog.php?action=new_post&blog_id='.$blog_id;
// attachment
echo '<div class="control-group">
<label class="control-label">
'.get_lang('AddAnAttachment').'
</label>
<div class="controls">
<input type="file" name="user_upload"/>
</div>
</div>';
// comment
echo '<div class="control-group">
<label class="control-label">
'.get_lang('FileComment').'
</label>
<div class="controls">
<textarea name="post_file_comment" cols="34" /></textarea>
</div>
</div>';
// submit
echo '<div class="control-group">
<div class="controls">
<input type="hidden" name="action" value="" />
<input type="hidden" name="new_post_submit" value="true" />
<button class="save" type="submit" name="Submit">'.get_lang('Save').'</button>
</div>
</div>';
echo '</form>';
$form = new FormValidator('add_post', 'post', $url, null, array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('NewPost'));
$form->addElement('hidden', 'post_title_edited', 'false');
$form->addElement('hidden', 'new_post_submit', 'true');
self::setForm($form);
$form->display();
} else {
api_not_allowed();
}
}
/**
* @param FormValidator $form
* @return mixed
*/
public static function setForm($form)
{
$form->addElement('hidden', 'action', '');
$form->addElement('text', 'post_title', get_lang('Title'));
$form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html_editor', 'post_full_text', get_lang('Content'));
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
$form->addElement('text', 'post_file_comment', get_lang('FileComment'));
$form->addElement('button', 'submit', get_lang('Save'));
return $form;
}
/**
* Displays the form to edit a post
* @author Toon Keppens
@ -1438,52 +1314,22 @@ class Blog
// Prepare data
$blog_post_text = stripslashes($blog_post['full_text']);
$text = isset($_POST['post_full_text']) ? stripslashes($_POST['post_full_text']) : $blog_post_text;
echo '<form name="edit_post" method="post" action="blog.php?action=edit_post&post_id='.Security::remove_XSS(
$_GET['post_id']
).'&blog_id='.Security::remove_XSS($blog_id).'&article_id='.Security::remove_XSS(
$_GET['article_id']
).'&task_id='.Security::remove_XSS($_GET['task_id']).'">';
// form title
echo '<legend>'.get_lang('EditPost').'</legend>';
// article title
echo '<div><span class="form_required">*</span>'.get_lang(
'Title'
).': <input name="post_title" id="post_title" type="text" size="60" value="'.stripslashes(
$blog_post['title']
).'" /><br /></div>';
// article text
$oFCKeditor = new FCKeditor('post_full_text');
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '200';
if (!api_is_allowed_to_edit()) {
$oFCKeditor->ToolbarSet = 'ProjectStudent';
} else {
$oFCKeditor->ToolbarSet = 'Project';
}
$oFCKeditor->Value = isset($_POST['post_full_text']) ? stripslashes($_POST['post_full_text']) : $blog_post_text;
echo '<div class="controls">';
echo $oFCKeditor->Create();
echo '</div>';
// submit
echo ' <div class="control-group">
$url = api_get_path(WEB_PUBLIC_PATH).'main/blog/blog.php?action=edit_post&post_id='.intval($_GET['post_id']).'&blog_id='.intval($blog_id).'&article_id='.intval($_GET['article_id']).'&task_id='.intval($_GET['task_id']);
<div class="controls">
<input type="hidden" name="action" value="" />
<input type="hidden" name="edit_post_submit" value="true" />
<input type="hidden" name="post_id" value="'.(int)$_GET['post_id'].'" />
<button class="save" type="submit" name="Submit">'.get_lang('Save').'</button>
</div>
</div>';
$form = new FormValidator('edit_post', 'post', $url, null, array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('EditPost'));
$form->addElement('hidden', 'edit_post_submit', 'true');
$form->addElement('hidden', 'post_id', intval($_GET['post_id']));
echo '</form>';
$defaults = array(
'post_title' => $blog_post['title'],
'post_full_text' => $text,
);
$form->setDefaults($defaults);
self::setForm($form);
$form->display();
}
/**
@ -2332,13 +2178,13 @@ class Blog
// Subscribe the user
$sql = "INSERT INTO $tbl_blogs_rel_user (c_id, blog_id, user_id ) VALUES ($course_id, '".(int)$blog_id."', '".(int)$user_id."');";
$result = Database::query($sql);
Database::query($sql);
// Give this user basic rights
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action) VALUES ($course_id, '".(int)$user_id."','BLOG_".(int)$blog_id."','article_add')";
$result = Database::query($sql);
Database::query($sql);
$sql = "INSERT INTO $tbl_user_permissions (c_id, user_id,tool,action) VALUES ($course_id, '".(int)$user_id."','BLOG_".(int)$blog_id."','article_comments_add')";
$result = Database::query($sql);
Database::query($sql);
}
/**
@ -2418,6 +2264,8 @@ class Blog
$student_list = CourseManager :: get_student_list_from_course_code(api_get_course_int_id(), false, $session_id);
$user_data = array();
$selectAll = isset($_GET['selectall']) ? $_GET['selectall'] : null;
// Add users that are not in this blog to the list.
foreach ($student_list as $key => $user) {
if (isset($user['id_user'])) {
@ -2426,7 +2274,7 @@ class Blog
if (!in_array($user['user_id'], $blog_member_ids)) {
$a_infosUser = UserManager :: get_user_info_by_id($user['user_id']);
$row = array();
$row[] = '<input type="checkbox" name="user[]" value="'.$a_infosUser['user_id'].'" '.(($_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '').'/>';
$row[] = '<input type="checkbox" name="user[]" value="'.$a_infosUser['user_id'].'" '.(($selectAll == "subscribe") ? ' checked="checked" ' : '').'/>';
$username = api_htmlentities(sprintf(get_lang('LoginX'), $a_infosUser["username"]), ENT_QUOTES);
if ($is_western_name_order) {
$row[] = $a_infosUser["firstname"];
@ -2482,7 +2330,8 @@ class Blog
*/
public static function display_form_user_unsubscribe($blog_id)
{
global $_user;
$userId = api_get_user_id();
$is_western_name_order = api_is_western_name_order();
// Init
@ -2553,7 +2402,7 @@ class Blog
$row[] = $task;
//Link to register users
if ($myrow["user_id"] != $_user['user_id']) {
if ($myrow["user_id"] != $userId) {
$row[] = "<a class=\"btn\" href=\"".api_get_self(
)."?action=manage_members&amp;blog_id=$blog_id&amp;unregister=yes&amp;user_id=".$myrow[user_id]."\">".get_lang(
'UnRegister'
@ -2611,75 +2460,35 @@ class Blog
*/
public static function display_new_comment_form($blog_id, $post_id, $title)
{
echo '<form name="add_post" enctype="multipart/form-data" method="post" action="blog.php?action=view_post&amp;blog_id='.intval(
$blog_id
).'&amp;post_id='.intval($post_id).'">';
$url = api_get_path(WEB_PUBLIC_PATH).'main/blog/blog.php?action=view_post&blog_id='.intval($blog_id).'&post_id='.intval($post_id);
$form = new FormValidator('add_post', 'post', $url, null, array('enctype' => 'multipart/form-data'));
$form->addElement('header', isset($_GET['task_id']) ? get_lang('ExecuteThisTask') : get_lang('AddNewComment'));
$form->addElement('text', 'comment_title', get_lang('Title'));
// form title
echo '<legend>';
echo (isset($_GET['task_id']) ? get_lang('ExecuteThisTask') : get_lang('AddNewComment'));
echo '</legend>';
// comment title
echo '<div><span class="form_required">*</span>'.get_lang(
'Title'
).': <input name="comment_title" id="comment_title" type="text" size="60" value="Re: '.stripslashes(
$title
).'" /></div><br />';
// comment text
$oFCKeditor = new FCKeditor('comment_text');
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '200';
if (!api_is_allowed_to_edit()) {
$oFCKeditor->ToolbarSet = 'ProjectCommentStudent';
} else {
$oFCKeditor->ToolbarSet = 'ProjectComment';
}
$oFCKeditor->Value = isset($_POST['comment_text']) ? stripslashes($_POST['comment_text']) : '';
echo '<div class="controls">';
echo $oFCKeditor->Create();
echo '
</div>';
$form->addElement('html_editor', 'comment_text');
$content = isset($_POST['comment_text']) ? $_POST['comment_text'] : '';
// attachment
echo ' <div class="control-group">
<label class="control-label">
'.get_lang('AddAnAttachment').'
</label>
<div class="controls">
<input type="file" name="user_upload"/>
</div>
</div>';
$form->setDefaults(array(
'comment_title' => $title,
'comment_text' => $content
));
// attachment comment
echo ' <div class="control-group">
<label class="control-label">
'.get_lang('FileComment').'
</label>
<div class="controls">
<textarea name="post_file_comment" cols="34" /></textarea>
</div>
</div>';
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
$form->addElement('text', 'post_file_comment', get_lang('FileComment'));
$form->addElement('hidden', 'action', '');
$form->addElement('hidden', 'comment_parent_id', 0);
// attachment comment
echo ' <div class="control-group">
<div class="controls">
<input type="hidden" name="action" value="" />
<input type="hidden" name="comment_parent_id" id="comment_parent_id" value="0" />';
if (isset($_GET['task_id'])) {
echo ' <input type="hidden" name="new_task_execution_submit" value="true" />';
echo ' <input type="hidden" name="task_id" value="'.intval($_GET['task_id']).'" />';
$form->addElement('hidden', 'new_task_execution_submit', 'true');
$form->addElement('hidden', 'task_id', intval($_GET['task_id']));
} else {
echo ' <input type="hidden" name="new_comment_submit" value="true" />';
$form->addElement('hidden', 'new_comment_submit', 'true');
}
echo ' <button class="save" type="submit" name="Submit">'.get_lang('Save').'</button>
</div>
</div>';
echo '</form>';
$form->addElement('button', 'submit', get_lang('Save'));
$form->display();
}
/**
* show the calender of the given month
* @author Patrick Cool
@ -2694,14 +2503,16 @@ class Blog
*/
public static function display_minimonthcalendar($month, $year, $blog_id)
{
// Init
global $_user;
global $DaysShort;
global $MonthsLong;
$userId = api_get_user_id();
$posts = array();
$tasks = array();
$filter = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
$tbl_users = Database::get_main_table(TABLE_MAIN_USER);
$tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
@ -2723,12 +2534,8 @@ class Blog
//Start the week on monday
$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
$backwardsURL = api_get_self()."?blog_id=".(int)$_GET['blog_id']."&amp;filter=".Security::remove_XSS(
$_GET['filter']
)."&amp;month=".($month == 1 ? 12 : $month - 1)."&amp;year=".($month == 1 ? $year - 1 : $year);
$forewardsURL = api_get_self()."?blog_id=".(int)$_GET['blog_id']."&amp;filter=".Security::remove_XSS(
$_GET['filter']
)."&amp;month=".($month == 12 ? 1 : $month + 1)."&amp;year=".($month == 12 ? $year + 1 : $year);
$backwardsURL = api_get_self()."?blog_id=".(int)$_GET['blog_id']."&amp;filter=".$filter."&amp;month=".($month == 1 ? 12 : $month - 1)."&amp;year=".($month == 1 ? $year - 1 : $year);
$forewardsURL = api_get_self()."?blog_id=".(int)$_GET['blog_id']."&amp;filter=".$filter."&amp;month=".($month == 12 ? 1 : $month + 1)."&amp;year=".($month == 12 ? $year + 1 : $year);
// Get posts for this month
$sql = "SELECT post.*, DAYOFMONTH(date_creation) as post_day, user.lastname, user.firstname FROM $tbl_blogs_posts post
@ -2752,7 +2559,7 @@ class Blog
}
// Get tasks for this month
if ($_user['user_id']) {
if ($userId) {
$sql = " SELECT task_rel_user.*, DAYOFMONTH(target_date) as task_day, task.title, blog.blog_name
FROM $tbl_blogs_tasks_rel_user task_rel_user
INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
@ -2761,7 +2568,7 @@ class Blog
task_rel_user.c_id = $course_id AND
task.c_id = $course_id AND
blog.c_id = $course_id AND
task_rel_user.user_id = '".(int)$_user['user_id']."'
task_rel_user.user_id = '".$userId."'
AND MONTH(target_date) = '".(int)$month."'
AND YEAR(target_date) = '".(int)$year."'
ORDER BY target_date ASC";
@ -2809,7 +2616,7 @@ class Blog
$bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
$dayheader = "$curday";
if (($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon])) {
if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
$dayheader = "$curday";
$class = "class=\"days_today\"";
}
@ -2920,7 +2727,8 @@ class Blog
*/
public static function display_blog_list()
{
global $charset, $_user;
global $charset;
$userInfo = api_get_user_info();
$course_id = api_get_course_int_id();
// Init
$counter = 0;
@ -2931,7 +2739,8 @@ class Blog
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id, false);
$sql = "SELECT blog_name,blog_subtitle,visibility,blog_id FROM $tbl_blogs WHERE c_id = $course_id ORDER BY date_creation DESC";
$sql = "SELECT blog_name,blog_subtitle,visibility,blog_id
FROM $tbl_blogs WHERE c_id = $course_id ORDER BY date_creation DESC";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($row_project = Database::fetch_row($result)) {
@ -2939,14 +2748,13 @@ class Blog
}
}
$list_content_blog = array();
$list_body_blog = array();
if (is_array($list_info)) {
foreach ($list_info as $key => $info_log) {
//validacion when belongs to a session
$session_img = api_get_session_image($info_log[4], $_user['status']);
// Validation when belongs to a session
$session_img = api_get_session_image($info_log[4], $userInfo['status']);
$url_start_blog = 'blog.php'."?"."blog_id=".$info_log[3]."&amp;".api_get_cidreq();
$title = $info_log[0];
@ -3172,8 +2980,5 @@ function get_blog_comment_from_user($course_code, $user_id)
$return_data .= '<br />';
}
}
return $return_data;
}
?>

@ -9,114 +9,108 @@
* Code
*/
require_once 'promotion.lib.php';
require_once 'fckeditor/fckeditor.php';
define ('CAREER_STATUS_ACTIVE', 1);
define ('CAREER_STATUS_INACTIVE',0);
/**
* @package chamilo.library
*/
class Career extends Model {
var $table;
var $columns = array('id', 'name','description','status','created_at','updated_at');
public function __construct() {
class Career extends Model
{
const CAREER_STATUS_ACTIVE = 1;
const CAREER_STATUS_INACTIVE = 0;
public $table;
public $columns = array('id', 'name','description','status','created_at','updated_at');
public function __construct()
{
$this->table = Database::get_main_table(TABLE_CAREER);
}
}
/**
* Get the count of elements
*/
public function get_count() {
public function get_count()
{
$row = Database::select('count(*) as count', $this->table, array(),'first');
return $row['count'];
}
public function get_all($where_conditions = array()) {
return Database::select('*',$this->table, array('where'=>$where_conditions,'order' =>'name ASC'));
}
/**
* Update all promotion status by career
* @param int career id
* @param int status (1 or 0)
*/
public function update_all_promotion_status_by_career_id($career_id, $status) {
$promotion = new Promotion();
$promotion = new Promotion();
$promotion_list = $promotion->get_all_promotions_by_career_id($career_id);
if (!empty($promotion_list)) {
foreach($promotion_list as $item) {
foreach($promotion_list as $item) {
$params['id'] = $item['id'];
$params['status'] = $status;
$promotion->update($params);
$promotion->update_all_sessions_status_by_promotion_id($params['id'], $status);
$params['status'] = $status;
$promotion->update($params);
$promotion->update_all_sessions_status_by_promotion_id($params['id'], $status);
}
}
}
/**
* Displays the title + grid
*/
public function display() {
public function display()
{
// action links
echo '<div class="actions" style="margin-bottom:20px">';
echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('new_career.png',get_lang('Add'),'','32').'</a>';
echo '</div>';
echo Display::grid_html('careers');
echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('new_career.png',get_lang('Add'),'','32').'</a>';
echo '</div>';
echo Display::grid_html('careers');
}
public function get_status_list() {
return array(CAREER_STATUS_ACTIVE => get_lang('Unarchived'), CAREER_STATUS_INACTIVE => get_lang('Archived'));
public function get_status_list()
{
return array(self::CAREER_STATUS_ACTIVE => get_lang('Unarchived'), self::CAREER_STATUS_INACTIVE => get_lang('Archived'));
}
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string url
* @param string action add, edit
* @return obj form validator obj
* @return obj form validator obj
*/
public function return_form($url, $action) {
$oFCKeditor = new FCKeditor('description') ;
$oFCKeditor->ToolbarSet = 'careers';
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '200';
$oFCKeditor->Value = '';
$oFCKeditor->CreateHtml();
public function return_form($url, $action)
{
$form = new FormValidator('career', 'post', $url);
// Settting the form elements
$header = get_lang('Add');
// Setting the form elements
$header = get_lang('Add');
if ($action == 'edit') {
$header = get_lang('Modify');
}
$form->addElement('header', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('hidden', 'id', $id);
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));
$status_list = $this->get_status_list();
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
if ($action == 'edit') {
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
}
if ($action == 'edit') {
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
} else {
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
}
// Setting the defaults
$defaults = $this->get($id);
if (!empty($defaults['created_at'])) {
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
}
@ -124,12 +118,12 @@ class Career extends Model {
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
}
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
return $form;
return $form;
}
/**
* Copies the career to a new one
* @param integer Career ID
@ -161,7 +155,7 @@ class Career extends Model {
if ($copy_promotions) {
//Now also copy each session of the promotion as a new session and register it inside the promotion
$promotion = new Promotion();
$promo_list = $promotion->get_all_promotions_by_career_id($id);
$promo_list = $promotion->get_all_promotions_by_career_id($id);
if (!empty($promo_list)) {
foreach($promo_list as $item) {
$pid = $promotion->copy($item['id'], $cid);
@ -169,8 +163,8 @@ class Career extends Model {
}
}
return $cid;
}
}
public function get_status($career_id) {
$TBL_CAREER = Database::get_main_table(TABLE_CAREER);
$career_id = intval($career_id);
@ -182,10 +176,10 @@ class Career extends Model {
} else {
return false;
}
}
public function save($params, $show_query = false) {
$id = parent::save($params, $show_query);
if (!empty($id)) {
@ -193,9 +187,9 @@ class Career extends Model {
}
return $id;
}
public function delete($id) {
parent::delete($id);
event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
}
}
}

@ -1,260 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/* INIT SECTION */
$language_file = array('create_course', 'document');
require_once 'global.inc.php';
/* Libraries */
require_once api_get_path(LIBRARY_PATH).'fckeditor/repository.php';
require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
//if(!$is_in_admin){
if (!api_is_platform_admin()){
api_protect_course_script();
}
//session
if(isset($_GET['id_session'])) {
$_SESSION['id_session'] = intval($_GET['id_session']);
}
$htmlHeadXtra[] =
"<script type=\"text/javascript\">
function confirmation (name)
{
if (confirm(\" ". api_utf8_encode(get_lang('AreYouSureToDelete')) ." \"+ name + \" ?\"))
{return true;}
else
{return false;}
}
</script>";
/* Variables
- some need defining before inclusion of libraries */
$sType = isset($sType) ? $sType : '';
if ($sType=="MP3") $sType="audio";
// Resource type
$sType = strtolower($sType);
// Choosing the repository to be used.
if (api_is_in_course()) {
if (!api_is_in_group()) {
// 1. We are inside a course and not in a group.
if (api_is_allowed_to_edit()) {
// 1.1. Teacher
$base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/';
$http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/';
} else {
// 1.2. Student
$base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
$http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
}
} else {
// 2. Inside a course and inside a group.
$base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
$http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
}
} else {
if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin') {
// 3. Platform administration activities.
$base_work_dir = api_get_path(SYS_DATA_PATH).'default_platform_document/';
$http_www = api_get_path(WEB_PUBLIC_PATH).'data/default_platform_document/';
} else {
// 4. The user is outside courses.
$my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'system');
$base_work_dir = $my_path['dir'].'my_files/';
$my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web');
$http_www = $my_path['dir'].'my_files/';
}
}
// Set the upload path according to the resource type.
if ($sType == 'audio') {
check_and_create_resource_directory($base_work_dir, '/audio', get_lang('Audio'));
$base_work_dir = $base_work_dir.'audio/';
$http_www = $http_www.'audio/';
$path = "/audio/";
} elseif ($sType == 'flash') {
check_and_create_resource_directory($base_work_dir, '/flash', get_lang('Flash'));
$base_work_dir = $base_work_dir.'flash/';
$http_www = $http_www.'flash/';
$path = "/flash/";
} elseif ($sType == 'images') {
check_and_create_resource_directory($base_work_dir, '/images', get_lang('Images'));
$base_work_dir = $base_work_dir.'images/';
$http_www = $http_www.'images/';
$path = "/images/";
} elseif ($sType == 'video') {
check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
$base_work_dir = $base_work_dir.'video/';
$http_www = $http_www.'video/';
$path = "/video/";
} elseif ($sType == 'video/flv') {
check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
check_and_create_resource_directory($base_work_dir, '/video/flv', 'flv');
$base_work_dir = $base_work_dir.'video/flv/';
$http_www = $http_www.'video/flv/';
$path = "/video/flv/";
}
$course_dir = $_course['path'].'/document/'.$sType;
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$dbl_click_id = 0; // used to avoid double-click
$is_allowed_to_edit = api_is_allowed_to_edit();
$req_gid = '';
/* Constants and variables */
$course_quota = DocumentManager::get_course_quota();
/* MAIN SECTION */
/* Header */
$tool_name = get_lang('Doc'); // Title of the page (should come from the language file)
?>
<style type="text/css" media="screen, projection">
/*<![CDATA[*/
@import "<?php echo api_get_path(WEB_CSS_PATH); ?>public_admin/default.css";
/*]]>*/
</style>
<?php
if(api_get_setting('stylesheets')<>'')
{
?>
<style type="text/css" media="screen, projection">
/*<![CDATA[*/
@import "<?php echo api_get_path(WEB_CSS_PATH), api_get_setting('stylesheets'); ?>/default.css";
/*]]>*/
</style>
<?php
}
$is_allowed_to_edit = api_is_allowed_to_edit();
if ($is_allowed_to_edit) { // TEACHER ONLY
/* DELETE FILE OR DIRECTORY */
if (isset($_GET['delete'])) {
if (DocumentManager::delete_document($_course,$_GET['delete'], $base_work_dir)) {
Display::display_normal_message(api_utf8_encode(get_lang('DocDeleted')));
} else {
Display::display_normal_message(api_utf8_encode(get_lang('DocDeleteError')));
}
}
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'delete':
foreach ($_POST['path'] as $index => $path) {
DocumentManager::delete_document($_course, $path, $base_work_dir);
}
Display::display_normal_message(api_utf8_encode(get_lang('DocDeleted')));
break;
}
}
}
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
$docs_and_folders = getlist ($base_work_dir.'/');
if ($docs_and_folders) {
//create a sortable table with our data
$sortable_data = array();
while (list ($key, $id) = each($docs_and_folders)) {
// Skip directories.
if ($id['filetype'] != 'file') {
continue;
}
$row = array ();
//if the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = ($id['visibility'] == 0) ? '<span class="invisible">' : '';
$invisibility_span_close = ($id['visibility'] == 0) ? '</span>' : '';
//size (or total size of a directory)
$size = $id['filetype'] == 'folder' ? FileManager::get_total_folder_size($id['path'], $is_allowed_to_edit) : $id[size];
//get the title or the basename depending on what we're using
if ($id['title'] != '') {
$document_name = $id['title'];
} else {
$document_name = basename($id['path']);
}
// icons with hyperlinks
$row[]= '<a href="#" onclick="javascript: OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.build_document_icon_tag($id['filetype'],$id['path']).'</a>';
//document title with hyperlink
$row[] = '<a href="#" onclick="javascript: OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.$id['title'].'</a>';
//comments => display comment under the document name
//$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
$display_size = Text::format_file_size($size);
$row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
//last edit date
$display_date = date('d.m.Y', (strtotime($id['lastedit_date'])));
$row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
$sortable_data[] = $row;
}
} else {
$sortable_data = array();
//$table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
}
$table = new SortableTableFromArray($sortable_data, 4, 10);
$query_vars['curdirpath'] = $curdirpath;
if (isset($_SESSION['_gid'])) {
$query_vars['gidReq'] = $_SESSION['_gid'];
}
$table->set_additional_parameters($query_vars);
$column = 0;
/*
if ($is_allowed_to_edit AND count($docs_and_folders) > 1) {
$table->set_header($column++, '', false);
}
*/
$table->set_header($column++, api_htmlentities(get_lang('Type'), ENT_QUOTES));
$table->set_header($column++, api_htmlentities(get_lang('Title'), ENT_QUOTES));
//$column_header[] = array(get_lang('Comment'),true); => display comment under the document name
$table->set_header($column++, api_htmlentities(get_lang('Size'), ENT_QUOTES));
$table->set_header($column++, api_htmlentities(get_lang('Date'), ENT_QUOTES));
echo api_utf8_encode($table->get_table_html());
echo api_utf8_encode($table_footer);
// Functions
?>
<script>
<!--
function OpenFile( fileUrl, type )
{
if (type=="audio")
{
ret = confirm('<?php echo api_utf8_encode(get_lang('AutostartMp3')); ?>');
if (ret)
{
GetE('autostart').checked = true;
}
else
{
GetE('autostart').checked = false;
}
}
SetUrl( fileUrl ) ;
//window.close() ;
}
//-->
</script>

@ -84,7 +84,7 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
}
/**
* Build this element using FCKeditor
* Build this element using an editor
*/
public function buildEditor()
{

@ -10,31 +10,33 @@
*/
require_once 'career.lib.php';
require_once 'fckeditor/fckeditor.php';
define ('PROMOTION_STATUS_ACTIVE', 1);
define ('PROMOTION_STATUS_INACTIVE',0);
define ('PROMOTION_STATUS_INACTIVE', 0);
/**
* @package chamilo.library
*/
class Promotion extends Model {
var $table;
var $columns = array('id','name','description','career_id','status','created_at','updated_at');
public function __construct() {
class Promotion extends Model
{
public $table;
public $columns = array('id', 'name', 'description', 'career_id', 'status', 'created_at', 'updated_at');
public function __construct()
{
$this->table = Database::get_main_table(TABLE_PROMOTION);
}
/**
* Get the count of elements
*/
public function get_count() {
public function get_count()
{
$row = Database::select('count(*) as count', $this->table, array(),'first');
return $row['count'];
}
/**
* Copies the promotion to a new one
* @param integer Promotion ID
@ -43,78 +45,79 @@ class Promotion extends Model {
* @return integer New promotion ID on success, false on failure
*/
public function copy($id, $career_id = null, $copy_sessions = false) {
$pid = false;
$promotion = $this->get($id);
if (!empty($promotion)) {
$new = array();
foreach ($promotion as $key => $val) {
switch ($key) {
case 'id':
case 'updated_at':
break;
case 'name':
$val .= ' '.get_lang('CopyLabelSuffix');
$new[$key] = $val;
break;
case 'created_at':
$val = api_get_utc_datetime();
$new[$key] = $val;
break;
case 'career_id':
if (!empty($career_id)) {
$val = (int)$career_id;
}
$new[$key] = $val;
default:
$new[$key] = $val;
break;
}
}
if ($copy_sessions) {
/**
* When copying a session we do:
* 1. Copy a new session from the source
* 2. Copy all courses from the session (no user data, no user list)
* 3. Create the promotion
*/
$session_list = SessionManager::get_all_sessions_by_promotion($id);
if (!empty($session_list)) {
$pid = $this->save($new);
if (!empty($pid)) {
$pid = false;
$promotion = $this->get($id);
if (!empty($promotion)) {
$new = array();
foreach ($promotion as $key => $val) {
switch ($key) {
case 'id':
case 'updated_at':
break;
case 'name':
$val .= ' '.get_lang('CopyLabelSuffix');
$new[$key] = $val;
break;
case 'created_at':
$val = api_get_utc_datetime();
$new[$key] = $val;
break;
case 'career_id':
if (!empty($career_id)) {
$val = (int)$career_id;
}
$new[$key] = $val;
default:
$new[$key] = $val;
break;
}
}
if ($copy_sessions) {
/**
* When copying a session we do:
* 1. Copy a new session from the source
* 2. Copy all courses from the session (no user data, no user list)
* 3. Create the promotion
*/
$session_list = SessionManager::get_all_sessions_by_promotion($id);
if (!empty($session_list)) {
$pid = $this->save($new);
if (!empty($pid)) {
$new_session_list = array();
foreach($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, false, false, true);
foreach ($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, false, false, true);
$new_session_list[] = $sid;
}
}
if (!empty($new_session_list)) {
SessionManager::suscribe_sessions_to_promotion($pid, $new_session_list);
}
}
}
} else {
$pid = $this->save($new);
}
}
}
} else {
$pid = $this->save($new);
}
}
return $pid;
}
/**
* Gets all promotions by career id
* @param int career id
* @return array results
*/
public function get_all_promotions_by_career_id($career_id, $order = false) {
public function get_all_promotions_by_career_id($career_id, $order = false)
{
return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id),'order' =>$order));
}
public function get_status_list() {
return array(PROMOTION_STATUS_ACTIVE => get_lang('Active'), PROMOTION_STATUS_INACTIVE => get_lang('Inactive'));
}
}
/**
* Displays the title + grid
* @return string html code
@ -123,76 +126,66 @@ class Promotion extends Model {
// action links
echo '<div class="actions" style="margin-bottom:20px">';
echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('new_promotion.png',get_lang('Add'),'','32').'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('new_promotion.png',get_lang('Add'),'','32').'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'','32').'</a>';
echo '</div>';
echo Display::grid_html('promotions');
echo Display::grid_html('promotions');
}
/**
* Update all session status by promotion
* @param int promotion id
* @param int status (1, 0)
*/
public function update_all_sessions_status_by_promotion_id($promotion_id, $status) {
$session_list = SessionManager::get_all_sessions_by_promotion($promotion_id);
$session_list = SessionManager::get_all_sessions_by_promotion($promotion_id);
if (!empty($session_list)) {
foreach($session_list as $item) {
SessionManager::set_session_status($item['id'], $status);
SessionManager::set_session_status($item['id'], $status);
}
}
}
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string url
* @param string header name
* @return obj form validator obj
* @return obj form validator obj
*/
function return_form($url, $action = 'add') {
$oFCKeditor = new FCKeditor('description') ;
$oFCKeditor->ToolbarSet = 'careers';
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '200';
$oFCKeditor->Value = '';
$oFCKeditor->CreateHtml();
$form = new FormValidator('promotion', 'post', $url);
// Settting the form elements
// Setting the form elements
$header = get_lang('Add');
if ($action == 'edit') {
$header = get_lang('Modify');
}
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('header', '', $header);
$form->addElement('hidden', 'id', $id);
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70','id' => 'name'));
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70','id' => 'name'));
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));
$career = new Career();
$careers = $career->get_all();
$career_list = array();
foreach($careers as $item) {
$career_list = array();
foreach($careers as $item) {
$career_list[$item['id']] = $item['name'];
}
$form->addElement('select', 'career_id', get_lang('Career'), $career_list);
$status_list = $this->get_status_list();
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
if ($action == 'edit') {
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
}
}
if ($action == 'edit') {
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
} else {
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
}
// Setting the defaults
$defaults = $this->get($id);
if (!empty($defaults['created_at'])) {
@ -200,32 +193,32 @@ class Promotion extends Model {
}
if (!empty($defaults['updated_at'])) {
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
}
}
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
public function save($params, $show_query = false) {
$id = parent::save($params, $show_query);
if (!empty($id)) {
event_system(LOG_PROMOTION_CREATE, LOG_PROMOTION_ID, $id, api_get_utc_datetime(), api_get_user_id());
}
return $id;
return $id;
}
public function delete($id)
public function delete($id)
{
if (parent::delete($id)) {
SessionManager::clear_session_ref_promotion($id);
event_system(LOG_PROMOTION_DELETE, LOG_PROMOTION_ID, $id, api_get_utc_datetime(), api_get_user_id());
event_system(LOG_PROMOTION_DELETE, LOG_PROMOTION_ID, $id, api_get_utc_datetime(), api_get_user_id());
} else {
return false;
}
}
}
}

@ -96,7 +96,6 @@ $session_id = api_get_session_id();
api_protect_course_script(true);
require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php';
$lpfound = false;
$myrefresh = 0;

@ -8,24 +8,24 @@
* Initialization
*/
$language_file = array('registration','messages','userInfo','admin');
$cidReset=true;
$cidReset = true;
require_once '../inc/global.inc.php';
$app['template.show_footer'] = false;
$app['template.show_header'] = false;
$app['default_layout'] = 'default/layout/blank.tpl';
api_block_anonymous_users();
if (api_get_setting('allow_social_tool') !='true') {
api_not_allowed();
}
require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php';
$tok = Security::get_token();
if (isset($_REQUEST['user_friend'])) {
$info_user_friend=array();
$info_path_friend=array();
$userfriend_id = intval($_REQUEST['user_friend']);
// panel=1 send message
// panel=2 send invitation
$panel = Security::remove_XSS($_REQUEST['view_panel']);
$info_user_friend = api_get_user_info($userfriend_id);
$info_path_friend = UserManager::get_user_picture_path_by_id($userfriend_id,'web',false,true);
@ -35,7 +35,7 @@ $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
$message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
$actions = array('add_message_group', 'edit_message_group', 'reply_message_group');
$allowed_action = (isset($_GET['action']) && in_array($_GET['action'],$actions))?Security::remove_XSS($_GET['action']):'';
$allowed_action = isset($_GET['action']) && in_array($_GET['action'],$actions) ? Security::remove_XSS($_GET['action']):'';
$to_group = '';
$subject = '';
@ -49,17 +49,17 @@ if (!empty($group_id) && $allowed_action) {
api_not_allowed(true);
}
$to_group = $group_info['name'];
if (!empty($message_id)) {
$message_info = MessageManager::get_message_by_id($message_id);
if ($allowed_action == 'reply_message_group') {
$subject = get_lang('Reply').': '.api_xml_http_response_encode($message_info['title']);
//$message = api_xml_http_response_encode($message_info['content']);
} else {
$subject = api_xml_http_response_encode($message_info['title']);
$message = api_xml_http_response_encode($message_info['content']);
}
}
$to_group = $group_info['name'];
if (!empty($message_id)) {
$message_info = MessageManager::get_message_by_id($message_id);
if ($allowed_action == 'reply_message_group') {
$subject = get_lang('Reply').': '.api_xml_http_response_encode($message_info['title']);
//$message = api_xml_http_response_encode($message_info['content']);
} else {
$subject = api_xml_http_response_encode($message_info['title']);
$message = api_xml_http_response_encode($message_info['content']);
}
}
}
$page_item = !empty($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']):1;
@ -67,67 +67,38 @@ $param_item_page = isset($_GET['items_page_nr']) && isset($_GET['topic_id']) ? (
if (isset($_GET['topic_id'])) {
$param_item_page .= '&topic_id='.intval($_GET['topic_id']);
}
$page_topic = isset($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']):1;
$anchor_topic = 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_topic ?>&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 />';
$oFCKeditor = new FCKeditor('content') ;
$oFCKeditor->ToolbarSet = 'messages';
$oFCKeditor->Width = '95%';
$oFCKeditor->Height = $height;
$oFCKeditor->Value = $message;
$return = $oFCKeditor->CreateHtml();
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'), Text::format_file_size(api_get_setting('message_max_upload_filesize')))) ?>)
<br />
<br />
<?php if ($allowed_action == 'add_message_group') { ?>
<button class="btn save" onclick="if(validate_text_empty(this.form.title.value,'<?php echo get_lang('YouShouldWriteASubject')?>')){return false;}" type="submit" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>"><?php echo api_xml_http_response_encode(get_lang('SendMessage')) ?></button>
<?php } else { ?>
<button class="btn save" type="submit" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>"><?php echo api_xml_http_response_encode(get_lang('SendMessage')) ?></button>
<?php } ?>
<?php } ?>
</dl>
</td>
</tr>
</div>
</table>
</form>
$page_topic = isset($_GET['topics_page_nr']) ? intval($_GET['topics_page_nr']) : 1;
$anchor_topic = isset($_GET['anchor_topic']) ? Security::remove_XSS($_GET['anchor_topic']) : null;
$url = api_get_path(WEB_PUBLIC_PATH).'main/social/group_topics.php?id='.$group_id.'&anchor_topic='.$anchor_topic.'&topics_page_nr='.$page_topic.$param_item_page;
$form = new FormValidator('form', 'post', $url, null, array('enctype' => 'multipart/form-data'));
$form->addElement('hidden', 'action', $allowed_action);
$form->addElement('hidden', 'group_id', $group_id);
$form->addElement('hidden', 'parent_id', $message_id);
$form->addElement('hidden', 'message_id', $message_id);
$form->addElement('hidden', '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->addElement('text', 'title', get_lang('Title'));
$height = 140;
}
$form->addElement('html_editor', 'content');
$form->addElement('label', null, get_lang('AttachmentFiles'));
$form->addElement('label', null, '<div id="link-more-attach">
<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>'
);
$form->addElement('html', '<span id="filepaths"></span>');
$form->addElement('file', 'attach_1', sprintf(get_lang('MaximunFileSizeX'), Text::format_file_size(api_get_setting('message_max_upload_filesize'))));
$form->addElement('html', '</div>');
$form->addElement('button', 'submit', get_lang('SendMessage'));
$form->display();
}

Loading…
Cancel
Save