示例#1
0
    $param_gradebook = '&gradebook=' . Security::remove_XSS($_SESSION['gradebook']);
}
if (!$error) {
    $token = Security::get_token();
}
$attendance_weight = floatval($attendance_weight);
// display form
$form = new FormValidator('attendance_edit', 'POST', 'index.php?action=attendance_edit&' . api_get_cidreq() . '&attendance_id=' . $attendance_id . $param_gradebook);
$form->addElement('header', '', get_lang('Edit'));
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'attendance_id', $attendance_id);
$form->add_textfield('title', get_lang('Title'), true, array('size' => '50'));
$form->applyFilter('title', 'html_filter');
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
// 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();"');
示例#2
0
 */
$cidReset = true;
//require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('skill.allow_skills_tool') != 'true') {
    api_not_allowed();
}
$interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'), "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateSkill'));
/* Process data */
$skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
$formDefaultValues = [];
$objSkill = new Skill();
$objGradebook = new Gradebook();
if ($skillParentId > 0) {
    $skillParentInfo = $objSkill->get_skill_info($skillParentId);
    $formDefaultValues = ['parent_id' => $skillParentInfo['id'], 'gradebook_id' => []];
    foreach ($skillParentInfo['gradebooks'] as $gradebook) {
        $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
    }
}
$allSkills = $objSkill->get_all();
$allGradebooks = $objGradebook->find('all');
$skillList = [0 => get_lang('None')];
$gradebookList = [];
foreach ($allSkills as $skill) {
    $skillList[$skill['id']] = $skill['name'];
}
foreach ($allGradebooks as $gradebook) {
/**
 * This function displays the form that is used to edit a post. This can be a new thread or a reply.
 * @param array contains all the information about the current post
 * @param array contains all the information about the current thread
 * @param array contains all info about the current forum (to check if attachments are allowed)
 * @param array contains the default values to fill the form
 * @return void
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @version february 2006, dokeos 1.8
 */
function show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
{
    // Initialize the object.
    $form = new FormValidator('edit_post', 'post', api_get_self() . '?' . api_get_cidreq() . '&forum=' . Security::remove_XSS($_GET['forum']) . '&thread=' . Security::remove_XSS($_GET['thread']) . '&post=' . Security::remove_XSS($_GET['post']));
    $form->addElement('header', get_lang('EditPost'));
    // Setting the form elements.
    $form->addElement('hidden', 'post_id', $current_post['post_id']);
    $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
    $form->addElement('hidden', 'id_attach', $id_attach);
    if ($current_post['post_parent_id'] == 0) {
        $form->addElement('hidden', 'is_first_post_of_thread', '1');
    }
    $form->addElement('text', 'post_title', get_lang('Title'));
    $form->applyFilter('post_title', 'html_filter');
    $form->addHtmlEditor('post_text', get_lang('Text'), null, null, api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Forum', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'ForumStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student'));
    $form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
    $form->addButtonAdvancedSettings('advanced_params');
    $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
    if (!isset($_GET['edit'])) {
        if (Gradebook::is_active()) {
            $form->addElement('label', '<strong>' . get_lang('AlterQualifyThread') . '</strong>');
            $form->addElement('checkbox', 'thread_qualify_gradebook', '', get_lang('QualifyThreadGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
            $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, $_GET['thread'], api_get_session_id());
            if (!empty($link_info)) {
                $defaults['thread_qualify_gradebook'] = true;
                $defaults['category_id'] = $link_info['category_id'];
            } else {
                $defaults['thread_qualify_gradebook'] = false;
                $defaults['category_id'] = '';
            }
        } else {
            $form->addElement('hidden', 'thread_qualify_gradebook', false);
            $defaults['thread_qualify_gradebook'] = false;
        }
        if (!empty($defaults['thread_qualify_gradebook'])) {
            $form->addElement('html', '<div id="options_field" style="display:block">');
        } else {
            $form->addElement('html', '<div id="options_field" style="display:none">');
        }
        // Loading gradebook select
        GradebookUtils::load_gradebook_select_in_tool($form);
        $form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'), array('value' => $current_thread['thread_qualify_max'], 'style' => 'width:40px'));
        $form->applyFilter('numeric_calification', 'html_filter');
        $form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'), array('value' => $current_thread['thread_title_qualify']));
        $form->applyFilter('calification_notebook_title', 'html_filter');
        $form->addElement('text', 'weight_calification', array(get_lang('QualifyWeight'), null, ''), array('value' => $current_thread['thread_weight'], 'style' => 'width:40px'));
        $form->applyFilter('weight_calification', 'html_filter');
        $group = array();
        $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
        $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
        $form->addGroup($group, '', [get_lang('ForumThreadPeerScoring'), get_lang('ForumThreadPeerScoringComment')], ' ');
        $form->addElement('html', '</div>');
    }
    if ($forum_setting['allow_post_notification']) {
        $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail') . ' (' . $current_post['email'] . ')');
    }
    if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $current_post['post_parent_id'] == 0) {
        // The sticky checkbox only appears when it is the first post of a thread.
        $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
        if ($current_thread['thread_sticky'] == 1) {
            $defaults['thread_sticky'] = true;
        }
    }
    if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
        if (empty($form_values) && !isset($_POST['SubmitPost'])) {
            //edit_added_resources('forum_post', $current_post['post_id']);
        }
    }
    $form->addElement('html', '</div>');
    $form->addFile('user_upload[]', get_lang('Attachment'));
    $form->addButton('add_attachment', get_lang('AddAttachment'), 'paperclip', 'default', 'default', null, ['id' => 'reply-add-attachment']);
    $form->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
    // Setting the default values for the form elements.
    $defaults['post_title'] = $current_post['post_title'];
    $defaults['post_text'] = $current_post['post_text'];
    if ($current_post['post_notification'] == 1) {
        $defaults['post_notification'] = true;
    }
    if (!empty($form_values)) {
        $defaults['post_notification'] = Security::remove_XSS($form_values['post_notification']);
        $defaults['thread_sticky'] = Security::remove_XSS($form_values['thread_sticky']);
    }
    $defaults['thread_peer_qualify'] = intval($current_thread['thread_peer_qualify']);
    $form->setDefaults($defaults);
    // The course admin can make a thread sticky (=appears with special icon and always on top).
    $form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
    // Validation or display
    if ($form->validate()) {
        $values = $form->exportValues();
        if (isset($values['thread_qualify_gradebook']) && $values['thread_qualify_gradebook'] == '1' && empty($values['weight_calification'])) {
            Display::display_error_message(get_lang('YouMustAssignWeightOfQualification') . '&nbsp;<a href="javascript:window.history.go(-1);">' . get_lang('Back') . '</a>', false);
            return false;
        }
        return $values;
    } else {
        // Delete from $_SESSION forum attachment from other posts
        clearAttachedFiles($current_post['post_id']);
        // Get forum attachment ajax table to add it to form
        $fileData = getAttachmentsAjaxTable($current_post['post_id'], $current_forum['forum_id']);
        $form->addElement('html', $fileData);
        $form->display();
    }
}
示例#4
0
     $count = $obj->get_count();
     break;
 case 'get_extra_field_options':
     $type = $_REQUEST['type'];
     $field_id = $_REQUEST['field_id'];
     $obj = new ExtraFieldOption($type);
     $count = $obj->get_count_by_field_id($field_id);
     break;
 case 'get_timelines':
     require_once $libpath . 'timeline.lib.php';
     $obj = new Timeline();
     $count = $obj->get_count();
     break;
 case 'get_gradebooks':
     require_once $libpath . 'gradebook.lib.php';
     $obj = new Gradebook();
     $count = $obj->get_count();
     break;
 case 'get_event_email_template':
     $obj = new EventEmailTemplate();
     $count = $obj->get_count();
     break;
 case 'get_careers':
     $obj = new Career();
     $count = $obj->get_count();
     break;
 case 'get_promotions':
     $obj = new Promotion();
     $count = $obj->get_count();
     break;
 case 'get_grade_models':
                            return \'<a href="?action=add_skill&id=\'+options.rowId+\'">' . Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL) . '</a>' . '\';
                        } else {
                            return \'' . Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL) . '' . '\';
                        }
                 }';
