Location: PHPKode > projects > IPD's eGovernance Application Suite > bbis/trunk/update.php
<?php
    include_once('include/functions.php');
    include_once('include/constants.php');    
    include_once('smarty_survey.php');
    include_once('pear/DB.php');

    // Update Page
    $SMARTY = new Smarty_Survey;
    $SMARTY->assign("message","(*) Required");
    session_start();
    is_Logged($_SESSION['login']);

    // Connecting, selecting database
    $dbconnect =& DB::connect("pgsql://". user .":" . password."@" . server ."/" . database, $options);
    is_dbError($dbconnect);
    if ($_REQUEST["action"] == "update") {        
        // validate form
        $err = ValidateForm(0,$SMARTY);
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_reg_sec'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_reg_sec  FROM " . surveytbl . " WHERE business_reg_sec = '".addslashes($_REQUEST["business_reg_sec"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_reg_sec_msg","SEC Registration Number already exists");
                $err++;
            }
        }
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_reg_cda'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_reg_cda FROM " . surveytbl . " WHERE business_reg_cda = '".addslashes($_REQUEST["business_reg_cda"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_reg_cda_msg","CDA Registration Number already exists");
                $err++;
            }
        }
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_reg_bmbe'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_reg_bmbe FROM " . surveytbl . " WHERE business_reg_bmbe = '".addslashes($_REQUEST["business_reg_bmbe"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_reg_bmbe_msg","BMBE Registration Number already exists");
                $err++;
            }
        }
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_reg_dti'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_reg_dti FROM " . surveytbl . " WHERE business_reg_dti = '".addslashes($_REQUEST["business_reg_dti"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_reg_dti_msg","DTI Registration Number already exists");
                $err++;
            }
        }
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_reg_bdt'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_reg_bdt FROM " . surveytbl . " WHERE business_reg_bdt = '".addslashes($_REQUEST["business_reg_bdt"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_reg_bdt_msg","BDT Registration Number already exists");
                $err++;
            }
        }
        // check if Registration Details is already existing
        if (trim($_REQUEST['business_tin'] != "")) {
            $query = $dbconnect->query("SELECT business_id, business_tin FROM " . surveytbl . " WHERE business_tin = '".addslashes($_REQUEST["business_tin"])."' AND business_id != ". $_REQUEST['id']);
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result[0]) {
                $SMARTY->assign("business_tin_msg","Business TIN already exists");
                $err++;
            }
        }        
        // Store chosen date to a variable
        $began_operation = $_REQUEST['began_operationYear'] . "-" . $_REQUEST['began_operationMonth']  . "-" . $_REQUEST['began_operationDay'] ;
        if (checkdate($_REQUEST['began_operationMonth'], $_REQUEST['began_operationDay'], $_REQUEST['began_operationYear']) != TRUE) {                
            $SMARTY->assign("began_operation_msg", $began_operation. " is an invalid Date");
            $err++;
        }
        $registration_date = $_REQUEST['registration_dateYear'] . "-" .  $_REQUEST['registration_dateMonth'] . "-" .  $_REQUEST['registration_dateDay'];
        if (checkdate($_REQUEST['registration_dateMonth'], $_REQUEST['registration_dateDay'], $_REQUEST['registration_dateYear']) != TRUE) {
            $SMARTY->assign("registration_date_msg", $registration_date. " is an invalid Date");
            $err++;
        }
        $owner_cedula_date = $_REQUEST['owner_cedula_dateYear'] . "-" . $_REQUEST['owner_cedula_dateMonth'] . "-" . $_REQUEST['owner_cedula_dateDay'] ;
        if (checkdate($_REQUEST['owner_cedula_dateMonth'], $_REQUEST['owner_cedula_dateDay'], $_REQUEST['owner_cedula_dateYear']) != TRUE) {
            $SMARTY->assign("owner_cedula_date_msg", $owner_cedula_date. " is an invalid Date");
            $err++;
        }
        $manager_cedula_date = $_REQUEST['manager_cedula_dateYear'] . "-" . $_REQUEST['manager_cedula_dateMonth'] . "-" . $_REQUEST['manager_cedula_dateDay'];
        if (checkdate($_REQUEST['manager_cedula_dateMonth'], $_REQUEST['manager_cedula_dateDay'], $_REQUEST['manager_cedula_dateYear']) != TRUE) {
            $SMARTY->assign("manager_cedula_date_msg",$manager_cedula_date. " is an invalid Date");
            $err++;
        }
        
        if ($err) {
            getEntryRecords($SMARTY,$_REQUEST,$began_operation,$registration_date,$owner_cedula_date,$manager_cedula_date);
            $SMARTY->assign("business_id", $_REQUEST['id']);
        } else {
            // Performing SQL query UPDATE
            $result =& $dbconnect->query("   UPDATE " . surveytbl . " SET" .
                                         "   brgy_name            = '".addslashes(getBrgyName($SMARTY))."'" .
                                         " , business_name        = '".addslashes($_REQUEST[business_name])."'" .
                                         " , business_address     = '".addslashes($_REQUEST[business_address])."'" .
                                         " , business_telno       = '".$_REQUEST[business_telno]."'" .
                                         " , business_cellno      = '".$_REQUEST[business_cellno]."'" .
                                         " , business_email       = '".$_REQUEST[business_email]."'" .
                                         " , business_date_oprtn  = '".$began_operation."'" .
                                         " , business_reg_sec     = '".$_REQUEST[business_reg_sec]."'" .
                                         " , business_reg_cda     = '".$_REQUEST[business_reg_cda]."'" .
                                         " , business_reg_bmbe    = '".$_REQUEST[business_reg_bmbe]."'" .
                                         " , business_reg_dti     = '".$_REQUEST[business_reg_dti]."'" .
                                         " , business_reg_bdt     = '".$_REQUEST[business_reg_bdt]."'" .
                                         " , business_tin         = '".$_REQUEST[business_tin]."'" .
                                         " , business_date_reg    = '".$registration_date."'" .
                                         " , business_category    = '".addslashes($_REQUEST[business_category])."'" .
                                         " , business_type        = '".$_REQUEST[business_type]."'" .
                                         " , business_capital     = '".$_REQUEST[business_capital]."'" .
                                         " , business_gross_sales = '".$_REQUEST[business_gross_sales]."'" .
                                         " , barangay_or          = '".$_REQUEST[barangay_or]."'" .
                                         " , business_no_employee = '".$_REQUEST[business_no_employee]."'" .
                                         " , business_status      = '".$_REQUEST[business_status]."'" .
                                         " , owner_name           = '".addslashes($_REQUEST[owner_name])."'" .
                                         " , owner_address        = '".addslashes($_REQUEST[owner_address])."'" .
                                         " , owner_telno          = '".$_REQUEST[owner_telno]."'" .
                                         " , owner_cellno         = '".$_REQUEST[owner_cellno]."'" .
                                         " , owner_age            = '".$_REQUEST[owner_age]."'" .
                                         " , owner_gender         = '".$_REQUEST[owner_gender]."'" .
                                         " , owner_email          = '".$_REQUEST[owner_email]."'" .
                                         " , owner_cedula         = '".$_REQUEST[owner_cedula]."'" .
                                         " , owner_cedula_date    = '".$owner_cedula_date."'" .
                                         " , owner_cedula_place   = '".addslashes($_REQUEST[owner_cedula_place])."'" .
                                         " , manager_name         = '".addslashes($_REQUEST[manager_name])."'" .
                                         " , manager_address      = '".addslashes($_REQUEST[manager_address])."'" .
                                         " , manager_telno        = '".$_REQUEST[manager_telno]."'" .
                                         " , manager_cellno       = '".$_REQUEST[manager_cellno]."'" .
                                         " , manager_age          = '".$_REQUEST[manager_age]."'" .
                                         " , manager_gender       = '".$_REQUEST[manager_gender]."'" .
                                         " , manager_email        = '".$_REQUEST[manager_email]."'" .
                                         " , manager_cedula       = '".$_REQUEST[manager_cedula]."'" .
                                         " , manager_cedula_date  = '".$manager_cedula_date."'" .
                                         " , manager_cedula_place = '".addslashes($_REQUEST[manager_cedula_place])."'"  .
                                         " , author               = '".$_SESSION[username]."'" .
                                         " WHERE business_id      = '".$_REQUEST['id']."'");
            is_dbError($result);
            if ($result) {
                $SMARTY->assign("msg_font", "blue");        
                $SMARTY->assign("message", "Form has been successfully updated !!!");
            }
            header("Location: survey_view.php?id=".$_REQUEST['id']);
        }
    } else {
        if (isset($_GET['id']) && $_GET['id']!="") {
            $query = $dbconnect->query("SELECT * FROM " . surveytbl . " WHERE business_id = '".$_GET['id']."'");
            is_dbError($query);
            $query->fetchInto($result);
            is_dbError($result);
            if ($result) {
                getRecords($SMARTY,$result);
                $SMARTY->assign("business_id", $_REQUEST['id']);
            }
        }
    }
    getBusinessType($SMARTY);
    getBusinessCapital($SMARTY);
    getStatus($SMARTY);
    getGender($SMARTY);
    // Closing connection 
    $result->free;
    $dbconnect->disconnect();
    $SMARTY->assign("brgy_name", getBrgyName($SMARTY));
    $SMARTY->assign("user_rights",$_SESSION['rights']);    
    $SMARTY->assign("action","update");
    $SMARTY->assign("script","update.php");
    $SMARTY->display('survey.html');
?>
Return current item: IPD's eGovernance Application Suite