123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php //$id: $
- /* For licensing terms, see /dokeos_license.txt */
- /**
- * @package dokeos.glossary
- * @author Christian Fasanando, initial version
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium, refactoring and tighter integration in Dokeos
- */
- // name of the language file that needs to be included
- $language_file = array('notebook');
- // including the global dokeos file
- require_once('../inc/global.inc.php');
- require_once('../inc/lib/events.lib.inc.php');
- // the section (tabs)
- $this_section=SECTION_COURSES;
- // notice for unauthorized people.
- api_protect_course_script(true);
- // including additional libraries
- require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
- // additional javascript
- $htmlHeadXtra[] = javascript_notebook();
- // setting the tool constants
- $tool = TOOL_NOTEBOOK;
- // tracking
- event_access_tool(TOOL_NOTEBOOK);
- if ( isset($_GET['action']) && ($_GET['action'] == 'addnote' || $_GET['action'] == 'editnote')) {
- $tool=get_lang('NotebookManagement');
- $interbreadcrumb[] = array ("url"=>"index.php", "name"=> ucfirst(get_lang(TOOL_NOTEBOOK)));
- }
- // displaying the header
- Display::display_header(get_lang(ucfirst($tool)));
- // Tool introduction
- $fck_attribute['Width'] = '100%';
- $fck_attribute['Height'] = '300';
- $fck_attribute['ToolbarSet'] = 'Introduction';
- Display::display_introduction_section(TOOL_NOTEBOOK,'left');
- $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
- // Config notebook FckEditor buttons bar
- $fck_attribute['Width'] = '100%';
- $fck_attribute['Height'] = '300';
- if(!api_is_allowed_to_edit())
- {
- $fck_attribute['Config']['UserStatus'] = 'student';
- $fck_attribute['ToolbarSet'] = 'Notebook_Student';
- }
- else
- {
- $fck_attribute['ToolbarSet'] = 'Notebook';
- }
- // Action handling: Adding a note
- if (isset($_GET['action']) && $_GET['action'] == 'addnote')
- {
-
- if (!empty($_GET['isStudentView'])) {
- display_notes();
- exit;
- }
-
- $_SESSION['notebook_view'] = 'creation_date';
-
- // initiate the object
- $form = new FormValidator('note','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
- // settting the form elements
- $form->addElement('header', '', get_lang('NoteAddNew'));
- $form->addElement('text', 'note_title', get_lang('NoteTitle'),array('size'=>'95'));
- $form->applyFilter('note_title', 'html_filter');
-
- $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'));
- $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddNote'), 'class="add"');
-
- // setting the rules
- $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
-
- // The validation or display
- if ( $form->validate() )
- {
- $check = Security::check_token('post');
- if ($check)
- {
- $values = $form->exportValues();
- save_note($values);
-
- }
- Security::clear_token();
- display_notes();
- }
- else
- {
- $token = Security::get_token();
- $form->addElement('hidden','sec_token');
- $form->setConstants(array('sec_token' => $token));
- $form->display();
- }
- }
- // Action handling: Editing a note
- else if (isset($_GET['action']) && $_GET['action'] == 'editnote' && is_numeric($_GET['notebook_id']))
- {
-
- if (!empty($_GET['isStudentView'])) {
- display_notes();
- exit;
- }
-
- // initiate the object
- $form = new FormValidator('note','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'¬ebook_id='.Security::remove_XSS($_GET['notebook_id']));
- // settting the form elements
- $form->addElement('header', '', get_lang('ModifyNote'));
- $form->addElement('hidden', 'notebook_id');
- $form->addElement('text', 'note_title', get_lang('NoteTitle'),array('size'=>'100'));
- $form->applyFilter('note_title', 'html_filter');
- $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'));
- $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyNote'), 'class="save"');
-
- // setting the defaults
- $defaults = get_note_information(Security::remove_XSS($_GET['notebook_id']));
- $form->setDefaults($defaults);
-
- // setting the rules
- $form->addRule('note_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
-
- // The validation or display
- if ( $form->validate() )
- {
- $check = Security::check_token('post');
- if ($check)
- {
- $values = $form->exportValues();
- update_note($values);
- }
- Security::clear_token();
- display_notes();
- }
- else
- {
- $token = Security::get_token();
- $form->addElement('hidden','sec_token');
- $form->setConstants(array('sec_token' => $token));
- $form->display();
- }
- }
- // Action handling: deleting a note
- else if (isset($_GET['action']) && $_GET['action'] == 'deletenote' && is_numeric($_GET['notebook_id']))
- {
- delete_note(Security::remove_XSS($_GET['notebook_id']));
- display_notes();
- }
- // Action handling: changing the view (sorting order)
- else if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('creation_date','update_date', 'title')))
- {
- $_SESSION['notebook_view'] = $_GET['view'];
- display_notes();
- } else {
- display_notes();
- }
- // footer
- Display::display_footer();
- /**
- * a little bit of javascript to display a prettier warning when deleting a note
- *
- * @return unknown
- *
- * @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\">
- function confirmation (name)
- {
- if (confirm(\" ". get_lang("NoteConfirmDelete") ." \"+ name + \" ?\"))
- {return true;}
- else
- {return false;}
- }
- </script>";
- }
- /**
- * This functions stores the note in the database
- *
- * @param array $values
- *
- * @author Christian Fasanando <christian.fasanando@dokeos.com>
- * @author Patrick Cool <patrick.cool@ugent.be>, 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($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 = api_sql_query($sql, __FILE__, __LINE__);
- // display the feedback message
- Display::display_confirmation_message(get_lang('NoteAdded'));
- }
- 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
- FROM $t_notebook
- WHERE notebook_id = '".Database::escape_string($notebook_id)."' ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return Database::fetch_array($result);
- }
- /**
- * This functions updates the note in the database
- *
- * @param array $values
- *
- * @author Christian Fasanando <christian.fasanando@dokeos.com>
- * @author Patrick Cool <patrick.cool@ugent.be>, 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($values['note_title'])."',
- description = '".Database::escape_string($values['note_comment'])."',
- update_date = '".Database::escape_string(date('Y-m-d H:i:s'))."'
- WHERE notebook_id = '".Database::escape_string($values['notebook_id'])."'";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- // display the feedback message
- Display::display_confirmation_message(get_lang('NoteUpdated'));
- }
- 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 = api_sql_query($sql, __FILE__, __LINE__);
- Display::display_confirmation_message(get_lang('NoteDeleted'));
- }
- function display_notes()
- {
- // action links
- echo '<div class="actions" style="margin-bottom:20px">';
- //if (api_is_allowed_to_edit())
- //{
- echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
- //}
- echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=creation_date">'.Display::return_icon('calendar_select.gif',get_lang('OrderByCreationDate')).get_lang('OrderByCreationDate').'</a>';
- echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=update_date">'.Display::return_icon('calendar_select.gif',get_lang('OrderByModificationDate')).get_lang('OrderByModificationDate').'</a>';
- echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=title">'.Display::return_icon('comment.gif',get_lang('OrderByTitle')).get_lang('OrderByTitle').'</a>';
- echo '</div>';
-
- 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']." DESC ";
- } else {
- $order_by = " ORDER BY ".$_SESSION['notebook_view']." ASC ";
- }
-
- $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())."' $cond_extra $order_by";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- while ($row = Database::fetch_array($result))
- {
- echo '<div class="sectiontitle">';
- echo '<span style="float: right;"> ('.get_lang('CreationDate').': '.date_to_str_ago($row['creation_date']).' <span class="dropbox_date">'.$row['creation_date'].'</span>';
- if ($row['update_date'] <> $row['creation_date'])
- {
- echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($row['update_date']).' <span class="dropbox_date">'.$row['update_date'].'</span>';
- }
- echo ')</span>';
- echo $row['title'];
- echo '</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.gif', get_lang('Edit')).'</a>';
- echo '<a href="'.api_get_self().'?action=deletenote&notebook_id='.$row['notebook_id'].'" onclick="return confirmation(\''.$row['title'].'\');">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
- echo '</div>';
- }
- return $return;
- }
- ?>
|