|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* EGroupware Setup |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://www.egroupware.org |
|
6
|
|
|
* @package setup |
|
7
|
|
|
* @copyright (c) 2006-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
|
8
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
|
9
|
|
|
* @version $Id$ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use EGroupware\Api; |
|
13
|
|
|
|
|
14
|
|
|
$GLOBALS['egw_info'] = array( |
|
15
|
|
|
'flags' => array( |
|
16
|
|
|
'noheader' => True, |
|
17
|
|
|
'nonavbar' => True, |
|
18
|
|
|
'currentapp' => 'home', |
|
19
|
|
|
'noapi' => True |
|
20
|
|
|
)); |
|
21
|
|
|
include('./inc/functions.inc.php'); |
|
22
|
|
|
|
|
23
|
|
|
/* Check header and authentication */ |
|
24
|
|
|
if(!$GLOBALS['egw_setup']->auth('Config')) |
|
25
|
|
|
{ |
|
26
|
|
|
Header('Location: index.php'); |
|
27
|
|
|
exit; |
|
28
|
|
|
} |
|
29
|
|
|
// Does not return unless user is authorized |
|
30
|
|
|
|
|
31
|
|
|
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup'); |
|
32
|
|
|
$setup_tpl = CreateObject('phpgwapi.Template',$tpl_root); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$cancel = $_REQUEST['cancel']; |
|
35
|
|
|
if($cancel) |
|
36
|
|
|
{ |
|
37
|
|
|
Header('Location: applications.php'); |
|
38
|
|
|
exit; |
|
39
|
|
|
} |
|
40
|
|
|
$apps = $_REQUEST['apps']; |
|
41
|
|
|
$download = $_REQUEST['download']; |
|
42
|
|
|
$submit = $_REQUEST['submit']; |
|
43
|
|
|
$showall = $_REQUEST['showall']; |
|
44
|
|
|
$appname = $_REQUEST['appname']; |
|
45
|
|
|
if($download) |
|
46
|
|
|
{ |
|
47
|
|
|
$setup_tpl->set_file(array( |
|
48
|
|
|
'sqlarr' => 'arraydl.tpl' |
|
49
|
|
|
)); |
|
50
|
|
|
$setup_tpl->set_var('idstring',"/* \$Id" . ": tables_current.inc.php" . ",v 1.0" . " 2001/05/28 08:42:04 username " . "Exp \$ */"); |
|
51
|
|
|
$setup_tpl->set_block('sqlarr','sqlheader','sqlheader'); |
|
52
|
|
|
$setup_tpl->set_block('sqlarr','sqlbody','sqlbody'); |
|
53
|
|
|
$setup_tpl->set_block('sqlarr','sqlfooter','sqlfooter'); |
|
54
|
|
|
} |
|
55
|
|
|
else |
|
56
|
|
|
{ |
|
57
|
|
|
$setup_tpl->set_file(array( |
|
58
|
|
|
'T_head' => 'head.tpl', |
|
59
|
|
|
'T_footer' => 'footer.tpl', |
|
60
|
|
|
'T_alert_msg' => 'msg_alert_msg.tpl', |
|
61
|
|
|
'T_login_main' => 'login_main.tpl', |
|
62
|
|
|
'T_login_stage_header' => 'login_stage_header.tpl', |
|
63
|
|
|
'T_setup_main' => 'schema.tpl', |
|
64
|
|
|
'applist' => 'applist.tpl', |
|
65
|
|
|
'sqlarr' => 'sqltoarray.tpl', |
|
66
|
|
|
'T_head' => 'head.tpl', |
|
67
|
|
|
'T_footer' => 'footer.tpl' |
|
68
|
|
|
)); |
|
69
|
|
|
$setup_tpl->set_block('T_login_stage_header','B_multi_domain','V_multi_domain'); |
|
70
|
|
|
$setup_tpl->set_block('T_login_stage_header','B_single_domain','V_single_domain'); |
|
71
|
|
|
$setup_tpl->set_block('T_setup_main','header','header'); |
|
72
|
|
|
$setup_tpl->set_block('applist','appheader','appheader'); |
|
73
|
|
|
$setup_tpl->set_block('applist','appitem','appitem'); |
|
74
|
|
|
$setup_tpl->set_block('applist','appfooter','appfooter'); |
|
75
|
|
|
$setup_tpl->set_block('sqlarr','sqlheader','sqlheader'); |
|
76
|
|
|
$setup_tpl->set_block('sqlarr','sqlbody','sqlbody'); |
|
77
|
|
|
$setup_tpl->set_block('sqlarr','sqlfooter','sqlfooter'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$GLOBALS['egw_setup']->loaddb(); |
|
81
|
|
|
|
|
82
|
|
|
function parse_vars($table,$term) |
|
83
|
|
|
{ |
|
84
|
|
|
$GLOBALS['setup_tpl']->set_var('table', $table); |
|
85
|
|
|
$GLOBALS['setup_tpl']->set_var('term',$term); |
|
86
|
|
|
|
|
87
|
|
|
list($arr,$pk,$fk,$ix,$uc) = $GLOBALS['egw_setup']->process->sql_to_array($table); |
|
88
|
|
|
$GLOBALS['setup_tpl']->set_var('arr',$arr); |
|
89
|
|
|
|
|
90
|
|
|
foreach(array('pk','fk','ix','uc') as $kind) |
|
91
|
|
|
{ |
|
92
|
|
|
$GLOBALS['setup_tpl']->set_var($kind.'s',_arr2str($$kind)); |
|
93
|
|
|
} |
|
94
|
|
|
unset($pk,$fk,$ix,$uc); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
function _arr2str($arr) |
|
98
|
|
|
{ |
|
99
|
|
|
if(!is_array($arr)) return $arr; |
|
100
|
|
|
|
|
101
|
|
|
$str = ''; |
|
102
|
|
|
foreach($arr as $key => $val) |
|
103
|
|
|
{ |
|
104
|
|
|
if($str) $str .= ','; |
|
105
|
|
|
|
|
106
|
|
|
if(!is_int($key)) |
|
107
|
|
|
{ |
|
108
|
|
|
$str .= "'$key' => "; |
|
109
|
|
|
} |
|
110
|
|
|
$str .= is_array($val) ? 'array('._arr2str($val).')' : "'$val'"; |
|
111
|
|
|
} |
|
112
|
|
|
return $str; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
function printout($template) |
|
116
|
|
|
{ |
|
117
|
|
|
$download = $_REQUEST['download']; |
|
118
|
|
|
$appname = $_REQUEST['appname']; |
|
119
|
|
|
$showall = $_REQUEST['showall']; |
|
120
|
|
|
$apps = $GLOBALS['apps'] ? $GLOBALS['apps'] : ''; |
|
121
|
|
|
|
|
122
|
|
|
if($download) |
|
123
|
|
|
{ |
|
124
|
|
|
$GLOBALS['setup_tpl']->set_var('appname',$appname); |
|
125
|
|
|
$GLOBALS['setup_tpl']->set_var('apps',$apps); |
|
126
|
|
|
$string = $GLOBALS['setup_tpl']->parse('out',$template); |
|
127
|
|
|
} |
|
128
|
|
|
else |
|
129
|
|
|
{ |
|
130
|
|
|
// $url = $GLOBALS['appname'] ? 'applications.php' : 'sqltoarray.php'; |
|
131
|
|
|
$GLOBALS['setup_tpl']->set_var('appname',$appname); |
|
132
|
|
|
$GLOBALS['setup_tpl']->set_var('lang_download',lang('Download')); |
|
133
|
|
|
$GLOBALS['setup_tpl']->set_var('lang_cancel',lang('Cancel')); |
|
134
|
|
|
$GLOBALS['setup_tpl']->set_var('showall',$showall); |
|
135
|
|
|
$GLOBALS['setup_tpl']->set_var('apps',$apps); |
|
136
|
|
|
$GLOBALS['setup_tpl']->set_var('action_url','sqltoarray.php'); |
|
137
|
|
|
$GLOBALS['setup_tpl']->pfp('out',$template); |
|
138
|
|
|
} |
|
139
|
|
|
return $string; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
function download_handler($dlstring,$fn='tables_current.inc.php') |
|
143
|
|
|
{ |
|
144
|
|
|
Api\Header\Content::type($fn); |
|
145
|
|
|
echo $dlstring; |
|
146
|
|
|
exit; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
if($submit || $showall) |
|
150
|
|
|
{ |
|
151
|
|
|
$dlstring = ''; |
|
152
|
|
|
$term = ''; |
|
153
|
|
|
|
|
154
|
|
|
if(!$download) |
|
155
|
|
|
{ |
|
156
|
|
|
$GLOBALS['egw_setup']->html->show_header(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if($showall) |
|
160
|
|
|
{ |
|
161
|
|
|
$table = $appname = ''; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if(!$table && !$appname) |
|
165
|
|
|
{ |
|
166
|
|
|
$term = ','; |
|
167
|
|
|
$dlstring .= printout('sqlheader'); |
|
168
|
|
|
|
|
169
|
|
|
$GLOBALS['egw_setup']->db->connect(); |
|
170
|
|
|
foreach($GLOBALS['egw_setup']->db->Link_ID->MetaTables() as $table) |
|
171
|
|
|
{ |
|
172
|
|
|
parse_vars($table,$term); |
|
173
|
|
|
$dlstring .= printout('sqlbody'); |
|
174
|
|
|
} |
|
175
|
|
|
$dlstring .= printout('sqlfooter'); |
|
176
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
elseif($appname) |
|
179
|
|
|
{ |
|
180
|
|
|
$dlstring .= printout('sqlheader'); |
|
181
|
|
|
$term = ','; |
|
182
|
|
|
|
|
183
|
|
|
if(!$setup_info[$appname]['tables']) |
|
184
|
|
|
{ |
|
185
|
|
|
$f = EGW_SERVER_ROOT . '/' . $appname . '/setup/setup.inc.php'; |
|
186
|
|
|
if(file_exists($f)) |
|
187
|
|
|
{ |
|
188
|
|
|
include($f); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
//$tables = explode(',',$setup_info[$appname]['tables']); |
|
193
|
|
|
$tables = $setup_info[$appname]['tables']; |
|
194
|
|
|
$i = 0; |
|
195
|
|
|
$tbls = count($tables); |
|
196
|
|
|
foreach($tables as $key => $table) |
|
197
|
|
|
{ |
|
198
|
|
|
$i++; |
|
199
|
|
|
if($i == $tbls) |
|
200
|
|
|
{ |
|
201
|
|
|
$term = ''; |
|
202
|
|
|
} |
|
203
|
|
|
parse_vars($table,$term); |
|
204
|
|
|
$dlstring .= printout('sqlbody'); |
|
205
|
|
|
/* $i++; */ |
|
206
|
|
|
} |
|
207
|
|
|
$dlstring .= printout('sqlfooter'); |
|
208
|
|
|
} |
|
209
|
|
|
elseif($table) |
|
210
|
|
|
{ |
|
211
|
|
|
$term = ';'; |
|
212
|
|
|
parse_vars($table,$term); |
|
213
|
|
|
$dlstring .= printout('sqlheader'); |
|
214
|
|
|
$dlstring .= printout('sqlbody'); |
|
215
|
|
|
$dlstring .= printout('sqlfooter'); |
|
216
|
|
|
} |
|
217
|
|
|
if($download) |
|
218
|
|
|
{ |
|
219
|
|
|
download_handler($dlstring); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
else |
|
223
|
|
|
{ |
|
224
|
|
|
$GLOBALS['egw_setup']->html->show_header(); |
|
225
|
|
|
|
|
226
|
|
|
$setup_tpl->set_var('action_url','sqltoarray.php'); |
|
227
|
|
|
$setup_tpl->set_var('lang_submit','Show selected'); |
|
228
|
|
|
$setup_tpl->set_var('lang_showall','Show all'); |
|
229
|
|
|
$setup_tpl->set_var('title','SQL to schema_proc array util'); |
|
230
|
|
|
$setup_tpl->set_var('lang_applist','Applications'); |
|
231
|
|
|
$setup_tpl->set_var('select_to_download_file',lang('Select to download file')); |
|
232
|
|
|
$setup_tpl->pfp('out','appheader'); |
|
233
|
|
|
|
|
234
|
|
|
$d = dir(EGW_SERVER_ROOT); |
|
235
|
|
|
while($entry = $d->read()) |
|
236
|
|
|
{ |
|
237
|
|
|
$f = EGW_SERVER_ROOT . '/' . $entry . '/setup/setup.inc.php'; |
|
238
|
|
|
if(file_exists($f)) |
|
239
|
|
|
{ |
|
240
|
|
|
include($f); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
foreach($setup_info as $key => $data) |
|
245
|
|
|
{ |
|
246
|
|
|
if($data['tables']) |
|
247
|
|
|
{ |
|
248
|
|
|
$setup_tpl->set_var('appname',$data['name']); |
|
249
|
|
|
$setup_tpl->set_var('apptitle',$data['title']); |
|
250
|
|
|
$setup_tpl->pfp('out','appitem'); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
$setup_tpl->pfp('out','appfooter'); |
|
254
|
|
|
} |
|
255
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.