Esempio n. 1
0
// Adavanced Parameters
if (Gradebook::is_active()) {
    if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:block">');
        $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), array('checked' => 'true', 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}'));
        $form->addElement('html', '<div id="options_field" style="display:block">');
    } else {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
        $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
        $form->addElement('html', '<div id="options_field" style="display:none">');
    }
    load_gradebook_select_in_tool($form);
    $form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook'));
    $form->applyFilter('attendance_qualify_title', 'html_filter');
    $form->addElement('text', 'attendance_weight', get_lang('QualifyWeight'), 'value="0.00" Style="width:40px" onfocus="javascript: this.select();"');
    $form->applyFilter('attendance_weight', 'html_filter');
    $form->addElement('html', '</div>');
    $form->addElement('html', '</div>');
}
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
// set default values
$default['title'] = Security::remove_XSS($title);
$default['description'] = Security::remove_XSS($description, STUDENT);
$default['attendance_qualify_title'] = $attendance_qualify_title;
$default['attendance_weight'] = $attendance_weight;
$link_info = is_resource_in_course_gradebook(api_get_course_id(), 7, $attendance_id, api_get_session_id());
$default['category_id'] = $link_info['category_id'];
$form->setDefaults($default);
$form->display();
Esempio n. 2
0
echo '<a href="viewforum.php?&amp;origin=' . $origin . '&amp;forum=' . $current_forum['forum_id'] . '" ' . class_visible_invisible($current_forum['visibility']) . '>' . prepare4display($current_forum['forum_title']) . '</a><br />';
echo '<span class="forum_description">' . prepare4display($current_forum['forum_comment']) . '</span>';
echo "</th>";
echo "</tr>";
echo '</table>';
// The form for the reply
$values = show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
if (!empty($values) and isset($_POST['SubmitPost'])) {
    store_edit_post($values);
    $option_chek = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
    // values 1 or 0
    if (1 == $option_chek) {
        $id = $values['thread_id'];
        $title_gradebook = Security::remove_XSS(stripslashes($values['calification_notebook_title']));
        $value_calification = $values['numeric_calification'];
        $weight_calification = $values['weight_calification'];
        $description = '';
        $session_id = api_get_session_id();
        $link_info = is_resource_in_course_gradebook(api_get_course_id(), 5, $id, $session_id);
        $link_id = $link_info['id'];
        if (!$link_info) {
            add_resource_to_course_gradebook($values['category_id'], api_get_course_id(), 5, $id, $title_gradebook, $weight_calification, $value_calification, $description, 1, api_get_session_id());
        } else {
            Database::query('UPDATE ' . $table_link . ' SET weight=' . $weight_calification . ' WHERE id=' . $link_id . '');
        }
    }
}
// Footer
if ($origin != 'learnpath') {
    Display::display_footer();
}
Esempio n. 3
0
    // Note: This has to be cleaned first.
}
// Locking and unlocking.
if (($my_action == 'lock' or $my_action == 'unlock') and isset($_GET['content']) and isset($_GET['id']) and api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
    // Note: This has to be cleaned first.
}
// Deleting.
if ($my_action == 'delete' and isset($_GET['content']) and isset($_GET['id']) and api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
    if ($locked == false) {
        $message = delete_forum_forumcategory_thread($_GET['content'], $_GET['id']);
        // Note: This has to be cleaned first.
        // Delete link
        require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
        $link_info = is_resource_in_course_gradebook(api_get_course_id(), 5, intval($_GET['id']), api_get_session_id());
        $link_id = $link_info['id'];
        if ($link_info !== false) {
            remove_resource_from_course_gradebook($link_id);
        }
    }
}
// Moving.
if ($my_action == 'move' and isset($_GET['thread']) and api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = move_thread_form();
}
// Notification.
if ($my_action == 'notify' and isset($_GET['content']) and isset($_GET['id']) && api_is_allowed_to_session_edit(false, true)) {
    $return_message = set_notification($_GET['content'], $_GET['id']);
    Display::display_confirmation_message($return_message, false);
}
Esempio n. 4
0
 /**
  * edit attendaces inside table
  * @param 	int	   attendance id
  * @param  	bool   true for adding link in gradebook or false otherwise (optional)
  * @return 	int    last id
  */
 public function attendance_edit($attendance_id, $link_to_gradebook = false)
 {
     $_course = api_get_course_info();
     $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
     $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
     $session_id = api_get_session_id();
     $user_id = api_get_user_id();
     $attendance_id = intval($attendance_id);
     $course_code = $this->get_course_id();
     $course_id = $this->get_course_int_id();
     $title_gradebook = Database::escape_string($this->attendance_qualify_title);
     $value_calification = 0;
     $weight_calification = floatval($this->attendance_weight);
     if (!empty($attendance_id)) {
         $sql = "UPDATE {$tbl_attendance}\n                    SET name ='" . Database::escape_string($this->name) . "',\n                        description = '" . Database::escape_string($this->description) . "',\n                        attendance_qualify_title = '" . $title_gradebook . "',\n                        attendance_weight = '" . $weight_calification . "'\n                    WHERE c_id = {$course_id} AND id = '{$attendance_id}'";
         Database::query($sql);
         api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id, "AttendanceUpdated", $user_id);
         // add link to gradebook
         if ($link_to_gradebook && !empty($this->category_id)) {
             $description = '';
             $link_id = is_resource_in_course_gradebook($course_code, 7, $attendance_id, $session_id);
             if (!$link_id) {
                 add_resource_to_course_gradebook($this->category_id, $course_code, 7, $attendance_id, $title_gradebook, $weight_calification, $value_calification, $description, 1, $session_id);
             } else {
                 Database::query('UPDATE ' . $table_link . ' SET weight=' . $weight_calification . ' WHERE id=' . $link_id . '');
             }
         }
         return $attendance_id;
     }
     return null;
 }
