/**
  * post-trigger of task
  */
 public function complete()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $task_id = (int) $this->request->post['task_id'];
     if ($task_id) {
         $tm = new ATaskManager();
         $tm->deleteTask($task_id);
         $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
         $backup_name = $this->request->get_or_post('backup_name');
         $backup_name = !$backup_name ? 'manual_backup' : $backup_name;
         $display_name = '';
         if (is_file(DIR_BACKUP . $backup_name . '.tar.gz')) {
             $display_name = $backup_name . '.tar.gz';
             $result_text = $this->html->convertLinks($this->language->get('backup_complete_text_file'));
         } elseif (is_dir(DIR_BACKUP . $backup_name)) {
             $display_name = $backup_name . '/...';
             $result_text = sprintf($this->language->get('backup_complete_text_dir'), DIR_BACKUP . $backup_name);
         }
         $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Manual Backup', 'version' => VERSION, 'backup_file' => $display_name, 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode(array('result' => true, 'result_text' => $result_text)));
 }
Beispiel #2
0
 public function delete()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $id = (int) $this->request->get_or_post('task_id');
     if ($id) {
         $tm = new ATaskManager();
         $tm->deleteTask($id);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->redirect($this->html->getSecureURL('tool/task'));
 }
 public function getTask()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!has_value($this->request->get['task_name'])) {
         $this->data['output'] = array('error' => true, 'error_text' => 'Error: Do not know what to run.');
     } else {
         $task_obj = new ATaskManager();
         $this->data['output'] = $task_obj->getTaskByName($this->request->get['task_name']);
     }
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     if ($this->data['output']) {
         $output = AJson::encode($this->data['output']);
     } else {
         $output = array('error' => true, 'error_text' => 'Error: Cannot find task "' . $this->request->get['task_name'] . '".');
     }
     $this->response->setOutput($output);
 }
Beispiel #4
0
 /**
  * @param string $task_name
  * @param array $data
  * @return array|bool
  */
 public function createTask($task_name, $data = array())
 {
     if (!$task_name) {
         $this->errors[] = 'Can not to create task. Empty task name has been given.';
     }
     //first of all needs to define recipient count
     $this->load->model('sale/customer');
     $this->load->model('setting/store');
     $store_info = $this->model_setting_store->getStore((int) $this->session->data['current_store_id']);
     if ($store_info) {
         $store_name = $store_info['store_name'];
     } else {
         $store_name = $this->config->get('store_name');
     }
     //get URIs of recipients
     if ($data['protocol'] == 'email') {
         list($uris, $subscribers) = $this->_get_email_list($data);
         $task_controller = 'task/sale/contact/sendEmail';
         //if message does not contains html-tags replace breaklines to <br>
         $decoded = html_entity_decode($data['message'], ENT_QUOTES, 'UTF-8');
         if ($decoded == strip_tags($decoded)) {
             $data['message'] = nl2br($data['message']);
         }
     } elseif ($data['protocol'] == 'sms') {
         list($uris, $subscribers) = $this->_get_phone_list($data);
         $task_controller = 'task/sale/contact/sendSms';
     }
     if (!$uris) {
         $this->errors[] = 'No recipients!';
         return false;
     }
     //numbers of emails per task step
     $divider = 10;
     //timeout in seconds for one email send
     $time_per_send = 4;
     $steps_count = ceil(sizeof($uris) / $divider);
     $tm = new ATaskManager();
     //create new task
     $task_id = $tm->addTask(array('name' => $task_name, 'starter' => 1, 'created_by' => $this->user->getId(), 'status' => 1, 'start_time' => date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))), 'last_time_run' => '0000-00-00 00:00:00', 'progress' => '0', 'last_result' => '1', 'run_interval' => '0', 'max_execution_time' => sizeof($uris) * $time_per_send * 2));
     if (!$task_id) {
         $this->errors = array_merge($this->errors, $tm->errors);
         return false;
     }
     $tm->updateTaskDetails($task_id, array('created_by' => $this->user->getId(), 'settings' => array('recipients_count' => sizeof($uris), 'sent' => 0)));
     //create steps for sending
     $k = 0;
     $sort_order = 1;
     while ($steps_count > 0) {
         $uri_list = array_slice($uris, $k, $divider);
         $step_id = $tm->addStep(array('task_id' => $task_id, 'sort_order' => $sort_order, 'status' => 1, 'last_time_run' => '0000-00-00 00:00:00', 'last_result' => '0', 'max_execution_time' => $time_per_send * $divider * 2, 'controller' => $task_controller, 'settings' => array('to' => $uri_list, 'subject' => $data['subject'], 'message' => $data['message'], 'store_name' => $store_name, 'subscribers' => $subscribers)));
         if (!$step_id) {
             $this->errors = array_merge($this->errors, $tm->errors);
             return false;
         } else {
             // get eta in seconds
             $this->eta[$step_id] = $time_per_send * $divider;
         }
         $steps_count--;
         $k = $k + $divider;
         $sort_order++;
     }
     $task_details = $tm->getTaskById($task_id);
     if ($task_details) {
         foreach ($this->eta as $step_id => $eta) {
             $task_details['steps'][$step_id]['eta'] = $eta;
             //remove settings from output json array. We will take it from database on execution.
             $task_details['steps'][$step_id]['settings'] = array();
         }
         return $task_details;
     } else {
         $this->errors[] = 'Can not to get task details for execution';
         $this->errors = array_merge($this->errors, $tm->errors);
         return false;
     }
 }
