Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-04-2012, 03:40 PM   PM User | #1
Jade78
New to the CF scene

 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Jade78 is an unknown quantity at this point
Disable members sending messaging if they are not in their search age group

Hi, I am a new member

I run a dating script that uses php, .tpl (Smarty Templates). I need to start to learn php to modify the script. The first thing I would like to do:

Currently Member A can set their search match preferences to the age group they are looking for ie 18-25 works fine.

Problem: Member B can message Member A, even if Member B is NOT in the age group that Member A is looking for in their search preferences.

Need: I need to stop Member B messaging Member A if Member B is not in the "search age group" that Member A is looking for.

I think this may be set in compose. tpl and compose.php. This already checks for blocked members I think.

Compose.php:
PHP Code:
<?php
if ( !defined'SMARTY_DIR' ) ) { include_once( 'init.php' ); } $returnto 'compose.php'; include ( 'sessioninc.php' );
if (
$_SESSION['UserId'] <= 0) { header('location: index.php?page=login'); exit; } $reply '';
if (isset(
$_SERVER["QUERY_STRING"]) ) { $reply preg_match("/reply/"$_SERVER["QUERY_STRING"]); }
if (
$reply == '0' and isset($_SESSION['security']['message']) && $_SESSION['security']['message'] !== '1') { header('location: index.php?page=login'); exit; }
if ((isset(
$_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] == '') || !isset($_SERVER["QUERY_STRING"])) { header('location: index.php?page=login'); exit; }
if( isset( 
$_POST['frm'] ) ) {
if ( 
$_POST['frm'] == 'frmTemplate' ) {
// templated message
// fetch the template message
$msgdata $osDB->getRow('SELECT subject, text FROM ! WHERE id = ?', array(USERTEMPLATE_TABLE$_POST['templateid']) ); $_POST['txtmessage'] = $msgdata['text'];
$_POST['txtsubject'] = $msgdata['subject'];
// make appropriate substitutions
$row $osDB->getRow'select username, firstname, email, country, state_province, county, city, floor((to_days(curdate())-to_days(birth_date))/365.25)  as age from ! where id = ?', array( USER_TABLE$_POST['txtrecipient'] ) );
// current template variables:
// [username], [firstname], [city], [state], [country], [age]
// you can add more template variables by simply adding to this array
$row['statename'] = getStateName$row['country'], $row['state_province'] ); $row['countryname'] = getCountryName($row['country'] ) ; $row['city'] = getCityName($row['country'], $row['state_province'], $row['city'], $row['county']); $sub = array( '[username]'     => $row['username'], '[firstname]' => $row['firstname'], '[city]' => $row['city'], '[state]' => $row['statename'], '[country]' => $row['countryname'], '[age]'    => $row['age'], ); foreach( $sub as $key => $val ) { $_POST['txtmessage'] = str_replace$key$val$_POST['txtmessage'] ); $_POST['txtsubject'] = str_replace$key$val$_POST['txtsubject'] ); } } $_POST['txtmessage'] = strip_tags($_POST['txtmessage']);
// this is frm = frmCompose
$msgs_for_today 0;
/* Check the count of messages sent for today... */
$msgs_for_today $osDB->getOne('select act_cnt from ! where userid = ? and act_type = ? and act_date = ?',array(USER_ACTIONS$_SESSION['UserId'], 'M' date('Ymd')));
if (!
$msgs_for_today$msgs_for_today 0$allowed_count = ($_SESSION['security']['message_keep_cnt'] > 0)? $_SESSION['security']['message_keep_cnt'] : $config['message_count']; $total_msgs_count $osDB->getOne('select count(*) from ! where owner = ?', array(MAILBOX_TABLE$_SESSION['UserId']));
if (!isset(
$_SESSION['security']['messages_per_day'])) $_SESSION['security']['messages_per_day'] = 0;
if (
$msgs_for_today $_SESSION['security']['messages_per_day'] && !isset($_REQUEST['reply'])) { $t->assign('errormsg',  get_lang('errormsgs',122)); } elseif ($allowed_count <= $total_msgs_count) { $t->assign('errormsg'get_lang('errormsgs'131)); } else {
if ( isset( 
$_SESSION['UserId'] ) && $_SESSION['UserId'] != '' ) {
// check if profile should be included //
if ($_POST["chkinclude"] == "1") {
// get information //
$dataSections $osDB->getAll'SELECT * FROM ! WHERE enabled = ? ORDER BY displayorder', array( SECTIONS_TABLE'Y'  ) ); $found false;
foreach( 
$dataSections as $section ){ $prefs = array(); $rsPref $osDB->getAll'SELECT DISTINCT q.id, q.question, q.extsearchhead, q.control_type as type FROM ! pref INNER JOIN ! q ON pref.questionid = q.id WHERE pref.userid = ? AND q.section = ? ORDER BY q.id ', array( USER_PREFERENCE_TABLEQUESTIONS_TABLE$_SESSION["UserId"], $section['id'] ) ); foreach( $rsPref as $row ){
if (
$row['type'] != 'textarea') {
$rsOptions $osDB->getAll'SELECT pref.answer as answer, opt.answer as anstxt from ! pref left join ! opt on pref.questionid = opt.questionid and opt.id = pref.answer where pref.userid = ? and opt.questionid = ? order by opt.questionid, opt.displayorder', array( USER_PREFERENCE_TABLEOPTIONS_TABLE$_SESSION["UserId"], $row['id'] ) ); } else { $rsOptions $osDB->getAll'select pref.answer as answer, pref.answer as anstxt from ! pref where pref.userid = ? and pref.questionid = ?', array( USER_PREFERENCE_TABLE$_SESSION["UserId"], $row['id'] ) ); } $opts = array(); foreach( $rsOptions as $key=>$opt ){ $opts[] = $opt['anstxt']; }
unset(
$rsOptions);
if (
count($opts)>0) { $optsPhr implode', '$opts); } else { $optsPhr ""; } $row['options'] = $optsPhr$prefs[] = $row$found true; } unset($rsPref);
if( 
count($prefs) > ){
$pref[] = array( 'SectionName' => $section['section'], 'preferences' => $prefs ); } } unset($dataSections$prefs);
// add to message //
if ( isset($pref) && is_array$pref ) ) { foreach ($pref as $item) { $_POST['txtmessage'] .= "<br />" "<br />" stripslashes$item['SectionName'] ) . "<br />";
$_POST['txtmessage'] .= "-----------------"; foreach ($item['preferences'] as $item2) {
if (
strlen($item2['options']) > 0) { $_POST['txtmessage'] .= "<br />" "<br />" stripslashes$item2['extsearchhead'] ). "<br />"$_POST['txtmessage'] .= "- " stripslashes$item2['options'] ); } } } } } $time001 time(); $osDB->query'INSERT INTO ! (owner, senderid, recipientid, subject, message, sendtime, folder, notifysender) values(?, ?, ?, ?, ?, ?, ?, ?)', array( MAILBOX_TABLE$_POST['txtrecipient'], $_SESSION['UserId'], $_POST['txtrecipient'], stripEmails(strip_tags($_POST['txtsubject'])), stripEmails($_POST['txtmessage']), $time001'inbox', ($_POST["chknotify"] - 0) ) );
/* MOD END */
$osDB->query'INSERT INTO ! (owner, senderid, recipientid, subject, message, sendtime, folder) values(?, ?, ?, ?, ?, ?, ?)', array( MAILBOX_TABLE$_SESSION['UserId'], $_SESSION['UserId'], $_POST['txtrecipient'], stripEmails(strip_tags($_POST['txtsubject'])), stripEmails($_POST['txtmessage']), $time001'sent' ) ); $recipient_choice $osDB->getOne('select choice_value from ! where userid=? and choice_name=?', array(USER_CHOICES_TABLE$_POST['txtrecipient'], 'email_message_received') );
if (
$recipient_choice == '1' or $recipient_choice == '' or !isset($recipient_choice) ) {
if (
$config['letter_messagereceived'] == 'Y' && ($config['nomail_for_onlineuser'] == 'Y' or ($config['nomail_for_onlineuser'] == 'Y' && !getOnlineStats($_POST['txtrecipient']) )) ) {
/* Send email about the received message to the receiver */
$row $osDB->getRow'select *, floor((to_days(curdate())-to_days(birth_date))/365.25)  as age from ! where id = ?', array( USER_TABLE$_POST['txtrecipient'] ) );
$sendername $osDB->getOne('select username from ! where id = ?', array(USER_TABLE$_SESSION['UserId']) ); $Subject get_lang('message_received_sub'); $From$config['admin_email']; $To $row['email']; $t->assign('item'$osDB->getRow('select *, floor((to_days(curdate())-to_days(birth_date))/365.25)  as age from ! where id = ?', array( USER_TABLE$_SESSION['UserId']) ) ); $message get_lang('message_received'MAIL_FORMAT); $message str_replace('#From#'get_lang('FROM1'), $message); $message str_replace('#TO#'get_lang('To1'), $message); $message str_replace('#FirstName#'$row['firstname'] ,$message); $message str_replace('#SenderName#'$sendername$message); $message str_replace('#UserName#'$row['username'], $message); $message str_replace('#Date#'get_lang('col_head_date'), $message);
$message str_replace('#MESSAGE_DATE#'date(get_lang('DISPLAY_DATETIME_FORMAT'),time()), $message); $message str_replace('#Subject#'get_lang('col_head_subject'), $message); $message str_replace('#MSG_SUBJECT#'stripEmails(strip_tags($_POST['txtsubject'])), $message);
if (
MAIL_FORMAT == 'html') { $message str_replace('#smallProfile#',  $t->fetch('profile_for_html_mail.tpl'), $message); } mailSender($From$To$row['email'], $Subject$message); unset($message$Subject); } }
if (
$msgs_for_today 0) {
$osDB->query('update ! set act_cnt=act_cnt+1 where userid=? and act_type=? and act_date = ?', array(USER_ACTIONS,$_SESSION['UserId'], 'M'date('Ymd')));
} else { 
$osDB->query('insert into ! (userid, act_type, act_date, act_cnt) values     (?,?,?,?)', array(USER_ACTIONS$_SESSION['UserId'], 'M'date('Ymd'), 1)); }
if (isset(
$_REQUEST['reply']) && $_REQUEST['reply'] == '2') {
/* update replied flag */
$osDB->query('update ! set replied=? where id=?', array(MAILBOX_TABLE1$_REQUEST['msgid']) );
header("location:mailmessages.php?folder=".$_REQUEST['folder']."&selflag=".$_REQUEST['selflag']."&sort=".$_REQUEST['sort']."&type=".$_REQUEST['type']."&replied=1"); exit; } } $t->assign'msg_sent'true ); } } $recipient = (isset($_REQUEST['txtrecipient'])?$_REQUEST['txtrecipient']:(isset($_REQUEST['recipient'])?$_REQUEST['recipient']:'-1') ) ; $t->assign'templates',$osDB->getAll'SELECT id, text FROM ! WHERE userid = ?', array( USERTEMPLATE_TABLE$_SESSION['UserId'] ) ) );
$t->assign'user',$osDB->getRow'SELECT username, firstname, lastname FROM ! WHERE id = ?', array( USER_TABLE$recipient) ) );
$isBanned $osDB->getOne('select count(*) from ! where act=? and ( (userid = ? and ref_userid = ?) or (userid=? and ref_userid = ?) )', array(BUDDY_BAN_TABLE'B'$_SESSION['UserId'], $recipient$recipient$_SESSION['UserId'] ) );  
if (
$isBanned == 0) {
if (isset(
$_REQUEST['reply']) && $_REQUEST['reply'] == '1') {
/* Reply for a message */
if ($_SESSION['security']['message']=='1' || $config['allow_reply_by_all'] == 'Y' || $config['allow_reply_by_all'] == '1' ) { $msg $osDB->getRow('select * from ! where id = ?', array(MAILBOX_TABLE$_REQUEST['msgid'] ) );
if (
substr($msg['subject'],0,3) != 'Re:') { $msg['subject'] = 'Re: '.$msg['subject']; }
if (
strpos($msg['message'],'__________________________') >= ) { $msg['message'] = str_replace('__________________________','__________________________',$msg['message']); }
$msg['message'] = chr(13).chr(13).chr(13).'__________________________'.chr(13).str_replace('<br>',chr(13),$msg['message']).chr(13).''.chr(13);
$t->assign('msg'$msg); } } elseif (isset($_REQUEST['reply'])&& $_REQUEST['reply'] == '11') {
/* Reply  "No Thanks" */
$msg['subject'] = get_lang('no_thanks_subject'); $message =  get_lang('no_thanks_message'MAIL_FORMAT); $message str_replace('#site_name#'$config['site_name'], $message);
if (!isset(
$_REQUEST['refuname'])) {
$_REQUEST['refuname'] = $osDB->getOne('select username from ! where id = ?',array(USER_TABLE$recipient)); } $message str_replace('#recipient_username#'$_REQUEST['refuname'], $message); $message str_replace('#sender_username#'$_SESSION['UserName'], $message); $msg['message'] = str_replace('<br>',chr(10),$message);
unset(
$message); $t->assign('msg'$msg); $_REQUEST['level'] = '1'; } unset($msg); } else { $t->assign('isbanned',  $isBanned); $t->assign('errormsg',  get_lang('in_ban_list')); } $t->assign('lang',$lang);
if ( isset(
$config['use_profilepopups']) && $config['use_profilepopups'] == 'Y' ) { $t->display('compose.tpl'); } else { $t->assign('rendered_page'$t->fetch('compose.tpl') ); $t->display 'index.tpl' ); }
?>

