Exemplo n.º 1
0
 private function addEvent($type, $id, $email, $datetime)
 {
     echo 'Adding ' . strtoupper($type) . ' to campaign ' . $id . ' with date of ' . $datetime . ' and email of ' . $email . "\r\n";
     $StoreModel = new Store();
     $encryptedEmail = $StoreModel->encryptEmail($email);
     // Look for this email address in store table
     $StoreRows = Store::model()->with('store2contact')->findAll(array('condition' => 'email = :email', 'params' => array(':email' => $encryptedEmail)));
     // collect our warehouse_ids up to match in campaign_contact table.
     $warehouseIDs = [];
     if (sizeof($StoreRows)) {
         // Save 1 suppression row for every instance of the email address in the store table - use store_id
         foreach ($StoreRows as $Store) {
             if ($Store->store2contact != null) {
                 $warehouseIDs[] = $Store->store2contact->contact_warehouse_id;
             }
         }
         $Contacts = null;
         // check for contact
         if (sizeof($warehouseIDs) && is_numeric($id)) {
             //Bounces
             if ($type === 'bounce') {
                 $Contacts = CampaignContact::model()->updateAll(array('bounced' => $datetime), "campaign_id = :campaign_id AND warehouse_id IN (" . implode(',', $warehouseIDs) . ") AND bounced IS NULL", array(':campaign_id' => $id));
             } else {
                 $Contacts = CampaignContact::model()->updateAll(array('opened' => $datetime), "campaign_id = :campaign_id AND warehouse_id IN (" . implode(',', $warehouseIDs) . ") AND opened IS NULL", array(':campaign_id' => $id));
             }
         }
         echo 'Updated ' . sizeof($Contacts) . ' contact';
     } else {
         echo 'Campaign contact not found' . "\r\n";
     }
     echo "\r\n";
 }
