/**
  * Function to perform processing before displaying form (overrides parent function)
  * 
  * @access public
  */
 function preProcess()
 {
     $this->ruleId = CRM_Utils_Request::retrieve('id', 'Integer');
     $this->rule = new CRM_Civirules_BAO_Rule();
     $this->event = new CRM_Civirules_BAO_Event();
     $this->assign('event_edit_params', false);
     $this->eventClass = false;
     if (!empty($this->ruleId)) {
         $this->rule->id = $this->ruleId;
         if (!$this->rule->find(TRUE)) {
             throw new Exception('Civirules could not find rule');
         }
         $this->event->id = $this->rule->event_id;
         if (!$this->event->find(TRUE)) {
             throw new Exception('Civirules could not find event');
         }
         $this->eventClass = CRM_Civirules_BAO_Event::getEventObjectByEventId($this->event->id, TRUE);
         $this->eventClass->setEventId($this->event->id);
         $this->eventClass->setRuleId($this->rule->id);
         $this->eventClass->setEventParams($this->rule->event_params);
         $this->assign('event_edit_params', $this->eventClass->getExtraDataInputUrl($this->ruleId));
     }
     $this->assign('eventClass', $this->eventClass);
     $ruleConditionAddUrl = CRM_Utils_System::url('civicrm/civirule/form/rule_condition', 'reset=1&action=add&rid=' . $this->ruleId, TRUE);
     $ruleActionAddUrl = CRM_Utils_System::url('civicrm/civirule/form/rule_action', 'reset=1&action=add&rid=' . $this->ruleId, TRUE);
     $this->assign('ruleConditionAddUrl', $ruleConditionAddUrl);
     $this->assign('ruleActionAddUrl', $ruleActionAddUrl);
     $this->assign('action', $this->_action);
     $this->assign('rule', $this->rule);
     $session = CRM_Core_Session::singleton();
     switch ($this->_action) {
         case CRM_Core_Action::DISABLE:
             CRM_Civirules_BAO_Rule::disable($this->ruleId);
             $session->setStatus('CiviRule disabled', 'Disable', 'success');
             CRM_Utils_System::redirect($session->readUserContext());
             break;
         case CRM_Core_Action::ENABLE:
             CRM_Civirules_BAO_Rule::enable($this->ruleId);
             $session->setStatus('CiviRule enabled', 'Enable', 'success');
             CRM_Utils_System::redirect($session->readUserContext());
             break;
     }
 }