1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class DataObjectSortBaseClass extends Controller implements PermissionProvider |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
private static $allowed_actions = array( |
|
|
|
|
9
|
|
|
"show" => 'DATA_OBJECT_SORT_AND_EDIT_PERMISSION' |
10
|
|
|
); |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Permission for user management. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
const CAN_DO_STUFF = 'DATA_OBJECT_SORT_AND_EDIT_PERMISSION'; |
18
|
|
|
|
19
|
|
|
public function providePermissions() |
20
|
|
|
{ |
21
|
|
|
return array( |
22
|
|
|
DataObjectSortBaseClass::CAN_DO_STUFF => array( |
23
|
|
|
'name' => _t( |
24
|
|
|
'DataObjectSortBaseClass.PERMISSION_MANAGE_USERS_DESCRIPTION', |
25
|
|
|
'Quick updates and edits' |
26
|
|
|
), |
27
|
|
|
'help' => _t( |
28
|
|
|
'DataObjectSortBaseClass.PERMISSION_MANAGE_USERS_HELP', |
29
|
|
|
'Allows for certain data to be sorted, edited, etc... This is around quick edits' |
30
|
|
|
), |
31
|
|
|
'category' => _t('DataObjectSortBaseClass.PERMISSIONS_CATEGORY', 'Miscellaneous'), |
32
|
|
|
'sort' => 100 |
33
|
|
|
) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function init() |
39
|
|
|
{ |
40
|
|
|
// Only administrators can run this method |
41
|
|
|
parent::init(); |
42
|
|
|
if (! Permission::check("DATA_OBJECT_SORT_AND_EDIT_PERMISSION")) { |
43
|
|
|
return $this->permissionFailureStandard(); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function show() |
48
|
|
|
{ |
49
|
|
|
return array(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
* @return string |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
protected function SecureFieldToBeUpdated() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
if (isset($_POST["Field"])) { |
60
|
|
|
return addslashes($_POST["Field"]); |
61
|
|
|
} |
62
|
|
|
$field = $this->getRequest()->param("OtherID"); |
63
|
|
|
if ($table = $this->SecureTableToBeUpdated()) { |
64
|
|
|
if ($tableObject = DataObject::get_one($table)) { |
65
|
|
|
if ($tableObject->hasDatabaseField($field)) { |
66
|
|
|
return $field; |
67
|
|
|
} else { |
68
|
|
|
user_error("$field does not exist on $table", E_USER_ERROR); |
69
|
|
|
} |
70
|
|
|
} else { |
71
|
|
|
user_error("there are no records in $table", E_USER_ERROR); |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
user_error("there is no table specified", E_USER_ERROR); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @return string |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
protected function SecureTableToBeUpdated() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
if (isset($_POST["Table"])) { |
85
|
|
|
$table = addslashes($_POST["Table"]); |
86
|
|
|
} else { |
87
|
|
|
$table = $this->getRequest()->param("ID"); |
88
|
|
|
} |
89
|
|
|
if (class_exists($table)) { |
90
|
|
|
return $table; |
91
|
|
|
} else { |
92
|
|
|
user_error("could not find record: $table", E_USER_ERROR); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
|
|
protected function SecureRecordToBeUpdated() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
if (isset($_POST["Record"])) { |
104
|
|
|
return intval($_POST["Record"]); |
105
|
|
|
} |
106
|
|
|
if (isset($_GET["id"])) { |
107
|
|
|
$record = $_GET["id"]; |
108
|
|
|
return intval($record); |
109
|
|
|
} |
110
|
|
|
return 0; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* |
116
|
|
|
* |
117
|
|
|
* @param DataObject $obj [description] |
118
|
|
|
* @param string $fieldName [description] |
119
|
|
|
* @return FormField |
120
|
|
|
*/ |
121
|
|
|
protected function getFormField($obj, $fieldName) |
122
|
|
|
{ |
123
|
|
|
if (!self::$field) { |
124
|
|
|
self::$field = $obj->dbObject($fieldName)->scaffoldFormField($obj->Title); |
125
|
|
|
} |
126
|
|
|
return self::$field; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
protected function HumanReadableTableName() |
134
|
|
|
{ |
135
|
|
|
return singleton($this->SecureTableToBeUpdated())->plural_name(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function Link($action = null) |
143
|
|
|
{ |
144
|
|
|
$link = Config::inst()->get($this->class, 'url_segment').'/'; |
145
|
|
|
if ($action) { |
146
|
|
|
$link .= "$action/"; |
147
|
|
|
} |
148
|
|
|
return $link; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function permissionFailureStandard() |
152
|
|
|
{ |
153
|
|
|
return Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need administrator rights to access it. Enter your credentials below and we will send you right along.')); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
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.