Exemplo n.º 2
0
 public function authenticate()
 {
     // Try to get user from User table - this will be an administrator
     $User = User::model()->findByAttributes(array('email' => strtolower($this->username), 'verified' => 1, 'mothballed' => 0));
     if (!is_null($User)) {
         // We have an admin user
         if (isset($User->password)) {
             if ($User->password === hash('sha256', $this->password . SHASALT)) {
                 $this->errorCode = self::ERROR_NONE;
                 $this->_id = $User->id;
                 $this->userType = 'admin';
             } else {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             }
         }
     } else {
         // For encryption
         $Store = new Store();
         $Criteria = new CDbCriteria();
         $Criteria->condition = "\n\t\t\t\temail = :email AND \n\t\t\t\torigin_organisation_id = :origin_organisation_id AND \n\t\t\t\tpassword IS NOT NULL \n\t\t\t";
         $Criteria->params = array(':email' => $Store->encryptEmail($this->username), ':origin_organisation_id' => 10);
         $Store = Store::model()->with('store2contact', 'store2contact.accession')->find($Criteria);
         if (!is_null($Store)) {
             // We have a user from THE LIST
             // Does the password match?
             if ($Store->store2contact->accession->password === hash('sha256', $this->password . SHASALT)) {
                 $this->errorCode = self::ERROR_NONE;
                 $this->_id = $Store->id;
                 $this->userType = 'contact';
             } else {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             }
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 3
0
 public function actionImportUnsubcribes()
 {
     $this->pageTitle = ' Import unsubscribes | ' . Yii::app()->name;
     $this->breadcrumbs = array('Import unsubscribes');
     ini_set('auto_detect_line_endings', true);
     if (isset($_POST['import'])) {
         if (!strlen($_POST['organisation_id'])) {
             Yii::app()->user->setFlash('error', 'Choose an organisation');
         } else {
             //print_r($_FILES);
             //exit();
             if (!strlen($_FILES['csv']['name'])) {
                 Yii::app()->user->setFlash('error', 'Choose a file');
             } else {
                 $dupeCount = 0;
                 $suppressionCount = 0;
                 $emailsChecked = array();
                 $emailDupeCount = 0;
                 $totalCount = 0;
                 $noRecordCount = 0;
                 if (($handle = fopen($_FILES['csv']['tmp_name'], "r")) !== FALSE) {
                     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                         if (sizeof($data) > 1) {
                             Yii::app()->user->setFlash('error', 'File should only contain 1 column');
                             break;
                         } else {
                             $totalCount++;
                             $Store = new Store();
                             $email = strtolower(trim(mb_convert_encoding($data[0], 'UTF-8')));
                             if (in_array($email, $emailsChecked)) {
                                 $emailDupeCount++;
                                 continue;
                             }
                             //add email to emails checked
                             $emailsChecked[] = $email;
                             //print $Store->encryptEmail(trim(mb_convert_encoding($data[0], 'UTF-8')));exit();
                             // Check for matching email in store table
                             $StoreRows = Store::model()->with('store2contact')->findAll(array('condition' => 'origin_organisation_id = :org_id AND email = :email', 'params' => array(':email' => $Store->encryptEmail($email), ':org_id' => (int) $_POST['organisation_id'])));
                             if (sizeof($StoreRows)) {
                                 foreach ($StoreRows as $Store) {
                                     if (is_null($Store->store2contact)) {
                                         continue;
                                     }
                                     // Check for existing based on store2contact id
                                     $Suppression = SuppressionList::model()->find(array('condition' => 'store2contact_id = :store2contact_id', 'params' => array(':store2contact_id' => $Store->store2contact->id)));
                                     if (is_null($Suppression)) {
                                         $Suppression = new SuppressionList();
                                         $Suppression->type = SuppressionList::TYPE_UNSUBSCRIBE;
                                         // always save the store id against this row
                                         $Suppression->store_id = $Store->id;
                                         $Suppression->store2contact_id = $Store->store2contact->id;
                                         //We DO NOT need the warehouse id, we're not supressing from everything.
                                         //$Suppression->warehouse_id = $Store->store2contact->contact_warehouse_id;
                                         $Suppression->date = date('Y-m-d H:i:s');
                                         if ($Suppression->save()) {
                                             $suppressionCount++;
                                         }
                                         $Store->contact_email = 0;
                                         $Store->save(true, array("contact_email"));
                                     } else {
                                         $dupeCount++;
                                     }
                                 }
                             } else {
                                 $noRecordCount++;
                             }
                         }
                     }
                     Yii::app()->user->setFlash('success', $suppressionCount . ' suppression rows saved. ' . $dupeCount . ' were already suppressed. Number of duplicate emails was ' . $emailDupeCount . '. Total number of rows processed was ' . $totalCount . '. We could not find a match for ' . $noRecordCount . '.');
                     $this->refresh();
                 }
                 fclose($handle);
             }
         }
     }
     $this->render('importUnsubcribes', array());
 }
Exemplo n.º 4
0
 public function actionOpen()
 {
     // See http://documentation.mailgun.com/user_manual.html#webhooks
     // Mail so we know we have received the opened webhook
     // Set up authorisation
     $authString = $_POST['timestamp'] . $_POST['token'];
     $authHash = hash_hmac('sha256', $authString, Yii::app()->params['mailgun']['key']);
     // Check Auth
     if ($authHash === $_POST['signature']) {
         // Huzzah! Authorized HTTP POST from Mailgun
         $uniques = array();
         $StoreModel = new Store();
         // Encrypt the email so we can find a match
         $openedEmailAddress = $StoreModel->encryptEmail($_POST['recipient']);
         // Look for this email address in store table
         $StoreRows = Store::model()->with('store2contact')->findAll(array('condition' => 'email = :email', 'params' => array(':email' => $openedEmailAddress)));
         // collect our warehouse_ids up to match in campaign_contact table.
         $warehouseIDs = [];
         if (sizeof($StoreRows)) {
             // Save 1 suppression row for every instance of the email address in the store table - use store_id
             foreach ($StoreRows as $Store) {
                 // expired? No store to contact. Skip
                 if (!is_null($Store->store2contact)) {
                     $warehouseIDs[] = $Store->store2contact->contact_warehouse_id;
                 }
             }
             // check for campaign_contacts.
             if (sizeof($warehouseIDs) && is_numeric($_POST['campaign_id']) && is_numeric($_POST['group_id'])) {
                 // it's a bounce of a campaign email. Mark against the row.
                 CampaignContact::model()->updateAll(array('opened' => date('Y-m-d H:i:s', $_POST['timestamp'])), "campaign_id = :campaign_id AND group_id = :group_id AND warehouse_id IN (" . implode(',', array_filter($warehouseIDs)) . ") AND opened IS NULL", array(':campaign_id' => $_POST['campaign_id'], ':group_id' => $_POST['group_id']));
             }
             header("HTTP/1.0 200 Ok");
             exit;
         } else {
             header("HTTP/1.0 404 Not Found");
             exit('Not Found');
         }
     } else {
         // Go away
         sleep(5);
         header("HTTP/1.0 401 Unauthorized");
         exit('Unauthorized');
     }
 }