Completed
Pull Request — master (#518)
by Daniel
35:40
created

UserDefinedForm_Controller::index()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 3
nop 0
crap 4.016
1
<?php
2
3
use SilverStripe\View\Requirements;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Requirements.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use SilverStripe\Forms\LabelField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LabelField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use SilverStripe\Forms\CompositeField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CompositeField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldConfig_RecordEditor.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use SilverStripe\Forms\GridField\GridField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use SilverStripe\ORM\DB;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DB.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use SilverStripe\Forms\GridField\GridFieldConfig;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldConfig.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldToolbarHeader.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldSortableHeader.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use SilverStripe\Forms\GridField\GridFieldDataColumns;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDataColumns.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
13
use SilverStripe\Forms\GridField\GridFieldEditButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldEditButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDeleteAction.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use SilverStripe\Forms\GridField\GridFieldPageCount;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPageCount.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use SilverStripe\Forms\GridField\GridFieldPaginator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPaginator.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use SilverStripe\Forms\GridField\GridFieldDetailForm;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDetailForm.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use SilverStripe\Forms\GridField\GridFieldButtonRow;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldButtonRow.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use SilverStripe\Forms\GridField\GridFieldExportButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldExportButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use SilverStripe\Forms\GridField\GridFieldPrintButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPrintButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use SilverStripe\Forms\CheckboxField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CheckboxField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
use SilverStripe\Forms\LiteralField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LiteralField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
23
use SilverStripe\ORM\ArrayList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ArrayList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
use SilverStripe\Forms\TextField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, TextField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use SilverStripe\Forms\FieldList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FieldList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
26
use SilverStripe\Core\Injector\Injector;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Injector.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
27
use SilverStripe\i18n\i18n;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, i18n.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
28
use SilverStripe\ORM\FieldType\DBField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DBField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
29
use SilverStripe\Core\Object;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Object.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
30
use SilverStripe\Security\Member;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Member.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
31
use SilverStripe\Assets\Upload;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Upload.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
32
use SilverStripe\Assets\File;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, File.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
33
use SilverStripe\Control\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Controller.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
34
use SilverStripe\ORM\ValidationException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ValidationException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
35
use SilverStripe\Control\HTTP;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HTTP.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
36
use SilverStripe\View\SSViewer;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, SSViewer.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
37
use SilverStripe\Control\Session;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
38
use SilverStripe\View\ArrayData;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ArrayData.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
39
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HTMLEditorField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
40
41
42
/**
43
 * @package userforms
44
 */
45
46
class UserDefinedForm extends Page
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
47
{
48
    
49
    /**
50
     * @var string
51
     */
52
    private static $icon = 'userforms/images/sitetree_icon.png';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
53
54
    /**
55
     * @var string
56
     */
57
    private static $description = 'Adds a customizable form.';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
59
    /**
60
     * @var string Required Identifier
61
     */
62
    private static $required_identifier = null;
0 ignored issues
show
Unused Code introduced by
The property $required_identifier is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
63
64
    /**
65
     * @var string
66
     */
67
    private static $email_template_directory = 'userforms/templates/email/';
0 ignored issues
show
Unused Code introduced by
The property $email_template_directory is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
69
    /**
70
     * Should this module automatically upgrade on dev/build?
71
     *
72
     * @config
73
     * @var bool
74
     */
75
    private static $upgrade_on_build = true;
0 ignored issues
show
Unused Code introduced by
The property $upgrade_on_build is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
76
77
    /**
78
     * Built in extensions required by this page
79
     * @config
80
     * @var array
81
     */
82
    private static $extensions = array(
0 ignored issues
show
Unused Code introduced by
The property $extensions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
83
        'UserFormFieldEditorExtension'
84
    );
85
86
    /**
87
     * @var array Fields on the user defined form page.
88
     */
89
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
90
        "SubmitButtonText" => "Varchar",
91
        "ClearButtonText" => "Varchar",
92
        "OnCompleteMessage" => "HTMLText",
93
        "ShowClearButton" => "Boolean",
94
        'DisableSaveSubmissions' => 'Boolean',
95
        'EnableLiveValidation' => 'Boolean',
96
        'HideFieldLabels' => 'Boolean',
97
        'DisplayErrorMessagesAtTop' => 'Boolean',
98
        'DisableAuthenicatedFinishAction' => 'Boolean',
99
        'DisableCsrfSecurityToken' => 'Boolean'
100
    );
101
102
    /**
103
     * @var array Default values of variables when this page is created
104
     */
105
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
106
        'Content' => '$UserDefinedForm',
107
        'DisableSaveSubmissions' => 0,
108
        'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
109
    );
