1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * functions used by and for querywindow
9 * holds the browser query window
14 * holds the query to be load from a new query window
16 var query_to_load
= '';
19 * sets current selected db
21 * @param string db name
23 function setDb(new_db
) {
24 //alert('setDb(' + new_db + ')');
27 //alert( new_db + '(' + new_db.length + ') : ' + db );
32 if (window
.frame_navigation
.document
.getElementById(db
) == null) {
33 // db is unknown, reload complete left frame
36 unmarkDbTable(old_db
);
40 // TODO: add code to expand db in lightview mode
42 // refresh querywindow
48 * sets current selected table (called from navigation.php)
50 * @param string table name
52 function setTable(new_table
) {
53 //alert('setTable(' + new_table + ')');
54 if (new_table
!= table
) {
56 //alert( new_table + '(' + new_table.length + ') : ' + table );
60 if (window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null
62 // table is unknown, reload complete left frame
66 // TODO: add code to expand table in lightview mode
68 // refresh querywindow
83 * @uses collation_connection
84 * @uses encodeURIComponent()
85 * @param string url name of page to be loaded
87 function refreshMain(url
) {
95 goTo(url
+ '?server=' + encodeURIComponent(server
) +
96 '&token=' + encodeURIComponent(token
) +
97 '&db=' + encodeURIComponent(db
) +
98 '&table=' + encodeURIComponent(table
) +
99 '&lang=' + encodeURIComponent(lang
) +
100 '&collation_connection=' + encodeURIComponent(collation_connection
),
105 * reloads navigation frame
113 * @uses collation_connection
114 * @uses encodeURIComponent()
116 function refreshNavigation() {
117 goTo('navigation.php?server=' + encodeURIComponent(server
) +
118 '&token=' + encodeURIComponent(token
) +
119 '&db=' + encodeURIComponent(db
) +
120 '&table=' + encodeURIComponent(table
) +
121 '&lang=' + encodeURIComponent(lang
) +
122 '&collation_connection=' + encodeURIComponent(collation_connection
)
127 * adds class to element
129 function addClass(element
, classname
)
131 if (element
!= null) {
132 element
.className
+= ' ' + classname
;
133 //alert('set class: ' + classname + ', now: ' + element.className);
138 * removes class from element
140 function removeClass(element
, classname
)
142 if (element
!= null) {
143 element
.className
= element
.className
.replace(' ' + classname
, '');
144 // if there is no other class anem there is no leading space
145 element
.className
= element
.className
.replace(classname
, '');
146 //alert('removed class: ' + classname + ', now: ' + element.className);
150 function unmarkDbTable(db
, table
)
152 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
153 if (element_reference
!= null) {
154 //alert('remove from: ' + db);
155 removeClass(element_reference
.parentNode
, 'marked');
158 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
159 if (element_reference
!= null) {
160 //alert('remove from: ' + db + '.' + table);
161 removeClass(element_reference
.parentNode
, 'marked');
165 function markDbTable(db
, table
)
167 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
168 if (element_reference
!= null) {
169 addClass(element_reference
.parentNode
, 'marked');
171 element_reference
.focus();
172 // opera marks the text, we dont want this ...
173 element_reference
.blur();
176 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
177 if (element_reference
!= null) {
178 addClass(element_reference
.parentNode
, 'marked');
180 element_reference
.focus();
181 // opera marks the text, we dont want this ...
182 element_reference
.blur();
185 // return to main frame ...
186 window
.frame_content
.focus();
190 * sets current selected server, table and db (called from libraries/footer.inc.php)
192 function setAll( new_lang
, new_collation_connection
, new_server
, new_db
, new_table
, new_token
) {
193 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ', ' + new_token + ' )');
194 if (new_server
!= server
|| new_lang
!= lang
195 || new_collation_connection
!= collation_connection
) {
196 // something important has changed
200 collation_connection
= new_collation_connection
;
204 } else if (new_db
!= db
|| new_table
!= table
) {
205 // save new db and table
207 var old_table
= table
;
211 if (window
.frame_navigation
.document
.getElementById(db
) == null
212 && window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null ) {
213 // table or db is unknown, reload complete left frame
216 unmarkDbTable(old_db
, old_table
);
217 markDbTable(db
, table
);
220 // TODO: add code to expand db in lightview mode
222 // refresh querywindow
223 refreshQuerywindow();
227 function reload_querywindow(db
, table
, sql_query
)
229 if ( ! querywindow
.closed
&& querywindow
.location
) {
230 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
231 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
232 querywindow
.document
.getElementById('hiddenqueryform').db
.value
= db
;
233 querywindow
.document
.getElementById('hiddenqueryform').table
.value
= table
;
236 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
239 querywindow
.document
.getElementById('hiddenqueryform').submit();
245 * brings query window to front and inserts query to be edited
247 function focus_querywindow(sql_query
)
249 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
250 if ( !querywindow
|| querywindow
.closed
|| !querywindow
.location
) {
251 // we need first to open the window and cannot pass the query with it
252 // as we dont know if the query exceeds max url length
253 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
254 query_to_load
= sql_query
;
258 //var querywindow = querywindow;
259 if ( querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
!= 'sql' ) {
260 querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= "sql";
261 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
262 querywindow
.document
.getElementById('hiddenqueryform').submit();
272 * inserts query string into query window textarea
273 * called from script tag in querywindow
275 function insertQuery() {
276 if (query_to_load
!= '' && querywindow
.document
&& querywindow
.document
.getElementById
&& querywindow
.document
.getElementById('sqlquery')) {
277 querywindow
.document
.getElementById('sqlquery').value
= query_to_load
;
284 function open_querywindow( url
) {
286 url
= 'querywindow.php?' + common_query
+ '&db=' + encodeURIComponent(db
) + '&table=' + encodeURIComponent(table
);
289 if (!querywindow
.closed
&& querywindow
.location
) {
290 goTo( url
, 'query' );
293 querywindow
= window
.open( url
+ '&init=1', '',
294 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
295 'scrollbars=yes,resizable=yes,' +
296 'width=' + querywindow_width
+ ',' +
297 'height=' + querywindow_height
);
300 if ( ! querywindow
.opener
) {
301 querywindow
.opener
= window
.window
;
304 if ( window
.focus
) {
311 function refreshQuerywindow( url
) {
313 if ( ! querywindow
.closed
&& querywindow
.location
) {
314 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
315 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
316 open_querywindow( url
)
322 * opens new url in target frame, with default beeing left frame
323 * valid is 'main' and 'querywindow' all others leads to 'left'
325 * @param string targeturl new url to load
326 * @param string target frame where to load the new url
328 function goTo(targeturl
, target
) {
329 if ( target
== 'main' ) {
330 target
= window
.frame_content
;
331 } else if ( target
== 'query' ) {
332 target
= querywindow
;
333 //return open_querywindow( targeturl );
334 } else if ( ! target
) {
335 target
= window
.frame_navigation
;
339 if ( target
.location
.href
== targeturl
) {
341 } else if ( target
.location
.href
== pma_absolute_uri
+ targeturl
) {
345 if ( safari_browser
) {
346 target
.location
.href
= targeturl
;
348 target
.location
.replace(targeturl
);
355 // opens selected db in main frame
356 function openDb(new_db
) {
357 //alert('opendb(' + new_db + ')');
360 refreshMain(opendb_url
);
364 function updateTableTitle( table_link_id
, new_title
) {
365 //alert('updateTableTitle');
366 if ( window
.parent
.frame_navigation
.document
.getElementById(table_link_id
) ) {
367 var left
= window
.parent
.frame_navigation
.document
;
368 left
.getElementById(table_link_id
).title
= new_title
;
369 new_title
= left
.getElementById('icon_' + table_link_id
).alt
+ ': ' + new_title
;
370 left
.getElementById('browse_' + table_link_id
).title
= new_title
;