Esempio n. 5
0
 /**
  * Static admin function allowing removal of a learnpath
  * @param    string    Course code
  * @param    integer    Learnpath ID
  * @param    string    Whether to delete data or keep it (default: 'keep', others: 'remove')
  * @return    boolean    True on success, false on failure (might change that to return number of elements deleted)
  */
 public function delete($course = null, $id = null, $delete = 'keep')
 {
     $course_id = api_get_course_int_id();
     // TODO: Implement a way of getting this to work when the current object is not set.
     // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
     //if (empty($course)) { $course = api_get_course_id(); }
     //if (empty($id)) { $id = $this->get_id(); }
     // If an ID is specifically given and the current LP is not the same, prevent delete.
     if (!empty($id) && $id != $this->lp_id) {
         return false;
     }
     $lp = Database::get_course_table(TABLE_LP_MAIN);
     $lp_item = Database::get_course_table(TABLE_LP_ITEM);
     // Proposed by Christophe (clefevre), see below.
     $lp_view = Database::get_course_table(TABLE_LP_VIEW);
     $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
     //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
     // Delete lp item id.
     foreach ($this->items as $id => $dummy) {
         //$this->items[$id]->delete();
         $sql_del_view = "DELETE FROM {$lp_item_view} WHERE c_id = {$course_id} AND lp_item_id = '" . $id . "'";
         $res_del_item_view = Database::query($sql_del_view);
     }
     // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
     $sql_del_item = "DELETE FROM {$lp_item} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     $res_del_item = Database::query($sql_del_item);
     $sql_del_view = "DELETE FROM {$lp_view} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
     $res_del_view = Database::query($sql_del_view);
     self::toggle_publish($this->lp_id, 'i');
     //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
     if ($this->type == 2 || $this->type == 3) {
         // This is a scorm learning path, delete the files as well.
         $sql = "SELECT path FROM {$lp} WHERE c_id = " . $course_id . " AND id = " . $this->lp_id;
         $res = Database::query($sql);
         if (Database::num_rows($res) > 0) {
             $row = Database::fetch_array($res);
             $path = $row['path'];
             $sql = "SELECT id FROM {$lp} WHERE c_id = " . $course_id . " AND path = '{$path}' AND id != " . $this->lp_id;
             $res = Database::query($sql);
             if (Database::num_rows($res) > 0) {
                 // Another learning path uses this directory, so don't delete it.
                 if ($this->debug > 2) {
                     error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
                 }
             } else {
                 // No other LP uses that directory, delete it.
                 $course_rel_dir = api_get_course_path() . '/scorm/';
                 // scorm dir web path starting from /courses
                 $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
                 // The absolute system path for this course.
                 if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty($course_scorm_dir)) {
                     if ($this->debug > 2) {
                         error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
                     }
                     // Proposed by Christophe (clefevre).
                     if (strcmp(substr($path, -2), "/.") == 0) {
                         $path = substr($path, 0, -1);
                         // Remove "." at the end.
                     }
                     //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
                     api_rmdirr($course_scorm_dir . $path);
                 }
             }
         }
     }
     $sql_del_lp = "DELETE FROM {$lp} WHERE c_id = " . $course_id . " AND id = " . $this->lp_id;
     //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
     $res_del_lp = Database::query($sql_del_lp);
     $this->update_display_order();
     // Updates the display order of all lps.
     api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
     require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be.inc.php';
     // Delete link of gradebook tool
     //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
     /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
       $result = Database::query($sql);
       $row = Database :: fetch_array($result, 'ASSOC');*/
     // Fixing gradebook link deleted see #5229.
     /*
             if (!empty($row['id'])) {
                    $link = LinkFactory :: load($row['id']);
                 if ($link[0] != null) {
                        $link[0]->delete();
                 }
             }*/
     require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
     $link_info = is_resource_in_course_gradebook(api_get_course_id(), 4, $id, api_get_session_id());
     if ($link_info !== false) {
         remove_resource_from_course_gradebook($link_info['id']);
     }
     if (api_get_setting('search_enabled') == 'true') {
         require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
         $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
     }
 }
