proba

// EDIT BELOW
/* ============================================================================= */

$pageTitle = “Song Requests”; //Page title
$limit = 25; //How many upcoming tracks to display?
$targetpage = $_SERVER[‘SCRIPT_NAME’]; //Link to this page
$reqLimit = 5; //Limit number of requests per IP

//messages:
define(“ERROR_TRACKID”, “Please select a track in order to send the request!
Go Back“);
define(“ERROR_USERNAME”, “Please enter your name in order to send the request!
Go Back“);
define(“ERROR_TRACKREQ”, “The selected track is already requested.
Please try again later, or select another track!”);
define(“ERROR_LIMITREACHED”, “Sorry, but you’ve reached the request limit for one day.”);
define(“ERROR_UNKNOWN”, “Unknown error occured! Please try again…”);

define(“MSG_REQSUCCESS”, “Your request was succesfully placed!”);
define(“MSG_NORESULTS”, “No results to display…”);

define(“REQ_DESCRIPTION”, “Please enter request details bellow”);
define(“REQ_NAME”, “Your Name:”);
define(“REQ_MESSAGE”, “Message (Optional):”);
define(“REQ_BUTTON”, “Submit Your Request”);

define(“NAV_NEXT”, “NEXT”);
define(“NAV_PREV”, “PREVIOUS”);

define(“SEARCH_TXT”, “Search artist or title:”);
define(“SEARCH_BUTTON”, “Search”);

define(“COL_ARTIST”, “Artist”);
define(“COL_TITLE”, “Title”);
define(“COL_DURATION”, “Duration”);
define(“COL_REQ”, “Req”);
define(“ALT_REQ”, “Request this track”);

/* ============================================================================= */
// END EDIT
/* ============================================================================= */

require_once(‘serv_inc.php’);
require_once(‘header.php’);

date_default_timezone_set($def_timezone);

//============ FUNCTIONS ==============//

//build duration string from seconds
function convertTime($seconds) {
$sec = $seconds;
// Time conversion
$hours = intval(intval($sec) / 3600);
$padHours = True;
$hms = ($padHours)
? str_pad($hours, 2, “0”, STR_PAD_LEFT). ‘:’
: $hours. ‘:’;
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, “0”, STR_PAD_LEFT). ‘:’;
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, “0”, STR_PAD_LEFT);

return $hms;
}

function getRealIpAddr() {
if (!empty($_SERVER[‘HTTP_CLIENT_IP’])){
//check ip from share internet
$ip=$_SERVER[‘HTTP_CLIENT_IP’];
}
elseif (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’])){
//to check ip is pass from proxy
$ip=$_SERVER[‘HTTP_X_FORWARDED_FOR’];
} else {
$ip=$_SERVER[‘REMOTE_ADDR’];
}
return $ip;
}

//============ END FUNCTIONS ==============//

$srch = “”; //search term value holder
$srchpath = “”; //search path holder
$srcquery = “”; //search query holder
$stages = 3; //how to split the pagination
$page = 1; //default page
$reqid = “”;

if(isset($_GET[‘searchterm’])){
if($_GET[‘searchterm’] != “”) {

$srch = mysql_escape_string($_GET[‘searchterm’]);
$srchpath = “&searchterm=$srch”;
$srcquery = “AND (`artist` LIKE ‘%$srch%’ OR `title` LIKE ‘%$srch%’)”; //Search artist and title
}
}

//Get the page if it’s requested
if(isset($_GET[‘page’])){
$page = mysql_escape_string($_GET[‘page’]);
}

if($page){
$start = ($page – 1) * $limit;
}else{
$start = 0;
}

if(isset($_POST[‘reqsubmit’])){

/*
ERROR CODES:
0 = No error
1 = no user name
2 = no requested track
3 = track already in queue
4 = request limit reached
*/

$reqname = mysql_escape_string($_POST[‘requsername’]);
$reqmsg = mysql_escape_string($_POST[‘reqmessage’]);
$reqsongID = mysql_escape_string($_POST[‘songID’]);
$reqIP = getRealIpAddr();

$error = 0;
$reccount = 0;

if(!$reqname){$error = 1;}
if(!$reqsongID){$error = 2;}

if($error == 0){

db_conn();

//track is already requested?
$recheck = “SELECT COUNT(*) AS num FROM `requests` WHERE `songID`=’$reqsongID’ AND `played`=0;”;
$total_req = mysql_fetch_array(mysql_query($recheck));

if($total_req[‘num’] > 0){
$error = 3;
}

@mysql_free_result($total_req);

if($error == 0){
//user has reached the request limit?
$recheck = “SELECT COUNT(*) AS num FROM `requests` WHERE `userIP`=’$reqIP’ AND DATE(`requested`) = DATE(NOW());”;
$total_req = mysql_fetch_array(mysql_query($recheck));

if($total_req[‘num’] >= $reqLimit){
$error = 4;
$reccount = $total_req[‘num’];
}

@mysql_free_result($total_req);
db_close($opened_db);
}

}

switch ($error) {
case 0:
db_conn();

$queryx = “INSERT INTO `requests` SET `songID`=’$reqsongID’, `username`=’$reqname’, `userIP`=’$reqIP’, `message`=’$reqmsg’, `requested`=now();”;
$resultx = mysql_query($queryx);

if($resultx > 0) {
echo ”

” . MSG_REQSUCCESS . “

“;
} else {
echo ”

” . ERROR_UNKNOWN . “

“;
}

@mysql_free_result($resultx);
db_close($opened_db);

break;
case 1:
echo ”

” . ERROR_USERNAME . “

“;
break;
case 2:
echo ”

” . ERROR_TRACKID . “

“;
break;
case 3:
echo ”

” . ERROR_TRACKREQ . “

“;
break;
case 4:
echo ”

” . ERROR_LIMITREACHED . ” (” . $reccount . “/” . $reqLimit . “)” . “

“;
break;
}

$reqid = “”;
}

