function createNewCustomerAction() { $active_worker = FegApplication::getActiveWorker(); @($account_number = DevblocksPlatform::importGPC($_REQUEST['account_name'], 'string', '')); @($message_id = DevblocksPlatform::importGPC($_REQUEST['message_id'], 'integer', 0)); if (!$active_worker->hasPriv('core.access.customer.create')) { return; } if (empty($account_number)) { $fields = array(DAO_CustomerAccount::IMPORT_SOURCE => 0, DAO_CustomerAccount::ACCOUNT_NAME => "", DAO_CustomerAccount::ACCOUNT_NUMBER => "", DAO_CustomerAccount::IS_DISABLED => 1); } else { $fields = array(DAO_CustomerAccount::IMPORT_SOURCE => 0, DAO_CustomerAccount::ACCOUNT_NAME => "Customer # " . $account_number, DAO_CustomerAccount::ACCOUNT_NUMBER => $account_number, DAO_CustomerAccount::IS_DISABLED => 1); } // Create a new Customer Recipients $account_id = DAO_CustomerAccount::create($fields); if ($message_id > 0) { ImportCron::importAccountReProcessMessage($message_id, $account_id); } // DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('customer', $customer_id,'property'))); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('customer', $account_id, 'property'))); }
function doBulkUpdate($filter, $do, $ids = array()) { @set_time_limit(0); $change_fields = array(); $custom_fields = array(); // Make sure we have actions if (empty($do)) { return; } // Make sure we have checked items if we want a checked list if (0 == strcasecmp($filter, "checks") && empty($ids)) { return; } if (is_array($do)) { foreach ($do as $k => $v) { switch ($k) { // $change_fields[DAO_CustomerAccount::ID] = intval($v); // $change_fields[DAO_CustomerAccount::ACCOUNT_NUMBER] = intval($v); // $change_fields[DAO_CustomerAccount::ACCOUNT_NAME] = intval($v); // $change_fields[DAO_CustomerAccount::IMPORT_SOURCE] = intval($v); // [TODO] Implement actions FIXME after bulkupdate form created case 'is_disabled': $change_fields[DAO_CustomerAccount::IS_DISABLED] = intval($v); break; default: // Custom fields if (substr($k, 0, 3) == "cf_") { $custom_fields[substr($k, 3)] = $v; } } } } $pg = 0; if (empty($ids)) { do { list($objects, $null) = DAO_CustomerAccount::search(array(), $this->params, 100, $pg++, SearchFields_CustomerAccount::ID, true, false); $ids = array_merge($ids, array_keys($objects)); } while (!empty($objects)); } $batch_total = count($ids); for ($x = 0; $x <= $batch_total; $x += 100) { $batch_ids = array_slice($ids, $x, 100); DAO_CustomerAccount::update($batch_ids, $change_fields); // Custom Fields self::_doBulkSetCustomFields(FegCustomFieldSource_CustomerAccount::ID, $custom_fields, $batch_ids); unset($batch_ids); } unset($ids); }
function showMessageRecipientPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($customer_id = DevblocksPlatform::importGPC($_REQUEST['customer_id'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $display_view = 0; $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('id', $id); $tpl->assign('customer_id', $customer_id); $tpl->assign('view_id', $view_id); $message_recipient = DAO_MessageRecipient::get($id); $tpl->assign('message_recipient', $message_recipient); $message = DAO_Message::get($message_recipient->message_id); $tpl->assign('message', $message); $message_lines = explode('\\n', substr($message->message, 1, -1)); $tpl->assign('message_lines', $message_lines); $recipient = DAO_CustomerRecipient::get($message_recipient->recipient_id); $tpl->assign('recipient', $recipient); $account = DAO_CustomerAccount::get($message_recipient->account_id); $tpl->assign('account', $account); // Below is the Audit log view only avaible is the audit log plugin is enabled. if (class_exists('View_MessageAuditLog', true)) { $display_view = 1; $defaults = new Feg_AbstractViewModel(); $defaults->class_name = 'View_MessageAuditLog'; $defaults->id = '_message_recipient_audit_log'; $defaults->renderLimit = 10; $defaults->renderSortBy = SearchFields_MessageAuditLog::CHANGE_DATE; $defaults->renderSortAsc = false; $defaults->params = array(); $view = Feg_AbstractViewLoader::getView($defaults->id, $defaults); $view->name = 'Message Recipient Audit Log'; $view->renderTemplate = 'peek_tab'; $view->params = array(SearchFields_MessageAuditLog::MESSAGE_RECIPIENT_ID => new DevblocksSearchCriteria(SearchFields_MessageAuditLog::MESSAGE_RECIPIENT_ID, DevblocksSearchCriteria::OPER_EQ, $id)); $view->renderPage = 0; $view->renderLimit = 10; $view->view_columns = array(SearchFields_MessageAuditLog::CHANGE_DATE, SearchFields_MessageAuditLog::WORKER_ID, SearchFields_MessageAuditLog::CHANGE_FIELD, SearchFields_MessageAuditLog::CHANGE_VALUE); Feg_AbstractViewLoader::setView($view->id, $view); $tpl->assign('view', $view); } $tpl->assign('display_view', $display_view); $tpl->display('file:' . $this->_TPL_PATH . 'customer/tabs/recent/peek.tpl'); }
function ExportFax(Model_ExportType $export_type) { $logger = DevblocksPlatform::getConsoleLog(); $db = DevblocksPlatform::getDatabaseService(); @($fax_current_hour = 0); @($fax_sent_today = 0); $memory_limit = ini_get('memory_limit'); if (substr($memory_limit, 0, -1) < 128) { @ini_set('memory_limit', '128M'); } @set_time_limit(0); // Unlimited (if possible) $logger->info("[Fax Exporter] Overloaded memory_limit to: " . ini_get('memory_limit')); $logger->info("[Fax Exporter] Overloaded max_execution_time to: " . ini_get('max_execution_time')); $timeout = ini_get('max_execution_time'); $runtime = microtime(true); $sql = sprintf("SELECT mr.id " . "FROM message_recipient mr " . "inner join customer_recipient cr on mr.recipient_id = cr.id " . "WHERE mr.send_status in (0,3,4) " . "AND cr.is_disabled = 0 " . "AND cr.export_type = %d " . "AND cr.type = 1 ", $export_type->id); $rs = $db->Execute($sql); // Loop though pending outbound emails. while ($row = mysql_fetch_assoc($rs)) { $id = $row['id']; $logger->info("[Fax Exporter] Procing MR ID: " . $id); $message_recipient = DAO_MessageRecipient::get($id); $message = DAO_Message::get($message_recipient->message_id); $message_lines = explode('\\n', substr($message->message, 1, -1)); $recipient = DAO_CustomerRecipient::get($message_recipient->recipient_id); $account = DAO_CustomerAccount::get($message_recipient->account_id); $message_str = implode("\r\n", $message_lines); // FIXME - Need to add in filter for now everything is unfiltered. // sendFax($phone_number, $message, $subject, $to, $account_name, $from=null, ) $fax_info = FegFax::sendFax($recipient->address, $message_str, $recipient->subject, $recipient->address_to, $account->account_number); if ($fax_info['status']) { $fax_current_hour++; $fax_sent_today++; $fields = array(DAO_MessageRecipient::SEND_STATUS => 5, DAO_MessageRecipient::FAX_ID => $fax_info['jobid']); $logger->info("[FAX Exporter] Fax added to queue"); } else { $fields = array(DAO_MessageRecipient::SEND_STATUS => 1, DAO_MessageRecipient::FAX_ID => 0); $logger->info("[FAX Exporter] Failed to add fax to queue"); } DAO_MessageRecipient::update($id, $fields); // Give plugins a chance to run export $eventMgr = DevblocksPlatform::getEventService(); $eventMgr->trigger(new Model_DevblocksEvent('cron.queue.fax', array('account' => $account, 'recipient' => $recipient, 'message' => $message, 'message_lines' => $message_lines, 'message_recipient' => $message_recipient, 'queue_status' => $fax_info['status'], 'fax_id' => $fax_info['status'] ? $fax_info['jobid'] : 0))); } mysql_free_result($rs); if ($fax_current_hour) { $current_fields = DAO_Stats::get(0); $fields = array(DAO_Stats::FAX_CURRENT_HOUR => $current_fields->fax_current_hour + $fax_current_hour, DAO_Stats::FAX_SENT_TODAY => $current_fields->fax_sent_today + $fax_sent_today); DAO_Stats::update(0, $fields); } return NULL; }
/** * @param Model_DevblocksEvent $event */ function handleEvent(Model_DevblocksEvent $event) { $translate = DevblocksPlatform::getTranslationService(); switch ($event->id) { case 'cron.maint': DAO_MessageAuditLog::maint(); break; case 'cron.import': // Is a worker around to invoke this change? 0 = automatic /* @$worker_id = (null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id)) ? $active_worker->id : 0; $fields = array( DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => 0, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => 0, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cron.import', DAO_MessageAuditLog::CHANGE_VALUE => 'Cron Importer Ran', ); $log_id = DAO_MessageAuditLog::create($fields); */ break; case 'cron.reprocessing.accounts': @($account_id = $event->params['account_id']); @($message_id = $event->params['message_id']); @($import_source = $event->params['import_source']); if ($account_id == 0) { break; } // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.status', DAO_MessageAuditLog::CHANGE_VALUE => sprintf("Message ID %d assocated to Account ID %d", $message_id, $account_id)); $log_id = DAO_MessageAuditLog::create($fields); break; case 'cron.export': // Is a worker around to invoke this change? 0 = automatic /* @$worker_id = (null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id)) ? $active_worker->id : 0; $fields = array( DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => 0, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => 0, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cron.export', DAO_MessageAuditLog::CHANGE_VALUE => 'Cron Exporter Ran', ); $log_id = DAO_MessageAuditLog::create($fields); */ break; case 'cron.send.email': @($recipient = $event->params['recipient']); @($message = $event->params['message']); @($message_recipient = $event->params['message_recipient']); @($message_text = $event->params['message_text']); @($send_status = $event->params['send_status']); $fields = array(DAO_MessageAuditLog::WORKER_ID => 0, DAO_MessageAuditLog::ACCOUNT_ID => $message_recipient->account_id, DAO_MessageAuditLog::RECIPIENT_ID => $message_recipient->recipient_id, DAO_MessageAuditLog::MESSAGE_ID => $message_recipient->message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => $message_recipient->id, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cs.message.email.send', DAO_MessageAuditLog::CHANGE_VALUE => $send_status ? "Successful Sent" : "Failed to Send"); $log_id = DAO_MessageAuditLog::create($fields); break; case 'cron.queue.fax': @($recipient = $event->params['recipient']); @($message = $event->params['message']); @($message_recipient = $event->params['message_recipient']); @($message_text = $event->params['message_text']); @($queue_status = $event->params['queue_status']); @($fax_id = $event->params['fax_id']); $fields = array(DAO_MessageAuditLog::WORKER_ID => 0, DAO_MessageAuditLog::ACCOUNT_ID => $message_recipient->account_id, DAO_MessageAuditLog::RECIPIENT_ID => $message_recipient->recipient_id, DAO_MessageAuditLog::MESSAGE_ID => $message_recipient->message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => $message_recipient->id, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cs.message.fax.queue', DAO_MessageAuditLog::CHANGE_VALUE => $queue_status ? "Fax successful queue with ID: " . $fax_id : "Failed to Queue"); $log_id = DAO_MessageAuditLog::create($fields); break; case 'cron.send.snpp': @($recipient = $event->params['recipient']); @($message = $event->params['message']); @($message_recipient = $event->params['message_recipient']); @($message_text = $event->params['message_text']); @($send_status = $event->params['send_status']); $fields = array(DAO_MessageAuditLog::WORKER_ID => 0, DAO_MessageAuditLog::ACCOUNT_ID => $message_recipient->account_id, DAO_MessageAuditLog::RECIPIENT_ID => $message_recipient->recipient_id, DAO_MessageAuditLog::MESSAGE_ID => $message_recipient->message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => $message_recipient->id, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cs.message.snpp.send', DAO_MessageAuditLog::CHANGE_VALUE => $send_status ? "Successful Sent" : "Failed to Send"); $log_id = DAO_MessageAuditLog::create($fields); break; case 'dao.customer.account.update': @($objects = $event->params['objects']); foreach ($objects as $object_id => $object) { $model = $object['model']; $changes = $object['changes']; // Filter out any changes we could care less about //unset($changes[DAO_CustomerAccount::IS_DISABLED]); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); if (!empty($changes)) { foreach ($changes as $key => $change) { $value = $change['to']; if (is_array($value)) { $value = implode("\r\n", $value); } $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $model['id'], DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => 0, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => "auditlog.ca." . $key, DAO_MessageAuditLog::CHANGE_VALUE => substr($value, 0, 128)); $log_id = DAO_MessageAuditLog::create($fields); } } } break; case 'dao.customer.recipient.update': @($objects = $event->params['objects']); foreach ($objects as $object_id => $object) { $model = $object['model']; $changes = $object['changes']; // Filter out any changes we could care less about //unset($changes[DAO_CustomerAccount::IS_DISABLED]); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); if (!empty($changes)) { foreach ($changes as $key => $change) { $value = $change['to']; if (is_array($value)) { $value = implode("\r\n", $value); } if ($key == 'cr.type') { $value = $translate->_('auditlog.cr.type_' . $value); if ($value == "") { $value = $translate->_('auditlog.cr.type_unknown'); } } $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $model['account_id'], DAO_MessageAuditLog::RECIPIENT_ID => $model['id'], DAO_MessageAuditLog::MESSAGE_ID => 0, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => "auditlog.cr." . $key, DAO_MessageAuditLog::CHANGE_VALUE => substr($value, 0, 128)); $log_id = DAO_MessageAuditLog::create($fields); } } } break; case 'message.account.assign': @($account_id = $event->params['account_id']); @($message_id = $event->params['message_id']); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); $account = DAO_CustomerAccount::get($account_id); $assign_text = "Message id: " . $message_id . " assigned to account: " . $account->account_number; $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.assign', DAO_MessageAuditLog::CHANGE_VALUE => $assign_text); $log_id = DAO_MessageAuditLog::create($fields); break; case 'message.create': @($account_id = $event->params['account_id']); @($message_id = $event->params['message_id']); @($message_text = $event->params['message_text']); $fields = array(DAO_MessageAuditLog::WORKER_ID => 0, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.created', DAO_MessageAuditLog::CHANGE_VALUE => sprintf("Message created for account %d", $account_id)); $log_id = DAO_MessageAuditLog::create($fields); break; case 'message.recipient.create': @($account_id = $event->params['account_id']); @($recipient_id = $event->params['recipient_id']); @($message_id = $event->params['message_id']); @($message_recipient_id = $event->params['message_recipient_id']); @($message_text = $event->params['message_text']); $cr_id = array_shift(DAO_CustomerRecipient::getWhere(sprintf("%s = %d", DAO_CustomerRecipient::ID, $recipient_id))); switch ($cr_id->type) { case 0: // Email @($send_type = "Email"); break; case 1: // Fax @($send_type = "Fax"); break; case 2: // SNPP @($send_type = "Page"); break; default: @($send_type = "Unknown"); break; } @($change_value = sprintf("%s Scheduled for %s <'%s'>", $send_type, $cr_id->address_to, $cr_id->address)); $fields = array(DAO_MessageAuditLog::WORKER_ID => 0, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => $recipient_id, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => $message_recipient_id, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.recipient.created', DAO_MessageAuditLog::CHANGE_VALUE => $change_value); $log_id = DAO_MessageAuditLog::create($fields); break; case 'message.recipient.status': @($message_recipient_id = $event->params['message_recipient_id']); @($account_id = $event->params['account_id']); @($recipient_id = $event->params['recipient_id']); @($message_id = $event->params['message_id']); @($send_status = $event->params['send_status']); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); $status_text = $translate->_('feg.message_recipient.status_' . $send_status); if ($status_text == "") { $status_text = $translate->_('feg.core.send_status.unknown'); } $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => $recipient_id, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => $message_recipient_id, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.recipient.status', DAO_MessageAuditLog::CHANGE_VALUE => $status_text); $log_id = DAO_MessageAuditLog::create($fields); break; case 'message.status': @($account_id = $event->params['account_id']); @($message_id = $event->params['message_id']); @($import_status = $event->params['import_status']); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = FegApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); $status_text = $translate->_('feg.message.import_status_' . $import_status); if ($status_text == "") { $status_text = $translate->_('feg.core.send_status.unknown'); } $fields = array(DAO_MessageAuditLog::WORKER_ID => $worker_id, DAO_MessageAuditLog::ACCOUNT_ID => $account_id, DAO_MessageAuditLog::RECIPIENT_ID => 0, DAO_MessageAuditLog::MESSAGE_ID => $message_id, DAO_MessageAuditLog::MESSAGE_RECIPIENT_ID => 0, DAO_MessageAuditLog::CHANGE_DATE => time(), DAO_MessageAuditLog::CHANGE_FIELD => 'auditlog.cf.message.status', DAO_MessageAuditLog::CHANGE_VALUE => $status_text); $log_id = DAO_MessageAuditLog::create($fields); break; } }