format(); $albums = $artist->get_albums(); require_once Config::get('prefix') . '/templates/show_artist.inc.php'; break; case 'show_all_songs': $artist = new Artist($_REQUEST['artist']); $artist->format(); require_once Config::get('prefix') . '/templates/show_artist_box.inc.php'; $song_ids = $artist->get_songs(); Browse::set_type('song'); Browse::show_objects($song_ids); break; case 'update_from_tags': $artist = new Artist($_REQUEST['artist']); show_box_top(_('Starting Update from Tags')); Catalog::update_single_item('artist',$_REQUEST['artist']); echo "
" . _('Update From Tags Complete') . "   "; echo "[" . _('Return') . "]"; show_box_bottom(); break; case 'rename_similar': if (!$user->has_access('100')) { access_denied(); } $count = 0; if (isset($_REQUEST['artist']) && is_numeric($_REQUEST['artist']) && isset($_REQUEST['artists']) && is_array($_REQUEST['artists'])) { $artist = new Artist($_REQUEST['artist']); if ($artist->id) foreach ($_REQUEST['artists'] as $artist_id) { if (is_numeric($artist_id)) { $that_artist = new Artist($artist_id); if ($that_artist->id) { $that_artist->merge($artist->id); $count++; } else $GLOBALS['error']->add_error('general',"Error: No such artist '$artist_id'"); } else { $GLOBALS['error']->add_error('general',"Error: '$artist_id' is not a valid ID"); } } else $GLOBALS['error']->add_error('general',"Error: No such artist '" . $_REQUEST['artist'] . "'"); } else { $GLOBALS['error']->add_error('general',"Error: Errenous request"); } if ($count > 0) { show_confirmation ( "Renamed artist(s)", "$count artists have been merged with " . $artist->name, conf('web_path') . "/artists.php?action=show&artist=" . $artist->id ); } else { $GLOBALS['error']->print_error('general'); } break; case 'show_similar': if (!$GLOBALS['user']->has_access('75')) { access_denied(); exit; } $artist = new Artist($_REQUEST['artist']); //options $similar_artists = $artist->get_similar_artists( make_bool($_POST['n_rep_uml']), $_POST['n_filter'], $_POST['n_ignore'], $_POST['c_mode'], $_POST['c_count_w'], $_POST['c_percent_w'], $_POST['c_distance_l'], make_bool($_POST['c_ignins_l'])); $artist_id = $artist->id; $artist_name = $artist->name; require Config::get('prefix') . '/templates/show_similar_artists.inc.php'; break; case 'rename': //die if not enough permissions if (!$user->has_access('100')) { access_denied(); } /* Get the artist */ $artist = new Artist($_REQUEST['artist']); $catalog = new Catalog(); //check if we've been given a target if ((isset($_POST['artist_id']) && $_POST['artist_id'] != $artist->id ) || (isset($_POST['artist_name']) && $_POST['artist_name'] != "")) { //if we want to update id3 tags, then get the array of ids now, it's too late afterwards if (make_bool($_POST['update_id3'])) $songs = $artist->get_songs(); $ret = 0; //the manual rename takes priority, but if they tested out the insert thing ignore if ($_POST['artist_name'] != "" && $_POST['artist_name'] != $artist->name) { //then just change the name of the artist in the db $ret = $artist->rename($_POST['artist_name']); $newid = $ret; $newname = $_POST['artist_name']; } //new id? elseif ($_POST['artist_id'] != $artist->id) { //merge with other artist $ret = $artist->merge($_POST['artist_id']); $newid = $_POST['artist_id']; $newname = $ret; } // elseif different artist and id //if no changes, no changes //now flag for id3tag update if selected, and something actually happaned if ($ret && make_bool($_POST['update_id3'])) { /* Set the rename information in the db */ foreach ($songs as $song) { $flag = new Flag(); $flag->add($song->id,"song","retag","Renamed artist, retag"); $flag_qstring = "REPLACE INTO flagged " . "SET type = 'setid3', song = '" . $song->id . "', date = '" . time() . "', user = '" . $GLOBALS['user']->username . "'"; mysql_query($flag_qstring, dbh()); } } // end if they wanted to update // show something other than a blank screen after this if ($ret) { show_confirmation ( "Renamed artist", $artist->name . " is now known as " . $newname, conf('web_path') . "/artists.php?action=show&artist=" . $newid ); } } // if we've got the needed variables /* Else we've got an error! But be lenient, and just show the form again */ else { require (conf('prefix') . '/templates/show_rename_artist.inc.php'); } break; case 'show_rename': $artist = new Artist($_REQUEST['artist']); require (conf('prefix') . '/templates/show_rename_artist.inc.php'); break; case 'match': case 'Match': $match = scrub_in($_REQUEST['match']); if ($match == "Browse" || $match == "Show_all") { $chr = ""; } else { $chr = $match; } /* Enclose this in the purty box! */ require (conf('prefix') . '/templates/show_box_top.inc.php'); show_alphabet_list('artists','artists.php',$match); show_alphabet_form($chr,_('Show Artists starting with'),"artists.php?action=match"); require (conf('prefix') . '/templates/show_box_bottom.inc.php'); if ($match === "Browse") { show_artists(); } elseif ($match === "Show_all") { $offset_limit = 999999; show_artists(); } else { if ($chr == '') { show_artists('A'); } else { show_artists($chr); } } break; } // end switch show_footer(); ?> a> 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
<?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.

*/

require_once '../lib/init.php';

if (!Access::check('interface','100')) { 
	access_denied();
	exit();
}

show_header(); 