Compose.tpl:
Code:
{if $config.use_profilepopups == 'Y'}
<?xml version="1.0" encoding="{lang mkey='ENCODING}'"?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>{$page_title}</title>
	<script type="text/javascript">
	/* <![CDATA[ */
	{if $config.use_popups == 'N'}
		var use_popups = false;
	{else}
		var use_popups = true;
	{/if}
	{if $config.use_profilepopups == 'N'}
		var use_profilepopups = false;
	{else}
		var use_profilepopups = true;
	{/if}
	/* ]]> */
	</script>

	<link href="{$css_path}default.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="javascript/functions.js"></script>
	<script type="text/javascript" src="javascript/validate.js"></script>
	<meta http-equiv="Content-Type" content="text/html; charset={lang mkey='ENCODING'}" />
	</head>
	<body   dir="{lang mkey='DIRECTION'}" >
{/if}

{strip}

<!-- MOD START -->

<script type="text/javascript">
/* <![CDATA[ */
function checkMe(form)
{ldelim}

var radio_choice = false;

for (counter = 0; counter < form.templateid.length; counter++)
{ldelim}

	if (form.templateid[counter].checked)
	{ldelim}
		radio_choice = true;
	{rdelim}

{rdelim}

if ( form.templateid.checked == true ) {ldelim}
	radio_choice = true;
{rdelim}

