Location: PHPKode > projects > Web-NoteTaker > notetaker/include/meeting.php
<?php
// NoteTaker
// Created and Coded by Bo Ahlberg
// Copyright 2008 by Bo Ahlberg ( bahlberg at mac.com )
// This code is licensed "AS-IS", No warranty is expressed or implied as to the
// suitability of this software for any purpose. Further, this code is licensed
//	under the:
//    Creative Commons Attribution-Share Alike 3.0 United States License
// This means you are free to:
//		to Share - to copy, distribute, display, and perorm work
//	  to remix - to make derivative works
//  Under the Following Conditions:
//		Attribution - You must attribute the work in the manner 
//    		specified by the author or licensor (but not in any way 
//    		that suggests that they endorse you or your use of the work).
//    Share Alike. If you alter, transform, or build upon this work, 
//				you may distribute the resulting work only under the same, 
//				similar or a compatible license.
//	For any reuse or distribution, you must make clear to others the license 
//		terms of this work. The best way to do this is with a link to this web page.
//	Any of the above conditions can be waived if you get permission from the 
//		copyright holder.
//	Apart from the remix rights granted under this license, nothing in this 
//		license impairs or restricts the author's moral rights.
//

$meetLabel = array(  'meetID'        => 'ID',   
					 'projID'        => 'Project',    
					 'meetHost'      => 'Host',    
					 'meetLocation'  => 'Location',    
					 'meetSubject'   => 'Subject',    
					 'meetDate'      => 'Date',    
					 'meetNote'      => 'Notes' ) ;

$meetingMenu = array( 'New'        => 'new', 
					  'Edit'       => 'edit', 
					  'List'       => 'list' );

function meetingMain( $mode  )
{
	$id   = (array_key_exists( 'id',   $_REQUEST ))? $_REQUEST['id']   : 0;
	//$mnu  = makeRow( makeCell( 5, makeMeetingMenu( ) ) );
	switch( $mode )
	{
		case 'post' :
			Message( 1, "meetingMain: post" );
			processMeetingInput( $id );
			break;
	}
	
	$body = makeRow( MakeCell( 3, ($id > 0 )? listActiveMeeting( $id ) : listMeetings( 'meet' ) ) )
	       .makeRow( makeCell( 1, listAttending( $id ), '', '', '15%' )
					        .makeCell( 1, listNotes( $id ), '', '', '55%' )
					        .makeCell( 1, listParking( $id ), '', '', '30%' ) ) 
         .makeRow( makeCell( 1, makeAttendingEntry( $id ), 'kanbanHeading' )
				          .makeCell( 2, makeItemEntry( $id ), 'kanbanHeading' ) );
	;
	
	
	return makeTable( 100, $body );
}

function listActiveMeeting( $id )
{	global $proplist;
	if ( $id > 0 )
	{
		$item = $proplist['meet'][$id];
		$ret = makeRow( makeCell( 1, 
								  makeTable( 100, makeRow(  makeCell( 1, $proplist['proj'][$item['projID']]['projName'], "kanbanHeading", '' )
															.makeCell( 1, $item['meetLocation'], "kanbanHeading", '' )
															.makeCell( 1, $item['meetDate'],     "kanbanHeading", '' )
															.makeCell( 1, $item['meetSubject'],  "kanbanHeading", '' )
															.makeCell( 1, makeActionLink( 'meeting', 'list',  $item['meetID'], 'meet',"Refresh")
																	     .makeActionLink( 'print',   'print', $item['meetID'], 'meet',"Print"), "kanbanHeading" )
															) 
											 ), 'kanbanTitle' 
								  )
						);
	}
	else
		$ret = makeRow( makeCell( 1, "&nbsp;" ) ) ;
	return makeTable( 100, $ret );
}