110
111
    /**
112
     * @var array
113
     */
114
    private static $has_many = array(
0 ignored issues
show
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
115
        "Submissions" => "SubmittedForm",
116
        "EmailRecipients" => "UserDefinedForm_EmailRecipient"
117
    );
118
119
    /**
120
     * @var array
121 2
     * @config
122 2
     */
123 2
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
124
        'ErrorContainerID' => 'Text'
125 2
    );
126
127
    /**
128
     * Error container selector which matches the element for grouped messages
129
     *
130 2
     * @var string
131 2
     * @config
132 2
     */
133
    private static $error_container_id = 'error-container';
0 ignored issues
show
Unused Code introduced by
The property $error_container_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
134
135 2
    /**
136 2
     * The configuration used to determine whether a confirmation message is to
137 2
     * appear when navigating away from a partially completed form.
138 2
     *
139
     * @var boolean
140 2
     * @config
141
     */
142 2
    private static $enable_are_you_sure = true;
0 ignored issues
show
Unused Code introduced by
The property $enable_are_you_sure is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
143 2
144
    /**
145
     * @var bool
146 2
     * @config
147 2
     */
148 2
    private static $recipients_warning_enabled = false;
0 ignored issues
show
Unused Code introduced by
The property $recipients_warning_enabled is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
149 2
150 2
    /**
151
     * Temporary storage of field ids when the form is duplicated.
152
     * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
153 2
     * @var array
154 2
     */
155 2
    protected $fieldsFromTo = array();
156 2
157
    /**
158 2
     * @return FieldList
159
     */
160 2
     public function getCMSFields()
