Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/istore/
Upload File :
Current File : /var/www/html/mmishra/istore/class.tender.php

<?php

class iTender {
	var $con;
	var $tbl;

	var $id;
	var $tenderNo;
	var $dateTender;
	var $dateSubmission;
	var $timeSubmission;
	var $dateOpening;
	var $timeOpening;
	var $classification;
	var $objective;
	var $title;
	var $tenderFee;
	var $estCost;
	var $emdAmount;
	var $userDept;
	var $userEmail;
	var $tenderFile;
	var $dateCancellation;
	var $cancellation;
	var $dateClosing;
	var $quotations;
	var $l1Quote;
	var $dateOrder;
	var $status;

        var $description;
        var $dateExtension;
        var $extensionFile;
	
        var $dateCorrigendum;
        var $corrigendumFile;
	
	var $dateQuotation;
	var $firmName;
	var $suplimentry;
	var $bidCost;
	var $ranking;
	var $quotationFile;
	
	public function __construct() {
		$this->tbl = 't_tenders';

		if (!$this->dateTender) $this->dateTender = date('Y-m-d');
		if (!$this->dateSubmission) $this->dateSubmission =  date('Y-m-d', strtotime("+15 days"));
		if (!$this->timeSubmission || $this->timeSubmission = '00:00:00') $this->timeSubmission =  '15:30:00';
		if (!$this->dateOpening) $this->dateOpening =  date('Y-m-d', strtotime("+15 days"));
		if (!$this->timeOpening || $this->timeOpening = '00:00:00') $this->timeOpening =  '15:30:00';
		if (!$this->dateCancellation) $this->dateCancellation =  date('Y-m-d');
		if (!$this->dateClosing) $this->dateClosing =  date('Y-m-d');
		if (!$this->dateOrder) $this->dateOrder =  date('Y-m-d');
		if (!$this->dateExtension) $this->dateExtension = date('Y-m-d');
		if (!$this->dateCorrigendum) $this->dateCorrigendum = date('Y-m-d');
		if (!$this->dateQuotation) $this->dateQuotation = date('Y-m-d');
		if (!$this->status) $this->status = 'Online';

        	$this->con = mysql_connect('localhost', 'root', 'irp2015');
        	if (!$this->con) die('Could not connect: ' . mysql_error());
		mysql_select_db('istore');
	}
	
	function saveTender() {
		if ($this->tenderFile) $this->tenderFile = uploadfile("tenderfiles");
		if (mysql_num_rows(mysql_query("select * from $this->tbl where id=$this->id"))) {
			//update existing tender
			mysql_query("update $this->tbl set tender_no='$this->tenderNo',date_tender='$this->dateTender',classification='$this->classification',
			objective='$this->objective',date_opening='$this->dateOpening',title='$this->title',tender_fee=$this->tenderFee,est_cost=$this->estCost,
			emd_amount=$this->emdAmount,user_dept='$this->userDept',user_email='$this->userEmail',date_submission='$this->dateSubmission',
			time_submission='$this->timeSubmission',date_opening='$this->dateOpening',time_opening='$this->timeOpening',dated=now()
			".($this->tenderFile ? ",tender_file='$this->tenderFile'" : '')." where id=$this->id");
		} else {
			//insert new tender
			mysql_query("insert into $this->tbl(tender_no,date_tender,classification,objective,title,est_cost,emd_amount,user_dept,user_email,
			tender_fee,date_submission,time_submission,date_opening,time_opening,tender_file,status,dated)
			values('$this->tenderNo','$this->dateTender','$this->classification','$this->objective','$this->title',$this->estCost,$this->emdAmount,
			'$this->userDept','$this->userEmail',$this->tenderFee,'$this->dateSubmission','$this->timeSubmission','$this->dateOpening','$this->timeOpening',
			'$this->tenderFile','Online',now())");
		}
	}

	function deleteTender() {
		mysql_query("delete from $this->tbl where id=$this->id");
		$$this->id = 0;
	}

	function cancelTender() {
		mysql_query("update $this->tbl set date_cancellation='$this->dateCancellation',cancellation='$this->cancellation',status='Cancelled' where id=$this->id");
	} 

	function reviveTender() {
		mysql_query("update $this->tbl set date_cancellation='',cancellation='Revived on ".date("Y/m/d")."',status='Online' where id=$this->id");
	}

	function closeTender() {
		mysql_query("update $this->tbl set date_closing='$this->dateClosing',quotations=$this->quotations,l1_quote='$this->l1Quote',status='Closed' where id=$this->id");
	}
	
	function mailTender() {
		$rs = mysql_query("select * from st_config");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
	        	$autoMailing = $o->auto_mailing;
	        	$tenderNotice = $o->tender_notice;
        		$tenderEmails = explode(",",$o->tender_emails);
	        	$uploadNotice = $o->upload_notice;
        		$uploadEmails = explode(",",$o->upload_emails);
		
       			if ($autoMailing) {
				$str = "<table width='100%' border='1' style='border-collapse:collapse'>
				<tr><th>Tender No.</th><th>Description</th><th>Dated</th><th>User Dept.</th></tr>
				<tr><td>$this->tenderNo</td><td>$this->title</td><td>$this->dateTender</td><td>$this->userDept</td></tr>
				</table>";
				foreach ($tenderEmails as $email) {
					automailer($email, "Tender Notification", $tenderNotice.$str, '/var/www/html/istore/'.$this->tenderFile);
				}
				foreach ($uploadEmails as $email) {
        				automailer($email, "Tender Notification", $uploadNotice.$str, '/var/www/html/istore/'.$this->tenderFile);
				}
			}
		}
        	automailer($this->userEmail, "Tender Notification", $uploadNotice.$str, '/var/www/html/istore/'.$this->tenderFile);
	}

