Location: PHPKode > projects > Web-NoteTaker > notetaker/include/admin.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.
//
// Globals
$defaults['role']  = array( 'roleID'        => '',   
														'roleName'      => '',  
														'roleColor'     => '',   
														'roleDesc'      => '' );
															
$defaults['user']  = array( 'username'      => '',   
														'password'      => '',  
														'userid'        => '',    
														'userlevel'     => '',    
														'email'         => '',    
														'timestamp'     => '' );
															
$defaults['types'] = array( 'typesID'        => '',   
														'typesName'      => '',    
														'typesColor'      => '',    
														'typesNotes'     => '' );
															
$defaults['proj'] = array(  'projID'        => '',   
														'projName'      => '',   
														'projOwner'     => '',   
														'projNotes'     => '' );

$defaults['color'] = array( 'colorID'       => '',   
														'colorName'     => '',    
														'colorNumber'   => '',    
														'colorValue'    => '' );

$defaults['meet']  = array( 'meetID'        => '',   
														'projID'        => '',    
														'meetHost'      => '',    
														'meetLocation'  => '',    
														'meetSubject'   => '',    
														'meetDate'      => '',    
														'meetNote'      => '' );
$defaults['attend']  = array( 'attendeeID'  => '',   
														'attendeeName'  => '',    
														'attendeeOrg'   => '',    
														'attendeeTitle' => '',    
														'attendeeRole'  => 0,    
														'attendeeNote'  => '' );
$insrtFlds['role']  = 'roleName,     roleColor,    roleDesc';
$insrtFlds['meet']  = 'projID,       meetHost,     meetLocation,   meetSubject,  meetDate,      meetNote ';
$insrtFlds['user']  = 'username,     userlevel,    email ';
$insrtFlds['types'] = 'typesName,    typesColor,   typesNotes';
$insrtFlds['attend']= 'attendeeName, attendeeOrg,  attendeeTitle,  attendeeRole, attendeeNote';
$insrtFlds['proj']  = 'projName,     projOwner,    projNotes';
$insrtFlds['color'] = 'colorName,    colorNumber,  colorValue';

// Admin Functions
//

function adminMain( $prop )
{ global $proplist;

	$mode = (array_key_exists( 'mode', $_REQUEST ))? $_REQUEST['mode'] : "default";
	$id   = (array_key_exists( 'id',   $_REQUEST ))? $_REQUEST['id']   : 0;
	$bdy  = "";
	switch( $mode )
	{
		case 'post' :
			$bdy.= processPropertyInput( $prop, $_POST, $id );
			initGlobals( $cardwanted, $activeproj );
			$bdy.= listProperties( $prop );
			break;
		case 'edit' :
				$id  = (array_key_exists( 'id',   $_REQUEST ))? $_REQUEST['id']   : "default";
				$bdy.= editProperties( $prop, $id );
			break;
		default:
			if ( $mode != "" )
				$bdy.= listProperties( $prop );
			else
				$bdy.= "";
			break;
	}
	return $bdy;
}

function processPropertyInput( $prop, $post, $id )
{	global $proplist, $tables, $insrtFlds, $labels;
	
	$ret = "\n<!-- processPropertyInput( ".$prop." )-->";
	if ( $id <= 0 )
	{
		$query = "INSERT INTO ".$tables[$prop]."( ".$insrtFlds[$prop]." )";
		$query.= "VALUES( ";
		$count = 0;
		foreach ( $post as $index => $item )
		{
			$query.= (($count > 0)? ", ": " ")."'".$item."' ";
			$count++;
		}
		$query.= " )";
		$ret.= "\n<!-- processPropertyInput( ".$query." ) -->";
	}
	else
	{
		$query = "UPDATE ".$tables[$prop]." SET ";
		$fields = "";
		$count = 0;
	
		foreach ( $post as $index => $item )
		{
			if ( $proplist[$mode][$id][$index] != $item )
			{
				$query.= (($count > 0)? ", ": " ").$index." = '".$item."' ";
				$count++;
			}
		}
		$query.= " WHERE ".$labels[$prop]['key']." = ".$id." ;";
	}
	if ( $count > 0 )
	{
		if ( processUpdate( $query ) )
			initGlobals( $cardwanted, $activeProj);
		else
			Message( 4, " processPropertyInput Query Error: ".$query );
		
	}
	
	return $ret;
}