Esempio n. 6
0
// Only for administrator
if ($is_allowedToEdit) {
    if (!empty($choice)) {
        // Construction of Exercise
        $objExerciseTmp = new Exercise();
        $check = Security::check_token('get');
        $exercise_action_locked = api_resource_is_locked_by_gradebook($exerciseId, LINK_EXERCISE);
        if ($objExerciseTmp->read($exerciseId)) {
            if ($check) {
                switch ($choice) {
                    case 'delete':
                        // deletes an exercise
                        if ($exercise_action_locked == false) {
                            $objExerciseTmp->delete();
                            require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
                            $link_info = is_resource_in_course_gradebook(api_get_course_id(), 1, $exerciseId, api_get_session_id());
                            if ($link_info !== false) {
                                remove_resource_from_course_gradebook($link_info['id']);
                            }
                            Display::display_confirmation_message(get_lang('ExerciseDeleted'));
                        }
                        break;
                    case 'enable':
                        // enables an exercise
                        $objExerciseTmp->enable();
                        $objExerciseTmp->save();
                        api_item_property_update($course_info, TOOL_QUIZ, $objExerciseTmp->id, 'visible', api_get_user_id());
                        // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
                        Display::display_confirmation_message(get_lang('VisibilityChanged'));
                        break;
                    case 'disable':
Esempio n. 7
0
     if ($locked == false) {
         $work_to_delete = get_work_data_by_id($delete_dir_id);
         del_dir($delete_dir_id);
         // gets calendar_id from student_publication_assigment
         $sql = "SELECT add_to_calendar FROM {$TSTDPUBASG} WHERE c_id = {$course_id} AND publication_id ='{$delete_dir_id}'";
         $res = Database::query($sql);
         $calendar_id = Database::fetch_row($res);
         // delete from agenda if it exists
         if (!empty($calendar_id[0])) {
             $t_agenda = Database::get_course_table(TABLE_AGENDA);
             $sql = "DELETE FROM {$t_agenda} WHERE c_id = {$course_id} AND id ='" . $calendar_id[0] . "'";
             Database::query($sql);
         }
         $sql = "DELETE FROM {$TSTDPUBASG} WHERE c_id = {$course_id} AND publication_id ='{$delete_dir_id}'";
         Database::query($sql);
         $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3, $delete_dir_id, api_get_session_id());
         $link_id = $link_info['id'];
         if ($link_info !== false) {
             remove_resource_from_course_gradebook($link_id);
         }
         Display::display_confirmation_message(get_lang('DirDeleted') . ': ' . $work_to_delete['title']);
     } else {
         Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
     }
 }
 /*	DELETE WORK COMMAND */
 if ($action == 'delete' && $item_id) {
     $file_deleted = false;
     $is_author = user_is_author($item_id);
     $work_data = get_work_data_by_id($item_id);
     $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION);
            $gradebook_option = $values['survey_qualify_gradebook'] > 0;
        }

        if ($gradebook_option) {
            $survey_id = intval($return['id']);
            if ($survey_id > 0) {
                $title_gradebook = ''; // Not needed here.
                $description_gradebook = ''; // Not needed here.
                $survey_weight = floatval($_POST['survey_weight']);
                $max_score = 1;
                $date = time(); // TODO: Maybe time zones implementation is needed here.
                $visible = 1; // 1 = visible

                $link_info = is_resource_in_course_gradebook(
                    $course_id,
                    $gradebook_link_type,
                    $survey_id,
                    $session_id
                );
                $gradebook_link_id = $link_info['id'];
                if (!$gradebook_link_id) {
                    add_resource_to_course_gradebook(
                        $course_id,
                        $gradebook_link_type,
                        $survey_id,
                        $title_gradebook,
                        $survey_weight,
                        $max_score,
                        $description_gradebook,
                        1,
                        $session_id
                    );
Esempio n. 9
0
/**
 * @param int $workId
 * @param array $params
 * @param array $courseInfo
 * @param int $groupId
 */
function updatePublicationAssignment($workId, $params, $courseInfo, $groupId)
{
    $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
    $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $workId = intval($workId);
    $time = time();
    $course_id = $courseInfo['real_id'];

    // Insert into agenda
    $agendaId = 0;

    if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) {
        require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
        require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';

        // Setting today date
        $date = $end_date = $time;

        if (!empty($params['enableExpiryDate'])) {
            $end_date = $params['expires_on'];
            $date = $end_date;
        }

        $title = sprintf(get_lang('HandingOverOfTaskX'), $params['new_dir']);
        $description = isset($params['description']) ? $params['description'] : '';
        $content = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId.'">'
            .$params['new_dir'].'</a>'.$description;

        $agendaId = agendaExistsForWork($workId, $courseInfo);

        // Add/edit agenda
        $agenda = new Agenda();
        $agenda->set_course($courseInfo);
        $agenda->type = 'course';

        if (empty($agendaId)) {
            $agendaId = $agenda->add_event(
                $date,
                $end_date,
                'false',
                $title,
                $content,
                array('GROUP:'.$groupId)
            );
        } else {
            $agenda->edit_event(
                $agendaId,
                $end_date,
                $end_date,
                'false',
                $title,
                $content
            );
        }
    }

    $qualification = isset($params['qualification']) && !empty($params['qualification']) ? 1 : 0;
    $expiryDate = (isset($params['enableExpiryDate']) && $params['enableExpiryDate'] == 1) ? api_get_utc_datetime($params['expires_on']) : '0000-00-00 00:00:00';
    $endDate = ((isset($params['enableEndDate']) && $params['enableEndDate']==1) ? api_get_utc_datetime($params['ends_on']) : '0000-00-00 00:00:00');

    $data = get_work_assignment_by_id($workId, $course_id);

    if (empty($data)) {

        $sql = "INSERT INTO $table SET
                c_id = $course_id ,
                expires_on              = '".Database::escape_string($expiryDate)."',
                ends_on                 = '".Database::escape_string($endDate)."',
                add_to_calendar         = $agendaId,
                enable_qualification    = '$qualification',
                publication_id          = '$workId'";
        Database::query($sql);

        $my_last_id = Database::insert_id();

        $sql = "UPDATE $workTable SET
                    has_properties  = $my_last_id ,
                    view_properties = 1
                WHERE c_id = $course_id AND id = $workId";
        Database::query($sql);
    } else {
        $sql = "UPDATE $table SET
                    expires_on = '".$expiryDate."',
                    ends_on = '".$endDate."',
                    add_to_calendar  = $agendaId,
                    enable_qualification = '".$qualification."'
                WHERE
                    publication_id = $workId AND
                    c_id = $course_id AND
                    id = ".$data['id'];
        Database::query($sql);
    }

    if (!empty($params['category_id'])) {

        require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
        require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
        require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
        require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';

        $link_info = is_resource_in_course_gradebook(
            $courseInfo['code'],
            LINK_STUDENTPUBLICATION,
            $workId,
            api_get_session_id()
        );

        $linkId = null;
        if (!empty($link_info)) {
            $linkId = $link_info['id'];
        }

        if (isset($params['make_calification']) && $params['make_calification'] == 1) {
            if (empty($linkId)) {
                add_resource_to_course_gradebook(
                    $params['category_id'],
                    $courseInfo['code'],
                    LINK_STUDENTPUBLICATION,
                    $workId,
                    $params['dir_name'],
                    (float)$params['weight'],
                    (float)$params['qualification'],
                    $params['description'],
                    1,
                    api_get_session_id()
                );
            } else {
                update_resource_from_course_gradebook(
                    $linkId,
                    $courseInfo['code'],
                    $params['weight']
                );
            }
        } else {
            // Delete everything of the gradebook for this $linkId
            remove_resource_from_course_gradebook($linkId);
        }
    }
}
Esempio n. 10
0
    'post',
    api_get_path(WEB_CODE_PATH) . 'work/edit_work.php?id=' . $workId . '&' . api_get_cidreq()
);
$form->addElement('header', get_lang('Edit'));

$title = !empty($workData['title']) ? $workData['title'] : basename($workData['url']);

$defaults = $workData;
$defaults['new_dir'] = Security::remove_XSS($title);

$there_is_a_end_date = false;

if (Gradebook::is_active()) {
    $link_info = is_resource_in_course_gradebook(
        api_get_course_id(),
        LINK_STUDENTPUBLICATION,
        $workId
    );
    if (!empty($link_info)) {
        $defaults['weight'] = $link_info['weight'];
        $defaults['category_id'] = $link_info['category_id'];
        $defaults['make_calification'] = 1;
    }
} else {
    $defaults['category_id'] = '';
}

if ($homework['expires_on'] != '0000-00-00 00:00:00') {
    $homework['expires_on'] = api_get_local_time($homework['expires_on']);
    $there_is_a_expire_date = true;
    $defaults['enableExpiryDate'] = true;
Esempio n. 11
0
/**
 * Display the list of student publications, taking into account the user status
 *
 * @param $origin - typically empty or 'learnpath'
 */
function display_student_publications_list($id, $my_folder_data, $work_parents, $origin, $add_in_where_query = '', $userList = array())
{
    global $gradebook;
    $_course = api_get_course_info();
    // Database table names
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
    $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
    $session_id = api_get_session_id();
    $condition_session = api_get_session_condition($session_id);
    $course_id = api_get_course_int_id();
    $course_info = api_get_course_info(api_get_course_id());
    $sort_params = array();
    if (isset($_GET['column'])) {
        $sort_params[] = 'column=' . Security::remove_XSS($_GET['column']);
    }
    if (isset($_GET['page_nr'])) {
        $sort_params[] = 'page_nr=' . Security::remove_XSS($_GET['page_nr']);
    }
    if (isset($_GET['per_page'])) {
        $sort_params[] = 'per_page=' . Security::remove_XSS($_GET['per_page']);
    }
    if (isset($_GET['direction'])) {
        $sort_params[] = 'direction=' . Security::remove_XSS($_GET['direction']);
    }
    $sort_params = implode('&amp;', $sort_params);
    $my_params = $sort_params;
    $origin = Security::remove_XSS($origin);
    $qualification_exists = false;
    if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) {
        $qualification_exists = true;
    }
    $edit_dir = isset($_GET['edit_dir']) ? intval($_GET['edit_dir']) : '';
    $table_header = array();
    $table_has_actions_column = false;
    $table_header[] = array(get_lang('Type'), false, 'style="width:40px"');
    $table_header[] = array(get_lang('Title'), true);
    if (!empty($id)) {
        $table_header[] = array(get_lang('FirstName'), true);
        $table_header[] = array(get_lang('LastName'), true);
    }
    $table_header[] = array(get_lang('HandOutDateLimit'), true, 'style="width:200px"');
    if ($is_allowed_to_edit) {
        $table_header[] = array(get_lang('HandedOut'), false);
        $table_header[] = array(get_lang('Actions'), false, 'style="width:90px"', array('class' => 'td_actions'));
        $table_has_actions_column = true;
        if ($qualification_exists) {
            $table_header[] = array(get_lang('Qualification'), true);
        }
    } else {
        // All users
        if ($course_info['show_score'] == 0) {
            $table_header[] = array(get_lang('Others'), false);
        }
    }
    $table_data = array();
    // List of all folders if no id was provided
    $group_id = api_get_group_id();
    if (is_array($work_parents)) {
        foreach ($work_parents as $work_parent) {
            $sql_select_directory = "SELECT\n\t\t\t        title,\n\t\t\t        url,\n\t\t\t        prop.insert_date,\n\t\t\t        prop.lastedit_date,\n\t\t\t        work.id, author,\n\t\t\t        has_properties,\n\t\t\t        view_properties,\n\t\t\t        description,\n\t\t\t        qualification,\n\t\t\t        weight,\n\t\t\t        allow_text_assignment\n                FROM " . $iprop_table . " prop INNER JOIN " . $work_table . " work ON (prop.ref=work.id AND prop.c_id = {$course_id})\n                WHERE active IN (0, 1) AND ";
            if (!empty($group_id)) {
                $sql_select_directory .= " work.post_group_id = '" . $group_id . "' ";
                // set to select only messages posted by the user's group
            } else {
                $sql_select_directory .= " work.post_group_id = '0' ";
            }
            $sql_select_directory .= " AND " . "  work.c_id = {$course_id} AND " . "  work.id  = " . $work_parent->id . " AND " . "  work.filetype = 'folder' AND " . "  prop.tool='work' {$condition_session}";
            $result = Database::query($sql_select_directory);
            $row = Database::fetch_array($result, 'ASSOC');
            if (!$row) {
                // the folder belongs to another session
                continue;
            }
            $direc_date = $row['lastedit_date'];
            //directory's date
            $author = $row['author'];
            //directory's author
            $view_properties = $row['view_properties'];
            $is_assignment = $row['has_properties'];
            $id2 = $row['id'];
            //work id
            $locked = api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION);
            // form edit directory
            if (!empty($row['has_properties'])) {
                $sql = Database::query('SELECT * FROM ' . $work_assigment . ' WHERE c_id = ' . $course_id . ' AND id = "' . $row['has_properties'] . '" LIMIT 1');
                $homework = Database::fetch_array($sql);
            }
            // save original value for later
            $utc_expiry_time = $homework['expires_on'];
            if ($is_allowed_to_edit && $locked == false) {
                if (!empty($edit_dir) && $edit_dir == $id2) {
                    $form_folder = new FormValidator('edit_dir', 'post', api_get_self() . '?origin=' . $origin . '&gradebook=' . $gradebook . '&edit_dir=' . $id2);
                    $form_folder->addElement('text', 'dir_name', get_lang('Title'));
                    $form_folder->addElement('hidden', 'work_id', $id2);
                    $form_folder->addRule('dir_name', get_lang('ThisFieldIsRequired'), 'required');
                    $my_title = !empty($row['title']) ? $row['title'] : basename($row['url']);
                    $defaults = array('dir_name' => Security::remove_XSS($my_title), 'description' => Security::remove_XSS($row['description']));
                    $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '80%', 'Height' => '200'));
                    $there_is_a_end_date = false;
                    $form_folder->addElement('advanced_settings', 'work', get_lang('AdvancedParameters'));
                    $form_folder->addElement('html', '<div id="work_options" style="display: none;">');
                    if (empty($default)) {
                        $default = api_get_local_time();
                    }
                    $parts = explode(' ', $default);
                    list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
                    list($d_hour, $d_minute) = explode(':', $parts[1]);
                    $qualification_input[] = $form_folder->createElement('text', 'qualification');
                    $form_folder->addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'));
                    if (Gradebook::is_active()) {
                        $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $id2);
                        $form_folder->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
                        if (!empty($link_info)) {
                            $form_folder->addElement('html', '<div id=\'option3\' style="display:block">');
                        } else {
                            $form_folder->addElement('html', '<div id=\'option3\' style="display:none">');
                        }
                        //Loading gradebook select
                        load_gradebook_select_in_tool($form_folder);
                        $weight_input2[] = $form_folder->createElement('text', 'weight');
                        $form_folder->addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
                        $form_folder->addElement('html', '</div>');
                        $defaults['weight[weight]'] = $link_info['weight'];
                        if (!empty($link_info)) {
                            $defaults['category_id'] = $link_info['category_id'];
                            $defaults['make_calification'] = 1;
                        }
                    } else {
                        $defaults['category_id'] = '';
                    }
                    if ($homework['expires_on'] != '0000-00-00 00:00:00') {
                        $homework['expires_on'] = api_get_local_time($homework['expires_on']);
                        $there_is_a_expire_date = true;
                        $defaults['enableExpiryDate'] = true;
                        $form_folder->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
                        $form_folder->addElement('html', '<div id=\'option1\' style="display:block">');
                        $form_folder->addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
                        $form_folder->addElement('html', '</div>');
                    } else {
                        $homework['expires_on'] = api_get_local_time();
                        $expires_date_array = convert_date_to_array(api_get_local_time(), 'expires');
                        $defaults = array_merge($defaults, $expires_date_array);
                        $there_is_a_expire_date = false;
                        $form_folder->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
                        $form_folder->addElement('html', '<div id=\'option1\' style="display:none">');
                        $form_folder->addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
                        $form_folder->addElement('html', '</div>');
                    }
                    if ($homework['ends_on'] != '0000-00-00 00:00:00') {
                        $homework['ends_on'] = api_get_local_time($homework['ends_on']);
                        $there_is_a_end_date = true;
                        $defaults['enableEndDate'] = true;
                        $form_folder->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
                        $form_folder->addElement('html', '<div id=\'option2\' style="display:block">');
                        $form_folder->addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
                        $form_folder->addElement('html', '</div>');
                        $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
                    } else {
                        $homework['ends_on'] = api_get_local_time();
                        $expires_date_array = convert_date_to_array(api_get_local_time(), 'ends');
                        $defaults = array_merge($defaults, $expires_date_array);
                        $there_is_a_end_date = false;
                        $form_folder->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
                        $form_folder->addElement('html', '<div id=\'option2\' style="display:none">');
                        $form_folder->addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
                        $form_folder->addElement('html', '</div>');
                        $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
                    }
                    if ($there_is_a_expire_date && $there_is_a_end_date) {
                        $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
                    }
                    $form_folder->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
                    $form_folder->addElement('html', '</div>');
                    $form_folder->addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"');
                    if ($there_is_a_end_date) {
                        $end_date_array = convert_date_to_array($homework['ends_on'], 'ends');
                        $defaults = array_merge($defaults, $end_date_array);
                    }
                    if ($there_is_a_expire_date) {
                        $expires_date_array = convert_date_to_array($homework['expires_on'], 'expires');
                        $defaults = array_merge($defaults, $expires_date_array);
                    }
                    if (!empty($row['qualification'])) {
                        $defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification']));
                    }
                    $defaults['allow_text_assignment'] = $row['allow_text_assignment'];
                    $form_folder->setDefaults($defaults);
                    $display_edit_form = true;
                    if ($form_folder->validate()) {
                        if ($_POST['enableExpiryDate'] == '1') {
                            $there_is_a_expire_date = true;
                        } else {
                            $there_is_a_expire_date = false;
                        }
                        if ($_POST['enableEndDate'] == '1') {
                            $there_is_a_end_date = true;
                        } else {
                            $there_is_a_end_date = false;
                        }
                        $values = $form_folder->exportValues();
                        $work_id = $values['work_id'];
                        $dir_name = replace_dangerous_char($values['dir_name']);
                        $dir_name = disable_dangerous_file($dir_name);
                        $edit_check = false;
                        $work_data = get_work_data_by_id($work_id);
                        if (!empty($work_data)) {
                            $edit_check = true;
                        } else {
                            $edit_check = true;
                        }
                        if ($edit_check) {
                            $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
                            $expires_query = ' SET expires_on = ' . "'" . ($there_is_a_expire_date ? api_get_utc_datetime(get_date_from_group('expires')) : '0000-00-00 00:00:00') . "'";
                            Database::query('UPDATE ' . $work_assigment . $expires_query . ' WHERE c_id = ' . $course_id . ' AND id = ' . "'" . $row['has_properties'] . "'");
                            $sql_add_publication = "UPDATE " . $work_table . " SET has_properties  = '" . $row['has_properties'] . "', view_properties=1 WHERE c_id = {$course_id} AND id ='" . $row['id'] . "'";
                            Database::query($sql_add_publication);
                            $ends_query = ' SET ends_on = ' . "'" . ($there_is_a_end_date ? api_get_utc_datetime(get_date_from_group('ends')) : '0000-00-00 00:00:00') . "'";
                            Database::query('UPDATE ' . $work_assigment . $ends_query . ' WHERE c_id = ' . $course_id . ' AND id = ' . "'" . $row['has_properties'] . "'");
                            $sql_add_publication = "UPDATE " . $work_table . " SET has_properties  = '" . $row['has_properties'] . "', view_properties=1 WHERE c_id = {$course_id} AND id ='" . $row['id'] . "'";
                            Database::query($sql_add_publication);
                            $qualification_value = isset($_POST['qualification']['qualification']) && !empty($_POST['qualification']['qualification']) ? intval($_POST['qualification']['qualification']) : 0;
                            $enable_qualification = !empty($qualification_value) ? 1 : 0;
                            $sql_add_publication = "UPDATE " . $work_assigment . " SET enable_qualification  = '" . $enable_qualification . "' WHERE c_id = {$course_id} AND publication_id ='" . $row['id'] . "'";
                            Database::query($sql_add_publication);
                            $sql = 'UPDATE ' . $work_table . ' SET
                                                 allow_text_assignment = ' . "'" . intval($_POST['allow_text_assignment']) . "'" . ' ,
                                                 title = ' . "'" . Database::escape_string($_POST['dir_name']) . "'" . ',
                                                 description = ' . "'" . Database::escape_string($_POST['description']) . "'" . ',
                                                 qualification = ' . "'" . Database::escape_string($_POST['qualification']['qualification']) . "'" . ',
                                                 weight = ' . "'" . Database::escape_string($_POST['weight']['weight']) . "'" . '
                                             WHERE c_id = ' . $course_id . ' AND id = ' . $row['id'];
                            Database::query($sql);
                            require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
                            require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/gradebookitem.class.php';
                            require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/evaluation.class.php';
                            require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/abstractlink.class.php';
                            $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], api_get_session_id());
                            $link_id = null;
                            if (!empty($link_info)) {
                                $link_id = $link_info['id'];
                            }
                            if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) {
                                if (empty($link_id)) {
                                    add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], $_POST['dir_name'], (double) $_POST['weight']['weight'], (double) $_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id(), $link_id);
                                } else {
                                    update_resource_from_course_gradebook($link_id, api_get_course_id(), $_POST['weight']['weight']);
                                }
                            } else {
                                //Delete everything of the gradebook
                                remove_resource_from_course_gradebook($link_id);
                            }
                            update_dir_name($work_data, $dir_name, $values['dir_name']);
                            $dir = $dir_name;
                            $display_edit_form = false;
                            // gets calendar_id from student_publication_assigment
                            $sql = "SELECT add_to_calendar FROM {$work_assigment} WHERE c_id = {$course_id} AND publication_id ='" . $row['id'] . "'";
                            $res = Database::query($sql);
                            $calendar_id = Database::fetch_row($res);
                            $dir_name = sprintf(get_lang('HandingOverOfTaskX'), $dir_name);
                            $end_date = $row['insert_date'];
                            if ($_POST['enableExpiryDate'] == '1') {
                                $end_date = Database::escape_string(api_get_utc_datetime(get_date_from_group('expires')));
                            }
                            // update from agenda if it exists
                            if (!empty($calendar_id[0])) {
                                $sql = "UPDATE " . $TABLEAGENDA . "\n\t\t\t\t\t\t\t\t\t\tSET title='" . $values['dir_name'] . "',\n\t\t\t\t\t\t\t\t\t\t\tcontent  = '" . Database::escape_string($_POST['description']) . "',\n\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $end_date . "',\n\t\t\t\t\t\t\t\t\t\t\tend_date   = '" . $end_date . "'\n\t\t\t\t\t\t\t\t\t\tWHERE c_id = {$course_id} AND id='" . $calendar_id[0] . "'";
                                Database::query($sql);
                            }
                            Display::display_confirmation_message(get_lang('FolderEdited'));
                        } else {
                            Display::display_warning_message(get_lang('FileExists'));
                        }
                    }
                }
            }
            $work_data = get_work_data_by_id($work_parent->id);
            $action = '';
            $row = array();
            $class = '';
            $course_id = api_get_course_int_id();
            $session_id = api_get_session_id();
            if (api_is_allowed_to_edit()) {
                $cant_files = get_count_work($work_data['id']);
            } else {
                $isSubscribed = userIsSubscribedToWork(api_get_user_id(), $work_data['id'], $course_id);
                if ($isSubscribed == false) {
                    continue;
                }
                $cant_files = get_count_work($work_data['id'], api_get_user_id());
            }
            $text_file = get_lang('FilesUpload');
            if ($cant_files == 1) {
                $text_file = api_strtolower(get_lang('FileUpload'));
            }
            $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), ICON_SIZE_SMALL);
            if (!empty($display_edit_form) && !empty($edit_dir) && $edit_dir == $id2) {
                $row[] = $icon;
                $row[] = '<span class="invisible" style="display:none">' . $dir . '</span>' . $form_folder->toHtml();
                // form to edit the directory's name
            } else {
                $row[] = '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . $gradebook . '">' . $icon . '</a>';
                $add_to_name = '';
                require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
                $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3, $id2, api_get_session_id());
                $link_id = $link_info['id'];
                $count = 0;
                if ($link_info !== false) {
                    $gradebook_data = get_resource_from_course_gradebook($link_id);
                    $count = $gradebook_data['weight'];
                }
                if ($count > 0) {
                    $add_to_name = Display::label(get_lang('IncludedInEvaluation'), 'info');
                } else {
                    $add_to_name = '';
                }
                $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']);
                // Work name
                if ($cant_files > 0) {
                    $zip = '<a href="downloadfolder.inc.php?id=' . $work_data['id'] . '">' . Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL) . '</a>';
                }
                $link = 'work_list.php';
                if (api_is_allowed_to_edit()) {
                    $link = 'work_list_all.php';
                }
                $url = $zip . '<a href="' . api_get_path(WEB_CODE_PATH) . 'work/' . $link . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . Security::remove_XSS($_GET['gradebook']) . '&id=' . $work_data['id'] . '"' . $class . '>' . $work_title . '</a> ' . $add_to_name . '<br />' . $cant_files . ' ' . $text_file . $dirtext;
                $row[] = $url;
            }
            if ($count_files != 0) {
                $row[] = '';
            }
            if (!empty($homework)) {
                // use original utc value saved previously to avoid doubling the utc-to-local conversion ($homework['expires_on'] might have been tainted)
                $row[] = !empty($utc_expiry_time) && $utc_expiry_time != '0000-00-00 00:00:00' ? api_get_local_time($utc_expiry_time) : '-';
            } else {
                $row[] = '-';
            }
            if (!$is_allowed_to_edit) {
                if ($course_info['show_score'] == 0) {
                    $url = api_get_path(WEB_CODE_PATH) . 'work/work_list_others.php?' . api_get_cidreq() . '&id=' . $work_parent->id;
                    $row[] = Display::url(Display::return_icon('group.png', get_lang('Others')), $url);
                }
            }
            if ($origin != 'learnpath') {
                if ($is_allowed_to_edit) {
                    $cant_files_per_user = getUniqueStudentAttempts($work_data['id'], $group_id, $course_id, api_get_session_id(), null, $userList);
                    $row[] = $cant_files_per_user . '/' . count($userList);
                    if (api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION)) {
                        $action .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
                        $action .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
                    } else {
                        $action .= '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&origin=' . $origin . '&gradebook=' . $gradebook . '&edit_dir=' . $id2 . '">' . Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL) . '</a>';
                        $action .= ' <a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . $gradebook . '&delete_dir=' . $id2 . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('DirDelete') . '"  >' . Display::return_icon('delete.png', get_lang('DirDelete'), '', ICON_SIZE_SMALL) . '</a>';
                    }
                    $row[] = $action;
                } else {
                    $row[] = '';
                }
            }
            //$row[] = $direc_date_local;
            $row[] = $work_data['title'];
            $table_data[] = $row;
        }
    }
    $sorting_options = array();
    $sorting_options['column'] = 1;
    // Here we change the way how the columns are going to be sorted
    // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
    // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
    $column_order = array();
    $i = 0;
    foreach ($table_header as $item) {
        $column_order[$i] = $i;
        $i++;
    }
    if (empty($my_folder_data)) {
        $column_order[1] = 5;
    } else {
        $column_order[2] = 2;
    }
    // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
    $column_show = array();
    $column_show[] = 1;
    // type 0
    $column_show[] = 1;
    // title 1
    if (!empty($my_folder_data)) {
        $column_show[] = 1;
        // 2
        $column_show[] = 1;
        // 3
        if ($qualification_exists) {
            $column_show[] = 1;
            // 4
        }
    }
    $column_show[] = 1;
    //date
    if ($table_has_actions_column) {
        $column_show[] = 1;
        // modify
    }
    $column_show[] = 1;
    //real date in correct format
    $column_show[] = 0;
    //real date in correct format
    $paging_options = array();
    if (isset($_GET['curdirpath'])) {
        $my_params = array('curdirpath' => Security::remove_XSS($_GET['curdirpath']));
    }
    $my_params = array('id' => isset($_GET['id']) ? $_GET['id'] : null);
    if (isset($_GET['edit_dir'])) {
        $my_params = array('edit_dir' => intval($_GET['edit_dir']));
    }
    $my_params['origin'] = $origin;
    Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order);
}
/**
 * This function stores the edit of a post in the forum_post table.
 *
 * @param array
 * @return void HTML
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @version february 2006, dokeos 1.8
 */
