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();
}
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time", "3000");
raise_memory_limit("memory_limit", "128M");
//get mod plural and singlar name
$strwikis = get_string("modulenameplural", 'wiki');
$strwiki = get_string("modulename", 'wiki');
print_header("{$course->shortname}: {$dfwiki->name}", "{$course->fullname}", "{$navigation} <a href=\"index.php?id={$course->id}\">{$strwikis}</a> -> {$dfwiki->name}", "", "", true);
//Check if either we're comming from the form or this is the first time
if (optional_param('sure', NULL, PARAM_ALPHA) == get_string('yes')) {
    //Form has already been visited
    if (wiki_convert_all_dfwikis($course)) {
        wiki_br();
        print_simple_box_start();
        $prop = null;
        $prop->class = "textcenter";
        wiki_size_text(get_string("convertdfwikicorrectly", "wiki"), 2, $prop);
        print_continue("view.php?id={$cm->id}");
        wiki_br();
        print_simple_box_end();
    } else {
        //there aren't dfwikis to convert
        wiki_div('&nbsp;');
        print_simple_box_start();
        $prop = null;
        $prop->class = "textcenter";
        wiki_paragraph(get_string('nodfwikistoconvert', 'wiki'), $prop);
        $prop = null;
        $prop->id = "form";
        $prop->method = "post";
        $prop->action = 'view.php?id=' . $cm->id;
        wiki_form_start($prop);
 }
 //Adjust some php variables to the execution of this script
 @ini_set("max_execution_time", "3000");
 raise_memory_limit("memory_limit", "128M");
 //get mod plural and singlar name
 $strwikis = get_string("modulenameplural", 'wiki');
 $strwiki = get_string("modulename", 'wiki');
 $navlinks[] = array('name' => $strwikis, 'link' => "{$CFG->wwwroot}/mod/wiki/index.php?id={$course->id}", 'type' => 'misc');
 $navlinks[] = array('name' => $WS->dfwiki->name, 'link' => "{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->id}", 'type' => 'misc');
 $navlinks[] = array('name' => get_string('wikitopdf', 'wiki'), 'link' => null, 'type' => 'misc');
 $navigation = build_navigation($navlinks);
 print_header("{$COURSE->shortname}: {$WS->dfwiki->name}", "{$COURSE->fullname}", $navigation, "", "", true);
 $prop = null;
 $prop->class = "textcenter";
 wiki_div_start($prop);
 wiki_size_text(get_string('selectwikitopdf', 'wiki'), 2);
 wiki_div_end();
 echo '<!-- Inici del Formulari -->' . "\n";
 echo '<!-- SELECCIONAR PAGINES WIKI A PASAR -->' . "\n";
 $prop = null;
 $prop->id = "form";
 $prop->method = "post";
 $prop->action = 'wikitopdf.php?id=' . $id . '&amp;cid=' . $cid . '&amp;gid=' . $WS->groupmember->groupid . '&amp;page=' . $WS->page . '&amp;version=' . $WS->pagedata->version;
 wiki_form_start($prop);
 $prop = null;
 $prop->class = "box generalbox generalboxcontent boxaligncenter";
 wiki_div_start($prop);
 $prop = null;
 $prop->name = "sesskey";
 if (!isset($sesskey)) {
     $sesskey = sesskey();
function wiki_edit_content(&$WS)
{
    global $CFG;
    $context = get_context_instance(CONTEXT_MODULE, $WS->cm->id);
    require_capability('mod/wiki:caneditawiki', $context);
    $cont = false;
    $txt = '';
    $titlebox = '';
    $oldcontentbox = '';
    $viewtitle = '0';
    if ($WS->pageaction == 'adddiscussion' or isset($WS->dfform['addtitle']) and $WS->pageaction == 'edit') {
        $viewtitle = '1';
        if (isset($WS->dfform['addtitle'])) {
            $titlebox = $WS->dfform['addtitle'];
            $oldcontentbox = $WS->dfform['oldcontent'];
            $contentbox = $WS->dfform['content'];
        } else {
            $titlebox = '';
            $oldcontentbox = $WS->dfform['content'];
            $contentbox = '';
        }
    } else {
        if (isset($WS->dfform['content'])) {
            $contentbox = $WS->dfform['content'];
        } else {
            $contentbox = '';
        }
    }
    //need to check if  we have preview mode
    $preview = optional_param('dfformpreview', NULL, PARAM_ALPHA);
    if (isset($preview)) {
        //we're in preview mode
        print_simple_box_start('center', '100%', '', '20');
        wiki_size_text("Preview", 2);
        // discussions
        if ($titlebox == '') {
            $txt = $oldcontentbox . $contentbox;
        } else {
            switch ($WS->dfwiki->editor) {
                case 'ewiki':
                    $txt = $oldcontentbox . chr(13) . chr(10) . '!!! ' . $titlebox . ' ' . chr(13) . chr(10) . $contentbox . chr(10);
                    break;
                case 'htmleditor':
                    $txt = $oldcontentbox . chr(13) . chr(10) . '<h1> ' . $titlebox . ' </h1>' . chr(13) . chr(10) . $contentbox . chr(10);
                    break;
                default:
                    $txt = $oldcontentbox . chr(13) . chr(10) . '= ' . $titlebox . ' =' . chr(13) . chr(10) . $contentbox . chr(10);
                    break;
            }
        }
        wiki_print_page_content(stripslashes_safe($txt), $WS);
        print_simple_box_end();
    } else {
        //we're not in preview mode
        //check if there's content
        //echo 'wiki_forceeditorchange='.$CFG->wiki_forceeditorchange;
        if (!isset($WS->pagedata->content) || $CFG->wiki_forceeditorchange) {
            if (!isset($WS->pagedata->content)) {
                $WS->pagedata->content = '';
            }
            //  si no hem decidit encara l'editor per aquesta pagina i no hem adjuntat cap arxiu demanem l'editor
            if (!isset($WS->dfform['selectedit']) && (!isset($WS->pagedata->editor) || $WS->pagedata->editor == '') || $CFG->wiki_forceeditorchange) {
                $cont = true;
                //$pagename=stripslashes($pagename);
                $prop = null;
                $prop->border = "0";
                $prop->class = "nwikileftnow";
                wiki_table_start($prop);
                /// removed "choose different wiki syntax on new page listbox" so teachers will not get confused (nadavkav 25.10.09)
                /*
                				print_string('anothereditor','wiki');
                				//Converts reserved chars for html to prevent chars misreading
                				$pagetemp = stripslashes_safe($WS->page);
                
                                wiki_change_column();
                				$prop = null;
                				$prop->id = "sel_edit";
                				$prop->method = "post";
                				$prop->action = 'view.php?id='.$WS->linkid.'&amp;page=edit/'.urlencode($pagetemp).'&amp;gid='.$WS->groupmember->groupid.'&amp;uid='.$WS->member->id;
                				wiki_form_start($prop);
                				wiki_div_start();
                				$opt = "";
                                if ($WS->dfwiki->editor != 'dfwiki'){
                                	$prop = null;
                                	$prop->value = "0";
                                	$opt = wiki_option(get_string('dfwiki','wiki'), $prop, true);
                                }
                                if ($WS->dfwiki->editor != 'nwiki'){
                                	$prop = null;
                                	$prop->value = "3";
                                	$opt .= wiki_option(get_string('nwiki','wiki'), $prop, true);
                                }
                                if ($WS->dfwiki->editor != 'ewiki'){
                                	$prop = null;
                                	$prop->value = "1";
                                	$opt .= wiki_option(get_string('ewiki','wiki'), $prop, true);
                				}
                                if ($WS->dfwiki->editor != 'htmleditor'){
                                	$prop = null;
                                	$prop->value = "2";
                                	$opt .= wiki_option(get_string('htmleditor','wiki'), $prop, true);
                                	}
                                $prop = null;
                                $prop->name = "dfformselectedit";
                                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();
                if (isset($WS->dfform['content'])) {
                    $content_text =& $WS->dfform['content'];
                } else {
                    $content_text =& $WS->pagedata->content;
                }
                if (isset($WS->dfform['selectedit'])) {
                    switch ($WS->dfform['selectedit']) {
                        case '0':
                            $WS->pagedata->editor = $WS->dfwiki->editor = 'dfwiki';
                            break;
                        case '1':
                            $WS->pagedata->editor = $WS->dfwiki->editor = 'ewiki';
                            break;
                        case '2':
                            $WS->pagedata->editor = $WS->dfwiki->editor = 'htmleditor';
                            break;
                        case '3':
                            $WS->pagedata->editor = $WS->dfwiki->editor = 'nwiki';
                            break;
                        default:
                            error('No editor was selected');
                            break;
                    }
                } else {
                    $WS->pagedata->editor = $WS->dfwiki->editor;
                }
                wiki_print_editor($content_text, $viewtitle, $titlebox, '', $WS);
            }
        }
    }
    if (isset($WS->dfform['content'])) {
        $content_text = stripslashes_safe($WS->dfform['content']);
    } else {
        $content_text = stripslashes_safe($WS->pagedata->content);
    }
    // partial editing of a section available only with nwiki editor
    $section = optional_param('section', '', PARAM_TEXT);
    $sectionnum = optional_param('sectionnum', 0, PARAM_INTEGER);
    if (!isset($preview) && $WS->pagedata->editor == 'nwiki' && !($section == '' && $sectionnum == 0) && !wiki_is_uploading_modified()) {
        $section = stripslashes($section);
        $sectionnum = wiki_get_real_section_position($WS->page, $section, $sectionnum);
        $res = wiki_split_sections($content_text, $section, $sectionnum);
        if ($res->error != '') {
            $sectionhash = optional_param('sectionhash', '', PARAM_TEXT);
            wiki_release_lock($WS, $WS->dfwiki->id, $WS->pagedata->pagename . '#' . $sectionhash);
            error($res->error);
        } else {
            $content_text = $res->current_part;
        }
    }
    //print the editor
    if ($cont == false) {
        if (!isset($WS->dfform['selectedit'])) {
            $editor = optional_param('editor', '', PARAM_ALPHA);
            if (!empty($WS->dfform['editor'])) {
                $WS->pagedata->editor = $WS->dfform['editor'];
            } else {
                if (!empty($editor)) {
                    $WS->pagedata->editor = $editor;
                }
            }
            if ($WS->pageaction == 'adddiscussion' or isset($WS->dfform['addtitle'])) {
                if (!isset($oldcontentbox)) {
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $content_text, $WS);
                } else {
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $oldcontentbox, $WS);
                }
            } else {
                wiki_print_editor($content_text, $viewtitle, $titlebox, '', $WS);
            }
        } else {
            //comming from the above form
            switch ($WS->dfform['selectedit']) {
                case '0':
                    $WS->pagedata->editor = 'dfwiki';
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $oldcontentbox, $WS);
                    break;
                case '1':
                    $WS->pagedata->editor = 'ewiki';
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $oldcontentbox, $WS);
                    break;
                case '2':
                    $WS->pagedata->editor = 'htmleditor';
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $oldcontentbox, $WS);
                    break;
                case '3':
                    $WS->pagedata->editor = 'nwiki';
                    wiki_print_editor($contentbox, $viewtitle, $titlebox, $oldcontentbox, $WS);
                    break;
                default:
                    error('No editor was selected');
                    break;
            }
        }
    }
}
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_diff_print_versions($diff = "diff")
{
    global $WS;
    //if ($diff=="newdiff"){
    $vers->current = $WS->pageolddata->version;
    $vers->old = $WS->pageverdata->version;
    wiki_size_text(get_string('comparingwith', 'wiki', $vers), 2);
    //}
    $prev = $WS->pageolddata->version - 1;
    $next = $WS->pageolddata->version + 1;
    $specialvers = array();
    $prop = null;
    $prop->href = 'view.php?id=' . $WS->linkid . '&amp;page=' . $diff . '/' . urlencode($WS->pageolddata->pagename) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;ver=' . $WS->pageolddata->version . '/1&amp;dfcontent=11';
    if ($WS->pageolddata->version != 1) {
        $out = wiki_a(get_string('initial', 'wiki'), $prop, true);
    } else {
        $out = '<b>1</b>';
    }
    $specialvers[1] = $out;
    $prop = null;
    $prop->href = 'view.php?id=' . $WS->linkid . '&amp;page=' . $diff . '/' . urlencode($WS->pageolddata->pagename) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;ver=' . $WS->pageolddata->version . '/' . $next . '&amp;dfcontent=11';
    $out = wiki_a(get_string('next'), $prop, true);
    $specialvers[$next] = $out;
    $prop = null;
    $prop->href = 'view.php?id=' . $WS->linkid . '&amp;page=' . $diff . '/' . urlencode($WS->pageolddata->pagename) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;ver=' . $WS->pageolddata->version . '/' . $prev . '&amp;dfcontent=11';
    $out = wiki_a(get_string('previous'), $prop, true);
    $specialvers[$prev] = $out;
    $prop = null;
    $prop->href = 'view.php?id=' . $WS->linkid . '&amp;page=' . $diff . '/' . urlencode($WS->pageolddata->pagename) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;ver=' . $WS->pageolddata->version . '&amp;dfcontent=11';
    $out = wiki_a(get_string('current', 'wiki'), $prop, true);
    $specialvers[$WS->pagedata->version] = $out;
    print_simple_box_start('center', '100%', '', '20');
    //get how many versions have the page
    $ead = wiki_manager_get_instance();
    $vers = $ead->get_wiki_page_versions($WS->pageolddata->dfwiki);
    if (!$vers) {
        $vers = array();
    }
    $vers = count($vers);
    echo get_string('comparewith', 'wiki') . ': ';
    //wiki_table_start();
    $j = false;
    for ($i = $WS->pagedata->version; $i > $WS->pagedata->version - $vers && $i > 0; $i--) {
        /*
         *if($j){
         *    wiki_change_column();
         *}else {
         *    $j=true;
         *}
         */
        //put in bold the compared version
        if ($i == $WS->pageverdata->version) {
            $bolds = array('<b>', '</b>');
        } else {
            $bolds = array('', '');
        }
        //print the version link
        if (isset($specialvers[$i])) {
            echo $bolds[0] . $specialvers[$i] . $bolds[1];
        } else {
            $prop = null;
            if ($i != $WS->pageolddata->version) {
                $prop->href = 'view.php?id=' . $WS->linkid . '&amp;page=' . $diff . '/' . urlencode($WS->pageolddata->pagename) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '&amp;ver=' . $WS->pageolddata->version . '/' . $i . '&amp;dfcontent=11';
                wiki_a($bolds[0] . $i . $bolds[1], $prop);
            } else {
                echo '<b>' . $i . '</b> ';
            }
        }
        if ($i != $WS->pagedata->version - $vers + 1 && $i > 1) {
            //wiki_change_column();
            echo '- ';
        }
    }
    wiki_table_end();
    print_simple_box_end();
    wiki_br();
}
 // Old print header
 /*    print_header($course->shortname .': '. get_string('wikibooks', 'wiki'), $course->fullname, 
       "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->
        <a href=\"{$CFG->wwwroot}/mod/wiki/index.php?id={$course->id}\">$strwikis</a> ->
        <a href=\"{$CFG->wwwroot}/mod/wiki/view.php?id=$cmid\">{$wikimain->name}</a> ->"
        .get_string('wikibooktopdf', 'wiki'));*/
 //New print header
 $navlinks[] = array('name' => $strwikis, 'link' => "{$CFG->wwwroot}/mod/wiki/index.php?id={$course->id}", 'type' => 'misc');
 $navlinks[] = array('name' => $wikimain->name, 'link' => "{$CFG->wwwroot}/mod/wiki/view.php?id={$cmid}", 'type' => 'misc');
 $navlinks[] = array('name' => get_string('wikibooktopdf', 'wiki'), 'link' => null, 'type' => 'misc');
 $navigation = build_navigation($navlinks);
 print_header($course->shortname . ': ' . get_string('wikibooks', 'wiki'), $course->fullname, $navigation);
 $prop = null;
 $prop->class = "textcenter";
 wiki_div_start($prop);
 wiki_size_text(get_string('wikibookselect', 'wiki'), 2);
 wiki_div_end();
 echo '<!-- Start of the Form -->' . "\n";
 echo '<!-- SELECT the WikiBooks to convert -->' . "\n";
 unset($prop);
 $prop->id = "form";
 $prop->method = "post";
 $prop->action = 'wikibooktopdf.php?cid=' . $cid . '&amp;cmid=' . $cmid . '&amp;uid=' . $uid . '&amp;gid=' . $gid;
 wiki_form_start($prop);
 // FORM
 // Input hidden studentmode and groupmode
 // STUDENT
 unset($prop);
 $prop->id = 'student';
 $prop->name = 'studentmode';
 $prop->value = $wikimain->studentmode;
function wiki_print_editor(&$content_text, $adddiscussion = '0', $addtitle = '', $oldcontent = '', &$WS)
{
    global $CFG, $USER;
    //show upload error @@@@@@@@
    //try to delete a file
    wiki_print_editor_setup($WS);
    require_once $CFG->dirroot . "/mod/wiki/weblib.php";
    require_once $CFG->dirroot . "/mod/wiki/locallib.php";
    //Scritp WIKI_TREE
    $prop = null;
    $prop->type = 'text/javascript';
    if (isset($WS->dfcourse)) {
        $prop->src = '../mod/wiki/editor/wiki_tree.js';
    } else {
        $prop->src = 'editor/wiki_tree.js';
    }
    wiki_script('', $prop);
    if (isset($WS->dfdir->error)) {
        foreach ($WS->dfdir->error as $err) {
            $prop = null;
            $prop->class = 'except';
            wiki_size_text($err, 3, $prop);
        }
    }
    if (substr($WS->pagedata->pagename, 0, strlen('discussion:')) != 'discussion:') {
        $event = 'view';
    } else {
        $event = 'discussion';
    }
    //mount editing form
    //Converts reserved chars for html to prevent chars misreading
    $pagetemp = stripslashes_safe($WS->pagedata->pagename);
    $pagetemp = wiki_clean_name($pagetemp);
    $prop = null;
    $prop->action = 'view.php?id=' . $WS->linkid . '&amp;page=' . $event . '/' . urlencode($pagetemp) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id;
    $prop->method = 'post';
    $prop->enctype = 'multipart/form-data';
    $prop->id = 'prim';
    wiki_form_start($prop);
    wiki_table_start();
    $prop = null;
    $prop->name = 'dfformversion';
    $prop->value = $WS->pagedata->version ? $WS->pagedata->version : '0';
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = 'dfformcreated';
    $prop->value = $WS->pagedata->created;
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = 'dfformeditable';
    $prop->value = $WS->pagedata->editable;
    wiki_input_hidden($prop);
    $prop = null;
    if ($adddiscussion == '1') {
        $prop->value = 'adddiscussion';
    } else {
        $prop->value = 'edit';
    }
    $prop->name = 'dfformaction';
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = 'dfformeditor';
    $prop->value = $WS->pagedata->editor;
    wiki_input_hidden($prop);
    /* necessary for joining the section with the rest of the page */
    // section name
    $section = optional_param('section', '', PARAM_TEXT);
    $prop = null;
    $prop->name = 'section';
    $preview = optional_param('dfformpreview', '', PARAM_TEXT);
    if ($preview != '' || wiki_is_uploading_modified()) {
        // if come from a preview, upload file or delete file
        // the string is already unslashed and encoded
        $prop->value = $section;
    } else {
        // gotta strip the slashes and encode it
        $prop->value = urlencode(stripslashes($section));
    }
    wiki_input_hidden($prop);
    // section number
    $prop = null;
    $prop->name = 'sectionnum';
    $prop->value = optional_param('sectionnum', '', PARAM_INTEGER);
    wiki_input_hidden($prop);
    $prop = null;
    $prop->name = 'sectionhash';
    $prop->value = optional_param('sectionhash', '', PARAM_TEXT);
    wiki_input_hidden($prop);
    // discussion
    if ($adddiscussion == '1') {
        wiki_size_text(get_string('adddiscussionitem', 'wiki'), 2);
        print_string('title', 'wiki');
        wiki_br();
        $prop = null;
        $prop->name = 'dfformaddtitle';
        $prop->value = $addtitle;
        $prop->size = '80';
        wiki_input_text($prop);
        wiki_br(2);
        $prop = null;
        $prop->name = 'dfformoldcontent';
        $prop->value = $oldcontent;
        wiki_input_hidden($prop);
        wiki_hr();
        wiki_change_row();
        date_default_timezone_set('UTC');
        // add editing username and date to the end of each discussion (nadavkav patch)
        $txt = $content_text . '<br/><br/>  <i>(' . get_string('discussioneditby', 'wiki') . ': ' . $USER->firstname . " " . $USER->lastname . " " . get_string('discussionediton', 'wiki') . ": " . date(DATE_RFC822) . ")</i>";
    } else {
        $txt = $content_text;
    }
    // wikibook
    $prop = null;
    $prop->name = 'wikibook';
    $prop->value = optional_param('wikibook', '', PARAM_TEXT);
    wiki_input_hidden($prop);
    wiki_print_edit_area($txt, $WS);
    wiki_tags_print_editbox($WS);
    $prop = null;
    $prop->class = 'nwikileftnow';
    wiki_change_row($prop);
    if ($WS->upload_bar) {
        wiki_print_edit_uploaded($WS);
    }
    wiki_change_row();
    $prop = null;
    $prop->name = 'dfformsave';
    $prop->value = get_string('save', 'wiki');
    wiki_input_submit($prop);
    $prop = null;
    $prop->name = 'dfformpreview';
    $prop->value = get_string('preview');
    wiki_input_submit($prop);
    $prop = null;
    $prop->name = 'dfformcancel';
    $prop->value = get_string('cancel');
    wiki_input_submit($prop);
    $prop = null;
    $prop->name = 'dfformdefinitive';
    $prop->value = '1';
    $prop->id = 'checkbox';
    wiki_input_checkbox($prop);
    print_string('highlight', 'wiki');
    wiki_table_end();
    wiki_form_end();
}