diff options
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | lib/class/ajax.class.php | 104 | ||||
-rw-r--r-- | lib/ui.lib.php | 31 | ||||
-rw-r--r-- | logout.php | 9 | ||||
-rwxr-xr-x | modules/kajax/ajax.js | 2 | ||||
-rw-r--r-- | templates/show_album_row.inc.php | 28 | ||||
-rw-r--r-- | templates/show_edit_album_row.inc.php | 23 | ||||
-rw-r--r-- | templates/show_songs.inc.php | 4 | ||||
-rw-r--r-- | templates/sidebar.inc.php | 29 |
9 files changed, 179 insertions, 55 deletions
@@ -31,11 +31,13 @@ $action = scrub_in($_REQUEST['action']); * going to let them break their servers */ if (Config::get('refresh_limit') > 5) { +/* $refresh_limit = Config::get('refresh_limit'); $ajax_url = Config::get('ajax_url') . '?action=reloadnp' . Config::get('ajax_info'); - /* Can't have the & stuff in the Javascript */ + $ajax_url = str_replace("&","&",$ajax_url); require_once Config::get('prefix') . '/templates/javascript_refresh.inc.php'; +*/ } require_once Config::get('prefix') . '/templates/show_index.inc.php'; diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php new file mode 100644 index 00000000..8f68da98 --- /dev/null +++ b/lib/class/ajax.class.php @@ -0,0 +1,104 @@ +<?php +/* + + Copyright (c) 2001 - 2007 Ampache.org + All rights reserved. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License v2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +/** + * Ajax class + * This class is specifically for setuping/printing out ajax related + * elements onto a page it takes care of the observing and all that raz-a-ma-taz + */ +class Ajax { + + /** + * constructor + * This is what is called when the class is loaded + */ + public function __construct() { + + // Rien a faire + + } // constructor + + /** + * observe + * This returns a string with the correct and full ajax 'observe' stuff from prototype + */ + public static function observe($source,$method,$action) { + + $observe = "<script type=\"text/javascript\">\n"; + $observe .= "\tEvent.observe('$source','$method',function(){" . $action . ";});\n"; + $observe .= "</script>\n"; + + return $observe; + + } // observe + + /** + * button + * This prints out an img of the specified icon with the specified alt text + * and then sets up the required ajax for it + */ + public static function button($action,$icon,$alt,$source='',$post='') { + + $url = Config::get('ajax_url') . $action; + + // Define the Action that is going to be performed + if ($post) { + $ajax_string = "ajaxPost('$url','$post','$source')"; + } + else { + $ajax_string = "ajaxPut('$url','$source')"; + } + + $string = get_user_icon($icon,$alt,$source); + + $string .= self::observe($source,'click',$ajax_string); + + return $string; + + } // button + + /** + * text + * This prints out the specified text as a link and setups the required + * ajax for the link so it works correctly + */ + public static function text($action,$text,$source,$post='') { + + $url = Config::get('ajax_url') . $action; + + if ($post) { + $ajax_string = "ajaxPost('$url','$post','$source')"; + } + else { + $ajax_string = "ajaxPut('$url','$post','$source')"; + } + + // If we pass a source put it in the ID + $string = "<span id=\"$source\">$text</span>\n"; + + $string .= self::observe($source,'click',$ajax_string); + + return $string; + + } // text + +} // end Ajax class +?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 459e8424..d7aaa0aa 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -661,21 +661,18 @@ function show_random_play_bar() { */ function show_artist_pulldown ($artist_id,$select_name='artist') { - $query = "SELECT id FROM artist ORDER BY name"; - $db_result = mysql_query($query, dbh()); + $sq = "SELECT `id`,`name` FROM `artist` ORDER BY `name`"; + $db_results = Dba::query($sq); echo "\n<select name=\"$select_name\">\n"; - while ($r = mysql_fetch_assoc($db_result)) { + while ($data = Dba::fetch_assoc($db_results)) { - $artist = new Artist($r['id']); - $artist->get_count(); - - if ( $artist_id == $r['id'] ) { - echo "\t<option value=\"" . $artist->id . "\" selected=\"selected\">". scrub_out($artist->name) . "</option>\n"; + if ( $artist_id == $data['id'] ) { + echo "\t<option value=\"" . $data['id'] . "\" selected=\"selected\">". scrub_out($data['name']) . "</option>\n"; } else { - echo "\t<option value=\"" . $artist->id . "\">". scrub_out($artist->name) ."</option>\n"; + echo "\t<option value=\"" . $data['id'] . "\">". scrub_out($data['name']) ."</option>\n"; } } // end while fetching artists @@ -1202,13 +1199,23 @@ function show_box_bottom() { * this function takes a name and a returns either a text representation * or an <img /> tag */ -function get_user_icon($name,$hover_name='',$title='') { +function get_user_icon($name,$title='',$id='') { /* Because we do a lot of calls cache the URLs */ static $url_cache = array(); + // If our name is an array + if (is_array($name)) { + $hover_name = $name['1']; + $name = $name['0']; + } + if (!$title) { $title = $name; } + if ($id) { + $id_element = 'id="' . $id . '"'; + } + if (isset($url_cache[$name])) { $img_url = $url_cache[$name]; $cache_url = true; @@ -1247,11 +1254,11 @@ function get_user_icon($name,$hover_name='',$title='') { } // end if not cached - $string = "<img style=\"cursor: pointer;\" src=\"$img_url\" border=\"0\" alt=\"" . ucfirst($title) . "\" title=\"" . ucfirst($title) . "\" $hov_txt/>"; + $string = "<img style=\"cursor: pointer;\" src=\"$img_url\" $id_element border=\"0\" alt=\"" . ucfirst($title) . "\" title=\"" . ucfirst($title) . "\" $hov_txt/>"; return $string; -} // show_icon +} // get_user_icon /** * xml_from_array @@ -1,13 +1,13 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + as published by the Free Software Foundation; version 2 + of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,7 +24,8 @@ * This is the logout page, it kills any cookies you have in your browser kills * your session in the database and then redirects you to the login page */ -require_once('lib/init.php'); +require_once 'lib/init.php'; + // To end a legitimate session, just call logout. setcookie("amp_longsess","",null); logout(); diff --git a/modules/kajax/ajax.js b/modules/kajax/ajax.js index 29f9fa7b..1e1f288c 100755 --- a/modules/kajax/ajax.js +++ b/modules/kajax/ajax.js @@ -5,7 +5,7 @@ function ajaxPut(url,source) {
if (document.getElementById(source)) {
- Event.stopObserving(source.'click',function(){ajaxPut(url,source);});
+ Event.stopObserving(source,'click',function(){ajaxPut(url,source);});
}
if (window.ActiveXObject) { // IE
diff --git a/templates/show_album_row.inc.php b/templates/show_album_row.inc.php index 58e03758..5c1b7aaa 100644 --- a/templates/show_album_row.inc.php +++ b/templates/show_album_row.inc.php @@ -20,24 +20,20 @@ */ ?> <td> - <span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=basket&type=album&id=<?php echo $album->id; ?>');return true;" > - <?php echo get_user_icon('add','',_('Add')); ?> - </span> - <span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=basket&type=album_random&id=<?php echo $album->id; ?>');return true;" > - <?php echo get_user_icon('random','',_('Random')); ?> - </span> - </td> - <td><?php echo $album->f_name_link; ?></td> - <td><?php echo $album->f_artist; ?></td> - <td><?php echo $album->song_count; ?></td> - <td><?php echo $album->year; ?></td> - <td> + <?php echo Ajax::button('?action=basket&type=album&id=' . $album->id,'add',_('Add'),'add_album_' . $album->id); ?> + <?php echo Ajax::button('?action=basket&type=album_random&id=' . $album->id,'random',_('Random'),'random_album_' . $album->id); ?> +</td> +<td><?php echo $album->f_name_link; ?></td> +<td><?php echo $album->f_artist; ?></td> +<td><?php echo $album->song_count; ?></td> +<td><?php echo $album->year; ?></td> +<td> <?php if (Access::check_function('batch_download')) { ?> <a href="<?php echo Config::get('web_path'); ?>/batch.php?action=album&id=<?php echo $album->id; ?>"> - <?php echo get_user_icon('batch_download','',_('Batch Download')); ?> + <?php echo get_user_icon('batch_download',_('Batch Download')); ?> </a> <?php } ?> - <span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=show_edit_object&type=album&id=<?php echo $album->id; ?>');return true;" > - <?php echo get_user_icon('edit','',_('Edit')); ?> - </span> + <?php if ($GLOBALS['user']->has_access('50')) { ?> + <?php echo Ajax::button('?action=show_edit_object&type=album&id=' . $album->id,'edit',_('Edit'),'edit_album_' . $album->id); ?> + <?php } ?> </td> diff --git a/templates/show_edit_album_row.inc.php b/templates/show_edit_album_row.inc.php index b66ae255..b5fd8d6d 100644 --- a/templates/show_edit_album_row.inc.php +++ b/templates/show_edit_album_row.inc.php @@ -21,12 +21,21 @@ ?> <td colspan="6"> <form method="post" id="edit_album_<?php echo $album->id; ?>"> -<input type="input" name="name" value="<?php echo scrub_out($album->name); ?>" /> -<input type="hidden" name="id" value="<?php echo $album->id; ?>" /> -<input type="hidden" name="type" value="album" /> -<span onclick="ajaxPost('<?php echo Config::get('ajax_url'); ?>?action=edit_object&id=<?php echo $album->id; ?>&type=album','edit_album_<?php echo $album->id; ?>');"> - <img src="<?php echo Config::get('web_path'); ?>/images/icon_download.png"> -</span> -</form> +<table border="0" cellpadding="3" cellspacing="0"> +<td> + <input type="textbox" name="name" value="<?php echo scrub_out($album->name); ?>" /> +</td> +<td> + <?php show_artist_pulldown($album->artist_id,'artist_id'); ?> +</td> +<td> + <input type="textbox" name="year" value="<?php echo scrub_out($album->year); ?>" /> </td> +<td> + <input type="hidden" name="id" value="<?php echo $album->id; ?>" /> + <input type="hidden" name="type" value="album" /> + <?php echo Ajax::button('?action=edit_object&id=' . $album->id . '&type=album','download',_('Save Changes'),'save_album_' . $album->id,'edit_album_' . $album->id); ?> +</td> +</table> +</form> </td> diff --git a/templates/show_songs.inc.php b/templates/show_songs.inc.php index 24687b10..224b552f 100644 --- a/templates/show_songs.inc.php +++ b/templates/show_songs.inc.php @@ -48,8 +48,8 @@ $ajax_url = Config::get('ajax_url'); $song->format(); ?> <tr class="<?php echo flip_class(); ?>"> - <td onclick="ajaxPut('<?php echo $ajax_url; ?>?action=basket&type=song&id=<?php echo $song->id; ?>');return true;"> - <?php echo get_user_icon('add'); ?> + <td> + <?php echo Ajax::button('?action=basket&atype=song&id=' . $song->id,'add',_('Add'),'add_' . $song->id); ?> </td> <td><?php echo $song->f_link; ?></td> <td><?php echo $song->f_artist_link; ?></td> diff --git a/templates/sidebar.inc.php b/templates/sidebar.inc.php index 13612552..90ac42ce 100644 --- a/templates/sidebar.inc.php +++ b/templates/sidebar.inc.php @@ -27,25 +27,30 @@ $web_path = Config::get('web_path'); $ajax_url = Config::get('ajax_url'); ?> <ul id="sidebar-tabs"> -<li <?php echo $sidebar_home; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=home');" > - <?php echo get_user_icon('home','',_('Home')); ?> +<li <?php echo $sidebar_home; ?>> + <?php echo Ajax::button("?action=sidebar&button=home",home,_('Home'),'sidebar_home'); ?> </li> -<li <?php echo $sidebar_browse; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=browse');" > - <?php echo get_user_icon('browse','',_('Browse')); ?> +<li <?php echo $sidebar_browse; ?>> + <?php echo Ajax::button("?action=sidebar&button=browse",browse,_('Browse'),'sidebar_browse'); ?> </li> -<li <?php echo $sidebar_search; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=search');" > - <?php echo get_user_icon('view','',_('Search')); ?> +<li <?php echo $sidebar_search; ?>> + <?php echo Ajax::button("?action=sidebar&button=search",'view',_('Search'),'sidebar_search'); ?> </li> -<li <?php echo $sidebar_preferences; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=preferences');" > - <?php echo get_user_icon('edit','',_('Preferences')); ?> +<li <?php echo $sidebar_preferences; ?>> + <?php echo Ajax::button("?action=sidebar&button=preferences",'edit',_('Preferences'),'sidebar_prefs'); ?> </li> <?php if ($GLOBALS['user']->has_access('100')) { ?> -<li <?php echo $sidebar_admin; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=admin');" > - <?php echo get_user_icon('admin','',_('Admin')); ?> +<li <?php echo $sidebar_admin; ?>> + <?php echo Ajax::button("?action=sidebar&button=admin",'admin',_('Admin'),'sidebar_admin'); ?> </li> <?php } ?> -<li <?php echo $sidebar_player; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=player');" > - <?php echo get_user_icon('all','',_('Player')); ?> +<!-- <li <?php echo $sidebar_player; ?> onclick="ajaxPut('<?php echo $ajax_url; ?>?action=sidebar&button=player');" > +</li> +--> +<li> + <a href="<?php echo Config::get('web_path'); ?>/logout.php"> + <?php echo get_user_icon('logout',_('Logout')); ?> + </a> </li> </ul> <div id="sidebar-page"> |