Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
function search_output()
{
    global $opt, $tpl, $login;
    global $enable_mapdisplay;
    global $called_by_search, $called_by_profile_query, $options, $lat_rad, $lon_rad, $distance_unit;
    global $startat, $caches_per_page, $sql, $query_userid, $query_name;
    $tpl->name = 'search.result.caches';
    $tpl->menuitem = MNU_CACHES_SEARCH_RESULT;
    $startat = floor($startat / $caches_per_page) * $caches_per_page;
    $sql .= ' LIMIT ' . $startat . ', ' . $caches_per_page;
    // run SQL query
    sql_enable_foundrows();
    $rs_caches = sql_slave("SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS " . $sql);
    $resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0);
    sql_foundrows_done();
    $tpl->assign('results_count', $resultcount);
    $tpl->assign('startat', $startat);
    $caches = array();
    while ($rCache = sql_fetch_array($rs_caches)) {
        // select best-fitting short desc for active language
        $rCache['short_desc'] = sql_value_slave("\n            SELECT `short_desc`\n            FROM `cache_desc`\n            WHERE `cache_id`='&1'\n            AND `language`='&2'", false, $rCache['cache_id'], $opt['template']['locale']);
        if ($rCache['short_desc'] === false) {
            $rCache['short_desc'] = sql_value_slave("\n\t\t\t\tSELECT `short_desc`\n\t\t\t\tFROM `cache_desc`\n\t\t\t\tWHERE `cache_id`='&1'\n\t\t\t\tAND `language`='EN'", false, $rCache['cache_id']);
        }
        if ($rCache['short_desc'] === false) {
            $rCache['short_desc'] = sql_value_slave("\n\t\t\t\tSELECT `short_desc`\n\t\t\t\tFROM `cache_desc`\n\t\t\t\tWHERE `cache_id`='&1'\n\t\t\t\tORDER BY `date_created`\n\t\t\t\tLIMIT 1", '', $rCache['cache_id']);
        }
        $rCache['desclangs'] = mb_split(',', $rCache['desc_languages']);
        // decide if the cache is new
        $dDiff = dateDiff('d', $rCache['date_created'], date('Y-m-d'));
        $rCache['isnew'] = $dDiff <= NEWCACHES_DAYS;
        // get last logs
        if ($options['sort'] != 'bymylastlog' || !$login->logged_in()) {
            $ownlogs = "";
        } else {
            $ownlogs = " AND `cache_logs`.`user_id`='" . sql_escape($login->userid) . "'";
        }
        $sql = "\n\t\t\t\tSELECT `cache_logs`.`id`, `cache_logs`.`type`, `cache_logs`.`date`, `log_types`.`icon_small`\n\t\t\t\tFROM `cache_logs`, `log_types`\n\t\t\t\tWHERE `cache_logs`.`cache_id`='" . sql_escape($rCache['cache_id']) . "'\n\t\t\t\t      AND `log_types`.`id`=`cache_logs`.`type`" . $ownlogs . "\n\t\t\t\tORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `cache_logs`.`id` DESC\n\t\t\t\tLIMIT 6";
        $rs = sql_slave($sql);
        $rCache['logs'] = sql_fetch_assoc_table($rs);
        $rCache['firstlog'] = array_shift($rCache['logs']);
        // get direction from search coordinate
        if ($rCache['distance'] > 0) {
            $direction = geomath::calcBearing($lat_rad / 3.14159 * 180, $lon_rad / 3.14159 * 180, $rCache['latitude'], $rCache['longitude']);
            $rCache['direction_deg'] = round($direction / 22.5) * 22.5;
            $rCache['direction_txt'] = geomath::Bearing2Text($direction, 0, $opt['template']['locale']);
        } else {
            $rCache['direction_deg'] = false;
        }
        // other data
        $rCache['icon'] = getCacheIcon($login->userid, $rCache['cache_id'], $rCache['status'], $rCache['user_id'], $rCache['icon_large']);
        $rCache['redname'] = $rCache['status'] == 5 || $rCache['status'] == 7;
        $caches[] = $rCache;
    }
    mysql_free_result($rs_caches);
    $tpl->assign('caches', $caches);
    $page = 'search.php?queryid=' . $options['queryid'] . '&startat={offset}&sortby=' . $options['sort'];
    if (isset($options['sortorder']) && $options['sortorder']) {
        $page .= "&sortorder=" . $options['sortorder'];
    }
    if (isset($options['creationdate']) && $options['creationdate']) {
        $page .= "&creationdate=" . $options['creationdate'];
    }
    $pager = new pager($page, 2, 9);
    $pager->make_from_offset($startat, $resultcount, $caches_per_page);
    // downloads
    $tpl->assign('queryid', $options['queryid']);
    if (isset($query_userid)) {
        $tpl->assign('query_name', $query_name);
    }
    $tpl->assign('startatp1', min($resultcount, $startat + 1));
    if ($resultcount - $startat < 500) {
        $tpl->assign('endat', $startat + $resultcount - $startat);
    } else {
        $tpl->assign('endat', $startat + 500);
    }
    // kompatibilität!
    if ($distance_unit == 'sm') {
        $tpl->assign('distanceunit', 'mi');
    } elseif ($distance_unit == 'nm') {
        $tpl->assign('distanceunit', 'sm');
    } else {
        $tpl->assign('distanceunit', $distance_unit);
    }
    $tpl->assign('displayownlogs', $options['sort'] == 'bymylastlog');
    $tpl->assign('search_headline_caches', $called_by_search);
    $tpl->assign('enable_mapdisplay', $enable_mapdisplay);
    // sort results by
    $tpl->assign('sortby', $options['sort']);
    if (isset($options['sortorder'])) {
        $tpl->assign('sortorder', $options['sortorder']);
    }
    if ($options['sort'] == 'bycreated' || isset($options['creationdate'])) {
        $tpl->assign('creationdate', true);
    }
    // cachelist data
    if (isset($options['cachelist'])) {
        $tpl->assign('cachelist', $options['cachelist']);
        $tpl->assign('cachelist_pw', $options['cachelist_pw']);
    } else {
        $tpl->assign('cachelist', false);
    }
    // disable "edit options" for internally generated searches
    if ($options['searchtype'] == 'bylist') {
        $tpl->assign('disable_edit_options', true);
    }
    $tpl->display();
}