Location: PHPKode > projects > IPD's eGovernance Application Suite > bbis/trunk/include/functions.php
<?php
    /* Form Validation */
    function is_whitespace($txtfield) {
       if (strlen(trim($txtfield)) == 0 ) { 
           return TRUE;
       } else {
           return FALSE;
       }
    }

    function is_email_valid($email){
       $bln_ind = true;
       $email_n = eregi_replace("\n", "", $email);
       $email   = eregi_replace(" +", "", $email_n);
       $email   = strtolower($email);
       if (!(ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email))) {
           $bln_ind = false;
       }
       return $bln_ind;
    }

    function is_phone_valid($txtfield){
       if(!preg_match("/[^0-9\ \-\(\)]+$/",$txtfield)) {
          return TRUE;
       } else {
          return FALSE;
       }
    }

    function check_field3($field_name_3){
       if(!preg_match("/[^0-9]+$/ ",$field_name_3))  {
          return TRUE;
       } else {
          return FALSE;
       }
    }

    /* Database error checking */
    function is_dbError($object){
        if (PEAR::isError($object)) {
            echo "An error occurred while trying to run your database command" . "<br>";
            echo "Error message: " . $object->getMessage() . "<br>";
            echo "A more detailed error description: " . $object->getDebugInfo() . "<br>";
        } else {
            return TRUE;
        }
    }
    
    /* is the one accessing this page logged in or not? */
    function is_Logged($session) {
        if (!isset($session) || $session != true) {
            header("Location:login.php");
            die();
        }
        return TRUE;
    }

    /* Option retrieval */
    function getBusinessType($template){
        $template->assign("type_options",array('Single',
        									   'Proprietorship',		
                                               'Partnership',
                                               'Corporation',
                                               'Cooperative',
                                               'Others'));
        return $template;
    }

    function getBusinessCapital($template){
        $template->assign("capital_options", array('Below P100,000',
                                                   'P100,001 - P200,000',
                                                   'P200,001 - P300,000',
                                                   'P300,001 - P400,000',
                                                   'P400,001 - P500,000',
                                                   'Over P500,000',
                                                   'Over P1 Million',
                                                   'Over P2 Million',
                                                   'Over P3 Million'));
        return $template;
    }
    
    function getStatus($template){
        $template->assign("status_options", array('Active',
                                                 'Inactive'));
        return $template;
    }
    
    function getGender($template){
        $template->assign("gender_options", array('Male',
                                                  'Female'));
        return $template;
    }

    function getUserRights($template){
        $template->assign("user_permission", array('Admin',
                                                   'Single User'));
        $template->assign("user_options","Single User");
        return $template;
    }
    
    function getBrgyName($template){
        // get contents of a file into a string
        $filename = "./include/brgy_name.txt";    
        $handle = @fopen($filename, "r");
        if ($handle) {
            while (!feof($handle)) {            
                $buffer = fgets($handle, 4096);
                if ($buffer!="") {
                    $brgyname = $buffer; 
                    
                }
            }
            fclose($handle);
        }    
        if (!$handle = fopen($filename, "r")) {
            $contents = fread($handle, filesize($filename));
            $brgyname =  $contents;
        }
        fclose($handle);
        return stripslashes($brgyname);
    }
    
    function getRecords($template,$query) {
        $template->assign("business_name", stripslashes($query[2]));
        $template->assign("business_address", stripslashes($query[3]));
        $template->assign("business_telno", $query[4]);
        $template->assign("business_cellno", $query[5]);
        $template->assign("business_email", $query[6]);
        $template->assign("business_date_oprtn", $query[7]);
        $template->assign("business_reg_sec", $query[8]);
        $template->assign("business_reg_cda", $query[9]);
        $template->assign("business_reg_bmbe", $query[10]);
        $template->assign("business_reg_dti", $query[11]);
        $template->assign("business_reg_bdt", $query[12]);
        $template->assign("business_tin", $query[13]);
        $template->assign("business_date_reg", $query[14]);
        $template->assign("business_category", stripslashes($query[15]));
        $template->assign("business_type", $query[16]);
        $template->assign("business_capital", $query[17]);
        $template->assign("business_gross_sales", $query[18]);
        $template->assign("barangay_or", $query[19]);
        $template->assign("business_no_employee", $query[20]);
        $template->assign("business_status", $query[21]);
        $template->assign("owner_name", stripslashes($query[22]));
        $template->assign("owner_address", stripslashes($query[23]));
        $template->assign("owner_telno", $query[24]);
        $template->assign("owner_cellno", $query[25]);
        $template->assign("owner_age", $query[26]);
        $template->assign("owner_gender", $query[27]);
        $template->assign("owner_email", $query[28]);
        $template->assign("owner_cedula", $query[29]);
        $template->assign("owner_cedula_date", $query[30]);
        $template->assign("owner_cedula_place", stripslashes($query[31]));
        $template->assign("manager_name", stripslashes($query[32]));
        $template->assign("manager_address", stripslashes($query[33]));
        $template->assign("manager_telno", $query[34]);
        $template->assign("manager_cellno", $query[35]);
        $template->assign("manager_age", $query[36]);
        $template->assign("manager_gender", $query[37]);
        $template->assign("manager_email", $query[38]);
        $template->assign("manager_cedula", $query[39]);
        $template->assign("manager_cedula_date", $query[40]);
        $template->assign("manager_cedula_place", stripslashes($query[41]));
        return $template;
    }
    
    function getEntryRecords($template,$REQ,$began,$reg,$owner,$manager){
        $template->assign("msg_font", "red");
        $template->assign("business_name", stripslashes($REQ['business_name'])); 
        $template->assign("business_address", stripslashes($REQ['business_address']));
        $template->assign("business_telno", $REQ['business_telno']);
        $template->assign("business_cellno", $REQ['business_cellno']);
        $template->assign("business_email", $REQ['business_email']);
        $template->assign("began_operation", $began);
        $template->assign("business_reg_sec", $REQ['business_reg_sec']);
        $template->assign("business_reg_cda", $REQ['business_reg_cda']);
        $template->assign("business_reg_bmbe", $REQ['business_reg_bmbe']);
        $template->assign("business_reg_dti", $REQ['business_reg_dti']);
        $template->assign("business_reg_bdt", $REQ['business_reg_bdt']);
        $template->assign("business_tin", $REQ['business_tin']);
        $template->assign("registration_date", $reg);
        $template->assign("business_category", stripslashes($REQ['business_category']));
        $template->assign("business_type", $REQ['business_type']);
        $template->assign("business_capital", $REQ['business_capital']);
        $template->assign("business_gross_sales", $REQ['business_gross_sales']);
        $template->assign("barangay_or", $REQ['barangay_or']);
        $template->assign("business_no_employee", $REQ['business_no_employee']);
        $template->assign("business_status", $REQ['business_status']);
        $template->assign("owner_name", stripslashes($REQ['owner_name']));
        $template->assign("owner_address", stripslashes($REQ['owner_address']));
        $template->assign("owner_telno", $REQ['owner_telno']);
        $template->assign("owner_cellno", $REQ['owner_cellno']);
        $template->assign("owner_age", $REQ['owner_age']);
        $template->assign("owner_gender", $REQ['owner_gender']);
        $template->assign("owner_email", $REQ['owner_email']);
        $template->assign("owner_cedula", $REQ['owner_cedula']);
        $template->assign("owner_cedula_date", $owner);
        $template->assign("owner_cedula_place", stripslashes($REQ['owner_cedula_place']));
        $template->assign("manager_name", stripslashes($REQ['manager_name']));
        $template->assign("manager_address", stripslashes($REQ['manager_address']));
        $template->assign("manager_telno", $REQ['manager_telno']);
        $template->assign("manager_cellno", $REQ['manager_cellno']);
        $template->assign("manager_age", $REQ['manager_age']);
        $template->assign("manager_gender", $REQ['manager_gender']);
        $template->assign("manager_email", $REQ['manager_email']);
        $template->assign("manager_cedula", $REQ['manager_cedula']);
        $template->assign("manager_cedula_date", $manager);
        $template->assign("manager_cedula_place", stripslashes($REQ['manager_cedula_place']));
        $template->assign("message", "There were errors !!!");
        return $template;        
    }
    function getDisplayRecords($record,$recno,$module = 'printall'){
       $results .= "<tr>";
       $results .= "<td nowrap>".$recno."</td>";
       if ($module == 'viewrecord') { 
           $results .= "<td nowrap>".$record[42]."</td>";
       } else if ($module == 'printselected') {
           $results .= "<td nowrap>".stripslashes($record[0])."</td>";
       }
       $results .= "<td nowrap>".stripslashes($record[1])."</td>";
       if ($module == 'search') {
           $results .= "<td nowrap><a href=\"survey_view.php?id=".$record[0]."\">".stripslashes($record[2])."</a></td>";
       } else {
           $results .= "<td nowrap>".stripslashes($record[2])."</td>";
       }    
       $results .= "<td nowrap>".stripslashes($record[3])."</td>";
       $results .= "<td nowrap>".$record[4]."</td>";
       $results .= "<td nowrap>".$record[5]."</td>";
       $results .= "<td nowrap>".$record[6]."</td>";
       $results .= "<td nowrap>".$record[7]."</td>";
       $results .= "<td nowrap>".$record[8]."</td>";
       $results .= "<td nowrap>".$record[9]."</td>";
       $results .= "<td nowrap>".$record[10]."</td>";
       $results .= "<td nowrap>".$record[11]."</td>";
       $results .= "<td nowrap>".$record[12]."</td>";
       $results .= "<td nowrap>".$record[13]."</td>";
       $results .= "<td nowrap>".stripslashes($record[14])."</td>";
       $results .= "<td nowrap>".stripslashes($record[15])."</td>";
       $results .= "<td nowrap>".$record[16]."</td>";
       $results .= "<td nowrap>".$record[17]."</td>";
       $results .= "<td nowrap>".$record[18]."</td>";
       $results .= "<td nowrap>".$record[19]."</td>";
       $results .= "<td nowrap>".$record[20]."</td>";
       $results .= "<td nowrap>".stripslashes($record[21])."</td>";
       $results .= "<td nowrap>".stripslashes($record[22])."</td>";
       $results .= "<td nowrap>".stripslashes($record[23])."</td>";
       $results .= "<td nowrap>".$record[24]."</td>";
       $results .= "<td nowrap>".$record[25]."</td>";
       $results .= "<td nowrap>".$record[26]."</td>";
       $results .= "<td nowrap>".$record[27]."</td>";
       $results .= "<td nowrap>".$record[28]."</td>";
       $results .= "<td nowrap>".stripslashes($record[29])."</td>";
       $results .= "<td nowrap>".stripslashes($record[30])."</td>";
       $results .= "<td nowrap>".stripslashes($record[31])."</td>";
       $results .= "<td nowrap>".stripslashes($record[32])."</td>";
       $results .= "<td nowrap>".$record[33]."</td>";
       $results .= "<td nowrap>".$record[34]."</td>";
       $results .= "<td nowrap>".$record[35]."</td>";
       $results .= "<td nowrap>".$record[36]."</td>";
       $results .= "<td nowrap>".$record[37]."</td>";
       $results .= "<td nowrap>".$record[38]."</td>";
       $results .= "<td nowrap>".$record[39]."</td>";
       $results .= "<td nowrap>".stripslashes($record[40])."</td>";
       $results .= "<td nowrap>".stripslashes($record[41])."</td>";           
       $results .= "</tr>";       
       return $results;    
    }
    
    /* Survey Validation */
    function ValidateForm($no, $template){
        $NLimit = 255;
        $ILimit = 99; 
        if (is_whitespace($_REQUEST['business_name'])) {
            $template->assign("business_name_msg","(*) Business Name is required");
            $no++;
        } else {
            if (strlen($_REQUEST['business_name']) > $NLimit) {
                    $template->assign("business_name_msg","(*) Name should not consists of more than ".$NLimit." characters");
                    $no++;
            }            
        }

        if (is_whitespace($_REQUEST['business_address'])) {
            $template->assign("business_address_msg","(*) Business address is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_address']) > $NLimit) {
                    $template->assign("business_address_msg","(*) Address should not consists of more than ".$NLimit." characters");
                    $no++;
            }                
        }

        if (is_whitespace($_REQUEST['business_telno'])) {
            $template->assign("business_telno_msg","(*) Business telephone is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_telno']) > $ILimit) {
                    $template->assign("business_telno_msg","(*) Telephone should not consists of more than ".$ILimit." characters");
                    $no++;
            }
        }
                
        if (is_whitespace($_REQUEST['business_cellno'])) {
            $template->assign("business_cellno_msg","(*) Business cellnum is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_cellno']) > $ILimit) {
                    $template->assign("business_cellno_msg","(*) Cellnum should not consists of more than ".$ILimit." characters");
                    $no++;
            }                
        }

        if (is_whitespace($_REQUEST['business_email'])) {
            $template->assign("business_email_msg","(*) Business email is required");
            $no++; 
        } else {
			if (strlen($_REQUEST['business_email']) > $ILimit){
               $template->assign("business_email_msg","(*) Email should not consists of more than ".$ILimit." characters");
               $no++;
            }
        }    

        if ((is_whitespace($_REQUEST['business_reg_sec'])) && 
            (is_whitespace($_REQUEST['business_reg_cda'])) && 
            (is_whitespace($_REQUEST['business_reg_bmbe'])) && 
            (is_whitespace($_REQUEST['business_reg_dti'])) && 
            (is_whitespace($_REQUEST['business_reg_bdt'])) && 
            (is_whitespace($_REQUEST['business_tin']))) {
                $template->assign("business_reg_sec_msg","(*) At least (1) Registration No. is required");
                $no++;
        } else if (strlen($_REQUEST['business_reg_sec']) > $ILimit) {
                    $template->assign("business_reg_sec_msg","(*) SEC Registration should not consists of more than ".$ILimit." characters");
                    $no++;
            } else if (strlen($_REQUEST['business_reg_cda']) > $ILimit) {
                        $template->assign("business_reg_cda_msg","(*) CDA Registration should not consists of more than ".$ILimit." characters");
                        $no++;
                } else if (strlen($_REQUEST['business_reg_bmbe']) > $ILimit) {
                            $template->assign("business_reg_bmbe_msg","(*) BMBE Registration should not consists of more than ".$ILimit." characters");
                            $no++;
                    } else if (strlen($_REQUEST['business_reg_dti']) > $ILimit) {
                                $template->assign("business_reg_dti_msg","(*) DTI Registration should not consists of more than ".$ILimit." characters");
                                $no++;
                            } else if (strlen($_REQUEST['business_reg_bdt']) > $ILimit) {
                                        $template->assign("business_reg_bdt_msg","(*) BDT Registration should not consists of more than ".$ILimit." characters");
                                        $no++;
                                    } else if (strlen($_REQUEST['business_reg_tin']) > $ILimit) {
                                                $template->assign("business_reg_tin_msg","(*) TIN should not consists of more than ".$ILimit." characters");
                                                $no++;            
                                    }

        if (is_whitespace($_REQUEST['business_category'])) {
            $template->assign("business_category_msg","(*) Business category is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_category']) > $ILimit) {
                    $template->assign("business_category_msg","(*) Category should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }

        if (is_whitespace($_REQUEST['business_type'])) {
            $template->assign("business_type_msg","(*) Business Type is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_type']) > $ILimit) {
                    $template->assign("business_type_msg","(*) Type should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['business_capital'])) {
            $template->assign("business_capital_msg","(*) Business Capital is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_capital']) > $ILimit) {
                    $template->assign("business_type_msg","(*) Capital should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['business_gross_sales'])) {
            $template->assign("business_gross_sales_msg","(*) Business Gross Sales is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_gross_sales']) > $ILimit) {
                    $template->assign("business_gross_sales_msg","(*) Gross Sales should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['barangay_or'])) {
            $template->assign("barangay_or_msg","(*) Barangay O.R. No is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['business_or']) > $ILimit) {
                    $template->assign("business_or_msg","(*) OR No should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['business_no_employee'])) {
            $template->assign("business_no_employee_msg","(*) No. of Employees is required");
            $no++; 
        } else {
            if (!is_numeric($_REQUEST['business_no_employee'])) {
                $template->assign("business_no_employee_msg","(*) No. of Employees is invalid");
                $no++; 
            }
        }

        if (is_whitespace($_REQUEST['owner_name'])) {
            $template->assign("owner_name_msg","(*) Name of owner is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_name']) > $NLimit) {
                    $template->assign("owner_name_msg","(*) Name should not consists of more than ".$NLimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['owner_address'])) {
            $template->assign("owner_address_msg","(*) Owner's Address is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_address']) > $NLimit) {
                    $template->assign("owner_address_msg","(*) Address should not consists of more than ".$NLimit." characters");
                    $no++;                
            }
        }

        if (is_whitespace($_REQUEST['owner_telno'])) {
            $template->assign("owner_telno_msg","(*) Owner's telephone is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_telno']) > $ILimit) {
                    $template->assign("owner_telno_msg","(*) Telephone should not consists of more than ".$ILimit." characters");
                    $no++;
            }
        }
                
        if (is_whitespace($_REQUEST['owner_cellno'])) {
            $template->assign("owner_cellno_msg","(*) Owner's cellnum is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_cellno']) > $ILimit) {
                    $template->assign("owner_cellno_msg","(*) Cellnum should not consists of more than ".$ILimit." characters");
                    $no++;
            }                
        }

        if (is_whitespace($_REQUEST['owner_age'])) {
            $template->assign("owner_age_msg","(*) Owner's age is required");
            $no++; 
        } else {
            if (!is_numeric($_REQUEST['owner_age'])) {
                $template->assign("owner_age_msg","(*) Owner's age is invalid");
                $no++; 
            }
        }
        
        if (is_whitespace($_REQUEST['owner_gender'])) {
            $template->assign("owner_gender_msg","(*) Owner's gender is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_gender']) > $ILimit) {
                    $template->assign("owner_gender_msg","(*) Owner's gender should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }

        if (is_whitespace($_REQUEST['owner_email'])) {
            $template->assign("owner_email_msg","(*) Owner's email is required");
            $no++; 
        } else {
			if (strlen($_REQUEST['owner_email']) > $ILimit){
               $template->assign("owner_email_msg","(*) Email should not consists of more than ".$ILimit." characters");
               $no++;
            }
        }        
        
        if (is_whitespace($_REQUEST['owner_cedula'])) {
            $template->assign("owner_cedula_msg","(*) Owner's CTC is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_cedula']) > $ILimit) {
                    $template->assign("owner_cedula_msg","(*) Cedula should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        if (is_whitespace($_REQUEST['owner_cedula_place'])) {
            $template->assign("owner_cedula_place_msg","(*) Owner's CTC - Place of Issue is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['owner_cedula_place']) > $ILimit) {
                    $template->assign("owner_cedula_place_msg","(*) Place should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        if (is_whitespace($_REQUEST['manager_name'])) {
            $template->assign("manager_name_msg","(*) Manager's Name is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_name']) > $NLimit) {
                    $template->assign("manager_name_msg","(*) Name should not consists of more than ".$NLimit." characters");
                    $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['manager_address'])) {
            $template->assign("manager_address_msg","(*) Manager's Address is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_address']) > $NLimit) {
                    $template->assign("manager_address_msg","(*) Address should not consists of more than ".$NLimit." characters");
                    $no++;                
            }
        }

        if (is_whitespace($_REQUEST['manager_telno'])) {
            $template->assign("manager_telno_msg","(*) Manager's telephone is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_telno']) > $ILimit) {
                    $template->assign("manager_telno_msg","(*) Telephone should not consists of more than ".$ILimit." characters");
                    $no++;
            }
        }
                
        if (is_whitespace($_REQUEST['manager_cellno'])) {
            $template->assign("manager_cellno_msg","(*) Manager's cellnum is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_cellno']) > $ILimit) {
                    $template->assign("manager_cellno_msg","(*) Cellnum should not consists of more than ".$ILimit." characters");
                    $no++;
            }                
        }        

        if (is_whitespace($_REQUEST['manager_age'])) {
            $template->assign("manager_age_msg","(*) Manager's age is required");
            $no++; 
        } else {
            if (!is_numeric($_REQUEST['manager_age'])) {
                $template->assign("manager_age_msg","(*) Manager's age is invalid");
                $no++; 
            }
        }        
        
        if (is_whitespace($_REQUEST['manager_gender'])) {
            $template->assign("manager_gender_msg","(*) Manager's gender is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_gender']) > $ILimit) {
                    $template->assign("manager_gender_msg","(*) Manager's gender should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
                
        if (is_whitespace($_REQUEST['manager_email'])) {
            $template->assign("manager_email_msg","(*) Manager's email is required");
            $no++; 
        } else  {
            if (strlen($_REQUEST['manager_email']) > $ILimit){
               $template->assign("manager_email_msg","(*) Email should not consists of more than ".$ILimit." characters");
               $no++;
          }
        }
        
        if (is_whitespace($_REQUEST['manager_cedula'])) {
            $template->assign("manager_cedula_msg","(*) Manager's CTC is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_cedula']) > $ILimit) {
                $template->assign("manager_cedula_msg","(*) Cedula should not consists of more than ".$ILimit." characters");
                $no++;                
            }
        }
        
        if (is_whitespace($_REQUEST['manager_cedula_place'])) {
            $template->assign("manager_cedula_place_msg","(*) Manager's CTC - Place of Issue is required");
            $no++; 
        } else {
            if (strlen($_REQUEST['manager_cedula_place']) > $ILimit) {
                    $template->assign("manager_cedula_place_msg","(*) Place should not consists of more than ".$ILimit." characters");
                    $no++;                
            }
        }
        
        return $no;
    }
?>
Return current item: IPD's eGovernance Application Suite