f63bd1bd5e5929c5402a27fc40fd848f133efb02
[atutor.git] / mods / wiki / plugins / mpi / mpi_bugreport.php
1 <?php
2
3 /*
4    Allows users to submit a bug report, automatically creates a new bug
5    page and adds a link to the current page (BugReports). It is used in
6    conjuntion with BugReportState on the ErfurtWiki: demo site.
7 */
8
9
10 $ewiki_plugins["mpi"]["bugreport"] = "ewiki_mpi_bugreport";
11
12
13
14 // view <form>
15 function ewiki_mpi_bugreport($action, $args, &$iii, &$s) 
16 {
17     global $ewiki_id;
18     $MAIN = $ewiki_id;   //"BugReports";
19     ($ELSE = $args[0]) or ($ELSE = rtrim($MAIN,"s"));
20     $o = "";
21
22     if ($_REQUEST["br_save"]) {
23
24        #-- check parameters
25        $content = $_REQUEST["content"];
26        $title = $_REQUEST["title"];
27        $author = $_REQUEST["author"];
28        if (strlen($content) < 50) {
29           return("<p><b>Insufficient information for a useful BugReport.</b></p>");
30        }
31        if (strstr($title,"???")) {
32           $title = substr($content, 0, 50);
33        }
34        
35        #-- make page name for bug report
36        $new_id = ewiki_title_to_pagename($title, $ELSE);
37        
38
39        #-- generate bug page text
40        $new = "This page is part of the $MAIN series. Please go there to submit a new bug or to see the list of all existing reports.\n";
41        if ($m=$_REQUEST["br_notify"]) {
42           $new .= "\n[notify:$m]\n";
43        }
44        $new .= "\n----\n\n"
45             . "!! $title\n\n";
46        foreach ($_REQUEST["i"] as $i=>$v) {
47           if ($v != "unknown") {
48              $new .= "| $i | $v |\n";
49           }
50        }
51        $new .= "| status | __open__ |\n <?plugin BugReportState ?"."> \n";
52        $new .= "\n$author: $content\n\n";
53        
54        #-- create new bug report page
55        $data = ewiki_db::CREATE($new_id);
56        $data["content"] = $new;
57        ewiki_db::UPDATE($data);
58        $data["version"] = 1;
59        $ok = ewiki_db::WRITE($data);
60        if (!$ok) {
61           return("<b>Error</b> while creating new bug report page. Please go back and change the title (at least two words required), so we can try again.");
62        }
63
64        #-- store bugreport entry on main page
65        $data = ewiki_db::GET($MAIN);
66        $list_e = "| __open__ | $new_id | $title |\n";
67        $data["content"] = preg_replace("/(\n\|.+\|.+\|\s*\n)/", "$1$list_e", $data["content"], 1);
68        ewiki_db::UPDATE($data);
69        $data["version"]++;
70        ewiki_db::WRITE($data);
71        if ($notify=function_exists($pf="ewiki_notify_edit_hook")) {
72           $pf($MAIN, $data, $uu);
73        }
74
75        #-- append to page output
76        $iii[] = array(
77           "\n\n| new bug report [#added \"added\"] as $new_id |\n\n",
78           0xFFFF,
79           "core"
80        );
81
82     }
83     else {
84
85        $url = ewiki_script("", $ewiki_id);
86        $ver = EWIKI_VERSION;
87        $current_vers = "<option>$ver";
88        for ($i=$ver[strlen($ver)-1]-1; $i>0; $i--) {
89           $current_vers .= "<option>" . substr($ver, 0, strlen($ver)-1) . $i;
90        }
91        $o .=<<<EOT
92 <form style="border:2px #444455 solid; background:#9999aa; padding:5px;"class="BugReport" action="$url#added" method="POST" enctype="multipart/form-data">
93 bug title: <input type="text" name="title" value="???" size="50">
94 <br/>
95 <br/>
96 YourName: <input type="text" name="author" value="anonymous" size="30">
97 <br/>
98 <br/>
99 your ewiki version: <select name="i[ewiki version]"><option>unknown<option>other{$current_vers}<option>CVS today<option>CVS yesterday<option>CVS last week<option>two weeks old<option>latest -dev<option>R1.02a<option>R1.01f<option>R1.01e<option>R1.01d<option>R1.01c<option>R1.01b<option>R1.01a</select>
100 plattform: <select name="i[operating system]"><option>unknown<option>other<option>Win4<option>NT (2K,XP)<option>Unix<option>Linux<option>OS X</select>
101 <br/>
102 database: <select name="i[database backend]"><option>unknown<option>mysql<option>db_flat_files<option>db_fast_files<option>anydb: other<option>anydb: pgsql<option>dzf2<option>dba/dbm<option>phpwiki13<option>zip<option>other<option>own</select>
103 php version: <select name="i[php version]"><option>unknown<option>4.0.x<option>4.1.x<option>4.2.x<option>4.3.x<option>4.4/4.5 (CVS)<option>5.0-beta/rc<option>5.0.x<option>CGI/suPHP<option>PHP/FastCGI<option>SafeMode 4.x</select>
104 <br>
105 problem category (vague): <select name="i[bug category]"><option>unknown<option>general<option>feature request<option>get running<option>markup<option>links<option>error message<option>plugin<option>page plugin<option>action plugin<option>auth plugin<option>aview plugin<option>edit plugin<option>feature extension<option>link tweak plugin<option>mpi plugin<option>spages<option>lib extension<option>module plugin<option>db plugin<option>configuration<option>documentation</select>
106 <br/>
107 <br/>
108 long error description:<br /> 
109 <textarea name="content" cols="75" rows="8">
110 </textarea>
111 <br/><br/>
112 <input type="submit" name="br_save" value="create bug page">
113 <br/>
114 <br/>
115 email notification <input type="text" name="br_notify" value="" size="16">
116 <br/><small>(opt., only enter if you want get notified on any responses)</small>
117 <br/>
118 </form>
119 EOT;
120     }
121
122     return($o);
123 }
124
125
126
127 function ewiki_title_to_pagename($title, $else="BugReport") {
128
129     global $ewiki_config;
130
131     #-- try to make a wikilink out of the title
132 //    $title = strtolower($title);
133     $title = preg_replace("/\b((?!not)[-_\w\d]{1,3})\b/", " ", $title);
134     $title = ucwords($title);
135     $link = preg_replace("/\s+/", "", $title);
136     
137     #-- if we don't get a WikiWord
138     if (!$link || ewiki_db::GET($link)
139     || !preg_match("/^([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}/", $link)) {
140        $n = 20;
141        do {
142           $link = "$else" . ($n++);
143        }
144        while (ewiki_db::GET($link));
145     }
146
147     return($link);    
148 }
149
150
151 ?>