1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* // @todo could probably extend ModuleHandler, and therefore not need the |
4
|
|
|
* constant pointing to the modules. |
5
|
|
|
@package Intraface_IntranetMaintenance |
6
|
|
|
*/ |
7
|
1 |
|
require_once 'Intraface/modules/intranetmaintenance/ModuleMaintenance.php'; |
8
|
|
|
|
9
|
|
|
class Intraface_ModuleGateway |
10
|
|
|
{ |
11
|
|
|
private $id; |
|
|
|
|
12
|
|
|
private $db; |
13
|
|
|
private $value; |
|
|
|
|
14
|
|
|
public $error; |
15
|
|
|
private $sub_access; |
|
|
|
|
16
|
|
|
|
17
|
21 |
|
public function __construct(MDB2_Driver_Common $db) |
18
|
1 |
|
{ |
19
|
21 |
|
$this->db = $db; |
20
|
21 |
|
$this->error = new Intraface_Error; |
21
|
21 |
|
} |
22
|
|
|
|
23
|
|
|
function findById($id) |
24
|
|
|
{ |
25
|
|
|
return new ModuleMaintenance($id); |
26
|
|
|
} |
27
|
|
|
|
28
|
20 |
|
function findByName($name) |
29
|
|
|
{ |
30
|
1 |
|
$result = $this->db->query("SELECT id FROM module WHERE name = ".$this->db->quote($name, 'text')); |
31
|
1 |
|
if (PEAR::isError($result)) { |
32
|
20 |
|
throw new Exception("Error in query: ".$result->getUserInfo()); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
if ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
36
|
1 |
|
return new ModuleMaintenance($row['id']); |
37
|
|
|
} else { |
38
|
|
|
throw new Exception("invalid module name ".$name."!"); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
20 |
|
public function registerByName($module_name) |
43
|
|
|
{ |
44
|
20 |
|
$db = new DB_Sql; |
45
|
20 |
|
$updated_sub_access_id = array(); |
46
|
20 |
|
$module_msg = array(); |
47
|
20 |
|
$updated_module_id = 0; |
48
|
|
|
|
49
|
20 |
|
$main_class_name = "Main".ucfirst($module_name); |
50
|
20 |
|
$main_class_path = PATH_INCLUDE_MODULE.$module_name."/".$main_class_name.".php"; |
51
|
|
|
|
52
|
|
|
|
53
|
20 |
|
if (!file_exists($main_class_path)) { |
54
|
20 |
|
$this->error->set("Filen ".$main_class_path." eksistere ikke!"); |
55
|
|
|
} else { |
56
|
20 |
|
include_once $main_class_path; |
57
|
20 |
|
$module = new $main_class_name; |
58
|
|
|
|
59
|
20 |
|
if (!is_object($module)) { |
60
|
|
|
$this->error->set($main_class_name." kunne ikke initialiseres!"); |
61
|
|
|
} else { |
62
|
|
|
// her kan vi oprette tabellerne n�dvendige for det enkelte modul i stedet for at have dem i starten. |
63
|
|
|
|
64
|
20 |
|
if (empty($module->menu_label) && empty($module->active) && empty($module->menu_index)) { |
65
|
|
|
$this->error->set('Properties for module "'.$module_name.'" er ikke loadet. Kontrol er constructor er sat rigtigt op i modulet'); |
66
|
|
|
} else { |
67
|
20 |
|
$sql = "menu_label = \"".$module->getMenuLabel()."\", |
68
|
20 |
|
show_menu = ".$module->getShowMenu().", |
69
|
20 |
|
active = ".$module->isActive().", |
70
|
20 |
|
menu_index = ".intval($module->getMenuIndex()).", |
71
|
20 |
|
frontpage_index = ".intval($module->getFrontpageIndex()).", |
72
|
20 |
|
required = " . intval($module->isRequired()); |
73
|
|
|
|
74
|
20 |
|
$db->query("SELECT id FROM module WHERE name = \"".$module_name."\""); |
75
|
20 |
|
if ($db->nextRecord()) { |
76
|
20 |
|
$module_id = $db->f("id"); |
77
|
20 |
|
$db->query("UPDATE module SET ".$sql." WHERE id = ".$module_id); |
78
|
20 |
|
$module_msg[$module_name] = "Opdateret"; |
79
|
20 |
|
} else { |
80
|
1 |
|
$db->query("INSERT INTO module SET name = \"".$module_name."\", ".$sql); |
81
|
1 |
|
$module_id = $db->insertedId(); |
82
|
1 |
|
$module_msg[$module_name] = "Registreret"; |
83
|
|
|
} |
84
|
20 |
|
$db->free(); |
85
|
|
|
|
86
|
20 |
|
$updated_module_id = $module_id; |
87
|
20 |
|
$count_subaccess = count($module->sub_access); |
88
|
|
|
|
89
|
20 |
|
for ($i = 0; $i < $count_subaccess; $i++) { |
90
|
20 |
|
$db->query("SELECT id FROM module_sub_access WHERE module_id = ".$module_id." AND name = \"".$module->sub_access[$i]."\""); |
91
|
20 |
|
if ($db->nextRecord()) { |
92
|
19 |
|
$updated_sub_access_id[] = $db->f('id'); |
93
|
19 |
|
$db->query("UPDATE module_sub_access SET description = \"".$module->sub_access_description[$i]."\", active = 1 WHERE id = ".$db->f("id")); |
94
|
19 |
|
} else { |
95
|
1 |
|
$db->query("INSERT INTO module_sub_access SET module_id = ".$module_id.", name = \"".$module->sub_access[$i]."\", description = \"".$module->sub_access_description[$i]."\", active = 1"); |
96
|
1 |
|
$updated_sub_access_id[] = $db->insertedId(); |
97
|
|
|
} |
98
|
20 |
|
$db->free(); |
99
|
20 |
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
20 |
|
return array('module_msg' => $module_msg, 'updated_module_id' => $updated_module_id, 'updated_sub_access_id' => $updated_sub_access_id); |
105
|
|
|
} |
106
|
|
|
|
107
|
19 |
|
public function registerAll() |
108
|
|
|
{ |
109
|
19 |
|
$msg = array(); |
|
|
|
|
110
|
19 |
|
$module_msg = array(); |
111
|
19 |
|
$db = new DB_Sql; |
112
|
19 |
|
$updated_sub_access_id = array(); |
|
|
|
|
113
|
|
|
|
114
|
19 |
|
if ($handle = opendir(PATH_INCLUDE_MODULE)) { |
115
|
19 |
|
$updated_module_id = array(); |
116
|
19 |
|
$updated_sub_access_id = array(); |
117
|
|
|
|
118
|
19 |
|
while (false !== ($module_name = readdir($handle))) { |
119
|
19 |
|
if (substr($module_name, 0, 1) == ".") { |
120
|
19 |
|
continue; // starter forfra p� n�ste directory |
121
|
|
|
} |
122
|
|
|
|
123
|
19 |
|
if (substr($module_name, 0, 5) == "_old_") { |
124
|
|
|
// Det er et slettet modul - det f�r lov at blive uden en besked |
125
|
|
|
continue; |
126
|
|
|
} |
127
|
|
|
|
128
|
19 |
|
if (!preg_match("/^[a-z0-9]+$/", $module_name)) { |
129
|
|
|
$this->error->set($module_name." er et ugyldigt navn"); |
130
|
|
|
// $msg[] = $module_name." er et ugyldigt navn"; |
|
|
|
|
131
|
|
|
continue; // starter forfra p� n�ste directory |
132
|
|
|
} |
133
|
|
|
|
134
|
19 |
|
$updated = $this->registerByName($module_name); |
135
|
|
|
|
136
|
19 |
|
$updated_module_id[] = (int)$updated['updated_module_id']; |
137
|
19 |
|
$updated_sub_access_id = array_merge($updated_sub_access_id, $updated['updated_sub_access_id']); |
138
|
19 |
|
$module_msg = array_merge($module_msg, $updated['module_msg']); |
139
|
19 |
|
} |
140
|
|
|
|
141
|
|
|
// S�tte alle moduler som ikke l�ngere eksistere til active = 0 |
142
|
19 |
View Code Duplication |
if (count($updated_module_id) > 0) { |
143
|
19 |
|
$db->query("UPDATE module SET active = 0 WHERE id NOT IN (".implode(",", $updated_module_id).")"); |
144
|
19 |
|
$module_msg['update'] = $db->affectedRows()." moduler er fjernet og blevet deaktiveret.<br />"; |
145
|
19 |
|
} |
146
|
|
|
|
147
|
19 |
View Code Duplication |
if (count($updated_sub_access_id) > 0) { |
148
|
19 |
|
$db->query("UPDATE module_sub_access SET active = 0 WHERE id NOT IN (".implode(",", $updated_sub_access_id).")"); |
149
|
19 |
|
$module_msg['update'] .= $db->affectedRows()." sub access' er fjernet og blevet deaktiveret."; |
150
|
19 |
|
} |
151
|
19 |
|
} |
152
|
|
|
|
153
|
19 |
|
return $module_msg; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function getList() |
157
|
|
|
{ |
158
|
|
|
$db = new DB_Sql; |
159
|
|
|
|
160
|
|
|
$i = 0; |
161
|
|
|
$result = $this->db->query("SELECT id, name, menu_label, show_menu, menu_index, frontpage_index FROM module WHERE active = 1 ORDER BY menu_index"); |
162
|
|
|
if (PEAR::isError($result)) { |
163
|
|
|
throw new Exception("Error in query: ".$result->getUserInfo()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
while ($row = $result->fetchRow()) { |
167
|
|
|
$value[$i] = $row; |
|
|
|
|
168
|
|
|
|
169
|
|
|
$j = 0; |
170
|
|
|
$db->query("SELECT id, name, description FROM module_sub_access WHERE active = 1 AND module_id = ".$row['id']." ORDER BY description"); |
171
|
|
|
while ($db->nextRecord()) { |
172
|
|
|
$value[$i]["sub_access"][$j]["id"] = $db->f("id"); |
|
|
|
|
173
|
|
|
$value[$i]["sub_access"][$j]["name"] = $db->f("name"); |
174
|
|
|
$value[$i]["sub_access"][$j]["description"] = $db->f("description"); |
175
|
|
|
$j++; |
176
|
|
|
} |
177
|
|
|
$i++; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $value; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.