Current File : /home/inlingua/public_html/sales/commonFunc.php |
<?php
// Store all common / global functions here
function sendEmail($from='',$fromName='', $to='', $subject='', $message='',$bcc)
{ //Do not send email while debugging
// Prevent attempts to send spam by injection
$cfrom = urldecode($from);
if (eregi("(\r|\n)", $cfrom)) die("Why ?? :(");
$cto = urldecode($to);
if (eregi("(\r|\n)", $cto)) die("Why ?? :(");
$csubject = urldecode($subject);
if (eregi("(\r|\n)", $csubject)) die("Why ?? :(");
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->SetLanguage( 'en', 'phpmailer/language/' );
$mail->IsSMTP();
$mail->Host = SMTPSERVER; // defined in globalVars.php
$mail->SMTPAuth = true;
$mail->Username = SMTPUSER; // defined in globalVars.php
$mail->Password = SMTPPASSWORD; // defined in globalVars.php
$mail->From = $from;
$mail->FromName = $fromName;//optional from name
$mail->AddAddress($to, "");
if ($bcc != "") $mail->AddBCC($bcc, "");
//$mail->AddBCC("subhash@panalinks.com", "");
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->Send())
{ echo "Message could not be sent. ";
echo "Mailer Error: " . $mail->ErrorInfo;
return false;
}
return true;
}
function g_uuid() {
return sprintf(uniqid(''));
}
function createKey($length=6) {
$chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$i = 0;
$password = "";
while ($i <= $length) {
$password .= $chars{mt_rand(0,strlen($chars))};
$i++;
}
$mTime = str_replace(".","",microtime(true));
$mTime = str_replace(" ","-",$mTime);
$key = $mTime . "-" . $password;
return $key;
}
function createPassword($length=6) {
$chars = "abcdefghijkmnopqrstuvwxyz";
$i = 0;
$password = "";
while ($i <= $length) {
$password .= $chars{mt_rand(0,strlen($chars))};
$i++;
}
return $password;
}
function select_drop($select_array,$name_select,$firstrow="Select",$firstrowvalue=0,$selected,$extra)
{
$a="<select name='".$name_select."' ".$extra.">";
$a.="<option value='".$firstrowvalue."'>".$firstrow."</option>";
foreach($select_array as $key=>$val)
{
$a.="<option value='".$key."' ";
if($key==$selected)
{
$a.="selected";
}
$a.=">".$val."</option>";
}
$a.="</select>";
return $a;
}
function radio_buttons($radio_array,$radio_name,$radio_checked,$extra,$breakafter)
{
$a.="<div style='float:left;width:100%;border:0px solid #cccccc;'>";
$percentage=100/$breakafter;
foreach($radio_array as $key=>$val)
{
$a.="<div style='float:left;width:".round($percentage)."%;border:0px solid #cccccc;'>";
$a.="<input type='radio' name='".$radio_name."' value='".$key."'";
if($key==$radio_checked)
{
$a.="checked";
}
$a.=" ".$extra.">".$val."";
$a.="</div>";
}
$a.="</div>";
return $a;
}
function check_buttons($check_array,$check_name,$check_checked,$extra,$breakafter)
{
$a.="<div style='float:left;width:100%;border:0px solid #cccccc;'>";
$percentage=100/$breakafter;
foreach($check_array as $key=>$val)
{
$a.="<div style='float:left;width:".round($percentage)."%;border:0px solid #cccccc;'>";
$a.="<input type='checkbox' name='".$check_name."[]' value='".$key."'";
if($key==$check_checked)
{
$a.="checked";
}
$a.=" ".$extra.">".$val."";
$a.="</div>";
}
$a.="</div>";
return $a;
}
?>