/**
 * Display History tab content with page versions
 */
function wiki_info_content(&$WS)
{
    global $CFG, $COURSE, $USER;
    //generate a list with all versions
    $vers = wiki_get_all_page_versions($CFG->prefix, $WS->page, $WS->dfwiki->id, $WS->groupmember->groupid, $WS->member->id);
    if ($vers) {
        $countver = count($vers);
        if ($countver > 1) {
            echo '<script type="text/javascript" src="wiki/hist.js"></script>';
            echo '<form id="historyform" method="post" ' . 'action="view.php?id=' . $WS->linkid . '&amp;page=' . urlencode('diff/' . $WS->page) . "&amp;gid={$WS->groupmember->groupid}&amp;uid={$WS->member->id}" . '">';
            echo '<input type="submit" name="' . get_string('compareversions', 'wiki') . '" value="' . get_string('compareversions', 'wiki') . '"/>';
            echo '<br/><br/>';
        }
        //print table with the page versions
        $prop = null;
        $prop->id = 'historytable';
        $prop->width = "100%";
        $prop->border = "1";
        $prop->padding = "5";
        $prop->spacing = "1";
        $prop->class = "generaltable boxalignleft";
        $prop->header = "true";
        $prop->valignth = "top";
        $prop->classth = 'header c0 nwikileftnow';
        wiki_table_start($prop);
        if ($countver > 1) {
            echo '';
            $prop = null;
            $prop->header = "true";
            $prop->valign = "top";
            $prop->class = "nwikileftnow header c1";
            wiki_change_column($prop);
        }
        echo get_string('version');
        $prop = null;
        $prop->header = "true";
        $prop->valign = "top";
        $prop->class = "nwikileftnow header c1";
        wiki_change_column($prop);
        echo get_string('user');
        $prop = null;
        $prop->header = "true";
        $prop->valign = "top";
        $prop->class = "nwikileftnow header c2";
        wiki_change_column($prop);
        echo get_string('lastmodified');
        if (wiki_grade_got_permission($WS)) {
            $prop = null;
            $prop->header = "true";
            $prop->valign = "top";
            $prop->class = "nwikileftnow header c3";
            wiki_change_column($prop);
            echo get_string('eval_editions_quality', 'wiki');
        }
        $prop = null;
        $prop->header = "true";
        //print content
        $i = 0;
        foreach ($vers as $ver) {
            if ($ver->highlight) {
                $class = "textcenter nwikihighlight";
            } else {
                $class = "textcenter nwikibargroundblanco";
            }
            if (isset($prop->header)) {
                $prop->class = $class;
                wiki_change_row($prop);
            } else {
                $prop = null;
                $prop->class = $class;
                wiki_change_row($prop);
            }
            // input types for history diff
            if ($countver > 1) {
                $style = 'style="visibility:hidden" ';
                $checked = 'checked="checked"';
                if ($i == 0) {
                    echo '<input type="radio" value="' . $ver->version . '" name="oldid" ' . $style . ' />';
                    echo '<input type="radio" value="' . $ver->version . '" name="diff" ' . $checked . ' />';
                } elseif ($i == 1) {
                    echo '<input type="radio" value="' . $ver->version . '" name="oldid" ' . $checked . ' />';
                    echo '<input type="radio" value="' . $ver->version . '" name="diff" ' . $style . ' />';
                } else {
                    echo '<input type="radio" value="' . $ver->version . '" name="oldid" />';
                    echo '<input type="radio" value="' . $ver->version . '" name="diff" ' . $style . ' />';
                }
                $prop = null;
                $prop->class = $class;
                wiki_change_column($prop);
            }
            if ($ver->version == $WS->pagedata->version) {
                echo $ver->version;
            } else {
                $prop = null;
                $prop->href = "javascript:document.forms['formu" . $i . "'].submit()";
                $out = wiki_a($ver->version, $prop, true);
                $prop = null;
                $prop->name = "dfcontent";
                $prop->value = "11";
                $out .= wiki_input_hidden($prop, true);
                $out2 = wiki_div($out, '', true);
                $prop = null;
                $prop->id = "formu{$i}";
                $prop->action = "view.php?id={$WS->linkid}&amp;page=" . urlencode("oldversion/{$ver->pagename}") . "&amp;ver={$ver->version}&amp;gid={$WS->groupmember->groupid}&amp;uid={$WS->member->id}";
                $prop->method = "post";
                wiki_form($out2, $prop);
            }
            $prop = null;
            $prop->class = $class;
            wiki_change_column($prop);
            $author = wiki_get_user_info($ver->author);
            echo $author;
            $prop = null;
            $prop->class = $class;
            wiki_change_column($prop);
            $modified = strftime('%A, %d %B %Y %H:%M', $ver->lastmodified);
            echo $modified;
            if (wiki_grade_got_permission($WS)) {
                $prop = null;
                $prop->class = $class;
                wiki_change_column($prop);
                $scale = array(1 => "+", 2 => "=", 3 => "-");
                $gradevalue = get_field_select('wiki_evaluation_edition', 'valoration', 'wiki_pageid=' . $ver->id);
                if ($gradevalue) {
                    echo wiki_grade_translate($gradevalue, $scale);
                } else {
                    echo get_string('eval_notset', 'wiki');
                }
            }
            $i++;
        }
        wiki_table_end();
        if ($countver > 1) {
            echo '<br/>';
            echo '<input type="submit" name="' . get_string('compareversions', 'wiki') . '" value="' . get_string('compareversions', 'wiki') . '"/>';
        }
        echo '</form>';
    } else {
        print_string('noversion', 'wiki');
    }
}
/** Prints the code that sets the wiki page grade 
 *  evaluation box.
 *
 * @param  Object $WS       WikiStorage
 */
