CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 CheckBox Lists - udf examples.

Print topic Send  topic

Author Message
Casey
Posted: 11/24/2004, 9:42 PM


These functions assist the show and modify of checkbox lists in a record form.
(With many thanks to Luis (lvalverdeb) and David Bannister).

THE SHOW FUNCTION - present form to user.
In the before show event of the form, for each checkboxlist in the form,
call the function to display correct boxes checked.

e.g.
chkListShow(new clsDBConnectionName(), "FormName",$FormName->ControlName,"ParameterName","IntersectTableName","IntersectField1","IntersectField2Name_ToMatchParameter");

And the function to show
		  
function chkListShow($ThisConnection,$FormName,&$ControlName,$PassedParam,$TableName,$Field1,$Field2)      
{      
    // set connection and arrays      
  	$TempArray  = array();      
	  // populate the multiselect checkbox list in $ControlName      
    	// create a new connection object      
	 $ThisConnection->query(  
	       "SELECT ".$Field1." FROM ".$TableName."   
	        WHERE ".$Field2." =".$ThisConnection->ToSQL(CCGetParam($PassedParam,0),ccsInteger));      
             
           while($ThisConnection->next_record()) {     
             array_push($TempArray,$ThisConnection->f($Field1));  
           }  
			      
        $ControlName->Multiple = true;      
        $ControlName->Value = $TempArray;      
		      
        // close and destroy recordset      
	    $ThisConnection->close();      
return $ControlName;   
}    

THE MODIFY FUNCTION - after user submits form
In the appropriate event code locations,
i.e in After Update, After Insert,Before Delete:
Add the preparations, and use the matching action ('Insert', 'Update','Delete') in the function call.
Then the call, with these parameters:
the action, the connection, the checkboxlist name, Intersect table name,
iField name matching the Main record parameter, IField name for second field
  
global $FormName;  
$Conn = New clsDBConnectionName();  
$ParamValue = CCGetFromGet("YourParameterName",0);  <<<-- the parameter for the main record key, i.e. record id  
ChecklistModify("Delete", $Conn, $ParamValue, CCGetFromPost("chkControlName",array()), "IntersectTableName", "FieldMatchingParameter", "Field2");  

//## and the modify function itself:
  
function ChecklistModify($Actions, $Conn, $MainId, $CheckList, $TableName, $MainIdName, $LKIdName) {  
  
$LookupId = 0;  
//  
if($Actions == "Insert") {  
   // retrieve tha last inserted key - will need change before multi user.  
   $MainId = CCDLookup("max(PREGNANCY_ID)","PREGNANCIES","",$Conn);  
}  
//  
if($MainId > 0) {  
    if(($Actions == "Delete") Or ($Actions == "Update")) {  
	    // Delete all link table records  
        $Conn->query("DELETE FROM ". $TableName." WHERE ".$MainIdName."=".$Conn->ToSQL($MainId,ccsInteger));  
	}  
    if(($Actions == "Update") Or ($Actions == "Insert")) {  
	    // insert assigned records  
        reset($CheckList);  
	    while(list($key,$LookupId) = each($CheckList)) {  
	        $Conn->query("INSERT INTO ".$TableName."(".$LKIdName.",".$MainIdName.") VALUES(".$Conn->ToSQL($LookupId, ccsInteger).",".$Conn->ToSQL($MainId,ccsInteger).")");  
	    }  
	}  
}  
//  
// close and destroy connection object  
$Conn->close();  
  
// close the function  
}  

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.