Location: PHPKode > projects > OpenEMR Mobile > mobile/main.php
<?php
/*
Copyright: 2010 Capraro Technologies Inc.
License: Licensed under The GPL
Website: http://www.caprarotechnologies.com
Email: hide@address.com
Author: James Scherzi
*/
?>
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: index.php");
}
?>

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/mobile/db/dbfunc.php");

$db = new EMRDbConn();
if (!$db->connect())
{
	die("ERROR: Couldn't connect to database.");
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>OpenEMR Mobile Calendar</title>

<script type="text/javascript" src="build/yahoo-dom-event/yahoo-dom-event.js"></script> 
<script type="text/javascript" src="build/calendar/calendar-min.js"></script> 
<script type="text/javascript" src="build/connection/connection_core-min.js"></script> 
<script type="text/javascript" src="build/datasource/datasource-min.js"></script> 
<script type="text/javascript" src="build/element/element-min.js"></script> 
<script type="text/javascript" src="build/datatable/datatable-min.js"></script> 

<script type="text/javascript" src="ymod-tableExtension-2.3.0.js"></script>
<script type="text/javascript" src="date.js"></script>

<link rel="stylesheet" type="text/css" href="css/datatable.css" />
<link rel="stylesheet" type="text/css" href="css/calendar.css" />
<link rel="stylesheet" type="text/css" href="css/mobile.css" />

<style type="text/css" media="all">

<?php
//start create CSS for the correct appointment colors from OpenEMR Admin->Calendar->Category
$qs = "SELECT pc_catname, pc_catcolor FROM openemr_postcalendar_categories";
$qy = $db->addQuery($qs);
$rs = $qy->execute();

if (is_null($rs))
{
  die("ERROR: Couldn't execute query.");
}
$rs->move_first();

while(!$rs->eof()){	
	$output .= "\n.yui-skin-sam .yui-dt tr.";
	$tmp = str_replace(' ','',$rs->fields('pc_catname'));
	$tmp = str_replace('/','',$tmp);
	$output .= str_replace('.','',$tmp);
	$output .= " {    background-color: ".$rs->fields('pc_catcolor')."; color: #black;}";
	$rs->move_next();
}
echo $output;
//end create CSS for the correct appointment colors from OpenEMR Admin->Calendar->Category
?>

</style>

</head>

<body class="yui-skin-sam" background="/openemr/interface/pic/aquabg.gif">
<div ><a href="http://www.cnybit.com/openemrmobile"><img src="img/header-bg.png" border="0"/></a></div>
<br>
<div id="showhideContainer" style="float:left;position:relative;left:0em;">
<form name="dates" id="dates">
    <button type="button" id="prev"><</button>
    <input type="text" name="date1" id="date1" />
    
    <button type="button" id="next">></button>
    <br><br>
    <input type="button" id="showhide" value="Show Calendar"/>
</form>
</div>
<div style="clear:both"></div>

<div id="cal1Container"></div>
<div style="clear:both"></div>

<div style="font-size:5em;font-family:arial;"><br>Providers</div>
<div id="providerSelect">
<form name="providers">

<select name="selPro" id="selPro" >
<option value="" selected>All Providers</option>

<?php
//start create the list of providers
$qs = "SELECT concat(fname,' ',lname) as name, id FROM users WHERE authorized = 1";
$qy = $db->addQuery($qs);
$rs = $qy->execute();

if (is_null($rs))
{
  die("ERROR: Couldn't execute query:<br>\n" . $qy->get_error());
}
$rs->move_first();

$output = "";
while(!$rs->eof()){	
	$output .= "\n<option value=".$rs->fields('id').">".$rs->fields('name')."</option>";
	$rs->move_next();
}

$db->close();
echo $output;
//end create the list of providers
?>

</select>
</form>
</div>
<div style="clear:both"></div>
<div style="font-size:5em;font-family:arial;"><br>Appointments</div>

<div id="tbl"></div>
<div style="font-size:2em;font-family:arial;">* Implies note for patient</div>
<script type="text/javascript">
	YAHOO.namespace("calendar");
	var selDate;
	var selDoc;
	var calOpen = false;
	
	
	YAHOO.calendar.init = function() {

		function mySelectHandler(type,args,obj) {
			var selected = args[0];
			//save some values for later use
			selPro = document.getElementById("selPro");
			selDoc = selPro.options[selPro.selectedIndex].value;
			selDate = this.toDate(selected[0]);
			
			//update the Date in the text input box
            var txtDate1 = document.getElementById("date1");
            txtDate1.value = selDate.toDateString();
		};

        function updateCal() {
        	//used to save the current providers and date then highlight the selected date
	        selPro = document.getElementById("selPro");
	        selDoc = selPro.options[selPro.selectedIndex].value;
        	//check if selDate is null, if so use curDate
        	if(selDate == null){
        		var curDate = new Date();
        	}
        	else {
        		var curDate = selDate;
        	}
        	//used with the datatable listener
        	var cellidx = YAHOO.calendar.cal1.getCellIndex(curDate);
        	YAHOO.calendar.cal1.selectCell(cellidx);
        }
        
        function showHideCal() {
        	//used with the Show/Hide button to bring up the full month calendar
        	if(calOpen == true){
				YAHOO.calendar.cal1.hide();
				calOpen = false;
				caltext = document.getElementById("showhide");
				caltext.value = "Show Calendar";
					
				}
			else 
			{
				YAHOO.calendar.cal1.show();
				calOpen = true;
				caltext = document.getElementById("showhide");
				caltext.value = "Hide Calendar";		
			}
        }   

        function prevDay() {
        	//used with the < arrow button to move one day back
            if(selDate == null){
        		var curDate = new Date();
        	}
        	else {
        		var curDate = selDate;
        	}
        	var month = curDate.getMonth();
        	curDate.add(-1).days();
        	if(month!=curDate.getMonth()) YAHOO.calendar.cal1.previousMonth();
        	var cellidx = YAHOO.calendar.cal1.getCellIndex(curDate);
        	YAHOO.calendar.cal1.selectCell(cellidx);
        } 
        
        function nextDay() {
        	//used with the > button to move one day forward
            if(selDate == null){
        		var curDate = new Date();
        	}
        	else {
        		var curDate = selDate;
        	}
        	var month = curDate.getMonth();
        	curDate.add(1).days()
        	if(month!=curDate.getMonth()) YAHOO.calendar.cal1.nextMonth();
        	var cellidx = YAHOO.calendar.cal1.getCellIndex(curDate);
        	YAHOO.calendar.cal1.selectCell(cellidx);
		}          
		//create the calendar
		YAHOO.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");
		//handle clicks on the calendar
		YAHOO.calendar.cal1.selectEvent.subscribe(mySelectHandler, YAHOO.calendar.cal1, true);
		//start with the calendar hidden
		YAHOO.calendar.cal1.hide();
		//still have to render it though
		YAHOO.calendar.cal1.render();
		
		//provider change listener
		YAHOO.util.Event.addListener("selPro", "change", updateCal);
		//show/hide calendar button listener
		YAHOO.util.Event.addListener("showhide", "click", showHideCal);
		//prev day < button listener
		YAHOO.util.Event.addListener("prev", "click", prevDay);
		//next day > button listener
		YAHOO.util.Event.addListener("next", "click", nextDay);
		
		//set the date box to the current date on load
		var txtDate1 = document.getElementById("date1");
		var d = new Date();
        txtDate1.value = d.toDateString();
	}

	YAHOO.util.Event.onDOMReady(YAHOO.calendar.init);


YAHOO.util.Event.onDOMReady(function () {
		//the columns to display in the datatable
		var myColumnDefs = [
            		{key:"Name"},
            		{key:"StartTime", label: "Start Time"}
        ];

		//our data provider
        var myDataSource = new YAHOO.util.DataSource("data.php?");
        //data.php creates a XML output
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
		//schema for the XML
        myDataSource.responseSchema = {
        	resultNode: "Result",
            fields: ["Pid","Name","StartTime","Cat","Text"]
        };

		//colorize appointments based on category type from OpenEMR
		var myRowFormatter = function(elTr, oRecord) {
    	    YAHOO.util.Dom.addClass(elTr, oRecord.getData('Cat'));
			return true;
		}; 

		// Instantiate the DataTable.
        var myDataTable = new YAHOO.widget.DataTable("tbl", myColumnDefs,
                myDataSource,{formatRow: myRowFormatter, selectionMode: 'single' });
        var mySuccessHandler = function() {
            myDataTable.deleteRows(myDataTable.getRecordSet().getLength() - 1, -1
			* myDataTable.getRecordSet().getLength());
			myDataTable.initializeTable();
			myDataTable.render(); 
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var myFailureHandler = function() {
            this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var callbackObj = {
            success : mySuccessHandler,
            failure : myFailureHandler,
            scope : myDataTable
        };
        
		//this function provides the drop down notes
		YAHOO.ymod.tableExtension.setup( myDataTable, function( contentDiv)
		{
    		var myContent = '<img src="img/arrow.png" />';
   			var selectedRows = this.getSelectedRows();
   			var getSelectedTrEls = this.getSelectedTrEls();
    		if( selectedRows.length > 0 )
    		{
        		myContent += this.getRecord(selectedRows[0]).getData("Text");
    		}
    		contentDiv.innerHTML = myContent;
		} );
		
		//reload the data anytime the user clicks on the calendar
        var handleClick = function() {
			myDataSource.sendRequest("date="+selDate.getFullYear()+"-"+selDate.getMonth()+"-"+selDate.getDate()+"&doc="+selDoc,
                callbackObj);	
        }
		
		//subscribe to calendar clicks
		YAHOO.calendar.cal1.selectEvent.subscribe(handleClick, YAHOO.calendar.cal1, true);

        return {
            ds: myDataSource,
            dt: myDataTable
        };                  
                
});
</script>

</body>
</html>
Return current item: OpenEMR Mobile