Example #1
0
 /**
  * Displays an campaign edit view.
  *
  * Note, that the campaign for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation campaign,
  */
 public function _handler_edit_query($handler_id, array $args, array &$data)
 {
     $this->_campaign = $this->_master->load_campaign($args[0]);
     $this->_campaign->require_do('midgard:update');
     $this->_prepare_request_data($handler_id);
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "campaign/edit_query_advanced/{$this->_campaign->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('advanced rule editor'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/repair.png'));
     midcom::get('head')->enable_jquery();
     midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/org.openpsa.directmarketing/edit_query.js');
     $this->add_stylesheet(MIDCOM_STATIC_URL . '/org.openpsa.directmarketing/edit_query.css');
     $this->add_stylesheet(MIDCOM_STATIC_URL . '/org.openpsa.core/list.css');
     // PONDER: Locking ?
     if (!empty($_POST['midcom_helper_datamanager2_cancel'])) {
         return new midcom_response_relocate("campaign/{$this->_campaign->guid}/");
     }
     //check if it should be saved or preview
     if (!empty($_POST['midcom_helper_datamanager2_save']) || isset($_POST['show_rule_preview'])) {
         $eval = '$tmp_array = ' . $_POST['midcom_helper_datamanager2_dummy_field_rules'] . ';';
         $eval_ret = eval($eval);
         if ($eval_ret === false || !is_array($tmp_array)) {
             //Rule could not be parsed
             midcom::get('uimessages')->add('org.openpsa.directmarketing', $this->_l10n->get('given rule could not be parsed'), 'error');
             return;
         }
         if (count($tmp_array) == 0) {
             // Rule array is empty
             midcom::get('uimessages')->add('org.openpsa.directmarketing', $this->_l10n->get('given rule is empty'), 'error');
             return;
         }
         $rule = $tmp_array;
         //add rule was generated with wizard
         $rule['generated'] = 'wizard';
         //resolve rules
         $solver = new org_openpsa_directmarketing_campaign_ruleresolver();
         $solver->resolve($tmp_array);
         $rule_persons = $solver->execute();
         //if it's not preview update campaign & Schedule background members refresh'
         if (!isset($_POST['show_rule_preview'])) {
             $this->_campaign->rules = $rule;
             $update_ret = $this->_campaign->update();
             if (!$update_ret) {
                 //Save failed
                 midcom::get('uimessages')->add('org.openpsa.directmarketing', sprintf($this->_l10n->get('error when saving rule, errstr: %s'), midcom_connection::get_error_string()), 'error');
                 break;
             }
             //Schedule background members refresh
             $this->_campaign->schedule_update_smart_campaign_members();
             //Save ok, relocate
             return new midcom_response_relocate("campaign/{$this->_campaign->guid}/");
         }
         //set data for preview & skip page_style because of javascript call
         $data['preview_persons'] = $rule_persons;
         midcom::get()->skip_page_style = true;
     }
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this);
     $this->set_active_leaf('campaign_' . $this->_campaign->id);
     midcom::get('head')->set_pagetitle($this->_campaign->title);
     $this->bind_view_to_object($this->_campaign);
     $this->_update_breadcrumb_line($handler_id);
 }