Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/istore/
Upload File :
Current File : /var/www/html/mmishra/istore/functions.inc.php

<?php

function user_group($uid) {
	$ds = ldap_connect("172.31.1.42");
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
	$z = ldap_bind($ds);
        $a = ldap_search($ds,"dc=iiita,dc=ac,dc=in","(&(uid=$uid)(objectclass=posixAccount))");
        $b = ldap_get_entries($ds,$a);
        $dn = $b[0]["dn"];
        $ou = explode(",", $dn);
        if (strpos($dn,"Employee") || strpos($dn,"PhD"))
                $grp = strtoupper(str_replace("ou=","",$ou[1]));
        else
                $grp = strtoupper(str_replace("ou=","",$ou[3] . $ou[2] . $ou[1]));
	ldap_close($ds);
	return $grp;
}

function user_name($uid) {
        $ds = ldap_connect("172.31.1.42");
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
        $z = ldap_bind($ds);
        $a = ldap_search($ds,"dc=iiita,dc=ac,dc=in","(&(uid=$uid)(objectclass=posixAccount))");
        $b = ldap_get_entries($ds,$a);
        $cn = $b[0]["gecos"][0];
        ldap_close($ds);
        return strtoupper($cn);
}

function get_email($patgroup, $patid) {
        if ($patgroup == 'Student')
	        return $patid.'@iiita.ac.in';
	else if ($patgroup == 'Employee') {
	        $rs = mysql_query("select email from employees where emp_no='$patid'");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
                	return $o->email;
        	} else
			return '';
        } else
		return '';
}

function is_student($patid) {
        $tbl = 'students';

        $rs = mysql_query("select * from $tbl where roll_no='$patid'");
        if (mysql_num_rows($rs)) return TRUE;
	else return FALSE;

}

function student_detail($rollno) {
        $tbl = 'students';

        $str = "<div>";
        $rs = mysql_query("select * from $tbl where roll_no='$rollno'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->name_eng ($o->dob)";
        }
        $str .= "</div>";

        return $str;
}

function is_employee($patid) {
        $tbl = 'employees';
        
        $rs = mysql_query("select * from $tbl where emp_no='$patid'");
        if (mysql_num_rows($rs)) return TRUE;
        else return FALSE;
        
}

function employee_detail($id) {
        $rs = mysql_query("select * from employees where emp_no='$id'");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->emp_name ($o->designation)";
        }

        return $str;
}

function employee_email($id) {
    $rs = mysql_query("select * from employees where emp_no='$id'");
    if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
        return $o->email;
    } else return 'istore@iiita.ac.in';
}

function employee_list($id) {
	$str = "<select name='emp_no' style='width:230'>
	<option value=''></option>";
	$rs = mysql_query("select * from employees order by emp_name");
	while ($o = mysql_fetch_object($rs)) {
			$str .= "<option value='$o->emp_no'";
	if ($id == $o->emp_no) $str .= ' selected';
	$str .= ">$o->emp_name</option>";
	}
	$str .= "</select>";

	return $str;
}

function supplier_detail($id) {
        $rs = mysql_query("select * from st_suppliers where id=$id");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->firm_name ($o->address)";
        }

        return $str;
}

function supplier_list($id) {
        $str = "<select name='supplier' style='width:230'><option value=''></option>";
        $rs = mysql_query("select id,firm_name,address from st_suppliers order by firm_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'".($id == $o->id ? ' selected' : '').">$o->firm_name</option>";
        }
        $str .= "</select>";

        return $str;
}

function bill_detail($id) {
        $rs = mysql_query("select * from st_bills where id=$id");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->bill_no dated $o->bill_date";
        }

        return $str;
}

function bill_list($id) {
        $str = "<select name='bill' style='width:230'><option value=''></option>";
        $rs = mysql_query("select * from st_bills order by id");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'".($id == $o->id ? ' selected' : '').">$o->bill_no</option>";
        }
        $str .= "</select>";

        return $str;
}

