Example #1
0
 public function addAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     //        require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Item.php';
     //        require_once APPLICATION_PATH . '/modules/asset/forms/Item.php';
     $form = new Asset_Form_Item();
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             //                $ItemID = (int) $form->getValue('ItemID');
             $maTS = $form->getValue('MaTS');
             $tenTS = $form->getValue('TenTS');
             $descr = $form->getValue('Description');
             $type = $form->getValue('Type');
             $startDate = $form->getValue('StartDate');
             $price = $form->getValue('Price');
             $warrantyTime = $form->getValue('WarrantyTime');
             $status = $form->getValue('Status');
             $place = $form->getValue('Place');
             $item = new Asset_Model_DbTable_Item();
             $return = $item->addItem($maTS, $tenTS, $descr, $type, $startDate, $price, $warrantyTime, $status, $place);
             switch ($return) {
                 case -1:
                     // loi MaTS da ton tai
                     $status = 'Error';
                     $msg = 'MaTS is exist';
                     break;
                 case 0:
                     // loi ko add dc
                     $status = 'Error';
                     $msg = 'Can\'t add this item';
                     break;
                 case 1:
                 default:
                     // add thanh cong
                     $status = 'Success';
                     $msg = 'Add item success';
                     break;
             }
         } else {
             $status = 'Error';
             $msg = 'POST value format invaild';
         }
     } else {
         $status = 'Error';
         $msg = 'Not found POST value';
     }
     echo Zend_Json::encode(array('status' => $status, 'msg' => $msg));
 }