function render()
 {
     switch (@$_GET["type"]) {
         case 'Content':
             $this->type = 'Content';
             break;
         case 'Default':
         default:
             $this->type = 'Default';
     }
     if (@$_GET['a'] == "edit" && !empty($_GET['cat_id'])) {
         $edit_cat = new Category();
         $edit_cat->category_id = $_GET['cat_id'];
         $edit_cat->load();
         $this->edit_title = $edit_cat->name;
         $this->edit_desc = $edit_cat->description;
         $this->cat_id = $edit_cat->category_id;
         $this->type = $edit_cat->type;
         $parent_id = $edit_cat->find_parent($edit_cat->category_id);
         $this->parent_id = $parent_id ? $parent_id : 0;
         if ($this->parent_id) {
             $edit_cat->category_id = $this->parent_id;
             $edit_cat->load();
             $this->parent_name = $edit_cat->name;
         } else {
             $this->parent_name = '';
         }
     }
     $this->categories = Category::build_all_category_list('', '', '', $this->type);
     $category = Category::build_root_list(NULL, $this->type);
     if (is_array($category)) {
         foreach ($category as $catg) {
             $this->get_childs($catg);
         }
     }
     $this->inner_HTML = $this->generate_inner_html();
     $content = parent::render();
     return $content;
 }
 public static function all()
 {
     $aCategories = [];
     $oCon = new Connection();
     $sSQL = 'SELECT CategoryID FROM tbcategory WHERE Active=1';
     $oResultSet = $oCon->query($sSQL);
     while ($aRow = $oCon->fetchArray($oResultSet)) {
         $iCategoryID = $aRow['CategoryID'];
         $oCategory = new Category();
         $oCategory->load($iCategoryID);
         $aCategories[] = $oCategory;
     }
     $oCon->close();
     return $aCategories;
 }
 /**
  * Constructor
  * To add link, define category_object and link_type
  * To edit link, define link_object
  */
 function LinkAddEditForm($form_type, $category_object, $link_type, $link_object, $form_name, $action = null)
 {
     parent::__construct($form_name, 'post', $action);
     // set or create link object
     if (isset($link_object)) {
         $link = $link_object;
     } elseif (isset($link_type) && isset($category_object)) {
         $link = LinkFactory::create($link_type);
         $link->set_course_code(api_get_course_id());
     } else {
         die('LinkAddEditForm error: define link_type/category_object or link_object');
     }
     $defaults = array();
     $this->addElement('hidden', 'zero', 0);
     if (!empty($_GET['editlink'])) {
         $this->addElement('header', '', get_lang('EditLink'));
     }
     // ELEMENT: name
     if ($form_type == self::TYPE_ADD || $link->is_allowed_to_change_name()) {
         if ($link->needs_name_and_description()) {
             $this->add_textfield('name', get_lang('Name'), true, array('size' => '40', 'maxlength' => '40'));
         } else {
             $select = $this->addElement('select', 'select_link', get_lang('ChooseItem'));
             foreach ($link->get_all_links() as $newlink) {
                 $select->addoption($newlink[1], $newlink[0]);
             }
         }
     } else {
         $this->addElement('label', get_lang('Name'), '<span class="freeze">' . $link->get_name() . ' [' . $link->get_type_name() . ']</span>');
         $this->addElement('hidden', 'name_link', $link->get_name(), array('id' => 'name_link'));
     }
     if (count($category_object) == 1) {
         $this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
     } else {
         $select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
         $this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero');
         $default_weight = 0;
         if (!empty($category_object)) {
             foreach ($category_object as $my_cat) {
                 if ($my_cat->get_course_code() == api_get_course_id()) {
                     $grade_model_id = $my_cat->get_grade_model_id();
                     if (empty($grade_model_id)) {
                         if ($my_cat->get_parent_id() == 0) {
                             $default_weight = $my_cat->get_weight();
                             $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
                         } else {
                             $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
                         }
                     } else {
                         $select_gradebook->addoption(get_lang('Select'), 0);
                     }
                     if ($link->get_category_id() == $my_cat->get_id()) {
                         $default_weight = $my_cat->get_weight();
                     }
                 }
             }
         }
     }
     $this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. ' . $category_object[0]->get_weight() . '] '), true, array('size' => '4', 'maxlength' => '5', 'class' => 'span1'));
     $this->addElement('hidden', 'weight');
     /*
     
     		// ELEMENT: weight
             $this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array (
                 'size' => '4',
                 'maxlength' => '5',
                 'class' => 'span1'
             ));*/
     $this->addRule('weight_mask', get_lang('OnlyNumbers'), 'numeric');
     $this->addRule(array('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     if ($form_type == self::TYPE_EDIT) {
         $parent_cat = Category::load($link->get_category_id());
         if ($parent_cat[0]->get_parent_id() == 0) {
             $values['weight'] = $link->get_weight();
         } else {
             $cat = Category::load($parent_cat[0]->get_parent_id());
             //$global_weight = $cat[0]->get_weight();
             //$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
             //$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight;
             //$values['weight'] = $weight;
             $values['weight'] = $link->get_weight();
         }
         $defaults['weight_mask'] = $values['weight'];
         $defaults['select_gradebook'] = $link->get_category_id();
     }
     // ELEMENT: max
     if ($link->needs_max()) {
         if ($form_type == self::TYPE_EDIT && $link->has_results()) {
             $this->add_textfield('max', get_lang('QualificationNumeric'), false, array('size' => '4', 'maxlength' => '5', 'disabled' => 'disabled'));
         } else {
             $this->add_textfield('max', get_lang('QualificationNumeric'), true, array('size' => '4', 'maxlength' => '5'));
             $this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
             $this->addRule(array('max', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
         }
         if ($form_type == self::TYPE_EDIT) {
             $defaults['max'] = $link->get_max();
         }
     }
     // ELEMENT: date
     //$this->add_datepicker('date',get_lang('Date'));
     //$defaults['date'] = ($form_type == self :: TYPE_EDIT ? $link->get_date() : time());
     // ELEMENT: description
     if ($link->needs_name_and_description()) {
         $this->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3', 'cols' => '34'));
         if ($form_type == self::TYPE_EDIT) {
             $defaults['description'] = $link->get_description();
         }
     }
     // ELEMENT: visible
     $visible = $form_type == self::TYPE_EDIT && $link->is_visible() ? '1' : '0';
     $this->addElement('checkbox', 'visible', null, get_lang('Visible'), $visible);
     if ($form_type == self::TYPE_EDIT) {
         $defaults['visible'] = $link->is_visible();
     }
     // ELEMENT: add results
     if ($form_type == self::TYPE_ADD && $link->needs_results()) {
         $this->addElement('checkbox', 'addresult', get_lang('AddResult'));
     }
     // submit button
     if ($form_type == self::TYPE_ADD) {
         $this->addElement('style_submit_button', 'submit', get_lang('CreateLink'), 'class="save"');
     } else {
         $this->addElement('style_submit_button', 'submit', get_lang('LinkMod'), 'class="save"');
     }
     if ($form_type == self::TYPE_ADD) {
         $setting = api_get_setting('tool_visible_by_default_at_creation');
         $visibility_default = 1;
         if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
             $visibility_default = 0;
         }
         $defaults['visible'] = $visibility_default;
     }
     // set default values
     $this->setDefaults($defaults);
 }
 /**
  * Get actual array data
  * @return array 2-dimensional array - each array contains the elements:
  * 0: user id
  * 1: user lastname
  * 2: user firstname
  * 3+: evaluation/link scores
  */
 public function get_data($users_sorting = 0, $users_start = 0, $users_count = null, $items_start = 0, $items_count = null, $ignore_score_color = false, $show_all = false)
 {
     // do some checks on users/items counts, redefine if invalid values
     if (!isset($users_count)) {
         $users_count = count($this->users) - $users_start;
     }
     if ($users_count < 0) {
         $users_count = 0;
     }
     if (!isset($items_count)) {
         $items_count = count($this->evals) + count($this->links) - $items_start;
     }
     if ($items_count < 0) {
         $items_count = 0;
     }
     // copy users to a new array that we will sort
     // TODO - needed ?
     $userTable = array();
     foreach ($this->users as $user) {
         $userTable[] = $user;
     }
     // sort users array
     if ($users_sorting & self::FVDG_SORT_LASTNAME) {
         usort($userTable, array('FlatViewDataGenerator', 'sort_by_last_name'));
     } elseif ($users_sorting & self::FVDG_SORT_FIRSTNAME) {
         usort($userTable, array('FlatViewDataGenerator', 'sort_by_first_name'));
     }
     if ($users_sorting & self::FVDG_SORT_DESC) {
         $userTable = array_reverse($userTable);
     }
     // select the requested users
     $selected_users = array_slice($userTable, $users_start, $users_count);
     // generate actual data array
     $scoredisplay = ScoreDisplay::instance();
     $data = array();
     $displaytype = SCORE_DIV;
     if ($ignore_score_color) {
         $displaytype |= SCORE_IGNORE_SPLIT;
     }
     //@todo move these in a function
     $sum_categories_weight_array = array();
     $mainCategoryId = null;
     $mainCourseCategory = $this->getMainCourseCategory();
     if (!empty($mainCourseCategory)) {
         $mainCategoryId = $mainCourseCategory->get_id();
     }
     if (isset($this->category) && !empty($this->category)) {
         $categories = Category::load(null, null, null, $this->category->get_id());
         if (!empty($categories)) {
             foreach ($categories as $category) {
                 $sum_categories_weight_array[$category->get_id()] = $category->get_weight();
             }
         } else {
             $sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
         }
     }
     $parent_id = $this->category->get_parent_id();
     if ($parent_id == 0 or $this->params['only_subcat'] == $this->category->get_id()) {
         $main_weight = $this->category->get_weight();
         $grade_model_id = $this->category->get_grade_model_id();
     } else {
         $main_cat = Category::load($parent_id, null, null);
         $main_weight = $main_cat[0]->get_weight();
         $grade_model_id = $main_cat[0]->get_grade_model_id();
     }
     $use_grade_model = true;
     if (empty($grade_model_id) || $grade_model_id == -1) {
         $use_grade_model = false;
     }
     $export_to_pdf = false;
     if (isset($this->params['export_pdf']) && $this->params['export_pdf']) {
         $export_to_pdf = true;
     }
     foreach ($selected_users as $user) {
         $row = array();
         if ($export_to_pdf) {
             $row['user_id'] = $user_id = $user[0];
             //user id
         } else {
             $row[] = $user_id = $user[0];
             //user id
         }
         if (isset($this->params['show_official_code']) && $this->params['show_official_code']) {
             if ($export_to_pdf) {
                 $row['official_code'] = $user[4];
                 //official code
             } else {
                 $row[] = $user[4];
                 //official code
             }
         }
         if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) {
             if ($export_to_pdf) {
                 $row['name'] = api_get_person_name($user[3], $user[2]);
                 //last name
             } else {
                 $row[] = api_get_person_name($user[3], $user[2]);
                 //last name
             }
         } else {
             if ($export_to_pdf) {
                 if (api_is_western_name_order()) {
                     $row['firstname'] = $user[3];
                     $row['lastname'] = $user[2];
                 } else {
                     $row['lastname'] = $user[2];
                     $row['firstname'] = $user[3];
                 }
             } else {
                 if (api_is_western_name_order()) {
                     $row[] = $user[3];
                     //first name
                     $row[] = $user[2];
                     //last name
                 } else {
                     $row[] = $user[2];
                     //last name
                     $row[] = $user[3];
                     //first name
                 }
             }
         }
         $item_value = 0;
         $item_value_total = 0;
         $item_total = 0;
         $convert_using_the_global_weight = true;
         $course_code = api_get_course_id();
         $session_id = api_get_session_id();
         $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id');
         $evaluationsAdded = array();
         if ($parent_id == 0 && !empty($allcat)) {
             foreach ($allcat as $sub_cat) {
                 $score = $sub_cat->calc_score($user_id);
                 $real_score = $score;
                 $divide = $score[1] == 0 ? 1 : $score[1];
                 $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
                 $item_value = $score[0] / $divide * $main_weight;
                 //Fixing total when using one or multiple gradebooks
                 $percentage = $sub_cat->get_weight() / $sub_cat_percentage * $sub_cat_percentage / $this->category->get_weight();
                 $item_value = $percentage * $item_value;
                 $item_total += $sub_cat->get_weight();
                 /*
                                     if ($convert_using_the_global_weight) {                                             
                                         $score[0] = $score[0]/$main_weight*$sub_cat->get_weight();                        
                                         $score[1] = $main_weight ;
                                     }                    
                 */
                 if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') {
                     //if (true) {
                     $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE);
                     $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
                     $temp_score = Display::tip($real_score, $temp_score);
                 } else {
                     $real_score = $scoredisplay->display_score($real_score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
                     $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
                     $temp_score = Display::tip($temp_score, $real_score);
                 }
                 if (!isset($this->params['only_total_category']) || isset($this->params['only_total_category']) && $this->params['only_total_category'] == false) {
                     if (!$show_all) {
                         $row[] = $temp_score . ' ';
                     } else {
                         $row[] = $temp_score;
                     }
                 }
                 $item_value_total += $item_value;
             }
             if ($convert_using_the_global_weight) {
                 //$item_total = $main_weight;
             }
         } else {
             $result = $this->parseEvaluations($user_id, $sum_categories_weight_array, $items_count, $items_start, $show_all, $row);
             $item_total += $result['item_total'];
             $item_value_total += $result['item_value_total'];
             $evaluationsAdded = $result['evaluations_added'];
             $item_total = $main_weight;
         }
         // All evaluations
         $result = $this->parseEvaluations($user_id, $sum_categories_weight_array, $items_count, $items_start, $show_all, $row, $mainCategoryId, $evaluationsAdded);
         $item_total += $result['item_total'];
         $item_value_total += $result['item_value_total'];
         $total_score = array($item_value_total, $item_total);
         if (!$show_all) {
             if ($export_to_pdf) {
                 $row['total'] = $scoredisplay->display_score($total_score);
             } else {
                 $row[] = $scoredisplay->display_score($total_score);
             }
         } else {
             if ($export_to_pdf) {
                 $row['total'] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS);
             } else {
                 $row[] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS);
             }
         }
         unset($score);
         $data[] = $row;
     }
     return $data;
 }
    public function get_students_content_html_for_drh()
    {
        $attendance = new Attendance();
        $students = $this->students;
        $content = '<div style="margin:5px;">';
        $content .= '<h3><font color="#000">' . get_lang('YourStudents') . '</font></h3>';
        $students_table = null;
        if (count($students) > 0) {
            $students_table .= '<table class="data_table">';
            $students_table .= '<tr>
									<th>' . get_lang('User') . '</th>
									<th>' . get_lang('AttendancesFaults') . '</th>
									<th>' . get_lang('Evaluations') . '</th>
								</tr>';
            $i = 1;
            foreach ($students as $student) {
                $student_id = $student['user_id'];
                $firstname = $student['firstname'];
                $lastname = $student['lastname'];
                $username = $student['username'];
                // get average of faults in attendances by student
                $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
                if (!empty($results_faults_avg)) {
                    $attendances_faults_avg = '<a title="' . get_lang('GoToStudentDetails') . '" href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $student_id . '">' . $results_faults_avg['faults'] . '/' . $results_faults_avg['total'] . ' (' . $results_faults_avg['porcent'] . '%)</a>';
                } else {
                    $attendances_faults_avg = '0%';
                }
                $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
                $evaluations_avg = 0;
                $score = $weight = 0;
                foreach ($courses_by_user as $course) {
                    $course_code = $course['code'];
                    $cats = Category::load(null, null, $course_code, null, null, null, false);
                    $scoretotal = array();
                    if (isset($cats) && isset($cats[0])) {
                        $scoretotal = $cats[0]->calc_score($student_id, $course_code);
                    }
                    if (!empty($scoretotal)) {
                        $score += $scoretotal[0];
                        $weight += $scoretotal[1];
                    }
                }
                if (!empty($weight)) {
                    $evaluations_avg = '<a title="' . get_lang('GoToStudentDetails') . '" href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $student_id . '">' . round($score, 2) . '/' . round($weight, 2) . '(' . round($score / $weight * 100, 2) . ' %)</a>';
                }
                if ($i % 2 == 0) {
                    $class_tr = 'row_odd';
                } else {
                    $class_tr = 'row_even';
                }
                $students_table .= '<tr class="' . $class_tr . '">
										<td>' . api_get_person_name($firstname, $lastname) . ' (' . $username . ')</td>
										<td>' . $attendances_faults_avg . '</td>
										<td>' . $evaluations_avg . '</td>
									</tr>';
                $i++;
            }
            $students_table .= '</table>';
        } else {
            $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
        }
        $content .= $students_table;
        if (count($students) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;">
                            <a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/index.php?view=admin&display=yourstudents">' . get_lang('SeeMore') . '</a>
                         </div>';
        }
        $content .= '</div>';
        return $content;
    }
