示例#1
0
 function Main()
 {
     switch ($this->formArray["formAction"]) {
         case "edit":
             $this->tpl->set_var("MessageBlock", "");
             $BarangayDetails = new SoapObject(NCCBIZ . "BarangayDetails.php", "urn:Object");
             if (!($xmlStr = $BarangayDetails->getBarangayDetails($this->formArray["barangayID"]))) {
                 $this->tpl->set_block("rptsTemplate", "Table", "TableBlock");
                 $this->tpl->set_var("TableBlock", "record not found");
             } else {
                 if (!($domDoc = domxml_open_mem($xmlStr))) {
                     $this->tpl->set_block("rptsTemplate", "Table", "TableBlock");
                     $this->tpl->set_var("TableBlock", "error xmlDoc");
                 } else {
                     $barangay = new Barangay();
                     $barangay->parseDomDocument($domDoc);
                     $this->formArray["barangayID"] = $barangay->getBarangayID();
                     $this->formArray["code"] = $barangay->getCode();
                     $this->formArray["districtID"] = $barangay->getDistrictID();
                     $this->formArray["description"] = $barangay->getDescription();
                     $this->formArray["status"] = $barangay->getStatus();
                 }
             }
             break;
         case "save":
             if ($this->codeAlreadyExists() == true) {
                 $this->message = "Error. Cannot Save. Code already exists.";
                 $this->tpl->set_var("message", $this->message);
                 $this->tpl->parse("MessageBlock", "Message", true);
                 break;
             } else {
                 $this->tpl->set_var("MessageBlock", "");
             }
             $BarangayEncode = new SoapObject(NCCBIZ . "BarangayEncode.php", "urn:Object");
             if ($this->formArray["barangayID"] != "") {
                 $BarangayDetails = new SoapObject(NCCBIZ . "BarangayDetails.php", "urn:Object");
                 if (!($xmlStr = $BarangayDetails->getBarangayDetails($this->formArray["barangayID"]))) {
                     exit("record not found");
                 } else {
                     if (!($domDoc = domxml_open_mem($xmlStr))) {
                         $this->tpl->set_block("rptsTemplate", "Table", "TableBlock");
                         $this->tpl->set_var("TableBlock", "error xmlDoc");
                     } else {
                         $barangay = new Barangay();
                         $barangay->parseDomDocument($domDoc);
                         $barangay->setBarangayID($this->formArray["barangayID"]);
                         $barangay->setCode($this->formArray["code"]);
                         $barangay->setDistrictID($this->formArray["districtID"]);
                         $barangay->setDescription($this->formArray["description"]);
                         $barangay->setStatus($this->formArray["status"]);
                         $barangay->setDomDocument();
                         $doc = $barangay->getDomDocument();
                         $xmlStr = $doc->dump_mem(true);
                         //echo htmlentities($xmlStr);
                         //exit;
                         if (!($ret = $BarangayEncode->updateBarangay($xmlStr))) {
                             exit("error update");
                         }
                     }
                 }
             } else {
                 $barangay = new Barangay();
                 $barangay->setBarangayID($this->formArray["barangayID"]);
                 $barangay->setCode($this->formArray["code"]);
                 $barangay->setDistrictID($this->formArray["districtID"]);
                 $barangay->setDescription($this->formArray["description"]);
                 $barangay->setStatus($this->formArray["status"]);
                 $barangay->setDomDocument();
                 $doc = $barangay->getDomDocument();
                 $xmlStr = $doc->dump_mem(true);
                 if (!($ret = $BarangayEncode->saveBarangay($xmlStr))) {
                     exit("error save");
                 }
             }
             $this->formArray["barangayID"] = $ret;
             header("location: BarangayClose.php" . $this->sess->url("") . $this->sess->add_query(array("barangayID" => $ret)));
             //header("location: BarangayEncode.php?".$this->sess->name."=".$this->sess->id."&barangayID=".$ret.".&formAction=edit");
             exit($ret);
             break;
         case "cancel":
             //header("location: BarangayList.php??".$this->sess->name."=".$this->sess->id."&barangayID=".$ret.".&formAction=edit");
             header("location: BarangayClose.php" . $this->sess->url("") . $this->sess->add_query(array("barangayID" => $ret)));
             exit;
             break;
         default:
             $this->tpl->set_block("rptsTemplate", "BarangayID", "BarangayIDBlock");
             $this->tpl->set_var("BarangayIDBlock", "");
             $this->tpl->set_block("rptsTemplate", "ACK", "ACKBlock");
             $this->tpl->set_var("ACKBlock", "");
             $this->tpl->set_var("MessageBlock", "");
     }
     $this->setForm();
     $this->tpl->parse("templatePage", "rptsTemplate");
     $this->tpl->finish("templatePage");
     $this->tpl->p("templatePage");
 }