/**
  * @param int $catId
  */
 public static function deleteAllCertificates($catId)
 {
     $certificate_list = GradebookUtils::get_list_users_certificates($catId);
     if (!empty($certificate_list)) {
         foreach ($certificate_list as $index => $value) {
             $list_certificate = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $catId);
             foreach ($list_certificate as $value_certificate) {
                 $certificate_obj = new Certificate($value_certificate['id']);
                 $certificate_obj->delete(true);
             }
         }
     }
 }
示例#2
0
 /**
  * edit attendances inside table
  * @param 	int	   attendance id
  * @param  	bool   true for adding link in gradebook or false otherwise (optional)
  * @return 	int    last id
  */
 public function attendance_edit($attendance_id, $link_to_gradebook = false)
 {
     $_course = api_get_course_info();
     $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
     $table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
     $session_id = api_get_session_id();
     $user_id = api_get_user_id();
     $attendance_id = intval($attendance_id);
     $course_code = $_course['code'];
     $course_id = $_course['real_id'];
     $title_gradebook = $this->attendance_qualify_title;
     $value_calification = 0;
     $weight_calification = floatval($this->attendance_weight);
     if (!empty($attendance_id)) {
         $params = ['name' => $this->name, 'description' => $this->description, 'attendance_qualify_title' => $title_gradebook, 'attendance_weight' => $weight_calification];
         Database::update($tbl_attendance, $params, ['c_id = ? AND id = ?' => [$course_id, $attendance_id]]);
         api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id, "AttendanceUpdated", $user_id);
         // add link to gradebook
         if ($link_to_gradebook && !empty($this->category_id)) {
             $description = '';
             $link_id = GradebookUtils::is_resource_in_course_gradebook($course_code, 7, $attendance_id, $session_id);
             if (!$link_id) {
                 GradebookUtils::add_resource_to_course_gradebook($this->category_id, $course_code, 7, $attendance_id, $title_gradebook, $weight_calification, $value_calification, $description, 1, $session_id);
             } else {
                 Database::query('UPDATE ' . $table_link . ' SET weight=' . $weight_calification . ' WHERE id=' . $link_id . '');
             }
         }
         return $attendance_id;
     }
     return null;
 }
    $url = api_get_self() . '?action=export_all_certificates' . '&' . api_get_cidReq() . '&cat_id=' . $cat_id . '&filter=' . $filterOfficialCode;
    echo Display::url(get_lang('ExportAllCertificatesToPDF'), $url, array('class' => 'btn btn-default'));
}
echo '</div>';
echo $filterForm;
if (count($certificate_list) == 0) {
    echo Display::display_warning_message(get_lang('NoResultsAvailable'));
} else {
    echo '<br /><br /><table class="data_table">';
    foreach ($certificate_list as $index => $value) {
        echo '<tr>
                <td width="100%" class="actions">' . get_lang('Student') . ' : ' . api_get_person_name($value['firstname'], $value['lastname']) . ' (' . $value['username'] . ')</td>';
        echo '</tr>';
        echo '<tr><td>
            <table class="data_table">';
        $list_certificate = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $cat_id);
        foreach ($list_certificate as $value_certificate) {
            echo '<tr>';
            echo '<td width="50%">' . get_lang('Score') . ' : ' . $value_certificate['score_certificate'] . '</td>';
            echo '<td width="30%">' . get_lang('Date') . ' : ' . api_convert_and_format_date($value_certificate['created_at']) . '</td>';
            echo '<td width="20%">';
            $url = api_get_path(WEB_PATH) . 'certificates/index.php?id=' . $value_certificate['id'];
            $certificates = Display::url(get_lang('Certificate'), $url, array('target' => '_blank', 'class' => 'btn btn-default'));
            echo $certificates;
            echo '<a onclick="return confirmation();" href="gradebook_display_certificate.php?sec_token=' . $token . '&cidReq=' . $course_code . '&action=delete&cat_id=' . $cat_id . '&certificate_id=' . $value_certificate['id'] . '">
                    ' . Display::return_icon('delete.png', get_lang('Delete')) . '
                  </a>';
            echo '</td></tr>';
        }
        echo '</table>';
        echo '</td></tr>';
// Adavanced Parameters
if (Gradebook::is_active()) {
    if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
        $form->addButtonAdvancedSettings('id_qualify');
        $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->addButtonAdvancedSettings('id_qualify');
        $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">');
    }
    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->addButtonUpdate(get_lang('Save'));
// set default values
$default['title'] = Security::remove_XSS($title);
$default['description'] = Security::remove_XSS($description, STUDENT);
$default['attendance_qualify_title'] = $attendance_qualify_title;
$default['attendance_weight'] = $attendance_weight;
$link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 7, $attendance_id, api_get_session_id());
$default['category_id'] = $link_info->getCategoryId();
$form->setDefaults($default);
$form->display();
示例#5
0
            if (!empty($diff)) {
                $weightToApply = $weight - $diff;
                $diffApplied = true;
            }
        }
        GradebookUtils::updateLinkWeight($link['id'], $link['resource_name'], $weightToApply);
    }
    foreach ($evaluations as $evaluation) {
        $weightToApply = $weight;
        if ($diffApplied == false) {
            if (!empty($diff)) {
                $weightToApply = $weight - $diff;
                $diffApplied = true;
            }
        }
        GradebookUtils::updateEvaluationWeight($evaluation['id'], $weightToApply);
    }
    header('Location:' . $currentUrl);
    exit;
}
// 	DISPLAY HEADERS AND MESSAGES
if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
    if (isset($_GET['studentoverview'])) {
        $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $my_selectcat, 'name' => get_lang('Gradebook'));
        Display::display_header(get_lang('FlatView'));
    } elseif (isset($_GET['search'])) {
        $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $my_selectcat, 'name' => get_lang('Gradebook'));
        Display::display_header(get_lang('SearchResults'));
    } else {
        $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=1', 'name' => get_lang('Gradebook'));
        $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditAllWeights'));
/**
 * This function stores the edit of a post in the forum_post table.
 *
 * @param array
 * @return void HTML
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @version february 2006, dokeos 1.8
 */
function store_edit_post($values)
{
    $threadTable = Database::get_course_table(TABLE_FORUM_THREAD);
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
    $course_id = api_get_course_int_id();
    //check if this post is the first of the thread
    // First we check if the change affects the thread and if so we commit
    // the changes (sticky and post_title=thread_title are relevant).
    $posts = getPosts($values['thread_id']);
    $first_post = null;
    if (!empty($posts) && count($posts) > 0 && isset($posts[0])) {
        $first_post = $posts[0];
    }
    if (!empty($first_post) && $first_post['post_id'] == $values['post_id']) {
        $params = ['thread_title' => $values['post_title'], 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : null, 'thread_title_qualify' => $values['calification_notebook_title'], 'thread_qualify_max' => $values['numeric_calification'], 'thread_weight' => $values['weight_calification'], 'thread_peer_qualify' => $values['thread_peer_qualify']];
        $where = ['c_id = ? AND thread_id = ?' => [$course_id, $values['thread_id']]];
        Database::update($threadTable, $params, $where);
    }
    // Update the post_title and the post_text.
    $params = ['post_title' => $values['post_title'], 'post_text' => $values['post_text'], 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : ''];
    $where = ['c_id = ? AND post_id = ?' => [$course_id, $values['post_id']]];
    Database::update($table_posts, $params, $where);
    // Update attached files
    if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
        foreach ($_POST['file_ids'] as $key => $id) {
            editAttachedFile(array('comment' => $_POST['file_comments'][$key], 'post_id' => $values['post_id']), $id);
        }
    }
    if (!empty($values['remove_attach'])) {
        delete_attachment($values['post_id']);
    }
    if (empty($values['id_attach'])) {
        add_forum_attachment_file(isset($values['file_comment']) ? $values['file_comment'] : null, $values['post_id']);
    } else {
        edit_forum_attachment_file(isset($values['file_comment']) ? $values['file_comment'] : null, $values['post_id'], $values['id_attach']);
    }
    if (api_is_course_admin() == true) {
        $ccode = api_get_course_id();
        $sid = api_get_session_id();
        $link_info = GradebookUtils::is_resource_in_course_gradebook($ccode, 5, $values['thread_id'], $sid);
        $link_id = $link_info['id'];
        $thread_qualify_gradebook = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
        if ($thread_qualify_gradebook != 1) {
            if ($link_info !== false) {
                GradebookUtils::remove_resource_from_course_gradebook($link_id);
            }
        } else {
            if ($link_info === false && !$_GET['thread']) {
                $weigthqualify = $values['weight_calification'];
                GradebookUtils::add_resource_to_course_gradebook($values['category_id'], $ccode, 5, $values['thread_id'], Database::escape_string(stripslashes($values['calification_notebook_title'])), $weigthqualify, $values['numeric_calification'], null, 0, $sid);
            }
        }
    }
    // Storing the attachments if any.
    //update_added_resources('forum_post', $values['post_id']);
    $message = get_lang('EditPostStored') . '<br />';
    $message .= get_lang('ReturnTo') . ' <a href="viewforum.php?' . api_get_cidreq() . '&forum=' . intval($_GET['forum']) . '&">
            ' . get_lang('Forum') . '</a><br />';
    $message .= get_lang('ReturnTo') . ' <a href="viewthread.php?' . api_get_cidreq() . '&forum=' . intval($_GET['forum']) . '&thread=' . $values['thread_id'] . '&post=' . intval($_GET['post']) . '">' . get_lang('Message') . '</a>';
    Session::erase('formelements');
    Session::erase('origin');
    Session::erase('breadcrumbs');
    Session::erase('addedresource');
    Session::erase('addedresourceid');
    Display::display_confirmation_message($message, false);
}
     $results = parse_xml_data($file_name);
 }
 $nr_results_added = 0;
 foreach ($results as $index => $importedresult) {
     //check username & score
     $importedresult['user_id'] = UserManager::get_user_id_from_username($importedresult['username']);
     $added = '0';
     foreach ($allresults as $allresult) {
         if ($importedresult['user_id'] == $allresult->get_user_id()) {
             if ($importedresult['score'] != $allresult->get_score()) {
                 if (!isset($values['overwrite'])) {
                     header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&import_score_error=' . $importedresult['user_id']);
                     exit;
                     break;
                 } else {
                     GradebookUtils::overwritescore($allresult->get_id(), $importedresult['score'], $eval[0]->get_max());
                     $overwritescore++;
                     $added = '1';
                 }
             } else {
                 $added = '1';
             }
         }
     }
     if ($importedresult['user_id'] == null) {
         header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&incorrectdata=');
         exit;
     }
     $userinfo = api_get_user_info($importedresult['user_id']);
     if ($userinfo['lastname'] != $importedresult['lastname'] || $userinfo['firstname'] != $importedresult['firstname'] || $userinfo['official_code'] != $importedresult['official_code']) {
         if (!isset($values['ignoreerrors'])) {
示例#8
0
    $lastname = $searchForm->getSubmitValue('lastname');
    $userList = UserManager::getUserByName($firstname, $lastname);
    if (empty($userList)) {
        Display::addFlash(Display::return_message(get_lang('NoResults'), 'warning'));
        header('Location: ' . api_get_self());
        exit;
    }
} elseif ($userId > 0) {
    $userInfo = api_get_user_info($userId);
    if (empty($userInfo)) {
        Display::addFlash(Display::return_message(get_lang('NoUser'), 'warning'));
        header('Location: ' . api_get_self());
        exit;
    }
    $courseList = GradebookUtils::getUserCertificatesInCourses($userId, false);
    $sessionList = GradebookUtils::getUserCertificatesInSessions($userId, false);
    if (empty($courseList) && empty($sessionList)) {
        Display::addFlash(Display::return_message(sprintf(get_lang('TheUserXNotYetAchievedCertificates'), $userInfo['complete_name']), 'warning'));
        header('Location: ' . api_get_self());
        exit;
    }
}
$template = new Template(get_lang('SearchCertificates'));
$template->assign('search_form', $searchForm->returnForm());
$template->assign('user_list', $userList);
$template->assign('user_info', $userInfo);
$template->assign('course_list', $courseList);
$template->assign('session_list', $sessionList);
$content = $template->fetch('default/gradebook/search.tpl');
$template->assign('header', get_lang('SearchCertificates'));
$template->assign('content', $content);
示例#9
0
 }
 // single exercise choice
 // construction of Exercise
 $objExerciseTmp = new Exercise();
 $check = Security::check_token('get');
 $exercise_action_locked = api_resource_is_locked_by_gradebook($exerciseId, LINK_EXERCISE);
 if ($objExerciseTmp->read($exerciseId)) {
     if ($check) {
         switch ($choice) {
             case 'delete':
                 // deletes an exercise
                 if ($exercise_action_locked == false) {
                     $objExerciseTmp->delete();
                     $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 1, $exerciseId, api_get_session_id());
                     if ($link_info !== false) {
                         GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
                     }
                     Display::display_confirmation_message(get_lang('ExerciseDeleted'));
                 }
                 break;
             case 'enable':
                 // enables an exercise
                 $objExerciseTmp->enable();
                 $objExerciseTmp->save();
                 api_item_property_update($courseInfo, TOOL_QUIZ, $objExerciseTmp->id, 'visible', $userId);
                 // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
                 Display::display_confirmation_message(get_lang('VisibilityChanged'));
                 break;
             case 'disable':
                 // disables an exercise
                 $objExerciseTmp->disable();
示例#10
0
 /**
  *  Generates an HTML Certificate and fills the path_certificate field in the DB
  **/
 public function generate($params = array())
 {
     // The user directory should be set
     if (empty($this->certification_user_path) && $this->force_certificate_generation == false) {
         return false;
     }
     $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false;
     $my_category = Category::load($this->certificate_data['cat_id']);
     if (isset($my_category[0]) && $my_category[0]->is_certificate_available($this->user_id)) {
         $user = api_get_user_info($this->user_id);
         $scoredisplay = ScoreDisplay::instance();
         $scorecourse = $my_category[0]->calc_score($this->user_id);
         $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable');
         // Prepare all necessary variables:
         $organization_name = api_get_setting('platform.institution');
         //$portal_name         = api_get_setting('platform.site_name');
         $stud_fn = $user['firstname'];
         $stud_ln = $user['lastname'];
         //@todo this code is not needed
         $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn . ' ' . $stud_ln, $my_category[0]->get_name(), $scorecourse_display);
         $certif_text = str_replace("\\n", "\n", $certif_text);
         //If the gradebook is related to skills we added the skills to the user
         $courseId = api_get_real_course_id();
         $sessionId = api_get_session_id();
         $skill = new Skill();
         $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id'], $courseId, $sessionId);
         if (is_dir($this->certification_user_path)) {
             if (!empty($this->certificate_data)) {
                 $new_content_html = GradebookUtils::get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), $my_category[0]->get_session_id(), false, $params['hide_print_button']);
                 if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) {
                     $name = $this->certificate_data['path_certificate'];
                     $my_path_certificate = $this->certification_user_path . basename($name);
                     if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) {
                         //Seems that the file was already generated
                         return true;
                     } else {
                         // Creating new name
                         $name = md5($this->user_id . $this->certificate_data['cat_id']) . '.html';
                         $my_path_certificate = $this->certification_user_path . $name;
                         $path_certificate = '/' . $name;
                         //Getting QR filename
                         $file_info = pathinfo($path_certificate);
                         $qr_code_filename = $this->certification_user_path . $file_info['filename'] . '_qr.png';
                         $my_new_content_html = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path . $file_info['filename'] . '_qr.png', 'QR'), $new_content_html['content']);
                         $my_new_content_html = mb_convert_encoding($my_new_content_html, 'UTF-8', api_get_system_encoding());
                         $result = @file_put_contents($my_path_certificate, $my_new_content_html);
                         if ($result) {
                             //Updating the path
                             self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate);
                             $this->certificate_data['path_certificate'] = $path_certificate;
                             if ($this->html_file_is_generated()) {
                                 if (!empty($file_info)) {
                                     $text = $this->parse_certificate_variables($new_content_html['variables']);
                                     $this->generate_qr($text, $qr_code_filename);
                                 }
                             }
                         }
                         return $result;
                     }
                 }
             }
         }
     }
     return false;
 }
