Example #1
0
 /**
  * reminderAction
  * This action send to every customers an email
  * reminder about their expiring services and domains
  */
 public static function remindersEmail()
 {
     $i = 0;
     $customers = array();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     /* We have to start to get all the domains that them expiring date is today
     		 then we have to create a custom array sorted by customerID in order to
     		group services and domains of a particular customer.
     		*/
     // Get all the active domains that expire in 1 day
     $domains = Domains::getExpiringDomainsByRange(0, 30, Statuses::id('active', 'domains'));
     if ($domains) {
         // Create the customer group list for the email summary
         foreach ($domains as $domain) {
             if ($domain['reseller']) {
                 $invoice_dest = Customers::getAllInfo($domain['reseller']);
                 $customers[$domain['customer_id']]['id'] = $invoice_dest['customer_id'];
                 $customers[$domain['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                 $customers[$domain['customer_id']]['email'] = $invoice_dest['email'];
                 $customers[$domain['customer_id']]['language_id'] = $invoice_dest['language_id'];
             } else {
                 $customers[$domain['customer_id']]['id'] = $domain['customer_id'];
                 $customers[$domain['customer_id']]['fullname'] = $domain['fullname'];
                 $customers[$domain['customer_id']]['email'] = $domain['email'];
                 $customers[$domain['customer_id']]['language_id'] = $domain['language_id'];
             }
             $customers[$domain['customer_id']]['products'][$i]['name'] = $domain['domain'];
             $customers[$domain['customer_id']]['products'][$i]['type'] = "domain";
             $customers[$domain['customer_id']]['products'][$i]['renew'] = $domain['renew'];
             $customers[$domain['customer_id']]['products'][$i]['expiring_date'] = $domain['expiringdate'];
             $customers[$domain['customer_id']]['products'][$i]['days'] = $domain['days'];
             $customers[$domain['customer_id']]['products'][$i]['oldorderitemid'] = $domain['detail_id'];
             $i++;
         }
     }
     /*
      * Now we have to get the services expired and we have to sum the previous $customers array with these
      * new information.
      */
     // Get all the services active that expire the day after
     $services = OrdersItems::getExpiringServicesByRange(0, 30, Statuses::id("complete", "orders"));
     if ($services) {
         // Create the customer group list for the email summary
         foreach ($services as $service) {
             if ($service['reseller']) {
                 $invoice_dest = Customers::getAllInfo($service['reseller']);
                 $customers[$service['customer_id']]['id'] = $invoice_dest['customer_id'];
                 $customers[$service['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company'];
                 $customers[$service['customer_id']]['email'] = $customer_email = Contacts::getEmails($invoice_dest['customer_id']);
                 $customers[$service['customer_id']]['password'] = $invoice_dest['password'];
                 $customers[$service['customer_id']]['language_id'] = $invoice_dest['language_id'];
             } else {
                 $customers[$service['customer_id']]['id'] = $service['id'];
                 $customers[$service['customer_id']]['fullname'] = $service['fullname'];
                 $customers[$service['customer_id']]['email'] = $customer_email = Contacts::getEmails($service['id']);
                 $customers[$service['customer_id']]['password'] = $service['password'];
                 $customers[$service['customer_id']]['language_id'] = $service['language_id'];
             }
             $customers[$service['customer_id']]['products'][$i]['name'] = $service['product'];
             $customers[$service['customer_id']]['products'][$i]['type'] = "service";
             $customers[$service['customer_id']]['products'][$i]['renew'] = $service['renew'];
             $customers[$service['customer_id']]['products'][$i]['expiring_date'] = $service['expiringdate'];
             $customers[$service['customer_id']]['products'][$i]['days'] = $service['days'];
             $customers[$service['customer_id']]['products'][$i]['oldorderitemid'] = $service['detail_id'];
             $i++;
         }
     }
     // EMAIL SUMMARY FOR ALL THE EXPIRED AND NOT AUTORENEWABLE DOMAINS/SERVICES
     // =========================================================================
     // Create the emailS for the customers
     if (count($customers) > 0) {
         // For each client do ...
         foreach ($customers as $customer) {
             $items = array();
             $translator->setLocale(Languages::get_locale($customer['language_id']));
             // Check if there are some product to be expired
             if (count($customer['products']) > 0) {
                 $i = 0;
                 // For each product do ...
                 foreach ($customer['products'] as $product) {
                     $items[$i][$translator->translate("Expiry Date")] = $product['expiring_date'];
                     $items[$i][$translator->translate("Days")] = $product['days'];
                     $items[$i][$translator->translate("Description")] = $product['name'];
                     if ($product['renew']) {
                         $items[$i][$translator->translate("Auto Renewal")] = $translator->translate("Active");
                     } else {
                         $items[$i][$translator->translate("Auto Renewal")] = $translator->translate("Not Active");
                     }
                     $i++;
                 }
             }
             $items = Shineisp_Commons_Utilities::array2table($items);
             if (!empty($items)) {
                 Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'reminder', array('items' => $items, 'fullname' => $customer['fullname']), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify'));
             }
         }
     }
     return true;
 }