function store_edit_post($values)
{
    $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
    $gradebook = Security::remove_XSS($_GET['gradebook']);
    $course_id = api_get_course_int_id();
    //check if this post is the first of the thread
    // First we check if the change affects the thread and if so we commit the changes (sticky and post_title=thread_title are relevant).
    $posts = get_posts($values['thread_id']);
    $first_post = null;
    if (!empty($posts)) {
        $first_post = $posts[0];
    }
    if (!empty($first_post) && $first_post['post_id'] == $values['post_id']) {
        //if (array_key_exists('is_first_post_of_thread', $values) AND $values['is_first_post_of_thread'] == '1') {
        $sql = "UPDATE {$table_threads} SET\n                thread_title            ='" . Database::escape_string($values['post_title']) . "',\n                thread_sticky           ='" . Database::escape_string(isset($values['thread_sticky']) ? $values['thread_sticky'] : null) . "'," . "thread_title_qualify   ='" . Database::escape_string($values['calification_notebook_title']) . "'," . "thread_qualify_max     ='" . Database::escape_string($values['numeric_calification']) . "'," . "thread_weight          ='" . Database::escape_string($values['weight_calification']) . "'" . " WHERE c_id = {$course_id} AND thread_id='" . intval($values['thread_id']) . "'";
        Database::query($sql);
    }
    // Update the post_title and the post_text.
    $sql = "UPDATE {$table_posts} SET\n                post_title          ='" . Database::escape_string($values['post_title']) . "',\n                post_text           ='" . Database::escape_string($values['post_text']) . "',\n                post_notification   ='" . Database::escape_string(isset($values['post_notification']) ? $values['post_notification'] : null) . "'\n                WHERE c_id = {$course_id} AND post_id = '" . intval($values['post_id']) . "'";
    Database::query($sql);
    // Update attached files
    if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
        foreach ($_POST['file_ids'] as $key => $id) {
            editAttachedFile(array('comment' => $_POST['file_comments'][$key], 'post_id' => $values['post_id']), $id);
        }
    }
    if (!empty($values['remove_attach'])) {
        delete_attachment($values['post_id']);
    }
    if (empty($values['id_attach'])) {
        add_forum_attachment_file($values['file_comment'], $values['post_id']);
    } else {
        edit_forum_attachment_file($values['file_comment'], $values['post_id'], $values['id_attach']);
    }
    if (api_is_course_admin() == true) {
        $ccode = api_get_course_id();
        $sid = api_get_session_id();
        $link_info = is_resource_in_course_gradebook($ccode, 5, $values['thread_id'], $sid);
        $link_id = $link_info['id'];
        $thread_qualify_gradebook = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
        if ($thread_qualify_gradebook != 1) {
            if ($link_info !== false) {
                remove_resource_from_course_gradebook($link_id);
            }
        } else {
            if ($link_info === false && !$_GET['thread']) {
                $weigthqualify = $values['weight_calification'];
                add_resource_to_course_gradebook($values['category_id'], $ccode, 5, $values['thread_id'], Database::escape_string(stripslashes($values['calification_notebook_title'])), $weigthqualify, $values['numeric_calification'], null, 0, $sid);
            }
        }
    }
    // Storing the attachments if any.
    //update_added_resources('forum_post', $values['post_id']);
    $message = get_lang('EditPostStored') . '<br />';
    $message .= get_lang('ReturnTo') . ' <a href="viewforum.php?' . api_get_cidreq() . '&forum=' . Security::remove_XSS($_GET['forum']) . '&">' . get_lang('Forum') . '</a><br />';
    $message .= get_lang('ReturnTo') . ' <a href="viewthread.php?' . api_get_cidreq() . '&forum=' . Security::remove_XSS($_GET['forum']) . '&gradebook=' . $gradebook . '&thread=' . $values['thread_id'] . '&post=' . Security::remove_XSS($_GET['post']) . '">' . get_lang('Message') . '</a>';
    Session::erase('formelements');
    Session::erase('origin');
    Session::erase('breadcrumbs');
    Session::erase('addedresource');
    Session::erase('addedresourceid');
    Display::display_confirmation_message($message, false);
}