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

		header("Location: index.php");
		
    // Survey Page
    $SMARTY = new Smarty_Survey;
    $SMARTY->assign("message","(*) Required");

    session_start();
    is_Logged($_SESSION['login']);
    
    // Check if the form action is insert
    if ($_REQUEST['action'] == "insert") {
        // validate form
        $err = ValidateForm(0,$SMARTY);
        // Connecting, selecting database
        $dbconnect =& DB::connect("pgsql://". user .":" . password."@" . server ."/" . database, $options);
        is_dbError($dbconnect);
        // check if Registration Details is already existing
        if (trim(strtoupper($_REQUEST['business_reg_sec'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_reg_sec = '".addslashes($_REQUEST["business_reg_sec"])."'");
            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(strtoupper($_REQUEST['business_reg_cda'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_reg_cda = '".addslashes($_REQUEST["business_reg_cda"])."'");
            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(strtoupper($_REQUEST['business_reg_bmbe'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_reg_bmbe = '".addslashes($_REQUEST["business_reg_bmbe"])."'");
            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(strtoupper($_REQUEST['business_reg_dti'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_reg_dti = '".addslashes($_REQUEST["business_reg_dti"])."'");
            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(strtoupper($_REQUEST['business_reg_bdt'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_reg_bdt = '".addslashes($_REQUEST["business_reg_bdt"])."'");
            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(strtoupper($_REQUEST['business_tin'])) != "N/A") {
            $query = $dbconnect->query("SELECT business_id FROM " . surveytbl . " WHERE business_tin = '".addslashes($_REQUEST["business_tin"])."'");
            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);           
        } else {
            // Performing SQL query
            $result =& $dbconnect->query("INSERT INTO " . surveytbl . 
                                         "(brgy_name," .
                                         " business_name," .
                                         " business_address," .
                                         " business_telno," .
                                         " business_cellno," .
                                         " business_email," .
                                         " business_date_oprtn," .
                                         " business_reg_sec," .
                                         " business_reg_cda," .
                                         " business_reg_bmbe," .
                                         " business_reg_dti," .
                                         " business_reg_bdt," .
                                         " business_tin," .
                                         " business_date_reg," .
                                         " business_category," .
                                         " business_type," .
                                         " business_capital," .
                                         " business_gross_sales," .
                                         " barangay_or," .
                                         " business_no_employee," .
                                         " business_status," .
                                         " owner_name," .
                                         " owner_address," .
                                         " owner_telno," .
                                         " owner_cellno," .
                                         " owner_age," .
                                         " owner_gender," .
                                         " owner_email," .
                                         " owner_cedula," .
                                         " owner_cedula_date," .
                                         " owner_cedula_place," .
                                         " manager_name," .
                                         " manager_address," .
                                         " manager_telno," .
                                         " manager_cellno," .
                                         " manager_age," .
                                         " manager_gender," .
                                         " manager_email," .
                                         " manager_cedula," .
                                         " manager_cedula_date," .
                                         " manager_cedula_place," .
                                         " author)" .
                                         " VALUES('". addslashes(getBrgyName($SMARTY))."'," .
                                         "'". addslashes($_REQUEST[business_name])."'," .
                                         "'". addslashes($_REQUEST[business_address])."'," .
                                         " '$_REQUEST[business_telno]'," .
                                         " '$_REQUEST[business_cellno]'," .
                                         " '$_REQUEST[business_email]'," .
                                         " '$began_operation'," .
                                         " '$_REQUEST[business_reg_sec]'," .
                                         " '$_REQUEST[business_reg_cda]'," .
                                         " '$_REQUEST[business_reg_bmbe]'," .
                                         " '$_REQUEST[business_reg_dti]'," .
                                         " '$_REQUEST[business_reg_bdt]'," .
                                         " '$_REQUEST[business_tin]'," .
                                         " '$registration_date'," .
                                         "'".addslashes($_REQUEST[business_category])."'," .
                                         " '$_REQUEST[business_type]'," .
                                         " '$_REQUEST[business_capital]'," .
                                         " '$_REQUEST[business_gross_sales]'," .
                                         " '$_REQUEST[barangay_or]'," .
                                         " '$_REQUEST[business_no_employee]'," .
                                         " '$_REQUEST[business_status]'," .
                                         "'".addslashes($_REQUEST[owner_name])."'," .
                                         "'".addslashes($_REQUEST[owner_address])."'," .
                                         " '$_REQUEST[owner_telno]'," .
                                         " '$_REQUEST[owner_cellno]'," .
                                         " '$_REQUEST[owner_age]'," .
                                         " '$_REQUEST[owner_gender]'," .
                                         " '$_REQUEST[owner_email]'," .
                                         " '$_REQUEST[owner_cedula]'," .
                                         " '$owner_cedula_date'," .
                                         "'".addslashes($_REQUEST[owner_cedula_place])."'," .
                                         "'".addslashes($_REQUEST[manager_name])."'," .
                                         "'".addslashes($_REQUEST[manager_address])."'," .
                                         " '$_REQUEST[manager_telno]'," .
                                         " '$_REQUEST[manager_cellno]'," .
                                         " '$_REQUEST[manager_age]'," .
                                         " '$_REQUEST[manager_gender]'," .
                                         " '$_REQUEST[manager_email]'," .
                                         " '$_REQUEST[manager_cedula]'," .
                                         " '$manager_cedula_date'," .
                                         "'".addslashes($_REQUEST[manager_cedula_place])."'," .
                                         " '$_SESSION[username]')");
            is_dbError($result);
            if ($result) {
                $SMARTY->assign("msg_font", "blue");		
                $SMARTY->assign("message", "Form has been successfully submitted !!!");
            }
        }
        // Closing connection
        $result->free;
        $dbconnect->disconnect();
    }    
    getBusinessType($SMARTY);
    getBusinessCapital($SMARTY);
    getStatus($SMARTY);
    getGender($SMARTY);
    $SMARTY->assign("brgy_name", getBrgyName($SMARTY));
    $SMARTY->assign("user_rights",$_SESSION['rights']);
    $SMARTY->assign("action","insert");
    $SMARTY->assign("script","survey.php");
    $SMARTY->display("survey.html");
?>
Return current item: IPD's eGovernance Application Suite