Changeset 485 for trunk/phpbms/include/common_functions.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/include/common_functions.php (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/include/common_functions.php
r427 r485 40 40 // it should be instanced in session.php 41 41 class phpbms{ 42 42 43 43 var $db; 44 44 var $modules = array();//array of installed modules … … 48 48 var $bottomJS = array(); 49 49 var $onload = array(); 50 50 51 51 var $showFooter = true; 52 52 var $showMenu = true; 53 53 54 54 function phpbms($db){ 55 55 $this->db = $db; 56 56 57 57 $this->modules = $this->getModules(); 58 58 } … … 65 65 } 66 66 } 67 67 68 68 function showJsIncludes(){ 69 69 foreach($this->jsIncludes as $theinclude){ … … 84 84 }//end method 85 85 86 86 87 87 function getModules(){ 88 88 $modules = array(); 89 89 90 90 $querystatement = "SELECT * FROM `modules`"; 91 91 $queryresult = $this->db->query($querystatement); 92 92 while($therecord = $this->db->fetchArray($queryresult)) 93 93 $modules[$therecord["name"]] = $therecord; 94 94 95 95 return $modules; 96 96 } 97 97 98 98 99 99 function displayRights($roleid,$rolename = NULL){ 100 100 switch($roleid){ 101 101 102 102 case 0: 103 103 echo "EVERYONE"; 104 104 break; 105 105 106 106 case -100: 107 107 echo "Administrators"; 108 108 break; 109 109 110 110 default: 111 111 if(!$rolename){ 112 112 $querystatement = "SELECT name FROM roles WHERE id=".((int) $roleid); 113 113 $queryresult = $this->db->query($querystatement); 114 114 115 115 $therecord = $this->db->fetchArray($queryresult); 116 116 $rolename = $therecord["name"]; 117 117 }//end if 118 118 119 119 echo $rolename; 120 120 }//end case … … 123 123 124 124 function showTabs($tabgroup,$currenttabid,$recordid=0){ 125 125 126 126 $querystatement="SELECT id,name,location,enableonnew,notificationsql,tooltip,roleid FROM tabs WHERE tabgroup=\"".$tabgroup."\" ORDER BY displayorder"; 127 127 $queryresult=$this->db->query($querystatement); 128 129 ?><ul class="tabs"><?php 128 129 ?><ul class="tabs"><?php 130 130 while($therecord=$this->db->fetchArray($queryresult)){ 131 131 132 132 if(hasRights($therecord["roleid"])){ 133 133 134 134 ?><li <?php if($therecord["id"]==$currenttabid) echo "class=\"tabsSel\"" ?>><?php 135 135 if($therecord["id"]==$currenttabid || ($recordid==0 && $therecord["enableonnew"]==0)){ … … 143 143 $therecord["notificationsql"]=str_replace("{{id}}",((int) $recordid),$therecord["notificationsql"]); 144 144 $notificationresult=$this->db->query($therecord["notificationsql"]); 145 145 146 146 if($this->db->numRows($notificationresult)!=0){ 147 147 $notificationrecord=$this->db->fetchArray($notificationresult); … … 153 153 } 154 154 } 155 155 156 156 echo $opener.$therecord["name"].$closer; 157 158 ?></li><?php 157 158 ?></li><?php 159 159 }//endif hasRights 160 }//end whilt 160 }//end whilt 161 161 ?> 162 162 </ul><?php … … 165 165 166 166 function getUserName($id=0){ 167 167 168 168 $querystatement="select concat(firstname,\" \",lastname) as name from users where id=".((int) $id); 169 169 $queryresult = $this->db->query($querystatement); 170 170 171 171 $tempinfo = $this->db->fetchArray($queryresult); 172 172 return trim($tempinfo["name"]); 173 173 174 174 }// end method 175 175 … … 222 222 if(count($temparray)==3) 223 223 $thedate=mktime(0,0,0,(int) $temparray[1],(int) $temparray[2],(int) $temparray[0]); 224 else 224 else 225 225 return false; 226 226 break; … … 231 231 if(count($temparray)==4) 232 232 $thedate=mktime(0,0,0,(int) $temparray[1],(int) $temparray[2],(int) $temparray[3]); 233 else 233 else 234 234 return false; 235 235 break; 236 236 237 237 case "English, UK": 238 238 $datestring="/".ereg_replace(",.","/",$datestring); … … 240 240 if(count($temparray)==4) 241 241 $thedate=mktime(0,0,0,(int) $temparray[2],(int) $temparray[1],(int) $temparray[3]); 242 else 242 else 243 243 return false; 244 244 break; 245 245 246 246 case "Dutch, NL": 247 247 $datestring="-".ereg_replace(",.","-",$datestring); … … 249 249 if(count($temparray)==4) 250 250 $thedate=mktime(0,0,0,(int) $temparray[2],(int) $temparray[1],(int) $temparray[3]); 251 else 251 else 252 252 return false; 253 253 break; … … 302 302 $datestring=strftime("%Y-%m-%d",$thedate); 303 303 break; 304 304 305 305 case "English, US": 306 306 $datestring=strftime("%m/%d/%Y",$thedate); 307 307 break; 308 308 309 309 case "English, UK": 310 310 $datestring=strftime("%d/%m/%Y",$thedate); … … 349 349 if($format=="24 Hour") 350 350 $timestring=$sqltime; 351 else 351 else 352 352 $timestring=timeToString(stringToTime($sqltime,"24 Hour"),$format); 353 353 return $timestring; … … 362 362 if(count($tempdatearray)>1 && count($temptimearray)>1) 363 363 $thedatetime=mktime((int) $temptimearray[0],(int) $temptimearray[1],(int) $temptimearray[2],(int) $tempdatearray[1],(int) $tempdatearray[2],(int) $tempdatearray[0]); 364 } 364 } 365 365 return $thedatetime; 366 366 } … … 371 371 if($sqldatetime!=""){ 372 372 $datetimearray=explode(" ",$sqldatetime); 373 373 374 374 $datestring=trim($datetimearray[0]); 375 375 if($dateformat=="SQL") 376 376 $datestring=$datestring; 377 else 377 else 378 378 $datestring=dateToString(stringToDate($datestring,"SQL"),$dateformat); 379 379 if(isset($datetimearray[1])){ … … 381 381 if($timeformat=="24 Hour") 382 382 $timestring=$timestring; 383 else 383 else 384 384 $timestring=timeToString(stringToTime($timestring,"24 Hour"),$timeformat); 385 385 } … … 400 400 settype($datetime, 'string'); 401 401 eregi('(....)(..)(..)(..)(..)(..)',$datetime,$matches); 402 array_shift ($matches); 402 array_shift ($matches); 403 403 foreach (array('year','month','day','hour','minute','second') as $var) { 404 404 $$var = (int) array_shift($matches); 405 405 } 406 407 406 407 408 408 $thedatetime=mktime($hour,$minute,$second,$month,$day,$year); 409 409 410 410 return trim(dateToString($thedatetime,$dateformat)." ".timeToString($thedatetime,$timeformat)); 411 411 } … … 448 448 $number=str_replace(DECIMAL_SYMBOL,".",$number); 449 449 $number=((real) $number); 450 450 451 451 return $number; 452 452 } 453 453 454 454 // Phone/Email functions 455 //===================================================================== 456 function 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 479 function 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-- 455 507 456 508 //============================================================================ … … 496 548 497 549 //This function prepares an array for SQL manipulation. 498 550 499 551 if(get_magic_quotes_runtime() || get_magic_quotes_gpc()){ 500 501 foreach ($thearray as $key=>$value) 552 553 foreach ($thearray as $key=>$value) 502 554 if(is_array($value)) 503 555 $thearray[$key]= addSlashesToArray($value); 504 556 else 505 557 $thearray[$key] = mysql_real_escape_string(stripslashes($value)); 506 507 } else 558 559 } else 508 560 foreach ($thearray as $key=>$value) 509 561 if(is_array($value)) 510 $thearray[$key]= addSlashesToArray($value); 562 $thearray[$key]= addSlashesToArray($value); 511 563 else 512 564 $thearray[$key] = mysql_real_escape_string($value); 513 565 514 566 return $thearray; 515 567 516 568 }//end function 517 569 … … 522 574 if(!isset($sqlEncoding)) 523 575 $sqlEncoding = ""; 524 576 525 577 switch ($sqlEncoding){ 526 578 527 579 case "latin1": 528 580 $encoding = "ISO-8859-15"; 529 581 break; 530 582 531 583 case "utf8": 532 584 default: 533 585 $encoding = "UTF-8"; 534 586 break; 535 587 536 588 }//endswitch 537 589 538 590 return htmlspecialchars($string, ENT_COMPAT, $encoding); 539 591 … … 605 657 $value=$value; 606 658 break; 607 608 659 660 609 661 case "bbcode": 610 662 $value=htmlQuotes($value); 611 663 612 664 // This list needs to be expanded 613 665 $bbcodelist["[b]"] = "<strong>"; … … 615 667 $bbcodelist["[br]"] = "<br />"; 616 668 $bbcodelist["[space]"] = " "; 617 669 618 670 foreach($bbcodelist as $bbcode => $translation) 619 671 $value = str_replace($bbcode, $translation, $value); 620 621 break; 622 672 673 break; 674 623 675 default: 624 676 $value=htmlQuotes($value); … … 639 691 640 692 function nl_langinfo($constant){ 641 642 return $constant; 643 693 694 return $constant; 695 644 696 }//end function 645 697 646 698 function nl_setup(){ 647 699 648 700 $date = mktime(0,0,0,10,7,2007); 649 701 650 702 for($i = 1; $i<=7; $i++){ 651 703 652 704 define("ABDAY_".$i, date("D", $date)); 653 705 define("DAY_".$i, date("l"), $date); 654 706 655 707 $date = strtotime("tomorrow", $date); 656 708 }//end for 657 658 709 710 659 711 for($i = 1; $i<=12; $i++){ 660 712 661 713 $date = mktime(0, 0, 0, $i, 1, 2007); 662 714 663 715 define("ABMON_".$i, date("M", $date)); 664 716 define("MON_".$i, date("F"), $date); 665 717 666 718 }//end for 667 719 668 720 }//end function 669 721 670 722 nl_setup(); 671 723 672 724 }//end if 673 725 ?>