if (!empty($keyword)) {
    $users = GradebookUtils::find_students($keyword);
} else {
    if (isset($alleval) && isset($alllinks)) {
        $users = GradebookUtils::get_all_users($alleval, $alllinks);
    } else {
        $users = null;
    }
}
$offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$addparams = array('selectcat' => $cat[0]->get_id());
if (isset($_GET['search'])) {
    $addparams['search'] = $keyword;
}
// Main course category
$mainCourseCategory = Category::load(null, null, api_get_course_id(), null, null, api_get_session_id());
$flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams, $mainCourseCategory[0]);
$flatviewtable->setAutoFill(false);
$parameters = array('selectcat' => intval($_GET['selectcat']));
$flatviewtable->set_additional_parameters($parameters);
$params = array();
if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
    $params['only_total_category'] = true;
    $params['join_firstname_lastname'] = true;
    $params['show_official_code'] = true;
    $params['export_pdf'] = true;
    if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
        Display::set_header(null, false, false);
        GradebookUtils::export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params, $mainCourseCategory[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);
}
$form = new LinkAddEditForm(LinkAddEditForm::TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat . '&editlink=' . $linkedit . '&' . api_get_cidreq());
if ($form->validate()) {
    $values = $form->exportValues();
    $parent_cat = Category::load($values['select_gradebook']);
    $final_weight = null;
    /*
        if ($parent_cat[0]->get_parent_id() == 0) {
            $final_weight = $values['weight_mask'];
        } else {
            $cat = Category :: load($parent_cat[0]->get_parent_id());
            $global_weight = $cat[0]->get_weight();
            $final_weight = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
        }*/
    $final_weight = $values['weight_mask'];
    $link->set_weight($final_weight);
    if (!empty($values['select_gradebook'])) {
        $link->set_category_id($values['select_gradebook']);
    }
    $link->set_visible(empty($values['visible']) ? 0 : 1);
Example #8
0
    $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query(['isStudentView' => 'false', 'action' => 'return_to_course_homepage']);
} else {
    $buttonHomeUrl = 'lp_controller.php?' . api_get_cidreq() . '&' . http_build_query(['action' => 'return_to_course_homepage']);
}
$buttonHomeText = get_lang('CourseHomepageLink');
// Return to lp list
if (api_get_course_setting('lp_return_link') == 1) {
    $buttonHomeUrl .= '&redirectTo=lp_list';
    $buttonHomeText = get_lang('LearningPathList');
}
$lpPreviewImagePath = api_get_path(WEB_IMG_PATH) . 'icons/64/unknown.png';
if ($learnPath->get_preview_image()) {
    $lpPreviewImagePath = $learnPath->get_preview_image_path();
}
if ($learnPath->current == $learnPath->get_last()) {
    $categories = Category::load(null, null, $course_code, null, null, $sessionId);
    if (!empty($categories)) {
        $gradebookEvaluations = $categories[0]->get_evaluations();
        $gradebookLinks = $categories[0]->get_links();
        if (count($gradebookEvaluations) === 0 && count($gradebookLinks) === 1 && $gradebookLinks[0]->get_type() == LINK_LEARNPATH && $gradebookLinks[0]->get_ref_id() == $learnPath->lp_id) {
            $gradebookMinScore = $categories[0]->get_certificate_min_score();
            $userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
            if ($userScore[0] >= $gradebookMinScore) {
                Category::register_user_certificate($categories[0]->get_id(), $user_id);
            }
        }
    }
}
$template = \Chamilo\CoreBundle\Framework\Container::getTwig();
$template->addGlobal('glossary_extra_tools', api_get_setting('glossary.show_glossary_in_extra_tools'));
$fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
function pageLoadGroup($group)
{
    $access = $group->access_type;
    $skip_group_modules = FALSE;
    $is_admin = FALSE;
    if ($group->access_type == $group->ACCESS_PRIVATE) {
        if (PA::$login_uid) {
            //if private group
            if (GROUP::member_exists($group->collection_id, PA::$login_uid)) {
                $skip_group_modules = FALSE;
            } else {
                // haha no way for non member of group
                $skip_group_modules = TRUE;
            }
        } else {
            //haha no way for anonymous user
            $skip_group_modules = TRUE;
        }
        $access_type = 'Private';
    } else {
        $access_type = 'Public';
    }
    if ($group->reg_type == $group->REG_OPEN) {
        $access_type .= ' Open';
    } else {
        $access_type .= ' Moderated';
    }
    if (Group::is_admin((int) $group->collection_id, (int) PA::$login_uid)) {
        $is_admin = TRUE;
    }
    $members = $group->get_members($cnt = FALSE, 5, 1, 'created', 'DESC', FALSE);
    $group_details = array();
    $group_details['collection_id'] = $group->collection_id;
    $group_details['type'] = $group->type;
    $group_details['author_id'] = $group->author_id;
    $user = new User();
    $user->load((int) $group->author_id);
    $login_name = $user->login_name;
    $first_name = $user->first_name;
    $last_name = $user->last_name;
    $group_details['author_name'] = $login_name;
    $group_details['author_picture'] = $user->picture;
    $group_details['title'] = $group->title;
    $group_details['description'] = $group->description;
    $group_details['is_active'] = $group->is_active;
    $group_details['picture'] = $group->picture;
    $group_details['desktop_picture'] = @$group->desktop_picture;
    $group_details['created'] = PA::datetime($group->created, 'long', 'short');
    // date("F d, Y h:i A", $group->created);
    $group_details['changed'] = $group->changed;
    $group_details['category_id'] = $group->category_id;
    $cat_obj = new Category();
    $cat_obj->set_category_id($group->category_id);
    $cat_obj->load();
    $cat_name = stripslashes($cat_obj->name);
    $cat_description = stripslashes($cat_obj->description);
    $group_details['category_name'] = $cat_name;
    $group_details['category_description'] = $cat_description;
    $group_details['members'] = Group::get_member_count($group->collection_id);
    $group_details['access_type'] = $access_type;
    $group_details['is_admin'] = $is_admin;
    //////////////////get details of group EOF
    if (is_array($members)) {
        $count = count($members);
        foreach ($members as $member) {
            $count_relations = Relation::get_relations($member['user_id'], APPROVED, PA::$network_info->network_id);
            $user = new User();
            $user->load((int) $member['user_id']);
            $login_name = $user->login_name;
            $user_picture = $user->picture;
            $users_data[] = array('user_id' => $member['user_id'], 'picture' => $user_picture, 'login_name' => $login_name, 'no_of_relations' => count($count_relations));
        }
        $final_array = array('users_data' => $users_data, 'total_users' => $count);
    }
    $users = $final_array;
    $is_member = Group::member_exists((int) $group->collection_id, (int) PA::$login_uid) ? TRUE : FALSE;
    $group_details['is_member'] = $is_member;
    $group_details['skip_group_modules'] = $skip_group_modules;
    $group_details['users'] = $users;
    return $group_details;
}
 static function register_user_certificate($category_id, $user_id)
 {
     // generating the total score for a course
     $cats_course = Category::load($category_id, null, null, null, null, null, false);
     $alleval_course = $cats_course[0]->get_evaluations($user_id, true);
     $alllink_course = $cats_course[0]->get_links($user_id, true);
     $evals_links = array_merge($alleval_course, $alllink_course);
     $item_total = 0;
     //@todo move these in a function
     $sum_categories_weight_array = array();
     if (isset($cats_course) && !empty($cats_course)) {
         $categories = Category::load(null, null, null, $category_id);
         if (!empty($categories)) {
             foreach ($categories as $category) {
                 $sum_categories_weight_array[$category->get_id()] = $category->get_weight();
             }
         } else {
             $sum_categories_weight_array[$category_id] = $cats_course[0]->get_weight();
         }
     }
     $main_weight = $cats_course[0]->get_weight();
     $item_total_value = 0;
     $item_value = 0;
     for ($count = 0; $count < count($evals_links); $count++) {
         $item = $evals_links[$count];
         $score = $item->calc_score($user_id);
         $divide = $score[1] == 0 ? 1 : $score[1];
         $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
         $item_value = $score[0] / $divide * $item->get_weight() * $sub_cat_percentage / $main_weight;
         $item_total_value += $item_value;
     }
     $item_total_value = (double) $item_total_value;
     $cattotal = Category::load($category_id);
     $scoretotal = $cattotal[0]->calc_score($user_id);
     //Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
     $scoredisplay = ScoreDisplay::instance();
     $my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
     //Show certificate
     $certificate_min_score = $cats_course[0]->get_certificate_min_score();
     $scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT);
     //a student always sees only the teacher's repartition
     if (isset($certificate_min_score) && $item_total_value >= $certificate_min_score) {
         $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id);
         if (empty($my_certificate)) {
             register_user_info_about_certificate($category_id, $user_id, $my_score_in_gradebook, api_get_utc_datetime());
             $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id);
         }
         if (!empty($my_certificate)) {
             $certificate_obj = new Certificate($my_certificate['id']);
             $url = Certificate::getCertificatePublicURL($my_certificate['id']);
             $certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 32), $url, array('target' => '_blank'));
             $html = '<div class="actions" align="right">';
             $html .= Display::url($url, $url, array('target' => '_blank'));
             $html .= $certificates;
             $html .= '</div>';
             return $html;
         }
     } else {
         return false;
     }
 }
 /**
  * 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;
 }
<?php

/* For licensing terms, see /license.txt */
/**
 * Script
 * @package chamilo.gradebook
 */
