OpenAds - clientid vs. campaignid

October 29, 2007

We use openads at work and needed to directly target a client’s banner. Any of their banners from any of their campaigns. You can’t do ’?what=clientid:123’ since clients don’t have any relation to banners. Campaigns do.

The below patch fixes this by finding all the campaigns for that client and then searches on that.

Index: libraries/lib-view-query.inc.php
===================================================================
--- libraries/lib-view-query.inc.php  (revision 7640)
+++ libraries/lib-view-query.inc.php  (working copy)
@@ -229,12 +229,19 @@
          $part_array[$k] = substr($part_array[$k], 9);
          if ($part_array[$k] != '' && $part_array[$k] != ' ')
          {
+            $res = phpAds_dbQuery("SELECT clientid FROM ".$phpAds_config['tbl_clients']." WHERE parent = '".trim($part_array[$k])."' ");
+            $clientids = array();
+            $clientids[] = trim($part_array[$k]);
+            while ($row = phpAds_dbFetchRow($res))
+            {
+               $clientids[] = $row[0];
+            }
            if ($operator == 'OR')
-             $conditions .= "OR ".$phpAds_config['tbl_banners'].".clientid='".trim($part_array[$k])."' ";
+             $conditions .= "OR ".$phpAds_config['tbl_banners'].".clientid IN (".join($clientids, ',').") ";
            elseif ($operator == 'AND')
-             $conditions .= "AND ".$phpAds_config['tbl_banners'].".clientid='".trim($part_array[$k])."' ";
+             $conditions .= "AND ".$phpAds_config['tbl_banners'].".clientid IN (".join($clientids, ',').") ";
            else
-             $conditions .= "AND ".$phpAds_config['tbl_banners'].".clientid!='".trim($part_array[$k])."' ";
+             $conditions .= "AND ".$phpAds_config['tbl_banners'].".clientid NOT IN (".join($clientids, ',').") ";
          }

          $onlykeywords = false;