?>
<script>
$(function() {
<?php 
// grid definition see the $career->display() function
echo Display::grid_js('gradebooks', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
?>
});
</script>
<?php 
$gradebook = new Gradebook();
switch ($action) {
    case 'display':
        $gradebook->display();
        break;
    case 'add_skill':
        $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
        $gradebook_info = $gradebook->get($id);
        $url = api_get_self() . '?action=' . $action . '&id=' . $id;
        $form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
        if ($form->validate()) {
            $values = $form->exportValues();
            $res = $gradebook->update_skills_to_gradebook($values['id'], $values['skill']);
            if ($res) {
                Display::display_confirmation_message(get_lang('ItemAdded'));
            }
 /**
  * Update the properties of this category in the database
  * @todo fix me
  */
 public function save()
 {
     $tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
     $sql = 'UPDATE ' . $tbl_grade_categories . " SET name = '" . Database::escape_string($this->get_name()) . "'" . ', description = ';
     if (isset($this->description)) {
         $sql .= "'" . Database::escape_string($this->get_description()) . "'";
     } else {
         $sql .= 'null';
     }
     $sql .= ', user_id = ' . intval($this->get_user_id()) . ', course_code = ';
     if (isset($this->course_code)) {
         $sql .= "'" . Database::escape_string($this->get_course_code()) . "'";
     } else {
         $sql .= 'null';
     }
     $sql .= ', parent_id = ';
     if (isset($this->parent)) {
         $sql .= intval($this->get_parent_id());
     } else {
         $sql .= 'null';
     }
     $sql .= ', certif_min_score = ';
     if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) {
         $sql .= Database::escape_string($this->get_certificate_min_score());
     } else {
         $sql .= 'null';
     }
     if (isset($this->grade_model_id)) {
         $sql .= ', grade_model_id = ' . intval($this->get_grade_model_id());
     }
     $sql .= ', weight = ' . Database::escape_string($this->get_weight()) . ', visible = ' . intval($this->is_visible()) . ' WHERE id = ' . intval($this->id);
     Database::query($sql);
     if (!empty($this->id)) {
         $parent_id = $this->get_parent_id();
         $grade_model_id = $this->get_grade_model_id();
         if ($parent_id == 0) {
             if (isset($grade_model_id) && !empty($grade_model_id) && $grade_model_id != '-1') {
                 $obj = new GradeModel();
                 $components = $obj->get_components($grade_model_id);
                 $default_weight_setting = api_get_setting('gradebook_default_weight');
                 $default_weight = 100;
                 if (isset($default_weight_setting)) {
                     $default_weight = $default_weight_setting;
                 }
                 $final_weight = $this->get_weight();
                 if (!empty($final_weight)) {
                     $default_weight = $this->get_weight();
                 }
                 foreach ($components as $component) {
                     $gradebook = new Gradebook();
                     $params = array();
                     $params['name'] = $component['acronym'];
                     $params['description'] = $component['title'];
                     $params['user_id'] = api_get_user_id();
                     $params['parent_id'] = $this->id;
                     $params['weight'] = $component['percentage'] / 100 * $default_weight;
                     $params['session_id'] = api_get_session_id();
                     $params['course_code'] = $this->get_course_code();
                     $gradebook->save($params);
                 }
             }
         }
     }
     $gradebook = new Gradebook();
     $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
 }
// error messages
if (isset($error)) {
    Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
}
if (!isset($error)) {
    $token = Security::get_token();
}
// display form
$form = new FormValidator('attendance_add', 'POST', 'index.php?action=attendance_add&' . api_get_cidreq());
$form->addElement('header', '', get_lang('CreateANewAttendance'));
$form->addElement('hidden', 'sec_token', $token);
$form->addText('title', get_lang('Title'), true);
$form->applyFilter('title', 'html_filter');
$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '150'));
// Adavanced Parameters
if (api_get_session_id() != 0 && Gradebook::is_active() || api_get_session_id() == 0) {
    $form->addButtonAdvancedSettings('id_qualify');
    $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
    // Qualify Attendance for gradebook option
    $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">');
    GradebookUtils::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->addButtonCreate(get_lang('Save'));
$form->display();
示例#8
0
 $grade_model_id = $cats[0]->get_grade_model_id();
 // No children.
 if (count($cats) == 1 && empty($grade_model_id) || count($cats) == 1 && $grade_model_id != -1) {
     if (!empty($grade_models)) {
         $form_grade = new FormValidator('grade_model_settings');
         $obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
         $form_grade->addButtonSave(get_lang('Save'));
         if ($form_grade->validate()) {
             $value = $form_grade->exportValue('grade_model_id');
             $gradebook = new Gradebook();
             $gradebook->update(array('id' => $cats[0]->get_id(), 'grade_model_id' => $value), true);
             //do something
             $obj = new GradeModel();
             $components = $obj->get_components($value);
             foreach ($components as $component) {
                 $gradebook = new Gradebook();
                 $params = array();
                 $params['name'] = $component['acronym'];
                 $params['description'] = $component['title'];
                 $params['user_id'] = api_get_user_id();
                 $params['parent_id'] = $cats[0]->get_id();
                 $params['weight'] = $component['percentage'];
                 $params['session_id'] = api_get_session_id();
                 $params['course_code'] = api_get_course_id();
                 $params['grade_model_id'] = api_get_session_id();
                 $gradebook->save($params);
             }
             // Reloading cats
             $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
         } else {
             $form_grade->display();
示例#9
0
/**
 * @param FormValidator $form
 * @param array $defaults
 * @return FormValidator
 */
function getFormWork($form, $defaults = array())
{
    if (!empty($defaults)) {
        if (isset($defaults['submit'])) {
            unset($defaults['submit']);
        }
    }
    // Create the form that asks for the directory name
    $form->addElement('text', 'new_dir', get_lang('AssignmentName'));
    $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required');
    $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
    $form->addElement(
        'advanced_settings',
        '<a href="javascript: void(0);" onclick="javascript: return plus();">
        <span id="plus">'.
        Display::return_icon(
            'div_show.gif',
            get_lang('AdvancedParameters'),
            array('style' => 'vertical-align:center')
        ).
        ' '.get_lang('AdvancedParameters').
        '</span></a>'
    );

    if (!empty($defaults) && (isset($defaults['enableEndDate']) || isset($defaults['enableExpiryDate']))) {
        $form->addElement('html', '<div id="options" style="display: block;">');
    } else {
        $form->addElement('html', '<div id="options" style="display: none;">');
    }

    // QualificationOfAssignment
    $form->addElement('text', 'qualification', get_lang('QualificationNumeric'));

    if ((api_get_session_id() != 0 && Gradebook::is_active()) || api_get_session_id() == 0) {
        $form->addElement(
            'checkbox',
            'make_calification',
            null,
            get_lang('MakeQualifiable'),
            array(
                'id' =>'make_calification_id',
                'onclick' => "javascript: if(this.checked) { document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}"
            )
        );
    } else {
        // QualificationOfAssignment
        $form->addElement('hidden', 'make_calification', false);
    }

    if (!empty($defaults) && isset($defaults['category_id'])) {
        $form->addElement('html', '<div id=\'option1\' style="display:block">');
    } else {
        $form->addElement('html', '<div id=\'option1\' style="display:none">');
    }

    // Loading Gradebook select
    load_gradebook_select_in_tool($form);

    $form->addElement('text', 'weight', get_lang('WeightInTheGradebook'));
    $form->addElement('html', '</div>');

    $form->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'id="expiry_date"');
    if (isset($defaults['enableExpiryDate']) && $defaults['enableExpiryDate']) {
        $form->addElement('html', '<div id="option2" style="display: block;">');
    } else {
        $form->addElement('html', '<div id="option2" style="display: none;">');
    }

    $currentDate = substr(api_get_local_time(), 0, 10);

    if (!isset($defaults['expires_on'])) {
        $date = substr($currentDate, 0, 10);
        $defaults['expires_on'] = $date.' 23:59';
    }

    if (!isset($defaults['ends_on'])) {
        $date = substr($currentDate, 0, 10);
        $defaults['ends_on'] = $date.' 23:59';
    }

    $form->addElement('date_time_picker', 'expires_on', get_lang('ExpiresAt'));
    $form->addElement('html', '</div>');

    $form->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'id="end_date"');

    if (isset($defaults['enableEndDate']) && $defaults['enableEndDate']) {
        $form->addElement('html', '<div id="option3" style="display: block;">');
    } else {
        $form->addElement('html', '<div id="option3" style="display: none;">');
    }

    $form->addElement('date_time_picker', 'ends_on', get_lang('EndsAt'));
    $form->addElement('html', '</div>');

    $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
    $form->addElement('select', 'allow_text_assignment', get_lang('DocumentType'), getUploadDocumentType());

    $form->addElement('html', '</div>');

    if (isset($defaults['enableExpiryDate']) && isset($defaults['enableEndDate'])) {
        $form->addRule(array('expires_on', 'ends_on'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
    }
    if (!empty($defaults)) {
        $form->setDefaults($defaults);
    }

    return $form;
}
示例#10
0
<?php

/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
/**
 * Responses to AJAX calls
 */
//require_once '../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
if (api_get_setting('skill.allow_skills_tool') != 'true') {
    exit;
}
Container::$legacyTemplate = 'layout_one_col_no_content.html.twig';
api_block_anonymous_users();
$skill = new Skill();
$gradebook = new Gradebook();
$skill_gradebook = new SkillRelGradebook();
switch ($action) {
    case 'add':
        if (api_is_platform_admin() || api_is_drh()) {
            if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
                $skill_id = $skill->edit($_REQUEST);
            } else {
                $skill_id = $skill->add($_REQUEST);
            }
        }
        echo $skill_id;
        break;
    case 'delete_skill':
        if (api_is_platform_admin() || api_is_drh()) {
            echo $skill->delete($_REQUEST['skill_id']);
示例#11
0
 /**
  * Shows the student's certificate (HTML file). If the global setting
  * allow_public_certificates is set to 'false', no certificate can be printed.
  * If the global allow_public_certificates is set to 'true' and the course
  * setting allow_public_certificates is set to 0, no certificate *in this
  * course* can be printed (for anonymous users). Connected users can always
  * print them.
  */
 public function show()
 {
     // Special rules for anonymous users
     $failed = false;
     if (api_is_anonymous()) {
         if (api_get_setting('allow_public_certificates') != 'true') {
             // The "non-public" setting is set, so do not print
             $failed = true;
         } else {
             // Check the course-level setting to make sure the certificate
             //  can be printed publicly
             if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
                 $gradebook = new Gradebook();
                 $gradebook_info = $gradebook->get($this->certificate_data['cat_id']);
                 if (!empty($gradebook_info['course_code'])) {
                     $allow_public_certificates = api_get_course_setting('allow_public_certificates', $gradebook_info['course_code']);
                     if ($allow_public_certificates == 0) {
                         // Printing not allowed
                         $failed = true;
                     }
                 } else {
                     // No course ID defined (should never get here)
                     Display::display_reduced_header();
                     Display::display_warning_message(get_lang('NoCertificateAvailable'));
                     exit;
                 }
             }
         }
     }
     if ($failed) {
         Display::display_reduced_header();
         Display::display_warning_message(get_lang('CertificateExistsButNotPublic'));
         exit;
     }
     //Read file or preview file
     if (!empty($this->certificate_data['path_certificate'])) {
         $user_certificate = $this->certification_user_path . basename($this->certificate_data['path_certificate']);
         if (file_exists($user_certificate)) {
             header('Content-Type: text/html; charset=' . api_get_system_encoding());
             echo @file_get_contents($user_certificate);
         }
     } else {
         Display::display_reduced_header();
         Display::display_warning_message(get_lang('NoCertificateAvailable'));
     }
     exit;
 }
示例#12
0
 /**
  * @param Application $app
  * @return string
  */
 public function indexAction(Application $app)
 {
     $request = $app['request'];
     $language_file = array('admin', 'exercice', 'gradebook', 'tracking');
     // 1. Setting variables needed by jqgrid
     $action = $request->get('a');
     $page = $request->get('page');
     //page
     $limit = $request->get('rows');
     //quantity of rows
     $sidx = $request->get('sidx');
     //index (field) to filter
     $sord = $request->get('sord');
     //asc or desc
     if (strpos(strtolower($sidx), 'asc') !== false) {
         $sidx = str_replace(array('asc', ','), '', $sidx);
         $sord = 'asc';
     }
     if (strpos(strtolower($sidx), 'desc') !== false) {
         $sidx = str_replace(array('desc', ','), '', $sidx);
         $sord = 'desc';
     }
     if (!in_array($sord, array('asc', 'desc'))) {
         $sord = 'desc';
     }
     if (!in_array($action, array('get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_user_skill_ranking', 'get_usergroups_teacher', 'get_question_list', 'get_user_list_plugin_widescale'))) {
         api_protect_admin_script(true);
     }
     if ($action == 'get_user_list_plugin_widescale') {
         $allowed = api_is_drh() || api_is_platform_admin();
         if (!$allowed) {
             api_not_allowed();
         }
     }
     // Search features.
     // If there is no search request sent by jqgrid, $where should be empty.
     $where_condition = "";
     $operation = $request->get('oper');
     $export_format = $request->get('export_format');
     $search_field = $request->get('searchField');
     $search_oper = $request->get('searchOper');
     $search_string = $request->get('searchString');
     $isSearch = $request->get('_search');
     $filters = $request->get('filters');
     $type = $request->get('type');
     $extra_fields = array();
     $questionFields = array();
     if ($isSearch == 'true') {
         $where_condition = ' 1 = 1 ';
         $where_condition_in_form = $this->getWhereClause($search_field, $search_oper, $search_string);
         if (!empty($where_condition_in_form)) {
             $where_condition .= ' AND ' . $where_condition_in_form;
         }
         $filters = isset($filters) ? json_decode($filters) : false;
         // for now
         if (!empty($filters)) {
             switch ($action) {
                 case 'get_questions':
                     $extraFieldtype = 'question';
                     break;
                 case 'get_sessions':
                     $extraFieldtype = 'session';
                     break;
             }
             // Extra field.
             $extraField = new \ExtraField($extraFieldtype);
             $result = $extraField->getExtraFieldRules($filters, 'extra_');
             $extra_fields = $result['extra_fields'];
             $condition_array = $result['condition_array'];
             if (!empty($condition_array)) {
                 $where_condition .= ' AND ( ';
                 $where_condition .= implode($filters->groupOp, $condition_array);
                 $where_condition .= ' ) ';
             }
             // Question field.
             $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_');
             $questionFields = $resultQuestion['extra_fields'];
             $condition_array = $resultQuestion['condition_array'];
             if (!empty($condition_array)) {
                 $where_condition .= ' AND ( ';
                 $where_condition .= implode($filters->groupOp, $condition_array);
                 $where_condition .= ' ) ';
             }
         }
     }
     // get index row - i.e. user click to sort $sord = $_GET['sord'];
     // get the direction
     if (!$sidx) {
         $sidx = 1;
     }
     //2. Selecting the count FIRST
     //@todo rework this
     switch ($action) {
         case 'get_questions':
             $categoryId = $request->get('categoryId');
             $exerciseId = $request->get('exerciseId');
             //$courseId = null; //$request->get('courseId');
             $courseId = $request->get('courseId');
             // Question manager can view all questions
             if (api_is_question_manager()) {
                 $courseId = null;
             }
             $count = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'extra' => $extra_fields, 'question' => $questionFields), true);
             break;
         case 'get_user_list_plugin_widescale':
             $count = \UserManager::get_user_data(null, null, null, null, true);
             break;
         case 'get_question_list':
             require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.class.php';
             $exerciseId = $request->get('exerciseId');
             $exercise = new \Exercise(api_get_course_int_id());
             $exercise->read($exerciseId);
             $count = $exercise->selectNbrQuestions();
             break;
         case 'get_group_reporting':
             $course_id = $request->get('course_id');
             $group_id = $request->get('gidReq');
             $count = \Tracking::get_group_reporting($course_id, $group_id, 'count');
             break;
         case 'get_user_course_report_resumed':
             $count = \CourseManager::get_count_user_list_from_course_code(true, 'ruc');
             break;
         case 'get_user_course_report':
             $count = \CourseManager::get_count_user_list_from_course_code(false);
             break;
         case 'get_course_exercise_medias':
             $course_id = api_get_course_int_id();
             $count = \Question::get_count_course_medias($course_id);
             break;
         case 'get_user_skill_ranking':
             $skill = new \Skill();
             $count = $skill->get_user_list_skill_ranking_count();
             break;
         case 'get_work_user_list':
             require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
             $work_id = $request->get('work_id');
             //$_REQUEST['work_id'];
             $count = get_count_work($work_id);
             break;
         case 'get_exercise_results':
             $exercise_id = $request->get('exerciseId');
             //$_REQUEST['exerciseId'];
             $filter_by_user = $request->get('filter_by_user');
             if (isset($filter_by_user) && !empty($filter_by_user)) {
                 $filter_user = intval($filter_by_user);
                 if ($where_condition == "") {
                     $where_condition .= " te.exe_user_id  = '{$filter_user}'";
                 } else {
                     $where_condition .= " AND te.exe_user_id  = '{$filter_user}'";
                 }
             }
             $count = \ExerciseLib::get_count_exam_results($exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $hotpot_path = $request->get('path');
             //$_REQUEST['path'];
             $count = \ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
             break;
         case 'get_sessions':
             $list_type = $request->get('list_type');
             if ($list_type == 'simple' || empty($list_type)) {
                 $count = \SessionManager::get_sessions_admin(array('where' => $where_condition, 'extra' => $extra_fields), true);
             } else {
                 $count = \SessionManager::get_count_admin_complete(array('where' => $where_condition, 'extra' => $extra_fields));
             }
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $count = $obj->get_count();
             break;
         case 'get_extra_field_options':
             $field_id = $request->get('field_id');
             $obj = new \ExtraFieldOption($type);
             $count = $obj->get_count_by_field_id($field_id);
             break;
         case 'get_timelines':
             $obj = new \Timeline();
             $count = $obj->get_count();
             break;
         case 'get_gradebooks':
             $obj = new \Gradebook();
             $count = $obj->get_count();
             break;
         case 'get_event_email_template':
             $obj = new \EventEmailTemplate();
             $count = $obj->get_count();
             break;
         case 'get_careers':
             $obj = new \Career();
             $count = $obj->get_count();
             break;
         case 'get_promotions':
             $obj = new \Promotion();
             $count = $obj->get_count();
             break;
         case 'get_grade_models':
             $obj = new \GradeModel();
             $count = $obj->get_count();
             break;
         case 'get_usergroups':
             $obj = new \UserGroup();
             $count = $obj->get_count();
             break;
         case 'get_usergroups_teacher':
             $obj = new \UserGroup();
             $course_id = api_get_course_int_id();
             if ($type == 'registered') {
                 $count = $obj->get_usergroup_by_course_with_data_count($course_id);
             } else {
                 $count = $obj->get_count();
             }
             break;
         default:
             exit;
     }
     //3. Calculating first, end, etc
     $total_pages = 0;
     if ((int) $count > 0) {
         if (!empty($limit)) {
             $total_pages = ceil($count / $limit);
         }
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start = $limit * $page - $limit;
     if ($start < 0) {
         $start = 0;
     }
     //4. Deleting an element if the user wants to
     if ($operation == 'del') {
         $obj->delete($request->get('id'));
     }
     $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh();
     //5. Querying the DB for the elements
     $columns = array();
     switch ($action) {
         case 'get_questions':
             $columns = \Question::getQuestionColumns(api_get_course_id(), $extra_fields, $questionFields, true);
             $columns = $columns['simple_column_name'];
             $result = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'question' => $questionFields, 'limit' => "{$start} , {$limit}"));
             //var_dump($result);
             break;
         case 'get_user_list_plugin_widescale':
             $columns = array('username', 'firstname', 'lastname', 'exam_password');
             $column_names = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password'));
             $result = \UserManager::get_user_data($start, $limit, $sidx, $sord);
             break;
         case 'get_question_list':
             if (isset($exercise) && !empty($exercise)) {
                 $columns = array('question', 'type', 'category', 'level', 'score', 'actions');
                 $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition);
             }
             break;
         case 'get_group_reporting':
             $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions');
             $result = \Tracking::get_group_reporting($course_id, $group_id, 'all', $start, $limit, $sidx, $sord, $where_condition);
             break;
         case 'get_course_exercise_medias':
             $columns = array('question');
             $result = \Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition);
             if (!empty($result)) {
                 foreach ($result as &$media) {
                     $media['id'] = $media['iid'];
                 }
             }
             break;
         case 'get_user_course_report_resumed':
             $columns = array('extra_ruc', 'training_hours', 'count_users', 'count_users_registered', 'average_hours_per_user', 'count_certificates');
             $column_names = array(get_lang('Company'), get_lang('TrainingHoursAccumulated'), get_lang('CountOfSubscriptions'), get_lang('CountOfUsers'), get_lang('AverageHoursPerStudent'), get_lang('CountCertificates'));
             $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true, true, 'ruc');
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $row) {
                     $row['training_hours'] = api_time_to_hms($row['training_hours']);
                     $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
                     $new_result[] = $row;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_user_course_report':
             $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress');
             $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance'));
             $extra_fields = \UserManager::get_extra_fields(0, 100, null, null, true, true);
             if (!empty($extra_fields)) {
                 foreach ($extra_fields as $extra) {
                     $columns[] = $extra['1'];
                     $column_names[] = $extra['3'];
                 }
             }
             $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true);
             break;
         case 'get_user_skill_ranking':
             $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
             $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
             $result = \ArrayClass::msort($result, 'skills_acquired', 'asc');
             $skills_in_course = array();
             if (!empty($result)) {
                 //$counter = 1;
                 foreach ($result as &$item) {
                     $user_info = api_get_user_info($item['user_id']);
                     $personal_course_list = \UserManager::get_personal_session_course_list($item['user_id']);
                     $count_skill_by_course = array();
                     foreach ($personal_course_list as $course_item) {
                         if (!isset($skills_in_course[$course_item['code']])) {
                             $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
                             $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
                         } else {
                             $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
                         }
                     }
                     $item['photo'] = \Display::img($user_info['avatar_small']);
                     $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
                 }
             }
             break;
         case 'get_work_user_list':
             if (isset($type) && $type == 'simple') {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
             } else {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions');
             }
             $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
             break;
         case 'get_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             if ($is_allowedToEdit) {
                 $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
             } else {
                 //$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
             }
             $result = \ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
             $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition);
             //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_sessions':
             $session_columns = \SessionManager::get_session_columns($list_type);
             $columns = $session_columns['simple_column_name'];
             if ($list_type == 'simple') {
                 $result = SessionManager::get_sessions_admin(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"), false);
             } else {
                 $result = SessionManager::get_sessions_admin_complete(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"));
             }
             break;
         case 'get_timelines':
             $columns = array('headline', 'actions');
             //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'headline';
             }
             $course_id = api_get_course_int_id();
             $result = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH) . 'timeline/view.php?id=' . $item['id']);
                 $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=add_item&parent_id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=edit&id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=delete&id=' . $item['id']);
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_gradebooks':
             $columns = array('name', 'certificates', 'skills', 'actions', 'has_certificates');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if ($item['parent_id'] != 0) {
                     continue;
                 }
                 $skills = $obj->get_skills_by_gradebook($item['id']);
                 //Fixes bug when gradebook doesn't have names
                 if (empty($item['name'])) {
                     $item['name'] = $item['course_code'];
                 } else {
                     //$item['name'] =  $item['name'].' ['.$item['course_code'].']';
                 }
                 $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?id_session=0&cidReq=' . $item['course_code']);
                 if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
                     $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '1';
                 } else {
                     $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '0';
                 }
                 if (!empty($skills)) {
                     foreach ($skills as $skill) {
                         $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
                     }
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_event_email_template':
             $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'subject';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $language_info = api_get_language_info($item['language_id']);
                 $item['language_id'] = $language_info['english_name'];
                 $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/event_type.php?action=edit&event_type_name=' . $item['event_type_name']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'admin/event_controller.php?action=delete&id=' . $item['id']);
                 /*if (!$item['status']) {
                       $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>';
                   }*/
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_careers':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_promotions':
             $columns = array('name', 'career', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "{$obj->table} p LEFT JOIN " . Database::get_main_table(TABLE_CAREER) . " c  ON c.id = p.career_id ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_grade_models':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', "{$obj->table} ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_usergroups':
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions');
             $result = Database::select('*', $obj->table, array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
                     $group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     switch ($group['group_type']) {
                         case '0':
                             $group['group_type'] = Display::label(get_lang('Class'), 'info');
                             break;
                         case '1':
                             $group['group_type'] = Display::label(get_lang('Social'), 'success');
                             break;
                     }
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             ArrayClass::msort($result, $sidx);
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
             $result = \Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $item) {
                     $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
                     $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $new_result[] = $item;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_extra_field_options':
             $obj = new \ExtraFieldOption($type);
             $columns = array('option_display_text', 'option_value', 'option_order');
             $result = \Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             /*$new_result = array();
               if (!empty($result)) {
                   foreach ($result as $item) {
                       $item['field_type']         = $obj->get_field_type_by_id($item['field_type']);
                       $item['field_changeable']   = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_visible']      = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_filter']       = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $new_result[]        = $item;
                   }
                   $result = $new_result;
               }*/
             break;
         case 'get_usergroups_teacher':
             $columns = array('name', 'users', 'actions');
             $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}");
             $options['course_id'] = $course_id;
             switch ($type) {
                 case 'not_registered':
                     $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
                     $result = $obj->get_usergroup_not_in_course($options);
                     break;
                 case 'registered':
                     $options['where'] = array(" usergroup.course_id = ? " => $course_id);
                     $result = $obj->get_usergroup_in_course($options);
                     break;
             }
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
                         $url = 'class.php?action=remove_class_from_course&id=' . $group['id'];
                         $icon = Display::return_icon('delete.png', get_lang('Remove'));
                     } else {
                         $url = 'class.php?action=add_class_to_course&id=' . $group['id'];
                         $icon = Display::return_icon('add.png', get_lang('Add'));
                     }
                     $group['actions'] = Display::url($icon, $url);
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             \ArrayClass::msort($result, $sidx);
             break;
         default:
             exit;
     }
     $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale', 'get_questions');
     //5. Creating an obj to return a json
     if (in_array($action, $allowed_actions)) {
         $response = new \stdClass();
         $response->page = $page;
         $response->total = $total_pages;
         $response->records = $count;
         if ($operation && $operation == 'excel') {
             $j = 1;
             $array = array();
             if (empty($column_names)) {
                 $column_names = $columns;
             }
             //Headers
             foreach ($column_names as $col) {
                 $array[0][] = $col;
             }
             foreach ($result as $row) {
                 foreach ($columns as $col) {
                     $array[$j][] = strip_tags($row[$col]);
                 }
                 $j++;
             }
             switch ($export_format) {
                 case 'xls':
                     Export::export_table_xls($array, 'company_report');
                     break;
                 case 'csv':
                 default:
                     Export::export_table_csv($array, 'company_report');
                     break;
             }
             exit;
         }
         $i = 0;
         if (!empty($result)) {
             foreach ($result as $row) {
                 //print_r($row);
                 // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
                 if (!isset($row['id']) || isset($row['id']) && $row['id'] == "") {
                     $response->rows[$i]['id'] = $i;
                 } else {
                     $response->rows[$i]['id'] = $row['id'];
                 }
                 $array = array();
                 foreach ($columns as $col) {
                     $array[] = isset($row[$col]) ? $row[$col] : null;
                 }
                 $response->rows[$i]['cell'] = $array;
                 $i++;
             }
         }
         return json_encode($response);
     }
 }
