Esempio n. 1
0
 public function save($coupon_code)
 {
     $new = 0;
     $type = $_POST['type'];
     $_POST['coupon_code'] = aecGetParam('coupon_code', 0, true, array('word', 'string', 'clear_nonalnum'));
     if ($_POST['coupon_code'] == '') {
         $this->setMessage(JText::_('AEC_MSG_NO_COUPON_CODE'));
         return;
     }
     $cph = new couponHandler();
     if (!empty($_POST['id'])) {
         $cph->coupon = new Coupon($_POST['oldtype']);
         $cph->coupon->load($_POST['id']);
         if ($cph->coupon->id) {
             $cph->status = true;
         }
     } else {
         $cph->load($_POST['coupon_code']);
     }
     if (!$cph->status) {
         $cph->coupon = new Coupon($type);
         $cph->coupon->createNew($_POST['coupon_code']);
         $cph->status = true;
         $new = 1;
     }
     if ($cph->status) {
         if (!$new) {
             if ($cph->coupon->type != $_POST['type']) {
                 $cph->switchType();
             }
         }
         unset($_POST['type']);
         unset($_POST['oldtype']);
         unset($_POST['id']);
         $post = AECToolbox::cleanPOST($_POST, false);
         $cph->coupon->savePOSTsettings($post);
         $cph->coupon->storeload();
     } else {
         $short = 'coupon store failure';
         $event = 'When trying to store coupon';
         $tags = 'coupon,loading,error';
         $params = array();
         $eventlog = new eventLog();
         $eventlog->issue($short, $tags, $event, 128, $params);
     }
     $this->setMessage(JText::_('AEC_MSG_SUCESSFULLY_SAVED'));
 }