Ejemplo n.º 1
0
function mail_expense($description, $amount, $type, $timestamp, $booker_userid, $groupid, $members, $eventid, $deposit = 0)
{
    if (!preg_match("/(,|\\.)/", $amount)) {
        $amount .= ".00";
    } elseif (preg_match("/,/", $amount)) {
        $amount = str_replace(",", ".", $amount);
    }
    $userList = array();
    foreach ($members as $id) {
        $userList[$id] = get_user_profile($id);
    }
    $allgroupmembers = get_groupmembers($groupid, false, true);
    $groupdetails = get_groupdetails($groupid);
    $balancelist = array_sort(get_group_balance_list($groupdetails), 'unformatted_balance', SORT_DESC);
    if ($deposit == 0) {
        $p1 = date('l jS \\of F Y');
        $p3 = number_format($amount, DECIMALS, DSEP, TSEP);
        $p4 = '';
        if (!empty($eventid)) {
            $eventdetails = get_eventdetails($eventid);
            $p4 = " for event \"{$eventdetails['eventname']}\"";
        }
        $p5 = $description;
        $p7 = number_format($amount / count($members), DECIMALS, DSEP, TSEP);
        $message = "On {1} {2} booked an expense of &#8364; {3}{4} with description \"{5}\".<br /><br />";
        $message .= "You were listed as a participant, together with {6}.<br /><br />";
        $message .= "The costs per person are &#8364; {7} making your balance &#8364; {8} which comes to position {9} in the group. ";
        $message .= "The balance list is now: <br /><br />{10}";
        $message .= "<br /><br /><a href=\"" . LOGIN_URL . "\">Going Dutch</a>";
        $from = '*****@*****.**';
        $from_name = 'Going Dutch';
        $subject = "Going Dutch expense booked in group \"{$groupdetails['name']}\"";
        $subject = addslashes($subject);
        foreach ($userList as $user) {
            // skip user if prefs are not set
            if (!isset($user['name_format']) || !isset($user['email_notify'])) {
                continue;
            }
            if ($user['user_id'] == $booker_userid) {
                $p2 = 'you have';
            } else {
                $p2 = format_name($user['name_format'], $userList[$booker_userid]['username'], $userList[$booker_userid]['realname']) . ' has';
            }
            $others = '';
            foreach ($members as $participant) {
                if ($participant != $user['user_id']) {
                    $others .= ', ' . format_name($user['name_format'], $userList[$participant]['username'], $userList[$participant]['realname']);
                }
            }
            //
            $p6 = preg_replace('/(.*),/', '$1 and', trim($others, ', '));
            //$text = preg_replace('/(.*),/','$1 and',$text)
            $p8 = $balancelist[$user['user_id']]['balance'];
            $i = 1;
            foreach ($balancelist as $key => $val) {
                if ($key == $user['user_id']) {
                    break;
                }
                $i++;
            }
            $p9 = $i;
            $tablehtml = create_memberlist_html_table($balancelist, $allgroupmembers, $user['name_format'], SORT_DESC);
            $p10 = $tablehtml;
            $a = 1;
            $body = str_format($message, $p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8, $p9, $p10);
            $pp = $amount / count($members);
            $floatval = floatval($user['email_notify']);
            if ($user['email_notify'] != '-1' && $pp >= $floatval) {
                // exec($command, $output = array());
                // smtpmailer($user['email'], $from, $from_name, $subject, $body, $replyto = '', $sendas='to');
                $replyto = '';
                $sendas = 'to';
                $background_mailfile = dirname(__FILE__) . '/background_mailer.php';
                //$output = '/var/log/test';
                $output = '/dev/null';
                $body = addslashes($body);
                $cmd = "/usr/bin/php5 {$background_mailfile} {$user['email']} {$from} \"{$from_name}\" \"{$subject}\" \"{$body}\" \"{$replyto}\" \"{$sendas}\"";
                //exec("/usr/bin/php {$background_mailfile} {$user['email']} {$from} {$from_name} {$subject} {$body} {$replyto} {$sendas} > {$ouput} &");
                exec("{$cmd} > {$output} &");
                //exec("/usr/bin/php {$background_mailfile} {$user['email']} {$from} \"{$from_name}\" \"{$subject}\" \"{$body}\" \"{$replyto}\" \"{$sendas}\" > {$output} &");
            }
        }
        //
        //      foreach ($members as $key => $value) {
        //
        //      }
        //$mysqldate = date('Y-m-d H:i:s', $timestamp);
        $sql = "INSERT INTO expenses (type, user_id, group_id, description, amount, expense_date, event_id, timestamp, currency) \n            VALUES ('{$type}', '{$userid}', '{$groupid}', '{$description}', '{$amount}', FROM_UNIXTIME({$timestamp}), {$eventid}, CURRENT_TIMESTAMP , '1')";
        //    if (!$result = mysql_query($sql)) {
        //      return false;
        //    } else {
        //      $expenseid = mysql_insert_id();
        //      foreach ($members as $key => $value) {
        //        $sql = "INSERT INTO users_expenses (`user_id` , `expense_id`) VALUES ('$value', '$expenseid')";
        //        if (!$result = mysql_query($sql)) {
        //          $inserterror = true;
        //        }
        //      }
        //      if ($inserterror)
        //        return false;
        //      return true;
        //    }
    } else {
        // making a deposit
        // for each person, make an expense with only deposit holder ($userid) as recipient
        // first register deposit to get a deposit id
        //    $sql = "INSERT INTO deposits (holder, description) VALUES ($userid, '$description')";
        //    if (!$result = mysql_query($sql)) {
        //      return false;
        //    } else {
        //      $depositid = mysql_insert_id();
        //    }
        //
        //    foreach ($members as $key => $value) {
        //      $sql = "INSERT INTO expenses (type, user_id, group_id, description, amount, expense_date, event_id, timestamp, currency, deposit_id)
        //            VALUES ('$type', '$value', '$groupid', '$description', '$amount', FROM_UNIXTIME($timestamp), $eventid, CURRENT_TIMESTAMP , '1', $depositid)";
        //      if (!$result = mysql_query($sql)) {
        //        return false;
        //      } else {
        //        $expenseid = mysql_insert_id();
        //        $sql = "INSERT INTO users_expenses (`user_id` , `expense_id`) VALUES ('$userid', '$expenseid')";
        //        if (!$result = mysql_query($sql)) {
        //          $inserterror = true;
        //        }
        //      }
        //    }
    }
    if ($inserterror) {
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
$groupid = get_groupid_by_acid($acid);
// get permisssions for group
$permissions = group_permissions($groupid, $user->data['user_id']);
if (!$permissions || !array_key_exists(5, $permissions)) {
    fatal_error("No permissions for this achievement");
}
// get message
if (isset($_GET['msg'])) {
    $message = get_msg($_GET['msg']);
}
$details = get_achievementdetails($acid);
print_header();
// array structure: $bararray['title'], $bararray['leftnav'][$i][name|url], $bararray['rightnav'][$i][name|url]
$urll = $_SERVER['PHP_SELF'] . "?acid={$acid}&mode=edit";
$urlld = $_SERVER['PHP_SELF'] . "?acid={$acid}&mode=del";
$topbar['title'] = $groupdetails['name'];
/*
$topbar['leftnav'][0]['name'] = "List";
$topbar['leftnav'][0]['url'] = $_SESSION['back'];*/
$back = get_back_page();
$topbar['leftnav'][0]['name'] = $back['name'];
//$topbar['leftnav'][0]['url'] =  $back['url'];
$topbar['leftnav'][0]['url'] = "javascript:history.back()";
print_topbar($topbar);
print_body_start();
if ($message) {
    print_pagetitle($message);
}
$groupdetails = get_groupdetails($groupid);
print_achievementdetails_html($details, $user, $groupdetails);
print_footer($user, 7);