//require_once '../inc/global.inc.php';
$current_course_tool = TOOL_GRADEBOOK;
api_protect_course_script(true);
api_block_anonymous_users();
GradebookUtils::block_students();
$catadd = new Category();
$catadd->set_user_id(api_get_user_id());
$catadd->set_parent_id($_GET['selectcat']);
$catcourse = Category::load($_GET['selectcat']);
$form = new CatForm(CatForm::TYPE_SELECT_COURSE, $catadd, 'add_cat_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&' . api_get_cidreq());
if ($form->validate()) {
    $values = $form->exportValues();
    $cat = new Category();
    $cat->set_course_code($values['select_course']);
    $cat->set_name($values['name']);
    header('location: gradebook_add_link.php?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&course_code=' . Security::remove_XSS($values['select_course']) . '&' . api_get_cidreq());
    exit;
}
$interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . Security::remove_XSS($_GET['selectcat']) . '&' . api_get_cidreq(), 'name' => get_lang('Gradebook'));
Display::display_header(get_lang('NewCategory'));
$form->display();
Display::display_footer();
$courses = CourseManager::get_courses_list(0, 0, 'title');
$options = array();
foreach ($courses as $course) {
    $options[$course['id']] = $course['title'];
}
$form->addElement('select', 'course', get_lang('Course'), $options);
$form->addElement('file', 'file', get_lang('File'));
$form->add_button('submit', get_lang('Submit'));
$form->display();
if ($form->validate()) {
    $values = $form->getSubmitValues();
    if (isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name'])) {
        $users = Import::csv_reader($_FILES['file']['tmp_name']);
        $courseId = $values['course'];
        $courseInfo = api_get_course_info_by_id($courseId);
        $courseCode = $courseInfo['code'];
        $cats = Category::load(null, null, $courseCode, null, null, 0, false);
        if (isset($cats[0])) {
            /** @var Category $cat */
            $userList = array();
            foreach ($users as $user) {
                $userInfo = api_get_user_info_from_official_code($user['official_code']);
                if (!empty($userInfo)) {
                    $userList[] = $userInfo;
                }
            }
            Category::exportAllCertificates($cat->get_id(), $userList);
        }
    }
}
Display::display_footer();
<?php

/* For licensing terms, see /license.txt */
/**
 * Responses to AJAX calls
 */