function agencystaff_detail($staffnm) {
        $tbl = 'agencystaffs';

        $str = "<div>";
        $rs = mysql_query("select * from $tbl where staff_name='$staffnm'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->staff_name ($o->staff_post)";
        }
        $str .= "</div>";

        return $str;
}

function user_name1($regno) {
	$rs = mysql_query("select pat_group,pat_id,dependent from registrations where reg_no=$regno");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
        	$patgroup = $o->pat_group;
        	$patid = $o->pat_id;
        	$dependent = $o->dependent;
        
		if ($patgroup == 'Student') $sql = "select name_eng as pname,gender as spec from students where roll_no='$patid'";
		else if ($patgroup == 'Employee') $sql = "select emp_name as pname,designation as spec from employees where emp_no='$patid'";
		else $sql = "select staff_name as pname,staff_post as spec from agencystaffs where staff_name='$patid'";

        	$rs = mysql_query($sql);
        	if (mysql_num_rows($rs)) {
        		$o = mysql_fetch_object($rs);
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]<br>$o->pname ($o->spec)";
        	} else {
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]";
		}
		$str .= ($dependent ? "<br>Dependent: $dependent" : '<br>Self');
        }

        return $str;
}

function department_list($dept_no) {
        $str = "<select name='dept_no'><option value=''></option>";
        $rs = mysql_query("select * from departments order by dept_code");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->dept_no'";
                if ($dept_no == $o->dept_no) $str .= ' selected';
                $str .= ">$o->dept_code ($o->dept_name)</option>";
        }
        $str .= '</select>';

        return $str;
}

function department_detail($dept_no) {
        $rs = mysql_query("select * from departments where dept_no=$dept_no");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->dept_code ($o->dept_name)";
        }

        return $str;
}

function project_list($project_no) {
        $str = "<select name='project_no'><option value=''></option>";
        $rs = mysql_query("select * from projects order by project_code");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->project_no'";
                if ($project_no == $o->project_no) $str .= ' selected';
                $str .= ">$o->project_code ($o->project_name)</option>";
        }
        $str .= '</select>';

        return $str;
}


function project_detail($project_no) {
        $rs = mysql_query("select * from projects where project_no=$project_no");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->project_code ($o->project_name)";
        }

        return $str;
}

function category_list($code) {
        $str = "<select name='category'>
        <option value=''></option>";
        $rs = mysql_query("select * from st_category order by code");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'";
                if ($code == $o->id) $str .= ' selected';
                $str .= ">$o->code ($o->description)</option>";
        }
        $str .= '</select>';

        return $str;
}

function category_detail($code) {
        $rs = mysql_query("select * from st_category where id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->code ($o->description)";
        }

        return $str;
}

function subcategory_list($code) {
        $str = "<select name='category'>
        <option value=''></option>";
        $rs = mysql_query("select * from st_subcategory order by code");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'";
                if ($code == $o->id) $str .= ' selected';
                $str .= ">$o->code ($o->description)</option>";
        }
        $str .= '</select>';

        return $str;
}

function subcategory_detail($code) {
        $rs = mysql_query("select * from st_subcategory where id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->code ($o->description)";
        }

        return $str;
}

function item_list($code) {
	$str = "<select name='item'>
	<option value=''></option>";
	$rs = mysql_query("select * from st_items order by code");
	while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'";
		if ($code == $o->id) $str .= ' selected';
		$str .= ">$o->code ($o->description)</option>";
        }
	$str .= '</select>';

        return $str;
}

function item_multilist($code) {
        $str = "<select name='item[]'>
        <option value=''></option>";
        $rs = mysql_query("select * from st_items order by code");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->id'";
                if ($code == $o->id) $str .= ' selected';
                $str .= ">$o->code ($o->description)</option>";
        }
        $str .= '</select>';

        return $str;
}

function item_category($code) {
        $rs = mysql_query("select * from st_category where id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = $o->code;
        }

        return $str;
}

function item_subcategory($code) {
        $rs = mysql_query("select * from st_subcategory where id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = $o->code;
        }

        return $str;
}

