Index: plugins/apt_plugin/apt_plugin.module
===================================================================
RCS file: /home/cvs/sites/all/modules/dist/casaa/plugins/apt_plugin/apt_plugin.module,v
retrieving revision 1.4
diff -u -r1.4 apt_plugin.module
--- plugins/apt_plugin/apt_plugin.module	20 Apr 2010 21:20:32 -0000	1.4
+++ plugins/apt_plugin/apt_plugin.module	27 Jul 2010 17:42:08 -0000
@@ -23,6 +23,7 @@
 define('CASAA_APT_SLT_SIZEW','weight');
 define('CASAA_APT_SLT_DEL',  'delete');
 
+define('CASAA_APT_DO_PROFILE', 'apt_do_profile');
 define('CASAA_APT_PUB_ID',    'apt_pubid');
 define('CASAA_APT_SITE',      'apt_site');
 define('CASAA_APT_SLOT',      'apt_slot_definitions');
@@ -127,6 +128,12 @@
     '#default_value' => variable_get('apt_plugin_has_defaults', 1),
     '#weight' => 11,
   );
+  $form['apt_plugin_settings'][CASAA_APT_DO_PROFILE] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Do user profile targeting?'),
+    '#default_value' => variable_get(CASAA_APT_DO_PROFILE, 1),
+    '#weight' => 11,
+  );
   $form['apt_plugin_settings'][CASAA_APT_PUB_ID] = array(
     '#type' => 'textfield',
     '#title' => t('Publisher ID'),
@@ -188,6 +195,7 @@
   }
   
   $form_state['values'][CASAA_APT_SLOT] = serialize($slot_data);
+  variable_set(CASAA_APT_DO_PROFILE, $form_state['values'][CASAA_APT_DO_PROFILE]);
 }
 
 function apt_plugin_mapping_settings_form($stored_values = null) {
@@ -310,8 +318,8 @@
   $output .= 'yld_mgr.site_name="' . variable_get(CASAA_APT_SITE, '') . '";' . "\n";
   $output .= 'yld_mgr.request_type="ac";' . "\n";
   $output .= 'yld_mgr.container_type="js";' . "\n";
-
-  if ($user->uid > 0 && module_exists('profile') && function_exists('profile_load_profile')) {
+  
+  if ( variable_get(CASAA_APT_DO_PROFILE, 1) && !user_is_anonymous() && function_exists('profile_load_profile')) {
     profile_load_profile($user);
     if ($user->profile_gender == 'M') {
       $output .= 'yld_mgr.user_gender = "male";' . "\n";
@@ -320,46 +328,51 @@
       $output .= 'yld_mgr.user_gender = "female";' . "\n";
     }
 
-    $output .= 'yld_mgr.user_zip = "' . $user->profile_zip . '";' . "\n";
-
-    $year = date('Y');
-    $age = $year - $user->profile_dob['year'];
-
-    if ($age > 65 && $age < $year) {
-      $output .= 'yld_mgr.user_age = "65-100";' . "\n";
-    }
-    else if ($age >= 60) {
-      $output .= 'yld_mgr.user_age = "60-64";' . "\n";
-    }
-    else if ($age >= 55) {
-      $output .= 'yld_mgr.user_age = "55-59";' . "\n";
-    }
-    else if ($age >= 50) {
-      $output .= 'yld_mgr.user_age = "50-54";' . "\n";
-    }
-    else if ($age >= 45) {
-      $output .= 'yld_mgr.user_age = "45-49";' . "\n";
-    }
-    else if ($age >= 40) {
-      $output .= 'yld_mgr.user_age = "40-44";' . "\n";
-    }
-    else if ($age >= 35) {
-      $output .= 'yld_mgr.user_age = "35-39";' . "\n";
-    }
-    else if ($age >= 30) {
-      $output .= 'yld_mgr.user_age = "30-34";' . "\n";
-    }
-    else if ($age >= 25) {
-      $output .= 'yld_mgr.user_age = "25-29";' . "\n";
-    }
-    else if ($age >= 21) {
-      $output .= 'yld_mgr.user_age = "21-24";' . "\n";
-    }
-    else if ($age >= 18) {
-      $output .= 'yld_mgr.user_age = "18-20";' . "\n";
+   if(!empty($user->profile_zip)) {
+      $output .= 'yld_mgr.user_zip = "' . $user->profile_zip . '";' . "\n";
     }
-    else if ($age >= 13) {
-      $output .= 'yld_mgr.user_age = "13-17";' . "\n";
+    
+    if(!empty($user->profile_dob) && !empty($user->profile_dob['year'])) {
+      
+	    $year = date('Y');
+	    $age = $year - $user->profile_dob['year'];
+	
+	    if ($age > 65 && $age < $year) {
+	      $output .= 'yld_mgr.user_age = "65-100";' . "\n";
+	    }
+	    else if ($age >= 60) {
+	      $output .= 'yld_mgr.user_age = "60-64";' . "\n";
+	    }
+	    else if ($age >= 55) {
+	      $output .= 'yld_mgr.user_age = "55-59";' . "\n";
+	    }
+	    else if ($age >= 50) {
+	      $output .= 'yld_mgr.user_age = "50-54";' . "\n";
+	    }
+	    else if ($age >= 45) {
+	      $output .= 'yld_mgr.user_age = "45-49";' . "\n";
+	    }
+	    else if ($age >= 40) {
+	      $output .= 'yld_mgr.user_age = "40-44";' . "\n";
+	    }
+	    else if ($age >= 35) {
+	      $output .= 'yld_mgr.user_age = "35-39";' . "\n";
+	    }
+	    else if ($age >= 30) {
+	      $output .= 'yld_mgr.user_age = "30-34";' . "\n";
+	    }
+	    else if ($age >= 25) {
+	      $output .= 'yld_mgr.user_age = "25-29";' . "\n";
+	    }
+	    else if ($age >= 21) {
+	      $output .= 'yld_mgr.user_age = "21-24";' . "\n";
+	    }
+	    else if ($age >= 18) {
+	      $output .= 'yld_mgr.user_age = "18-20";' . "\n";
+	    }
+	    else if ($age >= 13) {
+	      $output .= 'yld_mgr.user_age = "13-17";' . "\n";
+	    }
     }
   }
 
