function print_header($title, $morebreadcrumbs = NULL)
 {
     global $USER, $CFG, $WS;
     $this->init_full();
     if ($this->user_allowed_editing()) {
         $buttons = wiki_table_start('', true);
         $buttons .= update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'wiki'));
         if (!empty($CFG->showblocksonmodpages)) {
             $buttons .= wiki_change_column('', true);
             $prop = null;
             $prop->method = "get";
             $prop->action = "view.php";
             $prop->events = 'onsubmit="this.target=\'_top\'; return true"';
             $buttons .= wiki_form_start($prop, true);
             $buttons .= wiki_div_start('', true);
             $prop = null;
             $prop->name = "id";
             $prop->value = $this->modulerecord->id;
             $buttons .= wiki_input_hidden($prop, true);
             $prop = null;
             $prop->name = "edit";
             $prop->value = $this->user_is_editing() ? 'off' : 'on';
             $buttons .= wiki_input_hidden($prop, true);
             $prop = null;
             $prop->value = get_string($this->user_is_editing() ? 'blockseditoff' : 'blocksediton');
             $buttons .= wiki_input_submit($prop, true);
             $buttons .= wiki_div_end(true);
             $buttons .= wiki_form_end(true);
         }
         $buttons .= wiki_table_end('', true);
     } else {
         $buttons = ' ';
     }
     //        print_header($title, $this->courserecord->fullname, $crumbtext, '', '', true, $buttons, navmenu($this->courserecord, $this->modulerecord));
     /// Print header.
     $navlinks = array();
     $navlinks[] = array('name' => get_string('modulenameplural', 'wiki'), 'link' => $CFG->wwwroot . '/mod/wiki/index.php?id=' . $this->courserecord->id, 'type' => 'activity');
     $navlinks[] = array('name' => format_string($this->activityrecord->name), 'link' => "view.php", 'type' => 'activityinstance');
     $navigation = build_navigation($navlinks);
     print_header_simple(format_string($this->activityrecord->name), "", $navigation, "", "", true, $buttons, navmenu($this->courserecord, $WS->cm));
 }
