function phpAds_buildRatioPercentage($numerator, $denominator)
{
    return phpAds_formatPercentage(phpAds_buildRatio($numerator, $denominator));
}
 /**
  * A method to format a row of statistics according to the column's "format"
  * value in the {@link $this->_aFields} array, and according to user preferences
  * for how numbers/currency should be formatted.
  *
  * @param array   $aRow    An array containing a row of statistics to format.
  * @param boolean $isTotal Is the row a "total" row? When true, ensures that
  *                         all "id" formatted columns (from the
  *                         {@link $this->_aFields} array) are set to "-".
  */
 function _formatStats(&$aRow, $isTotal = false)
 {
     foreach ($this->_aFields as $k => $v) {
         if (array_key_exists($k, $aRow)) {
             if ($v['format'] == 'id') {
                 $aRow[$k] = $isTotal ? '-' : $aRow[$k];
             } elseif ($aRow[$k] == 0) {
                 $aRow[$k] = '-';
             } elseif ($v['format'] == 'percent') {
                 $aRow[$k] = phpAds_formatPercentage($aRow[$k]);
             } elseif ($v['format'] == 'currency') {
                 $aRow[$k] = phpAds_formatNumber($aRow[$k], 2);
             } else {
                 $aRow[$k] = phpAds_formatNumber($aRow[$k]);
             }
         }
     }
 }
 $cnt = 0;
 for ($i = 0; $i < sizeof($source_arr['children']); $i++) {
     if (is_array($source_arr['children'][$i])) {
         phpAds_printSourceRow($source_arr['children'][$i], $sources_expand, $listorder, $orderdirection, "&nbsp;&nbsp;");
         echo "\t\t\t\t<tr height='1'><td colspan='6' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>\n";
         $cnt++;
     }
 }
 // Total
 echo "\t\t\t\t<tr height='25'>\n";
 echo "\t\t\t\t\t<td>&nbsp;&nbsp;<b>" . $strTotal . "</b></td>\n";
 echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_arr['views']) . "</td>\n";
 echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_arr['clicks']) . "</td>\n";
 echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatPercentage($source_arr['ctr']) . "</td>\n";
 echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($source_arr['conversions']) . "</td>\n";
 echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatPercentage($source_arr['cnvr']) . "&nbsp;&nbsp;</td>\n";
 echo "\t\t\t\t</tr>\n";
 // Break
 echo "\t\t\t\t<tr height='1'><td colspan='6' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>\n";
 // Expand / Collapse
 echo "\t\t\t\t<tr>\n";
 echo "\t\t\t\t\t<td colspan='6' align='" . $phpAds_TextAlignRight . "' nowrap>";
 echo "<img src='images/triangle-d.gif' align='absmiddle' border='0'>";
 echo "&nbsp;<a href='stats-campaign-sources.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&expand=all' accesskey='" . $keyExpandAll . "'>" . $strExpandAll . "</a>";
 echo "&nbsp;&nbsp;|&nbsp;&nbsp;";
 echo "<img src='images/" . $phpAds_TextDirection . "/triangle-l.gif' align='absmiddle' border='0'>";
 echo "&nbsp;<a href='stats-campaign-sources.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&expand=none' accesskey='" . $keyCollapseAll . "'>" . $strCollapseAll . "</a>";
 echo "</td>\n";
 echo "\t\t\t\t</tr>";
 echo "\t\t\t\t</table>\n";
 echo "\t\t\t\t<br><br>\n";
function phpAds_displayStatsRow($data_arr, $total_arr, $expand_arr, $omit_arr, $level = 0)
{
    global $campaignid, $clientid, $cnt, $phpAds_TextDirection, $phpAds_TextAlignRight;
    $show_children = false;
    echo "\t\t\t\t<tr height='25' " . ($cnt % 2 == 0 ? "bgcolor='#F6F6F6'" : "") . ">\n";
    if ($level == 0) {
        echo "\t\t\t\t\t<td colspan='2'>";
    } else {
        $checked = in_array($data_arr['path'], $omit_arr) ? '' : ' checked';
        echo "\t\t\t\t\t<td><input type='checkbox' name='keep[]' value='" . $data_arr['path'] . "'" . $checked . "><input type='hidden' name='omit[]' value='" . $path . "'></td>\n";
        echo "\t\t\t\t\t<td>";
        if ($level > 1) {
            echo "<img src='images/spacer.gif' width='" . $level * 15 . "' height='1' border='0'>";
        }
    }
    if (isset($data_arr['children']) && is_array($data_arr['children']) && sizeof($data_arr['children']) > 0) {
        if (in_array($data_arr['name'], $expand_arr)) {
            echo "<a href='stats-campaign-optimise.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&collapse=" . $data_arr['name'] . "'><img src='images/triangle-d.gif' align='absmiddle' border='0'></a>";
            $show_children = true;
        } else {
            echo "<a href='stats-campaign-optimise.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&expand=" . $data_arr['name'] . "'><img src='images/" . $phpAds_TextDirection . "/triangle-l.gif' align='absmiddle' border='0'></a>";
        }
    }
    if ($level == 0) {
        echo "&nbsp;<b>" . $data_arr['name'] . "</b></td>\n";
    } else {
        echo "&nbsp;" . $data_arr['name'] . "</td>\n";
    }
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($data_arr['views']) . "</td>\n";
    echo "\t\t\t\t\t<td align='center'>(" . phpAds_formatPercentage(phpAds_buildRatio($data_arr['views'], $total_arr['views']), 0) . ")</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($data_arr['clicks']) . "</td>\n";
    echo "\t\t\t\t\t<td align='center'>(" . phpAds_formatPercentage(phpAds_buildRatio($data_arr['clicks'], $total_arr['clicks']), 0) . ")</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatPercentage($data_arr['ctr']) . "</td>\n";
    echo "\t\t\t\t\t<td align='center'>(" . phpAds_formatPercentage(phpAds_buildRatio($data_arr['ctr'], $total_arr['ctr']), 0) . ")</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatNumber($data_arr['conversions']) . "</td>\n";
    echo "\t\t\t\t\t<td align='center'>(" . phpAds_formatPercentage(phpAds_buildRatio($data_arr['conversions'], $total_arr['conversions']), 0) . ")</td>\n";
    echo "\t\t\t\t\t<td align='" . $phpAds_TextAlignRight . "'>" . phpAds_formatPercentage($data_arr['cnvr']) . "&nbsp;&nbsp;</td>\n";
    echo "\t\t\t\t\t<td align='center'>(" . phpAds_formatPercentage(phpAds_buildRatio($data_arr['cnvr'], $total_arr['cnvr']), 0) . ")</td>\n";
    echo "\t\t\t\t</tr>\n";
    if ($show_children) {
        for ($i = 0; $i < sizeof($data_arr['children']); $i++) {
            phpAds_displayStatsRow($data_arr['children'][$i], $total_arr, $expand_arr, $omit_arr, $level + 1);
        }
    }
    if ($level == 0) {
        $cnt++;
    }
}
function phpAds_buildCTR($views, $clicks)
{
    return phpAds_formatPercentage(phpAds_buildRatio($clicks, $views));
}