function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE);
     if ($oid) {
         $this->_id = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE);
     } else {
         $this->assign('hide_contact', TRUE);
         $this->_id = $cid;
     }
     if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
         CRM_Core_Error::fatal('We need a valid discount ID for view');
     }
     $this->assign('id', $this->_id);
     $defaults = array();
     $params = array('id' => $this->_id);
     require_once 'CRM/CiviDiscount/BAO/Item.php';
     CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
     require_once 'CRM/CiviDiscount/BAO/Track.php';
     if ($cid) {
         $rows = CRM_CiviDiscount_BAO_Track::getUsageByContact($this->_id);
     } else {
         $rows = CRM_CiviDiscount_BAO_Track::getUsageByOrg($this->_id);
     }
     $this->assign('rows', $rows);
     $this->assign('code_details', $defaults);
     $this->ajaxResponse['tabCount'] = count($rows);
     if (!empty($defaults['code'])) {
         CRM_Utils_System::setTitle($defaults['code']);
     }
 }
 function setDefaultValues()
 {
     $origID = NULL;
     $defaults = array();
     if ($this->_action & CRM_Core_Action::COPY) {
         $origID = $this->_cloneID;
     } else {
         if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
             $origID = $this->_id;
         }
     }
     if ($origID) {
         $params = array('id' => $origID);
         CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
     }
     $defaults['is_active'] = $origID ? CRM_Utils_Array::value('is_active', $defaults) : 1;
     $defaults['autodiscount_active_only'] = $origID ? CRM_Utils_Array::value('autodiscount_active_only', $defaults) : 1;
     $defaults['discount_msg_enabled'] = $origID ? CRM_Utils_Array::value('discount_msg_enabled', $defaults) : 0;
     $defaults['count_max'] = empty($defaults['count_max']) ? '' : $defaults['count_max'];
     // assign the defaults to smarty so delete can use it
     $this->assign('discountValue', $defaults);
     $this->applyFilterDefaults($defaults);
     $this->applyAutoDiscountDefaults($defaults);
     foreach ($this->_multiValued as $mv => $info) {
         if (!empty($defaults[$mv])) {
             $v = substr($defaults[$mv], 1, -1);
             $values = explode(CRM_Core_DAO::VALUE_SEPARATOR, $v);
             $defaults[$mv] = array();
             if (!empty($values)) {
                 foreach ($values as $val) {
                     $defaults[$mv][] = $val;
                 }
             }
         }
     }
     if (!empty($defaults['active_on'])) {
         list($defaults['active_on']) = CRM_Utils_Date::setDateDefaults($defaults['active_on']);
     }
     if (!empty($defaults['expire_on'])) {
         list($defaults['expire_on']) = CRM_Utils_Date::setDateDefaults($defaults['expire_on']);
     }
     if (!empty($defaults['organization_id'])) {
         $this->_orgID = $defaults['organization_id'];
     }
     // Convert if using html
     if (!empty($defaults['discount_msg'])) {
         $defaults['discount_msg'] = html_entity_decode($defaults['discount_msg']);
     }
     return $defaults;
 }
 function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
         CRM_Core_Error::fatal(ts('We need a valid discount ID for view'));
     }
     $this->assign('id', $this->_id);
     $defaults = array();
     $params = array('id' => $this->_id);
     require_once 'CRM/CiviDiscount/BAO/Item.php';
     CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
     $this->assign('code_id', $defaults['id']);
     $this->assign('code', $defaults['code']);
     $this->assign('description', $defaults['description']);
     $this->assign('amount', $defaults['amount']);
     $this->assign('amount_type', $defaults['amount_type']);
     $this->assign('count_use', $defaults['count_use']);
     $this->assign('count_max', $defaults['count_max']);
     $this->assign('is_active', $defaults['is_active']);
     $this->assign('discount_term', $defaults['discount_term']);
     if (array_key_exists('expire_on', $defaults)) {
         $this->assign('expire_on', $defaults['expire_on']);
     }
     if (array_key_exists('active_on', $defaults)) {
         $this->assign('active_on', $defaults['active_on']);
     }
     if (array_key_exists('organization_id', $defaults)) {
         $this->assign('organization_id', $defaults['organization_id']);
         require_once 'CRM/Contact/BAO/Contact.php';
         $orgname = CRM_Contact_BAO_Contact::displayName($defaults['organization_id']);
         $this->assign('organization', $orgname);
     }
     $this->_multiValued = array('autodiscount' => NULL, 'memberships' => NULL, 'events' => NULL, 'pricesets' => NULL, 'pp_types' => NULL);
     foreach ($this->_multiValued as $mv => $info) {
         if (!empty($defaults[$mv])) {
             $v = substr($defaults[$mv], 1, -1);
             $values = explode(CRM_Core_DAO::VALUE_SEPARATOR, $v);
             $defaults[$mv] = array();
             if (!empty($values)) {
                 foreach ($values as $val) {
                     $defaults[$mv][] = $val;
                 }
             }
         }
     }
     require_once 'CRM/CiviDiscount/Utils.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     if (array_key_exists('pp_types', $defaults)) {
         $pp_types = CRM_CiviDiscount_Utils::getPaymentProcessorTypes();
         $defaults['pp_types'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['pp_types'], $pp_types);
         $this->assign('pp_types', $defaults['pp_types']);
     }
     if (array_key_exists('events', $defaults)) {
         $events = CRM_CiviDiscount_Utils::getEvents();
         $defaults['events'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['events'], $events);
         $this->assign('events', $defaults['events']);
     }
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     if (array_key_exists('memberships', $defaults)) {
         $defaults['memberships'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['memberships'], $membershipTypes);
         $this->assign('memberships', $defaults['memberships']);
     }
     if (array_key_exists('autodiscount', $defaults)) {
         $defaults['autodiscount'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['autodiscount'], $membershipTypes);
         $this->assign('autodiscount', $defaults['autodiscount']);
     }
     if (array_key_exists('pricesets', $defaults)) {
         $priceSets = CRM_CiviDiscount_Utils::getPriceSets();
         $defaults['pricesets'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['pricesets'], $priceSets);
         $this->assign('pricesets', $defaults['pricesets']);
     }
     CRM_Utils_System::setTitle($defaults['code']);
 }
 function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
         CRM_Core_Error::fatal(ts('We need a valid discount ID for view'));
     }
     $this->assign('id', $this->_id);
     $defaults = array();
     $params = array('id' => $this->_id);
     require_once 'CRM/CiviDiscount/BAO/Item.php';
     CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
     require_once 'CRM/CiviDiscount/BAO/Track.php';
     $rows = CRM_CiviDiscount_BAO_Track::getUsageByCode($this->_id);
     $this->assign('rows', $rows);
     $this->assign('code_details', $defaults);
     CRM_Utils_System::setTitle($defaults['code']);
 }