function wiki_export_html(&$WS)
{
    global $CFG;
    check_dir_exists("{$CFG->dataroot}/temp", true);
    check_dir_exists("{$CFG->dataroot}/temp/html", true);
    check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}", true);
    check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}", true);
    //export contents
    wiki_export_html_content($WS);
    //export attached files
    $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}");
    if ($flist != null) {
        foreach ($flist as $fil) {
            $from_file = "{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}/{$fil}";
            $to_file = "{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments/{$fil}";
            copy($from_file, $to_file);
        }
    }
    //zip file name
    $times = time();
    $name = $WS->dfwiki->name . '-' . $times . '.zip';
    $cleanzipname = clean_filename($name);
    //List of files and directories
    $filelist = list_directories_and_files("{$CFG->dataroot}/temp/html");
    //Convert them to full paths
    $files = array();
    if ($filelist != null) {
        foreach ($filelist as $file) {
            $files[] = "{$CFG->dataroot}/temp/html/{$file}";
        }
    }
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml", true);
    $destination = "{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml/{$cleanzipname}";
    $status = zip_files($files, $destination);
    //delete the folder created in temp
    $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/html");
    if ($filelist2 != null) {
        $del = delete_dir_contents("{$CFG->dataroot}/temp/html");
    }
    //show it all to be albe to download the file
    $prop = null;
    $prop->class = "textcenter";
    wiki_div_start($prop);
    wiki_size_text(get_string("exporthtmlcorrectly", "wiki"), 2);
    wiki_div_end();
    $prop = null;
    $prop->border = "0";
    $prop->class = "boxaligncenter";
    $prop->classtd = "nwikileftnow";
    wiki_table_start($prop);
    $wdir = '/exportedhtml';
    $fileurl = "{$wdir}/{$cleanzipname}";
    $ffurl = "/file.php?file=/{$WS->cm->course}{$fileurl}";
    $icon = mimeinfo("icon", $cleanzipname);
    link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640);
    echo "\n" . '&nbsp;';
    link_to_popup_window($ffurl, "display", htmlspecialchars($cleanzipname), 480, 640);
    $prop = null;
    $prop->class = "nwikileftnow";
    wiki_change_row($prop);
    echo '&nbsp;';
    wiki_table_end();
    $prop = null;
    $prop->border = "0";
    $prop->class = "boxaligncenter";
    $prop->classtd = "nwikileftnow";
    wiki_table_start($prop);
    $prop = null;
    $prop->id = "form";
    $prop->method = "post";
    $prop->action = '../xml/index.php?id=' . $WS->dfwiki->course . '&amp;wdir=/exportedhtml';
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "dfform[viewexported]";
    $prop->value = get_string('viewexported', 'wiki');
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    wiki_change_column();
    print_continue("{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->cm->id}");
    wiki_table_end();
}
     $opt .= wiki_option($fontop, $prop, true);
 }
 $prop = null;
 $prop->name = "font";
 $prop->size = "1";
 $prop->events = "onchange=\"javascript:view_evaluations(event)\"";
 wiki_select($opt, $prop);
 //}
 $prop = null;
 $prop->align = "right";
 wiki_change_row($prop);
 echo "<!-- SELECCIONAR TAMANY LLETRA -->" . "\n";
 wiki_b(get_string('pdfFontSize', 'wiki') . ':');
 $prop = null;
 $prop->class = "nwikileftnow";
 wiki_change_column($prop);
 if (isset($dfwiki)) {
     print_string($dfwiki->evaluation, 'wiki');
     //<!-- corregir -->
 } else {
     $size_font_default = '12';
     $size_fonts = array('8', '9', '10', '11', '12', '14', '16', '18', '20', '22', '24', '26', '28', '36');
     $opt = null;
     foreach ($size_fonts as $size_fontop) {
         $prop = null;
         $prop->value = $size_fontop;
         if ($size_fontop == $size_font_default) {
             $prop->selected = "selected";
         }
         $opt .= wiki_option($size_fontop, $prop, true);
     }
function displaydir($wdir)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    global $basedir;
    global $id;
    global $USER, $CFG;
    global $choose;
    $fullpath = $basedir . $wdir;
    check_dir_exists($fullpath, true);
    $directory = opendir($fullpath);
    // Find all files
    while (false !== ($file = readdir($directory))) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (is_dir($fullpath . "/" . $file)) {
            $dirlist[] = $file;
        } else {
            $filelist[] = $file;
        }
    }
    closedir($directory);
    $strname = get_string("name");
    $strsize = get_string("size");
    $strmodified = get_string("modified");
    $straction = get_string("action");
    $strmakeafolder = get_string("makeafolder");
    $struploadafile = get_string("uploadafile");
    $strwithchosenfiles = get_string("withchosenfiles");
    $strmovetoanotherfolder = get_string("movetoanotherfolder");
    $strmovefilestohere = get_string("movefilestohere");
    $strdeletecompletely = get_string("deletecompletely");
    $strcreateziparchive = get_string("createziparchive");
    $strrename = get_string("rename");
    $stredit = get_string("edit");
    $strunzip = get_string("unzip");
    $strlist = get_string("list");
    $strrestore = get_string("restore");
    $strchoose = get_string("choose");
    $prop = null;
    $prop->action = "index.php";
    $prop->method = "post";
    $prop->id = "dirform";
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "choose";
    $prop->value = $choose;
    wiki_input_hidden($prop);
    wiki_hr();
    $prop = null;
    $prop->border = "0";
    $prop->spacing = "2";
    $prop->padding = "2";
    $prop->width = "640";
    $prop->class = "files";
    $prop->header = true;
    $prop->styleth = "width:5%";
    wiki_table_start($prop);
    $prop = null;
    $prop->header = true;
    $prop->align = "left";
    $prop->class = "header name";
    wiki_change_column($prop);
    echo $strname;
    $prop = null;
    $prop->header = true;
    $prop->align = "right";
    $prop->class = "header size";
    wiki_change_column($prop);
    echo $strsize;
    $prop = null;
    $prop->header = true;
    $prop->align = "right";
    $prop->class = "header date";
    wiki_change_column($prop);
    echo $strmodified;
    $prop = null;
    $prop->header = true;
    $prop->align = "right";
    $prop->class = "header commands";
    wiki_change_column($prop);
    echo $straction;
    if ($wdir == "/") {
        $wdir = "";
    }
    if (!empty($wdir)) {
        $dirlist[] = '..';
    }
    $count = 0;
    $header = true;
    if (!empty($dirlist)) {
        asort($dirlist);
        foreach ($dirlist as $dir) {
            if ($header) {
                $header = false;
                $prop = null;
                $prop->header = true;
            } else {
                $prop = null;
            }
            if ($dir == '..') {
                $fileurl = rawurlencode(dirname($wdir));
                $prop->style = "white-space: nowrap;";
                $prop->align = "center";
                $prop->classtr = "folder";
                wiki_change_row($prop);
                echo '&nbsp;';
                $prop = null;
                $prop->class = 'name';
                $prop->align = 'left';
                $prop->style = "white-space: nowrap;";
                wiki_change_column($prop);
                $prop = null;
                $prop->src = $CFG->pixpath . '/f/parent.gif';
                $prop->height = "16";
                $prop->width = "16";
                $prop->alt = get_string('parentfolder');
                $out = wiki_img($prop, true);
                $prop = null;
                $prop->href = 'index.php?id=' . $id . '&amp;wdir=' . $fileurl;
                wiki_a($out, $prop);
                $prop = null;
                $prop->href = 'index.php?id=' . $id . '&amp;wdir=' . $fileurl;
                wiki_a(get_string('parentfolder'), $prop);
                wiki_change_column();
                echo '&nbsp;';
                wiki_change_column();
                echo '&nbsp;';
                wiki_change_column();
                echo '&nbsp;';
            } else {
                $count++;
                $filename = $fullpath . "/" . $dir;
                $fileurl = rawurlencode($wdir . "/" . $dir);
                $filesafe = rawurlencode($dir);
                $filesize = display_size(get_directory_size("{$fullpath}/{$dir}"));
                $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
                $prop->align = "center";
                $prop->style = "white-space: nowrap;";
                $prop->class = "checkbox";
                $prop->classtr = "folder";
                wiki_change_row($prop);
                $prop = null;
                $prop->name = 'file' . $count;
                $prop->value = $fileurl;
                wiki_input_checkbox($prop);
                $prop = null;
                $prop->class = 'name';
                $prop->align = "left";
                $prop->style = "white-space: nowrap;";
                wiki_change_column($prop);
                $prop = null;
                $prop->src = $CFG->pixpath . '/f/folder.gif';
                $prop->height = "16";
                $prop->width = "16";
                $prop->alt = "Folder";
                $out = wiki_img($prop, true);
                $prop = null;
                $prop->href = 'index.php?id=' . $id . '&amp;wdir=' . $fileurl . '&amp;choose=' . $choose;
                wiki_a($out, $prop);
                $prop = null;
                $prop->href = 'index.php?id=' . $id . '&amp;wdir=' . $fileurl . '&amp;choose=' . $choose;
                wiki_a(htmlspecialchars($dir), $prop);
                $prop = null;
                $prop->class = 'size';
                $prop->align = "right";
                $prop->style = "white-space: nowrap;";
                wiki_change_column($prop);
                echo $filesize;
                $prop = null;
                $prop->class = 'date';
                $prop->align = "right";
                $prop->style = "white-space: nowrap;";
                wiki_change_column($prop);
                echo $filedate;
                $prop = null;
                $prop->class = 'commands';
                $prop->align = "right";
                $prop->style = "white-space: nowrap;";
                wiki_change_column($prop);
                $prop = null;
                $prop->href = 'index.php?id=' . $id . '&amp;wdir=' . $wdir . '&amp;file=' . $filesafe . '&amp;action=rename&amp;choose=' . $choose;
                wiki_a($strrename, $prop);
                //echo "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=rename&amp;choose=$choose\">$strrename</a>";
            }
        }
    }
    if (!empty($filelist)) {
        asort($filelist);
        foreach ($filelist as $file) {
            $icon = mimeinfo("icon", $file);
            $count++;
            $filename = $fullpath . "/" . $file;
            $fileurl = "{$wdir}/{$file}";
            $filesafe = rawurlencode($file);
            $fileurlsafe = rawurlencode($fileurl);
            $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
            if (substr($fileurl, 0, 1) == '/') {
                $selectfile = substr($fileurl, 1);
            } else {
                $selectfile = $fileurl;
            }
            if ($header) {
                $header = false;
                $prop = null;
                $prop->header = true;
            } else {
                $prop = null;
            }
            $prop->align = "center";
            $prop->style = "white-space: nowrap;";
            $prop->class = "checkbox";
            $prop->classtr = "file";
            wiki_change_row($prop);
            $prop = null;
            $prop->name = 'file' . $count;
            $prop->value = $fileurl;
            wiki_input_checkbox($prop);
            $prop = null;
            $prop->align = "left";
            $prop->class = "name nwikileftnow";
            wiki_change_column($prop);
            if ($CFG->slasharguments) {
                $ffurl = "/file.php/" . $id . $fileurl;
            } else {
                $ffurl = "/file.php?file=/" . $id . $fileurl;
            }
            link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640);
            echo '&nbsp;';
            link_to_popup_window($ffurl, "display", htmlspecialchars($file), 480, 640);
            $file_size = filesize($filename);
            $prop = null;
            $prop->class = 'size';
            $prop->align = "right";
            $prop->style = "white-space: nowrap;";
            wiki_change_column($prop);
            echo display_size($file_size);
            $prop = null;
            $prop->class = 'date';
            $prop->align = "right";
            $prop->style = "white-space: nowrap;";
            wiki_change_column($prop);
            echo $filedate;
            if ($choose) {
                $edittext = "<b><a onMouseDown=\"return set_value('{$selectfile}')\" href=\"\">{$strchoose}</a></b>&nbsp;";
            } else {
                $edittext = '';
            }
            if ($icon == "text.gif" || $icon == "html.gif") {
                $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=edit&amp;choose={$choose}\">{$stredit}</a>";
            } else {
                if ($icon == "zip.gif") {
                    $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=unzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strunzip}</a>&nbsp;";
                    $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=listzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strlist}</a> ";
                }
            }
            $prop = null;
            $prop->class = 'commands';
            $prop->align = "right";
            $prop->style = "white-space: nowrap;";
            wiki_change_column($prop);
            echo $edittext;
            echo "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}\">{$strrename}</a>";
        }
    }
    if ($header) {
        $prop = null;
        $prop->header = true;
        wiki_table_end($prop);
        $header = false;
    } else {
        wiki_table_end();
    }
    wiki_hr();
    if (empty($wdir)) {
        $wdir = "/";
    }
    $prop = null;
    $prop->name = "id";
    $prop->value = $id;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "choose";
    $prop->value = $choose;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "wdir";
    $prop->value = $wdir;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "sesskey";
    $prop->value = $USER->sesskey;
    wiki_input_hidden($prop);
    $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}");
    if (!empty($count)) {
        choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:document.forms['dirform'].submit()");
    }
    wiki_div_end();
    wiki_form_end();
    $prop = null;
    $prop->border = "0";
    $prop->spacing = "2";
    $prop->padding = "2";
    $prop->class = "boxalignright";
    $prop->aligntd = "center";
    wiki_table_start($prop);
    if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) {
        $prop = null;
        $prop->action = "index.php";
        $prop->method = "get";
        wiki_form_start($prop);
        wiki_div_start();
        $prop = null;
        $prop->name = "choose";
        $prop->value = $choose;
        wiki_input_hidden($prop);
        $prop = null;
        $prop->name = "id";
        $prop->value = $id;
        wiki_input_hidden($prop);
        $prop = null;
        $prop->name = "wdir";
        $prop->value = $wdir;
        wiki_input_hidden($prop);
        $prop = null;
        $prop->name = "action";
        $prop->value = "paste";
        wiki_input_hidden($prop);
        $prop = null;
        $prop->name = "sesskey";
        $prop->value = $USER->sesskey;
        wiki_input_hidden($prop);
        $prop = null;
        $prop->value = $strmovefilestohere;
        wiki_input_submit($prop);
        wiki_div_end();
        wiki_form_end();
        $prop = null;
        $prop->align = "right";
        wiki_change_column($prop);
    }
    $prop = null;
    $prop->action = "index.php";
    $prop->method = "get";
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "choose";
    $prop->value = $choose;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "id";
    $prop->value = $id;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "wdir";
    $prop->value = $wdir;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "action";
    $prop->value = "mkdir";
    wiki_input_hidden($prop);
    $prop = null;
    $prop->value = $strmakeafolder;
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    $prop = null;
    $prop->align = "right";
    wiki_change_column($prop);
    $prop = null;
    $prop->action = "index.php";
    $prop->method = "get";
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "choose";
    $prop->value = $choose;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "id";
    $prop->value = $id;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "wdir";
    $prop->value = $wdir;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = "action";
    $prop->value = "upload";
    wiki_input_hidden($prop);
    $prop = null;
    $prop->value = $struploadafile;
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    wiki_table_end();
    wiki_hr();
}
    $prop->class = "boxaligncenter";
    $prop->padding = "10";
    wiki_table_start($prop);
    $prop = null;
    $prop->id = "form1";
    $prop->method = "post";
    $prop->action = 'dfwikitonewwiki.php?id=' . $cm->id;
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "sure";
    $prop->value = get_string('yes');
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    wiki_change_column();
    $prop = null;
    $prop->id = "form2";
    $prop->method = "post";
    $prop->action = 'view.php?id=' . $cm->id;
    wiki_form_start($prop);
    wiki_div_start();
    $prop = null;
    $prop->name = "cancel";
    $prop->value = get_string('no');
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    wiki_table_end();
    print_simple_box_end();
}
function wiki_footer()
{
    global $COURSE, $CFG;
    ///document	ending
    $PAGE = wiki_page_info('PAGE');
    $pageblocks = wiki_page_info('pageblocks');
    $editing = $PAGE->user_is_editing();
    wiki_table_end();
    /// The right column
    //if there are not blocks on the right part then don't enter in this condition
    if (!empty($pageblocks[BLOCK_POS_RIGHT])) {
        //to work out the default widths need to check all blocks
        $preferred_width_right = optional_param('preferred_width_right', blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), PARAM_INT);
        //preferred_width_right sizes
        //should be between BLOCK_x_MAX_WIDTH and BLOCK_x_MIN_WIDTH.
        $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
        $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
    }
    //if there are blocks on the right part, then they are placed
    if (!empty($pageblocks[BLOCK_POS_RIGHT])) {
        //checks if there are blocks to place on the right-hand side
        if (!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing)) {
            $prop = new stdClass();
            $prop->id = "right-column";
            $prop->class = "blockcourse";
            wiki_change_column($prop);
            $prop = new stdClass();
            $prop->width = $preferred_width_right . 'px';
            wiki_table_start($prop);
            blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
            wiki_table_end();
            $prop = new stdClass();
        }
    }
    wiki_table_end();
    // select the teacher
    $cm = wiki_param('cm');
    $dfwiki = wiki_param('dfwiki');
    wiki_print_teacher_selection($cm, $dfwiki);
    wiki_div_end();
    // content wrapper end
    /// Finish the page
    print_footer($COURSE);
}
function wiki_print_menu_teachers($listteachers, $cm)
{
    //this function prints the list of theachers in the wiki's student
    if (empty($listteachers)) {
        return;
    }
    wiki_br(2);
    $prop = null;
    $prop->border = "0";
    $prop->class = "boxalignright";
    $prop->classtd = "nwikileftnow";
    wiki_table_start($prop);
    print_string('anotherteacher', 'wiki');
    wiki_change_column();
    $prop = null;
    $prop->id = "selectteacher";
    $prop->method = "post";
    $prop->action = 'view.php?id=' . $cm->id;
    wiki_form_start($prop);
    wiki_div_start();
    $opt = null;
    foreach ($listteachers as $lteacher) {
        $prop = null;
        $prop->value = $lteacher->id;
        $opt .= wiki_option($lteacher->lastname . ', ' . $lteacher->firstname, $prop, true);
    }
    $prop = null;
    $prop->name = "dfformselectteacher";
    wiki_select($opt, $prop);
    $prop = null;
    $prop->value = get_string("continue");
    wiki_input_submit($prop);
    wiki_div_end();
    wiki_form_end();
    $prop = null;
    $prop->class = "nwikileftnow";
    wiki_change_row($prop);
    echo "&nbsp;";
    wiki_table_end();
}
function wiki_grade_print_edition_evaluation_box(&$WS)
{
    $context = get_context_instance(CONTEXT_MODULE, $WS->cm->id);
    if (has_capability('mod/wiki:evaluateawiki', $context)) {
        print_box_start();
        $prop = null;
        $prop->id = "form_grades";
        $prop->method = "post";
        $prop->action = 'view.php?id=' . $WS->linkid . '&amp;page=' . urlencode($WS->pageaction . '/' . stripslashes_safe($WS->page)) . '&amp;dfcontent=11&amp;ver=' . $WS->ver . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id;
        wiki_form_start($prop);
        $prop = null;
        $prop->padding = "2";
        $prop->aligntd = "right";
        wiki_table_start($prop);
        echo '<b>' . get_string('grade') . '</b>:&nbsp;';
        wiki_change_column();
        /// 1 -> "+", 2 -> "=", 3 -> "-"
        $prop = null;
        $prop->value = '1';
        $opt = wiki_option('+', $prop, true);
        $prop = null;
        $prop->value = '2';
        $opt .= wiki_option('=', $prop, true);
        $prop = null;
        $prop->value = '3';
        $opt .= wiki_option('-', $prop, true);
        $prop = null;
        $prop->name = "grade_edition";
        wiki_select($opt, $prop);
        echo '&nbsp';
        $prop = null;
        $prop->name = 'grade_edition_confirm';
        $prop->value = get_string('set', 'wiki');
        wiki_input_submit($prop);
        unset($prop);
        $prop->name = 'oldversion';
        $prop->value = $WS->pageolddata->version;
        wiki_input_hidden($prop);
        unset($prop);
        $prop->name = 'currentversion';
        $prop->value = $WS->pageverdata->version;
        wiki_input_hidden($prop);
        wiki_change_row();
        echo '<b>' . get_string('eval_feedback', 'wiki') . '</b>:&nbsp';
        wiki_change_column();
        unset($prop);
        $prop->size = 60;
        $prop->value = '';
        $prop->name = 'feedback';
        wiki_input_text($prop);
        $prop->align = 'right';
        wiki_change_row($prop);
        echo '<i>' . get_string('note', 'wiki') . '</i>:&nbsp;';
        wiki_change_column();
        $oldversion = $WS->pageolddata->version;
        $currentversion = $WS->pageverdata->version;
        if ($currentversion < $oldversion) {
            $tmp = $currentversion;
            $currentversion = $oldversion;
            $oldversion = $tmp;
        }
        $version = $oldversion + 1;
        $count = $version - $currentversion;
        if ($count == 1) {
            echo get_string('evaluate_hist_edition', 'wiki') . ' ' . $version;
        } else {
            echo '<i>' . get_string('evaluate_hist_editions', 'wiki') . ': ';
            for ($i = $version; $i <= $currentversion; $i++) {
                echo $i;
                if ($i < $currentversion) {
                    echo ', ';
                }
            }
            echo '</i>';
        }
        wiki_table_end();
        wiki_form_end();
        print_box_end();
    }
}
function wiki_import_wiki(&$WS)
{
    global $file;
    //if the form is complete
    $sure = optional_param('dfformsure', NULL, PARAM_ALPHA);
    if (isset($sure)) {
        //import to xml
        wiki_import_wiki_XML($WS);
        $prop = null;
        $prop->class = 'textcenter';
        $info = wiki_size_text(get_string("importcorrectly", 'wiki'), 2, '', true);
        wiki_div($info, $prop);
        $prop = null;
        $prop->action = '../view.php?id=' . $WS->cm->id;
        $prop->method = 'post';
        $prop->id = 'form';
        wiki_form_start($prop);
        $prop = null;
        $prop->border = '0';
        $prop->class = 'boxaligncenter';
        $prop->classtd = 'nwikileftnow';
        wiki_table_start($prop);
        $prop = null;
        $prop->name = 'dfformcontinue';
        $prop->value = get_string('continue');
        $input = wiki_input_submit($prop, true);
        wiki_div($input);
        wiki_table_end();
        wiki_form_end();
    } else {
        if (isset($WS->dfform['import'])) {
            $extension = explode("/", $WS->path);
            $num = count($extension) - 1;
            $name = $extension[$num];
            $info = wiki_b(get_string("importcheckwarning", 'wiki'), '', true);
            $info .= '    ' . $name;
            $prop = null;
            $prop->class = 'textcenter';
            wiki_paragraph($info, $prop);
            switch ($WS->dfform['incase']) {
                case 0:
                    $name = get_string("always", 'diki');
                    break;
                case 1:
                    $name = get_string("never", 'wiki');
                    break;
                case 2:
                    $name = get_string("before", 'wiki');
                    break;
                case 3:
                    $name = get_string("after", 'wiki');
                    break;
                default:
                    break;
            }
            $info = wiki_b(get_string("incase", 'wiki'), '', true);
            $info .= '  ' . $name;
            $prop = null;
            $prop->class = 'textcenter';
            wiki_paragraph($info, $prop);
            switch ($WS->dfform['incaseatach']) {
                case 0:
                    $name = get_string("alwaysatach", 'wiki');
                    break;
                case 1:
                    $name = get_string("neveratach", 'wiki');
                    break;
                case 2:
                    $name = get_string("beforeatach", 'wiki');
                    break;
                case 3:
                    $name = get_string("afteratach", 'wiki');
                    break;
                case 4:
                    $name = get_string("bigeratach", 'wiki');
                    break;
                case 5:
                    $name = get_string("smalleratach", 'wiki');
                    break;
                default:
                    break;
            }
            $info = wiki_b(get_string("incaseatach", 'wiki'), '', true);
            $info .= '  ' . $name;
            $prop = null;
            $prop->class = 'textcenter';
            wiki_paragraph($info, $prop);
            wiki_br();
            $prop = null;
            $prop->class = 'textcenter';
            wiki_paragraph(get_string("importcheckfiles", 'wiki'), $prop);
            $prop = null;
            $prop->class = 'boxaligncenter';
            wiki_table_start($prop);
            $prop = null;
            $prop->action = 'exportxml.php?id=' . $WS->cm->id . '&amp;pageaction=importxml&amp;path=' . $WS->path;
            $prop->method = 'post';
            $prop->id = 'form1';
            wiki_form_start($prop);
            $prop = null;
            $prop->name = 'dfformincase';
            $prop->value = $WS->dfform['incase'];
            wiki_input_hidden($prop);
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = $WS->dfform['incaseatach'];
            wiki_input_hidden($prop);
            $prop = null;
            $prop->name = 'dfformsure';
            $prop->value = get_string('yes');
            wiki_input_submit($prop);
            wiki_form_end();
            wiki_change_column();
            $prop = null;
            $prop->action = 'exportxml.php?id=' . $WS->cm->id . '&amp;pageaction=importewiki&amp;path=' . $WS->path . '&amp;file=' . $file;
            $prop->method = 'post';
            $prop->id = 'form2';
            wiki_form_start($prop);
            $prop = null;
            $prop->name = 'dfformcancel';
            $prop->value = get_string('no');
            wiki_input_submit($prop);
            wiki_form_end();
            wiki_table_end();
        } else {
            //create the form to import
            $prop = null;
            $prop->action = 'exportxml.php?id=' . $WS->cm->id . '&amp;pageaction=importewiki&amp;type=' . $WS->type . '&amp;path=' . $WS->path . '&amp;file=' . $file;
            $prop->method = 'post';
            $prop->id = 'form';
            wiki_form_start($prop);
            $prop = null;
            $prop->border = '0';
            $prop->class = 'boxaligncenter';
            $prop->classtd = 'nwikileftnow';
            wiki_table_start($prop);
            wiki_b(get_string('incase', 'wiki'));
            wiki_table_start();
            $prop = null;
            $prop->name = 'dfformincase';
            $prop->value = '0';
            $prop->checked = 'checked';
            wiki_input_radio($prop);
            print_string('always', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincase';
            $prop->value = '1';
            wiki_input_radio($prop);
            print_string('never', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincase';
            $prop->value = '2';
            wiki_input_radio($prop);
            print_string('before', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincase';
            $prop->value = '3';
            wiki_input_radio($prop);
            print_string('after', 'wiki');
            wiki_table_end();
            wiki_br(2);
            $prop = null;
            $prop->class = "nwikileftnow";
            wiki_change_row($prop);
            wiki_b(get_string('incaseatach', 'wiki'));
            wiki_table_start();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '0';
            $prop->checked = 'checked';
            wiki_input_radio($prop);
            print_string('alwaysatach', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '1';
            wiki_input_radio($prop);
            print_string('neveratach', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '2';
            wiki_input_radio($prop);
            print_string('beforeatach', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '3';
            wiki_input_radio($prop);
            print_string('afteratach', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '4';
            wiki_input_radio($prop);
            print_string('bigeratach', 'wiki');
            wiki_change_row();
            $prop = null;
            $prop->name = 'dfformincaseatach';
            $prop->value = '5';
            wiki_input_radio($prop);
            print_string('smalleratach', 'wiki');
            wiki_table_end();
            wiki_br(2);
            $prop = null;
            $prop->class = "nwikicenternow";
            wiki_change_row($prop);
            $prop = null;
            $prop->name = 'dfformimport';
            $prop->value = get_string('import', 'wiki');
            wiki_input_submit($prop);
            wiki_table_end();
            wiki_form_end();
        }
    }
}
function wiki_hist_actions(&$WS)
{
    //print page title
    switch ($WS->pageaction) {
        case 'oldversion':
            wiki_table_start();
            wiki_size_text(wiki_hist_move_ver("&lt;", 1, 'oldversion'));
            wiki_change_column();
            wiki_size_text(get_string('oldversion', 'wiki') . ': ' . stripslashes_safe($WS->page) . ' v.' . $WS->pageolddata->version);
            wiki_change_column();
            wiki_size_text(wiki_hist_move_ver("&gt;", -1, 'oldversion'));
            wiki_table_end();
            print_box_start();
            wiki_hist_old($WS);
            break;
        case 'diff':
            wiki_table_start();
            wiki_size_text(wiki_hist_move_ver("&lt;", 1));
            wiki_change_column();
            wiki_size_text(get_string('oldversion', 'wiki') . ': ' . stripslashes_safe($WS->page) . ' v.' . $WS->pageolddata->version);
            wiki_change_column();
            wiki_size_text(wiki_hist_move_ver("&gt;", -1));
            wiki_table_end();
            ///// WIKI EVALUATION EDITION /////
            wiki_grade_print_edition_evaluation_box($WS);
            print_box_start();
            $prop = null;
            $prop->class = "textright";
            //wiki_paragraph(helpbutton('differences', get_string('version'), 'wiki',true,false,'',true), $prop);
            echo '<div align="right">' . helpbutton('differences', get_string('version'), 'wiki', true, false, '', true) . '</div>';
            wiki_hist_diff($WS);
            break;
        case 'newdiff':
            wiki_table_start();
            wiki_size_text(wiki_hist_move_ver("&lt;", 1, 'newdiff'));
            wiki_change_column();
            wiki_size_text(get_string('oldversion', 'wiki') . ': ' . stripslashes_safe($WS->page) . ' v.' . $WS->pageolddata->version);
            wiki_change_column();
            wiki_size_text(wiki_hist_move_ver("&gt;", -1, 'newdiff'));
            wiki_table_end();
            ///// WIKI EVALUATION EDITION /////
            wiki_grade_print_edition_evaluation_box($WS);
            print_box_start();
            $prop = null;
            $prop->class = "textright";
            wiki_paragraph('', $prop);
            wiki_hist_newdiff($WS);
            break;
    }
    print_box_end();
}
function wiki_print_view_uploaded(&$WS)
{
    global $CFG;
    //initiates images array
    $context = get_context_instance(CONTEXT_MODULE, $WS->cm->id);
    $pl->src = $CFG->wwwroot . '/mod/wiki' . '/images/plus.gif';
    if (isset($WS->dfcourse)) {
        $pl->class = 'wiki_folding_co';
    } else {
        $pl->class = 'wiki_folding';
    }
    $mi->src = $CFG->wwwroot . '/mod/wiki' . '/images/minus.gif';
    if (isset($WS->dfcourse)) {
        $mi->class = 'wiki_folding_co';
    } else {
        $mi->class = 'wiki_folding';
    }
    $sq->src = $CFG->wwwroot . '/mod/wiki' . '/images/weather-clear.png';
    $images = array('plus' => wiki_img($pl, true), 'minus' => wiki_img($mi, true), 'square' => wiki_img($sq, true));
    //get www path:
    if (has_capability('mod/wiki:uploadfiles', $context) || $WS->dfperms['attach']) {
        $prop = null;
        $prop->width = '30%';
        $prop->valigntd = 'top';
        $prop->classtd = 'nwikileftnow';
        echo '<hr>';
        wiki_table_start($prop);
        if ($WS->dfperms['attach']) {
            print_string('insertedfiles', 'wiki');
            $prop = null;
            $prop->valign = 'top';
            $prop->class = 'nwikileftnow';
            wiki_change_column($prop);
        }
        if ($WS->dfperms['attach']) {
            if (count($WS->dfdir->content) != 0) {
                $prop = null;
                $prop->class = 'wiki_listme';
                $prop->classli = 'wiki_listme';
                wiki_start_ul($prop);
                echo $images['plus'];
                $prop = null;
                $prop->href = '#';
                if (isset($WS->dfcourse)) {
                    $prop->class = 'wiki_folding_co';
                } else {
                    $prop->class = 'wiki_folding';
                }
                $button = wiki_a(get_string('uploaded', 'wiki'), $prop);
                $numm = 0;
                //generate tree content.
                foreach ($WS->dfdir->content as $file) {
                    if ($numm == 0) {
                        $prop = null;
                        $prop->class = 'wiki_listme';
                        $prop->style = 'margin:auto auto auto 15px;display:none';
                        $prop->classli = 'wiki_listme';
                        wiki_start_ul($prop);
                        $numm++;
                    } else {
                        $prop = null;
                        $prop->class = 'wiki_listme';
                        wiki_change_li($prop);
                    }
                    //image url: http://147.83.59.184/moodle15/file.php/#courseid/
                    $url = $WS->dfdir->www . '/' . $file;
                    $url = substr($url, strlen($CFG->wwwroot));
                    echo $images['square'];
                    $prop = null;
                    $prop->href = 'javascript:insertTags(\'[[attach:' . $file . ']]\',\'\',\'\');';
                    $button = wiki_a($file, $prop);
                    $prop = null;
                    $prop->src = $CFG->wwwroot . '/mod/wiki/editor/images/file_view.gif';
                    link_to_popup_window($url, get_string('view'), wiki_img($prop, true), $height = 400, $width = 500, get_string('view'));
                    if (has_capability('mod/wiki:deletefiles', $context)) {
                        $prop = null;
                        $prop->name = 'dfformdelfile';
                        $prop->value = $file;
                        $prop->src = $CFG->wwwroot . '/mod/wiki/images/delete.gif';
                        wiki_input_image($prop);
                    }
                }
                wiki_end_ul();
                wiki_end_ul();
            } else {
                //no files where uploaded
                print_string('nofiles', 'wiki');
            }
        }
        //     		//print upload form
        // 			$prop = null;
        // 			$prop->valign = 'top';
        // 			$prop->class = 'nwikiuptam';
        // 			wiki_change_column($prop);
        //
        //     		if (has_capability('mod/wiki:uploadfiles', $context)){
        //     			$prop = null;
        // 				$prop->name = 'MAX_FILE_SIZE';
        //     			$prop->value = get_max_upload_file_size();
        // 				wiki_input_hidden($prop);
        //
        //     			$prop = null;
        // 				$prop->name = 'dfformfile';
        //     			$prop->size = '20';
        // 				wiki_input_file($prop);
        //
        // 				$prop = null;
        // 				$prop->name = 'dfformupload';
        // 				$prop->value = get_string('upload');
        // 				wiki_input_submit($prop);
        //     		}
        //     	//print help
        // 		$prop = null;
        // 		$prop->valign = 'top';
        // 		$prop->class = 'nwikileftnow';
        // 		wiki_change_column($prop);
        //
        //     		helpbutton('attach', get_string('help'), 'wiki');
        wiki_table_end();
        wiki_hr();
    }
}