//Get the page if it’s requested
if(isset($_GET[‘requestid’])){

if($_GET[‘requestid’] != “”) {

$reqid = mysql_escape_string($_GET[‘requestid’]);

echo ”

\n”;
echo “

\n”;
echo “\n”;echo “\n”;echo “\n”;
echo “\n”;
echo “\n”;echo “\n”;
echo “\n”;
echo “\n”;
echo “\n”;echo “\n”;
echo “\n”;
echo “\n”;
echo “\n”;echo “\n”;
echo “\n”;
echo ”

” . REQ_DESCRIPTION . ”

” . REQ_NAME . “
” . REQ_MESSAGE . “

\n”;
echo ” \n”;
echo ”

\n”;
echo ”

\n”;
}
}

//================//

if($reqid == “”){
db_conn();

//Get the number of items
$query = “SELECT COUNT(*) as num FROM `songs` WHERE `enabled`=’1′ $srcquery AND `song_type`=0”;
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[‘num’];

//Get page data
$query1 = “SELECT `ID`, `artist`, `title`, `duration`, `date_played`, `artist_played` FROM `songs` WHERE `enabled`=’1′ $srcquery AND`song_type`=0 ORDER BY `artist` ASC LIMIT $start, $limit”;
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page – 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage – 1;

$paginate = ”;

if($lastpage > 1) {
$paginate .= ”

“;
// Previous
if ($page > 1){
$paginate.= “” . NAV_NEXT . ““;
}else{
$paginate.= “” . NAV_PREV . ““;
}// Pages

if ($lastpage < 7 + ($stages * 2)) {
for ($counter = 1; $counter <= $lastpage; $counter++) {
if ($counter == $page){
$paginate.= “$counter“;
}else{
$paginate.= “$counter“;
}
}
} elseif($lastpage > 5 + ($stages * 2)) {

// Beginning only hide later pages
if($page < 1 + ($stages * 2)) {
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) {
if ($counter == $page){
$paginate.= “$counter“;
}else{
$paginate.= “$counter“;
}
}

$paginate.= “…”;
$paginate.= “$LastPagem1“;
$paginate.= “$lastpage“;

} elseif($lastpage – ($stages * 2) > $page && $page > ($stages * 2)){

$paginate.= “1“;
$paginate.= “2“;
$paginate.= “…”;

for ($counter = $page – $stages; $counter <= $page + $stages; $counter++){
if ($counter == $page){
$paginate.= “$counter“;
}else{
$paginate.= “$counter“;
}
}

$paginate.= “…”;
$paginate.= “$LastPagem1“;
$paginate.= “$lastpage“;

} else {

$paginate.= “1“;
$paginate.= “2“;
$paginate.= “…”;

for ($counter = $lastpage – (2 + ($stages * 2)); $counter <= $lastpage; $counter++) {
if ($counter == $page){
$paginate.= “$counter“;
}else{
$paginate.= “$counter“;
}
}
}
}

// Next
if ($page < $counter – 1){
$paginate.= “” . NAV_NEXT . ““;
}else{
$paginate.= “” . NAV_NEXT . ““;
}
$paginate.= ”

“;
}

//Search box
echo ‘

‘;
echo “

“;
echo SEARCH_TXT . ” “;
echo ‘
‘;
echo ‘

‘;
echo ‘

‘;

if($total_pages > 0){

//Add the pagination
echo ”

$paginate

“;

//Results table
echo ‘

‘;echo “” . “\n”;echo “\n”;
echo “\n”;
echo “\n”;
echo “\n”;
echo “\n”;
echo “” . “\n”;$cnt = 1+($limit*$page)-$limit; //Results counter//Add results to the table
while($row = mysql_fetch_assoc($result)) {
echo “” . “\n”;echo “\n”;
echo “\n”;
echo “\n”;
echo “\n”;if(track_can_play($row[‘date_played’], $row[‘artist_played’]) == true) {
echo “\n”;
}else{
echo “\n”;
}echo “” . “\n”;
$cnt++;
}@mysql_free_result($result);
db_close($opened_db);
?>

# ” . COL_ARTIST . “ ” . COL_TITLE . “ ” . COL_DURATION . “ ” . COL_REQ . “
$cnt. ” . $row[‘artist’] . “ ” . $row[‘title’] . “ ” . convertTime($row[‘duration’]) . “
\""

 

echo ‘

‘ . $paginate . ‘

‘;
}else{
echo ”

” . MSG_NORESULTS . “

“;
}
}
require_once(‘footer.php’);
?>