161 2
     {
162 2
         Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
163
164 2
         $self = $this;
165 2
166 2
         $this->beforeUpdateCMSFields(function ($fields) use ($self) {
167
168
            // define tabs
169
            $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
170 2
            $fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
171 2
            $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
172 2
173 2
            // text to show on complete
174 2
            $onCompleteFieldSet = new CompositeField(
175
                $label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
176
                $editor = new HtmlEditorField('OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
177 2
            );
178
179
            $onCompleteFieldSet->addExtraClass('field');
180
181
            $editor->setRows(3);
182
            $label->addExtraClass('left');
183
184
            // Define config for email recipients
185 2
            $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
186 2
            $emailRecipientsConfig->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton')
187 2
                ->setButtonName(
188
                    _t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
189 2
                );
190 2
191
            // who do we email on submission
192 2
            $emailRecipients = new GridField(
193
                'EmailRecipients',
194 2
                _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
195 2
                $self->EmailRecipients(),
196 2
                $emailRecipientsConfig
197 2
            );
198 2
            $emailRecipients
199 2
                ->getConfig()
200 2
                ->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDetailForm')
201 2
                ->setItemRequestClass('UserFormRecipientItemRequest');
202 2
203 2
            $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
204 2
            $fields->addFieldToTab('Root.Recipients', $emailRecipients);
205 2
            $fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
206 2
207
208
            // view the submissions
209
            $submissions = new GridField(
210 2
                'Submissions',
211 2
                _t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
212
                 $self->Submissions()->sort('Created', 'DESC')
213 2
            );
214 2
215 2
            // make sure a numeric not a empty string is checked against this int column for SQL server
216 1
            $parentID = (!empty($self->ID)) ? (int) $self->ID : 0;
217 1
218 2
            // get a list of all field names and values used for print and export CSV views of the GridField below.
219
            $columnSQL = <<<SQL
220 2
SELECT "SubmittedFormField"."Name" as "Name", COALESCE("EditableFormField"."Title", "SubmittedFormField"."Title") as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort"
221
FROM "SubmittedFormField"
222
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
223
LEFT JOIN "EditableFormField" ON "EditableFormField"."Name" = "SubmittedFormField"."Name" AND "EditableFormField"."ParentID" = '$parentID'
224
WHERE "SubmittedForm"."ParentID" = '$parentID'
225 2
ORDER BY "Sort", "Title"
226
SQL;
227
            // Sanitise periods in title
228
            $columns = array();
229 2
            foreach (DB::query($columnSQL)->map() as $name => $title) {
230 2
                $columns[$name] = trim(strtr($title, '.', ' '));
231 2
            }
232
233
            $config = new GridFieldConfig();
234 2
            $config->addComponent(new GridFieldToolbarHeader());
235 2
            $config->addComponent($sort = new GridFieldSortableHeader());
236
            $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
237
            $config->addComponent(new GridFieldDataColumns());
238
            $config->addComponent(new GridFieldEditButton());
239 2
            $config->addComponent(new GridFieldDeleteAction());
240 2
            $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
241
            $config->addComponent($pagination = new GridFieldPaginator(25));
242
            $config->addComponent(new GridFieldDetailForm());
243 2
            $config->addComponent(new GridFieldButtonRow('after'));
244 2
            $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
245
            $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
246 2
247 2
            // show user form items in the summary tab
248 2
            $summaryarray = array(
249
                'ID' => 'ID',
250 2
                'Created' => 'Created',
251
                'LastEdited' => 'Last Edited'
252 2
            );
253
            foreach(EditableFormField::get()->filter(array("ParentID" => $parentID)) as $eff) {
254 2
                if($eff->ShowInSummary) {
255
                    $summaryarray[$eff->Name] = $eff->Title ?: $eff->Name;
256
                }
257
            }
258
            
259
            $config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray);
260
            
261 2
            /**
262
             * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
263
             */
264
            if (class_exists('GridFieldBulkManager')) {
265
                $config->addComponent(new GridFieldBulkManager());
266
            }
267
268
            $sort->setThrowExceptionOnBadDataType(false);
269
            $filter->setThrowExceptionOnBadDataType(false);
270
            $pagination->setThrowExceptionOnBadDataType(false);
271
272 3
            // attach every column to the print view form
273
            $columns['Created'] = 'Created';
274 3
            $filter->setColumns($columns);
275
276
            // print configuration
277
278 2
            $print->setPrintHasHeader(true);
279 3
            $print->setPrintColumns($columns);
280
281 3
            // export configuration
282
            $export->setCsvHasHeader(true);
283 3
            $export->setExportColumns($columns);
284
285
            $submissions->setConfig($config);
286
            $fields->addFieldToTab('Root.Submissions', $submissions);
287
            $fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')));
288
289
        });
290
291
         $fields = parent::getCMSFields();
292 3
293
         if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
294 3
             $fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
295 3
                "<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
296
                "Warning: You have not configured any recipients. Form submissions may be missed.")
297 3
                . "</p>"), "Title");
298 3
         }
299 3
300 3
         return $fields;
301 3
     }
302 3
303 3
    /**
304 3
     * Allow overriding the EmailRecipients on a {@link DataExtension}
305 3
     * so you can customise who receives an email.
306 3
     * Converts the RelationList to an ArrayList so that manipulation
307
     * of the original source data isn't possible.
308 3
     *
309
     * @return ArrayList
310 3
     */
311
    public function FilteredEmailRecipients($data = null, $form = null)
312
    {
313
        $recipients = new ArrayList($this->EmailRecipients()->toArray());
314
315
        // Filter by rules
316
        $recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
317
            return $recipient->canSend($data, $form);
318
        });