function listMeetings( $prop  )
{	global $meetLabel, $proplist;
	
	$colorIndex = "";
	$id = 0;
	$headers = "";
	$count = 0;
	$form = "";
	
	foreach( $meetLabel as $index => $label )
	{
		$count++;
		$headers.= makeCell( 1, $label, 'kanbanHeading' );
		if ( $label == "Color" )
			$colorIndex = $index;
	}
	
	$form.= makeRow( makeCell( $count+1, "List Properties: ".$prop, 'kanbanTitle' ), 'kanbanTitle' );
	$form.= makeRow( $headers.makeCell( 1, makeActionLink( 'admin', 'edit', 0, 'meet', "New"), 'kanbanHeading' ), 'kanbanTitle' );
	
	$count = 0;
	$property = $proplist[$prop];
	foreach ( $property as $index1 => $item )
	{
		$count++;
		$clr = ( $colorIndex != "" )? $item[$colorIndex] :"";
		$frm = makeCell( 1, "&nbsp;", "", $clr );
		$frm.= makeCell( 1, $proplist['proj'][$item['projID']]['projName'], "", $clr );
		$frm.= makeCell( 1, $item['meetHost'],     "", $clr );
		$frm.= makeCell( 1, $item['meetLocation'], "", $clr );
		$frm.= makeCell( 1, $item['meetDate'],     "", $clr );
		$frm.= makeCell( 1, $item['meetSubject'],  "", $clr );
		$frm.= makeCell( 1, $item['meetNote'],     "", $clr );
		$frm.= makeCell( 1, makeActionLink( 'meeting', 'list', $item['meetID'], 'meet',"Select"), "kanbanHeading", $clr) ;
		$form.= makeRow( $frm, (($count%2) == 0 )? 'kanbanEven' : 'kanbanOdd' );
	}
	$ret = makeTable( 100, $form );
	
	return $ret;
}

function makeMeetingMenu( )
{	global $meetingMenu;
	$form = "";
	foreach( $meetingMenu as $index => $item )
	{
		$class = ( $item == $mode )? "ActiveItem" : "InactiveItem" ;
		$form.= makeCell( 1, makeActionLink( 'meeting', $item, '', '', $index ), $class );
	}
	$ret = makeTable( 0, makeRow( $form, 'pageMenubanner' ) );
	
	return $ret;
}

function makeItem( $item )
{	global $proplist;
	$time = ( $item['itemTime'] != "" ) ? $item['itemTime'] : "&nbsp;" ;
	$name = ( $item['username'] != "" ) ? $item['username'] : "&nbsp;" ;
	$note = ( $item['itemNote'] != "" ) ? $item['itemNote'] : "&nbsp;" ;
	
	$colr = $proplist['types'][$item['itemTypeID']]['typesColor'];
	$type = $proplist['types'][$item['itemTypeID']]['typesName'];
	
	$bdy = makeRow(  makeNCell( 2, 1, $time, 'kanban', $colr, '20%' )
					.makeCell(  1,    $name." : ".$type." item", 'kanban', $colr ) )
		  .makeRow(  makeCell(  1,    $note, 'kanban', ''    ) );
	return makeTable( 100, $bdy );
}

function listNotes( $meeting )
{	global $proplist;
	
	$ret = "";
	$ret.= makeRow( makeCell( 1, "Meeting notes", 'kanbanHeading' ) );
	if ( $meeting > 0 )
	{	
		$rows = getNotes( $meeting, " itemTypeID IN( SELECT typesID FROM types WHERE typesName IN( 'Comments', 'Requirements', 'Notes'))" );
		$count = 1;
		foreach( $rows as $row )
		{
			Message( 2, "listNotes, making Note Cell: ".$count );
			$ret.= makeRow( makeCell( 1, makeItem( $row ) ) );
			$count++;
		}
	}
	else
		$ret.= makeRow( makeCell( 1, makeItem( "" ) ) );
	
	return makeTable( 100, $ret );
}

function listNoteEntry( $row, $count )
{ global $proplist;
	$ret = "";
	$class = ( ($count%2) == 0 )? 'kanbanEven' : 'kanbanOdd' ;
	if ( is_array( $row ) )
	{
		$ret.= makeCell( 1, $proplist['proj'][$row['projID']]['projName'], $class );
		$ret.= makeCell( 1, $proplist['task'][$row['taskID']]['taskName'], $class );
		$ret.= makeCell( 1, $row['tcDate'], $class  );
		$ret.= makeCell( 1, $row['tcHours'], $class );
		$lwr = makeCell( 4, "<B>Notes:</B><br>".$row['tcNotes'], $class );
	}
	else
	{
		$ret.= makeCell( 4, "No Time Entries", $class );
	}
	return makeRow( $ret );
}

