$opt .= wiki_option($size_fontop, $prop, true);
 }
 unset($prop);
 $prop->name = "font_base_size";
 $prop->size = "1";
 wiki_select($opt, $prop);
 wiki_table_end();
 // Table Font
 wiki_change_row();
 // Table parameter
 ///////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////// Header & Footer Section
 wiki_br(2);
 echo '<!-- SELECT FOOTERS -->';
 wiki_b("Header and Footer section");
 wiki_hr();
 unset($prop);
 $prop->class = "box";
 wiki_table_start($prop);
 // Table quetion wikibook header? & footer?
 wiki_paragraph(get_string('wikibooks_header_question', 'wiki'));
 wiki_change_column();
 unset($prop);
 $prop->name = "with_header";
 wiki_input_checkbox($prop);
 wiki_table_end();
 // Table quetion wikibook header?
 wiki_change_row();
 // Table parameter
 unset($prop);
 /////// Title
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();
}
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();
    }
}