Version: 1.0
Type: Full Script
Category: Other
License: GNU General Public License
Description: functions is use for other coding that can/need to be included.
<?
/*
$Id: functions.php3,v 1.2 2002/03/17 03:07:23 grant Exp $
$Name: $
Generic screen output type functions
*/
/*
WCDS_MAIL_IT
Mail wrapper to ensure valid email address and other stuff
NOTE: Ordinarily there MUST be two linefeeds between headers and message. PHP mail adds them.
*/
function WCDS_mail_it($from="root",$to="root",$subject="Unspecified Subject",$message="",$reply_to="root",$priority="") {
switch (strtolower($priority)) {
case "h":
$importance = "High";
$xpriority = "1 (Highest)";
break;
case "l":
$importance = "Low";
$xpriority = "5 (Lowest)";
break;
default:
$importance = "Normal";
$xpriority = "3 (Normal)";
break;
}
$from="From:$from";
$reply_to="Reply-To:$reply_to";
$mail_headers
= "$from\n"
. "$reply_to\n"
. "MIME-Version: 1.0\n"
. "Content-Type: text/plain\n"
. " charset=\"iso-8859-1\"\n"
. "Content-Transfer-Encoding: 7bit\n"
. "X-Priority: $xpriority\n"
. "X-MSMail-Priority: $importance\n"
. "X-Mailer: WCDS, Build 1.01\n"
. "X-MimeOLE: Hand crafted by the grunter :-)\n"
. "Importance: $importance"
;
$mail_body = ($message) ? $message : "Where is you message?";
return (mail($to,"$subject",$mail_body,$mail_headers)) ;
}
/*
WCDS_SPLIT_ONCE
function to split a string at the first occurrence of the splitter
result is returned in an array. if ther splitter isn't in the string
then the string is returned in the first element of the array
Example:
$WCDS_splitonce("--subject=Backup Results","=");
Returns:
Array
(
[0] => --subject
[1] => Backup Results
)
*/
function WCDS_split_once($data="",$splitter="") {
$WCDS_split_once = array();
$pos = strpos($data,$splitter);
$split_length=strlen($splitter);
if (!$pos === false) {
$env = substr($data,0,$pos);
$val = substr($data,$pos+$split_length,strlen($data)-$pos-split_length);
$WCDS_split_once[] = "$env";
$WCDS_split_once[] = "$val";
} else {
$WCDS_split_once[] = "$data";
$WCDS_split_once[] = "";
}
return $WCDS_split_once;
}
/*
WCDS_GETOPTS
function to create an array of command line parameters
parameters are processed in order, left to right
Example:
program --day="Tuesday" --month="January" -c -v /tmp/filename
Returns:
Array
(
[--day] => Tuesday
[--month] => January
[3] => -c
[4] => -v
[5] => /tmp/filename
)
*/
function WCDS_getopts() {
global $argc;
global $argv;
$WCDS_getopts = array();
$count = 1;
$option = 0;
$input="";
while ($count<$argc) {
$input = $argv[$count];
if ((substr($input,0,2))=="--") {
$options = WCDS_split_once($input,"=");
$WCDS_getopts[$options[0]] = $options[1];
} elseif ((substr($input,0,1))=="-") {
$WCDS_getopts[$count] = $input;
} else {
$WCDS_getopts[$count] = $input;
}
$count++;
}
return $WCDS_getopts;
}
/*
WCDS_GETENV
function to obtain the available environment variables
results are returned in an array with both numeric
and associative indices.
*/
function WCDS_getenv() {
$WCDS_getenv = "";
$count = 0;
if ($WCDS_pipe = popen("env","r")) {
while (!feof($WCDS_pipe)) {
$data=chop(fgets($WCDS_pipe,512));
$vars=WCDS_split_once($data,"=");
if ($vars[1] <> "") {
$WCDS_getenv[$count] = array(0=>$vars[0], 1=>$vars[1]);
$WCDS_getenv[$vars[0]] = $vars[1];
$count++;
}
}
pclose($WCDS_pipe);
}
return $WCDS_getenv;
}
/*
WCDS_GET_FILE
function to returns the contents of a file in a string
Example:
WCDS_get_file("/tmp/filename");
Returns:
Contents of File
OR
PHP Error Message
*/
function WCDS_get_file($file="") {
$WCDS_get_file = "";
if ($file) {
if (filesize($file)==0) { return ("WCDS:ERR: $file is empty.\n"); }
$fd = @fopen($file,"r");
if ($fd) {
$WCDS_get_file = @fread($fd,filesize($file));
if (!$WCDS_get_file) { return ("WCDS:ERR:$php_errormsg\n"); }
} else {
return ("WCDS:ERR:Can't open file $file\n");
}
} else {
return ("WCDS:ERR:Which file was that again?\n");
}
return ($WCDS_get_file);
}
/*
WCDS_scr
output text with or without termination character
*/
function WCDS_scr($text="",$termination=0) {
switch ($termination) {
case "1":
echo $text;
break;
default:
echo $text."\n";
break;
}
}
/*
WCDS_scr
*/
function WCDS_bit($text="",$termination=1) {
WCDS_scr($text."... ",$termination);
}
/*
WCDS_scr
*/
function WCDS_chk($text="",$termination=1) {
WCDS_scr("CHK:".date("His").": $text ... ",$termination);
}
/*
WCDS_scr
*/
function WCDS_err($text="") {
//get "ERR"
WCDS_scr("ERR:".date("His").": $text");
WCDS_scr("\nFinished Processing");
exit;
}
/*
$Log: functions.php3,v $
Revision 1.2 2002/03/17 03:07:23 grant
Lastest commit and introduction of new files
Revision 1.1.1.1 2002/03/16 03:08:38 grant
Imported Sources
*/
?>