function item_detail($code) {
        $rs = mysql_query("select a.*,b.item_type from st_items a, st_subcategory b where a.subcategory=b.id and a.id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->code; $o->description ($o->item_type)";
        }

        return $str;
}

function item_inventory($code) {
        $rs = mysql_query("select a.*,b.item_type from st_items a, st_subcategory b where a.subcategory=b.id and a.id=$code");
        while ($o = mysql_fetch_object($rs)) {
                $str = "$o->code; $o->description ($o->item_type, $o->qty_in/$o->qty_out)";
        }

        return $str;
}

function item_qtyin($code) {
	$rs = mysql_query("select * from st_items where id=$code");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		return number_format($o->qty_in,2);
	} else return 0;
}

function item_qtyout($code) {
    $rs = mysql_query("select * from st_items where id=$code");
    if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
        return number_format($o->qty_out,2);
    } else return 0;
}

function stock_status($code) {
	$rs = mysql_query("select * from st_items where id=$code");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		return number_format($o->qty_in - $o->qty_out,2);
	} else return 0;
}

function stock_available($code) {
	$ok = 0;
	$rs = mysql_query("select * from indent_items where indent_no=$code");
	while ($o = mysql_fetch_object($rs)) {
		if (stock_status($o->item)) $ok = 1;
	}
	return $ok;
}


function indent_approved($code) {
        $rs = mysql_query("select * from indents where indent_no=$code");
        if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
                $str = "<table border='1' width='99%' style='border-collapse: collapse'>
                <tr><th>Indent No.: $code</th><th>Dated: $o->indent_date</th></tr>
		<tr><td width='50%'>Purpose: $o->purpose</td><td>Recommendation: $o->recommendation</td></tr>
		</table>";
        
        	$str .= "<table border='1' width='99%' style='border-collapse: collapse'>
        	<tr><th>No.</th><th>Particulars</th><th>Demand Qty</th><th>Approve Qty</th><th>Approx. Cost</th></tr>";
        	$sr = mysql_query("select * from indent_items where indent_no=$code order by id");
        	while ($q = mysql_fetch_object($sr)) {
			$i++;
                        $str .= "<tr><td>$i $star</td><td>". item_detail($o->item). "</td><td>". number_format($o->qty_demand,2). " $o->unit</td>
                        <td>". number_format($o->qty_approve,2). " $o->unit</td><td>$o->approx_cost</td></tr>";
        	}
        	$str .= "</table><br>";
	}
        
	return $str;
}

function available_items($code) {
	$stock = 0;
	//get available items list
	$rs = mysql_query("select i.*,e.emp_name from indents as i,employees as e where i.emp_no=e.emp_no and indent_no=$code");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		$str = "<table width='90%' border='1' style='border-collapse: collapse'>
		<tr><th>Indent No.: $o->indent_no</th><th>Indentor: $o->emp_name ($o->account Account)</th><th>Dated: $o->date_indent</th></tr>
		<tr><td>Location: $o->location</td><td>Purpose: $o->purpose</td><td>Recommendor: $o->recommendation</td></tr>
		</table>
		<table border='1' width='90%' style='border-collapse: collapse'>
		<tr><th>No.</th><th>Particulars</th><th>Qty Demand</th><th>Qty Approve</th><th>Approx Cost</th></tr>";
		$rs = mysql_query("select * from indent_items where indent_no=$code order by id");
		while ($o = mysql_fetch_object($rs)) {
			$i++;
			if ($o->qty_approve > $o->qty_out && stock_status($o->item) > 0.00) {
				$star = "<font size='+1' color='red'>*</font>";
				$stock = 1;
			} else if ($o->qty_approve == $o->qty_out) {
				$star = "<font size='+1' color='green'>*</font>";
			} else { 
				$star = '';
			}

			//list indented items
			$str .= "<tr><td>$i $star</td><td>". item_detail($o->item). "</td><td>". number_format($o->qty_demand,2). " $o->unit</td>
			<td>". number_format($o->qty_approve,2). " $o->unit</td><td>$o->approx_cost</td></tr>";
		}
		$str .= "</table><br>";
    }
        
	if ($stock) return $str;
	else return '';
}