function makeItemEntry( $meeting, $existing )
{ global $session;

	if( $session->logged_in )
	{
		$attending = getAttending( $meeting );
		if ( $meeting > 0 )
		{ //makeSelectFromTable( $name, $table, $existing, $key, $field )
			$bdy = makeRow( makeNCell( 2, 1, ( $existing['itemTime'] != 0 )? $existing['itemTime'] :'Enter<br>New<br>Note', 'kanbanHeading', '20%' )
                     .makeCell( 1, "Attendee".makeSelectFromTable( 'username',   $attending,  $existing['username'],   'username', 'username' )
									   ."Kind:".   makeTypesSelect(      'itemTypeID', $existing['itemTypeID'] ) ) );
			$bdy.= makeRow( makeCell( 4, makeUserNote(   'itemNotes',  'Notes', 5, 160, $existing['itemNote'] ) ) );
			$ret = makeTable( 0, makeForm( "meeting", 'post', $meeting, 'note', '', $bdy, 'Add' ) );
		}
		else
		{ 
			$ret = makeTable( 0, makeRow( makeCell( 1, "" ) ) );
		}
	}
	else
		$ret = makeTable( 0, makeRow( makeCell( 1, "" ) ) );

	return $ret;
}

function processMeetingInput( $id )
{	global $session;
	// input fields are: meetID, username, itemTypeID, itemNote 
	Message( 1, " processMeetingInput entry " );
	$prop = (array_key_exists( 'prop',   $_REQUEST ))? $_REQUEST['prop']   : 'default' ; 
		switch( $prop )
		{
			case 'attending':
				if ( $id != 0 )
				{
					$query = "INSERT INTO items( meetID, username, itemTypeID, itemNote )";
					$query.=       " VALUES( ".$id.", '".$_POST['username']."' , (SELECT typesID FROM types where typesName='Attendee'), '".$_POST['role']."' )";
					if ( processUpdate( $query ) )
						initGlobals( $id, $id );
					else
						Message( 4, " processMeetingInput attending Query Error: ".$query );
				}
				break;
			default:
				if ( $id != 0 )
				{	// new
					$query = "INSERT INTO items( meetID, username, itemTypeID, itemNote )";
					$query.=       " VALUES( ";
					$query.= ($id != "" )? $id : 1;
					$query.=       ", ";
					$query.= ($_POST['username'] != "" )? "'".$_POST['username']."'" : 1;
					$query.=       ", ";
					$query.= ($_POST['itemTypeID'] != "" )? $_POST['itemTypeID'] : 1;
					$query.=       ", ";
					$query.= ($_POST['itemNotes'] != "" )? "'".htmlentities($_POST['itemNotes'])."'" : "";
					$query.= ")";
					if ( processUpdate( $query ) )
						initGlobals( $id, $id );
					else
						Message( 4, " processMeetingInput note Query Error: ".$query );
					
				}
				else
				{	// update
				}
				break;
		}
			return makeTable( 0,makeRow( makeCell( 1, $query ) ) );
}


function getNotes( $id, $criteria )
{	global $session;
	
	$query = "SELECT * FROM items";
	$query.= ( $id > 0 )         ? " WHERE meetId = '".$id."'" : "" ;
	$query.= ( $criteria != "" ) ? "   AND ".$criteria         : "" ;
	
	$row[1] = "";
	$result = processQuery( $query );
	if ( $result )
	{
		$count = 1;
		while ( $rec = mysql_fetch_array( $result, MYSQL_ASSOC ) )
		{
			Message( 2, "getNotes, getting Row: ".$count );
			$row[$count] = $rec;
			$count++;
		}
	}
	else
		Message( 9, "Query Failed: ".$query );
	//Message( 2, $query );
	return $row;
}

