phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/include/common_functions.php

    r427 r485  
    4040// it should be instanced in session.php 
    4141class phpbms{ 
    42          
     42 
    4343        var $db; 
    4444        var $modules = array();//array of installed modules 
     
    4848        var $bottomJS = array(); 
    4949        var $onload = array(); 
    50                  
     50 
    5151        var $showFooter = true; 
    5252        var $showMenu = true; 
    53          
     53 
    5454        function phpbms($db){ 
    5555                $this->db = $db; 
    56                  
     56 
    5757                $this->modules = $this->getModules(); 
    5858        } 
     
    6565                } 
    6666        } 
    67          
     67 
    6868        function showJsIncludes(){ 
    6969                foreach($this->jsIncludes as $theinclude){ 
     
    8484        }//end method 
    8585 
    86          
     86 
    8787        function getModules(){ 
    8888                $modules = array(); 
    89                  
     89 
    9090                $querystatement = "SELECT * FROM `modules`"; 
    9191                $queryresult = $this->db->query($querystatement); 
    9292                while($therecord = $this->db->fetchArray($queryresult)) 
    9393                        $modules[$therecord["name"]] = $therecord; 
    94                          
     94 
    9595                return $modules; 
    9696        } 
    97          
     97 
    9898 
    9999        function displayRights($roleid,$rolename = NULL){ 
    100100                        switch($roleid){ 
    101                                  
     101 
    102102                                case 0: 
    103103                                        echo "EVERYONE"; 
    104104                                break; 
    105                                  
     105 
    106106                                case -100: 
    107107                                        echo "Administrators"; 
    108108                                break; 
    109                                  
     109 
    110110                                default: 
    111111                                        if(!$rolename){ 
    112112                                                $querystatement = "SELECT name FROM roles WHERE id=".((int) $roleid); 
    113113                                                $queryresult = $this->db->query($querystatement); 
    114          
     114 
    115115                                                $therecord = $this->db->fetchArray($queryresult); 
    116116                                                $rolename = $therecord["name"]; 
    117117                                        }//end if 
    118                                          
     118 
    119119                                        echo $rolename; 
    120120                        }//end case 
     
    123123 
    124124        function showTabs($tabgroup,$currenttabid,$recordid=0){ 
    125                          
     125 
    126126                $querystatement="SELECT id,name,location,enableonnew,notificationsql,tooltip,roleid FROM tabs WHERE tabgroup=\"".$tabgroup."\" ORDER BY displayorder"; 
    127127                $queryresult=$this->db->query($querystatement); 
    128          
    129                 ?><ul class="tabs"><?php  
     128 
     129                ?><ul class="tabs"><?php 
    130130                        while($therecord=$this->db->fetchArray($queryresult)){ 
    131131 
    132132                                if(hasRights($therecord["roleid"])){ 
    133                          
     133 
    134134                                        ?><li <?php if($therecord["id"]==$currenttabid) echo "class=\"tabsSel\"" ?>><?php 
    135135                                                if($therecord["id"]==$currenttabid || ($recordid==0 && $therecord["enableonnew"]==0)){ 
     
    143143                                                        $therecord["notificationsql"]=str_replace("{{id}}",((int) $recordid),$therecord["notificationsql"]); 
    144144                                                        $notificationresult=$this->db->query($therecord["notificationsql"]); 
    145                  
     145 
    146146                                                        if($this->db->numRows($notificationresult)!=0){ 
    147147                                                                $notificationrecord=$this->db->fetchArray($notificationresult); 
     
    153153                                                        } 
    154154                                                } 
    155                                                  
     155 
    156156                                                echo $opener.$therecord["name"].$closer; 
    157                  
    158                                         ?></li><?php  
     157 
     158                                        ?></li><?php 
    159159                                }//endif hasRights 
    160                         }//end whilt     
     160                        }//end whilt 
    161161                ?> 
    162162                </ul><?php 
     
    165165 
    166166        function getUserName($id=0){ 
    167                  
     167 
    168168                $querystatement="select concat(firstname,\" \",lastname) as name from users where id=".((int) $id); 
    169169                $queryresult = $this->db->query($querystatement); 
    170          
     170 
    171171                $tempinfo = $this->db->fetchArray($queryresult); 
    172172                return trim($tempinfo["name"]); 
    173                  
     173 
    174174        }// end method 
    175175 
     
    222222                                if(count($temparray)==3) 
    223223                                        $thedate=mktime(0,0,0,(int) $temparray[1],(int) $temparray[2],(int) $temparray[0]); 
    224                                 else  
     224                                else 
    225225                                        return false; 
    226226                        break; 
     
    231231                                if(count($temparray)==4) 
    232232                                        $thedate=mktime(0,0,0,(int) $temparray[1],(int) $temparray[2],(int) $temparray[3]); 
    233                                 else  
     233                                else 
    234234                                        return false; 
    235235                        break; 
    236                          
     236 
    237237                        case "English, UK": 
    238238                                $datestring="/".ereg_replace(",.","/",$datestring); 
     
    240240                                if(count($temparray)==4) 
    241241                                        $thedate=mktime(0,0,0,(int) $temparray[2],(int) $temparray[1],(int) $temparray[3]); 
    242                                 else  
     242                                else 
    243243                                        return false; 
    244244                        break; 
    245                          
     245 
    246246                        case "Dutch, NL": 
    247247                                $datestring="-".ereg_replace(",.","-",$datestring); 
     
    249249                                if(count($temparray)==4) 
    250250                                        $thedate=mktime(0,0,0,(int) $temparray[2],(int) $temparray[1],(int) $temparray[3]); 
    251                                 else  
     251                                else 
    252252                                        return false; 
    253253                        break; 
     
    302302                                $datestring=strftime("%Y-%m-%d",$thedate); 
    303303                        break; 
    304                          
     304 
    305305                        case "English, US": 
    306306                                $datestring=strftime("%m/%d/%Y",$thedate); 
    307307                        break; 
    308                          
     308 
    309309                        case "English, UK": 
    310310                                $datestring=strftime("%d/%m/%Y",$thedate); 
     
    349349                if($format=="24 Hour") 
    350350                        $timestring=$sqltime; 
    351                 else  
     351                else 
    352352                        $timestring=timeToString(stringToTime($sqltime,"24 Hour"),$format); 
    353353        return $timestring; 
     
    362362                        if(count($tempdatearray)>1 && count($temptimearray)>1) 
    363363                                $thedatetime=mktime((int) $temptimearray[0],(int) $temptimearray[1],(int) $temptimearray[2],(int) $tempdatearray[1],(int) $tempdatearray[2],(int) $tempdatearray[0]); 
    364                 }                
     364                } 
    365365                return $thedatetime; 
    366366} 
     
    371371        if($sqldatetime!=""){ 
    372372                $datetimearray=explode(" ",$sqldatetime); 
    373                  
     373 
    374374                $datestring=trim($datetimearray[0]); 
    375375                if($dateformat=="SQL") 
    376376                        $datestring=$datestring; 
    377                 else  
     377                else 
    378378                        $datestring=dateToString(stringToDate($datestring,"SQL"),$dateformat); 
    379379                if(isset($datetimearray[1])){ 
     
    381381                        if($timeformat=="24 Hour") 
    382382                                $timestring=$timestring; 
    383                         else  
     383                        else 
    384384                                $timestring=timeToString(stringToTime($timestring,"24 Hour"),$timeformat); 
    385385                } 
     
    400400        settype($datetime, 'string'); 
    401401        eregi('(....)(..)(..)(..)(..)(..)',$datetime,$matches); 
    402         array_shift ($matches);  
     402        array_shift ($matches); 
    403403        foreach (array('year','month','day','hour','minute','second') as $var) { 
    404404                $$var = (int) array_shift($matches); 
    405405        } 
    406          
    407          
     406 
     407 
    408408        $thedatetime=mktime($hour,$minute,$second,$month,$day,$year); 
    409          
     409 
    410410        return trim(dateToString($thedatetime,$dateformat)." ".timeToString($thedatetime,$timeformat)); 
    411411} 
     
    448448        $number=str_replace(DECIMAL_SYMBOL,".",$number); 
    449449        $number=((real) $number); 
    450          
     450 
    451451        return $number; 
    452452} 
    453453 
    454  
     454// Phone/Email functions 
     455//===================================================================== 
     456function validateEmail($value){ 
     457 
     458        $thereturn = false; 
     459        $atPos = strpos($value, "@"); 
     460 
     461        //@ symobol must be after first char 
     462        if($atPos > 0){ 
     463 
     464                $dotPos = strpos($value, ".", $atPos); 
     465                $length = strlen($value); 
     466 
     467                //the dot must be at least 2 chars away from at 
     468                //it also must not be the last char in the string 
     469                if( ($dotPos > ($atPos + 1)) && ($length > ($dotPos + 1)) ) 
     470                        $thereturn = true; 
     471 
     472        }//end if 
     473 
     474        return $thereturn; 
     475 
     476}//end function --validateEmail-- 
     477 
     478 
     479function validatePhone($number){ 
     480 
     481        //need to decide on the phone reg ex based upon settings information 
     482        switch(PHONE_FORMAT){ 
     483 
     484                case "US - Loose": 
     485                        $phoneRegEx = "/^(?:[\+]?(?:[\d]{1,3})?(?:\s*[\(\.-]?(\d{3})[\)\.-])?\s*(\d{3})[\.-](\d{4}))(?:(?:[ ]+(?:[xX]|(?:[eE][xX][tT][\.]?)))[ ]?[\d]{1,5})?$/"; 
     486                break; 
     487 
     488                case "US - Strict": 
     489                        $phoneRegEx = "/^[2-9]\d{2}-\d{3}-\d{4}$/"; 
     490                break; 
     491 
     492                case "UK - Loose": 
     493                        $phoneRegEx = "/^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/"; 
     494                break; 
     495 
     496                case "International": 
     497                        $phoneRegEx = "/^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/"; 
     498                break; 
     499                case "No Verification": 
     500                        $phoneRegEx = "/.*/"; 
     501                break; 
     502        }//end switch 
     503 
     504        return preg_match($phoneRegEx,$number); 
     505 
     506}//end function --validatePhone-- 
    455507 
    456508//============================================================================ 
     
    496548 
    497549        //This function prepares an array for SQL manipulation. 
    498          
     550 
    499551        if(get_magic_quotes_runtime() || get_magic_quotes_gpc()){ 
    500          
    501                 foreach ($thearray as $key=>$value)  
     552 
     553                foreach ($thearray as $key=>$value) 
    502554                        if(is_array($value)) 
    503555                                $thearray[$key]= addSlashesToArray($value); 
    504556                        else 
    505557                                $thearray[$key] = mysql_real_escape_string(stripslashes($value)); 
    506                                  
    507         } else   
     558 
     559        } else 
    508560                foreach ($thearray as $key=>$value) 
    509561                        if(is_array($value)) 
    510                                 $thearray[$key]= addSlashesToArray($value);                              
     562                                $thearray[$key]= addSlashesToArray($value); 
    511563                        else 
    512564                                $thearray[$key] = mysql_real_escape_string($value); 
    513          
     565 
    514566        return $thearray; 
    515          
     567 
    516568}//end function 
    517569 
     
    522574        if(!isset($sqlEncoding)) 
    523575                $sqlEncoding = ""; 
    524                  
     576 
    525577        switch ($sqlEncoding){ 
    526          
     578 
    527579                case "latin1": 
    528580                        $encoding = "ISO-8859-15"; 
    529581                        break; 
    530                  
     582 
    531583                case "utf8": 
    532584                default: 
    533585                        $encoding = "UTF-8"; 
    534586                        break; 
    535          
     587 
    536588        }//endswitch 
    537          
     589 
    538590        return htmlspecialchars($string, ENT_COMPAT, $encoding); 
    539591 
     
    605657                        $value=$value; 
    606658                        break; 
    607                  
    608                  
     659 
     660 
    609661                case "bbcode": 
    610662                        $value=htmlQuotes($value); 
    611                                                  
     663 
    612664                        // This list needs to be expanded 
    613665                        $bbcodelist["[b]"] = "<strong>"; 
     
    615667                        $bbcodelist["[br]"] = "<br />"; 
    616668                        $bbcodelist["[space]"] = "&nbsp;"; 
    617                          
     669 
    618670                        foreach($bbcodelist as $bbcode => $translation) 
    619671                                $value = str_replace($bbcode, $translation, $value); 
    620                                                          
    621                         break; 
    622                          
     672 
     673                        break; 
     674 
    623675                default: 
    624676                        $value=htmlQuotes($value); 
     
    639691 
    640692        function nl_langinfo($constant){ 
    641          
    642                 return $constant;        
    643                  
     693 
     694                return $constant; 
     695 
    644696        }//end function 
    645697 
    646698        function nl_setup(){ 
    647          
     699 
    648700                $date = mktime(0,0,0,10,7,2007); 
    649                  
     701 
    650702                for($i = 1; $i<=7; $i++){ 
    651                  
     703 
    652704                        define("ABDAY_".$i, date("D", $date)); 
    653705                        define("DAY_".$i, date("l"), $date); 
    654                          
     706 
    655707                        $date = strtotime("tomorrow", $date); 
    656708                }//end for 
    657                  
    658                  
     709 
     710 
    659711                for($i = 1; $i<=12; $i++){ 
    660                          
     712 
    661713                        $date = mktime(0, 0, 0, $i, 1, 2007); 
    662                          
     714 
    663715                        define("ABMON_".$i, date("M", $date)); 
    664716                        define("MON_".$i, date("F"), $date); 
    665                  
     717 
    666718                }//end for 
    667                                  
     719 
    668720        }//end function 
    669721 
    670722        nl_setup(); 
    671          
     723 
    672724}//end if 
    673725?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.