Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/pages/out.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/
//
// --------------------------------------------------------------------------

if(!defined('SITE_PATH') || !(int)$_GET['id']) die('Access Denied');

function ShowItemDetails(){

global $a_Ad,$a_User,$db,$FSET_DIR,$DATE_FMT,
$HW_WRAP;

$id = (int)$_GET['id'];
$cid = (int)$_GET['cid'];

if(!defined('ADMIN_AREA')){ // not in html.php ?

  if(isset($_GET['hw_next'])){
// Next: index.php?page=out&id=##id##&cid=##cid##&hw_next=1
    $hw_next = $_GET['hw_next'];
    $ql = 'SELECT link_id FROM '.TBL_AD.' WHERE 1'.hwFilterGetSQL();
    if($cid) $ql.=" AND catid='$cid'";

    if($hw_next==1){ //next
      $id = $db->one_data($ql." AND link_id>$id ORDER BY link_id ASC LIMIT 1");
      if(!$id) $id = $db->one_data($ql." ORDER BY link_id ASC LIMIT 1");
    }
    elseif($hw_next==-1){ //previous
      $id = $db->one_data($ql." AND link_id<$id ORDER BY link_id DESC LIMIT 1");
      if(!$id) $id = $db->one_data($ql." ORDER BY link_id DESC LIMIT 1");
    }
  }

  $preview = isset($_GET['preview']) ? $_GET['preview'] : '';
  if($preview!='yes' || !IsUser()){ 
    $preview = '';
    if(EN_U_VIEW_AD_DET){ 
      $no_auth = false;
      $cid = $db->one_data('SELECT catid FROM '.TBL_AD.' WHERE link_id='.$id);
      if($cid){
        if(defined('TBL_CAT_EXTRA')) $no_auth = $db->one_data('SELECT COUNT(*) FROM '.TBL_CAT_EXTRA.' WHERE cid="'.$cid.'" AND type="A"');
        if(!$no_auth) CheckLoggedIn();
      }
    }
    hwRealm('U_VIEW_AD_DET');
  }
  
  if(!IsBanned($id,HIT_UNBAN)){
    
    $db->query('UPDATE '.TBL_HITS.' SET hits=hits+1 WHERE lid='.$id);
    if($db->affected_rows() == 0){
      $db->query('INSERT INTO '.TBL_HITS.' (lid, hits) VALUES ('.$id.',1) ON DUPLICATE KEY UPDATE hits=hits+1'); // ON DUPLICATE is ok since 4.1
    }

    if($_SERVER['HTTP_REFERER'] && hwModGetState('Pay_Per_Click')=='A'){
      $ptrn = EN_SE_URLS ? '/\w+-b\d+_\d+-\w+\.html/' : '/page=search/';
      if(preg_match($ptrn, $_SERVER['HTTP_REFERER'])){
        include_once SITE_PATH.'modules/Pay_Per_Click/ppc.lib.php';
        Pay_Per_Click_process_click();
      }
    }
  } // is_banned

}
else $preview = '';

 $ses_uid = (int)hwSessionGetVar('userid');

 $ql = 'SELECT *,UNIX_TIMESTAMP(hw_added) AS fdate,UNIX_TIMESTAMP(hw_updated) AS fupdated,
 exp_date>='.SQL_NOW.' AS hw_live FROM '.TBL_AD.' WHERE link_id='.$id;
 if($preview) $ql.=" AND userid='$ses_uid'";
 //$ql.=hwFilterCatGetSQL('catid');

  $a_Ad = $db->one_assoc($ql);

  if(!$a_Ad){

/*
  SEO advice: try not to delete old pages (think about 
  expired/deleted pages data repository w/o contact info and images ??)
  header('HTTP/1.0 404 Not Found');
  header('Status: 404 Not Found');
  readfile(SITE_URL);
  exit;
*/

    EvalAdvTpl(TPL_PATH.'not_found.htm', '', 1);
    return;
  }

  // duplicate URLs protection
  if(EN_SE_URLS && !$_GET['print'] && !defined('HW_MOD') && !$preview) SE_VerifyValidURL(hwGetAdURL($id));

  $hw_owner = 0;
  if($ses_uid && $a_Ad['userid']==$ses_uid){ $hw_owner = 1; $preview = 'yes'; }

  if(!$preview && (!$a_Ad['approved'] || !$a_Ad['user_approved'] || (EN_EXP_DATE && (!$a_Ad['hw_live'] && !$_GET['hw_closed'])))){ // disabled link
    EvalAdvTpl(TPL_PATH.'not_approved.htm', '', 1);
    return;
  }

  $fs = hwGetFsByCat($a_Ad['catid']);
  $O_LFS = &Factory::singleton('FieldsSet', $fs);
  if($fs != $FSET_DIR) $FSET_DIR = $fs;
  
  $cid = $_GET['cid'] = $_REQUEST['cid'] = $a_Ad['catid'];

  // Meta Tags
  hwMetaTagsSetup( array('cid' => $cid) );

  $tpl_v = $O_LFS->FillCustomFieldsArray($a_Ad, true);
  $O_LFS->AdjustCustomFields($tpl_v);

  $tpl_v['cat_path'] = GetCatPathCached($cid,1);
  /*if($a_Ad['hw_region_id'] && hwModGetState('Regions')){
    $reg_name = $db->one_data('SELECT name FROM '.hwModTable('Regions','category').' WHERE id='.$a_Ad['hw_region_id']);
    if($reg_name){
      $tpl_v['cat_path'] = preg_replace('/"[^"]+">([^<]+)<\/a>$/i',
        '"index.php?page=search&s_res=AND&hw_region_id='.$a_Ad['hw_region_id'].'&cid='.$cid.'">\\1 in '.$reg_name.'</a>',$tpl_v['cat_path']);
    }
  }*/

  //$tpl_v['hw_region_id'] = (int)$a_Ad['hw_region_id'];
  $tpl_v['hw_added'] = strftime($DATE_FMT,$a_Ad['fdate']);
  $tpl_v['hw_updated'] = strftime($DATE_FMT,$a_Ad['fupdated']);
  $tpl_v['hits'] = (int)$db->one_data('SELECT hits FROM '.TBL_HITS.' WHERE lid='.$id);

  if($a_Ad['images']){ 
    $images = explode("\n",$a_Ad['images']);
    $tpl_v['images_num'] = count($images);
    $tpl_v['images'] = $images[0];
    unset($images);
  }
  else{
    $tpl_v['images_num'] = 0;
    $tpl_v['images'] = '';
  }
  
  $tpl_v['posted_num'] = 0;
  if($a_Ad['userid']>0){
    $tpl_v['posted_num'] = $db->one_data('SELECT count(*) FROM '.TBL_AD.' WHERE userid="'.$a_Ad['userid'].'"');
  }

  $CFG = hwGetFSConfig();

  $A_MEDIA_OBJ = &Factory::getMediaObj('ALL');
  if($A_MEDIA_OBJ) foreach(array_keys($A_MEDIA_OBJ) as $media_id){
    $Media_Obj = &$A_MEDIA_OBJ[$media_id];
    $Media_Obj->SetDBKeyVal($id);
    // if($media_id=='images') $Media_Obj->SetFileFirst(1);
    $Media_Obj->SHOW_AMOUNT = $CFG['THUMB_MAX'];
    $tpl_v["media_files_$media_id"] = $Media_Obj->GetMediaArea(GetFSetFileName('media_files.htm'),1,$CFG['THUMB_PER_ROW'],1);
/*    if($media_id=='images'){
      $a_m = explode("\n",$Media_Obj->GetFileVal());
      for($i=0;$i<10;$i++) $tpl_v['image_'.($i+1)] = isset($a_m[$i]) ? $a_m[$i] : '';
    }*/
  }
  unset($A_MEDIA_OBJ);

  $tpl_v += compact('hw_owner','id','cid');
  
  $tpl_v['CURR_SIGN'] = CURR_SIGN;
  $tpl_v['ad_url'] = hwGetAdURL($id);
  $tpl_v['hw_pay_plan'] = array_shift(hwGetBasePlanFromStr($a_Ad['hw_pay_plan']));

  if(hwModGetState('Private_Messages')=='A') 
    $tpl_v['ad_reply_url'] = 'modules.php?mod=Private_Messages&lid='.$id.'&to_id='.$a_Ad['userid'].'&pm_new=Y';
  else $tpl_v['ad_reply_url'] = 'modules.php?mod=Form_to_Email&id='.$id;
	
  $A_EXTRA = array('userid','hw_feat','hw_sold','hw_vis','hw_color','hw_live');
//  $A_EXTRA_U = array();
  
  foreach($A_EXTRA as $v) $tpl_v[$v] = $a_Ad[$v];

  if(EN_UF){
    $O_UFS = &Factory::singleton('FieldsSet', '{user_fields}');
    $a_User = $db->one_assoc('SELECT * FROM '.TBL_USER." WHERE id='$a_Ad[userid]'");
    //foreach($A_EXTRA_U as $k) $tpl_v[$k] = $a_User[$k];
    $_tpl_v = $O_UFS->FillCustomFieldsArray($a_User, true);
    $O_UFS->AdjustCustomFields($_tpl_v);
    $tpl_v += $_tpl_v;
    unset($_tpl_v);
  }

  // alternative details page
  /*
  $tpl_f = '';
  $fn = $_GET['f'];
  if($fn && is_string($fn) && !preg_match('/\W/', $fn)){
    $tpl_f = GetFSetFileName($fn.'.htm');
    if(!file_exists($tpl_f)) $tpl_f = '';
  }
  
  if(!$tpl_f) */
  $tpl_f = GetFSetFileName('details.htm');

  // Custom cells or template file handling
  global $HW_TPL;
  if(!isset($_REQUEST['HW_TPL']) && is_array($HW_TPL) && !empty($HW_TPL)){

    if(is_array($HW_TPL['VARS'])) $tpl_v += $HW_TPL['VARS'];

    if($HW_TPL['TPL_F'] && strpos($HW_TPL['TPL_F'], '..')===false){ 
      $tpl_f_prev = $tpl_f;
      $tpl_f = GetFSetFileName($HW_TPL['TPL_F']);
      if(!file_exists($tpl_f)) $tpl_f = $tpl_f_prev;
    }
  }

  $tpl = new HawkTpl;

  if(isset($_GET['print'])){ // || $_GET['field']

    $tpl_v['media_files'] = preg_replace('/<a.*?>(.*?)<\/a>/i','\\1',$tpl_v['media_files']);

    /*$tpl_f = '';
    if(is_numeric($_GET['print'])) $tpl_f = GetFSetFileName('details_print_'.(int)$_GET['print'].'.htm');
    if(!$tpl_f || !file_exists($tpl_f)) */
    $tpl_f = GetFSetFileName('details_print.htm');

    $tpl->ReadBuf($tpl_f);
    hwProcessBlocks($tpl,'','Ad_Details');
    // $tpl_v['f_field'] = $tpl_v[$_GET['field']];
    $tpl->Parse(NULL,$tpl_v,1);
    $HW_WRAP = 0;
    return;
  }
  
  $tpl->ReadBuf($tpl_f);
  hwProcessBlocks($tpl,'','Ad_Details');
  $tpl->Parse(NULL,$tpl_v,1);

  /*
  global $HW_LANG;
  $a_v = hwSessionGetVar('b_RVA');
  if(!is_array($a_v)) $a_v = array();
  if(!array_key_exists($HW_LANG, $a_v)) $a_v[$HW_LANG] = array();

  if(!in_array($id, $a_v[$HW_LANG])){
    array_unshift($a_v[$HW_LANG], $id);
    hwSessionSetVar('b_RVA',$a_v);
    print_r($a_v);
  }
  */

}

// main
ShowItemDetails();

//$o_pg = &Factory::singleton('esPage');
//$o_pg->setHeader( preg_replace('/<title>.*?<\/title>/is','<title>##title##</title>', $o_pg->getHeader()) );

?>
Return current item: Esvon Personals