function makeNoteEntry( $existing )
{ 
	$ret = makeRow( makeNCell( 2, 1, ( $existing['itemTime'] != 0 )? $existing['itemTime'] :'&nbsp;', 'kanbanHeading' )
					.makeCell( 1, "User:".makeUserSelectByFldName( 'username', 'user',  $existing['username'],   'username', 'username' )
							   ."Note&nbsp;Type:".makeTypesSelect( 'itemTypeID', $existing['itemTypeID'] ) ) );
	$ret.= makeRow( makeCell( 4, makeUserNote(   'itemNotes',  'Notes', 5, 80, $existing['itemNote'] ) ) );
	return makeTable( 0, $ret );
}

function makeTypesSelect( $name, $id )
{	global $proplist;
	
	$query = "SELECT * FROM types where typesName <>'Attendee'";
	$result = processQuery( $query );
	if ( $result )
	{
		$count = 1;
		while ( $rec = mysql_fetch_array( $result, MYSQL_ASSOC ) )
		{
			Message( 2, "getNotes, getting Row: ".$count );
			$row[$count] = $rec;
			$count++;
		}
	}
	else
		Message( 9, "Query Failed: ".$query );
	
	$sel = "<SELECT name='".$name."'>";
	$sel.= "<OPTION value=''>Make Selection</OPTION>";
	foreach( $row as $prop )
	{
		$sel.= "<OPTION value='".$prop['typesID'];
		$sel.= ($id == $prop['typesID'])? " selected " : "" ;
		$sel.= "'>";
		$sel.= $prop[typesName];
		$sel.= "</OPTION>";
	}
	$sel.= "</SELECT>";
	
	return $sel;
}




function listAttending( $meeting )
{
	$ret = makeRow( makeCell( 2, "Attendees", 'kanbanHeading' ) );
	$rows = getAttending( $meeting  );
	$count = 1;
	foreach( $rows as $row )
	{
		print "\n<!-- listAttending:\n"; print_r( $row ); print "\n-->\n";
		$ret.= makeAttend( $row ) ;
		$count++;
	}
	//$ret.= makeRow( makeCell( 2, makeAttendingEntry( $meeting ), 'kanbanHeading' ) );
	return makeTable( 100, $ret );
}

function getAttending( $id )
{	global $session;
	
	if ( $id > 0 )
	{
		$query = "SELECT * FROM items WHERE meetID = ".$id." AND itemTypeID = (SELECT typesID FROM types where typesName='Attendee')" ;
		
		$row[1] = "";
		$result = processQuery( $query );
		if ( $result )
		{
			$count = 1;
			while ( $rec = mysql_fetch_array( $result, MYSQL_ASSOC ) )
			{
				$row[$count] = $rec;
				$count++;
			}
		}
		else
			Message( 9, "Query Failed: ".$query );
	}
	else
		$row = "";
	return $row;
}

function makeAttend( $item )
{
	$bdy = makeRow( makeCell(  1, $item['username'], '', '' ).makeCell(  1, $item['itemNote'], '', '' ) );
	return $bdy;
}

function makeAttendingEntry( $meeting )
{ global $session;
	if( $session->logged_in )
	{
		if ( $meeting > 0 )
		{	
			$ret = makeTable( 0, 
							  makeForm( "meeting", 'post', $meeting, 'attending', '', 
										makeRow( makeCell( 1, "Attending:<br>"
														   .makeUserInput( 'text', 'username', '30', '' )
														   ."<br>Role:<br>"
														   .makeUserInput( 'text', 'role',     '30', '' ) ) ), 'Add' ) );
		}
		else
			$ret = makeTable( 0, makeRow( makeCell( 1, "" ) ) );
	}
	else
		$ret = makeTable( 0, makeRow( makeCell( 1, "" ) ) );
	return $ret;
}


