Code Duplication    Length = 18-18 lines in 3 locations

api/v1/areas.php 2 locations

@@ 26-43 (lines=18) @@
23
    echo json_encode($areas);
24
}
25
26
function create_area()
27
{
28
    global $app;
29
    if(!$app->user)
30
    {
31
        throw new Exception('Must be logged in', ACCESS_DENIED);
32
    }
33
    if(!$app->user->isInGroupNamed("LDAPAdmins"))
34
    {
35
        throw new Exception('Must be Admin', ACCESS_DENIED);
36
    }
37
    $body = $app->request->getBody();
38
    $obj  = json_decode($body);
39
    $data_set = DataSetFactory::getDataSetByName('profiles');
40
    $data_table = $data_set['area'];
41
    $ret = $data_table->create($obj);
42
    echo json_encode($ret);
43
}
44
45
function get_area($name)
46
{
@@ 62-79 (lines=18) @@
59
    echo json_encode($areas);
60
}
61
62
function update_area($name)
63
{
64
    global $app;
65
    if(!$app->user)
66
    {
67
        throw new Exception('Must be logged in', ACCESS_DENIED);
68
    }
69
    if(!$app->user->isInGroupNamed("LDAPAdmins"))
70
    {
71
        throw new Exception('Must be Admin', ACCESS_DENIED);
72
    }
73
    $body = $app->request->getBody();
74
    $obj  = json_decode($body);
75
    $data_set = DataSetFactory::getDataSetByName('profiles');
76
    $data_table = $data_set['area'];
77
    $ret = $data_table->update(new \Data\Filter("short_name eq $name"), $obj);
78
    echo json_encode($ret);
79
}
80
81
function get_area_leads($name)
82
{

api/v1/index.php 1 location

@@ 215-232 (lines=18) @@
212
    $app->post('', 'validate_post_code');
213
}
214
215
function addLead()
216
{
217
    global $app;
218
    if(!$app->user)
219
    {
220
        throw new Exception('Must be logged in', ACCESS_DENIED);
221
    }
222
    if(!$app->user->isInGroupNamed('LDAPAdmins'))
223
    {
224
        throw new Exception('Must be LDAPAdmins', ACCESS_DENIED);
225
    }
226
    $body = $app->request->getBody();
227
    $obj  = json_decode($body);
228
    $data_set = DataSetFactory::getDataSetByName('profiles');
229
    $data_table = $data_set['position'];
230
    $ret = $data_table->create($obj);
231
    echo json_encode($ret);
232
}
233
234
$app->run();
235
?>