/** * Display the tree of classes * * @author Guillaume Lederer * @param list of all the classes informations of the platform * @param list of the classes that must be visible * @return * * @see * */ function display_tree_class_in_user($class_list, $course_code, $parent_class = null, $deep = 0) { $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $html_form = ''; // Get the course id with cours code $sql = "SELECT `C`.`cours_id`\n FROM `" . $tbl_course . "` as C\n WHERE `code` = '" . $course_code . "'"; claro_sql_query_get_single_value($sql); foreach ($class_list as $cur_class) { if ($parent_class == $cur_class['class_parent_id']) { // Set space characters to add in name display $blankspace = ' '; for ($i = 0; $i < $deep; $i++) { $blankspace .= ' '; } // See if current class to display has children $has_children = FALSE; foreach ($class_list as $search_parent) { if ($cur_class['id'] == $search_parent['class_parent_id']) { $has_children = TRUE; break; } } // Set link to open or close current class if ($has_children) { if (isset($_SESSION['class_add_visible_class'][$cur_class['id']]) && $_SESSION['class_add_visible_class'][$cur_class['id']] == "open") { $open_close_link = '<a href="' . $_SERVER['PHP_SELF'] . '?cmd=exClose&class_id=' . $cur_class['id'] . '">' . "\n" . '<img src="' . get_icon_url('collapse') . '" alt="" />' . "\n" . '</a>' . "\n"; } else { $open_close_link = '<a href="' . $_SERVER['PHP_SELF'] . '?cmd=exOpen&class_id=' . $cur_class['id'] . '">' . "\n" . '<img src="' . get_icon_url('expand') . '" alt="" />' . "\n" . '</a>' . "\n"; } } else { $open_close_link = ' ° '; } // Display current class $qty_user = get_class_user_number($cur_class['id']); // Need some optimisation here ... $html_form .= '<tr>' . "\n" . '<td>' . "\n" . $blankspace . $open_close_link . " " . $cur_class['name'] . '</td>' . "\n" . '<td align="center">' . "\n" . $qty_user . ' ' . get_lang('UsersMin') . '</td>' . "\n" . '<td align="center">' . "\n"; if (empty($cur_class['course_id'])) { $html_form .= '<a href="' . $_SERVER['PHP_SELF'] . '?cmd=exEnrol&class_id=' . $cur_class['id'] . '"' . ' onclick="return confirmation_enrol(\'' . clean_str_for_javascript($cur_class['name']) . '\');">' . '<img src="' . get_icon_url('enroll') . '" alt="' . get_lang('Enrol to course') . '" />' . "\n" . '</a>' . "\n"; } else { $html_form .= '<a href="' . $_SERVER['PHP_SELF'] . '?cmd=exUnenrol&class_id=' . $cur_class['id'] . '"' . ' onclick="return confirmation_unenrol(\'' . clean_str_for_javascript($cur_class['name']) . '\');">' . '<img src="' . get_icon_url('unenroll') . '" alt="' . get_lang('Unenrol from course') . '" />' . "\n" . '</a>' . "\n"; } $html_form .= '</td>' . "\n" . '</tr>' . "\n"; // RECURSIVE CALL TO DISPLAY CHILDREN if (isset($_SESSION['class_add_visible_class'][$cur_class['id']]) && $_SESSION['class_add_visible_class'][$cur_class['id']] == 'open') { $html_form .= display_tree_class_in_user($class_list, $course_code, $cur_class['id'], $deep + 1); } } } return $html_form; }
/*---------------------------------------------------------------------*/ // set bredcrump $nameTools = get_lang('Enrol class'); ClaroBreadCrumbs::getInstance()->prepend(get_lang('Users'), 'user.php' . claro_url_relay_context('?')); // javascript confirm pop up declaration for header $htmlHeadXtra[] = '<script type="text/javascript"> function confirmation_enrol (name) { if (confirm("' . clean_str_for_javascript(get_lang('Are you sure you want to enrol the whole class on the course ?')) . '")) {return true;} else {return false;} } function confirmation_unenrol (name) { if (confirm("' . clean_str_for_javascript(get_lang('Are you sure you want to unenrol the whole class on the course ?')) . '")) {return true;} else {return false;} } </script>'; // Command list $cmdList[] = array('img' => 'back', 'name' => get_lang('Back to list'), 'url' => claro_htmlspecialchars(Url::Contextualize('user.php')), 'params' => array('onclick' => 'return confirmationEmpty();')); $out = ''; $out .= claro_html_tool_title(get_lang('Enrol class'), null, $cmdList); // Display Forms or dialog box (if needed) $out .= $dialogBox->render(); // Display cols headers $out .= '<table class="claroTable" width="100%" border="0" cellspacing="2">' . "\n" . '<thead>' . "\n" . '<tr class="headerX">' . "\n" . '<th>' . get_lang('Classes') . '</th>' . "\n" . '<th>' . get_lang('Users') . '</th>' . "\n" . '<th>' . get_lang('Enrol to course') . '</th>' . "\n" . '</tr>' . "\n" . '</thead>' . "\n" . '<tbody>' . "\n" . (empty($classList) ? '<tr><td colspan="3">' . get_lang('Nothing to display') . '</td></tr>' : display_tree_class_in_user($classList, claro_get_current_course_id())) . '</tbody>' . "\n" . '</table>' . "\n"; $claroline->display->body->appendContent($out); echo $claroline->display->render();