function makeAdminMenu( $proj, $mode )
{	global $menuList;
	$form = "";
	foreach( $menuList as $index => $item )
	{
		$class = ( $item == $mode )? "ActiveItem" : "InactiveItem" ;
		$form.= makeCell( 1, makeActionLink( 'admin', 'list', '', $item, $index ), $class );
	}
	$ret = makeTable( 0 , makeRow( $form, 'pageMenubanner' ) );

	return $ret;
}


function editProperties( $prop, $id, $label )
{	global $labels, $proplist;
	
	$title = ( $label != "" ) ? $label.$prop : "Edit Properties: ".$prop ;
	$colorIndex = "";
	$headers = "";
	$count = 0;
	foreach( $labels[$prop]['fields'] as $index => $label )
	{
		$count++;
		$headers.= makeCell( 1, $label, 'kanbanHeading' );
		if ( $label == "Color" )
			$colorIndex = $index;
	}
	$form.= makeRow( makeCell( $count, $title, 'kanban' ) );
	$form.= makeRow( $headers );
	$count = 0;
	$property = ($id < 0 )? $defaults[$prop] : $proplist[$prop][$id];
	$clr.= ( $colorIndex != "" )? $property[$colorIndex] : "";
	$row = "";
	foreach ( $labels[$prop]['fields'] as $index => $label )
	{
		$count++;
		if ( $label == "ID" )
			$row.= makeCell( 1, $property[$index] );
		else if ( $label == "Role" )
		{
			$row.= makeCell( 1, makeMenuControl( $index, 'role', 'roleID', 'roleName', $property[$index], $count ) );
		}
		else
		{
			$color = ( $colorIndex != "" )? $property[$colorIndex] : "";
			$row.= makeCell( 1, makeUserInput( 'text', $index, '', $property[$index], $color ) );
		}
	}
	$form.= makeRow( $row, "", $clr );

	$ret.= makeForm( 'admin', 'post', $id, $prop, '', makeTable( 0, $form ) );

	return $ret;
}

function listProperties( $prop, $doEdit )
{	global $labels, $proplist;
	
	$colorIndex = "";
	$colorRole = "";
	$id = 0;
	$headers = "";
	$count = 0;
	$form = "";
	
	$edit = ( $doEdit != 0 ) ? editProperties( $prop, 0, "Add: " ) : "" ;
	foreach( $labels[$prop]['fields'] as $index => $label )
	{
		$count++;
		$headers.= makeCell( 1, $label, 'kanbanHeading' );
		if ( $label == "Color" )
			$colorIndex = $index;
		else if ($label == "Role" )
			$colorRole = $index;
	}
	
	$form.= makeRow( makeCell( $count+1, "List Properties: ".$prop, 'kanbanTitle' ), 'kanbanTitle' );
	$form.= makeRow( $headers.makeCell( 1, makeActionLink( 'admin', 'edit', 0, $prop, "New" ), 'kanbanHeading' ), 'kanbanTitle' );

	$count = 0;
	$property = $proplist[$prop];
	foreach ( $property as $index1 => $item )
	{
		$count++;

		if ( $colorIndex != "" )
			$clr = $item[$colorIndex] ;
		else if ( $colorRole != "" )
			$clr = $proplist['role'][$item[$colorRole]]['roleColor'];
		$frm = "";
		foreach ( $labels[$prop]['fields'] as $index2 => $label )
		{
			$id = ( $label == 'ID' ) ? $item[$index2] : $id;
			if ( $label != "Role" )
			{
				$frm.= makeCell( 1, $item[$index2], "", $clr );
			}
			else
			{
				$frm.= makeCell( 1, $proplist['role'][$item[$colorRole]]['roleName'], "", $clr );
				
			}
		}
		$frm.= ( $id != 0 ) ? makeCell( 1,makeActionLink( 'admin', 'edit', $id, $prop,"Edit"), "kanbanHeading", $clr) : "";
		$form.= makeRow( $frm, (($count%2) == 0 )? 'kanbanEven' : 'kanbanOdd', $clr );
	}
	$ret = makeTable( 100, $form.makeRow( makeCell( count($labels[$prop]['fields'])+1 , $edit, "kanbanHeading" ) ) );

	return $ret;
}



?>
Return current item: Web-NoteTaker