Failed SQL queries are now also reported in bug mails, SQL queries improved (more...
[mailer.git] / inc / libs / surfbar_functions.php
index e62d683..ab04a7f 100644 (file)
@@ -364,11 +364,11 @@ function SURFBAR_MEMBER_RESUBMIT_ACTION ($urlData) {
 // Display selected "action form"
 function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) {
        // Translate some data
-       $urlData['registered']    = generateDateTime($urlData['registered'], 2);
-       $urlData['views_total']   = translateComma($urlData['views_total']);
-       $urlData['views_max']     = translateComma($urlData['views_max']);
-       $urlData['views_allowed'] = translateComma($urlData['views_allowed']);
-       $urlData['last_locked']   = generateDateTime($urlData['last_locked'], 2);
+       $urlData['url_registered'] = generateDateTime($urlData['url_registered'], 2);
+       $urlData['views_total']    = translateComma($urlData['views_total']);
+       $urlData['views_max']      = translateComma($urlData['views_max']);
+       $urlData['views_allowed']  = translateComma($urlData['views_allowed']);
+       $urlData['last_locked']    = generateDateTime($urlData['last_locked'], 2);
 
        // Is the lock reason empty?
        if (empty($urlData['lock_reason'])) {
@@ -556,7 +556,7 @@ function SURFBAR_GET_URL_DATA ($searchTerm, $column = 'id', $order = 'id', $sort
        $result = SQL_QUERY_ESC("SELECT
        `id`, `userid`, `url`,
        `views_total`, `views_max`, `views_allowed`, `status`,
-       UNIX_TIMESTAMP(`registered`) AS `registered`, UNIX_TIMESTAMP(`last_locked`) AS `last_locked`, `lock_reason`,
+       UNIX_TIMESTAMP(`registered`) AS `url_registered`, UNIX_TIMESTAMP(`last_locked`) AS `last_locked`, `lock_reason`,
        `views_max`, `views_allowed`, `fixed_reload`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_urls`
@@ -684,12 +684,12 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
        } // END - if
 
        // Translate some data if present
-       if (isset($content['status']))        $content['status']        = translateSurfbarUrlStatus($content['status']);
-       if (isset($content['registered']))    $content['registered']    = generateDateTime($content['registered'], 2);
-       if (isset($content['last_locked']))   $content['last_locked']   = generateDateTime($content['last_locked'], 2);
-       if (isset($content['views_total']))   $content['views_total']   = translateComma($content['views_total']);
-       if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']);
-       if (isset($content['views_max']))     $content['views_max']     = translateComma($content['views_max']);
+       if (isset($content['status']))         $content['status']         = translateSurfbarUrlStatus($content['status']);
+       if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2);
+       if (isset($content['last_locked']))    $content['last_locked']    = generateDateTime($content['last_locked'], 2);
+       if (isset($content['views_total']))    $content['views_total']    = translateComma($content['views_total']);
+       if (isset($content['views_allowed']))  $content['views_allowed']  = translateComma($content['views_allowed']);
+       if (isset($content['views_max']))      $content['views_max']      = translateComma($content['views_max']);
 
        // Send the notification out
        return sendAdminNotification($subject, $templateName, $content, $content['userid']);
@@ -717,12 +717,12 @@ function SURFBAR_NOTIFY_USER ($messageType, $content) {
        } // END - if
 
        // Translate some data if present
-       if (isset($content['status']))        $content['status']        = translateSurfbarUrlStatus($content['status']);
-       if (isset($content['registered']))    $content['registered']    = generateDateTime($content['registered'], 2);
-       if (isset($content['last_locked']))   $content['last_locked']   = generateDateTime($content['last_locked'], 2);
-       if (isset($content['views_total']))   $content['views_total']   = translateComma($content['views_total']);
-       if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']);
-       if (isset($content['views_max']))     $content['views_max']     = translateComma($content['views_max']);
+       if (isset($content['status']))         $content['status']         = translateSurfbarUrlStatus($content['status']);
+       if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2);
+       if (isset($content['last_locked']))    $content['last_locked']    = generateDateTime($content['last_locked'], 2);
+       if (isset($content['views_total']))    $content['views_total']    = translateComma($content['views_total']);
+       if (isset($content['views_allowed']))  $content['views_allowed']  = translateComma($content['views_allowed']);
+       if (isset($content['views_max']))      $content['views_max']      = translateComma($content['views_max']);
 
        // Load template
        $mailText = loadEmailTemplate($templateName, $content, $content['userid']);
@@ -1445,14 +1445,25 @@ ORDER BY
 // "Getter" for maximum random number
 function SURFBAR_GET_MAX_RANDOM ($userids, $add) {
        // Count max availabe entries
-       $result = SQL_QUERY("SELECT sbu.id AS cnt
-FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
-LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
-ON sbu.id=sbs.url_id
-LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
-ON sbu.id=l.url_id
-WHERE sbu.userid NOT IN (".implode(',', $userids).") AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND sbu.`status`='ACTIVE'".$add."
-GROUP BY sbu.id", __FUNCTION__, __LINE__);
+       $result = SQL_QUERY("SELECT
+       sbu.id AS cnt
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
+ON
+       sbu.id=sbs.url_id
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
+ON
+       sbu.id=l.url_id
+WHERE
+       sbu.userid NOT IN (".implode(',', $userids).") AND
+       (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND
+       sbu.`status`='ACTIVE'
+       ".$add."
+GROUP BY
+       sbu.id ASC", __FUNCTION__, __LINE__);
 
        // Log last query
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false);
@@ -1473,10 +1484,19 @@ function SURFBAR_GET_USER_URLS () {
        $URLs = array();
 
        // Begin the query
-       $result = SQL_QUERY_ESC("SELECT u.id, u.userid, u.url, u.views_total, u.views_max, u.views_allowed, u.status, UNIX_TIMESTAMP(u.registered) AS registered, UNIX_TIMESTAMP(u.last_locked) AS last_locked, u.lock_reason AS lock_reason
-FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
-WHERE u.userid=%s AND u.status != 'DELETED'
-ORDER BY u.id ASC",
+       $result = SQL_QUERY_ESC("SELECT
+       u.id, u.userid, u.url, u.status,
+       u.views_total, u.views_max, u.views_allowed,
+       UNIX_TIMESTAMP(u.registered) AS url_registered,
+       UNIX_TIMESTAMP(u.last_locked) AS last_locked,
+       u.lock_reason AS lock_reason
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
+WHERE
+       u.userid=%s AND
+       u.status != 'DELETED'
+ORDER BY
+       u.id ASC",
        array(getMemberId()), __FUNCTION__, __LINE__);
 
        // Are there entries?