Author Topic: Regular Credits  (Read 5348 times)

Offline Tanix

Regular Credits
« on: January 29, 2007, 01:05:19 am »
I'd like to give members credits on a regular basis. How could I do that?

Example: Pay membergroup x the sum of 5 credits every day. Pay membergroup y the sum of 10 credits every month.

Offline feeble

Re: Regular Credits
« Reply #1 on: February 21, 2007, 07:38:16 am »
if you know cron jobs, should be fairly simple

Offline Tanix

Re: Regular Credits
« Reply #2 on: February 21, 2007, 08:02:41 am »
Forgotten I'd posted that. Thanks, feeble. I'd actually worked out the cron job side of things - using Daniel's code from the bank interest calculation and his guide on setting cron jobs:

Code: [Select]
<?php

//File: dosalaries.php - Pays salaries to members
//MUST SET UP A CRON JOB FOR THIS TO WORK

if(!isset($_SERVER["HTTP_HOST"])) {

include("../../SSI.php");

$salary $modSettings['salary'];
db_query("UPDATE {$db_prefix}members
  SET moneyBank = moneyBank + 
{$salary}"__FILE____LINE__);

echo "Salary paid on ".date("d/m/Y h:i:s A");
}
?>

What I haven't figured out yet is how to work out different salary payments for different membergroups. PHP learner here.

Offline feeble

Re: Regular Credits
« Reply #3 on: February 21, 2007, 11:49:31 am »
you could do something like

Code: [Select]
db_query("UPDATE {$db_prefix}members
  SET moneyBank = moneyBank + {$salary} WHERE ID_GROUP = '1' ", __FILE__, __LINE__);

does not take in additionalGroups field but its a start.

Offline Daniel15

Re: Regular Credits
« Reply #4 on: February 24, 2007, 09:03:43 am »
Quote
What I haven't figured out yet is how to work out different salary payments for different membergroups.
A slightly ugly solution, but usable nontheless:
Code: (php) [Select]
<?php

//File: dosalaries.php - Pays salaries to members
//MUST SET UP A CRON JOB FOR THIS TO WORK

if (isset($_SERVER["HTTP_HOST"]))
die('Grrrrrrr...');

include(
'SSI.php');
$salaries = array(
// array(group ID, amount of credits to add)
array(110),
array(220),
);

foreach (
$salaries as $salary)
{
$salary[0] = (int) $salary[0];
$salary[1] = (float) $salary[1];
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + 
{$salary[1]}
WHERE ID_GROUP = 
{$salary[0]}"__FILE____LINE__);
}

echo 
'Salary paid on ' date("d/m/Y h:i:s A");
?>


I haven't tested that, but it should work ;)