<?php
/**
 * 每月版主工资
 * 运行时间：1 0 1 * *
 */
require_once dirname(dirname(__FILE__)) . '/init.php';

if ('01' != date('d'))
{
    exit(0);
}
$sql = 'SELECT forumadmin FROM '.Forums::table()." WHERE type <> 'category'";
$forums = $db->setQueryString($sql)->find();
$wages = setting('bbsmwages');

if (empty($forums))
{
    exit(0);
}

foreach ($forums as $forum)
{
    if (empty($forum['forumadmin']))
    {
        continue;
    }

    $adminList = explode(',', $forum['forumadmin']);
    foreach ($adminList as $admin)
    {
        if ($admin)
        {
            $userName = userName($admin);
            $obj = iCredits::single($admin, $userName);
            $obj->setUid($admin);
            $obj->setUserName($userName);
            $obj->addMoney($wages);

            $subject = '[系统消息]版主工资';
            $content = '感谢您一个月来对社区繁荣做出的努力，特奖励'.$wages.setting('creditname').'以做鼓励！^_^';
            Members::sendMessage($subject, $content, 1, 'admin', $admin);
        }
    }
}