public static function createPage() { if (!isset($_POST['action']) || $_POST['action'] == '') { PAG_Item_Import::HTML_uploadForm(); } if ($_POST['action'] == 'upload') { // checks for errors and that file is uploaded if ($_FILES['uploadedfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { // TODO: check file format parameter (ILIAS5, ...) $ilias = new EXP_Ilias(); $items = $ilias->uploadFile($_FILES['uploadedfile']); if (is_string($items)) { printf("<div class='wrap'><h1>%s</h1></div>", $items); } else { PAG_Item_Import::HTML_itemlist($items, $ilias->dir, $ilias->name); } } else { printf("<div class='wrap'><h1>Error %s</h1></div>", $_FILES['uploadedfile']['error']); } } if ($_POST['action'] == 'import') { $ilias = new EXP_Ilias($_POST['file_dir'], $_POST['file_name']); $items = $ilias->loadAllItems(); foreach ($_POST["import"] as $importIdent) { $item = $items[$importIdent]; // update with metadata $item->learnout_id = $_POST[$importIdent . '_learnout_id']; $item->level["FW"] = $_POST[$importIdent . '__level_FW']; $item->level["KW"] = $_POST[$importIdent . '__level_KW']; $item->level["PW"] = $_POST[$importIdent . '__level_PW']; // save $ilias->saveItem($item, $_POST[$importIdent . '__taxonomy']); printf("<br/>Save item with id %s and ident %s", $item->id, $importIdent); } } }
public function process_bulk_action() { // security check! if (isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) { $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING); $action = 'bulk-' . $this->_args['plural']; if (!wp_verify_nonce($nonce, $action)) { wp_die('Nope! Security check failed!'); } } $action = $this->current_action(); switch ($action) { case 'removefrombasket': $b_old = get_user_meta(get_current_user_id(), 'itembasket', true); if ($_REQUEST['itemids'] != null) { $b_new = array_diff($b_old, $_REQUEST['itemids']); } if ($_REQUEST['itemid'] != null) { $b_new = array_diff($b_old, array($_REQUEST['itemid'])); } $x = update_user_meta(get_current_user_id(), 'itembasket', $b_new); return 'removefrombasket'; case 'exportILIAS5': $ilias = new EXP_Ilias(); $link = $ilias->generateExport($_REQUEST['itemids']); printf("<h2><a href='%s'>Download</a></h2>", $link); // echo (implode (',', $_REQUEST['itemids']) . ' sollen in das ILIAS-Format exportiert werden.'); // echo ("</br><a href='". plugins_url('download.php', __FILE__) . "?itemids=" . implode (',', $_REQUEST['itemids']) . "'>Download (" . count($_REQUEST['itemids']) . " Items)</a>"); // echo (plugins_url('download.php', __FILE__)); // echo ("<script>window.open('http://www.colorado.edu/conflict/peace/download/peace_essay.ZIP');</script>"); // echo ("<script>document.location = 'data:application/octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A';</script>"); return 'exportILIAS5'; case 'viewitems': return 'viewitems'; default: // do nothing or something else return; break; } return; }
public static function createPageView() { $itemids = array(); /* try to get learning outcomes */ $post_label = "Learning Outcome"; if ($_REQUEST['learnoutid'] != null) { $itemids = [$_REQUEST['learnoutid']]; } if ($_REQUEST['learnoutids'] != null) { if (is_array($_REQUEST['learnoutids'])) { $itemids = $_REQUEST['learnoutids']; } if (is_string($_REQUEST['learnoutids'])) { $itemids = explode(",", $_REQUEST["learnoutids"]); } } if (count($itemids) == 0) { // no learning outcomes found --> get reviews $post_label = "Review"; if ($_REQUEST['reviewid'] != null) { $itemids = [$_REQUEST['reviewid']]; } if ($_REQUEST['reviewids'] != null) { if (is_array($_REQUEST['reviewids'])) { $itemids = $_REQUEST['reviewids']; } if (is_string($_REQUEST['reviewids'])) { $itemids = explode(",", $_REQUEST["reviewids"]); } } } if (count($itemids) == 0) { // nothing found --> get items $post_label = "Item"; if ($_REQUEST['itemid'] != null) { $itemids = [$_REQUEST['itemid']]; } if ($_REQUEST['itemids'] != null) { if (is_array($_REQUEST['itemids'])) { $itemids = $_REQUEST['itemids']; } if (is_string($_REQUEST['itemids'])) { $itemids = explode(",", $_REQUEST["itemids"]); } } // fallback: get items from basket if (count($itemids) == 0) { $itemids = RoleTaxonomy::getCurrentBasket(); } // get_user_meta(get_current_user_id(), 'itembasket', true); } $html_list = ""; $html_select = "<form><select onChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) { this.form.nextSibling.childNodes[x].style.display = ((this.value<0) || (this.value==x)) ? \"block\" : \"none\"; }'>"; $html_select .= sprintf('<option value="-1" selected>[All %1$d %2$ss]</option>', count($itemids), $post_label); $count = 0; $items = array(); foreach ($itemids as $item_id) { $post = get_post($item_id); if ($post == null) { continue; } $item = null; if ($post->post_type == 'itemsc') { $item = new EAL_ItemSC(); } if ($post->post_type == 'itemmc') { $item = new EAL_ItemMC(); } if ($post->post_type == 'learnout') { $item = new EAL_LearnOut(); } if ($post->post_type == 'review') { $item = new EAL_Review(); } if ($item != null) { $item->loadById($item_id); $html_select .= sprintf("<option value='%d'>%s</option>", $count, $post->post_type == 'review' ? $item->getItem()->title : $item->title); $html_list .= sprintf("<div style='margin-top:2em;'><hr/>%s<br style='clear:both;'/></div>", substr($post->post_type, 0, 4) == "item" ? CPT_Item::getHTML_Item($item, FALSE) : ($post->post_type == 'learnout' ? CPT_LearnOut::getHTML_LearnOut($item) : CPT_Review::getHTML_Review($item))); $count++; array_push($items, $item); } } $html_select .= "</select> <input type='checkbox' checked \r\n\t\t\tonChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) { this.form.nextSibling.childNodes[x].querySelector(\"#postbox-container-1\").style.display = (this.checked==true) ? \"block\" : \"none\"; }'/> Show Metadata</form>"; if ($post_label == "Item") { $html_info = sprintf("<form style='margin-top:5em' enctype='multipart/form-data' action='admin.php?page=view&download=1&itemids=%s' method='post'><table class='form-table'><tbody'>", implode(",", $itemids)); $html_info .= sprintf("<tr><th style='padding-top:0px; padding-bottom:0px;'><label>%s</label></th>", "Number of Items"); $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>"); $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($items)); $html_info .= sprintf("</td></tr>"); // Min / Max for all categories $categories = array("type", "dim", "level", "topic1"); foreach ($categories as $category) { $html_info .= sprintf("<tr><th style='padding-bottom:0.5em;'><label>%s</label></th></tr>", EAL_Item::$category_label[$category]); foreach (PAG_Explorer::groupBy($category, $items, NULL, true) as $catval => $catitems) { $html_info .= sprintf("<tr><td style='padding-top:0px; padding-bottom:0px;'><label>%s</label></td>", $category == "topic1" ? $catval : EAL_Item::$category_value_label[$category][$catval]); $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>"); $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($catitems)); $html_info .= sprintf("</td></tr>"); } } $html_info .= sprintf("<tr><th><button type='submit' name='action' value='download'>Download</button></th><tr>"); $html_info .= sprintf("</tbody></table></form></div>"); } printf('<div class="wrap"><h1>%1$s Viewer</h1>', $post_label); if ($_REQUEST['download'] == '1') { $ilias = new EXP_Ilias(); $link = $ilias->generateExport($itemids); printf("<h2><a href='%s'>Download</a></h2>", $link); } if (count($itemids) > 1 || count($itemids) == 1) { print $html_select; print "<div style='margin-top:2em'>{$html_list}{$html_info}</div>"; } else { print "<div style='margin-top:2em'>{$html_list}</div>"; } print "</div>"; }
private function createQTI($itemids) { $dom = DOMDocument::loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE questestinterop SYSTEM "ims_qtiasiv1p2p1.dtd"> <questestinterop></questestinterop> '); foreach ($itemids as $item_id) { $post = get_post($item_id); if ($post == null) { continue; } if ($post->post_type == 'itemsc') { $item = new EAL_ItemSC(); $item_data = array("questiontype" => "SINGLE CHOICE QUESTION", "ident" => "MCSR", "rcardinality" => "Single"); } if ($post->post_type == 'itemmc') { $item = new EAL_ItemMC(); $item_data = array("questiontype" => "MULTIPLE CHOICE QUESTION", "ident" => "MCMR", "rcardinality" => "Multiple"); } $item->loadById($item_id); $xml_IT = $dom->createElement("item"); $xml_IT->setAttribute("ident", "il_0_qst_{$item_id}"); $xml_IT->setAttribute("title", $item->title); $xml_IT->setAttribute("maxattempts", 1); $xml_IT->appendChild($dom->createElement("qticomment", "[EALID:{$item_id}]")); $xml_IT->appendChild($dom->createElement("duration", "P0Y0M0DT0H1M0S")); /* QTI Metadata*/ $xml_QM = $dom->createElement("qtimetadata"); $meta = array("ILIAS_VERSION" => "5.0.8 2015-11-24", "QUESTIONTYPE" => $item_data["questiontype"], "AUTHOR" => get_the_author_meta('login', get_post_field('post_author', $post->ID)), "additional_cont_edit_mode" => "default", "externalId" => "il_0_qst_{$item_id}", "ealid" => $item_id, "thumb_size" => "", "feedback_setting" => 1); foreach ($meta as $key => $value) { $x = $dom->createElement("qtimetadatafield"); $x->appendChild($dom->createElement("fieldlabel", $key)); $x->appendChild($dom->createElement("fieldentry", $value)); $xml_QM->appendChild($x); } $xml_IM = $dom->createElement("itemmetadata"); $xml_IM->appendChild($xml_QM); $xml_IT->appendChild($xml_IM); /* Presentation */ $xml_PR = $dom->createElement("presentation"); $xml_PR->setAttribute("label", $item->title); $xml_FL = $dom->createElement("flow"); $xml_FL->appendChild(EXP_Ilias::createMaterialElement($dom, "text/html", $item->description . "<hr/>" . $item->question)); $xml_RL = $dom->createElement("response_lid"); $xml_RL->setAttribute("ident", $item_data["ident"]); $xml_RL->setAttribute("rcardinality", $item_data["rcardinality"]); $xml_RC = $dom->createElement("render_choice"); $xml_RC->setAttribute("shuffle", "Yes"); foreach ($item->answers as $number => $answer) { $xml_LAB = $dom->createElement("response_label"); $xml_LAB->setAttribute("ident", $number); $xml_LAB->appendChild(EXP_Ilias::createMaterialElement($dom, "text/plain", $answer["answer"])); $xml_RC->appendChild($xml_LAB); } $xml_RL->appendChild($xml_RC); $xml_FL->appendChild($xml_RL); $xml_PR->appendChild($xml_FL); $xml_IT->appendChild($xml_PR); $xml_RP = $dom->createElement("resprocessing"); $xml_OC = $dom->createElement("outcomes"); $xml_DV = $dom->createElement("decvar"); $xml_OC->appendChild($xml_DV); $xml_RP->appendChild($xml_OC); foreach ($item->answers as $number => $answer) { foreach (array(1, 0) as $checked) { $xml_RC = $dom->createElement("respcondition"); $xml_RC->setAttribute("continue", "Yes"); $xml_CV = $dom->createElement("conditionvar"); $xml_NO = $dom->createElement("not"); $xml_VE = $dom->createElement("varequal", $number); $xml_VE->setAttribute("respident", $item_data["ident"]); if ($checked == 1) { $xml_CV->appendChild($xml_VE); } else { $xml_NO->appendChild($xml_VE); $xml_CV->appendChild($xml_NO); } $xml_RC->appendChild($xml_CV); // if ($item->type == "itemsc") array_push ($item->answers, array ("answer" => $v["text"], "points" => $v["positive"])); // if ($item->type == "itemmc") array_push ($item->answers, array ("answer" => $v["text"], "positive" => $v["positive"], "negative" => $v["negative"])); if ($item->type == "itemsc") { $xml_SV = $dom->createElement("setvar", $checked == 1 ? $answer['points'] : 0); } if ($item->type == "itemmc") { $xml_SV = $dom->createElement("setvar", $checked == 1 ? $answer['positive'] : $answer['negative']); } $xml_SV->setAttribute("action", "Add"); $xml_RC->appendChild($xml_SV); $xml_RP->appendChild($xml_RC); } } $xml_IT->appendChild($xml_RP); $dom->documentElement->appendChild($xml_IT); } return $dom; }