示例#11
0
 /**
  * Static admin function allowing removal of a learnpath
  * @param	string	Course code
  * @param	integer	Learnpath ID
  * @param	string	Whether to delete data or keep it (default: 'keep', others: 'remove')
  * @return	boolean	True on success, false on failure (might change that to return number of elements deleted)
  */
 public function delete($course = null, $id = null, $delete = 'keep')
 {
     $course_id = api_get_course_int_id();
     // TODO: Implement a way of getting this to work when the current object is not set.
     // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
     // If an ID is specifically given and the current LP is not the same, prevent delete.
     if (!empty($id) && $id != $this->lp_id) {
         return false;
     }
     $lp = Database::get_course_table(TABLE_LP_MAIN);
     $lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $lp_view = Database::get_course_table(TABLE_LP_VIEW);
     $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
     // Delete lp item id.
     foreach ($this->items as $id => $dummy) {
         $sql = "DELETE FROM {$lp_item_view}\n                    WHERE c_id = {$course_id} AND lp_item_id = '" . $id . "'";
         Database::query($sql);
     }
     // Proposed by Christophe (nickname: clefevre)
     $sql = "DELETE FROM {$lp_item} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     Database::query($sql);
     $sql = "DELETE FROM {$lp_view} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     Database::query($sql);
     self::toggle_publish($this->lp_id, 'i');
     if ($this->type == 2 || $this->type == 3) {
         // This is a scorm learning path, delete the files as well.
         $sql = "SELECT path FROM {$lp}\n                    WHERE c_id = " . $course_id . " AND id = " . $this->lp_id;
         $res = Database::query($sql);
         if (Database::num_rows($res) > 0) {
             $row = Database::fetch_array($res);
             $path = $row['path'];
             $sql = "SELECT id FROM {$lp}\n                        WHERE c_id = " . $course_id . " AND path = '{$path}' AND id != " . $this->lp_id;
             $res = Database::query($sql);
             if (Database::num_rows($res) > 0) {
                 // Another learning path uses this directory, so don't delete it.
                 if ($this->debug > 2) {
                     error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
                 }
             } else {
                 // No other LP uses that directory, delete it.
                 $course_rel_dir = api_get_course_path() . '/scorm/';
                 // scorm dir web path starting from /courses
                 $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir;
                 // The absolute system path for this course.
                 if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty($course_scorm_dir)) {
                     if ($this->debug > 2) {
                         error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
                     }
                     // Proposed by Christophe (clefevre).
                     if (strcmp(substr($path, -2), "/.") == 0) {
                         $path = substr($path, 0, -1);
                         // Remove "." at the end.
                     }
                     //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
                     rmdirr($course_scorm_dir . $path);
                 }
             }
         }
     }
     $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $this->lp_id;
     // Delete tools
     $sql = "DELETE FROM {$tbl_tool}\n                WHERE c_id = " . $course_id . " AND (link LIKE '{$link}%' AND image='scormbuilder.gif')";
     Database::query($sql);
     $sql = "DELETE FROM {$lp} WHERE c_id = " . $course_id . " AND id = " . $this->lp_id;
     Database::query($sql);
     // Updates the display order of all lps.
     $this->update_display_order();
     api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
     $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 4, $id, api_get_session_id());
     if ($link_info !== false) {
         GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
     }
     if (api_get_setting('search_enabled') == 'true') {
         require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
         delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
     }
 }
            // Print certificates (without the common header/footer/watermark
            //  stuff) and return as one multiple-pages PDF
            $address = api_get_setting('platform.institution_address');
            $phone = api_get_setting('admin.administrator_phone');
            $address = str_replace('\\n', '<br />', $address);
            $pdf->custom_header = array('html' => "<h5 align='right'>{$address} <br />{$phone}</h5>");
            //  stuff) and return as one multiple-pages PDF
            $pdf->html_to_pdf($pdfList, null, null, false, true, true);
        }
        // Delete calc_score session data
        Session::erase('calc_score');
        break;
    case 'download':
        $userId = isset($_GET['user_id']) && $_GET['user_id'] ? $_GET['user_id'] : null;
        $cats = Category::load($cat_id, null, null, null, null, null, false);
        GradebookUtils::generateTable($userId, $cats);
        break;
}
$course_code = api_get_course_id();
$interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?', 'name' => get_lang('Gradebook'));
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('GradebookListOfStudentsReports'));
$this_section = SECTION_COURSES;
Display::display_header('');
$token = Security::get_token();
echo Display::page_header(get_lang('GradebookListOfStudentsReports'));
echo '<div class="btn-group">';
if (count($userList) > 0) {
    $url = api_get_self() . '?action=export_all&' . api_get_cidReq() . '&selectcat=' . $cat_id;
    echo Display::url(get_lang('ExportAllToPDF'), $url, array('class' => 'btn btn-default'));
}
echo '</div>';
示例#13
0
$homework = get_work_assignment_by_id($workId);
$locked = api_resource_is_locked_by_gradebook($workId, LINK_STUDENTPUBLICATION);
if (api_is_platform_admin() == false && $locked == true) {
    api_not_allowed(true);
}
$htmlHeadXtra[] = to_javascript_work();
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'work/work.php?' . api_get_cidreq(), 'name' => get_lang('StudentPublications'));
$interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
$form = new FormValidator('edit_dir', 'post', api_get_path(WEB_CODE_PATH) . 'work/edit_work.php?id=' . $workId . '&' . api_get_cidreq());
$form->addElement('header', get_lang('Edit'));
$title = !empty($workData['title']) ? $workData['title'] : basename($workData['url']);
$defaults = $workData;
$defaults['new_dir'] = Security::remove_XSS($title);
$there_is_a_end_date = false;
if (Gradebook::is_active()) {
    $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $workId);
    if (!empty($link_info)) {
        $defaults['weight'] = $link_info['weight'];
        $defaults['category_id'] = $link_info['category_id'];
        $defaults['make_calification'] = 1;
    }
} else {
    $defaults['category_id'] = '';
}
if (!empty($homework['expires_on'])) {
    $homework['expires_on'] = api_get_local_time($homework['expires_on']);
    $there_is_a_expire_date = true;
    $defaults['enableExpiryDate'] = true;
} else {
    $homework['expires_on'] = null;
    $there_is_a_expire_date = false;
示例#14
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->addHtmlEditor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
    $form->addButtonAdvancedSettings('advanced_params', get_lang('AdvancedParameters'));
    if (!empty($defaults) && (isset($defaults['enableEndDate']) || isset($defaults['enableExpiryDate']))) {
        $form->addElement('html', '<div id="advanced_params_options" style="display:block">');
    } else {
        $form->addElement('html', '<div id="advanced_params_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
    GradebookUtils::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;
}
 /**
  * This method return a graph containing information about evaluations
  * inside courses in sessions, it's used inside get_block method for
  * showing it inside dashboard interface
  * @return string  img html
  */
 public function get_evaluations_courses_in_sessions_graph()
 {
     $graphs = array();
     if (!empty($this->sessions)) {
         $session_ids = array_keys($this->sessions);
         foreach ($session_ids as $session_id) {
             $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id));
             $courses_graph = array();
             foreach ($courses_code as $course_code) {
                 $cats = Category::load(null, null, $course_code, null, null, $session_id);
                 if (isset($cats) && isset($cats[0])) {
                     $alleval = $cats[0]->get_evaluations(null, true, $course_code);
                     $alllinks = $cats[0]->get_links(null, true);
                     $users = GradebookUtils::get_all_users($alleval, $alllinks);
                     $datagen = new FlatViewDataGenerator($users, $alleval, $alllinks);
                     $evaluation_sumary = $datagen->get_evaluation_sumary_results();
                     if (!empty($evaluation_sumary)) {
                         $items = array_keys($evaluation_sumary);
                         $max = $min = $avg = array();
                         foreach ($evaluation_sumary as $evaluation) {
                             $max[] = $evaluation['max'];
                             $min[] = $evaluation['min'];
                             $avg[] = $evaluation['avg'];
                         }
                         // Dataset definition
                         $dataSet = new pData();
                         $dataSet->addPoints($min, 'Serie3');
                         $dataSet->addPoints($avg, 'Serie2');
                         $dataSet->addPoints($max, 'Serie1');
                         $dataSet->addPoints($items, 'Labels');
                         $dataSet->setSerieDescription('Serie1', get_lang('Max'));
                         $dataSet->setSerieDescription('Serie2', get_lang('Avg'));
                         $dataSet->setSerieDescription('Serie3', get_lang('Min'));
                         $dataSet->setAbscissa('Labels');
                         $dataSet->setAbscissaName(get_lang('EvaluationName'));
                         $dataSet->normalize(100, '%');
                         $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true);
                         // Cache definition
                         $cachePath = api_get_path(SYS_ARCHIVE_PATH);
                         $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
                         $chartHash = $myCache->getHash($dataSet);
                         if ($myCache->isInCache($chartHash)) {
                             $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
                             $myCache->saveFromCache($chartHash, $imgPath);
                             $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
                         } else {
                             /* Create the pChart object */
                             $widthSize = $this->bg_width;
                             $heightSize = $this->bg_height;
                             $fontSize = 8;
                             $angle = 50;
                             $myPicture = new pImage($widthSize, $heightSize, $dataSet);
                             /* Turn of Antialiasing */
                             $myPicture->Antialias = false;
                             /* Add a border to the picture */
                             $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0));
                             /* Set the default font */
                             $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10));
                             /* Do NOT Write the chart title */
                             /* Define the chart area */
                             $myPicture->setGraphArea(50, 30, $widthSize - 20, $heightSize - 100);
                             /* Draw the scale */
                             $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_MANUAL, 'ManualScale' => array('0' => array('Min' => 0, 'Max' => 100)), 'LabelRotation' => $angle);
                             $myPicture->drawScale($scaleSettings);
                             /* Turn on shadow computing */
                             $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
                             /* Draw the chart */
                             $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
                             $settings = array('DisplayValues' => true, 'DisplaySize' => $fontSize, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayOrientation' => ORIENTATION_HORIZONTAL, 'Gradient' => false, 'Surrounding' => 30, 'InnerSurrounding' => 25);
                             $myPicture->drawStackedBarChart($settings);
                             $legendSettings = array('Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER);
                             $myPicture->drawLegend($widthSize / 2, 15, $legendSettings);
                             /* Write and save into cache */
                             $myCache->writeToCache($chartHash, $myPicture);
                             $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
                             $myCache->saveFromCache($chartHash, $imgPath);
                             $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
                         }
                         if (!empty($imgPath)) {
                             $courses_graph[$course_code] = '<img src="' . $imgPath . '">';
                         }
                     }
                 }
             }
             if (!empty($courses_graph)) {
                 $graphs[$session_id] = $courses_graph;
             }
         }
     }
     return $graphs;
 }