function indent_issued($code) {
    $rs = mysql_query("select i.*,e.emp_name from indents as i,employees as e where i.emp_no=e.emp_no and indent_no=$code");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		$str = "<table width='90%' border='1' style='border-collapse: collapse'>
		<tr><th>Indent No.: $o->indent_no</th><th>Indentor: $o->emp_name ($o->account Account)</th><th>Dated: $o->date_indent</th></tr>
		<tr><td>Location: $o->location</td><td>Purpose: $o->purpose</td><td>Recommendor: $o->recommendation</td></tr>
		</table>
        	<table border='1' width='90%' style='border-collapse: collapse'>
        	<tr><th>No.</th><th>Particulars</th><th>Qty Demand</th><th>Qty Approve</th><th>Qty Out</th><th>Approx Cost</th></tr>";
        	$sr = mysql_query("select * from indent_items where indent_no=$code order by id");
        	while ($q = mysql_fetch_object($sr)) {
                	$i++;
                	$str .= "<tr><td>$i</td><td>".item_detail($q->item)."</td><td>$q->qty_demand</td><td>$q->qty_approve</td></td>";
        	
			$ss = mysql_query("select * from st_stockout where indent_no=$code and item=$q->item");
        		if (mysql_num_rows($ss)) {
				$r = mysql_fetch_object($ss);
                	       	$str .=  number_format($r->qty_out,2);
        		}
			$str .= "</td><td>$q->approx_cost</td></tr>";
        	}
		$str .= "</table><br>";
	}

        return $str;
}

function issued_indent($code) {
    $rs = mysql_query("select i.*,e.emp_name from indents as i,employees as e where i.emp_no=e.emp_no and indent_no=$code");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		$str = "<table width='90%' border='1' style='border-collapse: collapse'>
		<tr><th>Indent No.: $o->indent_no (Status: $o->status)</th><th>Indentor: $o->emp_name (Account: $o->account Account)</th><th>Dated: $o->date_indent</th></tr>
		<tr><td>Location: $o->location</td><td>Purpose: $o->purpose</td><td>Recommendor: $o->recommendation</td></tr>
		</table>
		<table width='90%' border='1' style='border-collapse: collapse'>
		<tr><th>No.</th><th>Particulars</th><th>Qty Demand</th><th>Qty Approve</th><th>Qty Out</th><th>Approx Cost</th></tr>";

		$sr = mysql_query("select * from indent_items where indent_no=$code order by id");
		while ($q = mysql_fetch_object($sr)) {
			$i++;
			//list indented items
			$str .= "<tr><td>$i</td><td>". item_detail($q->item). "</td><td>". number_format($q->qty_demand,2). "</td><td>". number_format($q->qty_approve,2). "</td>
			<td>". number_format($q->qty_out,2). "</td><td>$q->approx_cost</td></tr>";
		}
		$str .= "</table>";
	}

	return $str;
}

function issuedQty($indentno, $itemno) {
        $rs = mysql_query("select * from st_stockout where indent_no=$indentno and item=$itemno");
        if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		return $o->qty_out;
	} else {
		return 0;
	}
}

function staff_list($phid) {
        $tbl = 'staffs';
        
        $str = "<select name='phid'><option value=''></option>";
        $rs = mysql_query("select * from $tbl order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' selected';
                $str .= ">$o->ph_name</option>";
        }
        $str .= '</select>';

        return $str;
}

function staffmulti_list($phid) {
        $tbl = 'staffs';

        $str = "<select name='phid[]' size='7' multiple><option value=''></option>";
        $rs = mysql_query("select * from $tbl order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' selected';
                $str .= ">$o->ph_name</option>";
        }
        $str .= '</select>';

        return $str;
}