// Switch on the actions  
switch ($_REQUEST['action']) {
	case 'update_user':
	        if (Config::get('demo_mode')) { break; }

		/* Clean up the variables */
		$user_id	= scrub_in($_REQUEST['user_id']);
		$username 	= scrub_in($_REQUEST['username']);
		$fullname 	= scrub_in($_REQUEST['fullname']);
		$email 		= scrub_in($_REQUEST['email']);
		$access 	= scrub_in($_REQUEST['access']);
		$pass1 		= scrub_in($_REQUEST['password_1']);
		$pass2 		= scrub_in($_REQUEST['password_2']);
	
		/* Setup the temp user */	
	    	$client = new User($user_id);
	
		/* Verify Input */
		if (empty($username)) { 
			Error::add('username',_("Error Username Required"));
		}
		if ($pass1 !== $pass2 && !empty($pass1)) { 
			Error::add('password',_("Error Passwords don't match"));
		}

		/* If we've got an error then break! */
		if (Error::$state) { 
			$_REQUEST['action'] = 'show_edit';
			break;
		} // if we've had an oops!

		if ($access != $client->access) { 
			$client->update_access($access);
		}
		if ($email != $client->email) { 
			$client->update_email($email);
		}
		if ($username != $client->username) { 
			$client->update_username($username);
		} 
		if ($fullname != $client->fullname) {
			$client->update_fullname($fullname);
		}
		if ($pass1 == $pass2 && strlen($pass1)) { 
			$client->update_password($pass1);
		} 
		
		show_confirmation(_('User Updated'), $client->fullname . "(" . $client->username . ")" . _('updated'),'admin/users.php');
	break;
	case 'add_user':
        	if (Config::get('demo_mode')) { break; }
		$username	= scrub_in($_REQUEST['username']);
		$fullname	= scrub_in($_REQUEST['fullname']);
		$email		= scrub_in($_REQUEST['email']);
		$access		= scrub_in($_REQUEST['access']);
		$pass1		= scrub_in($_REQUEST['password_1']);
		$pass2		= scrub_in($_REQUEST['password_2']);

		if ($pass1 !== $pass2) { 
			Error::add('password',_("Error Passwords don't match"));
		}

		if (empty($username)) { 
			Error::add('username',_('Error Username Required'));
		}

		/* make sure the username doesn't already exist */
		if (!User::check_username($username)) { 
			Error::add('username',_('Error Username already exists'));
		} 

		if (!Error::$state) { 
			/* Attempt to create the user */
			$user_id = User::create($username, $fullname, $email, $pass1, $access);
			if (!$user_id) { 
				Error::add('general',"Error: Insert Failed");
			}
			
		} // if no errors
		else { 
			$_REQUEST['action'] = 'show_add_user';
			break;
		}
		if ($access == 5){ $access = _('Guest');}
		elseif ($access == 25){ $access = _('User');}
		elseif ($access == 100){ $access = _('Admin');}
		
		show_confirmation(_('New User Added'),__('%user% has been created with an access level of ' . $access,'%user%',$username),'admin/users.php');	
	break;
	case 'enable':
		$client = new User($_REQUEST['user_id']); 
		$client->enable(); 
		show_confirmation(_('User Enabled'),'','admin/users.php'); 
	break;
	case 'disable':
		$client = new User($_REQUEST['user_id']); 
		if ($client->disable()) { 
			show_confirmation(_('User Disabled'),'','admin/users.php'); 
		} 
		else { 
			show_confirmation(_('Error'),_('Unable to Disabled last Administrator'),'admin/users.php'); 
		} 
	break;

} // End Work Switch


/**
 * This is the second half, it handles displaying anything
 * the first half (work half) potentially has 'adjusted' the user
 * input
 */
switch ($_REQUEST['action']) { 
	case 'show_edit':
        	if (Config::get('demo_mode')) { break; }
		$client	= new User($_REQUEST['user_id']); 
		require_once Config::get('prefix') . '/templates/show_edit_user.inc.php';
	break;
	case 'confirm_delete':
	        if (Config::get('demo_mode')) { break; }
		$client = new User($_REQUEST['user_id']); 
		if ($client->delete()) { 
			show_confirmation(_('User Deleted'), "$client->username has been Deleted","admin/users.php");
		}
		else { 
			show_confirmation(_('Delete Error'), _("Unable to delete last Admin User"),"admin/users.php");
		}
	break;
	case 'delete':
        	if (Config::get('demo_mode')) { break; }
		$client = new User($_REQUEST['user_id']); 
		show_confirmation(_('Deletion Request'),
			_('Are you sure you want to permanently delete') . " $client->fullname ($client->username)?",
			"admin/users.php?action=confirm_delete&amp;user_id=" . $_REQUEST['user_id'],1);
	break;
	/* Show IP History for the Specified User */
	case 'show_ip_history':
		/* get the user and their history */
		$working_user	= new User($_REQUEST['user_id']); 
		
		if (!isset ($_REQUEST['all'])){
			$history	= $working_user->get_ip_history('',1);
		} 
		else {
			$history	= $working_user->get_ip_history('','');
		}
		require Config::get('prefix') . '/templates/show_ip_history.inc.php';
	break;
	case 'show_add_user':
	        if (Config::get('demo_mode')) { break; }
		require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
	break;
	case 'show_preferences': 
		$client = new User($_REQUEST['user_id']); 
		$preferences = Preference::get_all($client->id); 	
		require_once Config::get('prefix') . '/templates/show_user_preferences.inc.php';
	break;
	default:
		Browse::set_type('user'); 
		Browse::set_simple_browse(1);
		Browse::set_sort('name','ASC');
		$user_ids = Browse::get_objects(); 
		Browse::show_objects($user_ids); 
	break;
} // end switch on action

/* Show the footer */
show_footer();

?>