require_once '../global.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php';
api_protect_course_script(true);
$action = $_REQUEST['a'];
switch ($action) {
    case 'get_gradebook_weight':
        if (api_is_allowed_to_edit(null, true)) {
            $cat_id = $_GET['cat_id'];
            $cat = Category::load($cat_id);
            if ($cat && isset($cat[0])) {
                echo $cat[0]->get_weight();
            } else {
                echo 0;
            }
        }
        break;
    default:
        echo '';
}
exit;
Example #15
0
 /**
  * Subscribes courses to the given session and optionally (default)
  * unsubscribes previous users
  * @author Carlos Vargas from existing code
  * @param	int		$sessionId
  * @param	array	$courseList List of courses int ids
  * @param	bool	$removeExistingCoursesWithUsers Whether to unsubscribe
  * existing courses and users (true, default) or not (false)
  * @param $copyEvaluation from base course to session course
  * @return	void	Nothing, or false on error
  * */
 public static function add_courses_to_session($sessionId, $courseList, $removeExistingCoursesWithUsers = true, $copyEvaluation = false)
 {
     $sessionId = intval($sessionId);
     if (empty($sessionId) || empty($courseList)) {
         return false;
     }
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     // Get list of courses subscribed to this session
     $sql = "SELECT c_id\n                FROM {$tbl_session_rel_course}\n                WHERE session_id = {$sessionId}";
     $rs = Database::query($sql);
     $existingCourses = Database::store_result($rs);
     $nbr_courses = count($existingCourses);
     // Get list of users subscribed to this session
     $sql = "SELECT user_id\n                FROM {$tbl_session_rel_user}\n                WHERE\n                    session_id = {$sessionId} AND\n                    relation_type<>" . SESSION_RELATION_TYPE_RRHH . "";
     $result = Database::query($sql);
     $user_list = Database::store_result($result);
     // Remove existing courses from the session.
     if ($removeExistingCoursesWithUsers === true && !empty($existingCourses)) {
         foreach ($existingCourses as $existingCourse) {
             if (!in_array($existingCourse['c_id'], $courseList)) {
                 $sql = "DELETE FROM {$tbl_session_rel_course}\n                            WHERE\n                                c_id = " . $existingCourse['c_id'] . " AND\n                                session_id = {$sessionId}";
                 Database::query($sql);
                 $sql = "DELETE FROM {$tbl_session_rel_course_rel_user}\n                            WHERE\n                                c_id = " . $existingCourse['c_id'] . " AND\n                                session_id = {$sessionId}";
                 Database::query($sql);
                 Event::addEvent(LOG_SESSION_DELETE_COURSE, LOG_COURSE_ID, $existingCourse['c_id'], api_get_utc_datetime(), api_get_user_id(), $existingCourse['c_id'], $sessionId);
                 CourseManager::remove_course_ranking($existingCourse['c_id'], $sessionId);
                 $nbr_courses--;
             }
         }
     }
     // Pass through the courses list we want to add to the session
     foreach ($courseList as $courseId) {
         $courseInfo = api_get_course_info_by_id($courseId);
         // If course doesn't exists continue!
         if (empty($courseInfo)) {
             continue;
         }
         $exists = false;
         // check if the course we want to add is already subscribed
         foreach ($existingCourses as $existingCourse) {
             if ($courseId == $existingCourse['c_id']) {
                 $exists = true;
             }
         }
         if (!$exists) {
             // Copy gradebook categories and links (from base course)
             // to the new course session
             if ($copyEvaluation) {
                 $cats = Category::load(null, null, $courseInfo['code']);
                 if (!empty($cats)) {
                     $categoryIdList = [];
                     /** @var Category $cat */
                     foreach ($cats as $cat) {
                         $categoryIdList[$cat->get_id()] = $cat->get_id();
                     }
                     $newCategoryIdList = [];
                     foreach ($cats as $cat) {
                         $links = $cat->get_links(null, false, $courseInfo['code'], 0);
                         $cat->set_session_id($sessionId);
                         $oldCategoryId = $cat->get_id();
                         $newId = $cat->add();
                         $newCategoryIdList[$oldCategoryId] = $newId;
                         $parentId = $cat->get_parent_id();
                         if (!empty($parentId)) {
                             $newParentId = $newCategoryIdList[$parentId];
                             $cat->set_parent_id($newParentId);
                             $cat->save();
                         }
                         /** @var AbstractLink $link */
                         foreach ($links as $link) {
                             $newCategoryId = $newCategoryIdList[$link->get_category_id()];
                             $link->set_category_id($newCategoryId);
                             $link->add();
                         }
                     }
                     // Create
                     DocumentManager::generateDefaultCertificate($courseInfo, true, $sessionId);
                 }
             }
             // If the course isn't subscribed yet
             $sql = "INSERT INTO {$tbl_session_rel_course} (session_id, c_id)\n                        VALUES ({$sessionId}, {$courseId})";
             Database::query($sql);
             Event::addEvent(LOG_SESSION_ADD_COURSE, LOG_COURSE_ID, $courseId, api_get_utc_datetime(), api_get_user_id(), $courseId, $sessionId);
             // We add the current course in the existing courses array,
             // to avoid adding another time the current course
             $existingCourses[] = array('c_id' => $courseId);
             $nbr_courses++;
             // subscribe all the users from the session to this course inside the session
             $nbr_users = 0;
             foreach ($user_list as $enreg_user) {
                 $enreg_user_id = intval($enreg_user['user_id']);
                 $sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user} (session_id, c_id, user_id)\n                            VALUES ({$sessionId}, {$courseId}, {$enreg_user_id})";
                 $result = Database::query($sql);
                 Event::addEvent(LOG_SESSION_ADD_USER_COURSE, LOG_USER_ID, $enreg_user_id, api_get_utc_datetime(), api_get_user_id(), $courseId, $sessionId);
                 if (Database::affected_rows($result)) {
                     $nbr_users++;
                 }
             }
             $sql = "UPDATE {$tbl_session_rel_course}\n                        SET nbr_users = {$nbr_users}\n                        WHERE session_id = {$sessionId} AND c_id = {$courseId}";
             Database::query($sql);
         }
     }
     $sql = "UPDATE {$tbl_session}\n                SET nbr_courses = {$nbr_courses}\n                WHERE id = {$sessionId}";
     Database::query($sql);
 }
	/**
 	 * 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 = 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
						    $data_set = new pData;
						    $data_set->AddPoint($max, "Max");
						    $data_set->AddPoint($avg, "Avg");
						    $data_set->AddPoint($min, "Min");
						    $data_set->AddPoint($items, "Items");
						    $data_set->SetXAxisName(get_lang('EvaluationName'));
							$data_set->SetYAxisName(get_lang('Percentage'));
							$data_set->AddAllSeries();
						   	$data_set->RemoveSerie("Items");
						   	$data_set->SetAbsciseLabelSerie("Items");
						    $graph_id = $this->user_id.'StudentEvaluationGraph';
							$cache = new pCache();
							// the graph id
							$data = $data_set->GetData();
							if ($cache->IsInCache($graph_id, $data)) {
								//if we already created the img
								$img_file = $cache->GetHash($graph_id, $data);
							} else {
								// Initialise the graph
                                $angle = -30;
							    $test = new pChart($this->bg_width, $this->bg_height);
							    $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
                                $test->fixHeightByRotation(
                                    $data_set->GetData(),
                                    $data_set->GetDataDescription(),
                                    $angle
                                );
                                $test->setGraphArea(50, 30, $this->bg_width - 75, $this->bg_height - 75);
                                $test->drawFilledRoundedRectangle(
                                    7,
                                    7,
                                    $this->bg_width - 20,
                                    $test->YSize - 20,
                                    5,
                                    240,
                                    240,
                                    240
                                );
                                $test->drawRoundedRectangle(
                                    5,
                                    5,
                                    $this->bg_width - 18,
                                    $test->YSize - 18,
                                    5,
                                    230,
                                    230,
                                    230
                                );
							    $test->drawGraphArea(255,255,255,TRUE);
							    $test->setFixedScale(0,100,5);
                                $test->drawScale(
                                    $data_set->GetData(),
                                    $data_set->GetDataDescription(),
                                    SCALE_ADDALL,
                                    150,
                                    150,
                                    150,
                                    TRUE,
                                    $angle,
                                    2,
                                    TRUE
                                );
							    $test->setColorPalette(0,105,221,34);
								$test->setColorPalette(1,255,135,30);
								$test->setColorPalette(2,255,0,0);
							    $test->drawGrid(4,TRUE,230,230,230,50);
							    // Draw the 0 line
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6);
							    $test->drawTreshold(0,143,55,72,TRUE,TRUE);
							    // Draw the bar graph
							    $test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100);
							    // Finish the graph
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
							    $test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255);
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
							    $test->setColorPalette(0,50,50,50);
								$test->setColorPalette(1,50,50,50);
								$test->setColorPalette(2,50,50,50);
							    $test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg"));
							    $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
								ob_start();
								$test->Stroke();
								ob_end_clean();
								$img_file = $cache->GetHash($graph_id, $data_set->GetData());
							}
							if (!empty($img_file)) {
								$courses_graph[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
							}
						}
					}
				}
				if (!empty($courses_graph)) {
					$graphs[$session_id] = $courses_graph;
				}
			}
		}
    	return $graphs;
 	}
Example #17
0
$table_evaluated[LINK_LEARNPATH] = array(TABLE_LP_MAIN, 'name', 'id', get_lang('Learnpath'));
$table_evaluated[LINK_FORUM_THREAD] = array(TABLE_FORUM_THREAD, 'thread_title_qualify', 'thread_id', get_lang('Forum'));
$table_evaluated[LINK_ATTENDANCE] = array(TABLE_ATTENDANCE, 'attendance_title_qualify', 'id', get_lang('Attendance'));
$table_evaluated[LINK_SURVEY] = array(TABLE_SURVEY, 'code', 'survey_id', get_lang('Survey'));
$submitted = isset($_POST['submitted']) ? $_POST['submitted'] : '';
if ($submitted == 1) {
    Display::display_confirmation_message(get_lang('GradebookWeightUpdated')) . '<br /><br />';
    if (isset($_POST['evaluation'])) {
        $eval_log = new Evaluation();
    }
}
$output = '';
$my_cat = Category::load($my_selectcat);
$my_cat = $my_cat[0];
$parent_id = $my_cat->get_parent_id();
$parent_cat = Category::load($parent_id);
$my_category = array();
$cat = new Category();
$my_category = $cat->shows_all_information_an_category($my_selectcat);
$original_total = $my_category['weight'];
$masked_total = $parent_cat[0]->get_weight();
$sql = 'SELECT * FROM ' . $table_link . ' WHERE category_id = ' . $my_selectcat;
$result = Database::query($sql);
$links = Database::store_result($result, 'ASSOC');
foreach ($links as &$row) {
    $item_weight = $row['weight'];
    //$item_weight = $masked_total*$item_weight/$original_total;
    //
    $sql = 'SELECT * FROM ' . GradebookUtils::get_table_type_course($row['type']) . '
            WHERE c_id = ' . $course_id . ' AND ' . $table_evaluated[$row['type']][2] . ' = ' . $row['ref_id'];
    $result = Database::query($sql);
Example #18
0
 /**
  * Return user info array of all users registered in a course
  * This only returns the users that are registered in this actual course, not linked courses.
  * @param string $course_code
  * @param int $session_id
  * @param string $limit
  * @param string $order_by the field to order the users by.
  * Valid values are 'lastname', 'firstname', 'username', 'email', 'official_code' OR a part of a SQL statement
  * that starts with ORDER BY ...
  * @param null $filter_by_status if using the session_id: 0 or 2 (student, coach),
  * if using session_id = 0 STUDENT or COURSEMANAGER
  * @param null $return_count
  * @param bool $add_reports
  * @param bool $resumed_report
  * @param array $extra_field
  * @param array $courseCodeList
  * @param array $userIdList
  * @param string $filterByActive
  * @param array $sessionIdList
  * @return array|int
  */
 public static function get_user_list_from_course_code($course_code = null, $session_id = 0, $limit = null, $order_by = null, $filter_by_status = null, $return_count = null, $add_reports = false, $resumed_report = false, $extra_field = array(), $courseCodeList = array(), $userIdList = array(), $filterByActive = null, $sessionIdList = array())
 {
     $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
     $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
     $session_id = intval($session_id);
     $course_code = Database::escape_string($course_code);
     $courseInfo = api_get_course_info($course_code);
     $courseId = 0;
     if (!empty($courseInfo)) {
         $courseId = $courseInfo['real_id'];
     }
     $where = array();
     if (empty($order_by)) {
         $order_by = 'user.lastname, user.firstname';
         if (api_is_western_name_order()) {
             $order_by = 'user.firstname, user.lastname';
         }
     }
     // if the $order_by does not contain 'ORDER BY'
     // we have to check if it is a valid field that can be sorted on
     if (!strstr($order_by, 'ORDER BY')) {
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . $order_by;
         } else {
             $order_by = '';
         }
     }
     $filter_by_status_condition = null;
     if (!empty($session_id) || !empty($sessionIdList)) {
         $sql = 'SELECT DISTINCT
                     user.user_id,
                     user.email,
                     session_course_user.status as status_session,
                     session_id,
                     user.*,
                     course.*,
                     session.name as session_name
                 ';
         if ($return_count) {
             $sql = " SELECT COUNT(user.user_id) as count";
         }
         $sessionCondition = " session_course_user.session_id = {$session_id}";
         if (!empty($sessionIdList)) {
             $sessionIdListTostring = implode("','", array_map('intval', $sessionIdList));
             $sessionCondition = " session_course_user.session_id IN ('{$sessionIdListTostring}') ";
         }
         $courseCondition = " course.id = {$courseId}";
         if (!empty($courseCodeList)) {
             $courseCodeListForSession = array_map(array('Database', 'escape_string'), $courseCodeList);
             $courseCodeListForSession = implode('","', $courseCodeListForSession);
             $courseCondition = ' course.code IN ("' . $courseCodeListForSession . '")  ';
         }
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= " LEFT JOIN " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . " as session_course_user\n                      ON\n                        user.user_id = session_course_user.user_id AND\n                        {$sessionCondition}\n                        INNER JOIN {$course_table} course ON session_course_user.c_id = course.id AND\n                        {$courseCondition}\n                        INNER JOIN {$sessionTable} session ON session_course_user.session_id = session.id\n                   ";
         $where[] = ' session_course_user.c_id IS NOT NULL ';
         // 2 = coach
         // 0 = student
         if (isset($filter_by_status)) {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " session_course_user.status = {$filter_by_status} AND ";
         }
     } else {
         if ($return_count) {
             $sql = " SELECT COUNT(*) as count";
             if ($resumed_report) {
                 //$sql = " SELECT count(field_id) ";
             }
         } else {
             if (empty($course_code)) {
                 $sql = 'SELECT DISTINCT
                             course.title,
                             course.code,
                             course_rel_user.status as status_rel,
                             user.user_id,
                             user.email,
                             course_rel_user.is_tutor,
                             user.*  ';
             } else {
                 $sql = 'SELECT DISTINCT
                             course_rel_user.status as status_rel,
                             user.user_id,
                             user.email,
                             course_rel_user.is_tutor,
                             user.*  ';
             }
         }
         $sql .= ' FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_COURSE_USER) . ' as course_rel_user
                     ON user.user_id = course_rel_user.user_id AND
                     course_rel_user.relation_type <> ' . COURSE_RELATION_TYPE_RRHH . '  ';
         $sql .= " INNER JOIN {$course_table} course ON course_rel_user.c_id = course.id ";
         if (!empty($course_code)) {
             $sql .= ' AND course_rel_user.c_id="' . $courseId . '"';
         }
         $where[] = ' course_rel_user.c_id IS NOT NULL ';
         if (isset($filter_by_status) && is_numeric($filter_by_status)) {
             $filter_by_status = intval($filter_by_status);
             $filter_by_status_condition = " course_rel_user.status = {$filter_by_status} AND ";
         }
     }
     $multiple_access_url = api_get_multiple_access_url();
     if ($multiple_access_url) {
         $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER) . ' au
                   ON (au.user_id = user.user_id) ';
     }
     $extraFieldWasAdded = false;
     if ($return_count && $resumed_report) {
         foreach ($extra_field as $extraField) {
             $extraFieldInfo = UserManager::get_extra_field_information_by_name($extraField);
             if (!empty($extraFieldInfo)) {
                 $fieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
                 $sql .= ' LEFT JOIN ' . $fieldValuesTable . ' as ufv
                         ON (
                             user.user_id = ufv.item_id AND
                             (field_id = ' . $extraFieldInfo['id'] . ' OR field_id IS NULL)
                         )';
                 $extraFieldWasAdded = true;
             }
         }
     }
     $sql .= ' WHERE ' . $filter_by_status_condition . ' ' . implode(' OR ', $where);
     if ($multiple_access_url) {
         $current_access_url_id = api_get_current_access_url_id();
         $sql .= " AND (access_url_id =  {$current_access_url_id} ) ";
     }
     if ($return_count && $resumed_report && $extraFieldWasAdded) {
         $sql .= ' AND field_id IS NOT NULL GROUP BY value ';
     }
     if (!empty($courseCodeList)) {
         $courseCodeList = array_map(array('Database', 'escape_string'), $courseCodeList);
         $courseCodeList = implode('","', $courseCodeList);
         if (empty($sessionIdList)) {
             $sql .= ' AND course.code IN ("' . $courseCodeList . '")';
         }
     }
     if (!empty($userIdList)) {
         $userIdList = array_map('intval', $userIdList);
         $userIdList = implode('","', $userIdList);
         $sql .= ' AND user.user_id IN ("' . $userIdList . '")';
     }
     if (isset($filterByActive)) {
         $filterByActive = intval($filterByActive);
         $sql .= ' AND user.active = ' . $filterByActive;
     }
     $sql .= ' ' . $order_by . ' ' . $limit;
     $rs = Database::query($sql);
     $users = array();
     $extra_fields = UserManager::get_extra_fields(0, 100, null, null, true, true);
     $counter = 1;
     $count_rows = Database::num_rows($rs);
     if ($return_count && $resumed_report) {
         return $count_rows;
     }
     $table_user_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
     $tableExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
     if ($count_rows) {
         while ($user = Database::fetch_array($rs)) {
             if ($return_count) {
                 return $user['count'];
             }
             $report_info = array();
             $user_info = $user;
             $user_info['status'] = $user['status'];
             if (isset($user['is_tutor'])) {
                 $user_info['is_tutor'] = $user['is_tutor'];
             }
             if (!empty($session_id)) {
                 $user_info['status_session'] = $user['status_session'];
             }
             $sessionId = isset($user['session_id']) ? $user['session_id'] : 0;
             $course_code = isset($user['code']) ? $user['code'] : null;
             if ($add_reports) {
                 if ($resumed_report) {
                     $extra = array();
                     if (!empty($extra_fields)) {
                         foreach ($extra_fields as $extra) {
                             if (in_array($extra['1'], $extra_field)) {
                                 $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                                 break;
                             }
                         }
                     }
                     $row_key = '-1';
                     $name = '-';
                     if (!empty($extra)) {
                         if (!empty($user_data[$extra['1']])) {
                             $row_key = $user_data[$extra['1']];
                             $name = $user_data[$extra['1']];
                             $users[$row_key]['extra_' . $extra['1']] = $name;
                         }
                     }
                     $users[$row_key]['training_hours'] += Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, $sessionId);
                     $users[$row_key]['count_users'] += $counter;
                     $registered_users_with_extra_field = 0;
                     if (!empty($name) && $name != '-') {
                         $extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
                         $name = Database::escape_string($name);
                         $sql = "SELECT count(v.item_id) as count\n                                    FROM {$table_user_field_value} v INNER JOIN\n                                    {$tableExtraField} f\n                                    ON (f.id = v.field_id)\n                                    WHERE value = '{$name}' AND extra_field_type = {$extraFieldType}";
                         $result_count = Database::query($sql);
                         if (Database::num_rows($result_count)) {
                             $row_count = Database::fetch_array($result_count);
                             $registered_users_with_extra_field = $row_count['count'];
                         }
                     }
                     $users[$row_key]['count_users_registered'] = $registered_users_with_extra_field;
                     $users[$row_key]['average_hours_per_user'] = $users[$row_key]['training_hours'] / $users[$row_key]['count_users'];
                     $category = Category::load(null, null, $course_code, null, null, $sessionId);
                     if (!isset($users[$row_key]['count_certificates'])) {
                         $users[$row_key]['count_certificates'] = 0;
                     }
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $users[$row_key]['count_certificates']++;
                     }
                     foreach ($extra_fields as $extra) {
                         if ($extra['1'] == 'ruc') {
                             continue;
                         }
                         if (!isset($users[$row_key][$extra['1']])) {
                             $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                             if (!empty($user_data[$extra['1']])) {
                                 $users[$row_key][$extra['1']] = $user_data[$extra['1']];
                             }
                         }
                     }
                 } else {
                     $sessionName = !empty($sessionId) ? ' - ' . $user['session_name'] : '';
                     $report_info['course'] = $user['title'] . $sessionName;
                     $report_info['user'] = api_get_person_name($user['firstname'], $user['lastname']);
                     $report_info['email'] = $user['email'];
                     $report_info['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $courseId, $sessionId));
                     $category = Category::load(null, null, $course_code, null, null, $sessionId);
                     $report_info['certificate'] = Display::label(get_lang('No'));
                     if (isset($category[0]) && $category[0]->is_certificate_available($user['user_id'])) {
                         $report_info['certificate'] = Display::label(get_lang('Yes'), 'success');
                     }
                     $progress = intval(Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $sessionId));
                     $report_info['progress_100'] = $progress == 100 ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'));
                     $report_info['progress'] = $progress . "%";
                     foreach ($extra_fields as $extra) {
                         $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
                         $report_info[$extra['1']] = $user_data[$extra['1']];
                     }
                     $report_info['user_id'] = $user['user_id'];
                     $users[] = $report_info;
                 }
             } else {
                 $users[$user['user_id']] = $user_info;
             }
         }
     }
     return $users;
 }
