예제 #1
0
echo $this->headMeta();
echo $this->headLink();
$makhoisoi = $this->param->getParam("makhoisoi");
$khosoi = new Model_Khosoi();
$khosoirow = $khosoi->getWhere($makhoisoi);
$form = new Form_Formmoi_Caymoc();
//sua lai
$form->createForm($makhoisoi);
if ($this->param->isPost()) {
    $param = $this->param->getPost();
    $check = new Form_Valid_Caymoc($param, $khosoirow['SoTanSoi']);
    // sua lai
    if ($check->valid($param)) {
        $data = array("MaMoc" => null, "SoKgSoi" => $this->param->getParam("sokgsoi"), "MaVai" => $this->param->getParam("mavai"), "SoMetVai" => $this->param->getParam("sometvai"), "MaKhoSoi" => $khosoirow['MaKhoSoi']);
        $cm = new Model_Caymoc();
        $cm->insert_caymoc($data);
        //$cm_new = $cm->getMaxIndex();
        $_redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
        $_redirector->gotoUrl(HOST_PROJECT . "/index/xem/caymoc/true");
    } else {
        $form->populate($param);
        echo $form;
        echo "<div class='message'>";
        foreach ($check->messages as $item) {
            echo $item . "<br/>";
        }
        echo "</div>";
    }
} else {
    echo $form;
}
 $khomoc = $param["khomoc"];
 $thongso = array('sotansoi' => $sotansoi, 'mavai' => $mavai, 'socaymoc' => $socaymoc, 'tongsometvai' => $tongsomet, 'khomoc' => $khomoc);
 $form->populate($thongso);
 echo $form;
 $formmoc->createCayMoc($socaymoc, $mavai, $sotansoi, $tongsomet, $khomoc);
 $data = new My_Data();
 $valid = $data->isValidCaymoc($param);
 $change = false;
 $malo = $caymoc->getMaxMaLo() + 1;
 $num = new Zend_Validate_Digits();
 if (!is_array($valid)) {
     foreach ($param as $key => $item) {
         if ($num->isValid($key)) {
             $change = true;
             $data = array("MaMoc" => null, "MaVai" => $mavai, "SoMetVai" => $item, "MaKhoSoi" => $khosoirow['MaKhoSoi'], "MaLo" => $malo, 'MaKhoMoc' => $khomoc);
             $caymoc->insert_caymoc($data);
         }
     }
     if ($change) {
         $update = array("SoTanSoi" => $khosoirow['SoTanSoi'] - $param['sotan']);
         $khosoi->update_data($khosoirow['MaKhoSoi'], $update);
     }
     $_redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $_redirector->gotoUrl(HOST_PROJECT . "/index/xem/caymoc/true");
 } else {
     $formmoc->populate($param);
     echo $formmoc;
     echo "<div class='small_message'> ";
     echo $valid[0];
     echo "</div>";
 }