if ( radio_choice == false )
{ldelim}
	alert("{lang mkey='template_select'}");
	return false;
{rdelim}

return true;

{rdelim}

function updateExtras()
{ldelim}

	if (document.frmExtras.chknotify.checked == true)
	{ldelim}

		document.frmCompose.chknotify.value = 1;
		document.frmTemplate.chknotify.value = 1;

	{rdelim} else {ldelim}

		document.frmCompose.chknotify.value = 0;
		document.frmTemplate.chknotify.value = 0;

	{rdelim}

	if (document.frmExtras.chkinclude.checked == true)
	{ldelim}

		document.frmCompose.chkinclude.value = 1;
		document.frmTemplate.chkinclude.value = 1;

	{rdelim} else {ldelim}

		document.frmCompose.chkinclude.value = 0;
		document.frmTemplate.chkinclude.value = 0;

	{rdelim}

{rdelim}

function validate(form)
{ldelim}
	ErrorCount=0;
	ErrorMsg = new Array();
	ErrorMsg[0] = "" + String.fromCharCode(13);

	CheckFieldString("noblank",form.txtsubject,"{lang mkey='signup_js_errors' skey='subject_noblank'}");
	CheckFieldString("noblank",form.txtmessage,"{lang mkey='signup_js_errors' skey='comments_noblank'}");
	{if $config.spam_code_length > 0}
		CheckFieldString("noblank",form.spam_code,"{lang mkey='errormsgs' skey='120'}");
	{/if}
	result="";
	if( ErrorCount > 0)
	{ldelim}
		alert(ErrorMsg[1]);
		return false;
	{rdelim}
	return true;
{rdelim}

