public function get_units() { $units = $this->get_unit_objects(); //print_r($units); $um = new unitmanager($this); $cu = array(); foreach ($units as $unitobject) { $nu = $um->create_unit($unitobject); if (is_object($nu)) { $cu[] = $nu; } } return $cu; }
<?php require_once "classes/unitmanager.class.php"; if (!isset($portal)) { $portal = lms_portal::get_instance(); $portal->initialize(GUEST_NOT_ALLOWED); } if (!isset($html_handler)) { //$html_handler_course = new koala_html_course( $course ); //$html_handler_course->set_context( "units", array( "subcontext" => "unit" ) ); $html_handler = $owner->get_html_handler(); $html_handler->set_context("units", array("subcontext" => "unit")); } $unitmanager = unitmanager::create_unitmanager($course); $akt_unit = $unitmanager->get_unittype($unit->get_attribute("UNIT_TYPE")); include $akt_unit->get_path() . "/modules/" . $akt_unit->get_name() . "_delete.php"; //$html_handler_course->set_html_left( $content->get()); $portal->set_page_main(array(array("link" => $backlink . "units/", "name" => str_replace("%COURSE", $course->get_course_name(), gettext("All units of '%COURSE'"))), array("name" => str_replace("%UNIT", $unit->get_name(), gettext("Unit '%UNIT'")))), $html_handler->get_html(), ""); $portal->show_html();
function handle_path($path, $owner = FALSE, $portal = FALSE) { if (is_string($path)) { $path = url_parse_rewrite_path($path); } if (!is_object($owner)) { throw new Exception("No owner provided.", E_PARAMETER); } if (!isset($portal) || !is_object($portal)) { $portal = lms_portal::get_instance(); $portal->initialize(GUEST_NOT_ALLOWED); } $portal_user = $portal->get_user(); $user = lms_steam::get_current_user(); $scg = steam_factory::get_object($GLOBALS["STEAM"]->get_id(), STEAM_COURSES_GROUP, CLASS_GROUP); //$current_semester = steam_factory::groupname_to_object( $GLOBALS[ "STEAM" ]->get_id(), $scg->get_name() . "." . $path[0]); $current_semester = $owner->get_semester(); $backlink = $owner->get_url() . $this->get_path_name() . "/"; //$backlink = PATH_URL . "extensions/units/" . $path[0] ."/" . $path[1] . "/units/"; switch (TRUE) { case isset($path[0]) && $path[0] == "new": if (!$portal_user->is_logged_in()) { throw new Exception("Access denied. Please login.", E_USER_AUTHORIZATION); } $course = $owner; include self::$PATH . "unit_new.php"; exit; break; case isset($path[0]) && is_numeric($path[0]) && isset($path[1]) && $path[1] == "edit": if (!$portal_user->is_logged_in()) { throw new Exception("Access denied. Please login.", E_USER_AUTHORIZATION); } $course = $owner; $steam_unit = steam_factory::get_object($GLOBALS["STEAM"]->get_id(), (int) $path[0]); if (!is_object($steam_unit)) { include PATH_PUBLIC . "bad_link.php"; exit; } global $unit; $unit = koala_object::get_koala_object($steam_unit); if (!is_object($unit)) { include PATH_PUBLIC . "bad_link.php"; exit; } if (!$steam_unit->check_access_write($user)) { throw new Exception(gettext("You have no write access for this unit"), E_USER_RIGHTS); } $backlink = $backlink . $path[0] . "/"; include self::$PATH . "unit_edit.php"; exit; break; case isset($path[0]) && is_numeric($path[0]) && isset($path[1]) && $path[1] == "delete": if (!$portal_user->is_logged_in()) { throw new Exception("Access denied. Please login.", E_USER_AUTHORIZATION); } $course = $owner; $steam_unit = steam_factory::get_object($GLOBALS["STEAM"]->get_id(), (int) $path[0]); if (!is_object($steam_unit)) { include PATH_PUBLIC . "bad_link.php"; exit; } global $unit; $unit = koala_object::get_koala_object($steam_unit); if (!is_object($unit)) { include PATH_PUBLIC . "bad_link.php"; exit; } if (!$steam_unit->check_access_write($user)) { throw new Exception(gettext("You have no write access for this unit"), E_USER_RIGHTS); } $backlink = $backlink . $path[0] . "/"; include self::$PATH . "unit_delete.php"; exit; break; case isset($path[0]) && !empty($path[0]): if (!$portal_user->is_logged_in()) { throw new Exception("Access denied. Please login.", E_USER_AUTHORIZATION); } if (!is_numeric($path[0])) { return FALSE; } // not a unit id $steam_unit = steam_factory::get_object($GLOBALS["STEAM"]->get_id(), (int) $path[0]); if (!is_object($steam_unit)) { return FALSE; } // not a unit $unit_type = $steam_unit->get_attribute('UNIT_TYPE'); if (!is_string($unit_type) || empty($unit_type)) { return FALSE; } // not a valid unit $unit_extension = unitmanager::create_unitmanager($owner)->get_unittype($unit_type); if (!is_object($unit_extension)) { return FALSE; } // no matching unit extension if ($unit_extension->handle_path($path, $owner, $portal)) { exit; } else { return FALSE; } break; default: if (!$portal_user->is_logged_in()) { throw new Exception("Access denied. Please login.", E_USER_AUTHORIZATION); } $course = $owner; include self::$PATH . "units.php"; exit; break; } return FALSE; }
} else { $nr_show = 10; } if ($nr_show > 0) { $paginator_text .= ', <a href="' . $course->get_url() . 'units/?nrshow=0">' . gettext('show all') . '</a>'; } $start = $portal->set_paginator($content, $nr_show, count($units), '(' . $paginator_text . ')'); $end = $start + $nr_show > count($units) ? count($units) : $start + $nr_show; $content->setVariable("LABEL_UNITS", gettext("Units for the course") . " '" . h($course->get_attribute("OBJ_DESC")) . "'"); $content->setVariable("LABEL_NAME_DESCRIPTION", gettext("Name, description")); $content->setVariable("LABEL_TYPE", gettext("Unit type")); $content->setVariable("LABEL_ACTIONS", gettext("Actions")); $item_ids = array(); // initialize unitmanager for admin view if ($is_admin) { $unitmanager = new unitmanager(); } $tnr_read = array(); // Use buffer to determine read access for ($i = $start; $i < $end; $i++) { $unit = $units[$i]; if (is_object($unit)) { $tnr_read[$unit->get_id()] = $unit->check_access_read($current_user, TRUE); } } $result_read = $GLOBALS["STEAM"]->buffer_flush(); for ($i = $start; $i < $end; $i++) { $unit = $units[$i]; if (is_object($unit) && $result_read[$tnr_read[$unit->get_id()]]) { $content->setCurrentBlock("BLOCK_UNIT"); if (get_class($unit) === "steam_container") {
<?php define("PATH_TEMPLATES_UNITS_BASE", PATH_EXTENSIONS . "units_base/templates/"); require_once "classes/unitmanager.class.php"; $portal = lms_portal::get_instance(); $portal->initialize(GUEST_NOT_ALLOWED); $user = lms_steam::get_current_user(); if (!isset($owner) && isset($_POST["owner"])) { $steam_owner = steam_factory::get_object($GLOBALS["STEAM"]->get_id(), (int) $_POST["owner"]); $owner = koala_object::get_koala_object($steam_owner); } if (!$owner->is_admin($user)) { throw new Exception("No group admin!", E_ACCESS); } $um = unitmanager::create_unitmanager($owner); $content_ready = FALSE; if ($_SERVER["REQUEST_METHOD"] == "POST") { $problems = ""; $hints = ""; if (empty($problems)) { if (isset($_POST["unit_new"]) && is_array($_POST["unit_new"])) { $unitname = array_keys($_POST["unit_new"]); $unitname = $unitname[0]; $akt_unit = $um->get_unittype($unitname); if ($akt_unit != FALSE) { $akt_unit->set_course($owner); if (isset($_POST["values"])) { include $akt_unit->get_path() . "/modules/" . $akt_unit->get_name() . "_new.php"; $content_ready = TRUE; $html_ready = $unit_new_html; } else {