示例#13
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);
}
示例#14
0
 /**
  * Update the properties of this category in the database
  * @todo fix me
  */
 public function save()
 {
     $em = Database::getManager();
     $gradebookCategory = $em->getRepository('ChamiloCoreBundle:GradebookCategory')->find($this->id);
     if (empty($gradebookCategory)) {
         return false;
     }
     $gradebookCategory->setName($this->name);
     $gradebookCategory->setDescription($this->description);
     $gradebookCategory->setUserId($this->user_id);
     $gradebookCategory->setCourseCode($this->course_code);
     $gradebookCategory->setParentId($this->parent);
     $gradebookCategory->setWeight($this->weight);
     $gradebookCategory->setVisible($this->visible);
     $gradebookCategory->setCertifMinScore($this->certificate_min_score);
     $gradebookCategory->setGenerateCertificates($this->generateCertificates);
     $gradebookCategory->setGradeModelId($this->grade_model_id);
     $gradebookCategory->setIsRequirement($this->isRequirement);
     $em->merge($gradebookCategory);
     $em->flush();
     if (!empty($this->id)) {
         $parent_id = $this->get_parent_id();
         $grade_model_id = $this->get_grade_model_id();
         if ($parent_id == 0) {
             if (isset($grade_model_id) && !empty($grade_model_id) && $grade_model_id != '-1') {
                 $obj = new GradeModel();
                 $components = $obj->get_components($grade_model_id);
                 $default_weight_setting = api_get_setting('gradebook.gradebook_default_weight');
                 $default_weight = 100;
                 if (isset($default_weight_setting)) {
                     $default_weight = $default_weight_setting;
                 }
                 $final_weight = $this->get_weight();
                 if (!empty($final_weight)) {
                     $default_weight = $this->get_weight();
                 }
                 foreach ($components as $component) {
                     $gradebook = new Gradebook();
                     $params = array();
                     $params['name'] = $component['acronym'];
                     $params['description'] = $component['title'];
                     $params['user_id'] = api_get_user_id();
                     $params['parent_id'] = $this->id;
                     $params['weight'] = $component['percentage'] / 100 * $default_weight;
                     $params['session_id'] = api_get_session_id();
                     $params['course_code'] = $this->get_course_code();
                     $gradebook->save($params);
                 }
             }
         }
     }
     $gradebook = new Gradebook();
     $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false), true);
 }