示例#16
0
            $survey_id = intval($return['id']);
            if ($survey_id > 0) {
                $title_gradebook = '';
                // Not needed here.
                $description_gradebook = '';
                // Not needed here.
                $survey_weight = floatval($_POST['survey_weight']);
                $max_score = 1;
                $date = time();
                // TODO: Maybe time zones implementation is needed here.
                $visible = 1;
                // 1 = visible
                $link_info = GradebookUtils::is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
                $gradebook_link_id = $link_info['id'];
                if (!$gradebook_link_id) {
                    GradebookUtils::add_resource_to_course_gradebook($course_id, $gradebook_link_type, $survey_id, $title_gradebook, $survey_weight, $max_score, $description_gradebook, 1, $session_id);
                } else {
                    Database::query('UPDATE ' . $table_gradebook_link . ' SET weight=' . $survey_weight . ' WHERE id=' . $gradebook_link_id);
                }
            }
        }
    }
    Display::addFlash(Display::return_message($return['message'] == 'SurveyUpdatedSuccesfully' ? get_lang($return['message']) : $return['message'], false));
    // Redirecting to the survey page (whilst showing the return message)
    header('location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey.php?survey_id=' . $return['id'] . '&message=' . $return['message'] . '&' . api_get_cidreq());
    exit;
} else {
    // Displaying the header
    Display::display_header($tool_name);
    $form->display();
}
示例#17
0
 /**
  * Get the achieved certificates for a user in course sessions
  * @param int $userId The user id
  * @param type $includeNonPublicCertificates Whether include the non-plublic certificates
  * @return array
  */
 public static function getUserCertificatesInSessions($userId, $includeNonPublicCertificates = true)
 {
     $userId = intval($userId);
     $sessionList = [];
     $sessions = SessionManager::get_sessions_by_user($userId);
     foreach ($sessions as $session) {
         if (empty($session['courses'])) {
             continue;
         }
         $sessionCourses = SessionManager::get_course_list_by_session_id($session['session_id']);
         foreach ($sessionCourses as $course) {
             if (!$includeNonPublicCertificates) {
                 $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course['code']);
                 if (empty($allowPublicCertificates)) {
                     continue;
                 }
             }
             $courseGradebookCategory = Category::load(null, null, $course['code'], null, null, $session['session_id']);
             if (empty($courseGradebookCategory)) {
                 continue;
             }
             $courseGradebookId = $courseGradebookCategory[0]->get_id();
             $certificateInfo = GradebookUtils::get_certificate_by_user_id($courseGradebookId, $userId);
             if (empty($certificateInfo)) {
                 continue;
             }
             $sessionList[] = ['session' => $session['session_name'], 'course' => $course['title'], 'score' => $certificateInfo['score_certificate'], 'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT), 'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"];
         }
     }
     return $sessionList;
 }
