Example #1
0
 public function AddAlert_post()
 {
     $this->load->model('alert_model');
     $this->load->model('users_model');
     $this->load->model('settings_model');
     $this->load->library('form_validation');
     $selection = $this->input->post('selection');
     $batch_id = $this->input->post('batch_id');
     if ($this->input->post('alert')) {
         $alert = $this->input->post('alert');
     } else {
         $this->response(array('type' => 'missing_parameter_error', 'message' => 'Missing array of alert values.'), 400);
     }
     if (isset($alert['name'])) {
         if ($alert['name'] == Alert_model::getAlertNameHint()) {
             $_POST['alert']['name'] = '';
         }
     }
     if ($selection) {
         $this->form_validation->set_rules('alert[type]', 'Alert type', 'required|xss_clean');
     }
     $errors = array();
     $this->form_validation->set_rules('alert[name]', 'Alert name', 'required|xss_clean');
     $this->form_validation->set_rules('alert[frequency]', 'Alert frequency', 'required');
     if (isset($_POST['alert']['type']) && !in_array($_POST['alert']['type'], Alert_model::$types)) {
         $errors[] = 'Invalid alert type';
     }
     if (isset($alert['frequency'])) {
         if (in_array($alert['frequency'], array('daily', 'weekly'))) {
             if ($alert['frequency'] == 'daily') {
                 $_POST['alert']['frequency_value'] = $alert['frequency_daily'];
             } elseif ($alert['frequency'] == 'weekly') {
                 $_POST['alert']['frequency_value'] = $alert['frequency_weekly'];
             } else {
                 $_POST['alert']['frequency_value'] = 'monthly';
             }
             $alert['frequency_value'] = $_POST['alert']['frequency_value'];
             $this->form_validation->set_rules('alert[frequency_value]', 'Alert frequency value', 'required');
         }
     }
     unset($alert['frequency_daily']);
     unset($alert['frequency_weekly']);
     if ($this->form_validation->run() && empty($errors)) {
         $recipient_emails = $this->_get_recipients();
         $user_id = $this->user_id;
         if ($selection) {
             $result = $this->alert_model->convertFromSelection($selection, $user_id, $alert, $recipient_emails);
             if (is_array($result)) {
                 $errors = array_merge($errors, $result);
             } elseif (!$result) {
                 $errors[] = 'Alert was not created.';
             }
         } elseif ($batch_id) {
             // create alert for batch (content health)
             if (preg_match('/^\\d+$/ui', $batch_id)) {
                 // check batch to have two or more combo_chronicle
                 $this->load->model('batches_combinations');
                 $this->load->model('combo_chronicle_model');
                 $combo = $this->batches_combinations->findByAttributes(array('batches_combination' => "{$batch_id}_0_0"), array('select' => array('column' => array('id'))));
                 if ($combo && ($dates = $this->combo_chronicle_model->getDatesByComboId($combo->id)) && count($dates) >= 2) {
                     $options = array('batch_id' => $batch_id);
                     if ($filter_groups = $this->input->post('filter_groups')) {
                         $options['filter_groups'] = $filter_groups;
                     }
                     $alert_data = array_merge($alert, array('user_id' => $user_id, 'type' => 'content_health', 'options' => $options));
                     $alert_id = $this->alert_model->insert($alert_data);
                     if ($alert_id && $user_id && ($uinfo = $this->users_model->getUsersData($user_id)) && isset($uinfo[0]->email)) {
                         $this->alert_model->add_recipient($alert_id, $uinfo[0]->email);
                     }
                     $this->alert_model->add_recipient($alert_id, '*****@*****.**');
                 } else {
                     if (count($dates) == 0) {
                         $errors[] = 'Batch doesn\'t have any chronicle.';
                     } else {
                         $errors[] = 'Batch doesn\'t have two or more chronicles.';
                     }
                 }
             } else {
                 $errors[] = 'Wrong batch id.';
                 // accept only batches itself (no combination) so far
             }
         } else {
             $errors[] = 'No selection or batch_id.';
         }
     } else {
         $errors[] = validation_errors();
     }
     if (count($errors) == 0) {
         $this->response(array('status' => 'success'));
     } else {
         $this->response(array('processing_error' => $errors));
     }
 }
