Пример #1
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (!addon_installed('catalogues')) {
         return;
     }
     $last = get_value('last_classified_refresh');
     $time = time();
     if (!is_null($last) && intval($last) > $time - 60 * 60) {
         return;
     }
     // Don't do more than once per hour
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     $start = 0;
     do {
         $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices p ON p.c_catalogue_name=e.c_name', array('e.*'), array('ce_validated' => 1), '', 1000, $start);
         foreach ($entries as $entry) {
             if ($entry['ce_last_moved'] == $entry['ce_add_date']) {
                 require_code('classifieds');
                 initialise_classified_listing($entry);
             }
             // Expiring
             if ($entry['ce_last_moved'] < $time) {
                 $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_validated' => 0), array('id' => $entry['id']), '', 1);
                 decache('main_cc_embed');
                 decache('main_recent_cc_entries');
                 require_code('catalogues2');
                 calculate_category_child_count_cache($entry['cc_id']);
             } elseif ($entry['ce_last_moved'] < $time + 60 * 60 * 24 && $entry['ce_last_moved'] > $time + 60 * 60 * 23) {
                 // Expiring in 24 hours
                 require_code('notifications');
                 require_lang('classifieds');
                 $member_id = $entry['ce_submitter'];
                 $renew_url = build_url(array('page' => 'classifieds', 'type' => 'adverts', 'id' => $member_id), get_module_zone('classifieds'));
                 require_code('catalogues');
                 $data_map = get_catalogue_entry_map($entry, NULL, 'CATEGORY', 'DEFAULT', NULL, NULL, array(0));
                 $ad_title = $data_map['FIELD_0_PLAIN'];
                 if (is_object($ad_title)) {
                     $ad_title = $ad_title->evaluate();
                 }
                 $subject_tag = do_lang('SUBJECT_CLASSIFIED_ADVERT_EXPIRING', $ad_title, get_site_name(), NULL, get_lang($member_id), false);
                 $mail = do_lang('MAIL_CLASSIFIED_ADVERT_EXPIRING', $ad_title, comcode_escape(get_site_name()), comcode_escape($renew_url->evaluate()), get_lang($member_id), false);
                 // Send actual notification
                 dispatch_notification('classifieds__' . $entry['c_name'], '', $subject_tag, $mail, array($member_id), A_FROM_SYSTEM_PRIVILEGED);
             }
         }
     } while (count($entries) == 1000);
     set_value('last_classified_refresh', strval($time));
 }
Пример #2
0
 /**
  * View an overview of the members adverts on the system.
  *
  * @return tempcode		The UI
  */
 function adverts()
 {
     require_lang('classifieds');
     require_code('catalogues');
     require_code('ecommerce');
     $member_id = get_param_integer('member_id', get_member());
     $title = get_page_title($member_id == get_member() ? 'CLASSIFIED_ADVERTS' : '_CLASSIFIED_ADVERTS', true, array($GLOBALS['FORUM_DRIVER']->get_username($member_id)));
     if (is_guest()) {
         access_denied('NOT_AS_GUEST');
     }
     enforce_personal_access($member_id);
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 30);
     require_code('templates_results_browser');
     $max_rows = $GLOBALS['SITE_DB']->query_value('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices c ON c.c_catalogue_name=e.c_name', 'COUNT(*)', array('ce_submitter' => $member_id));
     $rows = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices c ON c.c_catalogue_name=e.c_name', array('e.*'), array('ce_submitter' => $member_id), 'GROUP BY e.id ORDER BY ce_add_date DESC');
     if (count($rows) == 0) {
         inform_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $ads = array();
     foreach ($rows as $row) {
         $root = get_param_integer('root', NULL);
         $data_map = get_catalogue_entry_map($row, NULL, 'CATEGORY', 'DEFAULT', $root, NULL, array(0));
         $ad_title = $data_map['FIELD_0'];
         $purchase_url = build_url(array('page' => 'purchase', 'type' => 'misc', 'filter' => 'CLASSIFIEDS_ADVERT', 'id' => $row['id']), get_module_zone('purchase'));
         // We'll show all transactions against this ad
         $transaction_details = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'transactions WHERE purchase_id=' . strval($row['id']) . ' AND item LIKE \'' . db_encode_like('CLASSIFIEDS\\_ADVERT\\_%') . '\'');
         $_transaction_details = array();
         foreach ($transaction_details as $t) {
             list($found, ) = find_product_row($t['item']);
             if (!is_null($found)) {
                 $item_title = $found[4];
             } else {
                 $item_title = $t['item'];
             }
             $_transaction_details[] = array('T_ID' => strval($t['id']), 'PURCHASE_ID' => strval($t['purchase_id']), 'STATUS' => $t['status'], 'REASON' => $t['reason'], 'AMOUNT' => float_format($t['amount']), 'T_CURRENCY' => $t['t_currency'], 'LINKED' => $t['linked'], 'T_TIME' => strval($t['t_time']), 'ITEM' => $t['item'], 'ITEM_TITLE' => $item_title, 'PENDING_REASON' => $t['pending_reason'], 'T_MEMO' => $t['t_memo'], 'T_VIA' => $t['t_via']);
         }
         $url_map = array('page' => 'catalogues', 'type' => 'entry', 'id' => $row['id'], 'root' => $root);
         $url = build_url($url_map, '_SELF');
         // No known expiry status: put on free, or let expire
         if ($row['ce_last_moved'] == $row['ce_add_date']) {
             require_code('classifieds');
             initialise_classified_listing($row);
         }
         $ads[] = array('AD_TITLE' => $ad_title, 'TRANSACTION_DETAILS' => $_transaction_details, 'DATE' => get_timezoned_date($row['ce_add_date']), 'DATE_RAW' => strval($row['ce_add_date']), 'EXPIRES_DATE' => get_timezoned_date($row['ce_last_moved']), 'EXPIRES_DATE_RAW' => strval($row['ce_last_moved']), 'ACTIVE' => $row['ce_validated'] == 1, 'PURCHASE_URL' => $purchase_url, 'ID' => strval($row['id']), 'URL' => $url, 'NUM_VIEWS' => integer_format($row['ce_views']));
     }
     $results_browser = results_browser(do_lang('_CLASSIFIED_ADVERTS'), NULL, $start, 'start', $max, 'max', $max_rows, NULL, NULL, true);
     return do_template('CLASSIFIED_ADVERTS_SCREEN', array('TITLE' => $title, 'RESULTS_BROWSER' => $results_browser, 'ADS' => $ads));
 }