Location: PHPKode > projects > Esvon Personals > esvon-personals/cron/cl_cron.php
<?php

// --------------------------------------------------------------------------
//
// Esvon Classifieds v.4.0
// Copyright(C), Esvon LTD, 2001-2010, All Rights Reserved.
// E-mail: hide@address.com
//
// All forms of reproduction, including, but not limited to, internet posting,
// printing, e-mailing, faxing and recording are strictly prohibited.
// One license required per site running Esvon Classifieds.
// To obtain a license for using Esvon Classifieds, please register at
// http://www.esvon.com/pg/products/p_classifieds/
//
// --------------------------------------------------------------------------

@set_time_limit(0);
ignore_user_abort(true);

define('IS_CRON', 1);
define('ADMIN_AREA', 1);

require substr(dirname(__FILE__),0,-4).'inc/application.php';

if(EN_CRON_CMD && isset($_SERVER['SERVER_ADDR']) && ($_SERVER['SERVER_ADDR']!=$_SERVER['REMOTE_ADDR'])) die("Access Denied");
if(hwModGetState('Cron_General') != 'A') die('Module inactive: Cron_General');

echo "\n"; // Trick to continue on headers received
flush();

Cron_Log_Entry('START');
register_shutdown_function(create_function('','if(connection_status()==2) Cron_Log_Entry("TIMEOUT");'));

$_cron_lock = FILE_DIR.'__CRON_LOCK__'; // cron lock file
$_cron_max_time = 3*60*60; // max. allowed cron execution time, 3h by default (hardly reachable)
if(is_file($_cron_lock) && (filemtime($_cron_lock) + $_cron_max_time > HW_TIME)){ 
  $age_in_hours = round((time()-filemtime($_cron_lock))/3600,2);
  Cron_Err_Exit(basename($_cron_lock)." exists and is $age_in_hours hours old");
}

touch($_cron_lock);
if(!chmod($_cron_lock, 0666)) Cron_Err_Exit('Delete '.basename($_cron_lock).' or make it writable');

$O_HW->Update(
  array('CRON_TIME' => HW_TIME)
);

$A_PP_INTO = $db->two_col_assoc('SELECT id,pp_exp_into FROM '.TBL_PAY_PLAN.' WHERE pp_exp_into<>"" AND enabled="1"');

// delete expired paid features

$a_v = array(
  TBL_AD => 'link_id',
  TBL_USER => 'id',
);

foreach($a_v as $tbl=>$tbl_key){

  $res = $db->query("SELECT $tbl_key,hw_pay_plan,UNIX_TIMESTAMP(exp_date) FROM $tbl WHERE hw_pay_plan<>''");
  while(list($hw_id,$hw_pay_plan,$exp_ts)=mysql_fetch_row($res)){

    $A_PLAN = hwPayOptsToArr($hw_pay_plan);
    if($A_PLAN) foreach($A_PLAN as $k=>$v){

      $id = $v['ID'];
      $time = isset($v['VAL']) ? $v['DT'] : $exp_ts;
      
      if($time && $time < HW_TIME){  // if not expired but it's time to expire

        $args = array(
          'PP_ID' => $id,
          'ID' => $hw_id,
          'EX_VAL' => $v['VAL'],
        );

        hwEvent('PayPlanOff',$args);

        $A_CRON['Cron_General'][hwLng('cron_plans')][$id]++;

        if(!isset($v['VAL']) && $A_PP_INTO[$id]) {

          $args = array(
            'PP_ID' => $A_PP_INTO[$id],
            'ID' => $hw_id,
          );

          hwEvent('PayPlanOn',$args);
            
        }

      }

    }
    
  }
}


$args = array();
hwModEvent('onCronExecute',$args);
$A_CRON = $args['A_CRON'];

Cron_Log_Entry('END');

@unlink($_cron_lock);

$subj = $msg = hwLng('cron_subj').strftime($DATE_TIME_FMT, time());
$sep = '======================================================================';

if($A_CRON) foreach($A_CRON as $k=>$v){
  $msg .= "\n\n$sep\n";
  $msg .= "$k\n\n";
  foreach($v as $kk=>$vv){
    if(is_array($vv)){
      $msg .= "$kk\n";
      foreach($vv as $kkk=>$vvv){
        $msg .= "$kkk - $vvv\n";
      }
      $msg .= "\n";
    }
    else $msg .= "$kk - $vv\n\n";
  }
}
else $msg .= "\n\n";

$msg .= "$sep\nRegards,\n".COMPANY."\n".SITE_URL;

if(EN_M_CRON) hwSendMail(ADMIN_EMAIL,ADMIN_EMAIL,$subj,$msg);

if($_SERVER['REMOTE_ADDR'] && $_SERVER['REMOTE_ADDR']!='127.0.0.1') $msg = '<HTML><BODY><PRE>'.$msg.'</PRE></BODY></HTML>';
echo $msg;

function Cron_Log_Entry($s){
  $conn = is_object($GLOBALS['db']) ? $GLOBALS['db']->CONN : $GLOBALS['MYSQL_CONN']; // on shutdown
  mysql_query('INSERT INTO '.hwModTable('Cron_General','log').' (entry, added)'.
  ' VALUES ("'.mysql_real_escape_string($s,$conn).'", NOW())', $conn);
}

function Cron_Err_Exit($msg){
  Cron_Log_Entry($msg);
  die($msg);
}

// exec(PHP_BINDIR.'/php '.SITE_PATH.'path/script.php 2>&1',$ex_out,$ex_ret);
// if($ex_ret>0) Cron_Log_Entry('ERROR: '.$ex_out[0]);

?>
Return current item: Esvon Personals