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