示例#18
0
    $message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
}
// Locking and unlocking.
if (($my_action == 'lock' || $my_action == 'unlock') && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
}
// Deleting.
if ($my_action == 'delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
    if ($locked == false) {
        $message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
        // Delete link
        $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, intval($_GET['id']), api_get_session_id());
        $link_id = $link_info->getId();
        if ($link_info) {
            GradebookUtils::remove_resource_from_course_gradebook($link_id);
        }
    }
}
// Moving.
if ($my_action == 'move' && isset($_GET['thread']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = move_thread_form();
}
// Notification.
if ($my_action == 'notify' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_session_edit(false, true)) {
    $return_message = set_notification($_GET['content'], $_GET['id']);
    Display::display_confirmation_message($return_message, false);
}
// Student list
if ($my_action == 'liststd' && isset($_GET['content']) && isset($_GET['id']) && (api_is_allowed_to_edit(null, true) || $is_group_tutor)) {
    $active = null;
示例#19
0
 /**
  * Creates a course
  * @param   array $params columns in the main.course table
  *
  * @return  mixed  false if the course was not created, array with the course info
  */
 public static function create_course($params, $extraFields = array())
 {
     global $_configuration;
     // Check portal limits
     $access_url_id = 1;
     if (api_get_multiple_access_url()) {
         $access_url_id = api_get_current_access_url_id();
     }
     if (isset($_configuration[$access_url_id]) && is_array($_configuration[$access_url_id])) {
         if (isset($_configuration[$access_url_id]['hosting_limit_courses']) && $_configuration[$access_url_id]['hosting_limit_courses'] > 0) {
             $num = self::count_courses($access_url_id);
             if ($num >= $_configuration[$access_url_id]['hosting_limit_courses']) {
                 api_warn_hosting_contact('hosting_limit_courses');
                 return api_set_failure(get_lang('PortalCoursesLimitReached'));
             }
         }
         if (isset($_configuration[$access_url_id]['hosting_limit_active_courses']) && $_configuration[$access_url_id]['hosting_limit_active_courses'] > 0) {
             $num = self::countActiveCourses($access_url_id);
             if ($num >= $_configuration[$access_url_id]['hosting_limit_active_courses']) {
                 api_warn_hosting_contact('hosting_limit_active_courses');
                 return api_set_failure(get_lang('PortalActiveCoursesLimitReached'));
             }
         }
     }
     if (empty($params['title'])) {
         return false;
     }
     if (empty($params['wanted_code'])) {
         $params['wanted_code'] = $params['title'];
         // Check whether the requested course code has already been occupied.
         $params['wanted_code'] = CourseManager::generate_course_code(api_substr($params['title'], 0, self::MAX_COURSE_LENGTH_CODE));
     }
     // Create the course keys
     $keys = AddCourse::define_course_keys($params['wanted_code']);
     $params['exemplary_content'] = isset($params['exemplary_content']) ? $params['exemplary_content'] : false;
     if (count($keys)) {
         $params['code'] = $keys['currentCourseCode'];
         $params['visual_code'] = $keys['currentCourseId'];
         $params['directory'] = $keys['currentCourseRepository'];
         $course_info = api_get_course_info($params['code']);
         if (empty($course_info)) {
             $course_id = AddCourse::register_course($params);
             $course_info = api_get_course_info_by_id($course_id);
             if (!empty($course_info)) {
                 AddCourse::prepare_course_repository($course_info['directory'], $course_info['code']);
                 AddCourse::fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $params['exemplary_content']);
                 if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true') {
                     //Create gradebook_category for the new course and add
                     // a gradebook model for the course
                     if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') {
                         GradebookUtils::create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']);
                     }
                 }
                 // If parameter defined, copy the contents from a specific
                 // template course into this new course
                 $template = api_get_setting('course.course_creation_use_template');
                 if (!empty($template)) {
                     // Include the necessary libraries to generate a course copy
                     require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseBuilder.class.php';
                     require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseRestorer.class.php';
                     require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseSelectForm.class.php';
                     // Call the course copy object
                     $originCourse = api_get_course_info_by_id($template);
                     $originCourse['official_code'] = $originCourse['code'];
                     $cb = new CourseBuilder(null, $originCourse);
                     $course = $cb->build(null, $originCourse['code']);
                     $cr = new CourseRestorer($course);
                     $cr->set_file_option();
                     $cr->restore($course_info['id']);
                     //course_info[id] is the course.code value (I know...)
                 }
                 $params['course_code'] = $course_info['code'];
                 $params['item_id'] = $course_info['real_id'];
                 $courseFieldValue = new ExtraFieldValue('course');
                 $courseFieldValue->saveFieldValues($params);
                 return $course_info;
             }
         }
     }
     return false;
 }
