private function buildClick($cid = null) { $this->click = new Click(); // if a click id is already present, check the details against the post if ($cid && $this->click->fillFromDbPk($cid)) { if (isset($this->post['hit_id']) && $this->click->hit_id != $this->post['hit_id']) { $this->click = new Click(); } } // is there a click id? if (!empty($this->post['click_id']) && is_numeric($this->post['click_id'])) { // is there a click record? if ($this->click->fillFromDbPk($this->post['click_id'])) { // check to see if click camp details match if ($this->campaign->campaign_id != $this->click->campaign_id) { // reset click and continue $this->click = new Click(); $this->post['hit_id'] = $this->post['click_id']; $this->post['click_id'] = ''; //$this->apiError('error5 - Invalid campaign/click info'); } } else { // there's a click_id, but it does not belong to LJ3. disregard info $this->post['hit_id'] = $this->post['click_id']; $this->post['click_id'] = ''; } } // is click empty? if (!$this->click->getPkValue()) { $this->click->fillFromArray($this->post); $this->click->fillIpAddress($this->post['user_ip']); $this->click->created = $this->click->updated = 'NOW():sql'; //date("Y-m-d H:i:s"); // check validity of // HOW TO HANDLE 3rd Party AFIDs? is the afid called something different if (isset($this->post['AFID']) && strlen($this->post['AFID']) && !isset($this->post['aff_id'])) { $this->click->getAffId($this->post['AFID']); // did it work? remove AFID then if ($this->click->aff_id) { $this->click->AFID = ''; } } $cookie_name = 's' . $this->click->campaign_id; $expire = time() + 3600 * 24 * 100; if (isset($this->cookie[$cookie_name])) { $old_click_id = $this->cookie[$cookie_name]; // check the ID $c = new Click(); $c->fillFromDbPk($old_click_id); if ($c->getPkValue()) { // is this click from a different affiliate? if so, don't use the old cookie click if ($c->aff_id == $this->click->aff_id) { $this->click->fillFromDbPk($old_click_id); unset($c); setcookie($cookie_name, $old_click_id, $expire, "/"); return; } unset($c); } } if (!$this->click->save()) { $this->apiError('click error ' . $this->click->geterrors2string()); } setcookie($cookie_name, $this->click->click_id, $expire, "/"); } }