|
|
|
@ -1,18 +1,19 @@ |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This class provides methods for the notebook management. |
|
|
|
|
* Include/require it in your code to use its features. |
|
|
|
|
* @author Carlos Vargas <litox84@gmail.com>, move code of main/notebook up here |
|
|
|
|
* @package chamilo.library |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
class NotebookManager |
|
|
|
|
{ |
|
|
|
|
* This class provides methods for the notebook management. |
|
|
|
|
* Include/require it in your code to use its features. |
|
|
|
|
* @author Carlos Vargas <litox84@gmail.com>, move code of main/notebook up here |
|
|
|
|
* @package chamilo.library |
|
|
|
|
*/ |
|
|
|
|
class NotebookManager { |
|
|
|
|
|
|
|
|
|
private function __construct() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* a little bit of javascript to display a prettier warning when deleting a note |
|
|
|
|
* |
|
|
|
@ -21,11 +22,11 @@ class NotebookManager |
|
|
|
|
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium |
|
|
|
|
* @version januari 2009, dokeos 1.8.6 |
|
|
|
|
*/ |
|
|
|
|
function javascript_notebook() { |
|
|
|
|
return "<script type=\"text/javascript\"> |
|
|
|
|
static function javascript_notebook() { |
|
|
|
|
return "<script> |
|
|
|
|
function confirmation (name) |
|
|
|
|
{ |
|
|
|
|
if (confirm(\" ". get_lang("NoteConfirmDelete") ." \"+ name + \" ?\")) |
|
|
|
|
if (confirm(\" " . get_lang("NoteConfirmDelete") . " \"+ name + \" ?\")) |
|
|
|
|
{return true;} |
|
|
|
|
else |
|
|
|
|
{return false;} |
|
|
|
@ -43,7 +44,7 @@ class NotebookManager |
|
|
|
|
* @version januari 2009, dokeos 1.8.6 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
function save_note($values) { |
|
|
|
|
static function save_note($values) { |
|
|
|
|
if (!is_array($values) or empty($values['note_title'])) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -54,13 +55,13 @@ class NotebookManager |
|
|
|
|
$sql = "INSERT INTO $t_notebook (c_id, user_id, course, session_id, title, description, creation_date,update_date,status) |
|
|
|
|
VALUES( |
|
|
|
|
$course_id, |
|
|
|
|
'".api_get_user_id()."', |
|
|
|
|
'".Database::escape_string(api_get_course_id())."', |
|
|
|
|
'".Database::escape_string($_SESSION['id_session'])."', |
|
|
|
|
'".Database::escape_string($values['note_title'])."', |
|
|
|
|
'".Database::escape_string($values['note_comment'])."', |
|
|
|
|
'".Database::escape_string(date('Y-m-d H:i:s'))."', |
|
|
|
|
'".Database::escape_string(date('Y-m-d H:i:s'))."', |
|
|
|
|
'" . api_get_user_id() . "', |
|
|
|
|
'" . Database::escape_string(api_get_course_id()) . "', |
|
|
|
|
'" . Database::escape_string($_SESSION['id_session']) . "', |
|
|
|
|
'" . Database::escape_string($values['note_title']) . "', |
|
|
|
|
'" . Database::escape_string($values['note_comment']) . "', |
|
|
|
|
'" . Database::escape_string(date('Y-m-d H:i:s')) . "', |
|
|
|
|
'" . Database::escape_string(date('Y-m-d H:i:s')) . "', |
|
|
|
|
'0')"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$id = Database::insert_id(); |
|
|
|
@ -69,13 +70,15 @@ class NotebookManager |
|
|
|
|
api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $id, 'NotebookAdded', api_get_user_id()); |
|
|
|
|
} |
|
|
|
|
$affected_rows = Database::affected_rows(); |
|
|
|
|
if (!empty($affected_rows)){ |
|
|
|
|
if (!empty($affected_rows)) { |
|
|
|
|
return $id; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function get_note_information($notebook_id) { |
|
|
|
|
if (empty($notebook_id)) { return array(); } |
|
|
|
|
static function get_note_information($notebook_id) { |
|
|
|
|
if (empty($notebook_id)) { |
|
|
|
|
return array(); |
|
|
|
|
} |
|
|
|
|
// Database table definition |
|
|
|
|
$t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
@ -85,9 +88,11 @@ class NotebookManager |
|
|
|
|
description AS note_comment, |
|
|
|
|
session_id AS session_id |
|
|
|
|
FROM $t_notebook |
|
|
|
|
WHERE c_id = $course_id AND notebook_id = '".Database::escape_string($notebook_id)."' "; |
|
|
|
|
WHERE c_id = $course_id AND notebook_id = '" . Database::escape_string($notebook_id) . "' "; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if (Database::num_rows($result)!=1) { return array(); } |
|
|
|
|
if (Database::num_rows($result) != 1) { |
|
|
|
|
return array(); |
|
|
|
|
} |
|
|
|
|
return Database::fetch_array($result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -100,7 +105,7 @@ class NotebookManager |
|
|
|
|
* @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium |
|
|
|
|
* @version januari 2009, dokeos 1.8.6 |
|
|
|
|
*/ |
|
|
|
|
function update_note($values) { |
|
|
|
|
static function update_note($values) { |
|
|
|
|
if (!is_array($values) or empty($values['note_title'])) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -110,34 +115,36 @@ class NotebookManager |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE $t_notebook SET |
|
|
|
|
user_id = '".api_get_user_id()."', |
|
|
|
|
course = '".Database::escape_string(api_get_course_id())."', |
|
|
|
|
session_id = '".Database::escape_string($_SESSION['id_session'])."', |
|
|
|
|
title = '".Database::escape_string($values['note_title'])."', |
|
|
|
|
description = '".Database::escape_string($values['note_comment'])."', |
|
|
|
|
update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."' |
|
|
|
|
WHERE c_id = $course_id AND notebook_id = '".Database::escape_string($values['notebook_id'])."'"; |
|
|
|
|
user_id = '" . api_get_user_id() . "', |
|
|
|
|
course = '" . Database::escape_string(api_get_course_id()) . "', |
|
|
|
|
session_id = '" . Database::escape_string($_SESSION['id_session']) . "', |
|
|
|
|
title = '" . Database::escape_string($values['note_title']) . "', |
|
|
|
|
description = '" . Database::escape_string($values['note_comment']) . "', |
|
|
|
|
update_date = '" . Database::escape_string(date('Y-m-d H:i:s')) . "' |
|
|
|
|
WHERE c_id = $course_id AND notebook_id = '" . Database::escape_string($values['notebook_id']) . "'"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
//update item_property (update) |
|
|
|
|
api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $values['notebook_id'], 'NotebookUpdated', api_get_user_id()); |
|
|
|
|
$affected_rows = Database::affected_rows(); |
|
|
|
|
if (!empty($affected_rows)){ |
|
|
|
|
if (!empty($affected_rows)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function delete_note($notebook_id) { |
|
|
|
|
if (empty($notebook_id) or $notebook_id != strval(intval($notebook_id))) { return false; } |
|
|
|
|
static function delete_note($notebook_id) { |
|
|
|
|
if (empty($notebook_id) or $notebook_id != strval(intval($notebook_id))) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// Database table definition |
|
|
|
|
$t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); |
|
|
|
|
|
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM $t_notebook WHERE c_id = $course_id AND notebook_id='".intval($notebook_id)."' AND user_id = '".api_get_user_id()."'"; |
|
|
|
|
$sql = "DELETE FROM $t_notebook WHERE c_id = $course_id AND notebook_id='" . intval($notebook_id) . "' AND user_id = '" . api_get_user_id() . "'"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$affected_rows = Database::affected_rows(); |
|
|
|
|
if ($affected_rows != 1){ |
|
|
|
|
if ($affected_rows != 1) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
//update item_property (delete) |
|
|
|
@ -145,7 +152,7 @@ class NotebookManager |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function display_notes() { |
|
|
|
|
static function display_notes() { |
|
|
|
|
|
|
|
|
|
global $_user; |
|
|
|
|
if (!$_GET['direction']) { |
|
|
|
@ -159,28 +166,24 @@ class NotebookManager |
|
|
|
|
$link_sort_direction = 'ASC'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// action links |
|
|
|
|
echo '<div class="actions" style="margin-bottom:20px">'; |
|
|
|
|
//if (api_is_allowed_to_edit()) |
|
|
|
|
//{ |
|
|
|
|
echo '<div class="actions">'; |
|
|
|
|
if (!api_is_anonymous()) { |
|
|
|
|
if (api_get_session_id()==0) |
|
|
|
|
echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'.Display::return_icon('new_note.png',get_lang('NoteAddNew'),'','32').'</a>'; |
|
|
|
|
elseif(api_is_allowed_to_session_edit(false,true)){ |
|
|
|
|
echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'.Display::return_icon('new_note.png',get_lang('NoteAddNew'),'','32').'</a>'; |
|
|
|
|
if (api_get_session_id() == 0) |
|
|
|
|
echo '<a href="index.php?' . api_get_cidreq() . '&action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>'; |
|
|
|
|
elseif (api_is_allowed_to_session_edit(false, true)) { |
|
|
|
|
echo '<a href="index.php?' . api_get_cidreq() . '&action=addnote">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
echo '<a href="javascript:void(0)">'.Display::return_icon('new_note.png',get_lang('NoteAddNew'),'','32').'</a>'; |
|
|
|
|
echo '<a href="javascript:void(0)">' . Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>'; |
|
|
|
|
} |
|
|
|
|
//} |
|
|
|
|
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=creation_date&direction='.$link_sort_direction.'">'.Display::return_icon('notes_order_by_date_new.png',get_lang('OrderByCreationDate'),'','32').'</a>'; |
|
|
|
|
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=update_date&direction='.$link_sort_direction.'">'.Display::return_icon('notes_order_by_date_mod.png',get_lang('OrderByModificationDate'),'','32').'</a>'; |
|
|
|
|
echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=title&direction='.$link_sort_direction.'">'.Display::return_icon('notes_order_by_title.png',get_lang('OrderByTitle'),'','32').'</a>'; |
|
|
|
|
|
|
|
|
|
echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=creation_date&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32') . '</a>'; |
|
|
|
|
echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=update_date&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32') . '</a>'; |
|
|
|
|
echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=title&direction=' . $link_sort_direction . '">' . Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32') . '</a>'; |
|
|
|
|
echo '</div>'; |
|
|
|
|
|
|
|
|
|
if (!in_array($_SESSION['notebook_view'],array('creation_date','update_date', 'title'))) { |
|
|
|
|
if (!in_array($_SESSION['notebook_view'], array('creation_date', 'update_date', 'title'))) { |
|
|
|
|
$_SESSION['notebook_view'] = 'creation_date'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -188,19 +191,19 @@ class NotebookManager |
|
|
|
|
$t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); |
|
|
|
|
$order_by = ""; |
|
|
|
|
if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') { |
|
|
|
|
$order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction "; |
|
|
|
|
$order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction "; |
|
|
|
|
} else { |
|
|
|
|
$order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction "; |
|
|
|
|
$order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//condition for the session |
|
|
|
|
$session_id = api_get_session_id(); |
|
|
|
|
$condition_session = api_get_session_condition($session_id); |
|
|
|
|
|
|
|
|
|
$cond_extra = ($_SESSION['notebook_view']== 'update_date')?" AND update_date <> '0000-00-00 00:00:00'":" "; |
|
|
|
|
$cond_extra = ($_SESSION['notebook_view'] == 'update_date') ? " AND update_date <> '0000-00-00 00:00:00'" : " "; |
|
|
|
|
$course_id = api_get_course_int_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $t_notebook WHERE c_id = $course_id AND user_id = '".api_get_user_id()."' $condition_session $cond_extra $order_by"; |
|
|
|
|
$sql = "SELECT * FROM $t_notebook WHERE c_id = $course_id AND user_id = '" . api_get_user_id() . "' $condition_session $cond_extra $order_by"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
while ($row = Database::fetch_array($result)) { |
|
|
|
|
//validacion when belongs to a session |
|
|
|
@ -208,19 +211,18 @@ class NotebookManager |
|
|
|
|
$creation_date = api_get_local_time($row['creation_date'], null, date_default_timezone_get()); |
|
|
|
|
$update_date = api_get_local_time($row['update_date'], null, date_default_timezone_get()); |
|
|
|
|
echo '<div class="sectiontitle">'; |
|
|
|
|
echo '<span style="float: right;"> ('.get_lang('CreationDate').': '.date_to_str_ago($creation_date).' <span class="dropbox_date">'.$creation_date.'</span>'; |
|
|
|
|
echo '<span style="float: right;"> (' . get_lang('CreationDate') . ': ' . date_to_str_ago($creation_date) . ' <span class="dropbox_date">' . $creation_date . '</span>'; |
|
|
|
|
if ($row['update_date'] <> $row['creation_date']) { |
|
|
|
|
echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($update_date).' <span class="dropbox_date">'.$update_date.'</span>'; |
|
|
|
|
echo ', ' . get_lang('UpdateDate') . ': ' . date_to_str_ago($update_date) . ' <span class="dropbox_date">' . $update_date . '</span>'; |
|
|
|
|
} |
|
|
|
|
echo ')</span>'; |
|
|
|
|
echo $row['title'] . $session_img; |
|
|
|
|
echo '</div>'; |
|
|
|
|
echo '<div class="sectioncomment">'.$row['description'].'</div>'; |
|
|
|
|
echo '<div class="sectioncomment">' . $row['description'] . '</div>'; |
|
|
|
|
echo '<div>'; |
|
|
|
|
echo '<a href="'.api_get_self().'?action=editnote&notebook_id='.$row['notebook_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'; |
|
|
|
|
echo '<a href="'.api_get_self().'?action=deletenote&notebook_id='.$row['notebook_id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
|
|
|
|
echo '<a href="' . api_get_self() . '?action=editnote&notebook_id=' . $row['notebook_id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>'; |
|
|
|
|
echo '<a href="' . api_get_self() . '?action=deletenote&notebook_id=' . $row['notebook_id'] . '" onclick="return confirmation(\'' . $row['title'] . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>'; |
|
|
|
|
echo '</div>'; |
|
|
|
|
} |
|
|
|
|
//return $return; |
|
|
|
|
} |
|
|
|
|
} |