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
82 * @uses collation_connection
83 * @uses encodeURIComponent()
84 * @param string url name of page to be loaded
86 function refreshMain(url
) {
94 goTo(url
+ '?server=' + encodeURIComponent(server
) +
95 '&db=' + encodeURIComponent(db
) +
96 '&table=' + encodeURIComponent(table
) +
97 '&lang=' + encodeURIComponent(lang
) +
98 '&collation_connection=' + encodeURIComponent(collation_connection
),
103 * reloads navigation frame
110 * @uses collation_connection
111 * @uses encodeURIComponent()
113 function refreshNavigation() {
114 goTo('navigation.php?server=' + encodeURIComponent(server
) +
115 '&db=' + encodeURIComponent(db
) +
116 '&table=' + encodeURIComponent(table
) +
117 '&lang=' + encodeURIComponent(lang
) +
118 '&collation_connection=' + encodeURIComponent(collation_connection
)
123 * adds class to element
125 function addClass(element
, classname
)
127 if (element
!= null) {
128 element
.className
+= ' ' + classname
;
129 //alert('set class: ' + classname + ', now: ' + element.className);
134 * removes class from element
136 function removeClass(element
, classname
)
138 if (element
!= null) {
139 element
.className
= element
.className
.replace(' ' + classname
, '');
140 // if there is no other class anem there is no leading space
141 element
.className
= element
.className
.replace(classname
, '');
142 //alert('removed class: ' + classname + ', now: ' + element.className);
146 function unmarkDbTable(db
, table
)
148 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
149 if (element_reference
!= null) {
150 //alert('remove from: ' + db);
151 removeClass(element_reference
.parentNode
, 'marked');
154 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
155 if (element_reference
!= null) {
156 //alert('remove from: ' + db + '.' + table);
157 removeClass(element_reference
.parentNode
, 'marked');
161 function markDbTable(db
, table
)
163 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
164 if (element_reference
!= null) {
165 addClass(element_reference
.parentNode
, 'marked');
167 element_reference
.focus();
168 // opera marks the text, we dont want this ...
169 element_reference
.blur();
172 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
173 if (element_reference
!= null) {
174 addClass(element_reference
.parentNode
, 'marked');
176 element_reference
.focus();
177 // opera marks the text, we dont want this ...
178 element_reference
.blur();
181 // return to main frame ...
182 window
.frame_content
.focus();
186 * sets current selected server, table and db (called from libraries/footer.inc.php)
188 function setAll( new_lang
, new_collation_connection
, new_server
, new_db
, new_table
) {
189 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ' )');
190 if (new_server
!= server
|| new_lang
!= lang
191 || new_collation_connection
!= collation_connection
) {
192 // something important has changed
196 collation_connection
= new_collation_connection
;
199 } else if (new_db
!= db
|| new_table
!= table
) {
200 // save new db and table
202 var old_table
= table
;
206 if (window
.frame_navigation
.document
.getElementById(db
) == null
207 && window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null ) {
208 // table or db is unknown, reload complete left frame
211 unmarkDbTable(old_db
, old_table
);
212 markDbTable(db
, table
);
215 // TODO: add code to expand db in lightview mode
217 // refresh querywindow
218 refreshQuerywindow();
222 function reload_querywindow(db
, table
, sql_query
)
224 if ( ! querywindow
.closed
&& querywindow
.location
) {
225 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
226 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
227 querywindow
.document
.getElementById('hiddenqueryform').db
.value
= db
;
228 querywindow
.document
.getElementById('hiddenqueryform').table
.value
= table
;
231 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
234 querywindow
.document
.getElementById('hiddenqueryform').submit();
240 * brings query window to front and inserts query to be edited
242 function focus_querywindow(sql_query
)
244 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
245 if ( !querywindow
|| querywindow
.closed
|| !querywindow
.location
) {
246 // we need first to open the window and cannot pass the query with it
247 // as we dont know if the query exceeds max url length
248 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
249 query_to_load
= sql_query
;
253 //var querywindow = querywindow;
254 if ( querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
!= 'sql' ) {
255 querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= "sql";
256 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
257 querywindow
.document
.getElementById('hiddenqueryform').submit();
267 * inserts query string into query window textarea
268 * called from script tag in querywindow
270 function insertQuery() {
271 if (query_to_load
!= '' && querywindow
.document
&& querywindow
.document
.getElementById
&& querywindow
.document
.getElementById('sqlquery')) {
272 querywindow
.document
.getElementById('sqlquery').value
= query_to_load
;
279 function open_querywindow( url
) {
281 url
= 'querywindow.php?' + common_query
+ '&db=' + encodeURIComponent(db
) + '&table=' + encodeURIComponent(table
);
284 if (!querywindow
.closed
&& querywindow
.location
) {
285 goTo( url
, 'query' );
288 querywindow
= window
.open( url
+ '&init=1', '',
289 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
290 'scrollbars=yes,resizable=yes,' +
291 'width=' + querywindow_width
+ ',' +
292 'height=' + querywindow_height
);
295 if ( ! querywindow
.opener
) {
296 querywindow
.opener
= window
.window
;
299 if ( window
.focus
) {
306 function refreshQuerywindow( url
) {
308 if ( ! querywindow
.closed
&& querywindow
.location
) {
309 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
310 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
311 open_querywindow( url
)
317 * opens new url in target frame, with default beeing left frame
318 * valid is 'main' and 'querywindow' all others leads to 'left'
320 * @param string targeturl new url to load
321 * @param string target frame where to load the new url
323 function goTo(targeturl
, target
) {
324 if ( target
== 'main' ) {
325 target
= window
.frame_content
;
326 } else if ( target
== 'query' ) {
327 target
= querywindow
;
328 //return open_querywindow( targeturl );
329 } else if ( ! target
) {
330 target
= window
.frame_navigation
;
334 if ( target
.location
.href
== targeturl
) {
336 } else if ( target
.location
.href
== pma_absolute_uri
+ targeturl
) {
340 if ( safari_browser
) {
341 target
.location
.href
= targeturl
;
343 target
.location
.replace(targeturl
);
350 // opens selected db in main frame
351 function openDb(new_db
) {
352 //alert('opendb(' + new_db + ')');
355 refreshMain(opendb_url
);
359 function updateTableTitle( table_link_id
, new_title
) {
360 //alert('updateTableTitle');
361 if ( window
.parent
.frame_navigation
.document
.getElementById(table_link_id
) ) {
362 var left
= window
.parent
.frame_navigation
.document
;
363 left
.getElementById(table_link_id
).title
= new_title
;
364 new_title
= left
.getElementById('icon_' + table_link_id
).alt
+ ': ' + new_title
;
365 left
.getElementById('browse_' + table_link_id
).title
= new_title
;