	function getTender() {
		$rs = mysql_query("select * from $this->tbl where id=$this->id");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
		        $this->id = $o->id;
		        $this->tenderNo = $o->tender_no;
		        $this->dateTender = $o->date_tender;
		        if($this->dateTender == '0000-00-00') $this->dateTender = date('Y-m-d');
		        $this->dateSubmission = $o->date_submission;
		        if($this->dateSubmission == '0000-00-00') $this->dateSubmission = date('Y-m-d', strtotime("+15 days"));
		        $this->timeSubmission = $o->time_submission;
			if ($this->timeSubmission == '00:00:00') $this->timeSubmission =  '12:30:00';
		        $this->dateOpening = $o->date_opening;
		        if($this->dateOpening == '0000-00-00') $this->dateOpening = date('Y-m-d', strtotime("+15 days"));
		        $this->timeOpening = $o->time_opening;
			if ($this->timeOpening == '00:00:00') $this->timeOpening = '15:30:00';
		        $this->classification = $o->classification;
		        $this->objective = $o->objective;
		        $this->title = $o->title;
		        $this->tenderFee = $o->tender_fee;
		        $this->estCost = $o->est_cost;
		        $this->emdAmount = $o->emd_amount;
		        $this->userDept = $o->user_dept;
		        $this->userEmail = $o->user_email;
		        $this->tenderFile = $o->tender_file;
		        $this->dateCancellation = $o->date_cancellation;
		        if($this->dateCancellation == '0000-00-00') $this->dateCancellation = date('Y-m-d');
		        $this->cancellation = $o->cancellation;
        		$this->dateClosing = $o->date_closing;
		        if($this->dateClosing == '0000-00-00') $this->dateClosing = date('Y-m-d');
        		$this->quotations = $o->quotations;
        		$this->l1Quote = $o->l1_quote;
		        $this->status = $o->status;
		}
	}

	function listTenders($status, $pg = '') {
		$str = "<ol>";
		$rs = mysql_query("select * from $this->tbl where status='$status' order by date_tender desc");
		while ($o = mysql_fetch_object($rs)) {
			$str .= "<li>[ <a href='?pg=$pg&id=$o->id'>$o->tender_no</a> ] $o->title <br> 
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Duration $o->date_tender to $o->date_submission <br>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; $o->tender_file &gt;</li>";
		}
		$str .= "</ol>";
		return $str;
	}

        function listCancellations($pg = '') {
                $str = "<ol>";
                $rs = mysql_query("select * from $this->tbl where status='Cancelled' order by date_tender desc");
		if (mysql_num_rows($rs)) {
                	while ($o = mysql_fetch_object($rs)) {
                        	$str .= "<li>[ <a href='?pg=$pg&id=$o->id'>$o->tender_no</a> ] $o->title <br>
                        	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dated $o->date_tender, Cancelled on $o->date_cancellation <br>
                        	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; $o->tender_file &gt;</li>";
                	}
                } else {
			$str .= "<li>None.</li>";
		}
		$str .= "</ol>";
                return $str;
        }

	
	function selectTender($id, $pg) {
		$str = "<select name='tender_no' onchange=\"javascript: document.location.href='?pg=$pg&id='+this.value\"><option value=''></option>";

		$rs = mysql_query("select * from t_tenders order by status desc");
		while ($o = mysql_fetch_object($rs)) {
        		$str .= "<option value='$o->id'".($id == $o->id ? ' selected' : '').">$o->tender_no</option>";
		}
		$str .= "</select>";
		return $str;
	}
	
	function countExtensions() {
		$rs = mysql_query("select count(tender_no) as no from t_extensions where tender_no=$this->id");
		if (mysql_num_rows($rs)) {
        		$o = mysql_fetch_object($rs);
        		return $o->no;
		}
	}
	
	function countCorrigendums() {
		$rs = mysql_query("select count(tender_no) as no from t_corrigendums where tender_no=$this->id");
		if (mysql_num_rows($rs)) {
        		$o = mysql_fetch_object($rs);
        		return $o->no;
		}
	}

	function tasksTender() {
		if ($this->id) {
			$str = "[ <a href='?pg=tcorrigendum&tender_no=$this->id'>Corrigendum</a> (".$this->countCorrigendums().") ]
			[ <a href='?pg=textension&tender_no=$this->id'>Extension</a> (".$this->countExtensions().") ]
			[ <a href='?pg=tcancellation&id=$this->id'>Cancellation</a> ]
			[ <a href='?pg=topening&id=$this->id'>Opening</a> ]
			[ <a href='?pg=tquotation&tender_no=$this->id'>Quotation</a> ]
			[ <a href='?pg=tClosing&id=$this->id'>Closing</a> ]";
		} else {
			$str = "[ Corrigendum ] [ Extension ][ Cancellation ][ Opening ][ Quotation ][ Closing ]";
		}
		return $str;
	}

	function docsTender() {
		$str = "[ <a href='tformats.php?pg=openingnote&tno=$this->id'>Opening Note</a> ]
		[ <a href='tformats.php?pg=summarynote&tno=$this->id'>Summary Note</a> ]
		[ <a href='tformats.php?pg=extensionnote&tno=$this->id'>Extension Note</a> ]
		[ <a href='tformats.php?pg=extensionorder&tno=$this->id'>Extension Order</a> ]";
		return $str;
	}

	function remindMeeting() {
		$rs = mysql_query("select * from st_config");
		if (mysql_num_rows($rs)) {
		        $o = mysql_fetch_object($rs);
		        $autoMailing = $o->auto_mailing;
		        $tenderNotice = $o->tender_notice;
		        $tenderEmails = explode(",",$o->tender_emails);
		        $uploadNotice = $o->upload_notice;
		        $uploadEmails = explode(",",$o->upload_emails);
		        $meetingNotice = $o->meeting_notice;
		        $meetingEmails = explode(",",$o->meeting_emails);
		}

		$sql = "select tender_no,concat(description,' (',objective,')') as title,est_cost,user_dept,date_tender as dated,
		date_submission as submission,date_opening as opening,quotations,l1_quote,date_final as finalization from t_tenders 
		where date_opening='".date("Y-m-d")."' order by id desc";

		$sql = "select tender_no,concat(description,' (',objective,')') as title,est_cost,user_dept,date_tender as dated,
		date_submission as submission,date_opening as opening,quotations,l1_quote,date_final as finalization from t_tenders order by id desc";

		$str = $this->listTenders($pg);

		if ($str && $autoMailing) {
        		foreach ($meetingEmails as $email) {
                		automailer($email, "Tender Processing - Regarding meeting", $meetingNotice.$str);
        		}
		}
	}	

        function showTender() {
                $str = 'Tender record not available.';
                $rs = mysql_query("select * from $this->tbl where id=$this->id");
                if (!mysql_num_rows($rs)) $rs = mysql_query("select * from $this->tbl where id=$this->tenderNo");
                if (mysql_num_rows($rs)) {
                        $o = mysql_fetch_object($rs);
                        $str = "<table width='100%' border='1' style='border-collapse: collapse'>
                        <tr><td width='15%'>Tender No.</td><td width='85%'>$o->tender_no <b>[ $o->status ]</b></td></tr>
                        <tr><td>Classification</td><td>$o->classification, Objective: $o->objective</td></tr>
                        <tr><td>Tender Period</td><td>$o->date_tender To $o->date_submission till $o->time_submission</td></tr>
                        <tr><td>Opening Date</td><td>$o->date_opening at $o->time_opening</td></tr>
                        <tr><td>Tender Title</td><td>$o->title</td></tr>
                        <tr><td>Tender Fee</td><td>$o->tender_fee in INR</td></tr>
                        <tr><td>Estimated Cost</td><td>$o->est_cost in INR</td></tr>
                        <tr><td>Emd Amount</td><td>$o->emd_amount in INR</td></tr>
                        <tr><td>User Dept.</td><td>$o->user_dept</td></tr>
                        <tr><td>User Email</td><td>$o->user_email</td></tr>
                        <tr><td>Tender File</td><td><a href='$o->tender_file'>$o->tender_file</a></td></tr>
                        </table>";
                }
                return $str;
        }


	//extension related
	function saveExtension() {
		if ($this->extensionFile) $extensionFile = uploadfile("tenderfiles");
		if (mysql_num_rows(mysql_query("select * from t_extensions where id=$this->id"))) {
			//update existing tender
			mysql_query("update t_extensions set date_extension='$this->dateExtension',date_submission='$this->dateSubmission',time_submission='$this->timeSubmission',
			date_opening='$this->dateOpening',time_opening='$this->timeOpening',description='$this->description',dated=now() 
			".($this->extensionFile ? ", extension_file='$this->extensionFile'" : '')." where id=$this->id");
		} else {
			//insert new tender
			mysql_query("insert into t_extensions(tender_no,date_extension,date_submission,time_submission,date_opening,time_opening,description,extension_file,dated)
			values($this->tenderno,'$this->dateExtension','$this->dateSubmission','$this->timeOpening','$this->dateOpnening',
			'$this->timeOpening','$this->description','$this->extensionFile',now())");
		}

	}

	function deleteExtension() {
		mysql_query("delete from t_extensions where id=$this->id");
		$this->id = 0;
	}

	function mailExtension() {
		$rs = mysql_query("select * from st_config");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
	        	$autoMailing = $o->auto_mailing;
	        	$tenderNotice = $o->tender_notice;
        		$tenderEmails = explode(",",$o->tender_emails);
	        	$uploadNotice = $o->upload_notice;
        		$uploadEmails = explode(",",$o->upload_emails);
		
       			if ($autoMailing) {
				$str = "<table width='100%' border='1' style='border-collapse:collapse'>
				<tr><th>Tender No.</th><th>Description</th><th>Submission</th><th>Opening</th></tr>
				<tr><td>$this->tenderNo</td><td>$this->description</td><td>$this->dateSubmission ($this->timeSubmission)</td><td>$this->dateOpening ($this->timeOpening)</td></tr>
				</table>";
				foreach ($tenderEmails as $email) {
					automailer($email, "Corrigendum Notification", $tenderNotice.$str, '/var/www/html/istore/'.$this->extensionFile);
				}
				foreach ($uploadEmails as $email) {
					automailer($email, "Corrigendum Notification", $uploadNotice.$str, '/var/www/html/istore/'.$this->extensionFile);
				}
			}
		}
	}

	function getExtension() {
		$rs = mysql_query("select * from t_extensions where id=$this->id");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
		        $this->tenderNo = $o->tender_no;
		        $this->description = $o->description;
		        $this->dateExtension = $o->date_extension;
		        $this->dateSubmission = $o->date_submission;
		        $this->timeSubmission = $o->time_submission;
			if ($this->timeSubmission == '00:00:00') $this->timeSubmission =  "12:30:00";
		        $this->dateOpening = $o->date_opening;
		        $this->timeOpening = $o->time_opening;
			if ($this->timeOpening == '00:00:00') $this->timeOpening =  "12:30:00";
		        $this->extensionFile = $o->extension_file;
		}
	}

	function listExtensions($pg = '') {
		$str = "<ol>";
		$rs = mysql_query("select e.*,t.tender_no as tno from t_extensions e, $this->tbl t where e.tender_no=t.id and t.status='Online' order by e.date_extension desc");
		if (mysql_num_rows($rs)) {
			while ($o = mysql_fetch_object($rs)) {
				$str .= "<li>[ <a href='?pg=$pg&id=$o->id'>$o->tno</a> ] $o->description<br> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Period $o->date_extension to $o->date_submission<br>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; $o->extension_file &gt;</li>";
			}
		} else {
			$str .= "<li>None</li>";
		}
		$str .= "</ol>";
		return $str;
	}
	
	//corrigendum related
	function saveCorrigendum() {
		if ($this->corrigendumFile) $this->corrigendumFile = uploadfile("tenderfiles");
		if (mysql_num_rows(mysql_query("select * from t_corrigendums where id=$this->id"))) {
			//update existing tender
			mysql_query("update t_corrigendums set date_corrigendum='$this->dateCorrigendum',description='$this->description',dated=now()
			".($this-corrigendumFile ? ",corrigendum_file='$this->corrigendumFile'" : '')." where id=$this->id");
		} else {
			//insert new tender
			mysql_query("insert into t_corrigendums(tender_no,date_corrigendum,description,corrigendum_file,dated)
			values($this->tenderNo,'$this->dateCorrigendum','$this->description','$this->corrigendumFile',now())");
		}	
	}

	function deleteCorrigendum() {
		mysql_query("delete from t_corrigendums where id=$this->id");
		$this->id = 0;
	}

	function mailCorrigendum() {
		$rs = mysql_query("select * from st_config");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
	        	$autoMailing = $o->auto_mailing;
	        	$tenderNotice = $o->tender_notice;
        		$tenderEmails = explode(",",$o->tender_emails);
	        	$uploadNotice = $o->upload_notice;
        		$uploadEmails = explode(",",$o->upload_emails);
		
       			if ($autoMailing) {
				$str = "<table width='100%' border='1' style='border-collapse:collapse'>
				<tr><th>Tender No.</th><th>Description</th><th>Dated</th></tr>
				<tr><td>$this->tenderNo</td><td>$this->description</td><td>$this->dateCorrigendum</td></tr>
				</table>";
				foreach ($tenderEmails as $email) {
					automailer($email, "Corrigendum Notification", $tenderNotice.$str, '/var/www/html/istore/'.$this->corrigendumFile);
				}
				foreach ($uploadEmails as $email) {
					automailer($email, "Corrigendum Notification", $uploadNotice.$str, '/var/www/html/istore/'.$this->corrigendumFile);
				}
			}
		}
	}

	function getCorrigendum() {
		$rs = mysql_query("select * from t_corrigendums where id=$this->id");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
		        $this->id = $o->id;
		        $this->tenderNo = $o->tender_no;
		        $this->dateCorrigendum = $o->date_corrigendum;
		        $this->description = $o->description;
		        $this->corrigendumFile = $o->corrigendum_file;
		}
	}

	function listCorrigendums($pg = '') {
		$str = "<ol>";
		$rs = mysql_query("select c.*,t.tender_no as tno from t_corrigendums c, $this->tbl t where c.tender_no=t.id and t.status='Online' order by c.date_corrigendum desc");
		if (mysql_num_rows($rs)) {
			while ($o = mysql_fetch_object($rs)) {
				$str .= "<li>[ <a href='?pg=$pg&id=$o->id'>$o->tno</a> ] $o->description<br> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dated $o->date_corrigendum<br>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; $o->corrigendum_file &gt;</li>";
			}
		} else {
			$str .= "<li>None</li>";
		}
		$str .= "</ol>";
		return $str;
	}


	//quotations
	function saveQuotation() {
		if ($quotationfile) $this->quotationFile = uploadfile("quotationfiles");
		
		if (mysql_num_rows(mysql_query("select * from t_quotations where id=$id"))) {
			//update existing tender
			mysql_query("update t_quotations set tender_no='$this->tenderNo',date_quotation='$this->dateQuotation',firm_name='$this->firmName',bid_cost=$this->bidCost,
			suplimentry='$this->suplimentry',status='$this->status',ranking=$this->ranking,".($this->quotationFile ? "quotation_file='$this->quotationFile'," : '')."dated=now()
			where id=$this->id");
		} else {
			//insert new tender
			mysql_query("insert into t_quotations(tender_no,date_quotation,firm_name,bid_cost,quotation_file,suplimentry,status,ranking,dated)
			values('$this->tenderNo','$this->dateQuotation','$this->firmName',$this->bidCost,'$this->quotationFile','$this->suplimentry','$this->status',$this->ranking,now())");
		}
	} 

	function deleteQuotation() {
		mysql_query("delete from t_quotations where id=$this->id");
		$this->id = 0;
	}

	function getQuotation() {
		$rs = mysql_query("select * from t_quotations where id=$id");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
        		$this->id = $o->id;
        		$this->tenderNo = $o->tender_no;
        		$this->dateQuotation = $o->date_quotation;
        		$this->firmName = $o->firm_name;
        		$this->bidCost = $o->bid_cost;
        		$this->suplimentry = $o->suplimentry;
        		$this->quotationFile = $o->quotation_file;
        		$this->status = $o->status;
        		$this->ranking = $o->ranking;
		}
	}

	function listQuotations($pg) {
		$str = '<ol>';
		$rs = mysql_query("select * from t_quotations where tender_no=$this->tenderNo order by date_quotation desc");
		while ($o = mysql_fetch_object($rs)) {
			$str .= "<li>[ <a href='?pg=$pg&id=$o->id'>$o->tender_no".'-'."$o->id</a> ] $o->firm_name <br> 
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Duration $o->date_quotation to $o->status <br>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; $o->quotation_file &gt;</li>";
		}
		$str .= '</ol>';
		return $str;
	}
}

?>