Welcome, Guest
Username Password: Remember me

Can you help be to make this script better ?
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Can you help be to make this script better ?

Can you help be to make this script better ? 8 months, 1 week ago #16917

  • legnou59
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Points: 55
  • Karma: 0
Hello !

I need to write a CallBack script (with Jumi) to add some points to a user who had posted a specific form... This form send datas to my CallBack script :

<!-- script adding Points to a user who had posted a form -->
<?php
## DATAS SENTS BACK BY THE FORM
$MYSECRETKEY = 'mysecretkey';

$docId		= (int) $_GET['docId'];
$uid		= $_GET['uid'];
$awards		= (int) $_GET['awards'];
$trId		= $_GET['trId'];
$promoId	= ((isset($_GET['promoId'])) ? (int) $_GET['promoId'] : 0 );
$hash		= $_GET['hash'];

## DATAS NEEDED TO ADD POINTS TO THE CORRECT USER
$database			= 'my_jommla_database'
$host				= 'localhost'
$main_AUP_table 	= 'jos_alpha_userpoints'
$custom_AUP_table 	= 'jos_alpha_userpoints_history_payments'
$DB_user			= 'myDBuser'
$DB_password		= 'myPassword'

## CHECK HASH VALUE	
if(md5($uid . $awards . $trId . $MYSECRETKEY) == $hash) {
	# DB connect
	$cnx = mysql_connect($host, $DB_user, $DB_password);
	mysql_select_db($database, $cnx);
	
	
	$rs = mysql_query('SELECT COUNT(1) AS NB FROM $custom_AUP_table WHERE external_reference = ''.addslashes($trId).''', $cnx);
	$ifFindTr = (int) mysql_result($rs, 0, 'NB');
	unset($rs);
	
	if($ifFindTr == 0) {
		# all is OK
		# we can add $awards points to the user and save transaction
		
		# Adding points
		mysql_query( 'UPDATE $main_AUP_table SET points=points+'.$awards.' WHERE userid=''.addslashes($uid).''', $cnx); 
		
		# Register in jos_alpha_userpoints_history_payments
		mysql_query( 'INSERT INTO $custom_AUP_table (doc_id, user_id, awards, external_reference, promo_id, date) ' 
					.'VALUE('.$docId.', ''.addslashes($uid).'', '.$awards.', ''.addslashes($trId).'', '.$promoId.', NOW())', $cnx);
		
		echo 'OK';
		
	}
	else {
		# this transaction reference already added
		# add in error log 	
		
		echo 'this transaction reference already added';
	}
	
	mysql_close($cnx);
}
else {
	# hash error
	# add in error log 	
	
	echo 'hash error';
	
}




?>


How to make this script correct for using with AUP ?

Re: Can you help be to make this script better ? 8 months, 1 week ago #16923

  • adroussel
  • OFFLINE
  • Moderator
  • Posts: 397
  • Points: 669
  • Karma: 21
Hi
Not sure I fully understand this code, is Jumi not a joomla application?
does a userid require a addslash function?

Any way it's highly NOT recommended to credit points using a DB query... In AUP points attributions or deductions should be done via rules. If you use queries to update tables, amounts will be mistaked in cuse you simply do a recalculation.

You need to read the AUP developper guide to use the easy API to use to credit points in you application.

Re: Can you help be to make this script better ? 8 months, 1 week ago #16934

  • legnou59
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Points: 55
  • Karma: 0
Thanks, so... I'm trying to write a plugin AUPJumi... But I'm a noob in PHP and i nedd some help :

In this his function :

{
AlphaUserPointsHelper::newpoints( 'Arg#1', 'Arg#2', 'Arg#3','Arg#4'.$jumiscriptID);
return;
}
I need to pass those datas :

  • User ID,
  • Number of points to add,
  • Transaction ID (for not to pass 2 time the same action


But i don't know the order in ( 'Arg#1', 'Arg#2', 'Arg#3','Arg#4'...) i must write those variables...

Can you help me ?
  • Page:
  • 1
Moderators: adroussel, dalekurt, migus, some1new
Time to create page: 0.49 seconds
Goto Top