Example #19
0
require_once './includes/functions/html_generate.php';
$parent_id = (int) $_GET['cid'];
if (empty($parent_id)) {
    $redirect_msg = "Required parameters missing in URL.";
    $back_to_page = $base_url . '/forums.php';
    header("Location: {$base_url}/generic_error.php?msg={$redirect_msg}&back_to_page={$back_to_page}");
    exit;
}
if ($parent_id) {
    $group_id = '';
    $parent_cat_obj = new Category();
    $arr_obj_categories = Category::build_children_list($parent_id);
    $parent_cat_obj = new Category();
    $parent_cat_obj->set_category_id($parent_id);
    try {
        $parent_cat_obj->load();
        $parent_cat_name = stripslashes($parent_cat_obj->name);
        $parent_cat_description = stripslashes($parent_cat_obj->description);
    } catch (PAException $e) {
        $msg = "Error occured in retreiving category information\n";
        $msg .= "<br><center><font color=\"red\">" . $e->message . "</font></center>";
        $error_code = $e->code;
        $error = TRUE;
    }
    if ($error) {
        $redirect_msg = "Category does not exist.";
        $back_to_page = $base_url . '/forums.php';
        header("Location: {$base_url}/generic_error.php?msg={$redirect_msg}&back_to_page={$back_to_page}");
        exit;
    }
    $thread_obj = new MessageBoard();
 /**
  * Find links by name
  * To keep consistency, do not call this method but LinkFactory::find_links instead.
  * @todo can be written more efficiently using a new (but very complex) sql query
  */
 public function find_links($name_mask, $selectcat)
 {
     $rootcat = Category::load($selectcat);
     $links = $rootcat[0]->get_links(api_is_allowed_to_edit() ? null : api_get_user_id(), true);
     $foundlinks = array();
     foreach ($links as $link) {
         if (!(api_strpos(api_strtolower($link->get_name()), api_strtolower($name_mask)) === false)) {
             $foundlinks[] = $link;
         }
     }
     return $foundlinks;
 }
 /**
  * Gets the info about a gradebook certificate for a user by course
  * @param string The course code
  * @param int The user id
  * @return array  if there is not information return false
  */
 public static function get_info_gradebook_certificate($course_code, $user_id)
 {
     $tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
     $tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
     $session_id = api_get_session_id();
     if (empty($session_id)) {
         $session_condition = ' AND (session_id = "" OR session_id = 0 OR session_id IS NULL )';
     } else {
         $session_condition = " AND session_id = {$session_id}";
     }
     $sql = 'SELECT * FROM ' . $tbl_grade_certificate . ' WHERE cat_id = (SELECT id FROM ' . $tbl_grade_category . '
             WHERE
                 course_code = "' . Database::escape_string($course_code) . '" ' . $session_condition . ' LIMIT 1 ) AND
                 user_id=' . intval($user_id);
     $rs = Database::query($sql);
     if (Database::num_rows($rs) > 0) {
         $row = Database::fetch_array($rs, 'ASSOC');
         $score = $row['score_certificate'];
         $category_id = $row['cat_id'];
         $cat = Category::load($category_id);
         $displayscore = ScoreDisplay::instance();
         if (isset($cat) && $displayscore->is_custom()) {
             $grade = $displayscore->display_score(array($score, $cat[0]->get_weight()), SCORE_DIV_PERCENT_WITH_CUSTOM);
         } else {
             $grade = $displayscore->display_score(array($score, $cat[0]->get_weight()));
         }
         $row['grade'] = $grade;
         return $row;
     }
     return false;
 }