function staffcheck_list($phid) {
        $tbl = 'staffs';

        $rs = mysql_query("select * from $tbl order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<input type='checkbox' name='phid[]' value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' checked';
                $str .= ">$o->ph_name";
        }

        return $str;
}

function staff_detail($phid) {
        $tbl = 'staffs';

        //$str = "<div>";
        $rs = mysql_query("select * from $tbl where ph_id='$phid'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->ph_name ($o->specialization)";
        }
        //$str .= "</div>";

        return $str;
}

function medicine_list($medid,$plusminus) {
        $tbl = 'medicines';

        $str = "<select name='medid'>";
        if ($plusminus == '+')
		$rs = mysql_query("select * from $tbl order by med_name");
        else { 
		//$rs = mysql_query("select med_id,med_name from $tbl where qty_inhand>qty_critical order by med_name");
		$rs = mysql_query("select * from $tbl where qty_inhand>0 order by med_name");
	}
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option style='color:".($o->qty_inhand <= $o->qty_critical ? 'red' : '')."' value='$o->med_id'";
                if ($medid == $o->med_id) $str .= ' selected';
                $str .= ">$o->med_name ($o->qty_inhand/$o->qty_critical/$o->qty_used)</option>";
        }
        $str .= '</select>';

        return $str;
}

function medicine_detail($medid) {
        $tbl = 'medicines';

        $str = "<div>";
        $rs = mysql_query("select med_name from $tbl where med_id=$medid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->med_name";
        }
	$str .= "</div>";

        return $str;
}

function material_list($medid,$plusminus) {
        $tbl = 'materials';

        $str = "<select name='medid'>";
        if ($plusminus == '+')
                $rs = mysql_query("select * from $tbl order by med_name");
        else {
                //$rs = mysql_query("select med_id,med_name from $tbl where qty_inhand>qty_critical order by med_name");
                $rs = mysql_query("select * from $tbl where qty_inhand>0 order by med_name");
        }
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option style='color:".($o->qty_inhand <= $o->qty_critical ? 'red' : '')."' value='$o->med_id'";
                if ($medid == $o->med_id) $str .= ' selected';
                $str .= ">$o->med_name ($o->qty_inhand/$o->qty_critical/$o->qty_used)</option>";
        }
        $str .= '</select>';

        return $str;
}

function material_detail($medid) {
        $tbl = 'materials';

        $str = "<div>";
        $rs = mysql_query("select med_name from $tbl where med_id=$medid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->med_name";
        }
        $str .= "</div>";

        return $str;
}


function registration_detail($regno) {
        $rs = mysql_query("select * from registrations where reg_no=$regno");
        while ($o = mysql_fetch_object($rs)) {
                $str = "<table border='1' width='80%'>
                <tr><th>RegNo</th><th>Registration Date</th><th>Patient Detail</th><th>Doctor Detail</th></tr>
                <tr><td align='center'>$regno</td><td align='center'>$o->reg_date $o->reg_time</td>
                <td>".patient_detail($o->pat_id)."</td>
                <td align='center'>".doctor_detail($o->dr_id)."</td>
                </tr></table><br>";
        }

	return $str;
}

//multiple registrations
function list_registrations($patid) {
        $str = "[ $patid]".patient_detail($patid);
	$rs = mysql_query("select * from registrations where pat_id='$patid' order by reg_no desc");
        while ($o = mysql_fetch_object($rs)) {
		$i++;
		$str .= "$i) ".($o->dependent ? "Dependent: ".strtoupper($o->dependent) : "Self");
                $str .= "<table border='1' width='95%'>
                <tr><th>RegNo</th><th>Registration Date</th><th>Doctor</th><th>Staff</th></tr>
                <tr><td align='center'>$o->reg_no</td><td align='center'> $o->reg_date $o->reg_time</td>
                <td align='center'>".doctor_detail($o->dr_id)."</td>
		<td align='center'>".staff_detail($o->login_id)."</td>
                </tr></table><br>";
        }

        return $str;
}

?>