示例#20
0
        Header::location($selfUrl);
    }
    $sessionList = SessionManager::getSessionsFollowedByUser($selectedStudent);
    foreach ($sessionList as $session) {
        $sessionCourseList = SessionManager::get_course_list_by_session_id($session['id']);
        foreach ($sessionCourseList as $sessionCourse) {
            $gradebookCategories = Category::load(null, null, $sessionCourse['code'], null, false, $session['id']);
            $gradebook = null;
            if (!empty($gradebookCategories)) {
                $gradebook = current($gradebookCategories);
            }
            if (!is_null($gradebook)) {
                $sessionName = $session['name'];
                $courseName = $sessionCourse['title'];
                $certificateStudent = ['fullName' => $selectedStudentInfo['complete_name'], 'sessionName' => $sessionName, 'courseName' => $courseName, 'certificates' => []];
                $studentCertificates = GradebookUtils::get_list_gradebook_certificates_by_user_id($selectedStudent, $gradebook->get_id());
                if (!is_array($studentCertificates) || empty($studentCertificates)) {
                    continue;
                }
                foreach ($studentCertificates as $certificate) {
                    $certificateStudent['certificates'][] = array('createdAt' => api_convert_and_format_date($certificate['created_at']), 'id' => $certificate['id']);
                }
                if (count($certificateStudent['certificates']) > 0) {
                    $certificateStudents[] = $certificateStudent;
                }
            }
        }
    }
}
/* View */
$template = new Template(get_lang('GradebookListOfStudentsCertificates'));
示例#21
0
    /**
     * This function stores a survey in the database.
     *
     * @param array $values
     *
     * @return array $return the type of return message that has to be displayed and the message in it
     *
     * @author Patrick Cool <*****@*****.**>, Ghent University
     * @version February 2007
     */
    public static function store_survey($values)
    {
        $_user = api_get_user_info();
        $course_id = api_get_course_int_id();
        $session_id = api_get_session_id();
        $courseCode = api_get_course_id();
        $table_survey = Database::get_course_table(TABLE_SURVEY);
        $shared_survey_id = 0;
        if (!isset($values['survey_id'])) {
            // Check if the code doesn't soon exists in this language
            $sql = 'SELECT 1 FROM ' . $table_survey . '
			        WHERE
			            c_id = ' . $course_id . ' AND
			            code="' . Database::escape_string($values['survey_code']) . '" AND
			            lang="' . Database::escape_string($values['survey_language']) . '"';
            $rs = Database::query($sql);
            if (Database::num_rows($rs) > 0) {
                Display::addFlash(Display::return_message(get_lang('ThisSurveyCodeSoonExistsInThisLanguage'), 'error'));
                $return['type'] = 'error';
                $return['id'] = isset($values['survey_id']) ? $values['survey_id'] : 0;
                return $return;
            }
            if (!isset($values['anonymous'])) {
                $values['anonymous'] = 0;
            }
            $values['anonymous'] = intval($values['anonymous']);
            $additional['columns'] = '';
            $extraParams = [];
            if ($values['anonymous'] == 0) {
                // Input_name_list
                $values['show_form_profile'] = isset($values['show_form_profile']) ? $values['show_form_profile'] : 0;
                $extraParams['show_form_profile'] = $values['show_form_profile'];
                if ($values['show_form_profile'] == 1) {
                    // Input_name_list
                    $fields = explode(',', $values['input_name_list']);
                    $field_values = '';
                    foreach ($fields as &$field) {
                        if ($field != '') {
                            if ($values[$field] == '') {
                                $values[$field] = 0;
                            }
                            $field_values .= $field . ':' . $values[$field] . '@';
                        }
                    }
                    $extraParams['form_fields'] = $field_values;
                } else {
                    $extraParams['form_fields'] = '';
                }
            } else {
                // Input_name_list
                $extraParams['show_form_profile'] = 0;
                $extraParams['form_fields'] = '';
            }
            if ($values['survey_type'] == 1) {
                $extraParams['survey_type'] = 1;
                $extraParams['shuffle'] = $values['shuffle'];
                $extraParams['one_question_per_page'] = $values['one_question_per_page'];
                $extraParams['parent_id'] = $values['parent_id'];
                // Logic for versioning surveys
                if (!empty($values['parent_id'])) {
                    $versionValue = '';
                    $sql = 'SELECT survey_version
                            FROM ' . $table_survey . '
					        WHERE
					            c_id = ' . $course_id . ' AND
					            parent_id = ' . intval($values['parent_id']) . '
                            ORDER BY survey_version DESC
                            LIMIT 1';
                    $rs = Database::query($sql);
                    if (Database::num_rows($rs) === 0) {
                        $sql = 'SELECT survey_version FROM ' . $table_survey . '
						        WHERE
						            c_id = ' . $course_id . ' AND
						            survey_id = ' . intval($values['parent_id']);
                        $rs = Database::query($sql);
                        $getversion = Database::fetch_array($rs, 'ASSOC');
                        if (empty($getversion['survey_version'])) {
                            $versionValue = ++$getversion['survey_version'];
                        } else {
                            $versionValue = $getversion['survey_version'];
                        }
                    } else {
                        $row = Database::fetch_array($rs, 'ASSOC');
                        $pos = api_strpos($row['survey_version']);
                        if ($pos === false) {
                            $row['survey_version'] = $row['survey_version'] + 1;
                            $versionValue = $row['survey_version'];
                        } else {
                            $getlast = explode('\\.', $row['survey_version']);
                            $lastversion = array_pop($getlast);
                            $lastversion = $lastversion + 1;
                            $add = implode('.', $getlast);
                            if ($add != '') {
                                $insertnewversion = $add . '.' . $lastversion;
                            } else {
                                $insertnewversion = $lastversion;
                            }
                            $versionValue = $insertnewversion;
                        }
                    }
                    $extraParams['survey_version'] = $versionValue;
                }
            }
            $params = ['c_id' => $course_id, 'code' => strtolower(CourseManager::generate_course_code($values['survey_code'])), 'title' => $values['survey_title'], 'subtitle' => $values['survey_subtitle'], 'author' => $_user['user_id'], 'lang' => $values['survey_language'], 'avail_from' => $values['start_date'], 'avail_till' => $values['end_date'], 'is_shared' => $shared_survey_id, 'template' => 'template', 'intro' => $values['survey_introduction'], 'surveythanks' => $values['survey_thanks'], 'creation_date' => api_get_utc_datetime(), 'anonymous' => $values['anonymous'], 'session_id' => api_get_session_id(), 'visible_results' => $values['visible_results']];
            $params = array_merge($params, $extraParams);
            $survey_id = Database::insert($table_survey, $params);
            if ($survey_id > 0) {
                $sql = "UPDATE {$table_survey} SET survey_id = {$survey_id}\n                        WHERE iid = {$survey_id}";
                Database::query($sql);
                // Insert into item_property
                api_item_property_update(api_get_course_info(), TOOL_SURVEY, $survey_id, 'SurveyAdded', api_get_user_id());
            }
            if ($values['survey_type'] == 1 && !empty($values['parent_id'])) {
                SurveyManager::copy_survey($values['parent_id'], $survey_id);
            }
            Display::addFlash(Display::return_message(get_lang('SurveyCreatedSuccesfully'), 'success'));
            $return['id'] = $survey_id;
        } else {
            // Check whether the code doesn't soon exists in this language
            $sql = 'SELECT 1 FROM ' . $table_survey . '
			        WHERE
			            c_id = ' . $course_id . ' AND
			            code = "' . Database::escape_string($values['survey_code']) . '" AND
			            lang = "' . Database::escape_string($values['survey_language']) . '" AND
			            survey_id !=' . intval($values['survey_id']);
            $rs = Database::query($sql);
            if (Database::num_rows($rs) > 0) {
                Display::addFlash(Display::return_message(get_lang('ThisSurveyCodeSoonExistsInThisLanguage'), 'error'));
                $return['type'] = 'error';
                $return['id'] = isset($values['survey_id']) ? $values['survey_id'] : 0;
                return $return;
            }
            if (!isset($values['anonymous']) || isset($values['anonymous']) && $values['anonymous'] == '') {
                $values['anonymous'] = 0;
            }
            $values['shuffle'] = isset($values['shuffle']) ? $values['shuffle'] : null;
            $values['one_question_per_page'] = isset($values['one_question_per_page']) ? $values['one_question_per_page'] : null;
            $values['show_form_profile'] = isset($values['show_form_profile']) ? $values['show_form_profile'] : null;
            $extraParams = [];
            $extraParams['shuffle'] = $values['shuffle'];
            $extraParams['one_question_per_page'] = $values['one_question_per_page'];
            $extraParams['shuffle'] = $values['shuffle'];
            if ($values['anonymous'] == 0) {
                $extraParams['show_form_profile'] = $values['show_form_profile'];
                if ($values['show_form_profile'] == 1) {
                    $fields = explode(',', $values['input_name_list']);
                    $field_values = '';
                    foreach ($fields as &$field) {
                        if ($field != '') {
                            if (!isset($values[$field]) || isset($values[$field]) && $values[$field] == '') {
                                $values[$field] = 0;
                            }
                            $field_values .= $field . ':' . $values[$field] . '@';
                        }
                    }
                    $extraParams['form_fields'] = $field_values;
                } else {
                    $extraParams['form_fields'] = '';
                }
            } else {
                $extraParams['show_form_profile'] = 0;
                $extraParams['form_fields'] = '';
            }
            $params = ['title' => $values['survey_title'], 'subtitle' => $values['survey_subtitle'], 'author' => $_user['user_id'], 'lang' => $values['survey_language'], 'avail_from' => $values['start_date'], 'avail_till' => $values['end_date'], 'is_shared' => $shared_survey_id, 'template' => 'template', 'intro' => $values['survey_introduction'], 'surveythanks' => $values['survey_thanks'], 'anonymous' => $values['anonymous'], 'session_id' => api_get_session_id(), 'visible_results' => $values['visible_results']];
            $params = array_merge($params, $extraParams);
            Database::update($table_survey, $params, ['c_id = ? AND survey_id = ?' => [$course_id, $values['survey_id']]]);
            // Update into item_property (update)
            api_item_property_update(api_get_course_info(), TOOL_SURVEY, $values['survey_id'], 'SurveyUpdated', api_get_user_id());
            Display::addFlash(Display::return_message(get_lang('SurveyUpdatedSuccesfully'), 'confirmation'));
            $return['id'] = $values['survey_id'];
        }
        $survey_id = intval($return['id']);
        // Gradebook
        $gradebook_option = false;
        if (isset($values['survey_qualify_gradebook'])) {
            $gradebook_option = $values['survey_qualify_gradebook'] > 0;
        }
        $gradebook_link_type = 8;
        $link_info = GradebookUtils::is_resource_in_course_gradebook($courseCode, $gradebook_link_type, $survey_id, $session_id);
        $gradebook_link_id = $link_info ? $link_info->getId() : false;
        if ($gradebook_option) {
            if ($survey_id > 0) {
                $title_gradebook = '';
                // Not needed here.
                $description_gradebook = '';
                // Not needed here.
                $survey_weight = floatval($_POST['survey_weight']);
                $max_score = 1;
                if (!$gradebook_link_id) {
                    GradebookUtils::add_resource_to_course_gradebook($values['category_id'], $courseCode, $gradebook_link_type, $survey_id, $title_gradebook, $survey_weight, $max_score, $description_gradebook, 1, $session_id);
                } else {
                    GradebookUtils::update_resource_from_course_gradebook($gradebook_link_id, $courseCode, $survey_weight);
                }
            }
        } else {
            // Delete everything of the gradebook for this $linkId
            GradebookUtils::remove_resource_from_course_gradebook($gradebook_link_id);
            //comenting this line to correctly return the function msg
            //exit;
        }
        return $return;
    }
