, 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 * * @return unknown * * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ function javascript_notebook() { return ""; } /** * This functions stores the note in the database * * @param array $values * @return bool * @author Christian Fasanando * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 * */ function save_note($values) { // Database table definition $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); $sql = "INSERT INTO $t_notebook (user_id, course, session_id, title, description, creation_date,update_date,status) VALUES( '".Database::escape_string(api_get_user_id())."', '".Database::escape_string(api_get_course_id())."', '".Database::escape_string($_SESSION['id_session'])."', '".Database::escape_string(Security::remove_XSS($values['note_title']))."', '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."', '".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(); if ($id > 0) { //insert into item_property 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)){ return true; } } function get_note_information($notebook_id) { // Database table definition $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); $sql = "SELECT notebook_id AS notebook_id, title AS note_title, description AS note_comment, session_id AS session_id FROM $t_notebook WHERE notebook_id = '".Database::escape_string($notebook_id)."' "; $result = Database::query($sql); return Database::fetch_array($result); } /** * This functions updates the note in the database * * @param array $values * * @author Christian Fasanando * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ function update_note($values) { // Database table definition $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); $sql = "UPDATE $t_notebook SET user_id = '".Database::escape_string(api_get_user_id())."', course = '".Database::escape_string(api_get_course_id())."', session_id = '".Database::escape_string($_SESSION['id_session'])."', title = '".Database::escape_string(Security::remove_XSS($values['note_title']))."', description = '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['note_comment'])),COURSEMANAGERLOWSECURITY))."', update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."' WHERE 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, Database::escape_string($values['notebook_id']), 'NotebookUpdated', api_get_user_id()); $affected_rows = Database::affected_rows(); if (!empty($affected_rows)){ return true; } } function delete_note($notebook_id) { // Database table definition $t_notebook = Database :: get_course_table(TABLE_NOTEBOOK); $sql = "DELETE FROM $t_notebook WHERE notebook_id='".Database::escape_string($notebook_id)."' AND user_id = '".Database::escape_string(api_get_user_id())."'"; $result = Database::query($sql); //update item_property (delete) api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($notebook_id), 'delete', api_get_user_id()); $affected_rows = Database::affected_rows(); if (!empty($affected_rows)){ return true; } } function display_notes() { global $_user; if (!$_GET['direction']) { $sort_direction = 'ASC'; $link_sort_direction = 'DESC'; } elseif ($_GET['direction'] == 'ASC') { $sort_direction = 'ASC'; $link_sort_direction = 'DESC'; } else { $sort_direction = 'DESC'; $link_sort_direction = 'ASC'; } // action links echo ''; if (!in_array($_SESSION['notebook_view'],array('creation_date','update_date', 'title'))) { $_SESSION['notebook_view'] = 'creation_date'; } // Database table definition $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 "; } else { $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'":" "; $sql = "SELECT * FROM $t_notebook WHERE user_id = '".Database::escape_string(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 $session_img = api_get_session_image($row['session_id'], $_user['status']); $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 '
'; echo ' ('.get_lang('CreationDate').': '.date_to_str_ago($creation_date).'  '.$creation_date.''; if ($row['update_date'] <> $row['creation_date']) { echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($update_date).'  '.$update_date.''; } echo ')'; echo $row['title'] . $session_img; echo '
'; echo '
'.$row['description'].'
'; echo ''; } //return $return; } } ?>