/* ]]> */
</script>

<div style="vertical-align:top;" >
	{assign var="page_hdr01_text" value="{lang mkey='writing_message'} "|cat:$user.username}
	{assign var="page_title" value=$page_hdr01_text}
	{include file="page_hdr01.tpl"}
	<div class="module_detail_inside">
	{if $msg_sent == '1'}
		{assign var="error_message" value=" {lang mkey='msg_sent'}" }
		{include file="display_error.tpl"}
	{else}
		<div class="line_outer">
			<form name="frmExtras" action="" >
			<table width="80%"   cellpadding="{$config.cellpadding}" cellspacing="{$config.cellspacing}" 

border="0">

				{if $errormsg != ''}
				<tr><td width="70%"><font color="#FF0000">{$errormsg}</font></td>
					<td width="30%">&nbsp;</td></tr>
				{/if}

{if $isbanned == 0}
				<tr>
					<td width="70%" valign="top" >
						<table   cellpadding="{$config.cellpadding}" 

cellspacing="{$config.cellspacing}" border="0">
							<tr>
								<td valign="middle" width="6"><input type="checkbox" 

name="chknotify" onclick="updateExtras();" value="1" />
								</td>
								<td valign="middle">{lang mkey='notify_me'}
								</td>
							</tr>
													</table>
					</td>
					<td width="30%" valign="top" height="110">
						<img src="getsnap.php?id={$smarty.request.recipient}&amp;typ=tn" 