/**
 * This function displays the form that is used to edit a post. This can be a new thread or a reply.
 * @param array contains all the information about the current post
 * @param array contains all the information about the current thread
 * @param array contains all info about the current forum (to check if attachments are allowed)
 * @param array contains the default values to fill the form
 * @return void
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @version february 2006, dokeos 1.8
 */
function show_edit_post_form($current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
{
    global $forum_setting;
    global $origin;
    $gradebook = Security::remove_XSS($_GET['gradebook']);
    // Initialize the object.
    $form = new FormValidator('edit_post', 'post', api_get_self() . '?forum=' . Security::remove_XSS($_GET['forum']) . '&amp;gradebook=' . $gradebook . '&amp;origin=' . $origin . '&amp;thread=' . Security::remove_XSS($_GET['thread']) . '&amp;post=' . Security::remove_XSS($_GET['post']));
    $form->addElement('header', get_lang('EditPost'));
    // Settting the form elements.
    $form->addElement('hidden', 'post_id', $current_post['post_id']);
    $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
    $form->addElement('hidden', 'id_attach', $id_attach);
    if ($current_post['post_parent_id'] == 0) {
        $form->addElement('hidden', 'is_first_post_of_thread', '1');
    }
    $form->addElement('text', 'post_title', get_lang('Title'), 'class="input_titles"');
    $form->applyFilter('post_title', 'html_filter');
    $form->addElement('html_editor', 'post_text', get_lang('Text'), null, api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Forum', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'ForumStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student'));
    $form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('advanced_settings', '<a href="javascript://" onclick="return advanced_parameters()"><span id="img_plus_and_minus">' . Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')) . '' . get_lang('AdvancedParameters') . '</span></a>');
    $form->addElement('html', '<div id="id_qualify" style="display:none">');
    if (!isset($_GET['edit'])) {
        if (Gradebook::is_active()) {
            $form->addElement('label', '<strong>' . get_lang('AlterQualifyThread') . '</strong>');
            $form->addElement('checkbox', 'thread_qualify_gradebook', '', get_lang('QualifyThreadGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
            $link_info = is_resource_in_course_gradebook(api_get_course_id(), 5, $_GET['thread'], api_get_session_id());
            if (!empty($link_info)) {
                $defaults['thread_qualify_gradebook'] = true;
                $defaults['category_id'] = $link_info['category_id'];
            } else {
                $defaults['thread_qualify_gradebook'] = false;
                $defaults['category_id'] = '';
            }
        } else {
            $form->addElement('hidden', 'thread_qualify_gradebook', false);
            $defaults['thread_qualify_gradebook'] = false;
        }
        if (!empty($defaults['thread_qualify_gradebook'])) {
            $form->addElement('html', '<div id="options_field" style="display:block">');
        } else {
            $form->addElement('html', '<div id="options_field" style="display:none">');
        }
        //Loading gradebook select
        load_gradebook_select_in_tool($form);
        $form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'), 'value="' . $current_thread['thread_qualify_max'] . '" style="width:40px"');
        $form->applyFilter('numeric_calification', 'html_filter');
        $form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'), 'value="' . $current_thread['thread_title_qualify'] . '"');
        $form->applyFilter('calification_notebook_title', 'html_filter');
        $form->addElement('text', 'weight_calification', array(get_lang('QualifyWeight'), null, ''), 'value="' . $current_thread['thread_weight'] . '" style="width:40px"');
        $form->applyFilter('weight_calification', 'html_filter');
        $form->addElement('html', '</div>');
    }
    if ($forum_setting['allow_post_notification']) {
        $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail') . ' (' . $current_post['email'] . ')');
    }
    if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $current_post['post_parent_id'] == 0) {
        // The sticky checkbox only appears when it is the first post of a thread.
        $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
        if ($current_thread['thread_sticky'] == 1) {
            $defaults['thread_sticky'] = true;
        }
    }
    $attachment_list = get_attachment($current_post['post_id']);
    $message = get_lang('AddAnAttachment');
    if (!empty($attachment_list)) {
        //$message = ;
        $form->addElement('label', get_lang('EditAnAttachment'), Display::return_icon('attachment.gif', get_lang('Attachment')) . '&nbsp;' . $attachment_list['filename'] . (!empty($attachment_list['comment']) ? '(' . $attachment_list['comment'] . ')' : ''));
        $form->addElement('checkbox', 'remove_attach', null, get_lang('DeleteAttachmentFile'));
    } else {
        // User upload
        $form->addElement('label', $message);
        $form->addElement('file', 'user_upload', get_lang('FileName'), '');
        $form->addElement('textarea', 'file_comment', get_lang('FileComment'), array('rows' => 4, 'cols' => 34));
        $form->applyFilter('file_comment', 'html_filter');
    }
    if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
        if (empty($form_values) && !isset($_POST['SubmitPost'])) {
            //edit_added_resources('forum_post', $current_post['post_id']);
        }
    }
    $form->addElement('html', '</div>');
    $form->addElement('style_submit_button', 'SubmitPost', get_lang('ModifyThread'), 'class="save"');
    // Setting the default values for the form elements.
    $defaults['post_title'] = $current_post['post_title'];
    $defaults['post_text'] = $current_post['post_text'];
    if ($current_post['post_notification'] == 1) {
        $defaults['post_notification'] = true;
    }
    if (!empty($form_values)) {
        $defaults['post_notification'] = Security::remove_XSS($form_values['post_notification']);
        $defaults['thread_sticky'] = Security::remove_XSS($form_values['thread_sticky']);
    }
    $form->setDefaults($defaults);
    // The course admin can make a thread sticky (=appears with special icon and always on top).
    $form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
    // Validation or display
    if ($form->validate()) {
        $values = $form->exportValues();
        if ($values['thread_qualify_gradebook'] == '1' && empty($values['weight_calification'])) {
            Display::display_error_message(get_lang('YouMustAssignWeightOfQualification') . '&nbsp;<a href="javascript:window.back()">' . get_lang('Back') . '</a>', false);
            return false;
        }
        return $values;
    } else {
        $form->display();
    }
}