Location: PHPKode > projects > Esvon Personals > esvon-personals/modules/Recommend_Us/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');

define('FR_NUM', 5); // Amount of the friends

function Recommend_Us_main(){
global $title, $MOD_CFG; // all globals here

  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;
  }

  if($_GET['id']) $title = hwLng('t_tf_link');
  elseif($_GET['cid']) $title = hwLng('t_tf_cat');
  else $title = hwLng('t_tf_site');

  if($_SERVER['REQUEST_METHOD']=='POST') ProcessForm();
  else ShowForm();

}

//functions section

function ShowForm() {
  global $err_msg,$title,$MOD_CFG;

  $tpl_v = array(
    'name' => '',
    'email' => '',
    'return' => '',
    'msg' => '',
  );
  for ($i=1;$i<=FR_NUM;$i++){
    $tpl_v["f_name$i"] = '';
    $tpl_v["f_email$i"] = '';
  }
  
  if($_SERVER['REQUEST_METHOD']=='GET') {
    $tpl_v['return'] = html_esc($_SERVER['HTTP_REFERER']);
    if(IsUser()) $tpl_v['email'] = hwSessionGetVar('email');
  }
  else{ 
    foreach(array_keys($tpl_v) as $k) $tpl_v[$k] = $_POST[$k] ? html_esc(strip_tags($_POST[$k])) : '';
    $tpl_v['msg'] = substr($tpl_v['msg'],0,$MOD_CFG['MAX_MSG_LEN']);
  }

  $tpl_v['EN_IMG_VER'] = $MOD_CFG['EN_IMG_VER'];
  $tpl_v += compact('err_msg','title');
  
  EvalAdvTpl(HW_MOD_TPL.'tf.htm', $tpl_v, 1);

}

function ProcessForm() {
  global $db,$err_msg,$MOD_CFG;
  
  $msg = html_esc($_POST['msg']);
  $email = html_esc($_POST['email']);
  $name = html_esc(strip_tags($_POST['name']));

  if($MOD_CFG['MAX_MSG_LEN'] > 0) $msg = substr($msg, 0, $MOD_CFG['MAX_MSG_LEN']);

  $err_msg = '';
  
  $a_friends = array();
  for($i=1;$i<=FR_NUM;$i++) {
      
    $f_v['name'] = html_esc(strip_tags($_POST["f_name$i"]));
    $f_v['email'] = html_esc($_POST["f_email$i"]);
    
    if($f_v['name'] || $f_v['email']){
      if(!$f_v['email'] || !IsEmail($f_v['email'])){ 
        $err_msg = sprintf(hwLng('fr_email_err'), $i);
        break;
      }
      $a_friends[] = $f_v;
    }
  }
 
  if(!$err_msg){
    if(!$name) $err_msg = hwErrMsgRequired(hwLng('name'));
    elseif(!$email) $err_msg = hwLng('req_email');
    elseif(!IsEmail($email)) $err_msg = hwLng('req_email');
    elseif(!count($a_friends)) $err_msg = hwErrMsgRequired(hwLng('fr_email'));
  }

  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){
    
    $tpl_v = compact('name','email','msg');

    $id = (int)$_GET['id'];
    $cid = (int)$_GET['cid'];
    if($id) {
      // tell about resource
      $tell_type = 'link';
      
      $v = $db->one_assoc('SELECT link_id,UNIX_TIMESTAMP(hw_added) AS fdate FROM '.TBL_AD.' WHERE link_id="'.$id.'"');
      if(!$v) exit;
      
      $tpl_v['id'] = $id;
      $tpl_v['hw_added'] = strftime($GLOBALS['DATE_FMT'],$v['fdate']);
      $tpl_v['ad_url'] = hwGetAdURL($v['link_id']);
      
    }
    elseif($cid) {
      // tell about category
      $tell_type = 'cat';
      
      $tpl_v['cid'] = $cid;
      $tpl_v['cat_path'] = GetCatPathCached($cid);
      $tpl_v['cat_url'] = hwGetBrowseURL($cid);
      hwProcessTags($tpl_v['cat_url']);
    }
    else {
      // tell about website
      $tell_type = 'site';
    }
    
    $tpl = new HawkTpl;
    $tpl->InitArray('row');

    $to_report = '';

    $a_emails = array($email);
    $email_body = EvalAdvTpl(HW_MOD_TPL.'tf_'.$tell_type.'.mail',$tpl_v);
    $tpl_v = array();
   
    foreach($a_friends AS $f_v) {

      $tpl_v['f_name'] = $f_v['name'];
      hwSendMail($f_v['email'], "$name <$email>",'', EvalBuffer($email_body, $tpl_v) );
      $a_emails[] = $f_v['email'];

      if($MOD_CFG['EN_M_TF']) $to_report .= $f_v['email'].' - '.$f_v['name'].', ';

      $tpl->AddCell('row', $f_v);
    }

    /*if(hwModGetState('Mailing_Lists')=='A' && file_exists(SITE_PATH.'modules/Mailing_Lists/hw_api.php')){
      include SITE_PATH.'modules/Mailing_Lists/hw_api.php';
      Mod_ML_Capture($a_emails);
    }*/

    if($MOD_CFG['EN_M_TF'] && $to_report){
      //notify admin until some anti-spam tech will be implemented
      $to_report = substr($to_report, 0, -2); 
      hwSendMail(ADMIN_EMAIL, "$name <$email>",'Tell a Friend',
      "To : $to_report\nIP: ##REMOTE_ADDR##\nComment:\n$msg");
    }
    
    $tpl_v = array(
      'return' => html_esc($_POST['return'])
    );
    
    $tpl->Parse(HW_MOD_TPL.'tf_ok.htm', $tpl_v, 1);
  }
  else ShowForm();

}

?>
Return current item: Esvon Personals