-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
75 lines (62 loc) · 2.63 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require "global.php";
require "Slim/Slim.php";
//load slim
$app = new \Slim\Slim(array('debug' => true));
$app->get('/phpinfo', function () {
echo phpinfo();
});
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->router()->map('/:dept/:module(/:action(/:id(/:params+)))',
function ($dept,$module) use ($app) {
//checking pagelist
$found=true;
$params = $app->router()->getCurrentRoute()->getParams();
$location = $params["dept"] . "/" . $params["module"];
if (!array_key_exists('action',$params)) {
$found=false;
} else if ($params["action"]==null || $params["action"]=="") {
$found=false;
} else {
$action = $params["action"];
}
//set default actions for post and get
if (!$found) {
switch ($_SERVER["REQUEST_METHOD"]) {
case "GET":
$action="LIST";
break;
case "POST":
$action="EDIT";
break;
}
}
//check page exist in pagelist
$sql = "select * from sys_pagelist left join sys_pagelistaction on sys_pagelist.pagelist_id = sys_pagelistaction.pagelist_id left join sys_pageaction on sys_pagelistaction.pageaction_id = sys_pageaction.pageaction_id where url='".escapesql($location)."' and sys_pageaction.name='".escapesql($action)."'";
$result = mysql_query($sql);
if (mysql_num_rows($result)>0) {
$row = mysql_fetch_array($result);
//load page
$moduleclass = $params["module"].ucfirst(strtolower($row["type"]));
$ref = new ReflectionClass ('\\'.$params["dept"]."\\".$moduleclass);
$webpage = $ref->newInstanceArgs(array("app"=>$app,"pagelist"=>$row["pagelist_id"]));
$webpage->run();
/*
if (!is_subclass_of($webpage, ucfirst($row["type"]))) {
$app->notFound();
} else {
}
*/
} else {
$app->notFound();
}
}
)->name("defaultroute")->via('GET','POST');
$app->run();
?>