Sign in to follow this  
sruder

Somewhat straight forward PHP

Recommended Posts

Using AppGini to develop an online resource for tracking information, similar to this link.

 

 

 

It shows a chart with the data and basically I would like generate a graph below to reflect the data!

 

 

 

Does anybody have an easy way to use the Record_ID_Week to build a graph based on any of the other aspects? Pay, Labor, etc... understand the concept in my head just can't seem to get it started yet.

 

 

 

Here is the PHP code:

 

 

 




<?php



// Data functions for table WeeklyData



// This script and data application were generated by AppGini 4.46

// Download AppGini for free from http://www.bigprof.com/appgini/download/



function WeeklyData_insert(){

global $Translation;



if($_GET['insert_x']){$_POST=$_GET;}



// mm: can member insert record?

$arrPerm=getTablePermissions('WeeklyData');

if(!$arrPerm[1]){

	return 0;

}



$WeekEndDate = makeSafe($_POST['WeekEndDateYear']) . '-' . makeSafe($_POST['WeekEndDateMonth']) . '-' . makeSafe($_POST['WeekEndDateDay']);

$WeekEndDate = parseMySQLDate($WeekEndDate, '');

$CP_RO_Count = makeSafe($_POST["CP_RO_Count"]);

$CP_HRs = makeSafe($_POST["CP_HRs"]);

$CustomerPay = makeSafe($_POST["CustomerPay"]);

$Total_CP_Labor = makeSafe($_POST["Total_CP_Labor"]);

$Total_CP_Parts = makeSafe($_POST["Total_CP_Parts"]);

$Notes = makeSafe($_POST["Notes"]);

if($WeekEndDate== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Week End Date': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

if($CP_RO_Count== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'CP RO Count': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

if($CP_HRs== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'CP HRs': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

if($CustomerPay== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Customer Pay': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

if($Total_CP_Labor== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Total CP Labor': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

if($Total_CP_Parts== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Total CP Parts': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}



sql("insert into `WeeklyData` set " . "`WeekEndDate`=" . (($WeekEndDate != '') ? "'$WeekEndDate'" : "NULL") . ", " . "`CP_RO_Count`=" . (($CP_RO_Count != '') ? "'$CP_RO_Count'" : "NULL") . ", " . "`CP_HRs`=" . (($CP_HRs != '') ? 



"'$CP_HRs'" : "NULL") . ", " . "`CustomerPay`=" . (($CustomerPay != '') ? "'$CustomerPay'" : "NULL") . ", " . "`Total_CP_Labor`=" . (($Total_CP_Labor != '') ? "'$Total_CP_Labor'" : "NULL") . ", " . "`Total_CP_Parts`=" . (($Total_CP_Parts 



!= '') ? "'$Total_CP_Parts'" : "NULL") . ", " . "`Notes`=" . (($Notes != '') ? "'$Notes'" : "NULL") . "");



// mm: save ownership data

$recID=mysql_insert_id();

sql("insert into membership_userrecords set tableName='WeeklyData', pkValue='$recID', memberID='".getLoggedMemberID()."', dateAdded='".time()."', dateUpdated='".time()."', groupID='".getLoggedGroupID()."'");



return (get_magic_quotes_gpc() ? stripslashes($recID) : $recID);

}



function WeeklyData_delete($selected_id, $AllowDeleteOfParents=false, $SkipChecks=false){

// insure referential integrity ...

global $Translation;





// mm: can member delete record?

$arrPerm=getTablePermissions('WeeklyData');

$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?

	// delete allowed, so continue ...

}else{

	return FALSE;

}





sql("delete from `WeeklyData` where `Record_ID_Week`='".makeSafe($selected_id)."'");



// mm: delete ownership data

sql("delete from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

}



function WeeklyData_update($selected_id){

global $Translation;



if($_GET['update_x']){$_POST=$_GET;}



// mm: can member edit record?

$arrPerm=getTablePermissions('WeeklyData');

$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?

	// update allowed, so continue ...

}else{

	return;

}



$WeekEndDate = makeSafe($_POST['WeekEndDateYear']) . '-' . makeSafe($_POST['WeekEndDateMonth']) . '-' . makeSafe($_POST['WeekEndDateDay']);

$WeekEndDate = parseMySQLDate($WeekEndDate, '');

if($WeekEndDate== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Week End Date': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$CP_RO_Count = makeSafe($_POST["CP_RO_Count"]);

if($CP_RO_Count== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'CP RO Count': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$CP_HRs = makeSafe($_POST["CP_HRs"]);

if($CP_HRs== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'CP HRs': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$CustomerPay = makeSafe($_POST["CustomerPay"]);

if($CustomerPay== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Customer Pay': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$Total_CP_Labor = makeSafe($_POST["Total_CP_Labor"]);

if($Total_CP_Labor== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Total CP Labor': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$Total_CP_Parts = makeSafe($_POST["Total_CP_Parts"]);

if($Total_CP_Parts== ''){

	echo StyleSheet() . "" . $Translation['error:'] . " 'Total CP Parts': " . $Translation['field not null'] . '



';

	echo ''.$Translation['< back'].'';

	exit;

}

$Notes = makeSafe($_POST["Notes"]);

sql("update `WeeklyData` set " . "`WeekEndDate`=" . (($WeekEndDate != '') ? "'$WeekEndDate'" : "NULL") . ", " . "`CP_RO_Count`=" . (($CP_RO_Count != '') ? "'$CP_RO_Count'" : "NULL") . ", " . "`CP_HRs`=" . (($CP_HRs != '') ? 



"'$CP_HRs'" : "NULL") . ", " . "`CustomerPay`=" . (($CustomerPay != '') ? "'$CustomerPay'" : "NULL") . ", " . "`Total_CP_Labor`=" . (($Total_CP_Labor != '') ? "'$Total_CP_Labor'" : "NULL") . ", " . "`Total_CP_Parts`=" . (($Total_CP_Parts 



!= '') ? "'$Total_CP_Parts'" : "NULL") . ", " . "`Notes`=" . (($Notes != '') ? "'$Notes'" : "NULL") . " where `Record_ID_Week`='".makeSafe($selected_id)."'");



// mm: update ownership data

sql("update membership_userrecords set dateUpdated='".time()."' where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");



}



function WeeklyData_form($selected_id = "", $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1, $ShowCancel = 0){

// function to return an editable form for a table records

// and fill it with data of record whose ID is $selected_id. If $selected_id

// is empty, an empty form is shown, with only an 'Add New'

// button displayed.



global $Translation;





// mm: get table permissions

$arrPerm=getTablePermissions('WeeklyData');

if(!$arrPerm[1] && $selected_id==""){ return ""; }

// combobox: WeekEndDate

$combo_WeekEndDate = new DateCombo;

$combo_WeekEndDate->DateFormat = "mdy";

$combo_WeekEndDate->MinYear = 1900;

$combo_WeekEndDate->MaxYear = 2100;

$combo_WeekEndDate->DefaultDate = date('Y-m-d', strtotime('last saturday'));

$combo_WeekEndDate->MonthNames = $Translation['month names'];

$combo_WeekEndDate->CSSOptionClass = 'Option';

$combo_WeekEndDate->CSSSelectedClass = 'SelectedOption';

$combo_WeekEndDate->NamePrefix = 'WeekEndDate';

$WeekEndDateToday=" [".$Translation['today']."]";



if($selected_id){

	// mm: check member permissions

	if(!$arrPerm[2]){

		return "";

	}

	// mm: who is the owner?

	$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

	$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='WeeklyData' and pkValue='".makeSafe($selected_id)."'");

	if($arrPerm[2]==1 && getLoggedMemberID()!=$ownerMemberID){

		return "";

	}

	if($arrPerm[2]==2 && getLoggedGroupID()!=$ownerGroupID){

		return "";

	}



	// can edit?

	if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){

		$AllowUpdate=1;

	}else{

		$AllowUpdate=0;

	}



	$res = sql("select * from `WeeklyData` where `Record_ID_Week`='".makeSafe($selected_id)."'");

	$row = mysql_fetch_array($res);

	$combo_WeekEndDate->DefaultDate = $row["WeekEndDate"];

}else{

}



// code for template based detail view forms



// open the detail view template

if(($_POST['dvprint_x'] || $_GET['dvprint_x']) && $selected_id){

	$templateCode=@implode('', @file('./templates/WeeklyData_templateDVP.html'));

	$dvprint=true;

}else{

	$templateCode=@implode('', @file('./templates/WeeklyData_templateDV.html'));

	$dvprint=false;

}



// process form title

$templateCode=str_replace('<%%DETAIL_VIEW_TITLE%%>', 'Detail View', $templateCode);

// process buttons

if($arrPerm[1]){ // allow insert?

	$templateCode=str_replace('<%%INSERT_BUTTON%%>', '', $templateCode);

}else{

	$templateCode=str_replace('<%%INSERT_BUTTON%%>', '', $templateCode);

}

if($selected_id){

	$templateCode=str_replace('<%%DVPRINT_BUTTON%%>', '', $templateCode);

	if($AllowUpdate){

		$templateCode=str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);

	}else{

		$templateCode=str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);



		// set records to read only if user can't insert new records

		if(!$arrPerm[1]){

			$jsReadOnly.="tif(document.getElementsByName('Record_ID_Week').length){ document.getElementsByName('Record_ID_Week')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('WeekEndDate').length){ document.getElementsByName('WeekEndDate')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('WeekEndDateDay').length){ var WeekEndDateDay=document.getElementsByName('WeekEndDateDay')[0]; WeekEndDateDay.disabled=true; 



WeekEndDateDay.style.backgroundColor='white'; WeekEndDateDay.style.color='black'; }";

			$jsReadOnly.="tif(document.getElementsByName('WeekEndDateMonth').length){ var WeekEndDateMonth=document.getElementsByName('WeekEndDateMonth')[0]; WeekEndDateMonth.disabled=true; 



WeekEndDateMonth.style.backgroundColor='white'; WeekEndDateMonth.style.color='black'; }";

			$jsReadOnly.="tif(document.getElementsByName('WeekEndDateYear').length){ var WeekEndDateYear=document.getElementsByName('WeekEndDateYear')[0]; WeekEndDateYear.disabled=true; 



WeekEndDateYear.style.backgroundColor='white'; WeekEndDateYear.style.color='black'; }";

			$jsReadOnly.="tif(document.getElementsByName('CP_RO_Count').length){ document.getElementsByName('CP_RO_Count')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('CP_HRs').length){ document.getElementsByName('CP_HRs')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('CustomerPay').length){ document.getElementsByName('CustomerPay')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('Total_CP_Labor').length){ document.getElementsByName('Total_CP_Labor')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('Total_CP_Parts').length){ document.getElementsByName('Total_CP_Parts')[0].readOnly=true; }";

			$jsReadOnly.="tif(document.getElementsByName('Notes').length){ document.getElementsByName('Notes')[0].readOnly=true; }";



			$noUploads=true;

		}

	}

	if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?

		$templateCode=str_replace('<%%DELETE_BUTTON%%>', "


"');">", $templateCode);

	}else{

		$templateCode=str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);

	}

	$templateCode=str_replace('<%%DESELECT_BUTTON%%>', "", 



$templateCode);

}else{

	$templateCode=str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);

	$templateCode=str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);

	$templateCode=str_replace('<%%DESELECT_BUTTON%%>', ($ShowCancel ? "" : ''), $templateCode);

}



// process combos

$templateCode=str_replace('<%%COMBO(WeekEndDate)%%>', $combo_WeekEndDate->GetHTML().($noUploads ? '' : $WeekEndDateToday), $templateCode);

$templateCode=str_replace('<%%COMBOTEXT(WeekEndDate)%%>', $combo_WeekEndDate->GetHTML(true), $templateCode);



// process foreign key links

if($selected_id){

}



// process images

$templateCode=str_replace('<%%UPLOADFILE(Record_ID_Week)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(WeekEndDate)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(CP_RO_Count)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(CP_HRs)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(CustomerPay)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(Total_CP_Labor)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(Total_CP_Parts)%%>', '', $templateCode);

$templateCode=str_replace('<%%UPLOADFILE(Notes)%%>', '', $templateCode);



// process values

if($selected_id){

	$templateCode=str_replace('<%%VALUE(Record_ID_Week)%%>', htmlspecialchars($row['Record_ID_Week'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(WeekEndDate)%%>', date('n/j/Y', strtotime(htmlspecialchars($row['WeekEndDate'], ENT_QUOTES))), $templateCode);

	$templateCode=str_replace('<%%VALUE(CP_RO_Count)%%>', htmlspecialchars($row['CP_RO_Count'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(CP_HRs)%%>', htmlspecialchars($row['CP_HRs'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(CustomerPay)%%>', htmlspecialchars($row['CustomerPay'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(Total_CP_Labor)%%>', htmlspecialchars($row['Total_CP_Labor'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(Total_CP_Parts)%%>', htmlspecialchars($row['Total_CP_Parts'], ENT_QUOTES), $templateCode);

	$templateCode=str_replace('<%%VALUE(Notes)%%>', htmlspecialchars($row['Notes'], ENT_QUOTES), $templateCode);

}else{

	$templateCode=str_replace('<%%VALUE(Record_ID_Week)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(WeekEndDate)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(CP_RO_Count)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(CP_HRs)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(CustomerPay)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(Total_CP_Labor)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(Total_CP_Parts)%%>', '', $templateCode);

	$templateCode=str_replace('<%%VALUE(Notes)%%>', '', $templateCode);

}



// process translations

foreach($Translation as $symbol=>$trans){

	$templateCode=str_replace("<%%TRANSLATION($symbol)%%>", $trans, $templateCode);

}



// clear scrap

$templateCode=str_replace('<%%', '', $templateCode);

// hide links to inaccessible tables

$templateCode.="";





// ajaxed auto-fill fields

$templateCode.="";

$templateCode.="";



// handle enforced parent values for read-only lookup fields



return $templateCode;

}

?>



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this