00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033 require_once "include/inc.header.php";
00034 require_once "content/classes/class.ilExercise.php";
00035 require_once "assessment/classes/class.assQuestionGUI.php";
00036 require_once "classes/class.ilObjectGUI.php";
00037 require_once "assessment/classes/class.ilObjQuestionPool.php";
00038 require_once "classes/class.ilMetaDataGUI.php";
00039
00040 class ilExerciseGUI extends assQuestionGUI {
00041 var $ilias;
00042 var $objExercise;
00043
00044 function ilExerciseGUI ($lm_id = 0, $chapter_id = 0) {
00045 global $ilias;
00046 $this->ilias = $ilias;
00047
00048 if ($lm_id != 0) {
00049
00050 $objExercise = new ilExercise($lm_id, $chapter_id);
00051
00052 $this->previewQuestion(2);
00053 } else {
00054 $this->raiseError("No Learning Module Id given, abort!", $this->ilias->error_obj->MESSAGE);
00055 }
00056 }
00057
00058 function showList () {
00059
00060
00061 }
00062
00063 function previewQuestion($question_id) {
00064
00065 $question_gui =& new assQuestionGUI();
00066 $question =& $question_gui->create_question("", $question_id);
00067 $question_gui->out_preview();
00068 }
00069
00070 function editQuestionForm($type, $question_id = 0) {
00071
00072 }
00073
00074
00075 }
00076
00077
00078 function exercise()
00079 {
00080 global $rbacsystem;
00081 $type = $_GET["sel_question_types"];
00082 if ($_GET["preview"])
00083 {
00084 $this->out_preview_page($_GET["preview"]);
00085 return;
00086 }
00087 if (($_GET["edit"]) or ($type))
00088 {
00089 $this->set_question_form($type, $_GET["edit"]);
00090 return;
00091 }
00092 if ($_POST["cmd"]["create"])
00093 {
00094 $this->set_question_form($_POST["sel_question_types"]);
00095 return;
00096 }
00097 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "assessment/templates/default/tpl.qpl_questions.html", true);
00098 $this->tpl->addBlockFile("CREATE_QUESTION", "create_question", "assessment/templates/default/tpl.il_as_create_new_question.html", true);
00099 $this->tpl->addBlockFile("A_BUTTONS", "a_buttons", "assessment/templates/default/tpl.il_as_qpl_action_buttons.html", true);
00100 $this->tpl->addBlockFile("FILTER_QUESTION_MANAGER", "filter_questions", "assessment/templates/default/tpl.il_as_qpl_filter_questions.html", true);
00101
00102 $add_parameter = $this->get_add_parameter();
00103
00104
00105 $checked_questions = array();
00106 foreach ($_POST as $key => $value)
00107 {
00108 if (preg_match("/cb_(\d+)/", $key, $matches))
00109 {
00110 array_push($checked_questions, $matches[1]);
00111 }
00112 }
00113
00114 if (strlen($_POST["cmd"]["edit"]) > 0)
00115 {
00116
00117 if (count($checked_questions) > 1)
00118 {
00119 sendInfo($this->lng->txt("qpl_edit_select_multiple"));
00120 }
00121 elseif (count($checked_questions) == 0)
00122 {
00123 sendInfo($this->lng->txt("qpl_edit_select_none"));
00124 }
00125 else
00126 {
00127 if ($rbacsystem->checkAccess('edit', $this->ref_id))
00128 {
00129 header("location:" . $_SERVER["PHP_SELF"] . $add_parameter . "&edit=" . $checked_questions[0]);
00130 exit();
00131 }
00132 else
00133 {
00134 sendInfo($this->lng->txt("qpl_edit_rbac_error"));
00135 }
00136 }
00137 }
00138 if (strlen($_POST["cmd"]["delete"]) > 0)
00139 {
00140
00141 if (count($checked_questions) > 0)
00142 {
00143 if ($rbacsystem->checkAccess('edit', $this->ref_id))
00144 {
00145 foreach ($checked_questions as $key => $value)
00146 {
00147 $this->object->delete_question($value);
00148 }
00149 }
00150 else
00151 {
00152 sendInfo($this->lng->txt("qpl_delete_rbac_error"));
00153 }
00154 }
00155 elseif (count($checked_questions) == 0)
00156 {
00157 sendInfo($this->lng->txt("qpl_delete_select_none"));
00158 }
00159 }
00160 if (strlen($_POST["cmd"]["duplicate"]) > 0)
00161 {
00162
00163 if (count($checked_questions) > 0)
00164 {
00165 foreach ($checked_questions as $key => $value)
00166 {
00167 $question_gui =& new assQuestionGUI();
00168 $question =& $question_gui->create_question("", $value);
00169 $question_gui->question->duplicate();
00170 }
00171 }
00172 elseif (count($checked_questions) == 0)
00173 {
00174 sendInfo($this->lng->txt("qpl_duplicate_select_none"));
00175 }
00176 }
00177
00178 if (strlen($_POST["cmd"]["export"]) > 0)
00179 {
00180
00181 if (count($checked_questions) > 0)
00182 {
00183
00184 }
00185 elseif (count($checked_questions) == 0)
00186 {
00187 sendInfo($this->lng->txt("qpl_export_select_none"));
00188 }
00189 }
00190 $filter_fields = array(
00191 "title" => $this->lng->txt("title"),
00192 "comment" => $this->lng->txt("description"),
00193 "author" => $this->lng->txt("author"),
00194 );
00195 $this->tpl->setCurrentBlock("filterrow");
00196 foreach ($filter_fields as $key => $value)
00197 {
00198 $this->tpl->setVariable("VALUE_FILTER_TYPE", "$key");
00199 $this->tpl->setVariable("NAME_FILTER_TYPE", "$value");
00200 if (!$_POST["cmd"]["reset"])
00201 {
00202 if (strcmp($_POST["sel_filter_type"], $key) == 0)
00203 {
00204 $this->tpl->setVariable("VALUE_FILTER_SELECTED", " selected=\"selected\"");
00205 }
00206 }
00207 $this->tpl->parseCurrentBlock();
00208 }
00209
00210 $this->tpl->setCurrentBlock("filter_questions");
00211 $this->tpl->setVariable("FILTER_TEXT", $this->lng->txt("filter"));
00212 $this->tpl->setVariable("TEXT_FILTER_BY", $this->lng->txt("by"));
00213 if (!$_POST["cmd"]["reset"])
00214 {
00215 $this->tpl->setVariable("VALUE_FILTER_TEXT", $_POST["filter_text"]);
00216 }
00217 $this->tpl->setVariable("VALUE_SUBMIT_FILTER", $this->lng->txt("set_filter"));
00218 $this->tpl->setVariable("VALUE_RESET_FILTER", $this->lng->txt("reset_filter"));
00219 $this->tpl->parseCurrentBlock();
00220
00221 if (!$_POST["cmd"]["reset"])
00222 {
00223 if (strlen($_POST["filter_text"]) > 0)
00224 {
00225 switch($_POST["sel_filter_type"])
00226 {
00227 case "title":
00228 $where = " AND qpl_questions.title LIKE " . $this->ilias->db->db->quote("%" . $_POST["filter_text"] . "%");
00229 break;
00230 case "comment":
00231 $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->db->quote("%" . $_POST["filter_text"] . "%");
00232 break;
00233 case "author":
00234 $where = " AND qpl_questions.author LIKE " . $this->ilias->db->db->quote("%" . $_POST["filter_text"] . "%");
00235 break;
00236 }
00237 }
00238 }
00239
00240
00241
00242
00243 $this->tpl->setCurrentBlock("standard");
00244 $this->tpl->setVariable("EDIT", $this->lng->txt("edit"));
00245 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00246 $this->tpl->setVariable("DUPLICATE", $this->lng->txt("duplicate"));
00247 $this->tpl->setVariable("EXPORT", $this->lng->txt("export"));
00248 $this->tpl->parseCurrentBlock();
00249
00250 $this->tpl->setCurrentBlock("Footer");
00251 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
00252 $this->tpl->parseCurrentBlock();
00253
00254 $this->tpl->setCurrentBlock("QTab");
00255
00256
00257 if (count($_GET["sort"]))
00258 {
00259 foreach ($_GET["sort"] as $key => $value)
00260 {
00261 switch($key)
00262 {
00263 case "title":
00264 $order = " ORDER BY title $value";
00265 $img_title = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00266 break;
00267 case "comment":
00268 $order = " ORDER BY comment $value";
00269 $img_comment = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00270 break;
00271 case "type":
00272 $order = " ORDER BY question_type_id $value";
00273 $img_type = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00274 break;
00275 case "author":
00276 $order = " ORDER BY author $value";
00277 $img_author = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00278 break;
00279 case "created":
00280 $order = " ORDER BY created $value";
00281 $img_created = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00282 break;
00283 case "updated":
00284 $order = " ORDER BY TIMESTAMP $value";
00285 $img_updated = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00286 break;
00287 }
00288 }
00289 }
00290
00291
00292 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.obj_fi = " . $_GET["ref_id"] . " $where$order";
00293 $query_result = $this->ilias->db->query($query);
00294 $colors = array("tblrow1", "tblrow2");
00295 $counter = 0;
00296 if ($query_result->numRows() > 0)
00297 {
00298 while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
00299 {
00300 if (($data->private != 1) or ($data->owner == $this->ilias->account->id)) {
00301 $this->tpl->setVariable("QUESTION_ID", $data->question_id);
00302 if ($rbacsystem->checkAccess('edit', $this->ref_id)) {
00303 $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&edit=$data->question_id\">$data->title</a>");
00304 } else {
00305 $this->tpl->setVariable("QUESTION_TITLE", $data->title);
00306 }
00307 $this->tpl->setVariable("PREVIEW", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&preview=$data->question_id\">" . $this->lng->txt("preview") . "</a>");
00308 $this->tpl->setVariable("QUESTION_COMMENT", $data->comment);
00309 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
00310 $this->tpl->setVariable("QUESTION_AUTHOR", $data->author);
00311 $this->tpl->setVariable("QUESTION_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data->created), "date"));
00312 $this->tpl->setVariable("QUESTION_UPDATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data->TIMESTAMP), "date"));
00313 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
00314 $this->tpl->parseCurrentBlock();
00315 $counter++;
00316 }
00317 }
00318 }
00319
00320
00321 if ($counter == 0) {
00322 $this->tpl->setCurrentBlock("Emptytable");
00323 $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
00324 $this->tpl->parseCurrentBlock();
00325 }
00326
00327
00328 $this->tpl->setCurrentBlock("QTypes");
00329 $query = "SELECT * FROM qpl_question_type ORDER BY question_type_id";
00330 $query_result = $this->ilias->db->query($query);
00331 while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
00332 {
00333 $this->tpl->setVariable("QUESTION_TYPE_ID", $data->type_tag);
00334 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
00335 $this->tpl->parseCurrentBlock();
00336 }
00337 $this->tpl->setCurrentBlock("CreateQuestion");
00338 $this->tpl->setVariable("QUESTION_ADD", $this->lng->txt("create"));
00339 $this->tpl->setVariable("ACTION_QUESTION_ADD", $_SERVER["PHP_SELF"] . $add_parameter);
00340 $this->tpl->parseCurrentBlock();
00341
00342
00343 $sort = array(
00344 "title" => $_GET["sort"]["title"],
00345 "comment" => $_GET["sort"]["comment"],
00346 "type" => $_GET["sort"]["type"],
00347 "author" => $_GET["sort"]["author"],
00348 "created" => $_GET["sort"]["created"],
00349 "updated" => $_GET["sort"]["updated"]
00350 );
00351 foreach ($sort as $key => $value) {
00352 if (strcmp($value, "ASC") == 0) {
00353 $sort[$key] = "DESC";
00354 } else {
00355 $sort[$key] = "ASC";
00356 }
00357 }
00358
00359 $this->tpl->setCurrentBlock("adm_content");
00360
00361 $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>$img_title");
00362 $this->tpl->setVariable("QUESTION_COMMENT", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[comment]=" . $sort["comment"] . "\">" . $this->lng->txt("description") . "</a>$img_comment");
00363 $this->tpl->setVariable("QUESTION_TYPE", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[type]=" . $sort["type"] . "\">" . $this->lng->txt("question_type") . "</a>$img_type");
00364 $this->tpl->setVariable("QUESTION_AUTHOR", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[author]=" . $sort["author"] . "\">" . $this->lng->txt("author") . "</a>$img_author");
00365 $this->tpl->setVariable("QUESTION_CREATED", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[created]=" . $sort["created"] . "\">" . $this->lng->txt("create_date") . "</a>$img_created");
00366 $this->tpl->setVariable("QUESTION_UPDATED", "<a href=\"" . $_SERVER["PHP_SELF"] . "$add_parameter&sort[updated]=" . $sort["updated"] . "\">" . $this->lng->txt("last_update") . "</a>$img_updated");
00367 $this->tpl->setVariable("BUTTON_CANCEL", $this->lng->txt("cancel"));
00368 $this->tpl->setVariable("ACTION_QUESTION_FORM", $_SERVER["PHP_SELF"] . $add_parameter);
00369 $this->tpl->parseCurrentBlock();
00370 }
00371 ?>