Location: PHPKode > projects > Esvon Personals > esvon-personals/modules/Reviews/hw_user.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')) die('Access denied');
if(!function_exists('hwModVer') || !hwModVer(12)) die('This module is incompatible with '.EC_TITLE.' '.EC_VERSION);

//define('REV_IMAGES_MAX', 0);
define('TBL_REVIEWS',hwModTable(HW_MOD,'data'));

// functions

function Reviews_main(){
  if($_GET['rid']) Reviews_ShowDetails($_GET['rid']);
  elseif($_GET['by_id']) Reviews_ShowList($_GET['by_id']);
  else Reviews_ShowForm();
}

function Reviews_ShowList($lid){
  global $db,$TITLE_FIELD,$a_Ad;
  $lid = (int)$lid;
  $z = array();
  $z['id'] = $lid;
  $z['f_title'] = $db->one_data('SELECT '.$TITLE_FIELD.' FROM '.TBL_AD.' WHERE link_id='.$lid);
  $z['item_url'] = hwGetAdURL($lid);
  $buf = EvalAdvTpl(HW_MOD_TPL.'list.htm', $z);
  $a_Ad['link_id'] = $lid;
  hwProcessBlocks($buf,'','Ad_Details');
  echo $buf;
}


function Reviews_ShowDetails($rid){
global $db,$TITLE_FIELD,$DATE_FMT;
  
  $rid = (int)$rid;
  $z = $db->one_assoc('SELECT *, UNIX_TIMESTAMP(date) AS rev_date FROM '.
    TBL_REVIEWS.' WHERE id='.$rid.' AND approved="1"');
  
  if(!$z) exit;
  
  $z['rev_date'] = strftime($DATE_FMT, $z['rev_date']);
  $z['f_title'] = $db->one_data('SELECT '.$TITLE_FIELD.' FROM '.TBL_AD.' WHERE link_id='.$z['link_id']);
  $z['item_url'] = hwGetAdURL($z['link_id']);

  $z['media_files_upload'] = '';
  /*if($z['images']){
    $Img_Obj = &Factory::create('Media_Image');
    $Img_Obj->DB_TABLE = TBL_REVIEWS;
    $Img_Obj->DB_KEY_NAME = 'id';
    $Img_Obj->SetDBKeyVal($rid);
    $Img_Obj->SHOW_AMOUNT = 0; // all
    $THUMB_PER_ROW = 2;
    $z['media_files_upload'] = $Img_Obj->GetMediaArea(HW_MOD_TPL.'media_files.htm',1,$THUMB_PER_ROW,1);
  }*/

  EvalAdvTpl(HW_MOD_TPL.'details.htm', $z, 1);
}

function Reviews_ShowForm(){
global $db,$MOD_CFG;

  if($MOD_CFG['EN_AUTH']) CheckLoggedIn();

  if(!GD_VER) $MOD_CFG['EN_IMG_VER'] = 0;

  if($_GET['mode']=='image'){
    if($MOD_CFG['EN_IMG_VER']) {
      $o_iv =& Factory::create('Image_Verify');
      $o_iv->DisplayImage();
    }
    exit;
  }

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

  $Img_Obj = false;
  /*if(REV_IMAGES_MAX > 0){
    $Img_Obj = &Factory::create('Media_Image');
    $Img_Obj->DB_TABLE = TBL_REVIEWS;
    $Img_Obj->DB_KEY_NAME = 'id';
    $Img_Obj->ID_NAMING_PFX = 'rev_';
    $Img_Obj->MAX = $Img_Obj->UPLOAD_NUM = REV_IMAGES_MAX;
    //THUMB_W, THUMB_H
  }*/

  $err_msg = '';

  $tpl_v = array(
    'id' => '',
    'name' => '',
    'email' => '',
    'comments' => '',
    'foundus' => '',
    'url' => '',
    'caption' => '',
  );

  if($_POST['go']) {

    foreach(array_keys($tpl_v) as $k) $tpl_v[$k] = trim(strip_tags($_POST[$k]));
    
    $id = (int)$_POST['id'];

    if(!$id) $err_msg = hwErrMsgRequired(hwLng('ID'));
    elseif(!$tpl_v['email'] || !IsEmail($tpl_v['email'])) $err_msg = hwLng('req_email');
    elseif(!$tpl_v['comments']) $err_msg = hwLng('req_comments');

    if(!$err_msg){
      $tpl_v['cid'] = $db->one_data('SELECT catid from '.TBL_AD.' where link_id='.$id);
      if(!$tpl_v['cid']) $err_msg = hwLng('err_no_ad');
    }

    if(!$err_msg && $MOD_CFG['EN_IMG_VER']){
      $o_iv =& Factory::create('Image_Verify');
      if(!$o_iv->IsTextOK($_POST['img_text'])) $err_msg = hwLng('err_img_code');
    }

    if(!$err_msg && $Img_Obj) $err_msg = $Img_Obj->Validate();

    if(!$err_msg){

     $tpl_v['comments'] = str_replace("\r",'', $tpl_v['comments']);

     $db->query('INSERT INTO '.TBL_REVIEWS." (link_id,writer_id,username,email,caption,review,date,approved,ip)
       VALUES ($id,".(int)hwSessionGetVar('userid').",?,?,?,?,".SQL_NOW.",'".($MOD_CFG['EN_APR_REQ'] ? 0 : 1)."',?)",
       array($tpl_v['name'], $tpl_v['email'], $tpl_v['caption'], $tpl_v['comments'], hwGetUserHostIP(true)) );

     $rev_id = $db->insert_id();

     if($Img_Obj){ 
       $Img_Obj->SetDBKeyVal($rev_id);
       $Img_Obj->ModifyData();
     }

     $email_body = EvalAdvTpl(HW_MOD_TPL.'feedback.mail', $tpl_v);
     hwSendMail(ADMIN_EMAIL,$tpl_v['email'],'',$email_body);

     EvalAdvTpl(HW_MOD_TPL.'feedback_ok.htm', $tpl_v, 1);
     return;

   }
   else{
     foreach(array_keys($tpl_v) as $k) $tpl_v[$k] = html_esc($tpl_v[$k]);
   }

  } //end POST
  else{
    if($ses_uid) $tpl_v['email'] = hwSessionGetVar('email');
    $tpl_v['id'] = (int)$_GET['id'];
  }

  $tpl_v['SES_UID'] = $ses_uid;
  $tpl_v['EN_IMG_VER'] = $MOD_CFG['EN_IMG_VER'];
  $tpl_v['err_msg'] = $err_msg;

  if($Img_Obj){
    $tpl_v['enc_type'] = 'ENCTYPE="multipart/form-data"';
    $tpl_v['media_files_upload'] = $Img_Obj->GetMediaArea(HW_MOD_TPL.'media_files_upload.htm', 0, 0, 0, 1);
  }
  else $tpl_v['media_files_upload'] = $tpl_v['enc_type'] = '';

  EvalAdvTpl(HW_MOD_TPL.'feedback.htm', $tpl_v, 1);

}

?>
Return current item: Esvon Personals