319
320
        $this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
321
322
        return $recipients;
323
    }
324
325
    /**
326
     * Custom options for the form. You can extend the built in options by
327
     * using {@link updateFormOptions()}
328
     *
329
     * @return FieldList
330
     */
331
    public function getFormOptions()
332
    {
333
        $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
334
        $clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
335
336
        $options = new FieldList(
337
            new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
338
            new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
339
            new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
340
            new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
341
            new CheckboxField("HideFieldLabels", _t('UserDefinedForm.HIDEFIELDLABELS', 'Hide field labels')),
342
            new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
343
            new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
344
            new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
345
        );
346
347
        $this->extend('updateFormOptions', $options);
348
349
        return $options;
350
    }
351
352
    /**
353
     * Get the HTML id of the error container displayed above the form.
354
     *
355
     * @return string
356
     */
357
    public function getErrorContainerID()
358
    {
359
        return $this->config()->error_container_id;
360
    }
361
362
    public function requireDefaultRecords()
363
    {
364
        parent::requireDefaultRecords();
365
366
        if (!$this->config()->upgrade_on_build) {
367
            return;
368 6
        }
369
370 5
        // Perform migrations
371
        Injector::inst()
372
            ->create('UserFormsUpgradeService')
373 5
            ->setQuiet(true)
374 5
            ->run();
375 5
376 5
        DB::alteration_message('Migrated userforms', 'changed');
377 5
    }
378 5
379
380 5
    /**
381 5
     * Validate formfields
382 5
     */
383 5
    public function getCMSValidator()
384 6
    {
385 6
        return new UserFormValidator();
386 5
    }
387
}
388
389
/**
390
 * Controller for the {@link UserDefinedForm} page type.
391 5
 *
392 5
 * @package userforms
393 5
 */
394 5
395 5
class UserDefinedForm_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
396
{
397
398
    private static $finished_anchor = '#uff';
0 ignored issues
show
Unused Code introduced by
The property $finished_anchor is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
399
400
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
401
        'index',
402
        'ping',
403
        'Form',
404 6
        'finished'
405
    );
406 6
407 6
    public function init()