function wiki_grade_print_page_evaluation_box(&$WS)
{
    global $USER;
    // evaluation box available only in view tab
    if ($WS->pageaction != 'view') {
        return;
    }
    if (!wiki_grade_got_permission($WS)) {
        return;
    }
    $wiki = get_record('wiki', 'id', $WS->cm->instance);
    if (!$wiki) {
        return;
    }
    $scale = get_record('scale', 'id', (int) $wiki->notetype);
    if (isset($scale) && $scale != false) {
        print_box_start();
        $prop = null;
        $prop->id = "form_grades";
        $prop->method = "post";
        $prop->action = 'view.php?id=' . $WS->linkid . '&amp;page=view/' . stripslashes_safe($WS->page) . '&amp;ver=' . $WS->ver . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id;
        wiki_form_start($prop);
        $prop = null;
        $prop->class = "evaluationbox";
        wiki_div_start($prop);
        $prop = null;
        //$prop->spacing = "40";
        $prop->padding = "2";
        //$prop->valigntd = "top";
        $prop->aligntd = "right";
        //$prop->border = 1;
        wiki_table_start($prop);
        echo '<b>' . get_string('grade') . '</b>:&nbsp;';
        wiki_change_column();
        $scale = wiki_grade_scale_box($scale, true);
        $eval_instance = wiki_grade_evaluation_exist($WS->page, $WS->dfwiki->id, $WS->groupmember->groupid, $WS->member->id, $USER->id);
        if ($scale) {
            echo '&nbsp;';
            $prop = null;
            $prop->name = 'grade_post_evaluation';
            $prop->value = get_string('set', 'wiki');
            wiki_input_submit($prop);
            echo '&nbsp;';
            $context = get_context_instance(CONTEXT_MODULE, $WS->cm->id);
            if ((has_capability('mod/wiki:authorreview', $context) || has_capability('mod/wiki:mainreview', $context)) && $eval_instance != false) {
                echo '<i>(' . get_string('eval_current', 'wiki') . ' "' . trim($scale[$eval_instance->wikigrade - 1]) . '")</i>';
            }
        } else {
            echo 'grades.lib.php: there is no wikigrade yet.';
        }
        wiki_change_row();
        echo '<b>' . get_string('eval_feedback', 'wiki') . '</b>:&nbsp';
        wiki_change_column();
        unset($prop);
        $prop->size = 60;
        $prop->value = '';
        if ($eval_instance) {
            $prop->value = $eval_instance->comment;
        }
        $prop->name = "grade_commentary";
        wiki_input_text($prop);
        $prop->align = 'right';
        wiki_change_row($prop);
        wiki_change_column();
        $prop = null;
        $prop->name = 'grade_appendtodiscussion';
        wiki_input_checkbox($prop);
        $a->link = 'view.php?id=' . $WS->cm->id . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;page=discussion/discussion:' . urlencode($WS->page);
        echo get_string('eval_append_to_disc', 'wiki', $a);
        $prop->align = 'right';
        wiki_change_row($prop);
        wiki_change_column();
        $prop = null;
        $prop->name = 'grade_anonymous';
        wiki_input_checkbox($prop);
        echo get_string('eval_anonymous', 'wiki');
        wiki_table_end();
        wiki_div_end();
        wiki_form_end();
        print_box_end();
    }
}