function engagements_handle_tracking_pixel_request

7.x engagements.module engagements_handle_tracking_pixel_request($cid, $token)
6.x engagements.module engagements_handle_tracking_pixel_request($cid, $token)

The user has opened an email with a tracking pixel. We will now record that it was opened in our engagements_tracking table.

We also need to actually render the pixel to the browser.

1 string reference to 'engagements_handle_tracking_pixel_request'
engagements_menu in modules/engagements/engagements.module
Implement hook_menu

File

modules/engagements/engagements.module, line 2418
This is the primary module file for the engagements module.

Code

function engagements_handle_tracking_pixel_request($cid, $token) 
 {

  // Record in database
  // Fist, get the current count, if it exists.
  $res = db_query("SELECT * FROM engagements_tracking WHERE cid = ? AND token = ?", array($cid, $token));
  $cur = db_fetch_array($res);
  if ($cur ['cid'] != $cid || $cur ['token'] != $token) {
    // Means it was not generated, this might be a malicious attempt or an old token or something.
    die;
  }
  $opens = intval($cur ['opens']) + 1;
  db_query('UPDATE engagements_tracking
              SET opens = ?,
                  updated = ?
              WHERE cid = ? AND token = ?', array($opens, time(), $cid, $token));

  watchdog('engagements_track', "Tracking request for: $cid - $token");


  // Create a new "activity record" that the student has viewed this email.
  $email_content = content_load($cid);

  // Create a new actvity_record.
  $content = new stdClass();
  $content->type = 'activity_record';
  $content->cid = "new";
  $content->published = 1;
  $content->delete_flag = 0;
  $content->title = t('Student opened email titled "@et".', array("@et" => $email_content->title));
  $content->field__student_id ['value'] = $email_content->field__student_id ['value'];
  $content->field__activity_type ['value'] = 'mail';
  content_save($content);



  // Render pixel to browser and die.  We will be using the 1x1.gif file in our assets folder.  
  // Output the image to browser
  header('Content-Type: image/gif');
  $im = imagecreatefromgif(fp_get_module_path('engagements', TRUE, FALSE) . '/assets/1x1.gif');
  imagegif($im);
  imagedestroy($im);
  die;
}