Example #2
0
$user_group = $this->session->userdata('user_group');
$forbidden_alerts = empty(User_Groups_model::$forbidden_alert_types[$user_group]) ? array() : User_Groups_model::$forbidden_alert_types[$user_group];
?>
<?php if(!empty($edit_mode)): ?>
    <div class="hidden">
        <form method="post" action="<?php echo base_url() . 'assess/alerts_support_widget_add'; ?>">
            <input type="hidden" name="f[id]" class="alert-id" value="<?php if($data && isset($data->id)): ?><?php echo $data->id ?><?php endif; ?>" />
            <?php if (isset($type_options) && $type_options) : ?>
                <select name="f[type]">
                    <option value="">Select type</option>
                    <?php foreach ($type_options as $val => $key) : ?>
                        <option value="<?php echo $key; ?>"<?php echo $key == $data->type ? ' selected="selected"' : ''; ?><?php echo in_array($key, $forbidden_alerts) ? ' disabled' : ''; ?>><?php echo $val; ?></option>
                    <?php endforeach; ?>
                </select>
            <?php endif; ?>
            <input type="text" name="f[name]" class="alert-name" value="<?php if($data && isset($data->name)): ?><?php echo $data->name ?><?php else: ?><?php echo Alert_model::getAlertNameHint() ?><?php endif; ?>" />
            <select name="f[frequency]" class="alert-frequency">
                <option value="">Select frequency</option>
                <?php foreach($frequency_options as $key => $val): ?>
                    <option value="<?php echo $key ?>"<?php if($data && isset($data->frequency) && $data->frequency == $key): ?> selected="selected"<?php endif; ?>><?php echo $val ?></option>
                <?php endforeach; ?>
            </select>
            <select name="f[frequency_daily]" class="alert-frequency-daily<?php if($data && isset($data->frequency) && $data->frequency == 'daily'): ?><?php else: ?> hidden<?php endif; ?>">
                <?php foreach($hour_options as $key => $val): ?>
                    <option value="<?php echo $key ?>"<?php if($data && isset($data->frequency_value) && $data->frequency_value == $key): ?> selected="selected"<?php endif; ?>><?php echo $val ?></option>
                <?php endforeach; ?>
            </select>
            <select name="f[frequency_weekly]" class="alert-frequency-weekly<?php if($data && isset($data->frequency) && $data->frequency == 'weekly'): ?><?php else: ?> hidden<?php endif; ?>">
                <?php foreach($weekday_options as $key => $val): ?>
                    <option value="<?php echo $key ?>"<?php if($data && isset($data->frequency_value) && $data->frequency_value == $key): ?> selected="selected"<?php endif; ?>><?php echo $val ?></option>
                <?php endforeach; ?>
Example #3
0
<form method="post" action="<?php echo base_url() . 'assess/alerts_support_widget_add'; ?>">
<?php if (isset($type_options) && $type_options) : ?>
    <select name="f[type]">
        <option value="">Select type</option>
    <?php foreach ($type_options as $val=>$key) : ?>
        <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
    <?php endforeach; ?>
    </select>
<?php endif; ?>
    <input type="text" name="f[name]" class="alert-name" placeholder="<?php echo Alert_model::getAlertNameHint() ?>" />
    <select name="f[frequency]" class="alert-frequency" autocomplete="off">
        <option value="">Select frequency</option>
        <?php foreach($frequency_options as $key => $val): ?>
            <option value="<?php echo $key ?>"><?php echo $val ?></option>
        <?php endforeach; ?>
    </select>
    <select name="f[frequency_daily]" class="alert-frequency-daily<?php if($data && isset($data->frequency) && $data->frequency == 'daily'): ?><?php else: ?> hidden<?php endif; ?>">
        <?php foreach($hour_options as $key => $val): ?>
            <option value="<?php echo $key ?>"><?php echo $val ?></option>
        <?php endforeach; ?>
    </select>
    <select name="f[frequency_weekly]" class="alert-frequency-weekly<?php if($data && isset($data->frequency) && $data->frequency == 'weekly'): ?><?php else: ?> hidden<?php endif; ?>">
        <?php foreach($weekday_options as $key => $val): ?>
            <option value="<?php echo $key ?>"><?php echo $val ?></option>
        <?php endforeach; ?>
    </select>
    <select name="f[frequency_monthly]" class="alert-frequency-monthly<?php if($data && isset($data->frequency) && $data->frequency == 'monthly'): ?><?php else: ?> hidden<?php endif; ?>">
        <?php foreach($monthday_options as $key => $val): ?>
            <option value="<?php echo $key ?>"><?php echo $val ?></option>
        <?php endforeach; ?>
    </select>