Example #22
0
<?php

/* For licensing terms, see /license.txt */
/**
 * Script
 * @package chamilo.gradebook
 */
require_once '../inc/global.inc.php';
api_block_anonymous_users();
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info());
if (!$isDrhOfCourse) {
    GradebookUtils::block_students();
}
$interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
$category = Category::load($_GET['selectcat']);
$my_user_id = Security::remove_XSS($_GET['userid']);
$allevals = $category[0]->get_evaluations($my_user_id, true);
$alllinks = $category[0]->get_links($my_user_id, true);
if ($_GET['selectcat'] != null) {
    $addparams = array('userid' => $my_user_id, 'selectcat' => Security::remove_XSS($_GET['selectcat']));
} else {
    $addparams = array('userid' => $my_user_id, 'selecteval' => Security::remove_XSS($_GET['selecteval']));
}
$user_table = new UserTable($my_user_id, $allevals, $alllinks, $addparams);
if (isset($_GET['exportpdf'])) {
    $datagen = new UserDataGenerator($my_user_id, $allevals, $alllinks);
    $data_array = $datagen->get_data(UserDataGenerator::UDG_SORT_NAME, 0, null, true);
    $newarray = array();
    $displayscore = ScoreDisplay::instance();
    foreach ($data_array as $data) {
        $newarray[] = array_slice($data, 1);
 /**
  * Find evaluations by name
  * @param string $name_mask search string
  * @return array evaluation objects matching the search criterium
  * @todo can be written more efficiently using a new (but very complex) sql query
  */
 public function find_evaluations($name_mask, $selectcat)
 {
     $rootcat = Category::load($selectcat);
     $evals = $rootcat[0]->get_evaluations(api_is_allowed_to_create_course() ? null : api_get_user_id(), true);
     $foundevals = array();
     foreach ($evals as $eval) {
         if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
             $foundevals[] = $eval;
         }
     }
     return $foundevals;
 }
 /**
  * @param int $userid
  */
 public static function display_header_user($userid)
 {
     $select_cat = intval($_GET['selectcat']);
     $user_id = $userid;
     $user = api_get_user_info($user_id);
     $catcourse = Category::load($select_cat);
     $scoredisplay = ScoreDisplay::instance();
     $scorecourse = $catcourse[0]->calc_score($user_id);
     // generating the total score for a course
     $allevals = $catcourse[0]->get_evaluations($user_id, true);
     $alllinks = $catcourse[0]->get_links($user_id, true);
     $evals_links = array_merge($allevals, $alllinks);
     $item_value = 0;
     $item_total = 0;
     for ($count = 0; $count < count($evals_links); $count++) {
         $item = $evals_links[$count];
         $score = $item->calc_score($user_id);
         $my_score_denom = $score[1] == 0 ? 1 : $score[1];
         $item_value += $score[0] / $my_score_denom * $item->get_weight();
         $item_total += $item->get_weight();
         //$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
     }
     $item_value = number_format($item_value, 2, '.', ' ');
     $total_score = array($item_value, $item_total);
     $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
     //$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
     $cattotal = Category::load(0);
     $scoretotal = $cattotal[0]->calc_score($user_id);
     $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable');
     $image_syspath = UserManager::get_user_picture_path_by_id($userid, 'system', false, true);
     $image_size = getimagesize($image_syspath['dir'] . $image_syspath['file']);
     //Web path
     $image_path = UserManager::get_user_picture_path_by_id($userid, 'web', false, true);
     $image_file = $image_path['dir'] . $image_path['file'];
     $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . $user['complete_name'] . '" ';
     if ($image_size[0] > 200) {
         //limit display width to 200px
         $img_attributes .= 'width="200" ';
     }
     $info = '<div class="row"><div class="span3">';
     $info .= '<div class="thumbnail"><img ' . $img_attributes . '/></div>';
     $info .= '</div>';
     $info .= '<div class="span6">';
     $info .= get_lang('Name') . ' :  <a target="_blank" href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php?u=' . $userid . '"> ' . $user['complete_name'] . '</a><br />';
     if (api_get_setting('show_email_addresses') == 'true') {
         $info .= get_lang('Email') . ' : <a href="mailto:' . $user['email'] . '">' . $user['email'] . '</a><br />';
     }
     $info .= get_lang('TotalUser') . ' : <b>' . $scorecourse_display . '</b>';
     $info .= '</div>';
     $info .= '</div>';
     echo $info;
 }
 /**
  * Function used by SortableTable to generate the data to display
  * @param int $from
  * @param int $per_page
  * @param int $column
  * @param string $direction
  * @param int $sort
  * @return array|mixed
  */
 public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null)
 {
     //variables load in index.php
     global $my_score_in_gradebook, $certificate_min_score;
     $scoretotal = 0;
     // determine sorting type
     $col_adjust = api_is_allowed_to_edit() ? 1 : 0;
     // By id
     $this->column = 5;
     switch ($this->column) {
         // Type
         case 0 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_TYPE;
             break;
         case 1 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_NAME;
             break;
         case 2 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION;
             break;
         case 3 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_WEIGHT;
             break;
         case 4 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_DATE;
         case 5 + $col_adjust:
             $sorting = GradebookDataGenerator::GDG_SORT_ID;
             break;
     }
     if ($this->direction == 'DESC') {
         $sorting |= GradebookDataGenerator::GDG_SORT_DESC;
     } else {
         $sorting |= GradebookDataGenerator::GDG_SORT_ASC;
     }
     //status of user in course
     $user_id = api_get_user_id();
     $course_code = api_get_course_id();
     $courseId = api_get_course_int_id();
     $session_id = api_get_session_id();
     $status_user = api_get_status_of_user_in_course($user_id, $courseId);
     $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
     // generate the data to display
     $sortable_data = array();
     $weight_total_links = 0;
     $main_categories = array();
     $main_cat = Category::load(null, null, $course_code, null, null, $session_id, false);
     $total_categories_weight = 0;
     $scoredisplay = ScoreDisplay::instance();
     //Categories
     foreach ($data_array as $data) {
         // list of items inside the gradebook (exercises, lps, forums, etc)
         $row = array();
         $item = $item_category = $data[0];
         $id = $item->get_id();
         //if the item is invisible, wrap it in a span with class invisible
         $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : '';
         $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : '';
         if (api_is_allowed_to_edit(null, true)) {
             //id
             $row[] = $this->build_id_column($item);
         }
         //Type
         $row[] = $this->build_type_column($item);
         //Name
         if (get_class($item) == 'Category') {
             $row[] = $invisibility_span_open . '<h3>' . $item->get_name() . '</h3>' . $invisibility_span_close;
             $main_categories[$item->get_id()]['name'] = $item->get_name();
         } else {
             $row[] = $invisibility_span_open . $this->build_name_link($item) . $invisibility_span_close;
             $main_categories[$item->get_id()]['name'] = $this->build_name_link($item);
         }
         $main_categories[$item->get_id()]['weight'] = $item->get_weight();
         $total_categories_weight += $item->get_weight();
         //Description
         $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close;
         //Weight
         //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close;
         //$average = $data['3']/$this->currentcat->get_weight()*100;
         $average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_SIMPLE, SCORE_BOTH, true);
         if (api_is_allowed_to_edit(null, true)) {
             $row[] = $invisibility_span_open . Display::tag('h4', $average) . $invisibility_span_close;
         } else {
             $row[] = $invisibility_span_open . $average . $invisibility_span_close;
         }
         $category_weight = $item->get_weight();
         if (api_is_allowed_to_edit(null, true)) {
             $weight_total_links += $data[3];
         } else {
             $cattotal = Category::load($_GET['selectcat']);
             $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
             $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
         }
         //Date
         //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close;
         //Edit (for admins)
         if (api_is_allowed_to_edit(null, true)) {
             $cat = new Category();
             $show_message = $cat->show_message_resource_delete($item->get_course_code());
             if ($show_message === false) {
                 $row[] = $this->build_edit_column($item);
             }
         } else {
             //students get the results and certificates columns
             if (count($this->evals_links) > 0 && $status_user != 1) {
                 $value_data = isset($data[4]) ? $data[4] : null;
                 if (!is_null($value_data)) {
                     $row[] = Display::tag('h4', $value_data);
                 } else {
                     $row[] = $this->build_edit_column($item);
                 }
             } else {
                 $score = $item->calc_score(api_get_user_id());
                 if (!empty($score[1])) {
                     $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
                     $score = $score[0] / $score[1] * $item->get_weight();
                     $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
                     $row[] = Display::tip($score, $complete_score);
                 } else {
                     $row[] = '-';
                 }
                 if (!empty($this->cats)) {
                     $row[] = $this->build_edit_column($item);
                 }
             }
         }
         //Category added
         $sortable_data[] = $row;
         // Loading childrens
         if (get_class($item) == 'Category') {
             $stud_id = api_get_user_id();
             $course_code = api_get_course_id();
             $session_id = api_get_session_id();
             $parent_id = $item->get_id();
             $cats = Category::load($parent_id, null, null, null, null, null);
             if (isset($cats[0])) {
                 $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
                 $alleval = $cats[0]->get_evaluations($stud_id);
                 $alllink = $cats[0]->get_links($stud_id);
                 $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink);
                 $data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page);
                 $total_weight = 0;
                 //Links
                 foreach ($data_array as $data) {
                     $row = array();
                     $item = $data[0];
                     //if the item is invisible, wrap it in a span with class invisible
                     $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : '';
                     $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : '';
                     $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name();
                     $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight();
                     if (api_is_allowed_to_edit(null, true)) {
                         $row[] = $this->build_id_column($item);
                     }
                     $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px'));
                     //Name
                     $row[] = $invisibility_span_open . "&nbsp;&nbsp;&nbsp;  " . $this->build_name_link($item) . $invisibility_span_close;
                     //Description
                     $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close;
                     //Weight
                     //$weight = $data[3]/$category_weight*$main_cat[0]->get_weight();
                     $weight = $data[3];
                     //$extra = " - $data[3]  $category_weight -".$main_cat[0]->get_weight();
                     $total_weight += $weight;
                     $row[] = $invisibility_span_open . $weight . $invisibility_span_close;
                     if (api_is_allowed_to_edit(null, true)) {
                         //$weight_total_links += intval($data[3]);
                     } else {
                         $cattotal = Category::load($_GET['selectcat']);
                         $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
                         $item_value = $scoretotal[0];
                     }
                     //Date
                     //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close;
                     //Admins get an edit column
                     if (api_is_allowed_to_edit(null, true)) {
                         $cat = new Category();
                         $show_message = $cat->show_message_resource_delete($item->get_course_code());
                         if ($show_message === false) {
                             $row[] = $this->build_edit_column($item);
                         }
                     } else {
                         //students get the results and certificates columns
                         $eval_n_links = array_merge($alleval, $alllink);
                         if (count($eval_n_links) > 0 && $status_user != 1) {
                             $value_data = isset($data[4]) ? $data[4] : null;
                             if (!is_null($value_data)) {
                                 $score = $item->calc_score(api_get_user_id());
                                 $new_score = $data[3] * $score[0] / $score[1];
                                 $new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals')));
                                 $row[] = Display::tip($new_score, $data[4]);
                             }
                         }
                         if (!empty($cats)) {
                             $row[] = null;
                         }
                     }
                     $row['child_of'] = $parent_id;
                     $sortable_data[] = $row;
                 }
                 //"Warning row"
                 if (!empty($data_array)) {
                     if (api_is_allowed_to_edit()) {
                         // Compare the category weight to the sum of all weights inside the category
                         if (intval($total_weight) == $category_weight) {
                             $label = null;
                             $total = score_badges(array($total_weight . ' / ' . $category_weight, '100'));
                         } else {
                             $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $category_weight));
                             $total = Display::badge($total_weight . ' / ' . $category_weight, 'warning');
                         }
                         $row = array(null, null, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h5>" . get_lang('SubTotal') . '</h5>', null, $total . ' ' . $label, 'child_of' => $parent_id);
                         $sortable_data[] = $row;
                     }
                 }
             }
         }
         //end looping categories
     }
     //end looping categories
     if (api_is_allowed_to_edit()) {
         if (count($main_cat) > 1) {
             $main_weight = intval($main_cat[0]->get_weight());
             if (intval($total_categories_weight) == $main_weight) {
                 $total = score_badges(array($total_categories_weight . ' / ' . $main_weight, '100'));
             } else {
                 $total = Display::badge($total_categories_weight . ' / ' . $main_weight, 'warning');
             }
             $row = array(null, null, '<h3>' . get_lang('Total') . '</h3>', null, $total);
             $sortable_data[] = $row;
         }
     }
     // warning messages
     $view = isset($_GET['view']) ? $_GET['view'] : null;
     if (api_is_allowed_to_edit()) {
         if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view != 'presence') {
             $id_cat = intval($_GET['selectcat']);
             $category = Category::load($id_cat);
             //$weight_category = intval($this->build_weight($category[0]));
             $weight_category = intval($this->build_weight($category[0]));
             $course_code = $this->build_course_code($category[0]);
             $weight_total_links = round($weight_total_links);
             if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) {
                 $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category);
                 $modify_icons = '<a class="right_link" href="gradebook_edit_cat.php?editcat=' . $id_cat . '&cidReq=' . $course_code . '">' . Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL) . '</a>';
                 $warning_message .= $modify_icons;
                 Display::display_warning_message($warning_message, false);
             }
             $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code);
             if (!empty($content_html)) {
                 $new_content = explode('</head>', $content_html['content']);
             }
             if (empty($new_content[0])) {
                 $warning_message = get_lang('ThereIsNotACertificateAvailableByDefault');
                 $cert_icon = '<a class="right_link" href="../document/document.php?curdirpath=/certificates&' . $course_code . '&origin=gradebook&selectcat=' . $id_cat . '">' . Display::return_icon('certificate.png', get_lang('AttachCertificate'), array(), ICON_SIZE_SMALL) . '</a>';
                 Display::display_warning_message($warning_message . $cert_icon, false);
             }
         }
         if (empty($_GET['selectcat'])) {
             $categories = Category::load();
             $weight_categories = $certificate_min_scores = $course_codes = array();
             foreach ($categories as $category) {
                 $course_code_category = $this->build_course_code($category);
                 if (!empty($course_code)) {
                     if ($course_code_category == $course_code) {
                         $weight_categories[] = intval($this->build_weight($category));
                         $certificate_min_scores[] = intval($this->build_certificate_min_score($category));
                         $course_codes[] = $course_code;
                         break;
                     }
                 } else {
                     $weight_categories[] = intval($this->build_weight($category));
                     $certificate_min_scores[] = intval($this->build_certificate_min_score($category));
                     $course_codes[] = $course_code_category;
                 }
             }
             if (is_array($weight_categories) && is_array($certificate_min_scores) && is_array($course_codes)) {
                 $warning_message = '';
                 for ($x = 0; $x < count($weight_categories); $x++) {
                     $weight_category = intval($weight_categories[$x]);
                     $certificate_min_score = intval($certificate_min_scores[$x]);
                     $course_code = $course_codes[$x];
                     if (empty($certificate_min_score) || $certificate_min_score > $weight_category) {
                         $warning_message .= $course_code . '&nbsp;-&nbsp;' . get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan') . '&nbsp;' . $weight_category . '<br />';
                     }
                 }
                 if (!empty($warning_message)) {
                     Display::display_warning_message($warning_message, false);
                 }
             }
         }
     }
     return $sortable_data;
 }
}
$interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
//load the evaluation & category
$select_eval = Security::remove_XSS($_GET['selecteval']);
if (empty($select_eval)) {
    api_not_allowed();
}
$displayscore = ScoreDisplay::instance();
$eval = Evaluation::load($select_eval);
$overwritescore = 0;
if ($eval[0]->get_category_id() < 0) {
    // if category id is negative, then the evaluation's origin is a link
    $link = LinkFactory::get_evaluation_link($eval[0]->get_id());
    $currentcat = Category::load($link->get_category_id());
} else {
    $currentcat = Category::load($eval[0]->get_category_id());
}
//load the result with the evaluation id
if (isset($_GET['delete_mark'])) {
    $result = Result::load($_GET['delete_mark']);
    if (!empty($result[0])) {
        $result[0]->delete();
    }
}
if (isset($_GET['selecteval'])) {
    $allresults = Result::load(null, null, $select_eval);
    $iscourse = $currentcat[0]->get_course_code() == null ? 1 : 0;
}
if (isset($_GET['editres'])) {
    $edit_res_xml = Security::remove_XSS($_GET['editres']);
    $select_eval_edit = Security::remove_XSS($_GET['selecteval']);
    $check = Security::check_token('get');
    if ($check) {
        $certificate = new Certificate($_GET['certificate_id']);
        $result = $certificate->delete(true);
        Security::clear_token();
        if ($result == true) {
            Display::display_confirmation_message(get_lang('CertificateRemoved'));
        } else {
            Display::display_error_message(get_lang('CertificateNotRemoved'));
        }
    }
}
$token = Security::get_token();
echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
//@todo replace all this code with something like get_total_weight()
$cats = Category::load($cat_id, null, null, null, null, null, false);
if (!empty($cats)) {
    //with this fix the teacher only can view 1 gradebook
    if (api_is_platform_admin()) {
        $stud_id = api_is_allowed_to_edit() ? null : api_get_user_id();
    } else {
        $stud_id = api_get_user_id();
    }
    $total_weight = $cats[0]->get_weight();
    $allcat = $cats[0]->get_subcategories($stud_id, api_get_course_id(), api_get_session_id());
    $alleval = $cats[0]->get_evaluations($stud_id);
    $alllink = $cats[0]->get_links($stud_id);
    $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink);
    $total_resource_weight = 0;
    if (!empty($datagen)) {
        $data_array = $datagen->get_data(GradebookDataGenerator::GDG_SORT_NAME, 0, null, true);
Example #28
0
 /**
  * load collection_id
  * @access private
  * @param int content_id
  */
 public function load($collection_id)
 {
     Logger::log("Enter: Group::load() | Args: \$collection_id = {$collection_id}");
     parent::load($collection_id);
     $res = Dal::query("SELECT * FROM {groups} WHERE group_id = ?", array($collection_id));
     if ($res->numRows()) {
         $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
         $this->access_type = $row->access_type;
         $this->reg_type = $row->reg_type;
         $this->is_moderated = $row->is_moderated;
         $this->category_id = $row->category_id;
         $this->header_image = $row->header_image;
         $this->header_image_action = $row->header_image_action;
         $this->display_header_image = $row->display_header_image;
         $Category = new Category();
         $Category->category_id = $this->category_id;
         $Category->load($Category->category_id);
         $this->category_name = $Category->name;
     } else {
         Logger::log("Thowing Exception CONTENT_NOT_FOUND");
         throw new PAException(CONTENT_NOT_FOUND, "No group matched the provided ID");
     }
     $res = Dal::query("SELECT * FROM {groups_users} WHERE group_id = ? AND (user_type =? OR user_type = ? )", array($collection_id, MODERATOR, OWNER));
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         // if users is a moderator or owner
         $this->moderators[] = $row['user_id'];
     }
     Logger::log("Exit: Group::load()");
 }
