/**
  * Append rejudge all link to the teachers' view subimissions link
  */
 function submittedlink($allgroups = false)
 {
     global $USER, $CFG;
     $parent_link = parent::submittedlink($allgroups);
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     if (has_capability('mod/assignment:grade', $context)) {
         $rejudge_link = element_to_popup_window('link', '/mod/assignment/type/onlinejudge/rejudge.php?id=' . $this->cm->id, null, get_string('rejudgeall', 'assignment_onlinejudge'), 330, 500, null, null, true, null, null);
         $testcase_link = '<a href = "' . $CFG->wwwroot . '/mod/assignment/type/onlinejudge/testcase.php?id=' . $this->cm->id . '">' . get_string('managetestcases', 'assignment_onlinejudge') . '</a>';
         return $parent_link . '<br />' . $rejudge_link . '<br />' . $testcase_link;
     } else {
         return $parent_link;
     }
 }
Example #2
0
/**
 * Creates and displays (or returns) a buttons to a popup window, using element_to_popup_window function.
 *
 * @return string html code to display a button to a popup window.
 * @see element_to_popup_window()
 */
function button_to_popup_window($url, $name = null, $linkname = null, $height = 400, $width = 500, $title = null, $options = null, $return = false, $id = null, $class = null)
{
    return element_to_popup_window('button', $url, $name, $linkname, $height, $width, $title, $options, $return, $id, $class);
}
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     // Update preferences
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 20, PARAM_INT);
         $perpage = $perpage <= 0 ? 20 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         $moderationtarget = optional_param('moderationtarget', 0, PARAM_INT);
         $moderationtarget = $moderationtarget <= 0 ? 0 : $moderationtarget;
         set_user_preference('assignment_moderationtarget', $moderationtarget);
     }
     // Get preferences
     $perpage = get_user_preferences('assignment_perpage', 10);
     $moderationtarget = get_user_preferences('assignment_moderationtarget', 0);
     // Some shortcuts to make the code read better
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $page = optional_param('page', 0, PARAM_INT);
     // Log this view
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     // Print header and navigation breadcrumbs
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     // Print tabs at top of page
     $tabs = array();
     $row = array();
     $inactive = array();
     $activated = array();
     $row[] = new tabobject('criteria', "type/peerreview/" . self::CRITERIA_FILE . "?id=" . $this->cm->id . "&a=" . $this->assignment->id, get_string('criteria', 'assignment_peerreview'));
     $row[] = new tabobject('submissions', '', get_string('submissions', 'assignment_peerreview'));
     $tabs[] = $row;
     $currenttab = 'submissions';
     $inactive[] = 'submissions';
     $activated[] = 'submissions';
     print_tabs($tabs, $currenttab, $inactive, $activated);
     // Print optional message
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     // Check to see if groups are being used in this assignment
     // find out current groups mode
     // $groupmode = groups_get_activity_groupmode($cm);
     // $currentgroup = groups_get_activity_group($cm, true);
     // groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/assignment/submissions.php?id=' . $cm->id);
     // Get all ppl that are allowed to submit assignments
     // if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id')) {
         $users = array_keys($users);
     }
     // Filter out teachers
     if ($users && ($teachers = get_users_by_capability($context, 'mod/assignment:grade', 'u.id'))) {
         $users = array_diff($users, array_keys($teachers));
     }
     // Warn if class is too small
     if (count($users) < 5) {
         notify(get_string('numberofstudentswarning', 'assignment_peerreview'));
     }
     // if groupmembersonly used, remove users who are not in any group
     // if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
     // if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
     // $users = array_intersect($users, array_keys($groupingusers));
     // }
     // }
     // Create the table to be shown
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $tablecolumns = array('picture', 'fullname', 'submitted', 'reviews', 'moderations', 'status', 'seedoreviews', 'suggestedmark', 'finalgrade');
     $table->define_columns($tablecolumns);
     $tableheaders = array('', get_string('fullname'), get_string('submission', 'assignment_peerreview'), get_string('reviewsbystudent', 'assignment_peerreview') . helpbutton('reviewsbystudent', get_string('reviewsbystudent', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('moderationstitle', 'assignment_peerreview') . helpbutton('moderationtarget', get_string('moderationtarget', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('status') . helpbutton('status', get_string('status', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('seedoreviews', 'assignment_peerreview') . helpbutton('seedoreviews', get_string('seedoreviews', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('suggestedgrade', 'assignment_peerreview') . helpbutton('suggestedgrade', get_string('suggestedgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('finalgrade', 'assignment_peerreview') . helpbutton('finalgrade', get_string('finalgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true));
     $table->define_headers($tableheaders);
     // $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
     // $table->sortable(true, 'submitted');
     $table->sortable(false);
     $table->collapsible(true);
     // $table->initialbars(true);
     $table->initialbars(false);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('submitted', 'submitted');
     $table->column_class('reviews', 'reviews');
     $table->column_class('moderations', 'moderations');
     $table->column_class('status', 'status');
     $table->column_class('seedoreviews', 'seedoreviews');
     $table->column_class('suggestedmark', 'suggestedmark');
     $table->column_class('finalgrade', 'finalgrade');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '99%');
     $table->set_attribute('align', 'center');
     $table->column_style('submitted', 'text-align', $alignment);
     $table->column_style('finalgrade', 'text-align', 'center');
     /*
     		$table->no_sorting('picture');
     		$table->no_sorting('fullname');
     		$table->no_sorting('submitted');
     		$table->no_sorting('reviews');
     		$table->no_sorting('moderations');
     		$table->no_sorting('status');
     		$table->no_sorting('seedoreviews');
     		$table->no_sorting('suggestedmark');
     		$table->no_sorting('finalgrade');
     */
     $table->setup();
     if (empty($users)) {
         print_heading(get_string('nosubmitusers', 'assignment'));
         return true;
     }
     // Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                       s.id AS submissionid, s.grade,
                       s.timecreated as submitted, s.timemarked ';
     $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id=s.userid AND s.assignment=' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $sort = 'ORDER BY COALESCE(submitted,2147483647) ASC, submissionid ASC, u.lastname ASC';
     // if ($sort = $table->get_sql_sort()) {
     // $sort = ' ORDER BY '.$sort;
     // }
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     // Get the criteria
     $criteriaList = get_records_list('assignment_criteria', 'assignment', $this->assignment->id, 'ordernumber');
     $numberOfCriteria = 0;
     if (is_array($criteriaList)) {
         $criteriaList = array_values($criteriaList);
         $numberOfCriteria = count($criteriaList);
     }
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         //            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             //              $final_grade = $grading_info->items[0]->grades[$auser->id];
             // Calculate user status
             $auser->status = $auser->timemarked > 0;
             $picture = print_user_picture($auser, $course->id, $auser->picture, false, true);
             $studentName = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $this->course->id . '">' . fullname($auser) . '</a>';
             // If submission has been made
             if (!empty($auser->submissionid)) {
                 $filearea = $this->file_area_name($auser->id);
                 $fileLink = '';
                 if (isset($this->assignment->var3) && $this->assignment->var3 == self::ONLINE_TEXT) {
                     $url = '/mod/assignment/type/peerreview/' . self::VIEW_ONLINE_TEXT . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '&view=moderation';
                     $fileLink .= '<a href="' . $CFG->wwwroot . $url . '" target="_blank" onclick="return openpopup(\'' . $url . '\',\'\',\'menubar=0,location=0,scrollbars,resizable,width=500,height=400\');"><img src="' . $CFG->pixpath . '/f/html.gif" /></a>';
                 } else {
                     $basedir = $this->file_area($auser->id);
                     if ($files = get_directory_list($basedir)) {
                         require_once $CFG->libdir . '/filelib.php';
                         foreach ($files as $key => $file) {
                             $icon = mimeinfo('icon', $file);
                             $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                             $fileLink .= '<a href="' . $ffurl . '" ><img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" /></a>';
                         }
                     }
                 }
                 $submitted = '<div class="files" style="display:inline;">' . $fileLink . '</div><div style="display:inline;" id="tt' . $auser->id . '">' . userdate($auser->submitted, get_string('strftimeintable', 'assignment_peerreview')) . '</div>';
                 $submitted .= ' <a href="' . $CFG->wwwroot . '/mod/assignment/type/peerreview/' . self::RESUBMIT_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '">(' . get_string('resubmitlabel', 'assignment_peerreview') . ')</a>';
                 // Reviews by student
                 $numberOfReviewsByThisStudent = 0;
                 if ($reviewsByThisStudent = get_records_select('assignment_review', 'assignment=\'' . $this->assignment->id . '\' AND reviewer=\'' . $auser->id . '\' AND complete=\'1\'')) {
                     $numberOfReviewsByThisStudent = count($reviewsByThisStudent);
                     $reviewsByThisStudent = array_values($reviewsByThisStudent);
                     $reviews = '<div style="text-align:center;" id="re' . $auser->id . '">';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= '<span id="rev' . $reviewsByThisStudent[$i]->id . '"  style="padding:5px 2px;">';
                         $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $reviewsByThisStudent[$i]->reviewee . '&amp;mode=single&amp;offset=1';
                         $reviews .= element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $i + 1, 600, 780, $i + 1, 'none', true, 'user' . $auser->id . 'rev' . $i);
                         $reviews .= '</span>';
                         // $reviews .= $i<$numberOfReviewsByThisStudent-1?', ':'';
                     }
                     $reviews .= '</div>';
                     $reviews .= '<script>';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseover\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="#ff9999";\');';
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseout\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="transparent";\');';
                     }
                     $reviews .= '</script>';
                 } else {
                     $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 }
                 // Reviews of student
                 $reviewsOfThisStudent = $this->get_reviews_of_student($auser->id);
                 $numberOfReviewsOfThisStudent = 0;
                 if (is_array($reviewsOfThisStudent)) {
                     $numberOfReviewsOfThisStudent = count($reviewsOfThisStudent);
                 }
                 $statusCode = $this->get_status($reviewsOfThisStudent, $numberOfCriteria);
                 $status = '<div id="st' . $auser->id . '">' . $this->print_status($statusCode, true) . '</div>';
                 $buttontext = get_string('review', 'assignment_peerreview');
                 $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $auser->id . '&amp;mode=single' . '&amp;offset=' . $offset++;
                 $button = element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'reviewbutton' . $auser->id);
                 $seedoreviews = '<div id="se' . $auser->id . '" style="text-align:center;padding:5px 0;"><span  id="seOutline' . $auser->id . '" class="s' . ($statusCode <= 3 ? '0' : '1') . '" style="padding:4px 1px;">' . $button . '</span></div>';
                 $seedoreviews .= '<script>';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseover\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="#ff9999";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseout\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="transparent";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= '</script>';
                 // Suggest mark
                 $suggestedmark = '<div style="text-align:center;" id="su' . $auser->id . '">';
                 $suggestedMarkToDisplay = $this->get_marks($reviewsOfThisStudent, $criteriaList, $numberOfReviewsByThisStudent, $this->assignment->var1);
                 $suggestedmark .= '<input type="text" size="4" id="gvalue' . $auser->id . '" value="' . $suggestedMarkToDisplay . '" />';
                 $suggestedmark .= '<input type="button" value="' . get_string('set', 'assignment_peerreview') . '" onclick="mark=parseInt(document.getElementById(\'gvalue' . $auser->id . '\').value); if(isNaN(mark)) {alert(\'' . get_string('gradenotanumber', 'assignment_peerreview') . '\'); return false;} else {popup_url=\'/mod/assignment/type/peerreview/' . self::SET_MARK_FILE . '?id=' . $this->cm->id . '&amp;a=' . $this->assignment->id . '&amp;userid=' . $auser->id . '&amp;mark=\'+mark; return openpopup(popup_url, \'grade5\', \'menubar=0,location=0,scrollbars,resizable,width=400,height=300\', 0);}" />';
                 $suggestedmark .= '</div>';
                 // Final grade
                 if ($auser->timemarked > 0) {
                     // if ($final_grade->locked or $final_grade->overridden) {
                     // $grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
                     // }
                     // else {
                     $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                     // }
                 } else {
                     $grade = '<div id="g' . $auser->id . '">' . get_string('notset', 'assignment_peerreview') . '</div>';
                 }
             } else {
                 $submitted = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 $seedoreviews = '<div id="se' . $auser->id . '">&nbsp;</div>';
                 $suggestedmark = '<div id="su' . $auser->id . '">&nbsp;</div>';
                 $grade = '<div id="g' . $auser->id . '">-</div>';
             }
             $moderationCountSQL = 'SELECT count(r.id) FROM ' . $CFG->prefix . 'assignment a, ' . $CFG->prefix . 'assignment_review r WHERE a.course=' . $course->id . ' AND a.id=r.assignment AND r.teacherreview=1 AND r.reviewee=\'' . $auser->id . '\'';
             $moderationCount = count_records_sql($moderationCountSQL);
             $moderations = '<div id="mo' . $auser->id . '" style="text-align:center;">' . ($moderationCount < $moderationtarget ? '<span class="errorStatus">' . $moderationCount . '</span>' : $moderationCount) . '</div>';
             // $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';
             // Add the row to the table
             $row = array($picture, $studentName, $submitted, $reviews, $moderations, $status, $seedoreviews, $suggestedmark, $grade);
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     require_once $CFG->dirroot . '/mod/assignment/type/peerreview/' . self::STYLES_FILE;
     $table->print_html();
     /// Print the whole table
     /// Mini form for setting user preference
     echo '<div style="margin:5px 10px;">';
     echo '<table id="optiontable" align="right">';
     echo '<tr><td colspan="2" align="right">';
     echo '<form id="options" action="type/peerreview/' . self::MASS_MARK_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '" method="post">';
     echo '<input type="submit" value="' . get_string('massmark', 'assignment_peerreview') . '" />';
     helpbutton('massmark', get_string('massmark', 'assignment_peerreview'), 'assignment/type/peerreview/');
     echo '</form>';
     echo '<br />';
     echo '</td></tr>';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment');
     echo '</td></tr>';
     echo '<tr align="right"><td>';
     echo '<label for="moderationtarget">' . get_string('moderationtarget', 'assignment_peerreview') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="moderationtarget" name="moderationtarget" size="1" value="' . $moderationtarget . '" />';
     helpbutton('moderationtarget', get_string('moderationtargetwhy', 'assignment_peerreview'), 'assignment/type/peerreview');
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</form>';
     echo '</td></tr></table>';
     echo '</div>';
     ///End of mini form
     print_footer($this->course);
 }
     $currentExam .= "</td></tr>";
     // Update the Exam Status
     $record = updateExamStatus($record, "Implementation");
     //'Orientation','Concepts','Implementation'
 } else {
     $currentExam .= "<tr><td colspan='2'>";
     // Check if active record
     $currentExam .= checkActiveExam($record, $anchor_record, examStatus($record, array(4), $exam_length, true));
     //$currentExam .= examStatus($record,array(4),$exam_length,true);
     $currentExam .= "</td></tr>";
     $currentExam .= "<tr><td valign='top'>";
     // Starttime to + 30 mins
     $opts = array('courseid' => $course->id, 'eid' => $record->id, 'view' => 1);
     $url = "/question/view_instructions.php?courseid={$course->id}&eid={$record->id}&view=1";
     //print_single_button("$CFG->wwwroot/question/view_instructions.php", $opts, 'Exam Orientation', 'get', '', false, '', false);
     $currentExam .= element_to_popup_window("button", $url, "orientation", "Exam Orientation", 900, 800, "Exam Orientation", true, true);
     $currentExam .= "</td><td>";
     //echo "<br/><br/>";
     $currentExam .= showOrientation($record, $exam_length, true);
     $currentExam .= "</td></tr>";
     $currentExam .= "<tr><td valign='top'>";
     // Update the Exam Status - is updated in the quiz attempt
     //$record = updateExamStatus($record,"Concepts"); //'Orientation','Concepts','Implementation'
     //echo "STATUS:$record->status";
     // Exam Part I: Concepts! Button
     // Was : $qca->attemptid
     if ($record->attemptid != null || $record->status == "Concepts") {
         // To prevent a duplicate user attempt when the quiz is in process.
         $examoptions = array('q' => $record->quizid, 'qcaid' => $record->id);
         $currentExam .= print_single_button("{$CFG->wwwroot}/mod/quiz/attempt.php", $examoptions, 'Exam Part I: Concepts!', 'get', '', true, '', false);
     } else {
Example #5
0
 /**
  * print_command
  *
  * @param xxx $type
  * @param xxx $hotpotscriptname
  * @param xxx $id
  * @param xxx $params
  * @param xxx $popup (optional, default=false)
  * @param xxx $return (optional, default=false)
  * @return xxx
  */
 function print_command($type, $hotpotscriptname, $id, $params, $popup = false, $return = false)
 {
     global $CFG;
     static $str;
     if (!isset($str)) {
         $str = new stdClass();
     }
     if (!isset($str->{$type})) {
         $str->{$type} = get_string($type);
     }
     switch ($type) {
         case 'add':
             $icon = '';
             break;
         case 'edit':
         case 'update':
             $icon = 't/edit';
             break;
         case 'delete':
             $icon = 't/delete.gif';
             break;
         case 'deleteall':
             $icon = '';
             break;
         default:
             // unknown command type !!
             return '';
     }
     foreach ($params as $key => $value) {
         if (empty($value)) {
             unset($params[$key]);
         }
     }
     $params['action'] = $type;
     $url = new moodle_url('/mod/hotpot/' . $hotpotscriptname, $params);
     if ($icon) {
         $linktext = $this->action_icon($url, new pix_icon($icon, get_string($type)));
     } else {
         $linktext = $str->{$type};
     }
     if ($popup) {
         if (is_bool($popup)) {
             $popup = array();
         } else {
             if (is_string($popup)) {
                 $popup = array('name' => $popup);
             }
         }
         $name = isset($popup['name']) ? $popup['name'] : '';
         $width = isset($popup['width']) ? $popup['width'] : 650;
         $height = isset($popup['height']) ? $popup['height'] : 400;
         $command = element_to_popup_window('link', $url, $name, $linktext, $height, $width, $str->{$type}, '', true, '', '');
     } else {
         $command = html_writer::link($url, $linktext, array('title' => $str->{$type})) . "\n";
     }
     if (!$icon) {
         // add white space between text commands
         $command .= ' &nbsp; ';
     }
     if ($return) {
         return ' ' . $command;
     } else {
         print ' ' . $command;
     }
 }