function process_new_cache($notify) { global $opt, $debug, $debug_mailto, $rootpath, $translate; global $maildomain, $mailfrom; //echo "process_new_cache(".$notify['id'].")\n"; $error = false; // fetch email template switch ($notify['type']) { case notify_new_cache: // Type: new cache $mailbody = fetch_email_template('notify_newcache', $notify['recp_lang'], $notify['recp_domain']); $mailsubject = '[' . $maildomain . '] ' . $translate->t($notify['oconly'] ? 'New OConly cache:' : 'New cache:', '', basename(__FILE__), __LINE__, '', 1, $notify['recp_lang']) . ' ' . $notify['cachename']; break; case notify_new_oconly: // Type: new OConly flag $mailbody = fetch_email_template('notify_newoconly', $notify['recp_lang'], $notify['recp_domain']); $mailsubject = '[' . $maildomain . '] ' . $translate->t('Cache was marked as OConly:', '', basename(__FILE__), __LINE__, '', 1, $notify['recp_lang']) . ' ' . $notify['cachename']; break; default: $error = true; break; } if (!$error) { $mailbody = mb_ereg_replace('{username}', $notify['recpname'], $mailbody); $mailbody = mb_ereg_replace('{date}', date($opt['locale'][$notify['recp_lang']]['format']['phpdate'], strtotime($notify['date_hidden'])), $mailbody); $mailbody = mb_ereg_replace('{cacheid}', $notify['cache_id'], $mailbody); $mailbody = mb_ereg_replace('{wp_oc}', $notify['wp_oc'], $mailbody); $mailbody = mb_ereg_replace('{user}', $notify['username'], $mailbody); $mailbody = mb_ereg_replace('{cachename}', $notify['cachename'], $mailbody); $mailbody = mb_ereg_replace('{distance}', round(geomath::calcDistance($notify['lat1'], $notify['lon1'], $notify['lat2'], $notify['lon2'], 1), 1), $mailbody); $mailbody = mb_ereg_replace('{unit}', 'km', $mailbody); $mailbody = mb_ereg_replace('{bearing}', geomath::Bearing2Text(geomath::calcBearing($notify['lat1'], $notify['lon1'], $notify['lat2'], $notify['lon2']), 0, $notify['recp_lang']), $mailbody); $mailbody = mb_ereg_replace('{cachetype}', get_cachetype_name($notify['cachetype'], $notify['recp_lang']), $mailbody); $mailbody = mb_ereg_replace('{cachesize}', get_cachesize_name($notify['cachesize'], $notify['recp_lang']), $mailbody); $mailbody = mb_ereg_replace('{oconly-}', $notify['oconly'] ? $translate->t('OConly-', '', basename(__FILE__), __LINE__, '', 1, $notify['recp_lang']) : '', $mailbody); /* begin send out everything that has to be sent */ $email_headers = 'From: "' . $mailfrom . '" <' . $mailfrom . '>'; // send email if ($debug == true) { $mailadr = $debug_mailto; } else { $mailadr = $notify['email']; } if (is_existent_maildomain(getToMailDomain($mailadr))) { mb_send_mail($mailadr, $mailsubject, $mailbody, $email_headers); } } else { echo "Unknown notification type: " . $notify['type'] . "<br />"; } // logentry($module, $eventid, $userid, $objectid1, $objectid2, $logtext, $details) logentry('notify_newcache', 8, $notify['recid'], $notify['cache_id'], 0, 'Sending mail to ' . $mailadr, []); return 0; }
public static function getLogsArray($cacheid, $start, $count, $deleted = false, $protect_old_coords = false) { global $login, $translate; // negative or abornally high numbers like 1.0E+15 can crash the LIMIT statement if ($count <= 0 || $count > 10000) { return array(); } $rsCoords = sql("SELECT `date_created` `date`, `latitude`, `longitude`\n\t\t\t FROM `cache_coordinates`\n\t\t\t WHERE `cache_id`='&1'\n\t\t\t ORDER BY `date_created` DESC", $cacheid); $coords = sql_fetch_assoc_table($rsCoords); if ($coords) { $coords[] = ['date' => '0000-00-00', 'latitude' => $coords[count($coords) - 1]['latitude'], 'longitude' => $coords[count($coords) - 1]['longitude']]; $current_coord = new coordinate($coords[0]['latitude'], $coords[0]['longitude']); } if ($deleted && ($login->admin && ADMIN_USER) > 0) { // admins may view owner-deleted logs $table = 'cache_logs_archived'; $delfields = 'IFNULL(`u2`.`username`,"") AS `deleted_by_name`, `deletion_date`, "1" AS `deleted`'; $addjoin = 'LEFT JOIN `user` `u2` ON `u2`.`user_id`=`cache_logs`.`deleted_by`'; } else { $table = 'cache_logs'; $delfields = '"" AS `deleted_by_name`, NULL AS `deletion_date`, "0" AS `deleted`'; $addjoin = ''; } $rsLogs = sql('SELECT `cache_logs`.`user_id` AS `userid`, `cache_logs`.`id` AS `id`, `cache_logs`.`uuid` AS `uuid`, `cache_logs`.`date` AS `date`, `cache_logs`.`order_date` AS `order_date`, `cache_logs`.`entry_last_modified`, DATEDIFF(`cache_logs`.`entry_last_modified`, `cache_logs`.`date_created`) >= 1 AS `late_modified`, substr(`cache_logs`.`date`,12) AS `time`, /* 00:00:01 = 00:00 logged, 00:00:00 = no time */ `cache_logs`.`type` AS `type`, `cache_logs`.`oc_team_comment` AS `oc_team_comment`, `cache_logs`.`needs_maintenance` AS `needs_maintenance`, `cache_logs`.`listing_outdated` AS `listing_outdated`, `cache_logs`.`text` AS `text`, `cache_logs`.`text_html` AS `texthtml`, `cache_logs`.`picture`, ' . $delfields . ",\n\t\t\t\t `user`.`username` AS `username`,\n\t\t\t\t IF(ISNULL(`cache_rating`.`cache_id`), 0, `cache_logs`.`type` IN (1,7)) AS `recommended`\n\t\t\t FROM {$table} AS `cache_logs`\n\t\t\t INNER JOIN `user` \n\t\t\t ON `user`.`user_id` = `cache_logs`.`user_id`\n\t\t\t LEFT JOIN `cache_rating` \n\t\t\t ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` \n\t\t\t AND `cache_logs`.`user_id`=`cache_rating`.`user_id` \n\t\t\t AND `cache_logs`.`date`=`cache_rating`.`rating_date`\n\t\t\t " . $addjoin . "\n\t\t\t WHERE `cache_logs`.`cache_id`='&1'\n\t\t\t ORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `id` DESC\n\t\t\t LIMIT &2, &3", $cacheid, $start + 0, $count + 0); $logs = array(); $coordpos = 0; $coord_changes = false; while ($rLog = sql_fetch_assoc($rsLogs)) { $pictures = array(); $rsPictures = sql("SELECT `url`, `title`, `uuid`, `id`, `spoiler`\n\t\t\t\t FROM `pictures`\n\t\t\t\t WHERE `object_id`='&1' \n\t\t\t\t AND `object_type`=1\n\t\t\t\t ORDER BY `seq`", $rLog['id']); while ($rPicture = sql_fetch_assoc($rsPictures)) { if (trim($rPicture['title']) == '') { $rPicture['title'] = $translate->t('Picture', '', '', 0) . ' ' . (count($pictures) + 1); } $pictures[] = $rPicture; } sql_free_result($rsPictures); $rLog['pictures'] = $pictures; $rLog['text'] = use_current_protocol_in_html($rLog['text']); $newcoord = false; while ($coordpos < count($coords) && $coords[$coordpos]['date'] > $rLog['order_date']) { if (!$newcoord) { $newcoord = $coords[$coordpos]; } ++$coordpos; } if ($newcoord) { $distance = geomath::calcDistance($newcoord['latitude'], $newcoord['longitude'], $coords[$coordpos]['latitude'], $coords[$coordpos]['longitude']); if (abs($distance) > 0.005) { $new = new coordinate($newcoord['latitude'], $newcoord['longitude']); $rLog['newcoord'] = $new->getDecimalMinutes($protect_old_coords && $new != $current_coord); if ($protect_old_coords) { $rLog['movedbykm'] = false; } elseif ($distance <= 1) { $rLog['movedbym'] = floor($distance * 1000); } elseif ($distance < 10) { $rLog['movedbykm'] = sprintf('%1.1f', $distance); } else { $rLog['movedbykm'] = round($distance); } $coord_changes = true; } } $logs[] = $rLog; } sql_free_result($rsLogs); if ($coord_changes) { $original = count($coords) - 1; $lastlogdate = $logs[count($logs) - 1]['order_date']; while ($original > 0 && $coords[$original - 1]['date'] < $lastlogdate) { --$original; } $coord = new coordinate($coords[$original]['latitude'], $coords[$original]['longitude']); $logs[] = ['newcoord' => $coord->getDecimalMinutes($protect_old_coords), 'movedby' => false]; } return $logs; }