From fc6a02c0106cf9641564442b820e15e05bbd5c2c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 13 Jan 2012 15:21:22 +0100 Subject: [PATCH] Fixing course description, now when clicking in the icons we create new elements, when editing or deleting elements we use the id and not the description_type id see BT#3468 (requires testing and validation) --- .../course_description_controller.php | 89 ++++++++----------- main/course_description/edit.php | 32 ++----- main/course_description/index.php | 10 ++- main/course_description/layout.php | 3 +- main/course_description/listing.php | 38 ++------ main/inc/lib/course_description.lib.php | 75 ++++++++++------ 6 files changed, 101 insertions(+), 146 deletions(-) mode change 100755 => 100644 main/course_description/edit.php mode change 100755 => 100644 main/course_description/layout.php mode change 100755 => 100644 main/course_description/listing.php diff --git a/main/course_description/course_description_controller.php b/main/course_description/course_description_controller.php index 711a6808bb..1c20ca0a4d 100644 --- a/main/course_description/course_description_controller.php +++ b/main/course_description/course_description_controller.php @@ -14,7 +14,7 @@ */ class CourseDescriptionController { // extends Controller { - private $toolname; + private $toolname; private $view; /** @@ -31,19 +31,14 @@ class CourseDescriptionController { // extends Controller { * @param boolean true for listing history (optional) * @param array message for showing by action['edit','add','destroy'] (optional) */ - public function listing($history=false,$messages=array()) { + public function listing($history=false, $messages=array()) { $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_session_id($session_id); $data = array(); - if ($history) { - $course_description_data = $course_description->get_description_history(THEMATIC_ADVANCE); - $data['history'] = true; - } else { - $course_description_data = $course_description->get_description_data(); - } - + $course_description_data = $course_description->get_description_data(); + $data['descriptions'] = $course_description_data['descriptions']; $data['default_description_titles'] = $course_description->get_default_description_title(); $data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); @@ -62,7 +57,7 @@ class CourseDescriptionController { // extends Controller { * render to listing or edit view * @param int description type */ - public function edit($description_type) { + public function edit($id, $description_type) { $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_session_id($session_id); @@ -79,36 +74,20 @@ class CourseDescriptionController { // extends Controller { $content = $_POST['contentDescription']; } $description_type = $_POST['description_type']; - $progress = $_POST['progress']; + $id = $_POST['id']; + $progress = $_POST['progress']; + $course_description->set_description_type($description_type); $course_description->set_title($title); $course_description->set_content($content); - $course_description->set_progress($progress); - if ($description_type >= ADD_BLOCK) { - $thematic_advance = $course_description->get_data_by_description_type($description_type); - if (!empty($thematic_advance)) { - $affected_rows = $course_description->update(); - } else { - $affected_rows = $course_description->insert(); - } - } else { - $thematic_advance = $course_description->get_data_by_description_type($description_type); - if (!empty($thematic_advance)) { - if ($description_type == THEMATIC_ADVANCE) { - // if is thematic advance type save in history - $course_description->set_title($thematic_advance['description_title']); - $course_description->set_content($thematic_advance['description_content']); - $course_description->set_progress($thematic_advance['progress']); - $course_description->insert_stats($description_type); - } - $course_description->set_title($title); - $course_description->set_content($content); - $course_description->set_progress($progress); - $affected_rows = $course_description->update(); - } else { - $affected_rows = $course_description->insert(); - } - } + $course_description->set_progress($progress); + + $thematic_advance = $course_description->get_data_by_id($id); + if (!empty($thematic_advance)) { + $affected_rows = $course_description->update(); + } else { + $affected_rows = $course_description->insert(); + } Security::clear_token(); } @@ -128,7 +107,7 @@ class CourseDescriptionController { // extends Controller { $data['description_content'] = $_POST['contentDescription']; $data['description_type'] = $_POST['description_type']; $data['progress'] = $_POST['progress']; - $data['descriptions'] = $course_description->get_data_by_description_type($_POST['description_type']); + $data['descriptions'] = $course_description->get_data_by_id($_POST['id']); // render to the view $this->view->set_data($data); $this->view->set_layout('layout'); @@ -136,20 +115,24 @@ class CourseDescriptionController { // extends Controller { $this->view->render(); } } else { - - if (!empty($description_type)) { + + $data['default_description_titles'] = $course_description->get_default_description_title(); + $data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); + $data['default_description_icon'] = $course_description->get_default_description_icon(); + $data['question'] = $course_description->get_default_question(); + $data['information'] = $course_description->get_default_information(); + + $data['description_type'] = $description_type; + + if (!empty($id)) { if (isset($_GET['id_session'])) { $session_id = intval($_GET['id_session']); } - $course_description_data = $course_description->get_data_by_description_type($description_type, null, $session_id); - $data['default_description_titles'] = $course_description->get_default_description_title(); - $data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); - $data['default_description_icon'] = $course_description->get_default_description_icon(); - $data['question'] = $course_description->get_default_question(); - $data['information'] = $course_description->get_default_information(); + $course_description_data = $course_description->get_data_by_id($id, null, $session_id); + $data['description_title'] = $course_description_data['description_title']; $data['description_content'] = $course_description_data['description_content']; - $data['description_type'] = $description_type; + $data['progress'] = $course_description_data['progress']; $data['descriptions'] = $course_description->get_data_by_description_type($description_type, null, $session_id); } @@ -230,19 +213,17 @@ class CourseDescriptionController { // extends Controller { * render to listing view * @param int description type */ - public function destroy($description_type) { + public function destroy($id) { $course_description = new CourseDescription(); $session_id = api_get_session_id(); $course_description->set_session_id($session_id); - if (!empty($description_type)) { - $course_description->set_description_type($description_type); + if (!empty($id)) { + $course_description->set_id($id); $affected_rows = $course_description->delete(); } if ($affected_rows) { $message['destroy'] = true; } - $this->listing(false,$message); + $this->listing(false, $message); } - -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/main/course_description/edit.php b/main/course_description/edit.php old mode 100755 new mode 100644 index 0c888cd769..df8059976f --- a/main/course_description/edit.php +++ b/main/course_description/edit.php @@ -14,7 +14,7 @@ if (!$error) { $token = Security::get_token(); } // display categories -$categories = array (); +$categories = array(); foreach ($default_description_titles as $id => $title) { $categories[$id] = $title; } @@ -49,19 +49,10 @@ if ($description_type >= ADD_BLOCK) { } // display form -$form = new FormValidator('course_description','POST','index.php?action=edit&description_type='.$description_type.'&'.api_get_cidreq(),'','style="width: 100%;"'); - -/* -if ($description_type == THEMATIC_ADVANCE) { - $form->addElement('html','
- -
'); -} else { - $form->addElement('header','',$header); -}*/ +$form = new FormValidator('course_description','POST','index.php?action=edit&id='.$id.'&description_type='.$description_type.'&'.api_get_cidreq(),'','style="width: 100%;"'); $form->addElement('header','',$header); - +$form->addElement('hidden', 'id', $id); $form->addElement('hidden', 'description_type',$description_type); $form->addElement('hidden', 'sec_token',$token); $form->add_textfield('title', get_lang('Title'), true, array('size'=>'50')); @@ -72,17 +63,8 @@ if (api_get_setting('wcag_anysurfer_public_pages')=='true') { } else { $form->add_html_editor('contentDescription', get_lang('Content'), true, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200')); } - -/* -if ($description_type == THEMATIC_ADVANCE) { - $options_select = array(0,10=>10,20=>20,30=>30,40=>40,50=>50,60=>60,70=>70,80=>80,90=>90,100=>100); - $form->addElement ('select', 'progress',get_lang('Progress'),$options_select); - $default['progress'] = intval($progress); -} -*/ - - $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); + // Set some default values $default['title'] = Security::remove_XSS($description_title); $default['contentDescription'] = Security::remove_XSS($description_content,COURSEMANAGERLOWSECURITY); @@ -90,14 +72,12 @@ $default['description_type'] = $description_type; $form->setDefaults($default); -//*********************************** if (isset ($question[$description_type])) { $message = ''.get_lang('QuestionPlan').'
'; $message .= $question[$description_type]; Display::display_normal_message($message, false); } - if (api_get_setting('wcag_anysurfer_public_pages')=='true') { echo (WCAG_Rendering::editor_header()); } @@ -105,6 +85,4 @@ if (api_get_setting('wcag_anysurfer_public_pages')=='true') { $form->display(); if (api_get_setting('wcag_anysurfer_public_pages')=='true') { echo (WCAG_Rendering::editor_footer()); -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/main/course_description/index.php b/main/course_description/index.php index 29a5755218..e6a1d1a4ea 100644 --- a/main/course_description/index.php +++ b/main/course_description/index.php @@ -20,7 +20,6 @@ require_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php'; // defining constants define('ADD_BLOCK', 8); -//define('THEMATIC_ADVANCE', 8); // current section $this_section = SECTION_COURSES; @@ -40,6 +39,11 @@ if (isset($_GET['description_type'])) { $description_type = intval($_GET['description_type']); } +$id = null; +if (isset($_GET['id'])) { + $id = intval($_GET['id']); +} + if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') { $action = 'listing'; } @@ -74,12 +78,12 @@ switch ($action) { break; case 'edit' : if (api_is_allowed_to_edit(null,true)) { - $course_description_controller->edit($description_type); + $course_description_controller->edit($id, $description_type); } break; case 'delete' : if (api_is_allowed_to_edit(null,true)) { - $course_description_controller->destroy($description_type); + $course_description_controller->destroy($id); } break; default : diff --git a/main/course_description/layout.php b/main/course_description/layout.php old mode 100755 new mode 100644 index 8944c1241c..66bbadba8c --- a/main/course_description/layout.php +++ b/main/course_description/layout.php @@ -23,5 +23,4 @@ event_access_tool(TOOL_COURSE_DESCRIPTION); echo $content; // Footer -Display :: display_footer(); -?> \ No newline at end of file +Display :: display_footer(); \ No newline at end of file diff --git a/main/course_description/listing.php b/main/course_description/listing.php old mode 100755 new mode 100644 index d25f6d6e31..d39690ee1a --- a/main/course_description/listing.php +++ b/main/course_description/listing.php @@ -49,46 +49,19 @@ if (isset($descriptions) && count($descriptions) > 0) { echo '
'; if (api_is_allowed_to_edit(null,true) && !$history) { - if (api_get_session_id() == $description['session_id']) { //delete - echo ''; + echo ''; echo Display::return_icon('delete.png', get_lang('Delete'), array('style' => 'vertical-align:middle;float:right;'),22); echo ' '; - } - + } //edit - echo ''; + echo ''; echo Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align:middle;float:right; padding-right:4px;'),22); - echo ' '; - - /* - if ($description['description_type'] == THEMATIC_ADVANCE) { - // thematic advance history link - echo ''; - echo Display::return_icon('lp_dir.png',get_lang('ThematicAdvanceHistory'),array('style'=>'vertical-align:middle;float:right;padding-right:4px;')); - echo ' '; - } - */ + echo ' '; } - /* - $progress = (isset($description['progress'])?$description['progress'].'%':''); - if ($description['description_type'] == THEMATIC_ADVANCE) { - echo ''; - echo get_lang('ThematicAdvance').' : '.$description['title'].' - '.$progress; - } else { - echo $description['title']; - } */ - echo $description['title']; - - /* - if ($history) { - echo ' - '.$progress.' ('.$description['lastedit_date'].') '; - } - */ - echo '
'; echo '
'; echo text_filter($description['content']); @@ -96,5 +69,4 @@ if (isset($descriptions) && count($descriptions) > 0) { } } else { echo ''.get_lang('ThisCourseDescriptionIsEmpty').''; -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/main/inc/lib/course_description.lib.php b/main/inc/lib/course_description.lib.php index 2ff661866f..e7f6eda403 100644 --- a/main/inc/lib/course_description.lib.php +++ b/main/inc/lib/course_description.lib.php @@ -72,13 +72,10 @@ class CourseDescription $sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id $condition_session ORDER BY id "; $rs = Database::query($sql); $data = array(); - while ($description = Database::fetch_array($rs)) { - if ($description['description_type'] == THEMATIC_ADVANCE) { - $description['progress_icon'] = $this->get_progress_porcent(); - } - $data['descriptions'][$description['description_type']] = Security::remove_XSS($description, STUDENT); + while ($description = Database::fetch_array($rs)) { + $data['descriptions'][$description['id']] = Security::remove_XSS($description, STUDENT); //reload titles to ensure we have the last version (after edition) - $data['default_description_titles'][$description['description_type']] = Security::remove_XSS($description['title'], STUDENT); + //$data['default_description_titles'][$description['id']] = Security::remove_XSS($description['title'], STUDENT); } return $data; } @@ -128,10 +125,10 @@ class CourseDescription } $condition_session = api_get_session_condition($session_id); if (!empty($course_code)) { - $course_info = api_get_course_info($course_code); - $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION, $course_info['dbName']); + $course_info = api_get_course_info($course_code); + $course_id = $course_info['real_id']; } - + $description_type = intval($description_type); $sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id AND description_type='$description_type' $condition_session "; $rs = Database::query($sql); $data = array(); @@ -142,6 +139,32 @@ class CourseDescription } return $data; } + + + public function get_data_by_id($id, $course_code = '', $session_id = null) { + $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION); + $course_id = api_get_course_int_id(); + + if (!isset($session_id)) { + $session_id = $this->session_id; + } + $condition_session = api_get_session_condition($session_id); + if (!empty($course_code)) { + $course_info = api_get_course_info($course_code); + $course_id = $course_info['real_id']; + } + $id = intval($id); + $sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id AND id='$id' $condition_session "; + $rs = Database::query($sql); + $data = array(); + if ($description = Database::fetch_array($rs)) { + $data['description_title'] = $description['title']; + $data['description_content'] = $description['content']; + $data['progress'] = $description['progress']; + } + return $data; + } + /** * Get maximum description type by session id, first you must set session_id properties with the object CourseDescription @@ -219,22 +242,22 @@ class CourseDescription * and session_id properties with the object CourseDescription * @return int affected rows */ - public function update($course_db = null) { - $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION); + public function update() { + $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION); $sql = "UPDATE $tbl_course_description SET - title = '".Database::escape_string($this->title)."', - content = '".Database::escape_string($this->content)."', - progress = '".$this->progress."' - WHERE description_type='".intval($this->description_type)."' AND - session_id = '".$this->session_id."' AND + title = '".Database::escape_string($this->title)."', + content = '".Database::escape_string($this->content)."', + progress = '".$this->progress."' + WHERE id = '".intval($this->id)."' AND + session_id = '".$this->session_id."' AND c_id = ".api_get_course_int_id()." "; Database::query($sql); $affected_rows = Database::affected_rows(); - $description_id = $this->get_id_by_description_type($this->description_type); - if ($description_id > 0) { + + if ($this->id > 0) { //insert into item_property - api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $description_id, 'CourseDescriptionUpdated', api_get_user_id()); + api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $this->id, 'CourseDescriptionUpdated', api_get_user_id()); } return $affected_rows; } @@ -243,17 +266,15 @@ class CourseDescription * Delete a description, first you must set description_type and session_id properties with the object CourseDescription * @return int affected rows */ - public function delete($course_db = null) { + public function delete() { $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION); - $description_id = $this->get_id_by_description_type($this->description_type); - - $course_id = api_get_course_int_id(); - $sql = "DELETE FROM $tbl_course_description WHERE c_id = $course_id AND description_type = '".intval($this->description_type)."' AND session_id = '".intval($this->session_id)."'"; + $course_id = api_get_course_int_id(); + $sql = "DELETE FROM $tbl_course_description WHERE c_id = $course_id AND id = '".intval($this->id)."' AND session_id = '".intval($this->session_id)."'"; Database::query($sql); $affected_rows = Database::affected_rows(); - if ($description_id > 0) { + if ($this->id > 0) { //insert into item_property - api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $description_id, 'CourseDescriptionDeleted', api_get_user_id()); + api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $this->id, 'CourseDescriptionDeleted', api_get_user_id()); } return $affected_rows; } @@ -317,7 +338,7 @@ class CourseDescription $default_description_titles[5]= get_lang('CourseMaterial'); $default_description_titles[6]= get_lang('HumanAndTechnicalResources'); $default_description_titles[7]= get_lang('Assessment'); - //$default_description_titles[8]= get_lang('ThematicAdvance'); + $default_description_titles[8]= get_lang('Other'); return $default_description_titles; }