| Current Path : /var/www/html/mmishra/indem/pks-ec/medical/ |
| Current File : /var/www/html/mmishra/indem/pks-ec/medical/functions.inc |
<?php
function dbConnect() {
$link = mysql_connect("localhost", "root", "iagtku!!");
mysql_select_db("examcell");
return $link;
}
function sendmail($email, $subject, $body) {
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.iiita.ac.in"; // SMTP server
$mail->FromName = "ADA Allahabad";
$mail->From = "indem@iiita.ac.in";
$mail->AddAddress($email,$email);
$mail->AddAddress("indem@iiita.ac.in","indem@iiita.ac.in");
$mail->Username = "indem";
$mail->Password = "iiita";
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 50;
if(!$mail->Send()){
echo "Message could not be sent\n Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent successfully.";
}
}
function logAccess($user, $referer, $url) {
if (!$user) $user = 'guest';
if (!$referer) $referer = 'direct';
if ($url == '/') $url = 'index.php';
$ip = $_SERVER["REMOTE_ADDR"];
mysql_query("insert into log values(NULL, '$user', '$referer', '$url','$ip',now())");
}
function setup($key) {
$rs1 = mysql_query("select setup_value from setup where setup_key='$key'");
if ($rs1) {
$o = mysql_fetch_object($rs1);
return $o->setup_value;
} else {
return "Ooops! missing";
}
}
function checkadmin($role) {
if ($role != "admin") {
echo "<div align=center>You must be a Site Administrator to access this page</div>";
exit;
}
}
function checklogin($user) {
if (!$user) {
echo "<div align=center>You must be logged in to access this page</div>";
exit;
}
}
function banner($fname) {
generate_file("banner.inc", "<img src='images/$fname' width='971' height='114'></img>");
}
function hitcounter($pg) {
$file = "counter.inc";
if (!file_exists($file)) {
touch ($file);
$count = 0;
} else {
include "counter.inc";
if ($pg == 'home') $count++;
$handle = fopen ($file, 'r+');
fwrite ($handle, '<?php $count = '.$count.'; ?>');
fclose($handle);
}
echo "Hits: $count";
}
function hitmeter($url) {
if (mysql_num_rows(mysql_query("select * from hitmeter where url='$url'"))) {
mysql_query("update hitmeter set counter=counter+1 where url='$url'");
} else {
mysql_query("insert into hitmeter(url,counter,dated) values('$url',1,now())");
}
if (mysql_num_rows(mysql_query("select * from webpages where id='$url'"))) {
mysql_query("update webpages set counter=counter+1 where id='$url'");
}
}
function album() {
$fp = fopen ("gallery.inc", "r");
if (!$fp) {
$images = array("indira-bhawan1.jpg");
} else {
$i = 0;
$images = array();
while (!feof ($fp)) {
$line = fgets ($fp, 1024);
//$images = explode(",", $line);
if ($line != "\n") $images[$i] = str_replace("\n", "", $line);
$i++;
}
}
fclose($fp);
$i--;
srand((double)microtime()*1000000);
$no = rand(0, $i);
$fname = $images[$no];
echo "<img src='images/$fname' width='420' height='240'></img>";
}
function search_site() {
if (!$conf) $conf = 'search';
$q = htmlsafe($_REQUEST["q"]);
echo "Search for text<br><input type='text' class='searchtext' name='q' size='10' value='$q'
onenter=\"document.location.href='inner.php?conf=search&q='+this.value\">
<script>
frmStatic.q.focus();
</script>";
}
function showdate() {
echo "<font color='orange' size=+1>( </font>
<font color='#000000'>" . date("l, jS F Y") . "</font>
<font color='#ADFF2F' size=+1> )</font>
";
}
function menu() {
$col1 = 'white';//'#FFEBCD';
$col2 = '#FFEBCD';
$str = "<table width='160' border='0' cellpadding='0' cellspacing='0'>";
$rs1 = mysql_query("select * from menus where referer=0 order by zindex");
while ($o = mysql_fetch_object($rs1)) {
$no++;
$str .= "<tr><td width='175' height='20'
onmouseover=\"style.backgroundColor='$col1';show('menu{$o->id}')\"
onmouseout=\"style.background='url(images/transparent.gif)';hide('menu{$o->id}')\">";
if ($o->href == 'submenu') $str .= "<a href='/'>";
else $str .= "<a href='$o->href'>";
$str .= "$o->title</a><br/>";
$rs2 = mysql_query("select * from menus where referer>0 and referer={$o->id} order by zindex");
if (mysql_num_rows($rs2)) {
$str .= "<table bgcolor='$col2' width='200' class='menu' id='menu{$o->id}'>";
while ($p = mysql_fetch_object($rs2)) {
$str .= "<tr><td height='20' class='menu'
onmouseover=\"style.backgroundColor='$col1';\"
onmouseout=\"style.backgroundColor='$col2'\">";
if (strpos($p->href,".")) $str .= "<a href='$p->href'>";
else $str .= "<a href='inner.php?conf=$p->href'>";
$str .= "$p->title</a></td></tr>";
}
$str .= "</table>";
}
$str .= "</td></tr>";
}
$str .= "</table>";
generate_file("menus.inc", $str);
fixed_links();
}
function site_intro(){
$rs1 = mysql_query("select title,content from webpages where id='site_intro'");
if ($rs1) {
$o = mysql_fetch_object($rs1);
$str = "<b>$o->title</b><br>$o->content<br>";
} else {
$str = "Welcome...<br><br>Nothing to show here.
Please visit control panel to create this section";
}
generate_file("site_intro.inc", $str);
}
function login(){
?>
<br>
<table width=100px class="login_box" border=0 cellpadding=0 cellspacing=2>
<tr><td></td><td height=20 align=right>
<input type="button" class="btn_close" value="X" onclick="hide_login();">
<input type=hidden name=login>
<!--helps inner.php know that we are trying to logon, so that it can create a session-->
<input type=hidden name=target value='<?=$target?>'>
</td></tr>
<tr><td><b>Username</b></td><td height=15>
<input class='text' type='text' name='txtID'>
</td></tr>
<tr><td height=15><b>Password</b></td><td>
<input class='text' type='password' name='txtPWD'>
</td></tr>
<tr><td height=30>
<input type='submit' class='btn_login' value='Login'>
</td></tr>
</table>
<?
}
function fixed_links(){
$str = "<table border=0 cellspacing=2 cellpadding=0>
<tr><td height='15'><a href='inner.php?conf=tendercur'>Tenders</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=rtiquery'>Query & RTI</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=formformats'>Form Formats</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=gallery'>Photo Gallery</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=profiles'>Web Profiles</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=telephone'>Telephones</a></td></tr>
<tr><td height='15'><a href='inner.php?conf=feedback'>Feedback</a></td></tr>
</table>";
generate_file("fixed_links.inc", $str);
}
function footer($user, $role, $target){
if ($user){
if ($user) {
echo "<a href='inner.php?conf=cpanel' title='Goto to control panel'><b>Control Panel</b></a> | ";
}
echo "<a href='inner.php?logout=1' title='You are logged in as $user'><b>Sign Out</b></a>
[ $user as $role ]";
} else {
echo "<a href='inner.php?conf=login&target=$target' title='Please login for webadmin'><b>Sign In</b></a>";
}
echo "<br>Webmaster: " . setup('webmaster') . "<br>
<font face='Verdana' size='1'>" . setup('footer') . "</font>";
}
function logView() {
mysql_query("insert into log values(NULL, '$user', '$referer', '$page_url','$ip',now())");
}
function upload_file($id) {
$maxsize =9998860800;
$filename = strtolower(basename($_FILES['photo']['name']));
$addto_gallery = $_POST['addto_gallery'];
$filesize = $_FILES["photo"]["size"];
if ($filename && $filesize < $maxsize) {
$filename1 = explode(".", strtolower($filename));
$ext = $filename1[count($filename1)-1];
//if ($ext == 'jpg' || $ext == 'gif' || $ext == 'tif' || $ext == 'png') {
if ($ext == 'jpg' || $ext == 'gif' || $ext == 'png') {
$dir = 'photos';
if ($addto_gallery == 'yes') addto_gallery($filename);
} else
$dir = 'documents';
if (move_uploaded_file($_FILES['photo']['tmp_name'], "$dir/$id.$ext")) {
shell_exec("chmod 755 $dir/$id.$ext");
return "$dir/$id.$ext";
} else {
return "Sorry! there may be some error.";
}
} else {
return "Either file is missing or size exceeds the max. limit of 10 MB.";
}
}
function uniq_sid($uid, $pwd) {
$epwd = base64_encode($pwd);
srand((double)microtime()*100000000);
//generate a unique s_id
do {
$ch = "";
for($i=0; $i<20; $i++) $ch = $ch . chr(rand(65, 90));
// loop until a uniq string is generated
} while (!mysql_query("insert into auth values('$ch','".$_SERVER["REMOTE_ADDR"]."',now())"));
return $ch;
}
function authenticate($uid, $pwd) {
$rs = mysql_query("select * from profiles where login='$uid' and passwd=password('$pwd')");
if (mysql_num_rows($rs)) {
$o = mysql_fetch_object($rs);
if ($o->webmaster == 'Yes') return 'admin';
else return 'user';
} else {
return 'guest';
}
}
function noticefeed() {
$rs = mysql_query("SELECT * FROM notices where status='online' order by dated desc, id desc");
while ($o = mysql_fetch_object($rs)) {
$i++;
$subject = $o->subject;
$url = $o->url;
$description = $o->description;
$dated = $o->dated;
$expiry = $o->expiry;
$str .= "<table border='0' cellpadding='0' cellspacing='2'>
<tr valign='top'><td><img src='images/arrow.gif'></td>
<td onmouseover=\"show('announce$i')\" onmouseout=\"hide('announce$i')\">
<a href='$url'>$subject</a><br/>
<table class='announce' id='announce$i' border='0' cellpadding='0' cellspacing='5'>
<tr valign='top'><td align='center' class='announce'>
<font size=1pts>$description<br>(Dated: $dated)</td>
</tr></table>
</td></tr></table>";
}
$str .= "<div align='right'>[ <a href='http://www.adobe.com/products/acrobat/readstep2.html'>
Download Acrobat</a> ][ <a href='inner.php?conf=noticemore'>More...</a> ]</div>";
generate_file("notice_cur.inc", $str);
$i = 0;
$rs = mysql_query("SELECT * FROM notices where status='offline' order by dated desc");
$str = "Past notifications only.<ul>";
$rs = mysql_query("SELECT * FROM notices where status='offline' order by dated desc");
while ($o = mysql_fetch_object($rs)) {
$i++;
$str .= "<li><b>$i) $o->subject</b>
<dir>$o->description<br>";
if ($o->url) $str .= "More details: <a href='$o->url'>$o->url</a>";
$str .= "<div align='right'><i>Dated $o->dated expired on $o->expiry</i></div>
</dir></li>";
}
$str .= "</ul>";
generate_file("notice_exp.inc", $str);
}
function tenderfeed() {
$str = "Please adhere with the dates and go through the file where ever attached. Thanks.<ul>";
$rs = mysql_query("SELECT * FROM tenders where status='online' order by dated desc, id desc");
while ($o = mysql_fetch_object($rs)) {
$i++;
$str .= "<li><b>$o->subject</b><dir style='margin:0 0 0 0'>";
if ($description) {
echo $o->description."<br>";
}
if ($o->filename) $str .= "More details:
<a href='downloads.php?filename=$o->filename&tbl=tenders'>$o->filename</a>";
$str .= "<div align='right'><i>
Dated $o->dated Downloads $o->counter (Last-date $o->expiry)</i></div>
</dir></li>";
}
$str .= "</ul> <? tenderfeed(); ?>
<div align='right'>
<a href='http://www.adobe.com/products/acrobat/readstep2.html'>Download Acrobat</a>
| <a href='inner.php?conf=tendermore'>More...</a></div>";
generate_file("tender_cur.inc", $str);
$i = 0;
$str = "Past tenders only.<ul>";
$rs = mysql_query("SELECT * FROM tenders where status='offline' order by dated desc");
while ($o = mysql_fetch_object($rs)) {
$i++;
$str .= "<li><b>$o->subject</b><dir style='margin:0 0 0 0'>";
if ($description) {
echo $o->description."<br>";
}
if ($o->filename) $str .= "More details:
<a href='downloads.php?filename=$o->filename&tbl=tenders'>$o->filename</a>";
$str .= "<div align='right'><i>
During $o->dated - $o->expiry total downloads $o->counter</i></div>
</dir></li>";
}
$str .= "</ul> <? tenderfeed(); ?>
<div align='right'>
<a href='http://www.adobe.com/products/acrobat/readstep2.html'>Download Acrobat</a>
| <a href='inner.php?conf=tendercur'>More...</a></div>";
generate_file("tender_exp.inc", $str);
}
function formatfeed() {
$rs = mysql_query("SELECT * FROM formats where status='online' order by dated desc");
$str = "Please click on the filename to download desired form format.<ul>";
while ($o = mysql_fetch_object($rs)) {
$i++;
$str .= "<li><b>$o->description</b>
<dir style='margin:0 0 0 0'>
<a href='downloads.php?filename=$o->filename&tbl=formats' target='new'>$o->filename</a><br>";
$str .= "<div align='right' style='margin:0 0 0 0'>
<i>Dated $o->dated Downloads $o->counter</i></div>
</dir></li>";
}
$str .= "</ul> <? formatfeed(); ?>
<div align='right'>
<a href='http://www.adobe.com/products/acrobat/readstep2.html'>Download Acrobat</a>
</div>";
generate_file("formats.inc", $str);
}
function newsfeed(){
$str = '<? xml version=\"1.0\" ?> <rss version=\"2.0\"><channel>';
$rs = mysql_query("SELECT * FROM news where status='online' order by dated desc, id desc");
while ($o = mysql_fetch_object($rs)) {
$str .= "<item>
<title>$o->subject</title>
<link>$o->url</link>
<description>$o->description</description>
<pubDate>$o->dated</pubDate>
<category>Achievement</category>
</item>";
}
$str .= "</channel></rss>";
generate_file("rss.xml", $str);
}
function generate_file($file, $str) {
if (!file_exists($file)) {
touch ($file);
}
if (!$handle = fopen ($file, 'w+')) {
echo "$file file permission error";
} else if (is_writable($file)) {
if (fwrite ($handle, $str) === FALSE) {
echo "Can't write to $file";
}
}
fclose($handle);
$out = shell_exec("chmod 757 $file");
}
function addto_gallery($fname){
$str = shell_exec("cat gallery.inc") . "\n";
//if not already in gallery
if (!strpos($str, $fname)) {
$str .= $fname;
generate_file("gallery.inc", $str);
}
}
function getFileExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
function create_img($image_in,$image_out,$text,$color,$font,$font_size,$angle,$offset_x,$offset_y,$shadow_color) {
if (!$text) $text = 'mmishra@iiita.ac.in';
if (!$offset_x) $offset_x = 0; // Horizontal offset in pixels, from the right
if (!$offset_y) $offset_y = 0; // Vertical offset in pixels, from the bottom
if ($shadow_color) $drop_shadow = true;
else $shadow_color = '#909009';
#################################################################################
# END OF SETTINGS
#################################################################################
// Load functions for image watermarking
include("watermark_text.class.php");
// create class instance
$img = new Zubrag_watermark($image_in);
// shadow params
$img->setShadow($drop_shadow, $shadow_color);
// font params
$img->setFont($font, $font_size);
// Apply watermark
$img->ApplyWatermark($text, $color, $angle, $offset_x, $offset_y);
// Save on server
$img->SaveAsFile($image_out);
// release resources
$img->Free();
return;
}
function check_email($email) {
if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) {
return FALSE;
}
list($Username, $Domain) = split("@",$email);
if (getmxrr($Domain, $MXHost)) {
return TRUE;
} else {
if (fsockopen($Domain, 25, $errno, $errstr, 30)) {
return TRUE;
} else {
return FALSE;
}
}
}
?>