Example #29
0
        //@todo replace image
        //$pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
        $pdf->ezSetY(480);
        $pdf->ezText($certif_text, 28, array('justification' => 'center'));
        //$pdf->ezSetY(750);
        $pdf->ezSetY(50);
        $pdf->ezText($date, 18, array('justification' => 'center'));
        $pdf->ezSetY(580);
        $pdf->ezText($organization_name, 22, array('justification' => 'left'));
        $pdf->ezSetY(580);
        $pdf->ezText($portal_name, 22, array('justification' => 'right'));
        $pdf->ezStream();
    }
    exit;
} else {
    $cats = Category::load($category);
    $stud_id = api_is_allowed_to_edit() ? null : api_get_user_id();
    $allcat = $cats[0]->get_subcategories($stud_id);
    $alleval = $cats[0]->get_evaluations($stud_id);
    $alllink = $cats[0]->get_links($stud_id);
}
$addparams = array('selectcat' => $cats[0]->get_id());
if (isset($_GET['search'])) {
    $addparams['search'] = $keyword;
}
if (isset($_GET['studentoverview'])) {
    $addparams['studentoverview'] = '';
}
if (isset($allcat_info) && count($allcat_info) >= 0 && (isset($_GET['selectcat']) && $_GET['selectcat'] == 0) && isset($_GET['search']) && strlen(trim($_GET['search'])) > 0) {
    $allcat = $allcat_info;
} else {
 /**
  * Builds a basic form that is used in add and edit
  */
 private function build_basic_form($edit = 0)
 {
     $form_title = get_lang('NewEvaluation');
     if (!empty($_GET['editeval']) && $_GET['editeval'] == 1) {
         $form_title = get_lang('EditEvaluation');
     }
     $this->addElement('header', $form_title);
     $this->addElement('hidden', 'zero', 0);
     $this->addElement('hidden', 'hid_user_id');
     $this->addElement('hidden', 'hid_course_code');
     $this->addText('name', get_lang('EvaluationName'), true, array('maxlength' => '50', 'id' => 'evaluation_title'));
     $cat_id = $this->evaluation_object->get_category_id();
     $session_id = api_get_session_id();
     $course_code = api_get_course_id();
     $all_categories = Category::load(null, null, $course_code, null, null, $session_id, false);
     if (count($all_categories) == 1) {
         $this->addElement('hidden', 'hid_category_id', $cat_id);
     } else {
         $select_gradebook = $this->addElement('select', 'hid_category_id', get_lang('SelectGradebook'), array(), array('id' => 'hid_category_id'));
         $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero');
         $default_weight = 0;
         if (!empty($all_categories)) {
             foreach ($all_categories as $my_cat) {
                 if ($my_cat->get_course_code() == api_get_course_id()) {
                     $grade_model_id = $my_cat->get_grade_model_id();
                     if (empty($grade_model_id)) {
                         if ($my_cat->get_parent_id() == 0) {
                             $default_weight = $my_cat->get_weight();
                             $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
                             $cats_added[] = $my_cat->get_id();
                         } else {
                             $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
                             $cats_added[] = $my_cat->get_id();
                         }
                     } else {
                         $select_gradebook->addoption(get_lang('Select'), 0);
                     }
                     if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
                         $default_weight = $my_cat->get_weight();
                     }
                 }
             }
         }
     }
     $this->addText('weight_mask', array(get_lang('Weight'), null, ' [0 .. <span id="max_weight">' . $all_categories[0]->get_weight() . '</span>] '), true, array('size' => '4', 'maxlength' => '5', 'class' => 'span1'));
     /* $this->addText('weight', array(null, null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array (
        'size' => '4',
        'maxlength' => '5',
        'class' => 'span1'
        )); */
     if ($edit) {
         if (!$this->evaluation_object->has_results()) {
             $this->addText('max', get_lang('QualificationNumeric'), true, array('class' => 'span1', 'maxlength' => '5'));
         } else {
             $this->addText('max', array(get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')), false, array('class' => 'span1', 'maxlength' => '5', 'disabled' => 'disabled'));
         }
     } else {
         $this->addText('max', get_lang('QualificationNumeric'), true, array('class' => 'span1', 'maxlength' => '5'));
         $default_max = api_get_setting('gradebook.gradebook_default_weight');
         $defaults['max'] = isset($default_max) ? $default_max : 100;
         $this->setDefaults($defaults);
     }
     $this->addElement('textarea', 'description', get_lang('Description'));
     $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required');
     $this->addElement('checkbox', 'visible', null, get_lang('Visible'));
     $this->addRule('weight_mask', get_lang('OnlyNumbers'), 'numeric');
     $this->addRule(array('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     $this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
     $this->addRule(array('max', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
     $setting = api_get_setting('document.tool_visible_by_default_at_creation');
     $visibility_default = 1;
     if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
         $visibility_default = 0;
     }
     $this->setDefaults(array('visible' => $visibility_default));
 }