| Current Path : /var/www/html/mmishra/indem/pcstore/pcStore/ |
| Current File : /var/www/html/mmishra/indem/pcstore/pcStore/mcell_library.php |
<?php
function access_log($sql9, $con){
mysql_query("insert into access_log(dated,login,activity) values(now(),'" . $_SESSION['login'] . "',\"$sql9\")", $con);
}
function category($row_id9, $con){
$sql9 = "select * from parts_category where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$name = $qd9["name"];
return $name;
}
function supplier($row_id9, $con){
$sql9 = "select * from supplier_master where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$firm_name = $qd9["firm_name"];
return $firm_name;
}
function ugroup($row_id9, $con){
$sql9 = "select * from customer_group where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$name = $qd9["name"];
return $name;
}
function customer($row_id9, $con){
$sql9 = "select * from customer_master where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$name = $qd9["name"];
$email = $qd9["email"];
if($email > '') $email = ' - ' . $qd9["email"];
$gid = $qd9['group_code'];
$sql9 = "select * from customer_group where row_id=$gid";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$name .= $email . ' (' . $qd9["name"] . ')';
return $name;
}
function series($row_id9, $con){
$sql9 = "select * from product_series where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$name = $qd9["name"];
return $name;
}
function product($row_id9, $con){
$sql9 = "select * from product_master where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$code = $qd9["pc_code"];
$description = $qd9["description"];
return $code . " (" . $description . ")";
}
function item($row_id9, $con){
$sql9 = "select * from parts_receipt where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$description = $qd9["description"];
return $description;
}
function parts($row_id9, $con){
$sql9 = "select * from parts_master where row_id=$row_id9";
$rs9 = mysql_query($sql9, $con);
$qd9 = mysql_fetch_array($rs9);
$code = $qd9["parts_code"];
return $code;// . " (" . $description . ")";
}
function table_data($sql9, $con, $no, $tbl){
$rs9 = mysql_query($sql9, $con);
if (!mysql_num_rows($rs9)){
$sdata .= "<dir>None</dir>";
}else{
$sdata .= "<table width='99%'><tr valign='top'><th>No.</th>";
$num_fields = mysql_num_fields($rs9);
for ($y = 0; $y < $num_fields; $y++){
$sdata .= "<th><a href='" . $_SERVER["SCRIPT_NAME"] . "?tbl=$tbl&sfield=" . mysql_field_name($rs9, $y) . "'>" . ucfirst(strtr(mysql_field_name($rs9, $y), "_", " ")) . "</a></th>";
}
$sdata .= "</tr>";
while ($qdata = mysql_fetch_row($rs9)){
$no++;
$sdata .= "<tr id='";
if ($no % 2) $sdata .= "row1'>"; else $sdata .= "row2'>";
$sdata .= "<td>$no</td>";
for ($z = 0; $z < $num_fields; $z++){
switch ($qdata[$z]){
case "0000-00-00":
$fldvalue = " ";
break;
case "0":
$fldvalue = "Nil";
break;
default:
$fldvalue = $qdata[$z];
break;
}
$sdata .= "<td>$fldvalue</td>";
}
$sdata .= "</tr>";
//$no++;
}
mysql_free_result($rs9);
$sdata .= "</table>";
$sdata .= "<div align='right'>Click on column heading to sort result</div>";
}
return $sdata;
}
//mail
function send_mail($user_code, $con){
include("class.phpmailer.php");
if (!$user_code) return "None";
$rs9 = mysql_query("select email from $customer_master where row_id=$user_code and email like '%@iiita.ac.in'", $con);
if (!mysql_num_rows($rs9)){
return "Invalid user/email";
}else{
$o = mysql_fetch_object($rs9);
$email = $o->email;
}
if (substr($email,0,2) == "..") return "Invalid email";
$mail_body = "Dear user,\n\tYour hardware related loan status is as below:\n\n";
$mail_body .= "Product Description:\n";
$sql9 = "select pm.series_code,pm.pc_code,pi.issue_date,pi.due_date,pi.issue_for,pi.destination,pi.remark from $product_issued pi, $product_master pm where pi.pc_code=pm.row_id and pi.user_code=$user_code";
$rs9 = mysql_query($sql9, $con);
if (!mysql_num_rows($rs9)){
$mail_body .= "\tNone";
}else{
while ($o = mysql_fetch_object($rs9)){
$i++;
$desc = $o->pc_code;
$issued_on = $o->issue_date;
$mail_body .= "\t" . $i . ") Code " . $desc . " issued on " . $issued_on . "\n";
}
}
$i = 0;
$mail_body .= "\nParts Detail:\n";
$sql9 = "select pi.*,pm.item_code from parts_issued pi, parts_master pm where pi.parts_code=pm.row_id and pi.user_code=$user_code order by pi.issue_date";
$rs9 = mysql_query($sql9, $con);
if (!mysql_num_rows($rs9)){
$mail_body .= "\tNone";
}else{
while ($o = mysql_fetch_object($rs9)){
$i++;
$parts_code = $o->parts_code;
$item_code = $o->item_code;
$desc = parts($parts_code, $con) . " (" . item($item_code, $con) . ")";
$issued_on = $o->issue_date;
$mail_body .= "\t" . $i . ") Code " . $desc . " issued on " . $issued_on . "\n";
}
}
$mail_body .= "\n\nHappy computing,\n\nMaintenance Cell\nIIIT - Allahabad\n\n(auto generated by pcStore ver. 2.0)";;
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->AddAddress($email,$email);
$mail->Subject = "MCell - Loan Status";
$mail->Body = $mail_body;
$mail->WordWrap = 50;
if(!$mail->Send()){
//echo "Message was not sent";
return "Mailer Error: " . $mail->ErrorInfo;
}else{
return $mail_body;//"Message has been sent";
}
}
?>