class="smallpic" style="margin:10px 20px 10px 0px;" alt="" />
					</td>
				</tr>
			</table>
			</form>

			<p ><b>{lang mkey='custom_message'}</b></p>

			<!-- MOD END -->

			<form name="frmCompose" action="" method="post" onsubmit="javascript: return validate(this);">
			<input type="hidden" name="frm" value="frmCompose"/>

			<!-- MOD START -->

			<input type="hidden" name="chknotify" value="0"/>
			<input type="hidden" name="chkinclude" value="0"/>

			<!-- MOD END -->

			<table   cellpadding="{$config.cellpadding}" cellspacing="{$config.cellspacing}" border="0">

				<tr>
					<td >{lang mkey='subject'}</td>
					<td><input type="text" class="textinput" name="txtsubject" size="70" value="{if 

$smarty.request.reply == '1' or $smarty.request.reply == '11'}{$msg.subject|stripslashes}{elseif $errormsg != ''}

{$smarty.request.txtsubject}{/if}" />
						<input type="hidden" name="txtrecipient" 

value="{$smarty.request.recipient}"/>
						{if $smarty.request.reply == '1' or $smarty.request.reply == '11'}
							<input type="hidden" name="reply" value="2" />
							<input type="hidden" name="sort" value="{$smarty.request.sort}" />
							<input type="hidden" name="type" value="{$smarty.request.type}" />
							<input type="hidden" name="folder" value="{$smarty.request.folder}" 

/>
							<input type="hidden" name="selflag" 

value="{$smarty.request.selflag}" />
							<input type="hidden" name="msgid" value="{$smarty.request.msgid}" 

/>

						{/if}
					</td>
				</tr>
				<tr>
					<td valign="top" >{lang mkey='message'}</td>
					<td><textarea name="txtmessage" rows="8" cols="50">

{if $smarty.request.reply == '1' or $smarty.request.reply == '11'}{$msg.message|stripslashes }{elseif $errormsg != ''}

{$smarty.request.txtmessage }{/if}</textarea></td>
				</tr>
								<tr>
					<td colspan="2" ><input type="submit" class="formbutton" name="btnsend" 

value="{lang mkey='send'}"/>
					</td>
				</tr>
			</table>
			</form>

			<!-- MOD START -->


			<form name="frmTemplate" action="" method="post" onsubmit="javascript: return checkMe(this);">

				<input type="hidden" name="frm" value="frmTemplate"/>
				<input type="hidden" name="txtrecipient" value="{$smarty.request.recipient}"/>

				<input type="hidden" name="chknotify" value="0"/>
				<input type="hidden" name="chkinclude" value="0"/>
				<input type="hidden" name="spam_code" value="" />

			<table width="100%"   cellpadding="{$config.cellpadding}" cellspacing="{$config.cellspacing}" 

border="0">

				{foreach item=item from=$templates}
					<tr>
						<td width="25" valign="top" ><input type="radio" name="templateid" 

value="{$item.id}" /></td>
						<td>{$item.text|nl2br|stripslashes}</td>
					</tr>
				{foreachelse}
									{/foreach}
{/if}
			</table>

			{if $templates|@count}
			<p ><input type="button" class="formbutton" name="btnsend" value="{lang mkey='send'}" 

onclick="javascript:document.frmTemplate.spam_code.value=document.frmCompose.spam_code.value; document.frmTemplate.submit

();" /></p>
			{/if}

			</form>
{if $isbanned == 0}
			{/if}
		</div>
	{/if}
	</div>
</div>
{/strip}

<!-- MOD END -->
{if $config.use_profilepopups == 'Y'}
	<script type="text/javascript"> /* <![CDATA[ */ window.focus(); /* ]]> */</script>
{/if}

{if $config.use_profilepopups == 'Y'}
	{closedb}
	</body>
	</html>
{/if}

Thanks for any help.
Jade78
Jade78 is offline   Reply With Quote
Old 07-04-2012, 04:24 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,657
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Far too much unformatted code to go through.
Why not instead of denying, instead display differently? So that way everyone can still communicate, but block them separately within the private messaging system to indicate that so and so is in a different age group then defined?
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:14 PM.


Advertisement
Log in to turn off these ads.