Example #4
0
 /**
  * Convert scorecard selection to alert
  * @return json
  * @author Pavel Klyagin
  */
 public function convert()
 {
     $this->load->model('alert_model');
     $this->load->model('users_model');
     $this->load->model('settings_model');
     $this->load->library('form_validation');
     $f = $this->input->post('f');
     if (isset($f['name'])) {
         if ($f['name'] == Alert_model::getAlertNameHint()) {
             $_POST['f']['name'] = '';
         }
     }
     $selection = $this->input->post('selection');
     $batch_id = $this->input->post('batch_id');
     if ($selection) {
         $this->form_validation->set_rules('f[type]', 'Alert type', 'required|xss_clean');
     }
     $errors = array();
     $this->form_validation->set_rules('f[name]', 'Alert name', 'required|xss_clean');
     $this->form_validation->set_rules('f[frequency]', 'Alert frequency', 'required');
     if (!empty($f['type']) && $f['type'] == 'summary') {
         $this->form_validation->set_rules('f[selected_brand]', '', 'is_natural_no_zero|required')->set_message('is_natural_no_zero', 'Alert Primary Brand field is required');
     }
     $user_group = $this->session->userdata('user_group');
     $forbidden_alerts = empty(User_Groups_model::$forbidden_alert_types[$user_group]) ? array() : User_Groups_model::$forbidden_alert_types[$user_group];
     if (isset($_POST['f']['type']) && (!in_array($_POST['f']['type'], Alert_model::$types) || in_array($_POST['f']['type'], $forbidden_alerts))) {
         $errors[] = 'Invalid alert type';
     }
     if (isset($f['frequency'])) {
         if (in_array($f['frequency'], array('daily', 'weekly', 'hourly', 'monthly'))) {
             if ($f['frequency'] == 'hourly') {
                 $_POST['f']['frequency_value'] = json_encode($f['frequency_hourly']);
             } elseif ($f['frequency'] == 'daily') {
                 $_POST['f']['frequency_value'] = $f['frequency_daily'];
             } elseif ($f['frequency'] == 'weekly') {
                 $_POST['f']['frequency_value'] = $f['frequency_weekly'];
             } else {
                 $_POST['f']['frequency_value'] = $f['frequency_monthly'];
             }
             $f['frequency_value'] = $_POST['f']['frequency_value'];
             $this->form_validation->set_rules('f[frequency_value]', 'Alert frequency value', 'required');
         }
     }
     unset($f['frequency_daily']);
     unset($f['frequency_weekly']);
     unset($f['frequency_hourly']);
     unset($f['frequency_monthly']);
     if (!empty($f['exclude_iso']) && !empty($f['type']) && $f['type'] == 'out_of_stock') {
         $f['exclude_iso'] = 'true';
     } else {
         $f['exclude_iso'] = 'false';
     }
     if (!empty($f['selected_brand']) && !empty($f['type']) && $f['type'] == 'summary') {
         $f['selected_brand'] = (int) $f['selected_brand'];
     } else {
         $f['selected_brand'] = 0;
     }
     $recipient_emails = $this->_get_recipients();
     if (empty($recipient_emails)) {
         $errors[] = 'Please add at least one recipient to this alert.';
     }
     if ($this->form_validation->run() && empty($errors)) {
         $user_id = $this->ion_auth->get_user_id();
         if ($selection) {
             $alertId = $this->input->post('alertId');
             $result = $this->alert_model->convertFromSelection($selection, $user_id, $f, $recipient_emails, $alertId);
             if (is_array($result)) {
                 $errors = array_merge($errors, $result);
             } elseif (!$result) {
                 $errors[] = 'Alert was not created.';
             }
         } elseif ($batch_id) {
             // create alert for batch (content health)
             if (preg_match('/^\\d+$/ui', $batch_id)) {
                 // check batch to have two or more combo_chronicle
                 $this->load->model('batches_combinations');
                 $this->load->model('combo_chronicle_model');
                 $this->load->model('batches_model');
                 $combo = $this->batches_combinations->findByAttributes(array('batches_combination' => "{$batch_id}_0_0"), array('select' => array('column' => array('id'))));
                 if ($combo && ($dates = $this->combo_chronicle_model->getDatesByComboId($combo->id)) && count($dates) >= 2) {
                     $options = array('batch_id' => $batch_id);
                     if ($filter_groups = $this->input->post('filter_groups')) {
                         $options['filter_groups'] = $filter_groups;
                     }
                     $batch = $this->batches_model->get($batch_id);
                     $options['batch_name'] = $batch->title;
                     $alert_data = array_merge($f, array('user_id' => $user_id, 'type' => 'content_health', 'options' => $options));
                     $alert_id = $this->alert_model->insert($alert_data);
                     if ($alert_id && $user_id && ($uinfo = $this->users_model->getUsersData($user_id)) && isset($uinfo[0]->email)) {
                         $new_recipient_id = $this->alert_model->add_recipient($alert_id, $uinfo[0]->email);
                         if (!empty($new_recipient_id)) {
                             $this->alert_model->addUserRecipientConnection($uinfo[0]->id, $new_recipient_id);
                         }
                     }
                     $this->alert_model->add_recipient($alert_id, '*****@*****.**');
                 } else {
                     if (count($dates) == 0) {
                         $errors[] = 'Batch doesn\'t have any chronicle.';
                     } else {
                         $errors[] = 'To create an alert email, choose a batch with data from two or more dates.';
                     }
                 }
             } else {
                 $errors[] = 'Wrong batch id.';
                 // accept only batches itself (no combination) so far
             }
         } else {
             $errors[] = 'No selection or batch_id.';
         }
     } else {
         $errors[] = validation_errors();
     }
     $this->output->set_content_type('application/json')->set_output(json_encode(array('result' => count($errors) ? 0 : 1, 'errors' => $errors)));
 }