function check_and_update_track($trackobj, $albumindex, $artistindex, $artistname) { global $find_track, $update_track, $numdone, $prefs, $doing_search; static $current_trackartist = null; static $trackartistindex = null; $ttid = null; $lastmodified = null; $hidden = 0; $disc = 0; $uri = null; $issearchresult = 0; // Why are we not checking by URI? That should be unique, right? // Well, er. no. They're not. // Especially Spotify returns the same URI multiple times if it's in mutliple playlists // We CANNOT HANDLE that. Nor do we want to. // The other advantage of this is that we can put an INDEX on Albumindex, TrackNo, and Title, // which we can't do with Uri cos it's too long - this speeds the whole process up by a factor // of about 32 (9 minutes when checking by URI vs 15 seconds this way, on my collection) // Also, URIs might change if the user moves his music collection. if ($prefs['collection_type'] == "sqlite") { // Lord knows why, but we have to re-prepare these every single bloody time! prepare_findtracks(); } if ($find_track->execute(array($trackobj->tags['Title'], $albumindex, $trackobj->tags['Track'], $trackobj->tags['Disc'], $artistindex))) { $obj = $find_track->fetch(PDO::FETCH_OBJ); if ($obj) { $ttid = $obj->TTindex; $lastmodified = $obj->LastModified; $hidden = $obj->Hidden; $disc = $obj->Disc; $issearchresult = $obj->isSearchResult; } } else { show_sql_error(); return false; } // NOTE: It is imperative that the search results have been tidied up - // i.e. there are no 1s or 2s in the database before we do a collection update // When doing a search, we MUST NOT change lastmodified of any track, because this will cause // user-added tracks to get a lastmodified date, and lastmodified == NULL // is how we detect user-added tracks and prevent them being deleted on collection updates if ($ttid) { if (!$doing_search && $trackobj->tags['Last-Modified'] != $lastmodified || $doing_search && $issearchresult == 0 || $trackobj->tags['Disc'] != $disc && $trackobj->tags['Disc'] !== '' || $hidden != 0) { if ($prefs['debug_enabled'] > 6) { # Don't bother doing all these string comparisons if debugging is disabled. It's slow. debuglog(" Updating track with ttid {$ttid} because :", "MYSQL", 7); if (!$doing_search && $lastmodified === null) { debuglog(" LastModified is not set in the database", "MYSQL", 7); } if (!$doing_search && $trackobj->tags['Last-Modified'] === null) { debuglog(" TrackObj LastModified is NULL too!", "MYSQL", 7); } if (!$doing_search && $lastmodified != $trackobj->tags['Last-Modified']) { debuglog(" LastModified has changed: We have " . $lastmodified . " but track has " . $trackobj->tags['Last-Modified'], "MYSQL", 7); } if ($disc != $trackobj->tags['Disc']) { debuglog(" Disc Number has changed: We have " . $disc . " but track has " . $trackobj->tags['Disc'], "MYSQL", 7); } if ($hidden != 0) { debuglog(" It is hidden", "MYSQL", 7); } } $newsearchresult = 0; $newlastmodified = $trackobj->tags['Last-Modified']; if ($issearchresult == 0 && $doing_search) { $newsearchresult = $hidden != 0 ? 3 : 1; debuglog(" It needs to be marked as a search result : Value " . $newsearchresult, "MYSQL", 7); $newlastmodified = $lastmodified; } if ($update_track->execute(array($trackobj->tags['Track'], $trackobj->tags['Time'], $trackobj->tags['Disc'], $newlastmodified, $trackobj->tags['file'], $albumindex, $newsearchresult, $ttid))) { $numdone++; check_transaction(); } else { show_sql_error(); } } } else { $a = $trackobj->get_artist_string(); if ($a != $current_trackartist || $trackartistindex == null) { if ($artistname != $a && $a != null) { $trackartistindex = check_artist($a, false); } else { $trackartistindex = $artistindex; } } if ($trackartistindex == null) { debuglog("ERROR! Trackartistindex is still null!", "MYSQL_TBT", 1); return false; } $current_trackartist = $a; $sflag = $doing_search ? 2 : 0; $ttid = create_new_track($trackobj->tags['Title'], null, $trackobj->tags['Track'], $trackobj->tags['Time'], null, null, null, null, null, $trackobj->tags['file'], $trackartistindex, $artistindex, $albumindex, null, null, $trackobj->tags['Last-Modified'], $trackobj->tags['Disc'], null, null, 0, $trackobj->getImage(), $sflag); $numdone++; check_transaction(); } if ($ttid == null) { debuglog("ERROR! No ttid for track " . $trackobj->tags['file'], "MYSQL", 1); } else { if (!$doing_search) { generic_sql_query("INSERT INTO Foundtracks (TTindex) VALUES (" . $ttid . ")", false, false); } } }
break; case 2: $item_number = rand(); $_SESSION['paypal']['catering'] = $_POST['catering']; $_SESSION['paypal']['donation'] = $_POST['donation']; $_SESSION['paypal']['item_number'] = $item_number; $smarty->assign('action', "document.paypal_form.submit();"); $dsp->NewContent(t('Senden der Daten'), t('Die Daten werden gesendet einen Moment bitte')); $dsp->SetForm($cfg['paypal_url'], "paypal_form"); $dsp->AddSingleRow("<font color=\"red\">" . t('Einen Moment Bitte die Daten werden gesendet') . "</font>"); $dsp->AddSingleRow("\n\t\t\t<!-- PayPal Configuration --> \n\t\t\t\t\t<input type=\"hidden\" name=\"business\" value=\"{$cfg['paypal_business']}\"> \n\t\t\t\t\t<input type=\"hidden\" name=\"cmd\" value=\"_xclick\"> \n\t\t\t\t\t<input type=\"hidden\" name=\"image_url\" value=\"\">\n\t\t\t\t\t<input type=\"hidden\" name=\"return\" value=\"{$cfg['paypal_site_url']}/index.php?mod=paypal&action=paying&design=base&step=3\">\n\t\t\t\t\t<input type=\"hidden\" name=\"cancel_return\" value=\"{$cfg['paypal_site_url']}/index.php?mod=paypal&action=paying&design=base&step=10\">\n\t\t\t\t\t<input type=\"hidden\" name=\"notify_url\" value=\"{$cfg['paypal_site_url']}/index.php?mod=paypal&action=paying&design=base&step=5\">\n\t\t\t\t\t<input type=\"hidden\" name=\"rm\" value=\"0\">\n\t\t\t\t\t<input type=\"hidden\" name=\"currency_code\" value=\"{$cfg['paypal_currency_code']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"lc\" value=\"DE\">\n\t\t\t\t\t<input type=\"hidden\" name=\"bn\" value=\"toolkit-php\">\n\t\t\t\t\t<input type=\"hidden\" name=\"cbt\" value=\"Next >>\">\n\t\t\t\t\t<!-- Payment Page Information --> \n\t\t\t\t\t<input type=\"hidden\" name=\"no_shipping\" value=\"1\">\n\t\t\t\t\t<input type=\"hidden\" name=\"no_note\" value=\"1\">\n\t\t\t\t\t<input type=\"hidden\" name=\"cn\" value=\"" . t('Kommentar') . "\">\n\t\t\t\t\t<!-- Customer Information --> \n\t\t\t\t\t<input type=\"hidden\" name=\"first_name\" value=\"{$_POST['firstname']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"last_name\" value=\"{$_POST['lastname']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"address1\" value=\"{$_POST['street']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"city\" value=\"{$_POST['city']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"zip\" value=\"{$_POST['zip']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"email\" value=\"{$_POST['email']}\">\n\t\t\t\t\t<!-- Product Information --> \n\t\t\t\t\t<input type=\"hidden\" name=\"item_name\" value=\"{$cfg['paypal_desc_name']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"item_number\" value=\"{$item_number}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"amount\" value=\"{$_POST['price_text']}\">"); $dsp->CloseForm(); $dsp->AddContent(); break; case 3: $check = check_transaction("ext_inc/paypal/ipn_success.txt.php", "ext_inc/paypal/ipn_checked.txt.php", $_POST['verify_sign'], $_POST['item_number']); if ($_POST['item_number'] == $_SESSION['paypal']['item_number'] && $check) { if (isset($_SESSION['paypal']['price'])) { foreach ($_SESSION['paypal']['price'] as $price_id) { $db->qry("UPDATE %prefix%party_user SET paid='1' WHERE user_id=%int% AND price_id=%int%", $auth['userid'], $price_id); if (isset($_SESSION['paypal']['depot']) && in_array($price_id, $_SESSION['paypal']['depot'])) { $db->qry("UPDATE %prefix%party_user SET seatcontrol='1' WHERE user_id=%int% AND price_id=%int%", $auth['userid'], $price_id); } } } if ($_SESSION['paypal']['catering'] > 0) { $db->qry("INSERT INTO %prefix%catering_accounting SET userID=%int%, actiontime=NOW(), comment=\"PAYPAL: %string% %string%\", movement=%string", $auth["userid"], $_POST['payment_date'], $_POST['txn_id'], $_SESSION['paypal']['catering']); } $dsp->NewContent(t('Zahlung erfolgreich')); $dsp->AddSmartyTpl('javascript', 'paypal'); $dsp->AddSingleRow(t('Die Zahlung war erfolgreich. Wir danken für die Einzahlung.'));
$listener = new IpnListener(); $listener->use_sandbox = true; try { // Process IPN request $verified = $listener->processIpn(); if (!$verified) { throw new Exception('Invalid IPN request'); } // Skip all notifications except for completed payments $payment_status = $listener->getData('payment_status'); if ($payment_status != 'Completed') { exit; } // Check transaction ID $transaction_id = $listener->getData('txn_id'); if (!check_transaction($transaction_id)) { throw new Exception('Unable to process IPN for transaction ID: ' . $transaction_id); } // Check receiver email $receiver_email = $listener->getData('receiver_email'); if (!check_receiver_email($receiver_email)) { throw new Exception('Unable to process IPN for receiver email: ' . $receiver_email); } // Check price and currency $payment_total = $listener->getData('mc_gross'); $payment_currency = $listener->getData('mc_currency'); if (!check_price($payment_total, $payment_currency)) { throw new Exception('Unable to process IPN due to issues with price/currency'); } // If we got this far, then its ok to fulfil the order $item_name = $listener->getData('item_name');