|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
*@author nicolaas[at]sunnysideup.co.nz |
|
5
|
|
|
* |
|
6
|
|
|
**/ |
|
7
|
|
|
|
|
8
|
|
|
class ErrorNotifierController extends Controller |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
11
|
|
|
"senderror" => "ADMIN" |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
private static $email_to_send_error_to = ''; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
protected $showThankYouNote = false; |
|
17
|
|
|
|
|
18
|
|
|
public function Form() |
|
19
|
|
|
{ |
|
20
|
|
|
if ($this->request->requestVar('_REDIRECT_BACK_URL')) { |
|
21
|
|
|
$url = $this->request->requestVar('_REDIRECT_BACK_URL'); |
|
22
|
|
|
} elseif ($this->request->getHeader('Referer')) { |
|
23
|
|
|
$url = $this->request->getHeader('Referer'); |
|
24
|
|
|
} else { |
|
25
|
|
|
$url = Director::baseURL(); |
|
26
|
|
|
} |
|
27
|
|
|
$folder = Folder::find_or_make("ErrorScreenshots"); |
|
28
|
|
|
|
|
29
|
|
|
$whatDidYouTryDoField = new TextareaField('WhatDidYouTryToDo', 'What did you try to do'); |
|
30
|
|
|
$whatDidYouTryDoField->setRows(3); |
|
31
|
|
|
|
|
32
|
|
|
$whatWentWrongField = new TextareaField('WhatWentWrong', 'What went wrong'); |
|
33
|
|
|
$whatWentWrongField->setRows(3); |
|
34
|
|
|
|
|
35
|
|
|
$screenshotField = new FileField( |
|
36
|
|
|
'Screenshot', |
|
37
|
|
|
'To take a screenshot press the PRT SCR button on your keyboard, then open MS Word or MS Paint and paste the screenshot. Save the file and then attach (upload) the file here.' |
|
38
|
|
|
); |
|
39
|
|
|
$screenshotField->setFolderName($folder->Name); |
|
40
|
|
|
|
|
41
|
|
|
$form = new Form($this, 'Form', |
|
42
|
|
|
new FieldList( |
|
43
|
|
|
new TextField('Name'), |
|
44
|
|
|
new TextField('Email'), |
|
45
|
|
|
new TextField('URL', 'What is the URL of the page the error occured (this is the address shown in the address bar (e.g. http://www.mysite.com/mypage/with/errors/)', $url), |
|
46
|
|
|
$whatDidYouTryDoField, |
|
47
|
|
|
$whatWentWrongField, |
|
48
|
|
|
$screenshotField |
|
49
|
|
|
), |
|
50
|
|
|
new FieldList( |
|
51
|
|
|
new FormAction('senderror', 'Submit Error') |
|
52
|
|
|
), |
|
53
|
|
|
new RequiredFields(array("Email", "Name")) |
|
54
|
|
|
); |
|
55
|
|
|
return $form; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function senderror($data, $form) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
mail($this->Config()->get("email_to_send_error_to"), "error on ".Director::absoluteURL(), print_r($data, true)); |
|
|
|
|
|
|
61
|
|
|
$this->showThankYouNote = true; |
|
62
|
|
|
return array(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function ShowThankYouNote() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->showThankYouNote; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function Link($action = "") |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
return "/error/report/"; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.