02f9890cdfeb116903674b7ca8587afa320ffecf
[atutor.git] / mods / wiki / plugins / edit / templates.php
1 <?php
2
3 /*
4    If you load this plugin, pages with names ending in "...Template"
5    would be shown as <select> list, whenever a new page was to be
6    created.
7 */
8
9
10 $ewiki_plugins["edit_form_final"][] = "ewiki_aedit_templates";
11 $ewiki_plugins["edit_hook"][] = "ewiki_edit_load_template";
12
13
14 function ewiki_aedit_templates(&$html, $id, &$data, $action)
15 {
16    if (!$data["content"]) {
17
18       #-- search template pages
19       $list = array();
20       $result = ewiki_db::SEARCH("id","Template");
21       while ($row = $result->get(0, 0x21, EWIKI_DB_F_TEXT)) {
22          if (preg_match('/Template$/', $row["id"])) {
23             $list[] = $row["id"];
24          }
25       }
26
27       #-- add list
28       if ($list) {
29          $o = '<form action="'.ewiki_script("", $id).'" method="POST" entype="multipart/form-data">'
30             . '<input type="hidden" name="id" value="'.$action.'/'.$id.'">'
31             . '<input type="submit" value="load"> '
32             . '<select name="load_template">';
33          foreach ($list as $i) {
34             $o .= '<option value="'.$i.'">'.$i.'</option>';
35          }
36          $o .= '</select></form>';
37
38          #-- output
39          $html = $o . $html;
40       }
41    }
42 }
43
44
45 function ewiki_edit_load_template($id, &$data, $action)
46 {
47    if ($id = $_REQUEST["load_template"]) {
48       $d2 = ewiki_db::GET($id);
49       $data["content"] = $d2["content"];
50    }
51 }
52
53
54 ?>