Beispiel #5
0
 private function _send()
 {
     $this->loadLanguage('sale/contact');
     $task_id = (int) $this->request->get['task_id'];
     $step_id = (int) $this->request->get['step_id'];
     if (!$task_id || !$step_id) {
         $error_text = 'Cannot run task step. Task_id (or step_id) has not been set.';
         $this->_return_error($error_text);
     }
     $tm = new ATaskManager();
     $task_info = $tm->getTaskById($task_id);
     $sent = (int) $task_info['settings']['sent'];
     $task_steps = $tm->getTaskSteps($task_id);
     $step_info = array();
     foreach ($task_steps as $task_step) {
         if ($task_step['step_id'] == $step_id) {
             $step_info = $task_step;
             if ($task_step['sort_order'] == 1) {
                 $tm->updateTask($task_id, array('last_time_run' => date('Y-m-d H:i:s')));
             }
             break;
         }
     }
     if (!$step_info) {
         $error_text = 'Cannot run task step. Looks like task #' . $task_id . ' does not contain step #' . $step_id;
         $this->_return_error($error_text);
     }
     $tm->updateStep($step_id, array('last_time_run' => date('Y-m-d H:i:s')));
     if (!$step_info['settings'] || !$step_info['settings']['to']) {
         $error_text = 'Cannot run task step #' . $step_id . '. Unknown settings for it.';
         $this->_return_error($error_text);
     }
     $this->loadModel('sale/customer');
     $this->loadModel('setting/store');
     $store_info = $this->model_setting_store->getStore((int) $this->session->data['current_store_id']);
     $from = '';
     if ($store_info) {
         $from = $store_info['store_main_email'];
     }
     if (!$from) {
         $from = $this->config->get('store_main_email');
     }
     $send_data = array('subject' => $step_info['settings']['subject'], 'message' => $step_info['settings']['message'], 'sender' => $step_info['settings']['store_name'], 'from' => $from);
     //send emails in loop and update task's step info for restarting if step or task failed
     $step_settings = $step_info['settings'];
     $cnt = 0;
     $step_result = true;
     foreach ($step_info['settings']['to'] as $to) {
         $send_data['subscriber'] = in_array($to, $step_info['settings']['subscribers']) ? true : false;
         if ($this->protocol == 'email') {
             $result = $this->_send_email($to, $send_data);
         } elseif ($this->protocol == 'sms') {
             $result = $this->_send_sms($to, $send_data);
         } else {
             $result = false;
         }
         if ($result) {
             //remove sent address from step
             $k = array_search($to, $step_settings['to']);
             unset($step_settings['to'][$k]);
             $tm->updateStep($step_id, array('settings' => serialize($step_settings)));
             //update task details to show them at the end
             $sent++;
             $tm->updateTaskDetails($task_id, array('created_by' => $this->user->getId(), 'settings' => array('recipients_count' => $task_info['settings']['recipients_count'], 'sent' => $sent)));
         } else {
             $step_result = false;
         }
         $cnt++;
     }
     $tm->updateStep($step_id, array('last_result' => $step_result));
     if (!$step_result) {
         $this->_return_error('Some errors during step run. See log for details.');
     }
     return $step_result;
 }