408 6
    {
409 5
        parent::init();
410
411 5
        // load the jquery
412
        $lang = i18n::get_lang_from_locale(i18n::get_locale());
413 5
        Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
414
        Requirements::javascript('http://code.jquery.com/jquery-1.7.2.min.js');
415 1
        Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
416
        Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
417
        Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
418 1
419 1
420 2 View Code Duplication
        if(file_exists(BASE_PATH . '/' . USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
421
            Requirements::javascript(
422
                USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
423
            );
424
        }
425 View Code Duplication
        if(file_exists(BASE_PATH . '/' . USERFORMS_DIR . "//thirdparty/jquery-validate/localization/methods_{$lang}.min.js")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
426
            Requirements::javascript(
427
                USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
428
            );
429
        }
430
        if ($this->HideFieldLabels) {
431
            Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
432
        }
433
434
        // Bind a confirmation message when navigating away from a partially completed form.
435
        $page = $this->data();
436
        if ($page::config()->enable_are_you_sure) {
437
            Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
438
        }
439 9
    }
440
441 9
    /**
442 9
     * Using $UserDefinedForm in the Content area of the page shows
443 9
     * where the form should be rendered into. If it does not exist
444
     * then default back to $Form.
445
     *
446
     * @return array
447
     */
448
    public function index()
449
    {
450
        if ($this->Content && $form = $this->Form()) {
451 9
            $hasLocation = stristr($this->Content, '$UserDefinedForm');
452
            if ($hasLocation) {
453 9
                $content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
454 9
                return array(
455
                    'Content' => DBField::create_field('HTMLText', $content),
456 9
                    'Form' => ""
457 9
                );
458
            }
459 9
        }
460 9
461 8
        return array(
462
            'Content' => DBField::create_field('HTMLText', $this->Content),
463
            'Form' => $this->Form()
464 8
        );
465
    }
466
467
    /**
468
     * Keep the session alive for the user.
469 8
     *
470
     * @return int
471
     */
472
    public function ping()
473
    {
474
        return 1;
475
    }
476
477
    /**
478
     * Get the form for the page. Form can be modified by calling {@link updateForm()}
479
     * on a UserDefinedForm extension.
480
     *
481
     * @return Forms
482
     */
483
    public function Form()
484
    {
485
        $form = UserForm::create($this);
486
        $this->generateConditionalJavascript();
487
        return $form;
488
    }
489
490
    /**
491
     * Generate the javascript for the conditional field show / hiding logic.
492
     *
493
     * @return void
494
     */
495
    public function generateConditionalJavascript()
496
    {
497
        $default = "";
498
        $rules = "";
499
500
        $watch = array();
501
        $watchLoad = array();
502
503
        if ($this->Fields()) {
504
            foreach ($this->Fields() as $field) {
505
                $holderSelector = $field->getSelectorHolder();
506
507 1
                // Is this Field Show by Default
508
                if (!$field->ShowOnLoad) {
509
                    $default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
510
                }
511
512
                // Check for field dependencies / default
513
                foreach ($field->EffectiveDisplayRules() as $rule) {
514
515 1
                    // Get the field which is effected
516
                    $formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
517
518
                    // Skip deleted fields
519
                    if (!$formFieldWatch) {
520
                        continue;
521
                    }
522
523 1
                    $fieldToWatch = $formFieldWatch->getSelectorField($rule);
524
                    $fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);
525
526
                    // show or hide?
527
                    $view = ($rule->Display == 'Hide') ? 'hide' : 'show';
528
                    $opposite = ($view == "show") ? "hide" : "show";
529
530
                    // what action do we need to keep track of. Something nicer here maybe?
531
                    // @todo encapulsation
532
                    $action = "change";
533
534
                    if ($formFieldWatch instanceof EditableTextField) {
535
                        $action = "keyup";
536
                    }
537
538
                    // is this field a special option field
539
                    $checkboxField = false;
540
                    $radioField = false;
541
542
                    if (in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
543
                        $action = "click";
544
                        $checkboxField = true;
545
                    } elseif ($formFieldWatch->ClassName == "EditableRadioField") {
546
                        $radioField = true;
547
                    }
548
549
                    // and what should we evaluate
550
                    switch ($rule->ConditionOption) {
551
                        case 'IsNotBlank':
552
                            $expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
553
554
                            break;
555
                        case 'IsBlank':
556
                            $expression = ($checkboxField || $radioField) ? '!($(this).is(":checked"))' : '$(this).val() == ""';
557
558
                            break;
559 View Code Duplication
                        case 'HasValue':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
560 1
                            if ($checkboxField) {
561
                                $expression = '$(this).prop("checked")';
562
                            } elseif ($radioField) {
563
                                // We cannot simply get the value of the radio group, we need to find the checked option first.
564
                                $expression = '$(this).parents(".field, .control-group").find("input:checked").val()=="'. $rule->FieldValue .'"';
565
                            } else {
566
                                $expression = '$(this).val() == "'. $rule->FieldValue .'"';
567
                            }
568 8
569 9
                            break;
570 9
                        case 'ValueLessThan':
571
                            $expression = '$(this).val() < parseFloat("'. $rule->FieldValue .'")';
572 9
573
                            break;
574
                        case 'ValueLessThanEqual':
575 1
                            $expression = '$(this).val() <= parseFloat("'. $rule->FieldValue .'")';
576
577
                            break;
578
                        case 'ValueGreaterThan':
579
                            $expression = '$(this).val() > parseFloat("'. $rule->FieldValue .'")';
580
581
                            break;
582
                        case 'ValueGreaterThanEqual':
583 1
                            $expression = '$(this).val() >= parseFloat("'. $rule->FieldValue .'")';
584
585
                            break;
586 View Code Duplication
                        default: // ==HasNotValue
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
587
                            if ($checkboxField) {
588
                                $expression = '!$(this).prop("checked")';
589
                            } elseif ($radioField) {
590
                                // We cannot simply get the value of the radio group, we need to find the checked option first.
591 1
                                $expression = '$(this).parents(".field, .control-group").find("input:checked").val()!="'. $rule->FieldValue .'"';
592
                            } else {
593
                                $expression = '$(this).val() != "'. $rule->FieldValue .'"';
594
                            }
595
596
                            break;
597
                    }
598
599
                    if (!isset($watch[$fieldToWatch])) {
600
                        $watch[$fieldToWatch] = array();
601
                    }
602
603
                    $watch[$fieldToWatch][] = array(
604
                        'expression' => $expression,
605
                        'holder_selector' => $holderSelector,
606
                        'view' => $view,
607
                        'opposite' => $opposite,
608
                        'action' => $action
609
                    );
610
611
                    $watchLoad[$fieldToWatchOnLoad] = true;
612
                }
613
            }
614 9
        }
615
616
        if ($watch) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $watch of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
617
            foreach ($watch as $key => $values) {
618
                $logic = array();
619
                $actions = array();
620
621
                foreach ($values as $rule) {
622
                    // Assign action
623 9
                    $actions[$rule['action']] = $rule['action'];
624
625
                    // Assign behaviour
626 3
                    $expression = $rule['expression'];
627
                    $holder = $rule['holder_selector'];
628
                    $view = $rule['view']; // hide or show
629
                    $opposite = $rule['opposite'];
630
                    // Generated javascript for triggering visibility
631
                    $logic[] = <<<"EOS"
632
if({$expression}) {
633
	{$holder}
634
		.{$view}()
635 9
		.trigger('userform.field.{$view}');
636
} else {
637
	{$holder}
638
		.{$opposite}()
639
		.trigger('userform.field.{$opposite}');
640
}
641
EOS;
642
                }
643
644
                $logic = implode("\n", $logic);
645
                $rules .= $key.".each(function() {\n
646
	$(this).data('userformConditions', function() {\n
647 3
		$logic\n
648
	}); \n
649 2
});\n";
650 2
                foreach ($actions as $action) {
651 2
                    $rules .= $key.".$action(function() {
652
	$(this).data('userformConditions').call(this);\n
653
});\n";
654 2
                }