示例#22
0
 /**
  * @param $item
  * @return string
  */
 private function build_type_column($item)
 {
     return GradebookUtils::build_type_icon_tag($item->get_icon_name());
 }
示例#23
0
    /**
     * Builds a result form containing inputs for all students with a given course_code
     */
    protected function build_result_add_form()
    {
        $renderer =& $this->defaultRenderer();
        $renderer->setFormTemplate('<form{attributes}>
		      <table class="data_table">
              {content}
		      </table>
		   </form>');
        $tblusers = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code());
        $nr_users = 0;
        //extra field for check on maxvalue
        $this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max());
        $this->addElement('hidden', 'minvalue', 0);
        $this->addElement('header', get_lang('AddResult'));
        if (api_is_western_name_order()) {
            $renderer->setHeaderTemplate('<tr>
                   <th>' . get_lang('OfficialCode') . '</th>
                  <th>' . get_lang('UserName') . '</th>
                  <th>' . get_lang('FirstName') . '</th>
                  <th>' . get_lang('LastName') . '</th>
                  <th>' . get_lang('Qualify') . '</th>
               </tr>');
        } else {
            $renderer->setHeaderTemplate('<tr>
                   <th>' . get_lang('OfficialCode') . '</th>
                  <th>' . get_lang('UserName') . '</th>
                  <th>' . get_lang('LastName') . '</th>
                  <th>' . get_lang('FirstName') . '</th>
                  <th>' . get_lang('Qualify') . '</th>
               </tr>');
        }
        $firstUser = true;
        foreach ($tblusers as $user) {
            $element_name = 'score[' . $user[0] . ']';
            $scoreColumnProperties = array('maxlength' => 5);
            if ($firstUser) {
                $scoreColumnProperties['autofocus'] = '';
                $firstUser = false;
            }
            //user_id, user.username, lastname, firstname
            $this->addText($element_name, $this->build_stud_label($user[0], $user[1], $user[2], $user[3]), false, $scoreColumnProperties);
            $this->addRule($element_name, get_lang('OnlyNumbers'), 'numeric');
            $this->addRule(array($element_name, 'maxvalue'), get_lang('OverMax'), 'compare', '<=');
            $this->addRule(array($element_name, 'minvalue'), get_lang('UnderMin'), 'compare', '>=');
            if (api_is_western_name_order()) {
                $user_info = '<td align="left" >' . $user[3] . '</td>';
                $user_info .= '<td align="left" >' . $user[2] . '</td>';
            } else {
                $user_info = '<td align="left" >' . $user[2] . '</td>';
                $user_info .= '<td align="left" >' . $user[3] . '</td>';
            }
            $nr_users++;
            $template = '<tr>
		      <td align="left" >' . $user[4] . '</td>
		      <td align="left" >' . $user[1] . '</td>
		      ' . $user_info . '
		       <td align="left">{element} / ' . $this->evaluation_object->get_max() . '
		         <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
		      </td>
            </tr>';
            $renderer->setElementTemplate($template, $element_name);
        }
        $this->addElement('hidden', 'nr_users', $nr_users);
        $this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id());
        $this->addButtonSave(get_lang('AddResult'), 'submit');
        $template_submit = '<tr>
                <td colspan="4" ></td>
                <td >
                {element}
                    <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
                </td>
            </tr>';
        $renderer->setElementTemplate($template_submit, 'submit');
    }
