<?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($_POST['go']) ProcessForm();
else ShowForm();
// sub area
function ShowForm() {
global $db;
if(!$_REQUEST['mlist_id']) $_REQUEST['mlist_id'] = -1;
$mlist_id = (int)$_REQUEST['mlist_id'];
if($_SERVER['REQUEST_METHOD']=='GET'){
$subject = $content = $is_html = '';
if($_GET['likeid']) list($subject,$content,$is_html) = $db->one_row('SELECT subj,content,is_html FROM '.TBL_ML_LOG.' WHERE id='.(int)$_GET['likeid']);
else{
$bottom_text = $db->one_data('SELECT bottom_text FROM '.TBL_ML_IDX.' WHERE id="'.$mlist_id.'"');
if($bottom_text) $content = "\n\n\n".$bottom_text;
}
}
else{
$subject = html_esc($_POST['subject']);
$is_html = (int)$_POST['is_html'];
$content = $_POST['content'];
}
$tpl_v = compact('subject','content');
$tpl_v['is_html'] = $is_html ? 'checked' : '';
$tpl_v['mlist'] = get_mail_lists(0,'OnChange="document.location=\''.HW_MOD_URL.'&file=ml_send&mlist_id=\'+document.frm.mlist_id.options[document.frm.mlist_id.selectedIndex].value"');
if($mlist_id>0) $ql = 'SELECT COUNT(*) FROM '.TBL_ML.' WHERE list_id="'.$mlist_id.'"';
elseif($mlist_id < 0){
$ql = ML_getEmailsAmountSQL($mlist_id);
if($_SERVER['REQUEST_METHOD']=='POST') $ql.=ML_PostGetUserSQL(); // adjust total calc
}
$tpl_v['sub_amt'] = $db->one_data($ql);
$tpl_v['s_date'] = GetDateSelects('s');
$tpl = new HawkTpl;
$tpl->InitArray('preview,filter');
if($_POST['preview']){
$z = array();
$z['c_preview'] = $is_html ? $content : str_replace("\n",'<br>', html_esc($content) );
$tpl->AddCell('preview',$z);
}
$tpl_v['is_member'] = $mlist_id < 0 ? 1 : 0;
if($tpl_v['is_member']){
$z = array();
$O_UFS = &Factory::singleton('FieldsSet', '{user_fields}');
$O_UFS->rewind();
while($o_f = &$O_UFS->next()){
if(strpos('|menu|select|checkbox|', '|'.$o_f->TYPE.'|')===false) continue;
$o_f->VALUE = isset($_POST[$o_f->ID]) ? $_POST[$o_f->ID] : '';
$z['f_t'] = $o_f->TITLE;
$z['f_v'] = $o_f->GetInputCtrl();
if($o_f->TYPE=='checkbox') $z['f_v'] = str_replace('>',' onClick="javascript:document.frm.submit()"',$z['f_v']);
else $z['f_v'] = preg_replace('/<select/i','<select onChange="Go()"',$z['f_v']);
$tpl->AddCell('filter',$z);
}
$tpl_v['pp_sel'] = '';
$res = $db->query('SELECT id,name FROM '.TBL_PAY_PLAN.' WHERE type="SUB" ORDER BY name');
while($v = mysql_fetch_assoc($res)){
$tpl_v['pp_sel'].='<OPTION '.($v['id']==$_POST['hw_pay_plan']?'SELECTED ':'').'VALUE="'.$v['id'].'">'.$v['id'].' - '.$v['name'];
}
}
$tpl->Parse(HW_MOD_TPL.'ml_send.htm', $tpl_v, 1);
}
function ML_PostGetUserSQL(){
global $db;
$sql = '';
$O_UFS = &Factory::singleton('FieldsSet', '{user_fields}');
$O_UFS->rewind();
while($o_f = &$O_UFS->next()){
if(strpos('|menu|select|checkbox|', '|'.$o_f->TYPE.'|')===false) continue;
if($_POST[$o_f->ID]) $sql.= " AND u.$o_f->DB_F='".$db->quote($_POST[$o_f->ID])."'";
}
if($_POST['hw_pay_plan']) $sql.= " AND u.hw_pay_plan LIKE '[".$db->quote($_POST['hw_pay_plan'])."-%'";
return $sql;
}
function ProcessForm() {
global $db;
$is_html = (int)$_POST['is_html'];
$mlist_id = (int)$_POST['mlist_id'];
$_POST['content'] = str_replace("\r",'',$_POST['content']);
$sql = $mlist_id < 0 ? ML_PostGetUserSQL() : '';
if($is_html && !preg_match('/<html/i',$content)) $content = '<html>'.$content.'</html>';
$db->query('INSERT INTO '.TBL_ML_LOG.' (list_id,date,is_html,subj,content,amount,extra)'.
" VALUES('$mlist_id',?,'$is_html',?,?,0,?)",
array($_POST['year_s'].'-'.$_POST['month_s'].'-'.$_POST['day_s'], $_POST['subject'], $_POST['content'], $sql )
);
header('Location: '.HW_MOD_URL.'&file=ml_log');
exit;
}
function GetDateSelects($np=''){
if(!$_POST["day_$np"])
list($_POST["day_$np"],$_POST["month_$np"],$_POST["year_$np"]) = explode('/',date('d/m/Y'));
$s="<select name=day_$np>";
for($i=1;$i<=31;$i++)
$s.='<option '.($i==$_POST["day_$np"]?'SELECTED':'')." value=$i>".($i<10?'0':'').$i;
$s.='</select>';
$s.="<select name=month_$np>";
for($i=1;$i<=12;$i++)
$s.='<option '.($i==$_POST["month_$np"]?'SELECTED':'')." value=$i>".($i<10?'0':'').$i;
$s.='</select>';
$s.="<select name=year_$np>";
$y1 = date('Y');
$y2 = $y1+5;
for($i=$y1;$i<$y2;$i++)
$s.='<option '.($i==$_POST["year_$np"]?'SELECTED':'')." value=$i>$i";
$s.='</select>';
return $s;
}
?>