Your IP : 216.73.216.40


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

<?php
class iStore {
	
	var $id;
	var $code;
	var $category;
	var $subcategory;
	var $description;
	var $dateCreation;
	var $dateUpdation;
	var $status;
	var $loginID;
	
	public function __construct() {

		if (!$this->dateCreation) $this->dateCreation = date('Y-m-d');
		if (!$this->dateUpdation) $this->dateUpdation =  date('Y-m-d', strtotime("+15 days"));
		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');
	}
	
	//**********************item functions********************//
	function saveItem() {
		$tbl = 'st_items';
		//if ($this->photograph) $this->photoFile = uploadfile("photofiles");
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where id=$this->id"))) {
			mysql_query("update $tbl set code='$this->code',description='$this->description',
			subcategory=$this->subcategory,category=$this->category,status='$this->status',loginID='$this->loginID' 
			where id=$id");
		} else {
                	mysql_query("insert into $tbl(code,description,subcategory,category,status,loginID) 
			values('$this->code','$this->description',$this->subcategory,$this->category,'$this->status','$this->loginID')");
		}
	}

	function daleteItem($confirm = 0, $pg = 'home') {
		$tbl = 'st_items';
		if ($confirm) {
			mysql_query("delete from $tbl where id=$this->id");
			$mm = "Successful deletion";
		} else {
			$mm = "Are you sure? [ <a href='?pg=$pg&delete=1&id=$this->id'>Yes</a> | <a href='?pg=$pg&rowID=$id'>No</a> ]";
		}
		$this->id = 0;
		return $mm;

	}

	
	function getItem() {
		$tbl = 'st_items';
		$rs = mysql_query("select * from $tbl where id=$this->id");
		while ($o = mysql_fetch_object($rs)) {
			$this->code = $o->code;
			$this->description = $o->description;
			$this->category = $o->category;
			$this->subcategory = $o->subcategory;
		}
	}

	function listItems($status = 'Online', $pg = 'home') {
		
		$mm = "<ol>";
		$rs = mysql_query("select id,code from st_category where status='$status' order by code");
		while ($o = mysql_fetch_object($rs)) {
			$mm .= "<li>";
			if ($this->category == $o->id) {
				$mm .= "<font size=+1>$o->code</font>
				<ol>"; 
				$sr = mysql_query("select id,code from st_subcategory where category=$o->id and status='$status' order by code");
				while ($q = mysql_fetch_object($sr)) {
					$mm .= "<li>";
					if ($this->subcategory == $q->id) {
						$mm .= "<font size=+1>$q->code</font>
						<ol>";
						$rr = mysql_query("select * from st_items where category=$o->id and subcategory=$q->id and status='$status' order by category,subcategory,code");
						while ($r = mysql_fetch_object($rr)) {
							$mm .= "<li>";
							if ($this->id == $r->id) {
								$mm .= "<font size=+1>$r->code</font>";
							} else {
								$mm .= "<a href='?pg=$pg&category=$o->id&subcategory=$q->id&id=$r->id'>$r->code</a>";
							}
							$mm .= "</li>";
						} 
						$mm .= "</ol>";
					} else {
						$mm .= "<a href='?pg=$pg&category=$o->id&subcategory=$q->id'>$q->code</a>";
					}
					$mm .= "</li>";
				} 
				$mm .= "</ol>";
			} else {
				$mm .= "<a href='?pg=$pg&category=$o->id'>$o->code</a>"; 
			}
			$mm .= "</li>";
		}
		$mm .= "</ol>";
		
		return $mm;
	}

	function saveAttachment($fileName = '',$objectName = '') {
		if ($fileName) upload();
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from st_attachments where id=$this->id"))) {
			mysql_query("update st_attachments set objectID=$this->objectID,objectName='$objectName',
			description='$this->description',".($this->fileName ? "fileName='$this->fileName'," : '')."
			loginID='$this->loginID' where id=$this->id");
		} else {
			mysql_query("insert into st_attachments(objectID,objectName,description,fileName,loginID)
			values($this->objectID,'$this->objectName','$this->description','$this->fileName','$this->loginID')");
		}
	}

	function selectCategory($pg = 'home') {
		//$mm = "<select name='category' onchange=\"javascript: document.location.href='?pg=$pg&category='+this.value\">
		$mm = "<select name='category'>
		<option value=''></option>";

		$rs = mysql_query("select id,code from st_category order by code");
		while ($o = mysql_fetch_object($rs)) {
        		$mm .= "<option value='$o->id'";
        		if ($o->id == $this->category) $mm .= " selected";
        		$mm .= ">$o->code</option>";
		}
		$mm .= "</select>";

		return $mm;
	}

	function selectSubcategory($pg = 'home') { 
		//$mm = "subcategory <select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&category=$this->category&subcategory='+this.value\">
		$mm = "<select name='subcategory'>
		<option value=''></option>";

		$rs = mysql_query("select id,code,item_type from st_subcategory where category=$this->category order by code");
		while ($o = mysql_fetch_object($rs)) {
        		$mm .= "<option value='$o->id'";
        		if ($o->id == $this->subcategory) $mm .= " selected";
        		$mm .= ">$o->code ($o->item_type)</option>";
		}
		$mm .= "</select>";

		return $mm;
	}

	function relatedLinks() {
		$mm = "[ <i class='fa fa-car' aria-hidden='true'></i><a href='?pg=stitems'>Item</a> ]
		[ <i class='fa fa-user-circle-o' aria-hidden='true'></i> <a href='?pg=stcategory'>Category</a> ]
		[ <i class='fa fa-random' aria-hidden='true'></i> <a href='?pg=stsubcategory'>Subcategory</a> ]";
		
		return $mm;
	}


}
?>