示例#24
0
echo '<h1><a href="viewforum.php?&origin=' . $origin . '&forum=' . $current_forum['forum_id'] . '" ' . class_visible_invisible($current_forum['visibility']) . '>' . prepare4display($current_forum['forum_title']) . '</a></h1>';
echo '<p class="forum_description">' . prepare4display($current_forum['forum_comment']) . '</p>';
echo '</div>';
/* End new display forum */
// Set forum attachment data into $_SESSION
getAttachedFiles($current_forum['forum_id'], $current_thread['thread_id'], $current_post['post_id']);
$values = show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '');
if (!empty($values) and isset($_POST['SubmitPost'])) {
    store_edit_post($values);
    $option_chek = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
    // values 1 or 0
    if (1 == $option_chek) {
        $id = $values['thread_id'];
        $title_gradebook = Security::remove_XSS(stripslashes($values['calification_notebook_title']));
        $value_calification = $values['numeric_calification'];
        $weight_calification = $values['weight_calification'];
        $description = '';
        $session_id = api_get_session_id();
        $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, $id, $session_id);
        $link_id = $link_info['id'];
        if (!$link_info) {
            GradebookUtils::add_resource_to_course_gradebook($values['category_id'], api_get_course_id(), 5, $id, $title_gradebook, $weight_calification, $value_calification, $description, 1, api_get_session_id());
        } else {
            Database::query('UPDATE ' . $table_link . ' SET weight=' . $weight_calification . ' WHERE id=' . $link_id . '');
        }
    }
}
// Footer
if (isset($origin) && $origin != 'learnpath') {
    Display::display_footer();
}
示例#25
0
<?php

