$nameLen2) { // so output Jane and John Smith $varNames = $arr_name1[0] . " and " . $arr_name2[0] . " " . $arr_name1[1]; } // if we have "John Smith" and "Jane" elseif($nameLen2>$nameLen1) { $varNames = $arr_name1[0] . " and " . $arr_name2[0] . " " . $arr_name2[1]; } // if we haven't satisfied any of the above conditions -- should rarely happen -- just dump it. else { $varNames=$varName1 . ' and '. $varName2; } } else { $varNames = $varName1; } // spit out the string. return $varNames; } /* this function takes a phone number in the database format and formats it like (613)555-4321. returns a string, so call this function like this: $myvariable = format_phone($param1); */ function Str_Format_Phone($var_PhoneNumber) { if ($var_PhoneNumber) { $LengthOfTelephoneNumber=strlen($var_PhoneNumber); if ($LengthOfTelephoneNumber==10) { $PhoneAC = substr("$var_PhoneNumber", 0, 3); $PhonePrefix = substr("$var_PhoneNumber", 3, 3); $PhoneSuffix = substr("$var_PhoneNumber", 6, 4); $var_PhoneNumber = "(".$PhoneAC.") ".$PhonePrefix."-".$PhoneSuffix; } elseif($LengthOfTelephoneNumber==11) { $PhoneCC = substr("$var_PhoneNumber", 0, 1); $PhoneAC = substr("$var_PhoneNumber", 1, 3); $PhonePrefix = substr("$var_PhoneNumber", 4, 3); $PhoneSuffix = substr("$var_PhoneNumber", 7, 4); $var_PhoneNumber = "$PhoneCC (".$PhoneAC.") ".$PhonePrefix."-".$PhoneSuffix; } } return $var_PhoneNumber; } // returns xth for days, useful for the xth day of month, year. function Str_Get_th_day_of_month_year($var_date) { // echo $var_date; $arr_date = array(); $arr_date = explode("-", $var_date); // print_r($arr_date); // handle the day // special cases here. if ($arr_date[2] == "01") $var_f_date = "1st"; elseif ($arr_date[2] == "02") $var_f_date = "2nd"; elseif ($arr_date[2]=="03") $var_f_date = "3rd"; elseif ($arr_date[2]=="21") $var_f_date = "21st"; elseif ($arr_date[2]=="22") $var_f_date = "22nd"; elseif ($arr_date[2]=="31") $var_f_date = "31st"; // everything else just gets Xth else { // trim off the first zero if there is one. if($arr_date[2] < 10) { $var_date = $arr_date[2]; $var_f_date = ltrim($arr_date[2], "0"); $var_f_date .= "th"; } else $var_f_date = $arr_date[2] . "th"; } // handle the month $arr_date[1] = GetLongMonth($arr_date[1]); $var_F_Date = $var_f_date . " day of " .$arr_date[1] .", " .$arr_date[0]; // echo "returning $var_F_Date
"; return $var_F_Date; } function GetMonthNumber($Month2Convert) { if (($Month2Convert=="Jan")||($Month2Convert=="January")) { return("01"); } if (($Month2Convert=="Feb")||($Month2Convert=="February")) { return("02"); } if (($Month2Convert=="Mar")||($Month2Convert=="March")) { return("03"); } if (($Month2Convert=="Apr")||($Month2Convert=="April")) { return("04"); } if ($Month2Convert=="May") { return("05"); } if (($Month2Convert=="Jun")||($Month2Convert=="June")) { return("06"); } if (($Month2Convert=="Jul")||($Month2Convert=="July")) { return("07"); } if (($Month2Convert=="Aug")||($Month2Convert=="August")) { return("08"); } if (($Month2Convert=="Sep")||($Month2Convert=="Sept")||($Month2Convert=="September")) { return("09"); } if (($Month2Convert=="Oct")||($Month2Convert=="October")) { return("10"); } if (($Month2Convert=="Nov")||($Month2Convert=="November")) { return("11"); } if (($Month2Convert=="Dec")||($Month2Convert=="December")) { return("12"); } } function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles) { $OB="----=_OuterBoundary_000"; $IB="----=_InnerBoundary_001"; $Html=$Html?$Html:preg_replace("/\n/","
",$Text) or die("neither text nor html part present."); $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail."; $From or die("sender address missing"); $To or die("recipient address missing"); $headers ="MIME-Version: 1.0\r\n"; $headers.="From: ".$FromName." <".$From.">\n"; $headers.=($ToName)? "To: ". $ToName ." <".$To.">\n":""; $headers.="Cc: ".$FromName." <".$From.">\n"; $headers.="Reply-To: ".$FromName." <".$From.">\n"; $headers.="X-Priority: 1\n"; $headers.="X-MSMail-Priority: High\n"; $headers.="X-Mailer: My PHP Mailer\n"; $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n"; //Messages start with text/html alternatives in OB $Msg ="This is a multi-part message in MIME format.\n"; $Msg.="\n--".$OB."\n"; $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n"; //plaintext section $Msg.="\n--".$IB."\n"; $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n"; $Msg.="Content-Transfer-Encoding: quoted-printable\n\n"; // plaintext goes here $Msg.=$Text."\n\n"; // html section $Msg.="\n--".$IB."\n"; $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n"; $Msg.="Content-Transfer-Encoding: base64\n\n"; // html goes here if($Html) $Msg.=chunk_split(base64_encode($Html))."\n\n"; // end of IB $Msg.="\n--".$IB."--\n"; // attachments // echo "
attmfiles is $AttmFiles
"; if($AttmFiles) { foreach($AttmFiles as $AttmFile) { // echo "
attmfile is $AttmFile
"; $patharray = explode ("/", $AttmFile); $FileName=$patharray[count($patharray)-1]; // echo "
filename is $FileName
"; $Msg.= "\n--".$OB."\n"; $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n"; $Msg.="Content-Transfer-Encoding: base64\n"; $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"; //file goes here $fd=fopen ($AttmFile, "r"); $FileContent=fread($fd,filesize($AttmFile)); fclose ($fd); $FileContent=chunk_split(base64_encode($FileContent)); $Msg.=$FileContent; $Msg.="\n\n"; } } //message ends $Msg.="\n--".$OB."--\n"; $var_Pass_Fail = mail($To,$Subject,$Msg,$headers); return $var_Pass_Fail; } function SendMailPDF($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles) { $OB="----=_OuterBoundary_000"; $IB="----=_InnerBoundary_001"; $Html=$Html?$Html:preg_replace("/\n/","
",$Text) or die("neither text nor html part present."); $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail."; $From or die("sender address missing"); $To or die("recipient address missing"); $headers ="MIME-Version: 1.0\r\n"; $headers.="From: ".$FromName." <".$From.">\n"; $headers.=($ToName)? "To: ". $ToName ." <".$To.">\n":""; $headers.="Cc: ".$FromName." <".$From.">\n"; $headers.= 'Bcc: system@buildersit.com' . "\r\n"; $headers.="Reply-To: ".$FromName." <".$From.">\n"; $headers.="X-Priority: 1\n"; $headers.="X-MSMail-Priority: High\n"; $headers.="X-Mailer: My PHP Mailer\n"; $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n"; //Messages start with text/html alternatives in OB $Msg ="This is a multi-part message in MIME format.\n"; $Msg.="\n--".$OB."\n"; $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n"; //plaintext section $Msg.="\n--".$IB."\n"; $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n"; $Msg.="Content-Transfer-Encoding: quoted-printable\n\n"; // plaintext goes here $Msg.=$Text."\n\n"; // end of IB $Msg.="\n--".$IB."--\n"; // attachments // echo "
attmfiles is $AttmFiles
"; if($AttmFiles) { foreach($AttmFiles as $AttmFile) { // echo "
attmfile is $AttmFile
"; $patharray = explode ("/", $AttmFile); $FileName=$patharray[count($patharray)-1]; // echo "
filename is $FileName
"; $Msg.= "\n--".$OB."\n"; $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n"; $Msg.="Content-Transfer-Encoding: base64\n"; $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"; //file goes here $fd=fopen ($AttmFile, "r"); $FileContent=fread($fd,filesize($AttmFile)); fclose ($fd); $FileContent=chunk_split(base64_encode($FileContent)); $Msg.=$FileContent; $Msg.="\n\n"; } } //message ends $Msg.="\n--".$OB."--\n"; $var_Pass_Fail = mail($To,$Subject,$Msg,$headers); return $var_Pass_Fail; } function ChangeDateFormat($Thedate,$Delimiter) { // note: the second parameter is the delimiter used in the explode function. //Receive a date in the form of 2008-05-14 and return 14May08 $arrDate = explode($Delimiter, $Thedate); $intYear = substr($arrDate[0], 2); $intMonth = $arrDate[1]; $intDay = $arrDate[2]; $value= $intDay. GetShortMonth($intMonth) . $intYear; return($value); } // following is deprecated but kept in case it would break things to remove it. function BSTEmailValidation($email) { $email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format $domain = explode( "@", $email ); //get the domain name if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) { //if the connection can be established, the email address is probabley valid return true; /* GENERATE A VERIFICATION EMAIL */ } else { return false; //if a connection cannot be established return false } } else { return false; //if email address is an invalid format return false } } //************************************************ //************************************************ // Get the short month name // // Example of code required // $DealDateYear = substr("$var_DealDate",2,2); // $DealDateMonth = substr("$var_DealDate",5,2); // $DealDateDay = substr("$var_DealDate",8,2); // $Month2Convert = $DealDateMonth; // $var_DealDate = GetShortMonth($Month2Convert); // function GetShortMonth($Month2Convert) { if ($Month2Convert=="01") { return("Jan"); } if ($Month2Convert=="02") { return("Feb"); } if ($Month2Convert=="03") { return("Mar"); } if ($Month2Convert=="04") { return("Apr"); } if ($Month2Convert=="05") { return("May"); } if ($Month2Convert=="06") { return("Jun"); } if ($Month2Convert=="07") { return("Jul"); } if ($Month2Convert=="08") { return("Aug"); } if ($Month2Convert=="09") { return("Sep"); } if ($Month2Convert=="10") { return("Oct"); } if ($Month2Convert=="11") { return("Nov"); } if ($Month2Convert=="12") { return("Dec"); } } //************************************************ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Get the long month name // // Example of code required // $DealDateYear = substr("$var_DealDate",2,2); // $DealDateMonth = substr("$var_DealDate",5,2); // $DealDateDay = substr("$var_DealDate",8,2); // $Month2Convert = $DealDateMonth; // $var_DealDate = GetLongMonth($Month2Convert); // function GetLongMonth($Month2Convert) { if ($Month2Convert=="01") { return("January"); } if ($Month2Convert=="02") { return("February"); } if ($Month2Convert=="03") { return("March"); } if ($Month2Convert=="04") { return("April"); } if ($Month2Convert=="05") { return("May"); } if ($Month2Convert=="06") { return("June"); } if ($Month2Convert=="07") { return("July"); } if ($Month2Convert=="08") { return("August"); } if ($Month2Convert=="09") { return("September"); } if ($Month2Convert=="10") { return("October"); } if ($Month2Convert=="11") { return("November"); } if ($Month2Convert=="12") { return("December"); } if($Month2Convert=="00") { return("zeros"); } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //************************************************ //****** Format Date Like 14-Feb-05 function ShowFormatDate($s) { $s = rtrim(ltrim($s)); $arr_month = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); $arr_separator = array ("-","\\",".","/"," "); for($i=0; $i< count($arr_separator); $i++) { if(strstr($s,$arr_separator[$i])) $arr = explode($arr_separator[$i], $s); } if($arr[1] > 12) return $s; if($arr[0] > 31) { $tmp = $arr[0]; $arr[0] = $arr[2]; $arr[2] = $tmp; } if($arr[0] > 31) return $s; for ($i=0; $i<3; $i++) while (strlen($arr[$i])>2) $arr[$i] = substr($arr[$i],1); return $arr[0].$arr_month[$arr[1] - 1].$arr[2]; } /******************************** * VINCE ********************************/ /* REMed while removing this function from pages that have it function DB_to_JQ($var_Date) { $arr_Date = array(); $arr_Date = explode("-", $var_Date); $var_Day = $arr_Date[2]; $var_Month = GetShortMonth($arr_Date[1]); $var_Year = substr($arr_Date[0],2,2); $var_JQDate = $var_Day . $var_Month . $var_Year; return $var_JQDate; } */ function FormatCurrency($v) { $v = round($v,2)+0.001; return substr($v, 0, -1); } function fixlen($v){ $s = "$v"; for ($i=strlen($s); $i<3; $i++){ $s = "  ".$s; } return $s; } $times = array( '00:00' => '00:00', '00:15' => '00:15', '00:30' => '00:30', '00:45' => '00:45', '01:00' => '01:00', '01:15' => '01:15', '01:30' => '01:30', '01:45' => '01:45', '02:00' => '02:00', '02:15' => '02:15', '02:30' => '02:30', '02:45' => '02:45', '03:00' => '03:00', '03:00' => '03:00', '03:15' => '03:15', '03:30' => '03:30', '03:45' => '03:45', '04:00' => '04:00', '04:15' => '04:15', '04:30' => '04:30', '04:45' => '04:45', '05:00' => '05:00', '05:15' => '05:15', '05:30' => '05:30', '05:45' => '05:45', '06:00' => '06:00', '06:15' => '06:15', '06:30' => '06:30', '06:45' => '06:45', '07:00' => '07:00', '07:15' => '07:15', '07:30' => '07:30', '07:45' => '07:45', 'day' => 'day', 'am' => 'am', '08:00' => '08:00', '08:15' => '08:15', '08:30' => '08:30', '08:45' => '08:45', '09:00' => '09:00', '09:15' => '09:15', '09:30' => '09:30', '09:45' => '09:45', '10:00' => '10:00', '10:15' => '10:15', '10:30' => '10:30', '10:45' => '10:45', '11:00' => '11:00', '11:15' => '11:15', '11:30' => '11:30', '11:45' => '11:45', 'pm' => 'pm', '12:00' => '12:00', '12:15' => '12:15', '12:30' => '12:30', '12:45' => '12:45', '13:00' => '13:00', '13:00' => '13:00', '13:15' => '13:15', '13:30' => '13:30', '13:45' => '13:45', '14:00' => '14:00', '14:15' => '14:15', '14:30' => '14:30', '14:45' => '14:45', '15:00' => '15:00', '15:15' => '15:15', '15:30' => '15:30', '15:45' => '15:45', '16:00' => '16:00', '16:15' => '16:15', '16:30' => '16:30', '16:45' => '16:45', '17:00' => '17:00', '17:15' => '17:15', '17:30' => '17:30', '17:45' => '17:45', '18:00' => '18:00', '18:15' => '18:15', '18:30' => '18:30', '18:45' => '18:45', '19:00' => '19:00', '19:15' => '19:15', '19:30' => '19:30', '19:45' => '19:45', '20:00' => '20:00', '20:15' => '20:15', '20:30' => '20:30', '20:45' => '20:45', '21:00' => '21:00', '21:15' => '21:15', '21:30' => '21:30', '21:45' => '21:45', '22:00' => '22:00', '22:15' => '22:15', '22:30' => '22:30', '22:45' => '22:45', '23:00' => '23:00', '23:00' => '23:00', '23:15' => '23:15', '23:30' => '23:30', '23:45' => '23:45', '24:00' => '24:00', '24:15' => '24:15', '24:30' => '24:30', '24:45' => '24:45' ); // Generalized version of injecttoselect, takes any table. // Be careful! there MUST be a col_Lot in the table. function GenerateLotSortInject($var_Table) { $inject = " (@p1 := LOCATE(' ',$var_Table.col_Lot)) + (@p2 := (@p1>0) *LOCATE(' ',$var_Table.col_Lot,@p1+1)) + (@p3 := (@p2>0) *LOCATE(' ',$var_Table.col_Lot,@p2+1)) + (@p4 := (@p3>0) *LOCATE(' ',$var_Table.col_Lot,@p3+1)) + (@p5 := (@p4>0) *LOCATE(' ',$var_Table.col_Lot,@p4+1)) + (@p6 := (@p5>0) *LOCATE(' ',$var_Table.col_Lot,@p5+1)) + ( (@l1 := IF(@p1,SUBSTRING($var_Table.col_Lot,1,@p1-1),$var_Table.col_Lot)) <> '') + ( (@l2 := IF(@p1, IF( @p2,SUBSTRING($var_Table.col_Lot,@p1+1,@p2-@p1), SUBSTRING($var_Table.col_Lot,@p1+1) ) , '')) <> '') + ( (@l3 := IF(@p2, IF( @p3,SUBSTRING($var_Table.col_Lot,@p2+1,@p3-@p2), SUBSTRING($var_Table.col_Lot,@p2+1) ) , '')) <> '') + ( (@l4 := IF(@p3, IF( @p4,SUBSTRING($var_Table.col_Lot,@p3+1,@p4-@p3), SUBSTRING($var_Table.col_Lot,@p3+1) ) , '')) <> '') + ( (@l5 := IF(@p4, IF( @p5,SUBSTRING($var_Table.col_Lot,@p4+1,@p5-@p4), SUBSTRING($var_Table.col_Lot,@p4+1) ) , '')) <> '') + ( (@l6 := IF(@p5, IF( @p6,SUBSTRING($var_Table.col_Lot,@p5+1,@p6-@p5), SUBSTRING($var_Table.col_Lot,@p5+1) ) , '')) <> '') + ((@r1 := IF(@l1 <> '', CONCAT(repeat('0', (substring(@l1,1,1) >= '0' && substring(@l1,1,1) <= '9') * (2 + (substring(@l1,2,1) >= '0' && substring(@l1,2,1) <= '9') * (-1 - (substring(@l1,3,1) >= '0' && substring(@l1,3,1) <= '9')) ) ),@l1),'')) <> '') + ((@r2 := IF(@l2 <> '', CONCAT(repeat('0', (substring(@l2,1,1) >= '0' && substring(@l2,1,1) <= '9') * (2 + (substring(@l2,2,1) >= '0' && substring(@l2,2,1) <= '9') * (-1 - (substring(@l2,3,1) >= '0' && substring(@l2,3,1) <= '9')) ) ),@l2),'')) <> '') + ((@r3 := IF(@l3 <> '', CONCAT(repeat('0', (substring(@l3,1,1) >= '0' && substring(@l3,1,1) <= '9') * (2 + (substring(@l3,2,1) >= '0' && substring(@l3,2,1) <= '9') * (-1 - (substring(@l3,3,1) >= '0' && substring(@l3,3,1) <= '9')) ) ),@l3),'')) <> '') + ((@r4 := IF(@l4 <> '', CONCAT(repeat('0', (substring(@l4,1,1) >= '0' && substring(@l4,1,1) <= '9') * (2 + (substring(@l4,2,1) >= '0' && substring(@l4,2,1) <= '9') * (-1 - (substring(@l4,3,1) >= '0' && substring(@l4,3,1) <= '9')) ) ),@l4),'')) <> '') + ((@r5 := IF(@l5 <> '', CONCAT(repeat('0', (substring(@l5,1,1) >= '0' && substring(@l5,1,1) <= '9') * (2 + (substring(@l5,2,1) >= '0' && substring(@l5,2,1) <= '9') * (-1 - (substring(@l5,3,1) >= '0' && substring(@l5,3,1) <= '9')) ) ),@l5),'')) <> '') + ((@r6 := IF(@l6 <> '', CONCAT(repeat('0', (substring(@l6,1,1) >= '0' && substring(@l6,1,1) <= '9') * (2 + (substring(@l6,2,1) >= '0' && substring(@l6,2,1) <= '9') * (-1 - (substring(@l6,3,1) >= '0' && substring(@l6,3,1) <= '9')) ) ),@l6),'')) <> ''), (1+@r1),(1+@r2),(1+@r3),(1+@r4),(1+@r5),(1+@r6),@r1, @r2, @r3, @r4, @r5, @r6 "; return $inject; } ?>