Beispiel #6
0
}
// if task details needed for ajax step-by-step run
if ($get['mode'] == 'query') {
    $get['task_name'] = $_GET['task_name'];
}
$_GET = $get;
unset($get);
$_GET['s'] = ADMIN_PATH;
// sign of admin side for controllers run from dispatcher
// Load all initial set up
require_once DIR_ROOT . '/core/init.php';
unset($_GET['s']);
// not needed anymore
ADebug::checkpoint('init end');
// Currency
$registry->set('currency', new ACurrency($registry));
//ok... let's start tasks
$tm = new ATaskManager();
if ($_GET['mode'] == 'query') {
    //$output = array();
    $tm->getTask();
    //TODO: in the future need to add ability json response for task result
} elseif ($_GET['mode'] == 'run') {
    //try to remove execution time limitation (can not work on some hosts!)
    ini_set("max_execution_time", "0");
    //start do tasks one by one
    $tm->runTasks();
}
ADebug::checkpoint('app end');
//display debug info
ADebug::display();
Beispiel #7
0
 public function incompleted()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('user/user');
     $this->data = $this->language->getASet('sale/contact');
     $tm = new ATaskManager();
     $incompleted = $tm->getTasks(array('filter' => array('name' => 'send_now')));
     $k = 0;
     foreach ($incompleted as $incm_task) {
         //show all incompleted tasks for Top Administrator user group
         if ($this->user->getUserGroupId() != 1) {
             if ($incm_task['starter'] != $this->user->getId()) {
                 continue;
             }
         }
         //define incompleted tasks by last time run
         $max_exec_time = (int) $incm_task['max_execution_time'];
         if (!$max_exec_time) {
             //if no limitations for execution time for task - think it's 2 hours
             //$max_exec_time = 7200;
             $max_exec_time = 7200;
         }
         if (time() - dateISO2Int($incm_task['last_time_run']) > $max_exec_time) {
             //get some info about task, for ex message-text and subject
             $steps = $tm->getTaskSteps($incm_task['task_id']);
             if (!$steps) {
                 $tm->deleteTask($incm_task['task_id']);
             }
             $user_info = $this->model_user_user->getUser($incm_task['starter']);
             $incm_task['starter_name'] = $user_info['username'] . ' ' . $user_info['firstname'] . ' ' . $user_info['lastname'];
             $step = current($steps);
             $step_settings = $step['settings'];
             if ($step_settings['subject']) {
                 $incm_task['subject'] = $step_settings['subject'];
             }
             $incm_task['message'] = mb_substr($step_settings['message'], 0, 300);
             $incm_task['date_added'] = dateISO2Display($incm_task['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
             $incm_task['last_time_run'] = dateISO2Display($incm_task['last_time_run'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
             $incm_task['was_sent'] = sprintf($this->language->get('text_was_sent'), $incm_task['settings']['sent'], $incm_task['settings']['recipients_count']);
             $this->data['tasks'][$k] = $incm_task;
         }
         $k++;
     }
     $this->data['restart_task_url'] = $this->html->getSecureURL('r/sale/contact/restartTask');
     $this->data['complete_task_url'] = $this->html->getSecureURL('r/sale/contact/complete');
     $this->data['abort_task_url'] = $this->html->getSecureURL('r/sale/contact/abort');
     $this->view->batchAssign($this->data);
     $this->processTemplate('responses/sale/contact_incompleted.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 /**
  * @param string $task_name
  * @param array $data
  * @return array|bool
  */
 public function createBackupTask($task_name, $data = array())
 {
     if (!$task_name) {
         $this->errors[] = 'Can not to create task. Empty task name given';
     }
     //NOTE: remove temp backup dir before process to prevent progressive increment of directory date if some backup-steps will be failed
     $bkp = new ABackup('manual_backup');
     $bkp->removeBackupDirectory();
     unset($bkp);
     $tm = new ATaskManager();
     //1. create new task
     $task_id = $tm->addTask(array('name' => $task_name, 'starter' => 1, 'created_by' => $this->user->getId(), 'status' => 1, 'start_time' => date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))), 'last_time_run' => '0000-00-00 00:00:00', 'progress' => '0', 'last_result' => '0', 'run_interval' => '0', 'max_execution_time' => '0'));
     if (!$task_id) {
         $this->errors = array_merge($this->errors, $tm->errors);
         return false;
     }
     //create step for table backup
     if ($data['table_list']) {
         //calculate estimate time for dumping of tables
         // get sizes of tables
         $table_list = array();
         foreach ($data['table_list'] as $table) {
             if (!is_string($table)) {
                 continue;
             }
             // clean
             $table_list[] = $this->db->escape($table);
         }
         $sql = "SELECT SUM(data_length + index_length - data_free) AS 'db_size'\n\t\t\t\t\tFROM information_schema.TABLES\n\t\t\t\t\tWHERE information_schema.TABLES.table_schema = '" . DB_DATABASE . "'\n\t\t\t\t\t\tAND TABLE_NAME IN ('" . implode("','", $data['table_list']) . "')\t";
         if ($prefix_len) {
             $sql .= " AND TABLE_NAME like '" . DB_PREFIX . "%'";
         }
         $result = $this->db->query($sql);
         $db_size = $result->row['db_size'];
         //size in bytes
         $step_id = $tm->addStep(array('task_id' => $task_id, 'sort_order' => 1, 'status' => 1, 'last_time_run' => '0000-00-00 00:00:00', 'last_result' => '0', 'max_execution_time' => ceil($db_size / 2794843) * 4, 'controller' => 'task/tool/backup/dumptables', 'settings' => array('table_list' => $data['table_list'], 'sql_dump_mode' => $data['sql_dump_mode'])));
         if (!$step_id) {
             $this->errors = array_merge($this->errors, $tm->errors);
             return false;
         } else {
             // get eta in seconds. 2794843 - "bytes per seconds" of dumping for Pentium(R) Dual-Core CPU E5200 @ 2.50GHz × 2
             $this->eta[$step_id] = ceil($db_size / 2794843) * 4;
             $this->est_backup_size += ceil($db_size * 1.61);
             // size of sql-file of output
         }
     }
     //create step for content-files backup
     if ($data['backup_code']) {
         //calculate estimate time for copying of code
         $dirs_size = $this->getCodeSize();
         $step_id = $tm->addStep(array('task_id' => $task_id, 'sort_order' => 2, 'status' => 1, 'last_time_run' => '0000-00-00 00:00:00', 'last_result' => '0', 'max_execution_time' => ceil($dirs_size / 28468838), 'controller' => 'task/tool/backup/backupCodeFiles', 'settings' => array('interrupt_on_step_fault' => false)));
         if (!$step_id) {
             $this->errors = array_merge($this->errors, $tm->errors);
             return false;
         } else {
             //// get eta in seconds. 28468838 - "bytes per seconds" of copiing of files for SATA III hdd
             $this->eta[$step_id] = ceil($dirs_size / 28468838);
             $this->est_backup_size += $dirs_size;
         }
     }
     //create step for content-files backup
     if ($data['backup_content']) {
         //calculate estimate time for copying of content files
         $dirs_size = $this->getContentSize();
         $step_id = $tm->addStep(array('task_id' => $task_id, 'sort_order' => 3, 'status' => 1, 'last_time_run' => '0000-00-00 00:00:00', 'last_result' => '0', 'max_execution_time' => ceil($dirs_size / 28468838), 'controller' => 'task/tool/backup/backupContentFiles', 'settings' => array('interrupt_on_step_fault' => false)));
         if (!$step_id) {
             $this->errors = array_merge($this->errors, $tm->errors);
             return false;
         } else {
             //// get eta in seconds. 28468838 - "bytes per seconds" of copiing of files for SATA III hdd
             $this->eta[$step_id] = ceil($dirs_size / 28468838);
             $this->est_backup_size += $dirs_size;
         }
     }
     //create last step for compressing backup
     if ($data['compress_backup']) {
         $step_id = $tm->addStep(array('task_id' => $task_id, 'sort_order' => 4, 'status' => 1, 'last_time_run' => '0000-00-00 00:00:00', 'last_result' => '0', 'max_execution_time' => ceil($this->est_backup_size / 18874368), 'controller' => 'task/tool/backup/compressbackup'));
         if (!$step_id) {
             $this->errors = array_merge($this->errors, $tm->errors);
             return false;
         } else {
             //// get eta in seconds. 18874368 - "bytes per seconds" of gz-compression, level 1 on
             // AMD mobile Athlon XP2400+ 512 MB RAM Linux 2.6.12-rc4 gzip 1.3.3
             $this->eta[$step_id] = ceil($this->est_backup_size / 18874368);
         }
     }
     $task_details = $tm->getTaskById($task_id);
     if ($task_details) {
         foreach ($this->eta as $step_id => $eta) {
             $task_details['steps'][$step_id]['eta'] = $eta;
         }
         return $task_details;
     } else {
         $this->errors[] = 'Can not to get task details for execution';
         $this->errors = array_merge($this->errors, $tm->errors);
         return false;
     }
 }
Beispiel #9
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!has_value($this->data['protocol'])) {
         $this->data['protocol'] = 'email';
     }
     $this->document->setTitle($this->language->get('text_send_' . $this->data['protocol']));
     $this->loadModel('sale/customer');
     $this->data['token'] = $this->session->data['token'];
     if (isset($this->error)) {
         $this->data['error_warning'] = '';
         foreach ($this->error as $message) {
             $this->data['error_warning'] .= $message . '<br/>';
         }
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->error['subject'])) {
         $this->data['error_subject'] = $this->error['subject'];
     } else {
         $this->data['error_subject'] = '';
     }
     if (isset($this->error['message'])) {
         $this->data['error_message'] = $this->error['message'];
     } else {
         $this->data['error_message'] = '';
     }
     if (isset($this->error['recipient'])) {
         $this->data['error_recipient'] = $this->error['recipient'];
     } else {
         $this->data['error_recipient'] = '';
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('sale/contact'), 'text' => $this->language->get('text_send_' . $this->data['protocol']), 'separator' => ' :: ', 'current' => true));
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     $this->data['action'] = $this->html->getSecureURL('sale/contact');
     $this->data['cancel'] = $this->html->getSecureURL('sale/contact');
     //get store from main switcher and current config
     $this->data['store_id'] = (int) $this->session->data['current_store_id'];
     $this->data['customers'] = array();
     $this->data['products'] = array();
     $this->loadModel('catalog/product');
     $customer_ids = $this->request->get_or_post('to');
     if (!$customer_ids && has_value($this->session->data['sale_contact_presave']['to'])) {
         $customer_ids = $this->session->data['sale_contact_presave']['to'];
     }
     $product_ids = $this->request->get_or_post('products');
     if (!$product_ids && has_value($this->session->data['sale_contact_presave']['products'])) {
         $product_ids = $this->session->data['sale_contact_presave']['products'];
     }
     //process list of customer or product IDs to be notified
     if (isset($customer_ids) && is_array($customer_ids)) {
         foreach ($customer_ids as $customer_id) {
             $customer_info = $this->model_sale_customer->getCustomer($customer_id);
             if ($customer_info) {
                 $this->data['customers'][$customer_info['customer_id']] = $customer_info['firstname'] . ' ' . $customer_info['lastname'] . ' (' . $customer_info['email'] . ')';
             }
         }
     }
     if (isset($product_ids) && is_array($product_ids)) {
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($product_ids as $product_id) {
             $product_info = $this->model_catalog_product->getProduct($product_id);
             if ($product_info) {
                 $thumbnail = $thumbnails[$product_id];
                 $this->data['products'][$product_id] = array('name' => $product_info['name'], 'image' => $thumbnail['thumb_html']);
             }
         }
     }
     foreach (array('recipient', 'subject', 'message') as $n) {
         $this->data[$n] = $this->request->post_or_get($n);
         if (!$this->data[$n] && has_value($this->session->data['sale_contact_presave'][$n])) {
             $this->data[$n] = $this->session->data['sale_contact_presave'][$n];
         }
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => 'sendFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'sendFrm', 'action' => '', 'attr' => 'data-confirm-exit="true" class="form-horizontal"'));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_send'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->data['form']['fields']['protocol'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'protocol', 'value' => $this->data['protocol']));
     $this->data['form']['build_task_url'] = $this->html->getSecureURL('r/sale/contact/buildTask');
     $this->data['form']['complete_task_url'] = $this->html->getSecureURL('r/sale/contact/complete');
     $this->data['form']['abort_task_url'] = $this->html->getSecureURL('r/sale/contact/abort');
     //set store selector
     $this->view->assign('form_store_switch', $this->html->getStoreSwitcher());
     //build recipient filter
     $options = array('' => $this->language->get('text_custom_send'));
     $db_filter = array('status' => 1, 'approved' => 1);
     if ($this->data['protocol'] == 'sms') {
         $db_filter['filter']['only_with_mobile_phones'] = 1;
     }
     $newsletter_dbfilter = $db_filter;
     $newsletter_dbfilter['filter']['newsletter_protocol'] = $this->data['protocol'];
     $all_subscribers_count = $this->model_sale_customer->getTotalAllSubscribers($newsletter_dbfilter);
     if ($all_subscribers_count) {
         $options['all_subscribers'] = $this->language->get('text_all_subscribers') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $all_subscribers_count);
     }
     $only_subscribers_count = $this->model_sale_customer->getTotalOnlyNewsletterSubscribers($newsletter_dbfilter);
     if ($only_subscribers_count) {
         $options['only_subscribers'] = $this->language->get('text_subscribers_only') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $only_subscribers_count);
     }
     $only_customers_count = $this->model_sale_customer->getTotalOnlyCustomers($db_filter);
     if ($only_customers_count) {
         $options['only_customers'] = $this->language->get('text_customers_only') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $only_customers_count);
     }
     if (sizeof($options) == 1) {
         $this->data['error_warning'] = $this->language->get('error_' . $this->data['protocol'] . '_no_recipients');
     }
     $options['ordered'] = $this->language->get('text_customers_who_ordered');
     $this->data['form']['fields']['to'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'recipient', 'value' => $this->data['recipient'], 'options' => $options, 'required' => true));
     $this->data['recipients_count_url'] = $this->html->getSecureURL('r/sale/contact/getRecipientsCount');
     $this->data['form']['fields']['customers'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'to[]', 'value' => $customer_ids, 'options' => $this->data['customers'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/listing_grid/customer/customers'), 'placeholder' => $this->language->get('text_customers_from_lookup')));
     $this->data['form']['fields']['product'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'products[]', 'value' => $product_ids, 'options' => $this->data['products'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/product/product/products'), 'placeholder' => $this->language->get('text_products_from_lookup')));
     if ($this->data['protocol'] == 'email') {
         $this->data['form']['fields']['subject'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'subject', 'value' => $this->data['subject'], 'required' => true));
     }
     $this->data['form']['fields']['message'] = $form->getFieldHtml(array('type' => $this->data['protocol'] == 'email' ? 'texteditor' : 'textarea', 'name' => 'message', 'value' => $this->data['message'], 'style' => 'ml_ckeditor', 'required' => true));
     //if email address given
     if (has_value($this->request->get['email'])) {
         $this->data['emails'] = (array) $this->request->get['email'];
     }
     $this->data['category_products'] = $this->html->getSecureURL('product/product/category');
     $this->data['customers_list'] = $this->html->getSecureURL('user/customers');
     $this->data['presave_url'] = $this->html->getSecureURL('r/sale/contact/presave');
     $this->data['help_url'] = $this->gen_help_url('send_mail');
     if ($this->data['protocol'] == 'email') {
         $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'contact', 'object_id' => '', 'types' => array('image')));
         $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
         $this->data['rl'] = $this->html->getSecureURL('common/resource_library', '&action=list_library&object_name=&object_id&type=image&mode=single');
     }
     //load tabs controller
     if ($this->data['protocol'] == 'email' || !has_value($this->data['protocol'])) {
         $this->data['active'] = 'email';
     } elseif ($this->data['protocol'] == 'sms') {
         $this->data['active'] = 'sms';
     }
     $this->data['protocols'] = array();
     $this->data['protocols']['email'] = array('title' => $this->language->get('text_email'), 'href' => $this->html->getSecureURL('sale/contact/email'), 'icon' => 'mail');
     $driver = $this->config->get('config_sms_driver');
     //if sms driver not set or disabled - redirect
     if ($driver && $this->config->get($driver . '_status')) {
         $this->data['protocols']['sms'] = array('title' => $this->language->get('text_sms'), 'href' => $this->html->getSecureURL('sale/contact/sms'));
     }
     //check for incompleted tasks
     $tm = new ATaskManager();
     $incompleted = $tm->getTasks(array('filter' => array('name' => 'send_now')));
     foreach ($incompleted as $incm_task) {
         //show all incompleted tasks for Top Administrator user group
         if ($this->user->getUserGroupId() != 1) {
             if ($incm_task['starter'] != $this->user->getId()) {
                 continue;
             }
             //rename task to prevent colission with new
             if ($incm_task['name'] == 'send_now') {
                 $tm->updateTask($incm_task['task_id'], array('name' => 'send_now_' . date('YmdHis')));
             }
         }
         //define incompleted tasks by last time run
         $max_exec_time = (int) $incm_task['max_execution_time'];
         if (!$max_exec_time) {
             //if no limitations for execution time for task - think it's 2 hours
             $max_exec_time = 7200;
         }
         if (time() - dateISO2Int($incm_task['last_time_run']) > $max_exec_time) {
             $this->data['incomplete_tasks_url'] = $this->html->getSecureURL('r/sale/contact/incompleted');
             break;
         }
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/sale/contact.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Beispiel #10
0
 public function run()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     if (has_value($this->request->post_or_get('task_id'))) {
         $tm = new ATaskManager();
         $task = $tm->getTaskById($this->request->post_or_get('task_id'));
         //check
         if ($task && $task['status'] == 1) {
             $tm->updateTask($task['task_id'], array('start_time' => date('Y-m-d H:i:s')));
         }
         $this->_run_task();
     } else {
         $this->response->setOutput(AJson::encode(array('result' => false)));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }