source: trunk/setup/schematoy.php @ 2

Revision 2, 9.6 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Setup - Developer tools                                     *
4  * http://www.egroupware.org                                                *
5  * --------------------------------------------                             *
6  *  This program is free software; you can redistribute it and/or modify it *
7  *  under the terms of the GNU General Public License as published by the   *
8  *  Free Software Foundation; either version 2 of the License, or (at your  *
9  *  option) any later version.                                              *
10  \**************************************************************************/
11
12
13        $GLOBALS['DEBUG'] = True;
14
15        $phpgw_info = array();
16        $GLOBALS['phpgw_info']['flags'] = array(
17                'noheader' => True,
18                'nonavbar' => True,
19                'currentapp' => 'home',
20                'noapi' => True
21        );
22        include ('./inc/functions.inc.php');
23
24        // Check header and authentication
25        if (!$GLOBALS['phpgw_setup']->auth('Config'))
26        {
27                Header('Location: index.php');
28                exit;
29        }
30        // Does not return unless user is authorized
31
32        $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
33        $GLOBALS['setup_tpl'] = CreateObject('setup.Template',$tpl_root);
34        $GLOBALS['setup_tpl']->set_file(array(
35                'T_head' => 'head.tpl',
36                'T_footer' => 'footer.tpl',
37                'T_alert_msg' => 'msg_alert_msg.tpl',
38                'T_login_main' => 'login_main.tpl',
39                'T_login_stage_header' => 'login_stage_header.tpl',
40                'T_setup_main' => 'schema.tpl'
41        ));
42
43        $GLOBALS['setup_tpl']->set_block('T_login_stage_header','B_multi_domain','V_multi_domain');
44        $GLOBALS['setup_tpl']->set_block('T_login_stage_header','B_single_domain','V_single_domain');
45        $GLOBALS['setup_tpl']->set_block('T_setup_main','header','header');
46        $GLOBALS['setup_tpl']->set_block('T_setup_main','app_header','app_header');
47        $GLOBALS['setup_tpl']->set_block('T_setup_main','apps','apps');
48        $GLOBALS['setup_tpl']->set_block('T_setup_main','detail','detail');
49        $GLOBALS['setup_tpl']->set_block('T_setup_main','table','table');
50        $GLOBALS['setup_tpl']->set_block('T_setup_main','hook','hook');
51        $GLOBALS['setup_tpl']->set_block('T_setup_main','dep','dep');
52        $GLOBALS['setup_tpl']->set_block('T_setup_main','app_footer','app_footer');
53        $GLOBALS['setup_tpl']->set_block('T_setup_main','submit','submit');
54        $GLOBALS['setup_tpl']->set_block('T_setup_main','footer','footer');
55
56        $bgcolor = array('DDDDDD','EEEEEE');
57
58        function parsedep($depends,$main=True)
59        {
60                $depstring = '(';
61                while (list($a,$b) = each ($depends))
62                {
63                        while (list($c,$d) = each($b))
64                        {
65                                if (is_array($d))
66                                {
67                                        $depstring .= $c . ': ' .implode(',',$d) . '; ';
68                                        $depver[] = $d;
69                                }
70                                else
71                                {
72                                        $depstring .= $c . ': ' . $d . '; ';
73                                        $depapp[] = $d;
74                                }
75                        }
76                }
77                $depstring .= ')';
78                if ($main)
79                {
80                        return $depstring;
81                }
82                else
83                {
84                        return array($depapp,$depver);
85                }
86        }
87
88        $GLOBALS['phpgw_setup']->loaddb();
89        $GLOBALS['phpgw_info']['setup']['stage']['db'] = $GLOBALS['phpgw_setup']->detection->check_db();
90
91        $GLOBALS['setup_info'] = $GLOBALS['phpgw_setup']->detection->get_versions();
92        //var_dump($GLOBALS['setup_info']);exit;
93        $GLOBALS['setup_info'] = $GLOBALS['phpgw_setup']->detection->get_db_versions($GLOBALS['setup_info']);
94        //var_dump($GLOBALS['setup_info']);exit;
95        $GLOBALS['setup_info'] = $GLOBALS['phpgw_setup']->detection->compare_versions($GLOBALS['setup_info']);
96        //var_dump($GLOBALS['setup_info']);exit;
97        $GLOBALS['setup_info'] = $GLOBALS['phpgw_setup']->detection->check_depends($GLOBALS['setup_info']);
98        //var_dump($GLOBALS['setup_info']);exit;
99        @ksort($GLOBALS['setup_info']);
100
101        if (get_var('cancel',Array('POST')))
102        {
103                Header('Location: index.php');
104                exit;
105        }
106
107        $GLOBALS['phpgw_setup']->html->show_header(lang("Developers' Table Schema Toy"),False,'config',$GLOBALS['phpgw_setup']['ConfigDomain']);
108
109        if(get_var('submit',Array('POST')))
110        {
111                $GLOBALS['setup_tpl']->set_var('description',lang('App process') . ':');
112                $GLOBALS['setup_tpl']->pparse('out','header');
113
114                $appname = get_var('appname','POST');
115                $install = get_var('install','POST');
116                $version = get_var('version','POST');
117
118                while (list($appname,$key) = @each($install))
119                {
120                        $terror = array();
121                        $terror[$appname]['name'] = $appname;
122                        $terror[$appname]['version'] = $version[$appname];
123                        $terror[$appname]['status'] = 'U';
124
125                        $appdir  = PHPGW_SERVER_ROOT . SEP . $appname . SEP . 'setup' . SEP;
126
127                        // Drop newest tables
128                        $terror[$appname]['tables'] = $GLOBALS['setup_info'][$appname]['tables'];
129                        $GLOBALS['phpgw_setup']->process->droptables($terror,$GLOBALS['DEBUG']);
130                        $terror[$appname]['tables'] = array();
131
132                        // Reset tables field to baseline table names
133                        if (file_exists($appdir.'tables_baseline.inc.php'))
134                        {
135                                include($appdir.'tables_baseline.inc.php');
136                                while(list($table,$null) = @each($phpgw_baseline))
137                                {
138                                        $terror[$appname]['tables'][] = $table;
139                                        echo '<br>Adding app table: ' . $table;
140                                }
141                        }
142
143                        if($version[$appname])
144                        {
145                                echo '<br>Processing ' . $terror[$appname]['name'] . ' to ' . $version[$appname];
146
147                                $terror = $GLOBALS['phpgw_setup']->process->droptables($terror,$GLOBALS['DEBUG']);
148                                $GLOBALS['phpgw_setup']->deregister_app($terror[$appname]['name']);
149
150                                $terror = $GLOBALS['phpgw_setup']->process->baseline($terror,$GLOBALS['DEBUG']);
151                                $terror = $GLOBALS['phpgw_setup']->process->test_data($terror,$GLOBALS['DEBUG']);
152
153                                $terror = $GLOBALS['phpgw_setup']->process->upgrade($terror,$GLOBALS['DEBUG']);
154                                $terror[$appname]['version'] = $version[$appname];
155                        }
156                        else
157                        {
158                                echo '<br>Baseline-only completed for ' . $terror[$appname]['name'];
159                        }
160                        echo '<br>' . $GLOBALS['setup_info'][$appname]['title'] . ' '
161                                . lang('tables installed, unless there are errors printed above') . '.';
162
163                        $GLOBALS['setup_info'][$appname]['version'] = $terror[$appname]['version'];
164                        $GLOBALS['phpgw_setup']->register_app($appname);
165                        echo '<br>' . $terror[$appname]['title'] . ' ' . lang('registered') . '.';
166                }
167
168                echo '<br><a href="schematoy.php">' . lang('Go back') . '</a>';
169                $GLOBALS['setup_tpl']->pparse('out','footer');
170                exit;
171        }
172        $detail = get_var('detail',Array('POST'));
173        if($detail)
174        {
175                @ksort($GLOBALS['setup_info'][$detail]);
176                @reset($GLOBALS['setup_info'][$detail]);
177                $GLOBALS['setup_tpl']->set_var('description',lang('App details') . ':');
178                $GLOBALS['setup_tpl']->pparse('out','header');
179               
180                while (list($key,$val) = each($GLOBALS['setup_info'][$detail]))
181                {
182                        if ($i) { $i = 0; }
183                        else    { $i = 1; }
184
185                        //if(!$val) { $val = 'none'; }
186
187                        if ($key == 'tables')
188                        {
189                                if(is_array($val))
190                                {
191                                        $key = '<a href="sqltoarray.php?appname=' . $detail . '&submit=True">' . $key . '</a>' . "\n";
192                                        $val = implode(',',$val);
193                                }
194                        }
195                        if ($key == 'hooks')   { $val = implode(',',$val); }
196                        if ($key == 'depends') { $val = parsedep($val); }
197                        if (is_array($val))    { $val = implode(',',$val); }
198
199                        $GLOBALS['setup_tpl']->set_var('bg_color',$bgcolor[$i]);
200                        $GLOBALS['setup_tpl']->set_var('name',$key);
201                        $GLOBALS['setup_tpl']->set_var('details',$val);
202                        $GLOBALS['setup_tpl']->pparse('out','detail');
203                }
204
205                echo '<br><a href="schematoy.php">' . lang('Go back') . '</a>';
206                $GLOBALS['setup_tpl']->pparse('out','footer');
207                exit;
208        }
209        else
210        {
211                $GLOBALS['setup_tpl']->set_var('description',lang("Select an app, enter a target version, then submit to process to that version.<br>If you do not enter a version, only the baseline tables will be installed for the app.<br><blink>THIS WILL DROP ALL OF THE APPS' TABLES FIRST!</blink>"));
212                $GLOBALS['setup_tpl']->pparse('out','header');
213
214                $GLOBALS['setup_tpl']->set_var('appdata',lang('Application Data'));
215                $GLOBALS['setup_tpl']->set_var('actions',lang('Actions'));
216                $GLOBALS['setup_tpl']->set_var('action_url','schematoy.php');
217                $GLOBALS['setup_tpl']->set_var('app_info',lang('Application Name and Status'));
218                $GLOBALS['setup_tpl']->set_var('app_title',lang('Application Title'));
219                $GLOBALS['setup_tpl']->set_var('app_version',lang('Target Version'));
220                $GLOBALS['setup_tpl']->set_var('app_install',lang('Process'));
221                $GLOBALS['setup_tpl']->pparse('out','app_header');
222
223                @reset ($GLOBALS['setup_info']);
224                while (list ($key, $value) = each ($GLOBALS['setup_info']))
225                {
226                        unset($test);
227                        if (file_exists(PHPGW_SERVER_ROOT . '/' . $value['name'] . '/setup/tables_update.inc.php'))
228                        {
229                                include(PHPGW_SERVER_ROOT . '/' . $value['name'] . '/setup/tables_update.inc.php');
230                        }
231
232                        if (is_array($test))
233                        {
234                                reset($test);
235                        }
236
237                        $s = '<option value="">&nbsp;</option>';
238                        while (is_array($test) && list(,$versionnumber) = each($test))
239                        {
240                                $s .= '<option value="' . $versionnumber . '">' . $versionnumber . '</option>';
241                        }
242                        $GLOBALS['setup_tpl']->set_var('select_version',$s);
243
244                        if ($value['name'])
245                        {
246                                if ($i)
247                                {
248                                        $i = 0;
249                                }
250                                else
251                                {
252                                        $i = 1;
253                                }
254                                $GLOBALS['setup_tpl']->set_var('apptitle',$value['title']);
255                                $GLOBALS['setup_tpl']->set_var('currentver',$value['currentver']);
256                                $GLOBALS['setup_tpl']->set_var('bg_color',$bgcolor[$i]);
257
258                                $GLOBALS['setup_tpl']->set_var('instimg','completed.png');
259                                $GLOBALS['setup_tpl']->set_var('instalt',lang('Completed'));
260                                $GLOBALS['setup_tpl']->set_var('install','<input type="checkbox" name="install[' . $value['name'] . ']">');
261                                $status = lang('OK') . ' - ' . $value['status'];
262
263                                $GLOBALS['setup_tpl']->set_var('appinfo',$value['name'] . '-' . $status);
264                                $GLOBALS['setup_tpl']->set_var('appname',$value['name']);
265
266                                $GLOBALS['setup_tpl']->pparse('out','apps',True);
267                        }
268                }
269        }
270        $GLOBALS['setup_tpl']->set_var('submit',lang('Save'));
271        $GLOBALS['setup_tpl']->set_var('cancel',lang('Cancel'));
272        $GLOBALS['setup_tpl']->pparse('out','app_footer');
273        $GLOBALS['setup_tpl']->pparse('out','footer');
274        $GLOBALS['phpgw_setup']->html->show_footer();
275?>
Note: See TracBrowser for help on using the repository browser.