phpBMS

Changeset 485 for trunk/phpbms/include

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Location:
trunk/phpbms/include
Files:
8 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?> 
  • trunk/phpbms/include/db.php

    r427 r485  
    1 <?php  
     1<?php 
    22/* 
    33 $Rev: 249 $ | $LastChangedBy: brieb $ 
     
    4141                //we may want to do more than connect via mysql; 
    4242                var $type="mysql"; 
    43                                  
     43 
    4444                // mysql vars; 
    4545                var $db_link; 
     
    4949                var $dbpass; 
    5050                var $pconnect=true; 
    51                  
     51 
    5252                var $showError=false; 
    5353                var $logError=true; 
    5454                var $stopOnError=true; 
    5555                var $errorFormat="xhtml"; 
    56                  
     56 
    5757                var $error = NULL; 
    58                                  
     58 
    5959                function db($connect = true, $hostname = NULL, $schema = NULL, $user = NULL, $pass = NULL, $pconnect = NULL, $type = "mysql"){ 
    60                          
     60 
    6161                        if($type!="mysql") 
    6262                        $this->type=$type; 
     
    6969                                        if($hostname!=NULL) 
    7070                                                $this->hostname = $hostname; 
    71                                          
     71 
    7272                                        if(defined("MYSQL_DATABASE")) 
    7373                                                $this->schema = MYSQL_DATABASE; 
    7474                                        if($schema!=NULL) 
    7575                                                $this->schema = $schema; 
    76                  
     76 
    7777                                        if(defined("MYSQL_USER")) 
    7878                                                $this->dbuser = MYSQL_USER; 
    7979                                        if($schema!=NULL) 
    8080                                                $this->dbuser = $user; 
    81                  
     81 
    8282                                        if(defined("MYSQL_USERPASS")) 
    8383                                                $this->dbpass = MYSQL_USERPASS; 
    8484                                        if($schema!=NULL) 
    8585                                                $this->dbpass = $pass; 
    86                  
     86 
    8787                                        if(defined("MYSQL_PCONNECT")) 
    8888                                                $this->pconnect = MYSQL_PCONNECT; 
    8989                                        if($pconnect!=NULL) 
    9090                                                $this->pconnect = $pconnect; 
    91                                 break;                           
     91                                break; 
    9292                        } 
    93                                                  
     93 
    9494                        if($connect){ 
    9595                                if($this->connect()){ 
     
    9797                                                return $this->db_link; 
    9898                                        else 
    99                                                 return false;                            
     99                                                return false; 
    100100                                } else 
    101101                                        return false; 
     
    106106                function connect(){ 
    107107                        // This functions connects to the database.  It uses pconnect if the variable is set; 
    108                                                  
     108 
    109109                        if($this->pconnect) 
    110110                                $this->db_link = @ mysql_pconnect($this->hostname,$this->dbuser,$this->dbpass); 
    111111                        else 
    112112                                $this->db_link = @ mysql_connect($this->hostname,$this->dbuser,$this->dbpass); 
     113 
    113114                        if(!$this->db_link){ 
     115 
    114116                                $error = new appError(-400,"Could not connect to database server.\n\n".$this->getError(),"",$this->showError,$this->stopOnError,false,$this->errorFormat); 
    115117                                return false; 
    116                         } else                   
     118 
     119                        } else 
    117120                                return $this->db_link; 
    118                 } 
    119  
    120                  
     121 
     122                }//end function connect 
     123 
     124 
    121125                function selectSchema($schema=NULL){ 
    122126                        if($schema!=NULL) 
    123127                                $this->schema=$schema; 
    124                                  
     128 
    125129                        if(! @ mysql_select_db($this->schema,$this->db_link)){ 
    126                                 $error = new appError(-410,"Could not open schema ".$this->schema,"",$this->showError,$this->stopOnError,false,$this->errorFormat);      
     130                                $error = new appError(-410,"Could not open schema ".$this->schema,"",$this->showError,$this->stopOnError,false,$this->errorFormat); 
    127131                                return false; 
    128132                        } else 
    129                                 return true;                                                     
     133                                return true; 
    130134                } 
    131135 
     
    134138                        switch($this->type){ 
    135139                                case "mysql": 
    136                                         if(!isset($this->db_link))  
    137                                                 if(!$this->dataB()) die($this->error); 
     140                                        if(!isset($this->db_link)) 
     141                                                if(!$this->db()) die($this->error); 
    138142                                        $queryresult = @ mysql_query($sqlstatement,$this->db_link); 
    139143                                        if(!$queryresult){ 
     
    141145                                                $error = new appError(-420,$this->getError($this->db_link)."\n\nStatement: ".$sqlstatement,"",$this->showError,$this->stopOnError,$this->logError,$this->errorFormat); 
    142146                                                return false; 
    143                                         }                                        
    144                                 break; 
    145                         }//end case 
    146                          
     147                                        } 
     148                                break; 
     149                        }//end case 
     150 
    147151                        $this->error=NULL; 
    148152                        return $queryresult; 
     
    153157 
    154158                        switch($this->type){ 
    155                                 case "mysql":                    
     159                                case "mysql": 
    156160                                        @ mysql_query("SET NAMES ".$encoding, $this->db_link); 
    157161                                        break; 
    158                                          
     162 
    159163                        }//endswitch 
    160164 
     
    163167 
    164168                function getError($link = NULL){ 
    165                          
    166                         switch($this->type){ 
    167                                 case "mysql": 
    168                                         $thereturn = mysql_error($link); 
     169 
     170                        switch($this->type){ 
     171                                case "mysql": 
     172                                        if($link) 
     173                                                $thereturn = @ mysql_error($link); 
     174                                        else 
     175                                                $thereturn = @ mysql_error(); 
    169176                                break; 
    170177                        }//end switch --type-- 
    171                          
    172                         return $thereturn; 
    173                          
     178 
     179                        return $thereturn; 
     180 
    174181                }//end method --getError-- 
    175                  
     182 
    176183 
    177184                function numRows($queryresult){ 
     
    200207                }//end function 
    201208 
    202                  
     209 
    203210                function startTransaction(){ 
    204                          
    205                         switch($this->type){ 
    206                                  
     211 
     212                        switch($this->type){ 
     213 
    207214                                case "mysql": 
    208215                                        $this->query("START TRANSACTION;"); 
    209216                                break; 
    210                          
     217 
    211218                        }//end switch 
    212                          
     219 
    213220                }//end method --startTransaction-- 
    214                  
    215                  
     221 
     222 
    216223                function commitTransaction(){ 
    217                          
    218                         switch($this->type){ 
    219                                  
     224 
     225                        switch($this->type){ 
     226 
    220227                                case "mysql": 
    221228                                        $this->query("COMMIT;"); 
    222229                                break; 
    223                          
     230 
    224231                        }//end switch 
    225                          
     232 
    226233                }//end method --startTransaction-- 
    227                  
    228                  
     234 
     235 
    229236                function rollbackTransaction(){ 
    230                          
    231                         switch($this->type){ 
    232                                  
     237 
     238                        switch($this->type){ 
     239 
    233240                                case "mysql": 
    234241                                        $this->query("ROLLBACK;"); 
    235242                                break; 
    236                          
     243 
    237244                        }//end switch 
    238                          
     245 
    239246                }//end method --startTransaction-- 
    240                  
     247 
    241248 
    242249                function seek($queryresult,$rownum){ 
     
    278285                        return $thereturn; 
    279286                }//end function 
    280                  
    281                  
     287 
     288 
    282289                function tableInfo($tablename){ 
    283290                        //this function returns a multi-dimensional array describing the fields in a given table 
     
    291298                                                        $thereturn[$name]["type"] = @ mysql_field_type($queryresult,$offset); 
    292299                                                        $thereturn[$name]["length"] = mysql_field_len($queryresult,$offset); 
    293                                                         $thereturn[$name]["flags"] = mysql_field_flags($queryresult,$offset);                                                    
     300                                                        $thereturn[$name]["flags"] = mysql_field_flags($queryresult,$offset); 
    294301                                                } 
    295302                                        } 
     
    305312                                case "mysql": 
    306313                                        $thereturn = @ mysql_insert_id($this->db_link); 
    307                                 break;                   
     314                                break; 
    308315                        } 
    309                          
     316 
    310317                        return $thereturn; 
    311318                } 
    312                  
     319 
    313320                function affectedRows(){ 
    314321                        $thereturn = false; 
     
    316323                                case "mysql": 
    317324                                        $thereturn = @ mysql_affected_rows($this->db_link); 
    318                                 break;                   
     325                                break; 
    319326                        } 
    320                          
     327 
    321328                        return $thereturn; 
    322329                } 
    323                  
     330 
    324331}//end db class 
    325332?> 
  • trunk/phpbms/include/fields.php

    r447 r485  
    451451                                ?><option value="0" <?php 
    452452                                if ($this->value==0 || $this->value==""){ 
    453                                         echo " selected=\"selected\" "?>>&lt;none&gt;</option><?php 
     453                                        echo " selected=\"selected\" "; 
    454454                                }//end if --value-- 
     455                                ?>>&lt;none&gt;</option><?php 
    455456                        }//end if --hasblank-- 
    456457 
  • trunk/phpbms/include/imports.php

    r433 r485  
    11<?php 
    22        class phpbmsImport{ 
    3                  
     3 
    44                var $table; 
    55                var $error = ""; 
     
    1010                var $data; 
    1111                var $revertID = 0; 
    12                  
     12 
    1313                // Do not manually override 
    1414                var $transactionRecords = array(); 
    1515                var $tempFileID = 0; 
    1616                var $pageType = "main"; 
    17                  
     17 
    1818                function phpbmsImport($table, $importType = "csv"){ 
    19                          
     19 
    2020                        $this->table = $table; 
    2121                        $this->importType = $importType; 
     
    2525                                break; 
    2626                        }//end switch 
    27                          
     27 
    2828                        $this->table->db->logError = true; 
    2929                        //So, that, when there is a db error, it will go all the way through and not just stop 
    3030                        $this->table->db->stopOnError = false; 
    31                         //Won't display db errors, just log them.        
     31                        //Won't display db errors, just log them. 
    3232                        $this->table->db->showError = false; 
    3333                        if(isset($_POST["pageType"])) 
    3434                                $this->pageType = $_POST["pageType"]; 
    35                          
     35 
    3636                        if(isset($_POST["tempFileID"])) 
    3737                                $this->tempFileID = ((int)$_POST["tempFileID"]); 
    38                          
     38 
    3939                }//end method --imports-- 
    40                  
     40 
    4141                function _parseFromData($data){ 
    42                          
     42 
    4343                        switch($this->importType){ 
    44                                  
     44 
    4545                                case "csv": 
    46                                          
     46 
    4747                                        if(is_readable($data)){ 
    4848                                                $contents = $this->_getFile($data); 
    49                                          
     49 
    5050                                                if(is_readable($contents)){ 
    5151                                                        $this->docError = "invalid csv document"; 
    5252                                                        return false; 
    5353                                                }//end if 
    54                                                  
     54 
    5555                                        }//end if 
    56                                          
     56 
    5757                                        $this->parser->parse($data); 
    58                                                  
     58 
    5959                                        if(!count($this->parser->titles) || !count($this->parser->data)){ 
    6060                                                $this->docError = "invalid csv document"; 
    61                                                 return false;    
     61                                                return false; 
    6262                                        }//end if 
    63                                          
     63 
    6464                                        return true; 
    6565                                break; 
    66                          
     66 
    6767                        }//end swtich 
    68                  
     68 
    6969                }//end method --_parseFromFile-- 
    70                  
    71                  
     70 
     71 
    7272                function _getTransactionData(){ 
    7373                //needs to be changed for more complicated tables 
     
    7575                        foreach($this->transactionIDs as $theid) 
    7676                                $inStatement .= $theid.","; 
    77                          
     77 
    7878                        if($inStatement){ 
    79                                  
     79 
    8080                                $inStatement = substr($inStatement, 0, -1); 
    81                          
     81 
    8282                                $querystatement = " 
    8383                                        SELECT 
     
    8888                                                `id` IN (".$inStatement."); 
    8989                                        "; 
    90                                  
     90 
    9191                                $queryresult = $this->table->db->query($querystatement); 
    92                                  
     92 
    9393                                while($therecord = $this->table->db->fetchArray($queryresult)) 
    9494                                        $this->transactionRecords[] = $therecord; 
    95                                          
    96                         }//end if  
    97                          
     95 
     96                        }//end if 
     97 
    9898                }//end method --_getTransactionData-- 
    99                  
    100                  
     99 
     100 
    101101                function _getFile($fileName){ 
    102102                        if(function_exists('file_get_contents')){ 
     
    106106                                $file = addslashes(fread(fopen($fileName, 'r'), filesize($fileName))); 
    107107                        }//end if 
    108                          
     108 
    109109                        return $file; 
    110110                }//end method --_getFile-- 
    111                  
     111 
    112112                //DO NOT CALL IN TRANSACTION 
    113113                function _storeTempCSV($fileName){ 
    114                          
     114 
    115115                        $querystatement = " 
    116116                                INSERT INTO 
     
    136136                                                '".$_SESSION["userinfo"]["id"]."', 
    137137                                                '".$_SESSION["userinfo"]["id"]."' 
    138                                                  
     138 
    139139                                        ) 
    140140                                "; 
    141                          
     141 
    142142                        $this->table->db->query($querystatement); 
    143                          
     143 
    144144                        $id = $this->table->db->insertId(); 
    145                          
     145 
    146146                        if($id) 
    147147                                $this->tempFileID = ((int) $id); 
    148148                        else 
    149149                                $this->error .= '<li> inserting temporary file failure </li>'; 
    150                          
     150 
    151151                }//end method --_storeTempCSV-- 
    152                  
    153                  
     152 
     153 
    154154                function _getTempCSV($tempFileID){ 
    155                          
     155 
    156156                        if($tempFileID){ 
    157                                  
     157 
    158158                                $querystatement = " 
    159159                                        SELECT 
     
    164164                                                id = ".((int)$tempFileID)." 
    165165                                        "; 
    166                                  
     166 
    167167                                $queryresult = $this->table->db->query($querystatement); 
    168                                  
     168 
    169169                                $therecord = $this->table->db->fetchArray($queryresult); 
    170                                  
     170 
    171171                                return $therecord["file"]; 
    172                          
     172 
    173173                        }//end if 
    174                          
     174 
    175175                        return false; 
    176                          
     176 
    177177                }//end method --_getTempCSV-- 
    178                  
     178 
    179179                //DO NOT CALL IN TRANSACTION 
    180180                function _removeTempCSV($tempFileID = 0){ 
    181                          
     181 
    182182                        $querystatement = " 
    183183                                DELETE FROM 
     
    192192                                        ); 
    193193                                "; 
    194                                  
     194 
    195195                        $queryresult = $this->table->db->query($querystatement); 
    196                          
     196 
    197197                        $querystatement = " 
    198198                                ALTER TABLE 
     
    200200                                AUTO_INCREMENT = ".((int) $tempFileID)."; 
    201201                                "; 
    202                          
     202 
    203203                        $queryresult = $this->table->db->query($querystatement); 
    204                          
     204 
    205205                }//end method --_removeTempCSV-- 
    206                  
     206 
    207207                //DO NOT USE THIS METHOD INSIDE AN OPEN TRANSACTION. 
    208208                //IT WILL AUTOMATICALLY COMMIT THE TRANSACTION 
    209209                function _revertAutoIncrement($revertID = 0){ 
    210                          
     210 
    211211                        //check to see if there is a revert id (i.e. there was a valid insert) 
    212212                        if($revertID) 
    213213                                if(is_numeric($revertID)){ 
    214                                          
     214 
    215215                                        $querystatement = " 
    216216                                                ALTER TABLE 
     
    218218                                                AUTO_INCREMENT = ".((int) $revertID)."; 
    219219                                                "; 
    220                                          
     220 
    221221                                        $this->table->db->query($querystatement); 
    222                                          
     222 
    223223                                }//end if 
    224                          
     224 
    225225                }//end method --_revertAutoIncrement-- 
    226                  
    227                  
     226 
     227 
    228228                function importRecords($rows, $titles){ 
    229                          
     229 
    230230                        switch($this->importType){ 
    231                                  
    232                                 case "csv":                      
     231 
     232                                case "csv": 
    233233                                        //count total fieldnames (top row of csv document) 
    234234                                        $fieldNum = count($titles); 
    235                                          
     235 
    236236                                        //the file starts at line number 1, but since line 1 is 
    237237                                        //supposed to be the fieldnames in the table(s), the lines 
    238238                                        //being insereted start @ 2. 
    239239                                        $rowNum = 2; 
    240                                          
     240 
    241241                                        //get the data one row at a time 
    242242                                        foreach($rows as $rowData){ 
    243                                                  
    244                                                 $theid = 0; 
    245                                                  
     243 
     244                                                $theid = 0; // set for when verifification does not pass 
     245                                                $verify = array(); //set for when number of field rows does not match number of titles 
     246 
    246247                                                //trim off leading/trailing spaces 
    247248                                                $trimmedRowData = array(); 
     249 
    248250                                                foreach($rowData as $name => $data) 
    249251                                                        $trimmedRowData[$name] = trim($data); 
    250                                                  
     252 
    251253                                                //check to see if number of fieldnames is consistent for each row 
    252254                                                $rowFieldNum = count($trimmedRowData); 
    253                                                  
     255 
    254256                                                //if valid, insert, if not, log error and don't insert. 
    255                                                 if($rowFieldNum == $fieldNum) 
    256                                                         $theid = $this->table->insertRecord($trimmedRowData); 
    257                                                 else 
     257                                                if($rowFieldNum == $fieldNum){ 
     258                                                        $verify = $this->table->verifyVariables($trimmedRowData); 
     259                                                        if(!count($verify)) 
     260                                                                $theid = $this->table->insertRecord($trimmedRowData); 
     261                                                }else 
    258262                                                        $this->error .= '<li> incorrect amount of fields for line number '.$rowNum.'.</li>'; 
    259                                                  
     263 
    260264                                                if($theid){ 
    261265                                                        //keep track of the ids in the transaction to be able to select them 
    262266                                                        //for preview purposes 
    263267                                                        $this->transactionIDs[] = $theid; 
    264                                                          
     268 
    265269                                                        //get first id to correct auto increment 
    266270                                                        if(!$this->revertID) 
     
    268272                                                }else 
    269273                                                        $this->error .= '<li> failed insert for line number '.$rowNum.'.</li>'; 
    270                                                  
     274 
     275                                                foreach($verify as $error) 
     276                                                        $this->error .= '<li class="subError">'.$error.'</li>'; 
     277 
    271278                                                $rowNum++; 
    272                                                  
     279 
    273280                                        }//end foreach 
    274281                                break; 
    275                                  
     282 
    276283                        }//end switch 
    277                          
     284 
    278285                }//end method --importRecords-- 
    279                  
    280                  
     286 
     287 
    281288                function displayTransaction($recordsArray, $fieldsArray){ 
    282289                //needs to be changed for more complicated tables 
     
    317324                                <?php 
    318325                        }//end if 
    319                          
     326 
    320327                }//end method --displayTransaction-- 
    321                  
    322                  
     328 
     329 
    323330                function processImportPage(){ 
    324                          
     331 
    325332                        $this->table->getTableInfo(); 
    326                          
     333 
    327334                        if(!isset($_POST["command"])){ 
    328                                  
     335 
    329336                                //happens upon first coming to page 
    330                                  
     337 
    331338                                //remove any other temporary csv files in the `files` table 
    332339                                //present from previous imports 
    333340                                $this->_removeTempCSV(); 
    334                                  
     341 
    335342                                //check to see if user has the rights to be here. 
    336343                                //If not, kick him to the no access page. 
    337344                                if(!hasRights($this->table->importroleid)) 
    338345                                        goURL(APP_PATH."noaccess.php"); 
    339                                  
     346 
    340347                        }else{ 
    341348                                //form has been submitted 
    342349                                switch($_POST["command"]){ 
    343                                          
     350 
    344351                                        //cancel button pressed. 
    345352                                        case "cancel": 
     
    354361                                                }//end if 
    355362                                        break; 
    356                                  
     363 
    357364                                        case "upload": 
    358                                                  
     365 
    359366                                                //check for valid file upload 
    360367                                                if(!$_FILES["import"]["error"] && ($_FILES["import"]["size"] > 0)){ 
    361                                                          
     368 
    362369                                                        //check and parse the file 
    363370                                                        if($this->_parseFromData($_FILES["import"]["tmp_name"])){ 
    364                                                                  
     371 
    365372                                                                //start transaction 
    366373                                                                $this->table->db->startTransaction(); 
    367                                                                  
     374 
    368375                                                                $this->importRecords($this->parser->data, $this->parser->titles); 
    369                                                                  
     376 
    370377                                                                //get data for preview purposes 
    371378                                                                $this->_getTransactionData(); 
    372379                                                                //"undo" any inserts 
    373380                                                                $this->table->db->rollbackTransaction(); 
    374                                                                  
     381 
    375382                                                                //DO NOT CALL IN TRANSACTION 
    376383                                                                //ALTER TABLES AUTO COMMIT AND THE FILE NEEDS TO CARRY 
     
    378385                                                                $this->_revertAutoIncrement($this->revertID); 
    379386                                                                $this->_storeTempCSV($_FILES["import"]["tmp_name"]); 
    380                                                                  
     387 
    381388                                                        }//end if 
    382                                                          
     389 
    383390                                                }else 
    384391                                                        $this->docError .= "failed file upload"; 
    385                                                  
     392 
    386393                                                //switch page types 
    387394                                                $this->pageType = "confirm"; 
    388                                                  
     395 
    389396                                                if(!$this->error && !$this->docError){ 
    390397                                                        $therecord["phpbmsStatus"] = "Confirm Import"; 
     
    394401                                                }else 
    395402                                                        $therecord["phpbmsStatus"] = "Import Error"; 
    396                                                  
     403 
    397404                                        break; 
    398                                          
     405 
    399406                                        case "import": 
    400                                                  
     407 
    401408                                                //get the contents of the stored csv document 
    402409                                                $CSVcontents = $this->_getTempCSV($this->tempFileID); 
    403                                                  
     410 
    404411                                                //parser uses newline character to be able to parse the last line 
    405412                                                if(substr($CSVcontents,-1,1) != "\n") 
    406413                                                        $CSVcontents .= "\n"; 
    407                                                  
    408                                                  
     414 
     415 
    409416                                                $this->parser->parse($CSVcontents); 
    410                                                  
     417 
    411418                                                $this->importRecords($this->parser->data, $this->parser->titles); 
    412                                                  
     419 
    413420                                                $this->table->db->commitTransaction(); 
    414                                                  
     421 
    415422                                                //DO NOT CALL IN TRANSACTION 
    416                                                  
     423 
    417424                                                //get rid of temporary csv document 
    418425                                                $this->_removeTempCSV($this->tempFileID); 
    419                                                  
     426 
    420427                                                $therecord["phpbmsStatus"] = "Record(s) Imported"; 
    421428                                                //change page type 
    422429                                                $this->pageType = "main"; 
    423430                                        break; 
    424                                          
     431 
    425432                                }//end command switch 
    426                                          
     433 
    427434                        }// end if 
    428                          
     435 
    429436                        //display the title 
    430437                        $therecord["title"] = $this->table->displayname." Import"; 
    431438                        return $therecord; 
    432                          
     439 
    433440                }//end method --imports-- 
    434                  
     441 
    435442        }//end class --imports-- 
    436          
    437          
     443 
     444 
    438445        //this class is to have different buttons, and no created/modified. 
    439446        if(class_exists("phpbmsForm")){ 
    440447                class importForm extends phpbmsForm{ 
    441                          
     448 
    442449                        function importForm($action = NULL, $method="post", $name="record", $onsubmit="return validateForm(this);", $dontSubmit = true){ 
    443                                  
     450 
    444451                                parent::phpbmsForm($action,$method,$name,$onsubmit,$dontSubmit); 
    445                                  
     452 
    446453                        }//end method --importForm-- 
    447                          
    448                         function startForm($pageTitle, $pageType){ 
    449                  
    450                                 ?><form action="<?php echo str_replace("&","&amp;",$this->action) ?>" method="<?php echo $this->method?>" name="<?php echo $this->name?>" onsubmit="<?php echo $this->onsubmit?>" <?php  
     454 
     455                        function startForm($pageTitle, $pageType, $numberOfRecords = 0){ 
     456 
     457                                ?><form action="<?php echo str_replace("&","&amp;",$this->action) ?>" method="<?php echo $this->method?>" name="<?php echo $this->name?>" onsubmit="<?php echo $this->onsubmit?>" <?php 
    451458                                        if(isset($this->enctype)) echo ' enctype="'.$this->enctype.'" '; 
    452459                                        if(isset($this->id)) echo ' id="'.$this->id.'" '; 
    453                                 ?>><?php  
     460                                ?>><?php 
    454461                                if($this->dontSubmit){ 
    455462                                        ?><div id="dontSubmit"><input type="submit" value=" " onclick="return false;" /></div><?php 
    456463                                } ?> 
    457                                 <div id="topButtons"><?php $this->showButtons(1, $pageType); ?></div> 
    458                                 <h1 id="h1Title"><span><?php echo $pageTitle ?></span></h1><?php         
    459                                  
     464                                <div id="topButtons"><?php $this->showButtons(1, $pageType, $numberOfRecords); ?></div> 
     465                                <h1 id="h1Title"><span><?php echo $pageTitle ?></span></h1><?php 
     466 
    460467                        }//end method --startForm-- 
    461                          
    462                         function showButtons($ids = 1, $pageType = "main"){ 
     468 
     469                        function showButtons($ids = 1, $pageType = "main", $numberOfRecords = 0){ 
    463470                                ?> 
    464471                                <div class="importCancels"> 
    465472                                        <?php if($pageType == "main"){ ?> 
    466                                         <input <?php if($ids==1) {?>accesskey="i"<?php }?> title="Upload (alt+u)" id="uploadButton<?php echo $ids?>" name="command" type="submit" value="upload" class="Buttons" /> 
     473                                        <input <?php if($ids==1) {?>accesskey="u"<?php }?> title="Upload (alt+u)" id="uploadButton<?php echo $ids?>" name="command" type="submit" value="upload" class="Buttons" /> 
    467474                                        <input id="cancelButton<?php echo $ids?>" name="command" type="submit" value="cancel" class="Buttons" <?php if($ids==1) {?>accesskey="x" <?php }?> title="(access key+x)" /> 
    468475                                        <?php }else{?> 
    469                                         <input type="submit" class="Buttons" value="import" name="command" id="import<?php echo $ids?>" title="commit"/> 
     476                                        <input type="submit" class="Buttons" value="import" name="command" id="import<?php echo $ids?>" title="commit" <?php echo ($numberOfRecords? '':'disabled="disabled"') ?>/> 
    470477                                        <input type="submit" class="Buttons" value="cancel" name="command" id="cancelButton<?php echo $ids?>" title="rollback"/> 
    471478                                        <?php }//end if ?> 
    472479                                </div><?php 
    473480                        }//end method --showButtons-- 
    474                  
     481 
    475482                }//end class --importForm-- 
    476483        } 
  • trunk/phpbms/include/jstransport.php

    r440 r485  
    1 <?php  
     1<?php 
    22        $loginNoKick=true; 
    33        $loginNoDisplayError=true; 
    4         require_once("session.php");     
    5          
     4        require_once("session.php"); 
     5 
    66        //phone formating 
    7         ?>phoneRegExpression=<?php  
     7        ?>phoneRegExpression=<?php 
    88        switch(PHONE_FORMAT){ 
    99                case "US - Loose": 
     
    1111                break; 
    1212                case "US - Strict": 
    13                         ?>/^[2-9]\d{2}-\d{3}-\d{4}$/;<?php               
     13                        ?>/^[2-9]\d{2}-\d{3}-\d{4}$/;<?php 
    1414                break; 
    1515                case "UK - Loose": 
    1616                        ?>/^((\(?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}))?$/;<?php 
    17                 break;   
     17                break; 
    1818                case "International": 
    1919                    ?>/^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;<?php 
    20                 break;   
    21         }  
    22                  
     20                break; 
     21                case "No Verification": 
     22                        ?>/.*/;<?php 
     23                break; 
     24        } 
     25 
    2326        //date formating 
    2427        ?>APP_PATH="<?php echo htmlQuotes(APP_PATH)?>";<?php 
     
    2629        //date formating 
    2730        ?>DATE_FORMAT="<?php echo htmlQuotes(DATE_FORMAT)?>";<?php 
    28          
     31 
    2932        //time formating 
    3033        ?>TIME_FORMAT="<?php echo htmlQuotes(TIME_FORMAT)?>";<?php 
     
    4043 
    4144        ?>LOGIN_REFRESH=<?php echo LOGIN_REFRESH?>;<?php 
    42          
     45 
    4346        if(defined("TERM1_DAYS")){ 
    4447        ?>TERM1_DAYS=<?php echo TERM1_DAYS?>;<?php 
    4548        }//end if 
    46          
    47         ?>MONTH_NAMES_LONG= [ <?php  
    48                  
     49 
     50        ?>MONTH_NAMES_LONG= [ <?php 
     51 
    4952                $mNames = ""; 
    5053                for($i=0; $i < 11; $i++) 
    5154                        $mNames .= ', "'.strftime("%B", mktime(0, 0, 0, $i+1, 1, 1974)).'"'; 
    5255                $mNames = substr($mNames, 2); 
    53                  
     56 
    5457                echo $mNames; 
    55          
    56         ?> ];<?php  
     58 
     59        ?> ];<?php 
    5760 
    5861        if(isset($phpbms->modules["bms"])){ 
    59          
     62 
    6063                ?>TERM1_DAYS=<?php echo TERM1_DAYS?>;<?php 
    61          
     64 
    6265        }//end if 
    63          
     66 
    6467 
    6568?> 
  • trunk/phpbms/include/login_include.php

    r311 r485  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39         function verifyLogin($username,$password,$db){ 
    40                 $thereturn = "Login Failed"; 
    41                  
    42                 $querystatement = "SELECT id, firstname, lastname, email, phone, department, employeenumber, admin 
    43                                                 FROM users  
    44                                                 WHERE login=\"".mysql_real_escape_string($username)."\"  
    45                                                 AND password=ENCODE(\"".mysql_real_escape_string($password)."\",\"".mysql_real_escape_string(ENCRYPTION_SEED)."\")  
    46                                                 AND revoked=0 AND portalaccess=0"; 
    47                                                  
    48                 $queryresult = $db->query($querystatement); 
    49                                  
    50                 if($db->numRows($queryresult)){ 
    51                          
     39class login{ 
     40 
     41        var $db; 
     42 
     43        function login($db){ 
     44 
     45                $this->db = $db; 
     46 
     47        }//end function init 
     48 
     49 
     50        function verify($username, $password){ 
     51 
     52                $querystatement = " 
     53                        SELECT 
     54                                id, 
     55                                firstname, 
     56                                lastname, 
     57                                email, 
     58                                phone, 
     59                                department, 
     60                                employeenumber, 
     61                                admin 
     62                        FROM 
     63                                users 
     64                        WHERE 
     65                                login = '".mysql_real_escape_string($username)."' 
     66                                AND password = ENCODE('".mysql_real_escape_string($password)."','".mysql_real_escape_string(ENCRYPTION_SEED)."') 
     67                                AND revoked = 0 
     68                                AND portalaccess = 0"; 
     69 
     70                $queryresult = $this->db->query($querystatement); 
     71 
     72                if($this->db->numRows($queryresult)){ 
     73 
    5274                        //We found a record that matches in the database 
    5375                        // populate the session and go in 
    54                         $_SESSION["userinfo"]=$db->fetchArray($queryresult); 
    55                          
     76                        $_SESSION["userinfo"] = $this->db->fetchArray($queryresult); 
     77 
    5678                        // Next get the users roles, and populate the session with them 
    57                         $_SESSION["userinfo"]["roles"][]=0; 
    58                         $querystatement = "SELECT roleid FROM rolestousers WHERE userid=".$_SESSION["userinfo"]["id"]; 
    59                         $rolesqueryresult = $db->query($querystatement); 
    60                          
    61                         while($rolerecord=$db->fetchArray($rolesqueryresult)) 
     79                        $_SESSION["userinfo"]["roles"][] = 0; 
     80                        $querystatement = " 
     81                                SELECT 
     82                                        roleid 
     83                                FROM 
     84                                        rolestousers 
     85                                WHERE userid=".$_SESSION["userinfo"]["id"]; 
     86 
     87                        $rolesqueryresult = $this->db->query($querystatement); 
     88 
     89                        while($rolerecord = $this->db->fetchArray($rolesqueryresult)) 
    6290                                $_SESSION["userinfo"]["roles"][]=$rolerecord["roleid"]; 
    63                          
    64                  
    65                         $querystatement = "UPDATE users SET modifieddate=modifieddate, lastlogin=Now() WHERE id = ".$_SESSION["userinfo"]["id"]; 
    66                         $updateresult = $db->query($querystatement); 
    6791 
    68                         $_SESSION["tableparams"]=array(); 
     92                        //update lastlogin 
     93                        $ip = $_SERVER["REMOTE_ADDR"]; 
     94 
     95                        $updatestatement = " 
     96                                UPDATE 
     97                                        users 
     98                                SET 
     99                                        modifieddate = modifieddate, 
     100                                        lastlogin = Now(), 
     101                                        `lastip` = '".$ip."' 
     102                                WHERE 
     103                                        id = ".$_SESSION["userinfo"]["id"]; 
     104 
     105                        $this->db->query($updatestatement); 
     106 
     107                        $_SESSION["tableparams"] = array(); 
    69108 
    70109                        goURL(DEFAULT_LOAD_PAGE); 
    71                 } else           
    72                 return "Login Failed"; 
    73         } 
     110 
     111                } else  { 
     112 
     113                        //log login attempt 
     114                        $log = new phpbmsLog("Login attempt failed for user '".$username."'", "SECURITY"); 
     115 
     116                        return "Login Failed"; 
     117 
     118                }//endif numrows 
    74119 
    75120 
    76 // Start Code 
    77 //================================================================================================================= 
    78          
    79         $failed=""; 
    80         if (isset($_POST["name"])) { 
    81                 $variables=addSlashesToArray($_POST); 
    82                 $failed=verifyLogin($variables["name"],$variables["password"],$db); 
    83         } else  
    84                 $_POST["name"]=""; 
    85 ?> 
     121        }//end function verify 
     122 
     123}//end class 
  • trunk/phpbms/include/session.php

    r402 r485  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
     39 
     40// Turn on/or off debugging 
    3941@ define("APP_DEBUG",true); 
    4042if(APP_DEBUG) 
    4143        error_reporting(E_ALL); 
    4244 
     45 
     46// Error Class - This class reports errors.  It can also log these errors 
     47// to the phpBMS log table in some cases. 
    4348class appError{ 
     49 
    4450        var $number=0; 
    4551        var $title=""; 
     
    4854        var $logerror=true; 
    4955        var $format="xhtml"; 
    50          
     56 
     57        //init 
    5158        function appError($number=0,$details="",$title="",$display=false,$stop=true,$logerror=true,$format="xhtml"){ 
     59 
    5260                $this->title = $title; 
    53                  
    54                  
    5561                $this->details = $details; 
    56                  
    5762                $this->stop = $stop; 
    58                                  
     63 
    5964                $this->logerror = $logerror; 
    6065                $this->format = $format; 
    6166                $this->number = $number; 
    62                                  
     67 
     68                // find a predetermined title; 
    6369                if($this->number<0){ 
     70 
    6471                        switch($number){ 
     72                                case -300: 
     73                                        $this->title = "settings.php file not readable"; 
     74                                        $this->details = 
     75                                        'If this is the initial installation of the program, 
     76                                        you may wan to run the installer.  Use your web browser to navigate to:<br /><br /> 
     77 
     78                                        <a href="'.APP_PATH.'install">phpBMS Installation</a><br /><br /> 
     79 
     80                                        If your application already has a settings.php file in the main phpbms directory, you may need to give your web server rights to read the file.'; 
     81                                        break; 
    6582                                case -400: 
    6683                                case -410: 
     
    7188                                case -460: 
    7289                                        $this->title="Database Error"; 
    73                                 break; 
    74                         } 
    75                 }  
    76                  
     90                                        break; 
     91                        }//end case; 
     92 
     93                }//endif this->number 
     94 
    7795                if($display || APP_DEBUG) $this->display($format); 
    7896                if($logerror) $this->logError(); 
    7997                if($this->stop) exit; 
    80         } 
    81          
    82         function display($format=NULL){ 
    83  
    84                 if($format==NULL) 
    85                         $format=$this->format; 
    86          
     98 
     99        }//eend function init 
     100 
     101 
     102        //This function outputs the error to screen either in 
     103        // XHTML, plain text, or JSON format 
     104        function display($format = NULL){ 
     105 
     106                if($format == NULL) 
     107                        $format = $this->format; 
     108 
    87109                switch(strtolower($format)){ 
     110 
    88111                        case "json": 
    89112 
    90                                 echo "{\n"; 
    91                                 echo "\"error\" : { \"id\" : ".$this->number; 
    92                                 if($this->title) 
    93                                         echo ", \"title\" : \"".addslashes($this->title)."\""; 
    94                                 if($this->details) 
    95                                         echo ", \"details\" : \"".addslashes($this->details)."\""; 
    96                                 echo "\n}"; 
    97  
    98                         break; 
    99                          
     113                                $return["id"] = $this->number; 
     114                                $return["title"] = $this->title; 
     115                                $return["details"] = $this->details; 
     116 
     117                                echo json_encode($return); 
     118 
     119                                break; 
     120 
    100121                        case "xhtml": 
    101122 
    102                                 $this->details = str_replace("\n","<br />", htmlspecialchars($this->details,ENT_COMPAT,"UTF-8")); 
     123                                // Unsure if this line is needed, as it limits what we can do with detail print out 
     124                                //$this->details = str_replace("\n","<br />", htmlspecialchars($this->details,ENT_COMPAT,"UTF-8")); 
    103125 
    104126                                if(defined("APP_PATH")){ 
     127 
    105128                                        if(!defined("STYLESHEET")) 
    106129                                                define("STYLESHEET","mozilla"); 
    107                                 ?><link href="<?php echo APP_PATH ?>common/stylesheet/<?php echo STYLESHEET ?>/base.css" rel="stylesheet" type="text/css" /><?php 
     130 
     131                                        ?><link href="<?php echo APP_PATH ?>common/stylesheet/<?php echo STYLESHEET ?>/base.css" rel="stylesheet" type="text/css" /><?php 
     132 
    108133                                } else { 
    109                                         //if the app_path is not defined, we can try including the mozilla stylesheet, relative to  
     134 
     135                                        //if the app_path is not defined, we can try including the mozilla stylesheet, relative to 
    110136                                        // the assumed phpbms root 
    111                                 ?><link href="common/stylesheet/mozilla/base.css" rel="stylesheet" type="text/css" /><?php  
     137                                        ?><link href="common/stylesheet/mozilla/base.css" rel="stylesheet" type="text/css" /><?php 
     138 
    112139                                }//end if 
     140 
    113141                                ?><div class="bodyline"> 
    114142                                        <h1><span>phpBMS Error: <?php echo $this->number; if($this->title) echo " ".$this->title?></span></h1> 
     
    118146                                        </div> 
    119147                                        <?php  } //end if?> 
    120                                 </div><?php  
    121  
    122                         break; 
    123                          
     148                                </div><?php 
     149 
     150                                break; 
     151 
    124152                        default: 
    125                          
     153 
    126154                                echo "phpBMS Error: ".$this->number; 
    127155                                if($this->title) echo ": ".$this->title; 
    128156                                if($this->details) echo  " - ".$this->details; 
    129                                  
    130                         break; 
     157 
     158                                break; 
    131159                }//end switch 
    132160        }// end dispaly function 
    133          
     161 
     162 
     163        // this function logs the error in the phpBMS log table 
    134164        function logError(){ 
     165 
    135166                $message = $_SERVER["REQUEST_URI"]."\n"; 
    136167                $message .= $this->number; 
     168 
    137169                if($this->title) 
    138170                        $message.=": ".$this->title; 
     171 
    139172                if($this->details) 
    140173                        $message.="\n\n".$this->details; 
    141                                                  
     174 
    142175                $log = new phpbmsLog($message,"ERROR"); 
     176 
    143177        }//end logError 
    144          
     178 
    145179}//end appError class 
    146180 
     181 
     182// This is the class for logging items tot the phpBMS 
     183// log table; 
    147184class phpbmsLog{ 
    148          
    149         var $db=NULL; 
    150         var $type="ERROR"; 
    151         var $value=""; 
    152         var $userid=2; 
    153          
     185 
     186        var $db = NULL; 
     187        var $type = "ERROR"; 
     188        var $value = ""; 
     189        var $userid = 2; 
     190 
    154191        function phpbmsLog($value=NULL,$type=NULL,$userid=NULL,$db=NULL,$sendLog=true){ 
    155192 
     
    158195                if($db){ 
    159196                        if(is_object($db)){ 
    160                                 $this->db=$db; 
    161          
     197 
     198                                $this->db = $db; 
     199 
    162200                                $this->db->showError=false; 
    163201                                $this->db->logError=false; 
    164202                                $this->db->stopOnError=false; 
    165                         } 
    166                 } 
    167                 else{ 
     203 
     204                        }//endif object 
     205 
     206                } else { 
     207 
    168208                        if(class_exists("db")){ 
     209 
    169210                                $this->db= new db(false); 
    170          
     211 
    171212                                $this->db->showError=false; 
    172213                                $this->db->logError=false; 
    173214                                $this->db->stopOnError=false; 
    174          
     215 
    175216                                $this->db->connect(); 
    176217                                $this->db->selectSchema(); 
    177                         } else  
     218 
     219                        } else 
    178220                                return false; 
    179                 } 
    180                  
     221 
     222                }//endif db 
     223 
    181224                if($value) 
    182                         $this->value=$value; 
     225                        $this->value = $value; 
     226 
    183227                if($type) 
    184                         $this->type=$type; 
     228                        $this->type = $type; 
     229 
    185230                if($userid) 
    186                         $this->userid=((int) $userid); 
    187                  
     231                        $this->userid = ((int) $userid); 
     232 
    188233                if($sendLog) 
    189234                        return $this->sendLog(); 
    190235                else 
    191236                        return true; 
    192                  
    193         }//end function 
    194          
     237 
     238        }//end function init 
     239 
     240 
     241        // inserts record into log table 
    195242        function sendLog(){ 
    196                          
    197                 $ip=$_SERVER["REMOTE_ADDR"]; 
    198          
    199                 $querystatement="INSERT INTO `log` (`type`,`value`,`userid`,`ip`) VALUES ("; 
    200                 $querystatement.="\"".mysql_real_escape_string($this->type)."\", "; 
    201                 $querystatement.="\"".mysql_real_escape_string($this->value)."\", "; 
    202                 $querystatement.=$this->userid.", "; 
    203                 $querystatement.="\"".$ip."\")"; 
    204                  
    205                 $this->db->query($querystatement); 
    206                  
    207         } 
    208 }//end phpbmslog 
    209  
    210  
    211  
     243 
     244                $ip = $_SERVER["REMOTE_ADDR"]; 
     245 
     246                $insertstatement = " 
     247                        INSERT INTO 
     248                                `log` 
     249                        (`type`, `value`, `userid`, `ip`) VALUES ( 
     250                                '".mysql_real_escape_string($this->type)."', 
     251                                '".mysql_real_escape_string($this->value)."', 
     252                                ".$this->userid.", 
     253                                '".$ip."' 
     254                        )"; 
     255 
     256                $this->db->query($insertstatement); 
     257 
     258        }//end function sendLog 
     259 
     260}//end class phpbmslog 
     261 
     262 
     263// This class handles the loading of the database, session and application 
     264// variables, as well as verifying API level logins 
    212265class phpbmsSession{ 
    213266 
    214         var $db=null; 
     267        var $db = null; 
    215268 
    216269        function loadDBSettings($reportError = true){ 
     270 
    217271                // This functions looks for the settings.php file, and loads 
    218272                // the database variables as constants.  As an added benefit 
    219273                // it adds the phpBMS root as an included path. 
    220                  
    221                 $path=""; 
    222                 $count=1; 
     274 
    223275 
    224276                //need to look for settings file... only go up a total of 10 directories 
    225                 $currdirectory= getcwd(); 
    226                  
    227                 while(!file_exists("settings.php") and ($count<10)){ 
     277                $currdirectory = getcwd(); 
     278 
     279                //Prep the setting of the application path; 
     280                $currentURL = explode("/",$_SERVER["PHP_SELF"]); 
     281                array_pop($currentURL); 
     282 
     283                $count = 0; 
     284                $path = ""; 
     285 
     286                //We need to find the applications root 
     287                while(!file_exists("phpbmsversion.php") && $count < 9){ 
     288 
    228289                        $path.="../"; 
    229290                        @ chdir("../"); 
    230291                        $count++; 
    231                 } 
    232                  
     292 
     293                }//end while 
     294 
     295                //Now set the Web location (APP_PATH) 
     296                $appPath = "/"; 
     297                for($i = 0; $i < count($currentURL) - $count; $i++) 
     298                        if($currentURL[$i]) 
     299                                $appPath .= $currentURL[$i]."/"; 
     300 
     301                define("APP_PATH", $appPath); 
     302 
    233303                $settingsfile =  @ fopen("settings.php","r"); 
     304 
    234305                if($settingsfile){ 
    235                         //loop through the settings file and load variables into the session  
     306 
     307                        //loop through the settings file and load variables into the session 
    236308                        while( !feof($settingsfile)) { 
    237                                 $line=NULL; 
    238                                 $key=NULL; 
    239                                 $value=NULL; 
    240                                 $line=fscanf($settingsfile,"%[^=]=%[^[]]",$key,$value); 
     309 
     310                                $line = NULL; 
     311                                $key = NULL; 
     312                                $value = NULL; 
     313                                $line = @ fscanf($settingsfile,"%[^=]=%[^[]]",$key,$value); 
     314 
    241315                                if ($line){ 
     316 
    242317                                        $key=trim($key); 
    243318                                        $value=trim($value); 
    244                                         if($key!="" and !strpos($key,"]")){      
     319 
     320                                        if($key!="" and !strpos($key,"]")){ 
     321 
    245322                                                $startpos=strpos($value,"\""); 
    246323                                                $endpos=strrpos($value,"\""); 
     324 
    247325                                                if($endpos!=false) 
    248326                                                        $value=substr($value,$startpos+1,$endpos-$startpos-1); 
    249                                                 if(strpos($key,"mysql_")===0){ 
     327 
     328                                                if(strpos($key,"mysql_")===0) 
    250329                                                        define(strtoupper($key),$value); 
    251                                                 } 
    252                                         } 
    253                                 } 
    254                         } 
    255                          
     330 
     331                                        }//endif key 
     332 
     333                                }//endif line 
     334 
     335                        }//endwhile 
     336 
    256337                        @ fclose($settingsfile); 
    257338 
     
    261342 
    262343                        //this adds the phpbms root to the include path 
    263                         if ( ! defined( "PATH_SEPARATOR" ) ) { 
    264                            
    265                           //if we cannot determin the OS, we will assume its unix 
    266                           if(!isset($_ENV["OS"])) 
    267                                   $_ENV["OS"] = "unix"; 
    268                            
    269                           if ( strpos( $_ENV["OS"], "Win" ) !== false ) 
    270                                 define( "PATH_SEPARATOR", ";" ); 
    271                           else  
    272                                 define( "PATH_SEPARATOR", ":" ); 
    273                            
     344                        if ( !defined( "PATH_SEPARATOR" ) ) { 
     345 
     346                                //if we cannot determin the OS, we will assume its unix 
     347                                if(!isset($_ENV["OS"])) 
     348                                        $_ENV["OS"] = "unix"; 
     349 
     350                                if ( strpos( $_ENV["OS"], "Win" ) !== false ) 
     351                                        define( "PATH_SEPARATOR", ";" ); 
     352                                else 
     353                                        define( "PATH_SEPARATOR", ":" ); 
     354 
    274355                        }//end if 
    275356 
    276                         $pathToAdd=@ getcwd(); 
    277                         ini_set("include_path",ini_get("include_path").PATH_SEPARATOR.$pathToAdd); 
    278                          
    279                         //Now to set the path 
    280                         $pathrev = strrev($_SERVER["PHP_SELF"]); 
    281                         $choppos=0; 
    282  
    283                         for($x=0;$x<$count;$x++) 
    284                                 $choppos = strpos($pathrev,"/",$choppos+1); 
    285                         define("APP_PATH",strrev(substr($pathrev,$choppos))); 
    286                          
     357                        $pathToAdd = @ getcwd(); 
     358 
     359                        //Now we include the root application path to php's include path 
     360                        if(ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$pathToAdd) === false && $reportError) 
     361                                $error = new appError(-310, "Your implementation of PHP does not allow changing of the include path. You may need to modify your PHP settings to allow phpBMS to modify this php ini setting. If you are using a web hosting company, you may need to contact them to allow this.", "Cannot add to include path", true, true, false); 
     362 
     363 
     364                        //return directory to current directory 
    287365                        @ chdir ($currdirectory); 
     366 
    288367                        return $path; 
     368 
    289369                } else { 
     370 
    290371                        if($reportError) 
    291                                 $error= new appError(-300,"You may need to run the install process, or set the permission on your settings file correctly.","Settings File Could Not Be Read",true,true,false); 
     372                                $error = new appError(-300,"","",true,true,false); 
     373 
    292374                        return false; 
    293                 } 
     375 
     376                }//endif settingsfile 
     377 
    294378        }//end function 
    295          
     379 
     380 
    296381        function loadSettings($encoding = "utf8"){ 
    297                 // We are going to make sure that we are using utf8  
     382 
     383                // We are going to make sure that we are using utf8 
    298384                // but it works only in mySQL 5, so we supress errors 
    299385                // when trying it. 
    300386                if($this->db==NULL) 
    301387                        $error=new appError(-310,"","Database not loaded"); 
    302                  
     388 
    303389                $this->db->logError = false; 
    304390                $this->db->stopOnError = false; 
    305          
     391 
    306392                $this->db->setEncoding($encoding); 
    307          
     393 
    308394                $this->db->logError = true; 
    309          
     395 
    310396                $querystatement = "SELECT name,value FROM settings"; 
    311397 
     
    313399 
    314400                if(!$queryresult){ 
     401 
    315402                        $error= new appError(-310,"If you have not ran the update script for phpBMS, please run it before logging in.","Could Not Retrieve Settings From Database"); 
    316403                        return false; 
     404 
    317405                } else { 
     406 
    318407                        while($therecord=$this->db->fetchArray($queryresult)){ 
    319                          
     408 
    320409                                //old versions used a reserved constant in certain php versions 
    321410                                if($therecord["name"] == "currency_symbol") 
    322411                                        $therecord["name"] = "currency_sym"; 
    323                                          
     412 
    324413                                if(!defined(strtoupper($therecord["name"]))) 
    325414                                        define(strtoupper($therecord["name"]),$therecord["value"]); 
     
    330419                        if(!isset($_SERVER['REQUEST_URI'])) { 
    331420                                $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; 
    332                                  
     421 
    333422                                if(!defined("HOUR_FORMAT")) 
    334423                                        define("HOUR_FORMAT","%I"); 
    335                          
     424 
    336425                                // Append the query string if it exists and isn't null 
    337426                                if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) 
     
    342431 
    343432                        return true; 
    344                 } 
    345         } 
    346  
    347  
     433 
     434                }//endif queryresult 
     435 
     436        }//end function 
     437 
     438 
     439        // This is in a function in case we want to do sessions differently in the future 
    348440        function startSession(){ 
    349                 // This is in a function in case we want to do sessions differently in the future                
    350                  
     441 
    351442                session_name("phpBMS".preg_replace('/\W/',"",APPLICATION_NAME)."v096ID"); 
    352443                session_start(); 
    353         } 
    354  
    355  
    356         function verifyAPIlogin($user,$pass){ 
    357                 $thereturn=false; 
     444 
     445        }//end function startSesion 
     446 
     447 
     448        function verifyAPIlogin($user, $pass){ 
     449 
     450                $thereturn = false; 
    358451                $this->db->stopOnError = false; 
    359                  
    360                 $querystatement = "SELECT id, firstname, lastname, email, phone, department, employeenumber, admin 
    361                                                 FROM users  
    362                                                 WHERE login!=\"Scheduler\" AND login=\"".mysql_real_escape_string($user)."\"  
    363                                                 AND password=ENCODE(\"".mysql_real_escape_string($pass)."\",\"".mysql_real_escape_string(ENCRYPTION_SEED)."\")  
    364                                                 AND revoked=0 AND portalaccess=1"; 
     452 
     453                $querystatement = " 
     454                        SELECT 
     455                                id, 
     456                                firstname, 
     457                                lastname, 
     458                                email, 
     459                                phone, 
     460                                department, 
     461                                employeenumber, 
     462                                admin 
     463                        FROM 
     464                                users 
     465                        WHERE 
     466                                login != 'Scheduler' 
     467                                AND login = '".mysql_real_escape_string($user)."' 
     468                                AND password = ENCODE('".mysql_real_escape_string($pass)."', '".mysql_real_escape_string(ENCRYPTION_SEED)."') 
     469                                AND revoked = 0 
     470                                AND portalaccess = 1"; 
     471 
    365472                $queryresult = $this->db->query($querystatement); 
     473 
    366474                if(!$queryresult) { 
     475 
    367476                        $error = new appError(-720,"","Error retrieving user record",true,true,true,"json"); 
    368477                        return false; 
    369                 } 
    370                  
     478 
     479                }//endif 
     480 
    371481                if($this->db->numRows($queryresult)){ 
     482 
    372483                        //We found a record that matches in the database 
    373484                        // populate the session and go in 
    374                         $_SESSION["userinfo"]=$this->db->fetchArray($queryresult); 
    375                  
    376                         $querystatement="UPDATE users SET modifieddate=modifieddate, lastlogin=Now() WHERE id = ".$_SESSION["userinfo"]["id"]; 
    377                         $queryresult=@ $this->db->query($querystatement); 
    378                         if(!$queryresult) { 
     485                        $_SESSION["userinfo"] = $this->db->fetchArray($queryresult); 
     486 
     487                        $querystatement = " 
     488                                UPDATE 
     489                                        users 
     490                                SET 
     491                                        modifieddate=modifieddate, 
     492                                        lastlogin=Now() 
     493                                WHERE 
     494                                        id = ".$_SESSION["userinfo"]["id"]; 
     495 
     496                        $queryresult = @ $this->db->query($querystatement); 
     497 
     498                        if(!$queryresult) 
    379499                                $error = new appError(-730,"","Error Updating User Login Time",true,true,true,"json"); 
    380                         } else 
    381                                 $thereturn=true; 
    382                 } 
    383                 return $thereturn;       
    384         } 
    385          
    386 }//end loginSession class 
    387  
    388  
    389 // Start Code 
    390 //================================================================================================================= 
    391 //php <4.3.0 compatibility 
    392 if(!function_exists("mysql_real_escape_string")){ 
    393         function mysql_real_escape_string($string){ 
    394                 return mysql_escape_string($string); 
    395         } 
    396          
    397    function utf8_replaceEntity($result){ 
    398            $value = (int)$result[1]; 
    399            $string = ''; 
    400            
    401            $len = round(pow($value,1/8)); 
    402            
    403            for($i=$len;$i>0;$i--){ 
    404                    $part = ($value & (255>>2)) | pow(2,7); 
    405                    if ( $i == 1 ) $part |= 255<<(8-$len); 
    406                    
    407                    $string = chr($part) . $string; 
    408                    
    409                    $value >>= 6; 
    410            } 
    411            
    412            return $string; 
    413    } 
    414    
    415         if(!function_exists("mysql_real_escape_string")){ 
    416                 function html_entity_decode($string){ 
    417                         return preg_replace_callback('/&#([0-9]+);/u','utf8_replaceEntity',$string); 
    418                 }//end function 
    419         }//end if 
    420  
    421 }// end PHP<4.3 compatibility 
     500                        else 
     501                                $thereturn = true; 
     502 
     503                }//endif numrows 
     504 
     505                return $thereturn; 
     506 
     507        }//end function verifyAPIlogin 
     508 
     509 
     510        //Check to see if install folders are present.  If so, do not continue. 
     511        function checkForInstallDirs($errorFormat = "xhtml"){ 
     512 
     513                //first lets check for the main programs install folder 
     514                if(file_exists("install") && is_dir("install")) 
     515                        $error = new appError(-353,"You must remove the install directory and all modules' install directories before phpBMS can run.","Main Install Directory Present",true,true,true,$errorFormat); 
     516 
     517                $thedir= @ opendir("modules"); 
     518 
     519                while($entry = readdir($thedir)){ 
     520 
     521                        if($entry != "." && $entry != ".." && $entry != "base" && $entry != "sample" && is_dir("modules/".$entry)){ 
     522 
     523                                if(file_exists("modules/".$entry."/install") && is_dir("modules/".$entry."/install")){ 
     524 
     525                                        $error = new appError(-354,"You must remove the install directory and all modules' install directories before phpBMS can run.","Module '".$entry."' Install Directory Present",true,true,true,$errorFormat); 
     526 
     527                                }//endif 
     528 
     529                        }//endif 
     530 
     531                }//end if 
     532 
     533        }//end function checkForInstallDirs 
     534 
     535}//end phpbmsSession class 
     536 
    422537 
    423538 
    424539// Start Login verification Code 
    425 //================================================================================================================= 
     540//============================================================================== 
    426541if(!isset($sqlEncoding)) 
    427542        $sqlEncoding = "utf8"; 
    428543 
    429544if(!defined("noStartup")){ 
     545 
    430546        $scriptname = basename($_SERVER["PHP_SELF"]); 
    431547        $phpbmsSession = new phpbmsSession; 
    432          
     548 
    433549        //Testing for API login 
    434550        if(strpos($scriptname,"api_")!==false){ 
    435551                if(isset($_POST["phpbmsusername"]) && isset($_POST["phpbmspassword"])){ 
     552 
    436553                        $phpbmsSession->loadDBSettings(APP_DEBUG); 
    437                          
     554 
     555                        if(!APP_DEBUG) 
     556                                $phpbmsSession->checkForInstallDirs("json"); 
     557 
    438558                        include_once("include/db.php"); 
    439559                        $db = new db(); 
    440560                        $phpbmsSession->db = $db; 
    441561 
    442                         include_once("common_functions.php");                    
     562                        include_once("common_functions.php"); 
    443563                        $phpbmsSession->loadSettings($sqlEncoding); 
    444564                        $phpbms = new phpbms($db); 
    445          
    446          
     565 
     566 
    447567                        if(!$phpbmsSession->verifyAPILogin($_POST["phpbmsusername"],$_POST["phpbmspassword"])) 
    448568                                $error = new appError(-700,"","Login credentials incorrect",true,true,true,"json"); 
     569 
    449570                } else 
    450571                        $error= new appError(-710,"","No login credentials passed",true,true,true,"json"); 
     572 
    451573        } else { 
    452          
     574 
    453575                $phpbmsSession->loadDBSettings(APP_DEBUG); 
    454          
    455          
     576 
     577                if(!APP_DEBUG) 
     578                        $phpbmsSession->checkForInstallDirs(); 
     579 
     580                //start database 
    456581                include_once("include/db.php"); 
    457582                $db = new db(); 
    458                  
     583 
    459584                $phpbmsSession->db = $db; 
    460                  
     585 
     586                //load application settings from table 
    461587                $phpbmsSession->loadSettings($sqlEncoding); 
    462                  
     588 
    463589                include_once("common_functions.php"); 
    464590                $phpbms = new phpbms($db); 
    465                  
     591 
    466592                if(!isset($noSession)) 
    467593                        $phpbmsSession->startSession(); 
    468                  
     594 
    469595                if (!isset($_SESSION["userinfo"]) && $scriptname != "index.php") { 
    470                  
     596 
    471597                        if(isset($loginNoKick)){ 
     598 
    472599                                if(!isset($loginNoDisplayError)) 
    473600                                        exit(); 
     601 
    474602                        } else{ 
     603 
    475604                                goURL(APP_PATH."index.php"); 
    476                         } 
    477                 } 
    478                  
    479         } 
    480          
    481         $db->stopOnError=true; 
     605 
     606                        }//endif 
     607 
     608                }//endif iseet userinfo 
     609 
     610        }//endif 
     611 
     612        $db->stopOnError = true; 
     613 
    482614}//end if 
    483615 
  • trunk/phpbms/include/tables.php

    r427 r485  
    3939 
    4040 
    41 class phpbmsTable{ 
    42          
    43         var $db = NULL; 
    44         var $backurl = NULL; 
    45          
    46         // The table definition record id. 
    47         var $id=0; 
    48          
    49         var $fields = array(); 
    50  
    51         function phpbmsTable($db,$tabledefid = 0,$backurl = NULL){ 
    52          
    53                 if(is_object($db)) 
    54                         if(get_class($db)=="db") 
    55                                 $this->db = $db; 
    56                 if($this->db === NULL) 
    57                         $error = new appError(-800,"database object is required for parameter 1.","Initializing phpbmsTable Class"); 
    58  
    59                 $this->id = ((int) $tabledefid); 
    60                  
    61                 if($backurl == NULL) 
    62                         $this->backurl = APP_PATH."search.php?id=".$this->id; 
    63                 else  
    64                         $this->backurl = $backurl; 
    65                          
    66                 if(!$this->getTableInfo()) 
    67                         $error = new appError(-810,"Table definition not found for id ".$this->id,"Initializing phpbmsTable Class"); 
    68         } 
    69          
    70          
    71         function getTableInfo(){ 
    72                 $querystatement = "SELECT * FROM tabledefs WHERE id=".$this->id; 
    73                  
    74                 $queryresult = $this->db->query($querystatement); 
    75                  
    76                 if($this->db->numRows($queryresult)){ 
    77                         foreach($this->db->fetchArray($queryresult) as $key => $value) 
    78                                 $this->$key = $value; 
    79                          
    80                         $this->fields = $this->db->tableInfo($this->maintable); 
    81                          
    82                         return true;                                             
    83                 } else 
    84                         return false; 
    85         } 
    86          
    87         function getDefaultByType($fieldtype){ 
    88                         $default = NULL; 
    89                          
    90                         switch ($fieldtype){ 
    91                                 case "blob": 
    92                                 case "string": 
    93                                         $default = ""; 
    94                                 break; 
    95                                 case "real": 
    96                                 case "int": 
    97                                         $default = 0; 
    98                                 break; 
    99                                 case "date": 
    100                                         $default=dateToString(mktime(),"SQL"); 
    101                                 break; 
    102                                 case "time": 
    103                                         $default=timeToString(mktime(),"SQL"); 
    104                                 break; 
    105                                 case "year": 
    106                                         $default=strftime("%Y"); 
    107                                 break; 
    108                                 case "datetime": 
    109                                 case "timestamp": 
    110                                         $default = dateToString(mktime(),"SQL")." ".timeToString(mktime(),"24 Hour"); 
    111                                 break; 
    112                         } 
    113                          
    114                         return $default; 
    115                          
    116         } 
    117          
    118         function prepareFieldForSQL($value,$type,$flags){ 
    119                         switch ($type){ 
    120                                  
    121                                 case "blob": 
    122                                 case "string": 
    123                                         if($value === "" or $value === NULL){ 
    124                                                 if(strpos($flags,"not_null") === false) 
    125                                                         $value = NULL; 
    126                                                 else 
    127                                                         $value = "''"; 
    128                                         } else                                   
    129                                                 $value = "'".$value."'"; 
    130                                 break; 
    131                                  
    132                                 case "real": 
    133                                         if($value === "" or $value === NULL){ 
    134                                                 if(strpos($flags,"not_null") === false) 
    135                                                         $value = NULL; 
    136                                                 else 
    137                                                         $value = 0; 
    138                                         } else                                   
    139                                                 $value = (real) $value; 
    140                                 break; 
    141                                  
    142                                 case "int": 
    143                                         if($value === "" or $value === NULL){ 
    144                                                 if(strpos($flags,"not_null") === false) 
    145                                                         $value = NULL; 
    146                                                 else 
    147                                                         $value = 0; 
    148                                         } else 
    149                                                 $value = (int) $value; 
    150                                 break; 
    151                                  
    152                                 case "date": 
    153                                         if($value === "" or $value === NULL){ 
    154                                                 if(strpos($flags,"not_null") === false) 
    155                                                         $value = NULL; 
    156                                                 else 
    157                                                         $value = "'".dateToString(mktime(),"SQL")."'"; 
    158                                         } else 
    159                                                 $value = "'".sqlDateFromString($value)."'"; 
    160                                 break; 
    161  
    162                                 case "time": 
    163                                         if($value === "" or $value === NULL){ 
    164                                                 if(strpos($flags,"not_null") === false) 
    165                                                         $value = NULL; 
    166                                                 else 
    167                                                         $value = "'".timeToString(mktime(),"SQL")."'"; 
    168                                         } else 
    169                                                 $value = "'".sqlTimeFromString($value)."'"; 
    170                                 break; 
    171                                  
    172                                 case "year": 
    173                                         if($value === "" or $value === NULL) 
    174                                                 if(strpos($flags,"not_null") === false) 
    175                                                         $value = NULL; 
    176                                                 else 
    177                                                         $value = strftime("%Y"); 
    178                                 break; 
    179                                  
    180                                 case "datetime": 
    181                                 case "timestamp": 
    182                                         if($value === "" or $value === NULL){ 
    183                                                 if(strpos($flags,"not_null") === false) 
    184                                                         $value = NULL; 
    185                                                 else 
    186                                                         $value = "'".dateToString(mktime(),"SQL")." ".timeToString(mktime(),"24 Hour")."'"; 
    187                                         } else{ 
    188                                                 $datetimearray = explode(" ",$value); 
    189                                                 if(count($datetimearray) > 1){ 
    190                                                         $value = "'".sqlDateFromString($datetimearray[0])." ".sqlTimeFromString($datetimearray[1])."'"; 
    191                                                 } else  
    192                                                 $value = "'".$value."'"; 
    193                                         } 
    194                                 break; 
    195                                 case "password": 
    196                                         $value = "ENCODE('".$value."','".ENCRYPTION_SEED."')"; 
    197                                 break;           
    198                         }//end case 
    199  
    200  
    201                         if($value === NULL) 
    202                                 $value = "NULL"; 
    203                         return $value; 
    204         }//end method 
    205          
    206          
    207         function getDefaults(){ 
    208                 $therecord = array(); 
    209                  
    210                 foreach($this->fields as $fieldname => $thefield){ 
    211                         switch($fieldname){ 
    212                                 case "id": 
    213                                 case "modifiedby":                       
    214                                 case "modifieddate": 
    215                                         $therecord[$fieldname] = NULL; 
    216                                 break; 
    217                                  
    218                                 case "createdby": 
    219                                         $therecord["createdby"] = $_SESSION["userinfo"]["id"]; 
    220                                 break; 
    221                                                                  
    222                                 default: 
    223                                         if(strpos($thefield["flags"],"not_null") === false) 
    224                                                 $therecord[$fieldname] = NULL; 
    225                                         else { 
    226                                                 $therecord[$fieldname] = $this->getDefaultByType($thefield["type"]); 
    227                                         } 
    228                                 break; 
    229                         }//end switch 
    230                 }//end foreach 
    231                  
    232                 return $therecord; 
    233         } 
    234          
    235          
    236         function getRecord($id = 0){ 
    237                 $id = (int) $id; 
    238                  
    239                 $querystatement = "SELECT "; 
    240                                  
    241                 foreach($this->fields as $fieldname => $thefield){ 
    242                         if(isset($thefield["select"])) 
    243                                 $querystatement .= "(".$thefield["select"].") AS `".$fieldname."`, "; 
     41        class phpbmsTable{ 
     42 
     43                var $db = NULL; 
     44                var $backurl = NULL; 
     45                var $verifyErrors = array(); 
     46 
     47                // The table definition record id. 
     48                var $id=0; 
     49 
     50                var $fields = array(); 
     51 
     52                function phpbmsTable($db,$tabledefid = 0,$backurl = NULL){ 
     53 
     54                        if(is_object($db)) 
     55                                if(get_class($db)=="db") 
     56                                        $this->db = $db; 
     57                        if($this->db === NULL) 
     58                                $error = new appError(-800,"database object is required for parameter 1.","Initializing phpbmsTable Class"); 
     59 
     60                        $this->id = ((int) $tabledefid); 
     61 
     62                        if($backurl == NULL) 
     63                                $this->backurl = APP_PATH."search.php?id=".$this->id; 
    24464                        else 
    245                                 $querystatement .= "`".$fieldname."`, "; 
    246                 }//end foreach 
    247                 $querystatement = substr($querystatement, 0, strlen($querystatement)-2); 
    248                  
    249                 $querystatement .= " FROM `".$this->maintable."` WHERE `".$this->maintable."`.`id` = ".$id; 
    250                                  
    251                 $queryresult = $this->db->query($querystatement); 
    252                  
    253                 if($this->db->numRows($queryresult)) 
    254                         $therecord = $this->db->fetchArray($queryresult); 
    255                 else  
    256                         $therecord = $this-> getDefaults(); 
    257                  
    258                 return $therecord; 
    259         }//end getRecord function 
    260          
    261          
    262         function updateRecord($variables, $modifiedby = NULL){ 
    263                 $variables = addSlashesToArray($variables); 
    264                  
    265                 if($modifiedby === NULL) 
    266                         if(isset($_SESSION["userinfo"]["id"])) 
    267                                 $modifiedby = $_SESSION["userinfo"]["id"]; 
    268                         else 
    269                                 $error = new appError(-840,"Session Timed Out.","Creating New Record"); 
    270  
    271                 if(!isset($variables["id"])) 
    272                         $error = new appError(-820,"id not set","Updating Record"); 
    273                  
    274                 $updatestatement = "UPDATE `".$this->maintable."` SET "; 
    275                  
    276                 foreach($this->fields as $fieldname => $thefield){ 
    277                         if(!isset($thefield["select"])){ 
     65                                $this->backurl = $backurl; 
     66 
     67                        if(!$this->getTableInfo()) 
     68                                $error = new appError(-810,"Table definition not found for id ".$this->id,"Initializing phpbmsTable Class"); 
     69                } 
     70 
     71 
     72                function getTableInfo(){ 
     73                        $querystatement = "SELECT * FROM tabledefs WHERE id=".$this->id; 
     74 
     75                        $queryresult = $this->db->query($querystatement); 
     76 
     77                        if($this->db->numRows($queryresult)){ 
     78                                foreach($this->db->fetchArray($queryresult) as $key => $value) 
     79                                        $this->$key = $value; 
     80 
     81                                $this->fields = $this->db->tableInfo($this->maintable); 
     82 
     83                                return true; 
     84                        } else 
     85                                return false; 
     86                } 
     87 
     88                function getDefaultByType($fieldtype){ 
     89                                $default = NULL; 
     90 
     91                                switch ($fieldtype){ 
     92                                        case "blob": 
     93                                        case "string": 
     94                                                $default = ""; 
     95                                        break; 
     96                                        case "real": 
     97                                        case "int": 
     98                                                $default = 0; 
     99                                        break; 
     100                                        case "date": 
     101                                                $default=dateToString(mktime(),"SQL"); 
     102                                        break; 
     103                                        case "time": 
     104                                                $default=timeToString(mktime(),"SQL"); 
     105                                        break; 
     106                                        case "year": 
     107                                                $default=strftime("%Y"); 
     108                                        break; 
     109                                        case "datetime": 
     110                                        case "timestamp": 
     111                                                $default = dateToString(mktime(),"SQL")." ".timeToString(mktime(),"24 Hour"); 
     112                                        break; 
     113                                } 
     114 
     115                                return $default; 
     116 
     117                } 
     118 
     119                function prepareFieldForSQL($value,$type,$flags){ 
     120                                switch ($type){ 
     121 
     122                                        case "blob": 
     123                                        case "string": 
     124                                                if($value === "" or $value === NULL){ 
     125                                                        if(strpos($flags,"not_null") === false) 
     126                                                                $value = NULL; 
     127                                                        else 
     128                                                                $value = "''"; 
     129                                                } else 
     130                                                        $value = "'".$value."'"; 
     131                                        break; 
     132 
     133                                        case "real": 
     134                                                if($value === "" or $value === NULL){ 
     135                                                        if(strpos($flags,"not_null") === false) 
     136                                                                $value = NULL; 
     137                                                        else 
     138                                                                $value = 0; 
     139                                                } else 
     140                                                        $value = (real) $value; 
     141                                        break; 
     142 
     143                                        case "int": 
     144                                                if($value === "" or $value === NULL){ 
     145                                                        if(strpos($flags,"not_null") === false) 
     146                                                                $value = NULL; 
     147                                                        else 
     148                                                                $value = 0; 
     149                                                } else 
     150                                                        $value = (int) $value; 
     151                                        break; 
     152 
     153                                        case "date": 
     154                                                if($value === "" or $value === NULL){ 
     155                                                        if(strpos($flags,"not_null") === false) 
     156                                                                $value = NULL; 
     157                                                        else 
     158                                                                $value = "'".dateToString(mktime(),"SQL")."'"; 
     159                                                } else 
     160                                                        $value = "'".sqlDateFromString($value)."'"; 
     161                                        break; 
     162 
     163                                        case "time": 
     164                                                if($value === "" or $value === NULL){ 
     165                                                        if(strpos($flags,"not_null") === false) 
     166                                                                $value = NULL; 
     167                                                        else 
     168                                                                $value = "'".timeToString(mktime(),"SQL")."'"; 
     169                                                } else 
     170                                                        $value = "'".sqlTimeFromString($value)."'"; 
     171                                        break; 
     172 
     173                                        case "year": 
     174                                                if($value === "" or $value === NULL) 
     175                                                        if(strpos($flags,"not_null") === false) 
     176                                                                $value = NULL; 
     177                                                        else 
     178                                                                $value = strftime("%Y"); 
     179                                        break; 
     180 
     181                                        case "datetime": 
     182                                        case "timestamp": 
     183                                                if($value === "" or $value === NULL){ 
     184                                                        if(strpos($flags,"not_null") === false) 
     185                                                                $value = NULL; 
     186                                                        else 
     187                                                                $value = "'".dateToString(mktime(),"SQL")." ".timeToString(mktime(),"24 Hour")."'"; 
     188                                                } else{ 
     189                                                        $datetimearray = explode(" ",$value); 
     190                                                        if(count($datetimearray) > 1){ 
     191                                                                $value = "'".sqlDateFromString($datetimearray[0])." ".sqlTimeFromString($datetimearray[1])."'"; 
     192                                                        } else 
     193                                                        $value = "'".$value."'"; 
     194                                                } 
     195                                        break; 
     196                                        case "password": 
     197                                                $value = "ENCODE('".$value."','".ENCRYPTION_SEED."')"; 
     198                                        break; 
     199                                }//end case 
     200 
     201 
     202                                if($value === NULL) 
     203                                        $value = "NULL"; 
     204                                return $value; 
     205                }//end method 
     206 
     207 
     208                function getDefaults(){ 
     209                        $therecord = array(); 
     210 
     211                        foreach($this->fields as $fieldname => $thefield){ 
    278212                                switch($fieldname){ 
    279213                                        case "id": 
    280                                         case "creationdate": 
     214                                        case "modifiedby": 
     215                                        case "modifieddate": 
     216                                                $therecord[$fieldname] = NULL; 
     217                                        break; 
     218 
    281219                                        case "createdby": 
    282                                         break; 
     220                                                $therecord["createdby"] = $_SESSION["userinfo"]["id"]; 
     221                                        break; 
     222 
     223                                        default: 
     224                                                if(strpos($thefield["flags"],"not_null") === false) 
     225                                                        $therecord[$fieldname] = NULL; 
     226                                                else { 
     227                                                        $therecord[$fieldname] = $this->getDefaultByType($thefield["type"]); 
     228                                                } 
     229                                        break; 
     230                                }//end switch 
     231                        }//end foreach 
     232 
     233                        return $therecord; 
     234                } 
     235 
     236 
     237                function getRecord($id = 0){ 
     238                        $id = (int) $id; 
     239 
     240                        $querystatement = "SELECT "; 
     241 
     242                        foreach($this->fields as $fieldname => $thefield){ 
     243                                if(isset($thefield["select"])) 
     244                                        $querystatement .= "(".$thefield["select"].") AS `".$fieldname."`, "; 
     245                                else 
     246                                        $querystatement .= "`".$fieldname."`, "; 
     247                        }//end foreach 
     248                        $querystatement = substr($querystatement, 0, strlen($querystatement)-2); 
     249 
     250                        $querystatement .= " FROM `".$this->maintable."` WHERE `".$this->maintable."`.`id` = ".$id; 
     251 
     252                        $queryresult = $this->db->query($querystatement); 
     253 
     254                        if($this->db->numRows($queryresult)) 
     255                                $therecord = $this->db->fetchArray($queryresult); 
     256                        else 
     257                                $therecord = $this-> getDefaults(); 
     258 
     259                        return $therecord; 
     260                }//end getRecord function 
     261 
     262 
     263                function prepareVariables($variables){ 
     264 
     265                        return $variables; 
     266 
     267                }//end method --prepareVariables-- 
     268 
     269 
     270                function verifyVariables($variables){ 
     271 
     272                        $thereturn = array(); 
     273 
     274                        if(!isset($this->verifyErrors)) 
     275                                $this->verifyErrors = array(); 
     276 
     277                        if(isset($variables["id"])) 
     278                                if(!is_numeric($variables["id"]) && $variables["id"]) 
     279                                        $this->verifyErrors[] = "The `id` field must be numeric or equivalent to zero (although positive is reccomended)."; 
     280 
     281                        if(isset($variables["inactive"])) 
     282                                if($variables["inactive"] && $variables["inactive"] != 1) 
     283                                        $this->verifyErrors[] = "The `inactive` field must be a boolean (equivalent to 0 or exactly 1)."; 
    283284                                         
    284                                         case "modifiedby": 
    285                                                 $updatestatement .= "`modifiedby` = ".((int) $modifiedby).", "; 
    286                                         break; 
    287          
    288                                         case "modifieddate": 
    289                                                 $updatestatement .= "`modifieddate` = NOW(), "; 
    290                                         break; 
    291                                          
    292                                         default: 
    293                                                 if(!isset($variables[$fieldname]) && strpos($thefield["flags"],"not_null") !== false) 
    294                                                         $variables[$fieldname] = $this->getDefaultByType($thefield["type"],true); 
    295                                                  
    296                                                 if(isset($variables[$fieldname])) 
    297                                                         $updatestatement .= "`".$fieldname."` = ".$this->prepareFieldForSQL($variables[$fieldname],$thefield["type"],$thefield["flags"]).", "; 
    298                                         break; 
    299                                 }//end switch field name 
    300                         }//end if 
    301                 }//end foreach 
    302                 $updatestatement = substr($updatestatement, 0, strlen($updatestatement)-2); 
    303                  
    304                 $updatestatement .= " WHERE `id`=".((int) $variables["id"]); 
    305  
    306                 $updateresult = $this->db->query($updatestatement); 
    307                  
    308                 return true; 
    309         } 
    310          
    311          
    312         function insertRecord($variables,$createdby = NULL, $overrideID = false){ 
    313          
    314                 if($createdby === NULL) 
    315                         if(isset($_SESSION["userinfo"]["id"])) 
    316                                 $createdby = $_SESSION["userinfo"]["id"]; 
     285                        if(count($this->verifyErrors)) 
     286                                $thereturn = $this->verifyErrors; 
     287 
     288                        unset($this->verifyErrors); 
     289 
     290                        return $thereturn; 
     291 
     292                }//end method --verifyVariables-- 
     293 
     294 
     295                function updateRecord($variables, $modifiedby = NULL){ 
     296 
     297                        $variables = addSlashesToArray($variables); 
     298 
     299                        if($modifiedby === NULL) 
     300                                if(isset($_SESSION["userinfo"]["id"])) 
     301                                        $modifiedby = $_SESSION["userinfo"]["id"]; 
     302                                else 
     303                                        $error = new appError(-840,"Session Timed Out.","Creating New Record"); 
     304 
     305                        if(!isset($variables["id"])) 
     306                                $error = new appError(-820,"id not set","Updating Record"); 
     307 
     308                        $updatestatement = "UPDATE `".$this->maintable."` SET "; 
     309 
     310                        foreach($this->fields as $fieldname => $thefield){ 
     311                                if(!isset($thefield["select"])){ 
     312                                        switch($fieldname){ 
     313                                                case "id": 
     314                                                case "creationdate": 
     315                                                case "createdby": 
     316                                                break; 
     317 
     318                                                case "modifiedby": 
     319                                                        $updatestatement .= "`modifiedby` = ".((int) $modifiedby).", "; 
     320                                                break; 
     321 
     322                                                case "modifieddate": 
     323                                                        $updatestatement .= "`modifieddate` = NOW(), "; 
     324                                                break; 
     325 
     326                                                default: 
     327                                                        if(!isset($variables[$fieldname]) && strpos($thefield["flags"],"not_null") !== false) 
     328                                                                $variables[$fieldname] = $this->getDefaultByType($thefield["type"],true); 
     329 
     330                                                        if(isset($variables[$fieldname])) 
     331                                                                $updatestatement .= "`".$fieldname."` = ".$this->prepareFieldForSQL($variables[$fieldname],$thefield["type"],$thefield["flags"]).", "; 
     332                                                break; 
     333                                        }//end switch field name 
     334                                }//end if 
     335                        }//end foreach 
     336                        $updatestatement = substr($updatestatement, 0, strlen($updatestatement)-2); 
     337 
     338                        $updatestatement .= " WHERE `id`=".((int) $variables["id"]); 
     339 
     340                        $updateresult = $this->db->query($updatestatement); 
     341 
     342 
     343                        return true; 
     344                } 
     345 
     346 
     347                function insertRecord($variables,$createdby = NULL, $overrideID = false){ 
     348 
     349                        if($createdby === NULL) 
     350                                if(isset($_SESSION["userinfo"]["id"])) 
     351                                        $createdby = $_SESSION["userinfo"]["id"]; 
     352                                else 
     353                                        $error = new appError(-840,"Session Timed Out.","Creating New Record"); 
     354 
     355 
     356                        $variables = addSlashesToArray($variables); 
     357 
     358                        $fieldlist = ""; 
     359                        $insertvalues = ""; 
     360                        foreach($this->fields as $fieldname => $thefield){ 
     361                                if(!isset($thefield["select"])){ 
     362                                        switch($fieldname){ 
     363                                                case "id": 
     364                                                        if(isset($variables["id"])) 
     365                                                                if($overrideID && $variables["id"]){ 
     366                                                                        $fieldlist .= "id, "; 
     367                                                                        $insertvalues .= ((int) $variables["id"]).", "; 
     368                                                                }//endif 
     369                                                        break; 
     370 
     371                                                case "createdby": 
     372                                                case "modifiedby": 
     373                                                        $fieldlist .= $fieldname.", "; 
     374                                                        $insertvalues .= ((int) $createdby).", "; 
     375                                                        break; 
     376 
     377                                                case "creationdate": 
     378                                                case "modifieddate": 
     379                                                        $fieldlist .= $fieldname.", "; 
     380                                                        $insertvalues .= "NOW(), "; 
     381                                                        break; 
     382 
     383                                                default: 
     384                                                        if(!isset($variables[$fieldname]) && strpos($thefield["flags"],"not_null") !== false) 
     385                                                                $variables[$fieldname] = $this->getDefaultByType($thefield["type"],true); 
     386 
     387                                                        if(isset($variables[$fieldname])){ 
     388                                                                $fieldlist .= "`".$fieldname."`, "; 
     389                                                                $insertvalues .= $this->prepareFieldForSQL($variables[$fieldname],$thefield["type"],$thefield["flags"]).", "; 
     390                                                        }//endif - fieldname 
     391                                                        break; 
     392                                        }//end switch field name 
     393                                }//end if 
     394                        }//end foreach 
     395                        $fieldlist = substr($fieldlist, 0, strlen($fieldlist)-2); 
     396                        $insertvalues = substr($insertvalues, 0, strlen($insertvalues)-2); 
     397 
     398                        $insertstatement = "INSERT INTO ".$this->maintable." (".$fieldlist.") VALUES (".$insertvalues.")"; 
     399                        $insertresult = $this->db->query($insertstatement); 
     400 
     401                        if($insertresult) 
     402                                return $this->db->insertId(); 
    317403                        else 
    318                                 $error = new appError(-840,"Session Timed Out.","Creating New Record"); 
    319  
    320                  
    321                 $variables = addSlashesToArray($variables); 
    322  
    323                 $fieldlist = ""; 
    324                 $insertvalues = ""; 
    325                 foreach($this->fields as $fieldname => $thefield){ 
    326                         if(!isset($thefield["select"])){ 
    327                                 switch($fieldname){ 
    328                                         case "id": 
    329                                                 if(isset($variables["id"])) 
    330                                                         if($overrideID && $variables["id"]){ 
    331                                                                 $fieldlist .= "id, "; 
    332                                                                 $insertvalues .= ((int) $variables["id"]).", "; 
    333                                                         }//endif 
    334                                                 break; 
    335                                          
    336                                         case "createdby": 
    337                                         case "modifiedby": 
    338                                                 $fieldlist .= $fieldname.", ";                                   
    339                                                 $insertvalues .= ((int) $createdby).", "; 
    340                                                 break; 
    341          
    342                                         case "creationdate": 
    343                                         case "modifieddate": 
    344                                                 $fieldlist .= $fieldname.", "; 
    345                                                 $insertvalues .= "NOW(), "; 
    346                                                 break; 
    347                                          
    348                                         default: 
    349                                                 if(!isset($variables[$fieldname]) && strpos($thefield["flags"],"not_null") !== false) 
    350                                                         $variables[$fieldname] = $this->getDefaultByType($thefield["type"],true); 
    351                                                  
    352                                                 if(isset($variables[$fieldname])){ 
    353                                                         $fieldlist .= "`".$fieldname."`, "; 
    354                                                         $insertvalues .= $this->prepareFieldForSQL($variables[$fieldname],$thefield["type"],$thefield["flags"]).", "; 
    355                                                 }//endif - fieldname 
    356                                                 break; 
    357                                 }//end switch field name 
    358                         }//end if 
    359                 }//end foreach 
    360                 $fieldlist = substr($fieldlist, 0, strlen($fieldlist)-2); 
    361                 $insertvalues = substr($insertvalues, 0, strlen($insertvalues)-2); 
    362  
    363                 $insertstatement = "INSERT INTO ".$this->maintable." (".$fieldlist.") VALUES (".$insertvalues.")"; 
    364                 $insertresult = $this->db->query($insertstatement); 
    365                  
    366                 if($insertresult) 
    367                         return $this->db->insertId(); 
    368                 else 
    369                         return false; 
    370         } 
    371          
    372          
    373         function processAddEditPage(){ 
    374                 if(!isset($_POST["command"])){ 
    375                          
    376                         if(isset($_GET["id"])){ 
    377                                 //editing 
    378                                 if(!hasRights($this->editroleid)) 
    379                                         goURL(APP_PATH."noaccess.php"); 
    380                                 else 
    381                                         return $this->getRecord((integer) $_GET["id"]); 
    382                         } else { 
    383                                 if(!hasRights($this->addroleid)) 
    384                                         goURL(APP_PATH."noaccess.php"); 
    385                                 else     
    386                                         return $this->getDefaults(); 
     404                                return false; 
     405                } 
     406 
     407 
     408                function processAddEditPage(){ 
     409                        if(!isset($_POST["command"])){ 
     410 
     411                                if(isset($_GET["id"])){ 
     412                                        //editing 
     413                                        if(!hasRights($this->editroleid)) 
     414                                                goURL(APP_PATH."noaccess.php"); 
     415                                        else 
     416                                                return $this->getRecord((integer) $_GET["id"]); 
     417                                } else { 
     418                                        if(!hasRights($this->addroleid)) 
     419                                                goURL(APP_PATH."noaccess.php"); 
     420                                        else 
     421                                                return $this->getDefaults(); 
     422                                } 
    387423                        } 
    388                 } 
    389                 else 
    390                 { 
    391                         switch($_POST["command"]){ 
    392                                 case "cancel": 
    393                                         // if we needed to do any clean up (deleteing temp line items) 
    394                                         if(!isset($_POST["id"])) $_POST["id"]=0; 
    395  
    396                                         $theurl = $this->backurl; 
    397                                          
    398                                         if(isset($_POST["id"])) 
    399                                                 $theurl .= "#".((int) $_POST["id"]); 
    400                                         goURL($theurl);                                  
    401                                 break; 
    402                                 case "save": 
    403                                         if($_POST["id"]) { 
    404                                                 $this->updateRecord($_POST);                                             
    405                                                 $theid = $_POST["id"]; 
    406                                                 //get record 
    407                                                 $therecord = $this->getRecord($theid); 
    408                                                 $therecord["phpbmsStatus"]="Record Updated"; 
    409  
    410                                                 return $therecord; 
    411                                         } 
    412                                         else { 
    413                                                 $theid = $this->insertRecord($_POST); 
    414                                                  
    415                                                 //get record 
    416                                                 $therecord=$this->getRecord($theid); 
    417                                                 $therecord["phpbmsStatus"] = "<div style=\"float:right;margin-top:-3px;\"><button type=\"button\" class=\"smallButtons\" onclick=\"document.location='".str_replace("&","&amp;",$_SERVER["REQUEST_URI"])."'\">add new</button></div>"; 
    418                                                 $therecord["phpbmsStatus"] .= "Record Created"; 
    419                                                  
    420                                                 return $therecord; 
    421                                         } 
    422                                 break; 
    423                         }//end command switch                    
    424                 }// end if 
    425         }// end function 
    426 } 
     424                        else 
     425                        { 
     426                                switch($_POST["command"]){ 
     427                                        case "cancel": 
     428                                                // if we needed to do any clean up (deleteing temp line items) 
     429                                                if(!isset($_POST["id"])) $_POST["id"]=0; 
     430 
     431                                                $theurl = $this->backurl; 
     432 
     433                                                if(isset($_POST["id"])) 
     434                                                        $theurl .= "#".((int) $_POST["id"]); 
     435                                                goURL($theurl); 
     436                                        break; 
     437                                        case "save": 
     438 
     439                                                $variables = $this->prepareVariables($_POST); 
     440                                                $errorArray = $this->verifyVariables($variables); 
     441 
     442                                                if($_POST["id"]) { 
     443 
     444                                                        $theid = $variables["id"]; 
     445 
     446                                                        if(!count($errorArray)){ 
     447 
     448                                                                $this->updateRecord($variables); 
     449 
     450                                                                //get record 
     451                                                                $therecord = $this->getRecord($theid); 
     452                                                                $therecord["phpbmsStatus"] = "Record Updated"; 
     453                                                        }else{ 
     454                                                                foreach($errorArray as $error) 
     455                                                                        $logError = new appError(-900, $error, "Verification Error"); 
     456 
     457                                                                //get record 
     458                                                                $therecord = $this->getRecord($theid); 
     459                                                                $therecord["phpbmsStatus"] = "Data Verification Error"; 
     460                                                        }//end if 
     461 
     462 
     463 
     464                                                        return $therecord; 
     465                                                } 
     466                                                else { 
     467 
     468                                                        $theid = 0; 
     469 
     470                                                        if(!count($errorArray)){ 
     471                                                                $theid = $this->insertRecord($variables); 
     472                                                                //get record 
     473                                                                $therecord = $this->getRecord($theid); 
     474                                                                $therecord["phpbmsStatus"] = "<div style=\"float:right;margin-top:-3px;\"><button type=\"button\" class=\"smallButtons\" onclick=\"document.location='".str_replace("&","&amp;",$_SERVER["REQUEST_URI"])."'\">add new</button></div>"; 
     475                                                                $therecord["phpbmsStatus"] .= "Record Created"; 
     476                                                        }else{ 
     477                                                                foreach($errorArray as $error) 
     478                                                                        $logError = new appError(-900, $error, "Verification Error"); 
     479 
     480                                                                //get record 
     481                                                                $therecord = $this->getRecord($theid); 
     482                                                                $therecord["phpbmsStatus"] .= "Data Verification Error"; 
     483                                                        }//end if 
     484 
     485                                                        return $therecord; 
     486                                                } 
     487                                        break; 
     488                                }//end command switch 
     489                        }// end if 
     490                }// end function 
     491        }//end class 
    427492?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.