function phpAds_printSourceRow($source_row, $expand_arr, $begin_str)
{
    global $anonymous, $campaignid, $clientid, $cnt, $phpAds_TextDirection, $phpAds_TextAlignRight;
    $expand = $expand_arr == 'all' || isset($expand_arr[$source_row['path']]) && $expand_arr[$source_row['path']] == 1;
    $children_present = isset($source_row['children']) && is_array($source_row['children']) & sizeof($source_row['children']) > 0;
    echo "\t\t\t\t<tr height='25' " . ($cnt % 2 == 0 ? "bgcolor='#F6F6F6'" : "") . ">\n";
    echo "\t\t\t\t\t<td>";
    echo $begin_str;
    if ($children_present && !$anonymous) {
        if ($expand) {
            echo "<a href='stats-banner-sources.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&collapse=" . $source_row['path'] . "'><img src='images/triangle-d.gif' align='absmiddle' border='0'></a>&nbsp;";
        } else {
            echo "<a href='stats-banner-sources.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&expand=" . $source_row['path'] . "'><img src='images/" . $phpAds_TextDirection . "/triangle-l.gif' align='absmiddle' border='0'></a>&nbsp;";
        }
    } else {
        echo "<img src='images/spacer.gif' align='absmiddle' width='16' height='16' border='0'>";
    }
    if ($anonymous) {
        echo "(hidden source #" . ($cnt + 1) . ")";
    } else {
        echo $source_row['name'];
    }
    echo "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['views']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['clicks']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_buildCTR($source_row['views'], $source_row['clicks']) . "</td>";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['conversions']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_buildCTR($source_row['clicks'], $source_row['conversions']) . "&nbsp;&nbsp;</td>";
    echo "\t\t\t\t</tr>\n";
    if ($expand && $children_present && !$anonymous) {
        $child_source_row = $source_row['children'];
        for ($i = 0; $i < sizeof($child_source_row); $i++) {
            echo "\t\t\t\t<tr height='1'" . ($cnt % 2 == 0 ? " bgcolor='#F6F6F6'" : "") . "><td><img src='images/spacer.gif' width='100%' height='1' border='0'></td><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>\n";
            phpAds_printSourceRow($child_source_row[$i], $expand_arr, $begin_str . "&nbsp;&nbsp;&nbsp;&nbsp;");
        }
    }
}
function phpAds_printSourceRow($source_row, $sources, $expand_arr, $listorder, $orderdirection, $begin_str)
{
    global $anonymous, $campaignid, $clientid, $cnt, $phpAds_TextDirection, $phpAds_TextAlignRight;
    $expand = $expand_arr == 'all' || isset($expand_arr['sources/' . $source_row['path']]) && $expand_arr['sources/' . $source_row['path']] == 1;
    $children_present = isset($source_row['children']) && is_array($source_row['children']) & sizeof($source_row['children']) > 0;
    $checked = '';
    for ($i = 0; $i < sizeof($sources); $i++) {
        if ($sources[$i] == $source_row['path']) {
            $checked = ' checked';
            break;
        }
    }
    echo "\t\t\t\t<tr height='25' " . ($cnt % 2 == 0 ? "bgcolor='#F6F6F6'" : "") . ">\n";
    echo "\t\t\t\t\t<td><input type='checkbox' name='sources[]' value='" . $source_row['path'] . "'" . $checked . "></td>\n";
    echo "\t\t\t\t\t<td>";
    echo $begin_str;
    if ($children_present && !$anonymous) {
        if ($expand) {
            echo "<a href='stats-campaign-optimise.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&collapse=" . urlencode('sources/' . $source_row['path']) . "'><img src='images/triangle-d.gif' align='absmiddle' border='0'></a>&nbsp;";
        } else {
            echo "<a href='stats-campaign-optimise.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&expand=" . urlencode('sources/' . $source_row['path']) . "'><img src='images/" . $phpAds_TextDirection . "/triangle-l.gif' align='absmiddle' border='0'></a>&nbsp;";
        }
    } else {
        echo "<img src='images/spacer.gif' align='absmiddle' width='16' height='16' border='0'>";
    }
    if ($anonymous) {
        echo "(hidden source #" . ($cnt + 1) . ")";
    } else {
        echo $source_row['source'];
    }
    echo "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['views']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['clicks']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_buildCTR($source_row['views'], $source_row['clicks']) . "</td>";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_row['conversions']) . "</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_buildCTR($source_row['clicks'], $source_row['conversions']) . "&nbsp;&nbsp;</td>";
    echo "\t\t\t\t</tr>\n";
    if ($expand && $children_present && !$anonymous) {
        $child_source_row = $source_row['children'];
        for ($i = 0; $i < sizeof($child_source_row); $i++) {
            phpAds_printTableBreak(7, 2, $cnt % 2 == 0 ? "#F6F6F6" : "");
            phpAds_printSourceRow($child_source_row[$i], $sources, $expand_arr, $listorder, $orderdirection, $begin_str . "&nbsp;&nbsp;&nbsp;&nbsp;");
        }
    }
}