Rev Author Line No. Line
250 kaklik 1 var querywindow = '';
2  
3 /**
4 * sets current selected db
5 *
6 * @param string db name
7 */
8 function setDb( new_db ) {
9 //alert('setDb(' + new_db + ')');
10 if ( new_db != db ) {
11 // db has changed
12 //alert( new_db + '(' + new_db.length + ') : ' + db );
13  
14 db = new_db;
15  
16 if ( window.frames[0].document.getElementById( db ) == null ) {
17 // db is unknown, reload complete left frame
18 refreshLeft();
19  
20 }
21 // TODO: add code to expand db in lightview mode
22  
23 // refresh querywindow
24 refreshQuerywindow();
25 }
26 }
27  
28 /**
29 * sets current selected table (called from left.php)
30 *
31 * @param string table name
32 */
33 function setTable( new_table ) {
34 //alert('setTable(' + new_table + ')');
35 if ( new_table != table ) {
36 // table has changed
37 //alert( new_table + '(' + new_table.length + ') : ' + table );
38  
39 table = new_table;
40  
41 if ( window.frames[0].document.getElementById( db + '.' + table ) == null ) {
42 // table is unknown, reload complete left frame
43 refreshLeft();
44  
45 }
46 // TODO: add code to expand table in lightview mode
47  
48 // refresh querywindow
49 refreshQuerywindow();
50 }
51 }
52  
53 function refreshMain( url ) {
54 if ( ! url ) {
55 if ( db ) {
56 url = opendb_url;
57 } else {
58 url = 'main.php';
59 }
60 }
61 goTo( url + '?&server=' + server +
62 '&db=' + db +
63 '&table=' + table +
64 '&lang=' + lang +
65 '&collation_connection=' + collation_connection,
66 'main' );
67 }
68  
69 function refreshLeft() {
70 goTo('left.php?&server=' + server +
71 '&db=' + db +
72 '&table=' + table +
73 '&lang=' + lang +
74 '&collation_connection=' + collation_connection
75 );
76 }
77  
78 /**
79 * sets current selected server, table and db (called from libraries/footer.inc.php)
80 */
81 function setAll( new_lang, new_collation_connection, new_server, new_db, new_table ) {
82 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ' )');
83 if ( new_server != server || new_lang != lang
84 || new_collation_connection != collation_connection ) {
85 // something important has changed
86 server = new_server;
87 db = new_db;
88 table = new_table;
89 collation_connection = new_collation_connection;
90 lang = new_lang;
91 refreshLeft();
92 }
93 else if ( new_db != db || new_table != table ) {
94 // save new db and table
95 db = new_db;
96 table = new_table;
97  
98 if ( window.frames[0].document.getElementById( db ) == null
99 && window.frames[0].document.getElementById( db + '.' + table ) == null ) {
100 // table or db is unknown, reload complete left frame
101 refreshLeft();
102 }
103  
104 // TODO: add code to expand db in lightview mode
105  
106 // refresh querywindow
107 refreshQuerywindow();
108 }
109 }
110  
111 function reload_querywindow( db, table, sql_query ) {
112 if ( ! querywindow.closed && querywindow.location ) {
113 if ( ! querywindow.document.sqlform.LockFromUpdate
114 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
115 querywindow.document.querywindow.db.value = db;
116 querywindow.document.querywindow.query_history_latest_db.value = db;
117 querywindow.document.querywindow.table.value = table;
118 querywindow.document.querywindow.query_history_latest_table.value = table;
119  
120 if ( sql_query ) {
121 querywindow.document.querywindow.query_history_latest.value = sql_query;
122 }
123  
124 querywindow.document.querywindow.submit();
125 }
126 }
127 }
128  
129 function focus_querywindow( sql_query ) {
130 if ( querywindow && !querywindow.closed && querywindow.location) {
131 var querywindow = querywindow;
132 if ( querywindow.document.querywindow.querydisplay_tab != 'sql' ) {
133 querywindow.document.querywindow.querydisplay_tab.value = "sql";
134 querywindow.document.querywindow.query_history_latest.value = sql_query;
135 querywindow.document.querywindow.submit();
136 querywindow.focus();
137 } else {
138 querywindow.focus();
139 }
140 } else {
141 url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=' + sql_query;
142 open_querywindow( url );
143 }
144 }
145  
146 function open_querywindow( url ) {
147 if ( ! url ) {
148 url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table;
149 }
150  
151 if (!querywindow.closed && querywindow.location) {
152 goTo( url, 'query' );
153 querywindow.focus();
154 } else {
155 querywindow=window.open( url, '',
156 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
157 'scrollbars=yes,resizable=yes,' +
158 'width=' + querywindow_width + ',' +
159 'height=' + querywindow_height );
160 }
161  
162 if ( ! querywindow.opener ) {
163 querywindow.opener = window.window;
164 }
165  
166 if ( window.focus ) {
167 querywindow.focus();
168 }
169  
170 return true;
171 }
172  
173 function refreshQuerywindow( url ) {
174  
175 if ( ! querywindow.closed && querywindow.location ) {
176 if ( ! querywindow.document.sqlform.LockFromUpdate
177 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
178 open_querywindow( url )
179 }
180 }
181 }
182  
183 /**
184 * opens new url in target frame, with default beeing left frame
185 * valid is 'main' and 'querywindow' all others leads to 'left'
186 *
187 * @param string targeturl new url to load
188 * @param string target frame where to load the new url
189 */
190 function goTo( targeturl, target ) {
191 //alert('goto');
192 if ( target == 'main' ) {
193 if (text_dir == 'ltr') {
194 target = window.frames[1];
195 } else {
196 target = window.frames[0];
197 }
198 } else if ( target == 'query' ) {
199 target = querywindow;
200 //return open_querywindow( targeturl );
201 } else if ( ! target ) {
202 if (text_dir == 'ltr') {
203 target = window.frames[0];
204 } else {
205 target = window.frames[1];
206 }
207 }
208  
209 if ( target ) {
210 if ( target.location.href == targeturl ) {
211 return true;
212 } else if ( target.location.href == pma_absolute_uri + targeturl ) {
213 return true;
214 }
215  
216 if ( safari_browser ) {
217 target.location.href = targeturl;
218 } else {
219 target.location.replace(targeturl);
220 }
221 }
222  
223 return true;
224 }
225  
226 // opens selected db in main frame
227 function openDb( new_db ) {
228 //alert('opendb(' + new_db + ')');
229 setDb( new_db );
230 setTable( '' );
231 refreshMain( opendb_url );
232 return true;
233 }
234  
235 function updateTableTitle( table_link_id, new_title ) {
236 //alert('updateTableTitle');
237 if ( window.parent.frames[0].document.getElementById(table_link_id) ) {
238 var left = window.parent.frames[0].document;
239 left.getElementById(table_link_id).title = new_title;
240 new_title = left.getElementById('icon_' + table_link_id).alt + ': ' + new_title;
241 left.getElementById('browse_' + table_link_id).title = new_title;
242 return true;
243 }
244  
245 return false;
246 }