/* For licensing terms, see /license.txt */
/**
 * Script
 * @package chamilo.gradebook
 */
//$cidReset = true;
require_once '../inc/global.inc.php';
api_block_anonymous_users();
GradebookUtils::block_students();
$tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
//selected name of database
$course_id = GradebookUtils::get_course_id_by_link_id($_GET['editlink']);
$tbl_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$linkarray = LinkFactory::load($_GET['editlink']);
$link = $linkarray[0];
if ($link->is_locked() && !api_is_platform_admin()) {
    api_not_allowed();
}
$linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
$linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']) : '';
$session_id = api_get_session_id();
if ($session_id == 0) {
    $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
    //already init
} else {
    $cats = Category::load_session_categories(null, $session_id);
}
 /**
  * @param $item
  * @return null|string
  */
 private function build_edit_column($item)
 {
     switch ($item->get_item_type()) {
         // category
         case 'C':
             return GradebookUtils::build_edit_icons_cat($item, $this->currentcat);
             // evaluation
         // evaluation
         case 'E':
             return GradebookUtils::build_edit_icons_eval($item, $this->currentcat->get_id());
             // link
         // link
         case 'L':
             return GradebookUtils::build_edit_icons_link($item, $this->currentcat->get_id());
     }
 }
示例#27
0
}
if (isset($_GET['print'])) {
    $printable_data = GradebookUtils::get_printable_data($cat[0], $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
    echo print_table($printable_data[1], $printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
    exit;
}
if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
    if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
        $user_id = null;
        if (empty($_SESSION['export_user_fields'])) {
            $_SESSION['export_user_fields'] = false;
        }
        if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
            $user_id = api_get_user_id();
        }
        $printable_data = GradebookUtils::get_printable_data($cat[0], $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
        switch ($_GET['export_format']) {
            case 'xls':
                $export = new GradeBookResult();
                $export->exportCompleteReportXLS($printable_data);
                break;
            case 'doc':
                $export = new GradeBookResult();
                $export->exportCompleteReportDOC($printable_data);
                exit;
                break;
            case 'csv':
            default:
                $export = new GradeBookResult();
                $export->exportCompleteReportCSV($printable_data);
                exit;
$visibleResults = array(SURVEY_VISIBLE_TUTOR => get_lang('Coach'), SURVEY_VISIBLE_TUTOR_STUDENT => get_lang('CoachAndStudent'), SURVEY_VISIBLE_PUBLIC => get_lang('Everyone'));
$form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults);
//$defaults['visible_results'] = 0;
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
// Additional Parameters
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
if (Gradebook::is_active()) {
    // An option: Qualify the fact that survey has been answered in the gradebook
    $form->addElement('checkbox', 'survey_qualify_gradebook', null, get_lang('QualifyInGradebook'), 'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"');
    $form->addElement('html', '<div id="gradebook_options"' . ($gradebook_link_id ? '' : ' style="display:none"') . '>');
    $form->addElement('text', 'survey_weight', get_lang('QualifyWeight'), 'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"');
    $form->applyFilter('survey_weight', 'html_filter');
    // Loading Gradebook select
    GradebookUtils::load_gradebook_select_in_tool($form);
    if ($_GET['action'] == 'edit') {
        $element = $form->getElement('category_id');
        $element->freeze();
    }
    $form->addElement('html', '</div>');
}
// Personality/Conditional Test Options
$surveytypes[0] = get_lang('Normal');
$surveytypes[1] = get_lang('Conditional');
if ($_GET['action'] == 'add') {
    $form->addElement('hidden', 'survey_type', 0);
    $survey_tree = new SurveyTree();
    $list_surveys = $survey_tree->createList($survey_tree->surveylist);
    $list_surveys[0] = '';
    $form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
示例#29
0
if ($course_to_crsind && !isset($_GET['confirm'])) {
    GradebookUtils::block_students();
    if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
        die('Error: movecat or moveeval not defined');
    }
    $button = '<form name="confirm"
					 method="post"
					 action="' . api_get_self() . '?confirm=' . (isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat']) : '&moveeval=' . Security::remove_XSS($_GET['moveeval'])) . '&selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&targetcat=' . Security::remove_XSS($_GET['targetcat']) . '">
			   <input type="submit" value="' . '  ' . get_lang('Ok') . '  ' . '">
			   </form>';
    $warning_message = get_lang('MoveWarning') . '<br><br>' . $button;
    $filter_warning_msg = false;
}
//actions on the sortabletable
if (isset($_POST['action'])) {
    GradebookUtils::block_students();
    $number_of_selected_items = count($_POST['id']);
    if ($number_of_selected_items == '0') {
        $warning_message = get_lang('NoItemsSelected');
        $filter_warning_msg = false;
    } else {
        switch ($_POST['action']) {
            case 'deleted':
                $number_of_deleted_categories = 0;
                $number_of_deleted_evaluations = 0;
                $number_of_deleted_links = 0;
                foreach ($_POST['id'] as $indexstr) {
                    if (api_substr($indexstr, 0, 4) == 'CATE') {
                        $cats = Category::load(api_substr($indexstr, 4));
                        if ($cats[0] != null) {
                            $cats[0]->delete_all();
示例#30
0
 }
 // single exercise choice
 // construction of Exercise
 $objExerciseTmp = new Exercise();
 $check = Security::check_token('get');
 $exercise_action_locked = api_resource_is_locked_by_gradebook($exerciseId, LINK_EXERCISE);
 if ($objExerciseTmp->read($exerciseId)) {
     if ($check) {
         switch ($choice) {
             case 'delete':
                 // deletes an exercise
                 if ($exercise_action_locked == false) {
                     $objExerciseTmp->delete();
                     $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 1, $exerciseId, api_get_session_id());
                     if ($link_info) {
                         GradebookUtils::remove_resource_from_course_gradebook($link_info->getId());
                     }
                     Display::display_confirmation_message(get_lang('ExerciseDeleted'));
                 }
                 break;
             case 'enable':
                 // enables an exercise
                 if (empty($sessionId)) {
                     $objExerciseTmp->enable();
                     $objExerciseTmp->save();
                 } else {
                     if (!empty($objExerciseTmp->sessionId)) {
                         $objExerciseTmp->enable();
                         $objExerciseTmp->save();
                     }
                 }