function processAttending( $id )
{	global $session;
	// input fields are: proj, task, date, hours, notes 
	if ( $id == 0 )
	{	// new
		$query = "INSERT INTO timecards( projID, taskID, userName, tcDate, tcHours, tcNotes)";
		$query.=       " VALUES( ";
		$query.= ($_POST['projID'] != "" )? $_POST['projID'] : 1;
		$query.=       ", ";
		$query.= ($_POST['taskID'] != "" )? $_POST['taskID'] : 1;
		$query.=       ", '".$session->username."' ";
		$query.=       ", ";
		$query.= ($_POST['month'] != "" )? "date('".$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']."' )" : date('2008-1-1');
		$query.=       ", ";
		$query.= ($_POST['hours'] != "" )? $_POST['hours'] : 1;
		$query.=       ", ";
		$query.= ($_POST['notes'] != "" )? "'".$_POST['notes']."'" : "";
		$query.= ")";
	}
	else
	{	// update
	}
	return makeTable( 0,makeRow( makeCell( 1, $query ) ) );
}

function listParking( $meeting )
{	global $proplist;
	$ret = "";
	$ret.= makeRow( makeCell( 1, "Parking Lot", 'kanbanHeading' ) );
	if ( $meeting > 0 )
	{
		$rows = getNotes( $meeting, " itemTypeID = 4 " );
		$count = 1;
		foreach( $rows as $row )
		{
			Message( 2, "listParking, making Note Cell: ".$count );
			$ret.= makeRow( makeCell( 1, makeItem( $row ) ) );
			$count++;
		}
	}
	else
		$ret.= makeRow( makeCell( 1, makeItem( "" ) ) );
	
	//$ret.= makeRow( makeCell( 1, "&nbsp;", 'kanbanHeading' ) );
	return makeTable( 100, $ret );
}

function getParking( $id )
{	global $session;
	
	$query = "SELECT * FROM items WHERE itemTypeID = (SELECT typesID FROM types where typesName='Parking Lot')" ;
	
	$row[1] = "No Time Entries";
	$result = processQuery( $query );
	if ( $result )
	{
		$count = 1;
		while ( $rec = mysql_fetch_array( $result, MYSQL_ASSOC ) )
		{
			$row[$count] = $rec;
			$count++;
		}
	}
	else
		Message( 9, "Query Failed: ".$query );
	//Message( 2, $query );
	return $row;
}

function makeParking( $item )
{
	$bdy = makeRow( makeCell(  1,    "Who", 'kanbanHeading', '' ) )
				.makeRow( makeCell(  1,    "Item", 'kanban', '' ) );
	return makeTable( 100, $body );
}


function processParking( $id )
{	global $session;
	// input fields are: proj, task, date, hours, notes 
	if ( $id == 0 )
	{	// new
		$query = "INSERT INTO timecards( projID, taskID, userName, tcDate, tcHours, tcNotes)";
		$query.=       " VALUES( ";
		$query.= ($_POST['projID'] != "" )? $_POST['projID'] : 1;
		$query.=       ", ";
		$query.= ($_POST['taskID'] != "" )? $_POST['taskID'] : 1;
		$query.=       ", '".$session->username."' ";
		$query.=       ", ";
		$query.= ($_POST['month'] != "" )? "date('".$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']."' )" : date('2008-1-1');
		$query.=       ", ";
		$query.= ($_POST['hours'] != "" )? $_POST['hours'] : 1;
		$query.=       ", ";
		$query.= ($_POST['notes'] != "" )? "'".$_POST['notes']."'" : "";
		$query.= ")";
	}
	else
	{	// update
	}
	return makeTable( 0,makeRow( makeCell( 1, $query ) ) );
}

function editMeetingRecord( $id )
{
	return makeTable( 0, makeRow( makeCell( 1, "Edit Time Record (".$id.")" ) ) );
}

function newMeetingRecord(  )
{	global $session;
	
	$form.= makeRow( makeCell( $count, "New Timecard: ", 'kanbanTitle' ) );
	$count = 0;
	$row = "";
	$form.= makeTimeEntry( "" );
	
	$ret.= makeTable( 100, makeForm( 'time', 'post', $id, $prop, '', $form ) );
	
	return makeTable( 0, makeRow( makeCell( 1, $ret ) ) );
}

?>
Return current item: Web-NoteTaker