private function processDistribution($cronjob = array())
 {
     global $dbNewsletterArchive;
     global $dbProvider;
     global $dbContact;
     global $dbNewsletterTemplates;
     global $newsletterCommands;
     global $dbNewsletterCfg;
     global $dbNewsProcess;
     if (!isset($cronjob[dbKITnewsletterProcess::field_archiv_id])) {
         // Fehler, Aufruf ohne Archiv ID
         $this->setError(sprintf('[%s -%s] %s', __METHOD__, __LINE__, 'call function without valid Newsletter Archive ID!'));
         exit($this->getError());
     }
     // Newsletter auslesen
     $where = array();
     $where[dbKITnewsletterArchive::field_id] = $cronjob[dbKITnewsletterProcess::field_archiv_id];
     $newsletter = array();
     if (!$dbNewsletterArchive->sqlSelectRecord($where, $newsletter)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbNewsletterArchive->getError()));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     if (count($newsletter) < 1) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(kit_error_item_id, $cronjob[dbKITnewsletterProcess::field_archiv_id])));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     $newsletter = $newsletter[0];
     // Provider
     $where = array();
     $where[dbKITprovider::field_id] = intval($newsletter[dbKITnewsletterArchive::field_provider]);
     $provider = array();
     if (!$dbProvider->sqlSelectRecord($where, $provider)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbProvider->getError()));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     if (count($provider) < 1) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(kit_error_item_id, $newsletter[dbKITnewsletterArchive::field_provider])));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     $provider = $provider[0];
     // Template
     $where = array();
     $where[dbKITnewsletterTemplates::field_id] = $newsletter[dbKITnewsletterArchive::field_template];
     $template = array();
     if (!$dbNewsletterTemplates->sqlSelectRecord($where, $template)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbNewsletterTemplates->getError()));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     if (count($template) < 1) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(kit_error_item_id, $newsletter[dbKITnewsletterArchive::field_template])));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     $template = $template[0];
     $worker = explode(',', $cronjob[dbKITnewsletterProcess::field_distribution_ids]);
     $in_ids = '';
     foreach ($worker as $id) {
         $in_ids .= strlen($in_ids) > 0 ? sprintf(",'%d'", $id) : sprintf("'%d'", $id);
     }
     // Empfaenger Adressen zusammenstellen
     $SQL = sprintf("SELECT * FROM %s WHERE %s IN (%s)", $dbContact->getTableName(), dbKITcontact::field_id, $in_ids);
     $addresses = array();
     if (!$dbContact->sqlExec($SQL, $addresses)) {
         $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbContact->getError()));
         // finish newsletter process with actual status
         $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_archiv_id], 0);
         exit($this->getError());
     }
     $transmitted = 0;
     foreach ($addresses as $address) {
         // E-Mail Programm starten
         $kitMail = new kitMail($provider[dbKITprovider::field_id]);
         // HTML body generieren
         $html = $newsletter[dbKITnewsletterArchive::field_html];
         if ($newsletterCommands->parseCommands($html, '', $address[dbKITcontact::field_id], $newsletter)) {
             $html_content = $template[dbKITnewsletterTemplates::field_html];
             if (!$newsletterCommands->parseCommands($html_content, $html, $address[dbKITcontact::field_id], $newsletter)) {
                 $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $newsletterCommands->getError()));
                 // important: dont leave on error, continue the process!
                 continue;
             }
         } else {
             $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $newsletterCommands->getError()));
             // important: dont leave on error, continue the process!
             continue;
         }
         // TEXT body generieren
         $text = $newsletter[dbKITnewsletterArchive::field_text];
         if ($newsletterCommands->parseCommands($text, '', $address[dbKITcontact::field_id], $newsletter)) {
             $text_content = $template[dbKITnewsletterTemplates::field_text];
             if (!$newsletterCommands->parseCommands($text_content, $text, $address[dbKITcontact::field_id], $newsletter)) {
                 $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $newsletterCommands->getError()));
                 // important: dont leave on error, continue the process!
                 continue;
             }
         } else {
             $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $newsletterCommands->getError()));
             // important: dont leave on error, continue the process!
             continue;
         }
         // use standard email address
         $email_address = $dbContact->getStandardEMailByID($address[dbKITcontact::field_id]);
         if ($cronjob[dbKITnewsletterProcess::field_simulate] == 1) {
             // Versand wird nur simuliert!
             $this->writeNewsletterLog($cronjob[dbKITnewsletterProcess::field_id], $email_address, $address[dbKITcontact::field_id], dbCronjobNewsletterLog::status_simulation, '');
         } else {
             // send Newsletter!
             if ($kitMail->sendNewsletter($newsletter[dbKITnewsletterArchive::field_subject], $html_content, $text_content, $provider[dbKITprovider::field_email], $provider[dbKITprovider::field_name], $email_address, '', true)) {
                 $transmitted++;
                 $protocol = sprintf(kit_protocol_send_newsletter_success, $newsletter[dbKITnewsletterArchive::field_subject], date('H:i:s'), $email_address);
                 if (!$dbContact->addSystemNotice($address[dbKITcontact::field_id], $protocol)) {
                     $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE, $dbContact->getError()));
                     // important: dont leave on error, continue the process!
                     continue;
                 }
                 $this->writeNewsletterLog($cronjob[dbKITnewsletterProcess::field_id], $email_address, $address[dbKITcontact::field_id], dbCronjobNewsletterLog::status_ok, '');
             } else {
                 if (!$dbContact->addSystemNotice($address[dbKITcontact::field_id], sprintf(kit_protocol_send_newsletter_fail, $newsletter[dbKITnewsletterArchive::field_subject], date('H:i:s'), $email_address, $kitMail->getMailError()))) {
                     $this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE, $dbContact->getError()));
                     // important: dont leave on error, continue the process!
                     continue;
                 }
                 $this->writeNewsletterLog($cronjob[dbKITnewsletterProcess::field_id], $email_address, $address[dbKITcontact::field_id], dbCronjobNewsletterLog::status_error, $kitMail->getMailError());
             }
         }
         // send Newsletter
         $kitMail->__destruct();
     }
     // write newsletter process status
     $this->processNewsletterStatus($cronjob[dbKITnewsletterProcess::field_id], $transmitted);
     exit('OK');
 }