655 2
            }
656 2
        }
657
658 2
        if ($watchLoad) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $watchLoad of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
659 2
            foreach ($watchLoad as $key => $value) {
660
                $rules .= $key.".each(function() {
661 2
	$(this).data('userformConditions').call(this);\n
662 2
});\n";
663 2
            }
664
        }
665
666 2
        // Only add customScript if $default or $rules is defined
667 2
        if ($default  || $rules) {
668 2
            Requirements::customScript(<<<JS
669 3
				(function($) {
670
					$(document).ready(function() {
671
						$default
672 2
673
						$rules
674
					})
675 2
				})(jQuery);
676 2
JS
677 2
, 'UserFormsConditional');
678
        }
679
    }
680 2
681 2
    /**
682
     * Process the form that is submitted through the site
683
     *
684
     * {@see UserForm::validate()} for validation step prior to processing
685
     *
686
     * @param array $data
687
     * @param Form $form
688
     *
689
     * @return Redirection
690
     */
691
    public function process($data, $form)
0 ignored issues
show
Coding Style introduced by
process uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
692
    {
693
        $submittedForm = Object::create('SubmittedForm');
694
        $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
695
        $submittedForm->ParentID = $this->ID;
696
697
        // if saving is not disabled save now to generate the ID
698
        if (!$this->DisableSaveSubmissions) {
699
            $submittedForm->write();
700
        }
701
702
        $attachments = array();
703
        $submittedFields = new ArrayList();
704
705
        foreach ($this->Fields() as $field) {
706
            if (!$field->showInReports()) {
707 2
                continue;
708
            }
709 2
710
            $submittedField = $field->getSubmittedFormField();
711 2
            $submittedField->ParentID = $submittedForm->ID;
712 2
            $submittedField->Name = $field->Name;
713 2
            $submittedField->Title = $field->getField('Title');
714
715 2
            // save the value from the data
716 2
            if ($field->hasMethod('getValueFromData')) {
717
                $submittedField->Value = $field->getValueFromData($data);
718
            } else {
719 2
                if (isset($data[$field->Name])) {
720
                    $submittedField->Value = $data[$field->Name];
721 2
                }
722
            }
723 2
724
            if (!empty($data[$field->Name])) {
725
                if (in_array("EditableFileField", $field->getClassAncestry())) {
726 2
                    if (isset($_FILES[$field->Name])) {
727 2
                        $foldername = $field->getFormField()->getFolderName();
728 1
729 1
                        // create the file from post data
730
                        $upload = new Upload();
731 1
                        $file = new File();
732
                        $file->ShowInSearch = 0;
733
                        try {
734
                            $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
735
                        } catch (ValidationException $e) {
0 ignored issues
show
Bug introduced by
The class SilverStripe\ORM\ValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
736
                            $validationResult = $e->getResult();
737
                            $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
738
                            Controller::curr()->redirectBack();
739
                            return;
740
                        }
741
742
                        // write file to form field
743 1
                        $submittedField->UploadedFileID = $file->ID;
744
745 1
                        // attach a file only if lower than 1MB
746
                        if ($file->getAbsoluteSize() < 1024*1024*1) {
747
                            $attachments[] = $file;
748
                        }
749 1
                    }
750 1
                }
751 1
            }
752 1
753 1
            $submittedField->extend('onPopulationFromField', $field);
754 1
755
            if (!$this->DisableSaveSubmissions) {
756 1
                $submittedField->write();
757
            }
758
759
            $submittedFields->push($submittedField);
760
        }
761 1
762 1
        $emailData = array(
763
            "Sender" => Member::currentUser(),
764 1
            "Fields" => $submittedFields
765
        );
766
767 1
        $this->extend('updateEmailData', $emailData, $attachments);
768
769 1
        // email users on submit.
770 1
        if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
771
            foreach ($recipients as $recipient) {
772 1
                $email = new UserFormRecipientEmail($submittedFields);
773
                $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
774
    
775 1
                if ($attachments) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $attachments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
776
                    foreach ($attachments as $file) {
777
                        if ($file->ID != 0) {
778 1
                            $email->attachFile(
779 1
                                $file->Filename,
780
                                $file->Filename,
781 1
                                HTTP::get_mime_type($file->Filename)
782
                            );
783
                        }
784 1
                    }
785
                }
786 1
                
787
                $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
788 1
789 1
                if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
790 1
                    $email->setTemplate($recipient->EmailTemplate);
791 1
                }
