tra('Mini Quiz'), 'documentation' => 'PluginMiniQuiz', 'description' => tra('Create a quiz using a tracker'), 'prefs' => [ 'feature_trackers', 'wikiplugin_miniquiz' ], 'body' => tra('Instructions::Feedback'), 'iconname' => 'help', 'introduced' => 1, 'format' => 'html', 'params' => [ 'trackerId' => [ 'required' => true, 'name' => tra('Tracker ID'), 'description' => tra('Numeric value representing the miniquiz tracker ID'), 'since' => '1', 'default' => '', 'profile_reference' => 'tracker', ], ], ]; } function rcmp($a, $b) { return mt_rand(-1, 1); } function shuf(&$ar) { srand((double) microtime() * 10000000); uksort($ar, "rcmp"); } function wikiplugin_miniquiz($data, $params) { global $prefs; $trklib = TikiLib::lib('trk'); if ($prefs['feature_trackers'] != 'y' || ! isset($params['trackerId']) || ! ($tracker = $trklib->get_tracker($params['trackerId']))) { $smarty = TikiLib::lib('smarty'); return $smarty->fetch("wiki-plugins/error_tracker.tpl"); } $items = $trklib->list_tracker_items($params['trackerId'], 0, -1, 'lastModif_desc', '', 'o'); $info = []; foreach ($items['data'] as $it) { $id = $it['itemId']; foreach ($it['field_values'] as $val) { $field = $val['name']; $info["$id"]["$field"] = $val['value']; } $info["$id"]['qresult'] = 'n'; } $back = ''; if ($tracker) { $success_mess[] = "Wow !"; $success_mess[] = "Congratulation !"; $success_mess[] = "Success !"; $success_mess[] = "Excellent !"; $success_mess[] = "Superb !"; $success_mess[] = "Bravo !"; $success_mess[] = "Well done !"; $success_comment[] = "You found it right !"; $success_comment[] = "This is correct."; $success_comment[] = "You are the best !"; $success_comment[] = "The answer is correct."; $success_comment[] = "Your cleverness is amazing."; $success_comment[] = "Go on that way !"; $failed_mess[] = "Wrong !"; $failed_mess[] = "Too bad !"; $failed_mess[] = "No luck !"; $failed_mess[] = "Failed !"; $failed_mess[] = "Argh !"; $failed_mess[] = "Missed !"; $failed_comment[] = "Please think before clicking."; $failed_comment[] = "Did you read the question before reading the answer ?"; $failed_comment[] = "Try again."; $failed_comment[] = "Get another chance."; $failed_comment[] = "Think carefully that time."; $failed_comment[] = "Use the force !"; $failed_comment[] = "You should concentrate a little more."; if (isset($_REQUEST['quizit']) and $_REQUEST['quizit']) { if (isset($_REQUEST['answer']) and is_array($_REQUEST['answer'])) { foreach ($_REQUEST['answer'] as $q => $a) { if ($info["$q"]['answer'] == $a) { $info["$q"]['qresult'] = 'y'; } else { $info["$q"]['qresult'] = $a; } } } else { $back .= '