792 1
793 1
                $email->populateTemplate($recipient);
794 1
                $email->populateTemplate($emailData);
795
                $email->setFrom($recipient->EmailFrom);
796 1
                $email->setBody($parsedBody);
797 1
                $email->setTo($recipient->EmailAddress);
798 1
                $email->setSubject($recipient->EmailSubject);
799 1
800
                if ($recipient->EmailReplyTo) {
801 2
                    $email->setReplyTo($recipient->EmailReplyTo);
802 2
                }
803
804 2
                // check to see if they are a dynamic reply to. eg based on a email field a user selected
805 View Code Duplication
                if ($recipient->SendEmailFromField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
806 2
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
807 2
808
                    if ($submittedFormField && is_string($submittedFormField->Value)) {
809 2
                        $email->setReplyTo($submittedFormField->Value);
810
                    }
811
                }
812
                // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
813 2 View Code Duplication
                if ($recipient->SendEmailToField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
814 2
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
815
816
                    if ($submittedFormField && is_string($submittedFormField->Value)) {
817
                        $email->setTo($submittedFormField->Value);
818
                    }
819 2
                }
820 2
821 2
                // check to see if there is a dynamic subject
822 2 View Code Duplication
                if ($recipient->SendEmailSubjectField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
823 2
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
824 2
825
                    if ($submittedFormField && trim($submittedFormField->Value)) {
826 2
                        $email->setSubject($submittedFormField->Value);
827
                    }
828 2
                }
829 2
830 2
                $this->extend('updateEmail', $email, $recipient, $emailData);
831
832 2
                if ($recipient->SendPlain) {
833
                    $body = strip_tags($recipient->getEmailBodyContent()) . "\n";
834
                    if (isset($emailData['Fields']) && !$recipient->HideFormData) {
835
                        foreach ($emailData['Fields'] as $Field) {
836
                            $body .= $Field->Title .': '. $Field->Value ." \n";
837
                        }
838
                    }
839
840
                    $email->setBody($body);
841 1
                    $email->sendPlain();
842
                } else {
843 1
                    $email->send();
844
                }
845 1
            }
846 1
        }
847 1
848
        $submittedForm->extend('updateAfterProcess');
849 1
850
        Session::clear("FormInfo.{$form->FormName()}.errors");
851
        Session::clear("FormInfo.{$form->FormName()}.data");
852
853
        $referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
854
855
        // set a session variable from the security ID to stop people accessing
856
        // the finished method directly.
857
        if (!$this->DisableAuthenicatedFinishAction) {
858 9
            if (isset($data['SecurityID'])) {
859
                Session::set('FormProcessed', $data['SecurityID']);
860 3
            } else {
861
                // if the form has had tokens disabled we still need to set FormProcessed
862 3
                // to allow us to get through the finshed method
863 1
                if (!$this->Form()->getSecurityToken()->isEnabled()) {
864 1
                    $randNum = rand(1, 1000);
865
                    $randHash = md5($randNum);
866 3
                    Session::set('FormProcessed', $randHash);
867
                    Session::set('FormProcessedNum', $randNum);
868 3
                }
869 3
            }
870
        }
871 3
872 1
        if (!$this->DisableSaveSubmissions) {
873
            Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
874 2
        }
875
876 2
        return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor);
877
    }
878 1
879 1
    /**
880
     * Allows the use of field values in email body.
881
     *
882 1
     * @param ArrayList fields
883
     * @return ArrayData
884
     */
885 2
    private function getMergeFieldsMap($fields = array())
886 9
    {
887
        $data = new ArrayData(array());
888 2
889 2
        foreach ($fields as $field) {
890 2
            $data->setField($field->Name, DBField::create_field('Text', $field->Value));
891
        }
892 2
893 2
        return $data;
894 2
    }
895
896
    /**
897
     * This action handles rendering the "finished" message, which is
898
     * customizable by editing the ReceivedFormSubmission template.
899
     *
900
     * @return ViewableData
901
     */
902
    public function finished()
0 ignored issues
show
Coding Style introduced by
finished uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
903
    {
904
        $submission = Session::get('userformssubmission'. $this->ID);
905
906
        if ($submission) {
907
            $submission = SubmittedForm::get()->byId($submission);
908
        }
909
910
        $referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
911
912
        if (!$this->DisableAuthenicatedFinishAction) {
913
            $formProcessed = Session::get('FormProcessed');
914
915
            if (!isset($formProcessed)) {
916
                return $this->redirect($this->Link() . $referrer);
917
            } else {
918
                $securityID = Session::get('SecurityID');
919
                // make sure the session matches the SecurityID and is not left over from another form
920
                if ($formProcessed != $securityID) {
921
                    // they may have disabled tokens on the form
922
                    $securityID = md5(Session::get('FormProcessedNum'));
923
                    if ($formProcessed != $securityID) {
924
                        return $this->redirect($this->Link() . $referrer);
925
                    }
926
                }
927
            }
928
929
            Session::clear('FormProcessed');
930
        }
931
932
        return $this->customise(array(
933
            'Content' => $this->customise(array(
934
                'Submission' => $submission,
935
                'Link' => $referrer
936
            ))->renderWith('ReceivedFormSubmission'),
937
            'Form' => '',
938
        ));
939
    }
940
}
941