I need help on PHP Generator

Discussion in 'PHP' started by bweb11, Aug 16, 2009.

  1. #1
    Hi, i am working on a php code generator and would really like some help.
    I am not paying and it is an incredible project but i would appreciate the help.

    It's to be a project management php code generation system, to be able to generate php code and classes.

    Thanks.

    What i've got so far for the project management side of the script is:

    
    <?php
    
    
    class obphpgen
    {
    
    //To include php files
    function includefile ($path)
    	{
    	if(!include($path)){echo "Could not include: ".$path."";}
    	}
    
    //Connect to database passing variables such as below,  most likely from a config file included
    function connecttodb ($dbhosturl, $dbusername, $dbpassword, $db) 
    	{
    	
    	$con = mysql_connect($dbhosturl, $dbusername, $dbpassword);
    	if (!$con){echo 'Could not connect with database username and password.'; }
    	$select = mysql_select_db($db, $con);
    	if (!$select){echo 'Could not select database: '.$db; }
    	return true;
    	}
    	
    
    
    
    // Get Projects Created By The Logged in User
    function getuserprojects ($userid, $dbhosturl, $dbusername, $dbpassword, $db, $db_prefix)
    {
    
    //Connect to the database
    $this->connecttodb ($dbhosturl, $dbusername, $dbpassword, $db);
    
    //Set Needed Variables to be accessible outside of function
    global $errors;
    global $user;
    
    $errors = array();
    
    // If they are logged in, retrieve project for logged in user from database 
    $query = "SELECT * from ".$db_prefix."user_projects WHERE userid = '$userid' ";
    $result = mysql_query($query);
    
    	if($result) 
    	{
    
    		while ($row = mysql_fetch_array($result)) 
    		{
        	$user[projects][] = $row[projectid]; //The ID Number of the Project
    		$proid = $row[projectid];
    		$user[projects][$proid][name] = $row[name]; //The Name of the Project
    		$user[projects][$proid][userid] = $row[userid]; //Userid of the project starter
    		$user[projects][$proid][defaults] = explode(", ", $row[defaults]); // Default settings of the project as an array
    		$user[projects][$proid][started] = $row[started]; // Date and time project started
    		$user[projects][$proid][networkids] = explode(", ", $row[networkids]); // ID's of networks with access as an array
    		$user[projects][$proid][userperms] =  explode(", ", $row[userperms]); // Id's of Users with access as an array
    		$user[projects][$proid][bannedusers] =  explode(", ", $row[banned]); // Id's of Users without access as an array
    		$user[projects][$proid][settings] =  explode(", ", $row[settings]); // Settings of the project as an array
    
    		unset($proid); // Delete $proid variable
    		
      				}
    	}
    	else
    	{$error[] = "Could Not Select User's Projects";}
    
    unset($query);
    
    return true;
    
    }
    
    
    
    //Load a php project from Database
    function loaddbproject ($useridno, $projectidno, $dbhosturl, $dbusername, $dbpassword, $db, $db_prefix)
    {
    //Connect to the database
    $this->connecttodb ($dbhosturl, $dbusername, $dbpassword, $db);
    
    //Set Needed Variable to be accessible outside of function
    global $errors;
    global $project;
    
    $errors = array();
    
    // Retrieve project for logged in user from database 
    $query = "SELECT * from ".$db_prefix."user_projects WHERE userid = '$useridno' AND projectid = '$projectidno'";
    $result = mysql_query($query);
    
    	if($result) 
    	{
    
    		while ($row = mysql_fetch_array($result)) 
    		{
        	$project[id] = $row[projectid]; //The ID Number of the Project
    		$proid = $row[projectid];
    		$project[$proid][name] = $row[name]; //The Name of the Project
    		$project[$proid][userid] = $row[userid]; //Userid of the project starter
    		$project[$proid][defaults] = explode(", ", $row[defaults]); // Default settings of the project
    		$project[$proid][started] = $row[started];
    		$project[$proid][networkids] = explode(", ", $row[networkids]);
    		$project[$proid][userperms] =  explode(", ", $row[userperms]);
    		$project[$proid][bannedusers] =  explode(", ", $row[banned]);
    		$project[$proid][settings] =  explode(", ", $row[settings]);
    	
    				
    		}
    	}
    
    	else
    	{$error[] = "Could Not Load Project From Database";}
    
    unset($query);
    
    return true;
    
    }	
    	
    	
    	
    	
    // Get all the files belonging to a single project
    function getprojectfiles ($projectno, $dbhosturl, $dbusername, $dbpassword, $db, $dbprefix)
    {
    
    //Connect to the database
    $this->connecttodb ($dbhosturl, $dbusername, $dbpassword, $db);
    
    //Set Needed Variable to be accessible outside of function
    global $errors;
    global $project;
    
    // Retrieve Files For project form database 
    $query = "SELECT * from ".$db_prefix."project_files WHERE projectid = '$projectno' ";
    $result = mysql_query($query);
    
    if($result) 
    	{
    
    		while ($row = mysql_fetch_array($result)) 
    		{
        	$filename = $row[name];
    		$proid = $projectno;
    		$project[$proid][files][$filename][id] = $row[fileid];
    		$project[$proid][files][$filename][variables] = explode(", ", $row[vrbs]); //The Variables in this file
    		$project[$proid][files][$filename][funcs] = explode(", ", $row[funcids]); //The Custom Functions in this file
    		$project[$proid][files][$filename][code] = $row[code]; //The Code for this file
    		$project[$proid][files][$filename][created] = $row[created]; //The Date and time the file was created
    		$project[$proid][files][$filename][userid] = $row[userid]; //The Creator's Userid
    		$project[$proid][files][$filename][networkids] = explode(", ", $row[networksids]); //Networks with access to file
    		$project[$proid][files][$filename][userperms] = explode(", ", $row[userperms]); //Individuals with access
    		$project[$proid][files][$filename][banned] = explode(", ", $row[banned]); //Exclusively banned Individuals
    		$project[$proid][files][$filename][projectid] = $row[projectid]; //Id of project which file belongs to
    		$project[$proid][files][$filename][classesid] = explode(", ", $row[classesid]); //ID of classes in this file
    		$project[$proid][files][$filename][description] = $row[description]; //Description of the file for own purposes
    		
    
    		unset($filename); // Delete $filename variable
    		unset($proid); // Delete $proid variable
    		
      				}
    	}
    	else
    	{$error[] = "Could Not Select the Files for The Project";}
    
    unset($query);
    
    return true;
    }
    
    
    
    // Display Details of the project retrieved from getuserprojects, and getnetworkprojects and getuseraccessprojects function, through variable.
    function projectdetails ($userprojectsarr, $projectno = NULL, $dbhosturl = NULL, $dbusername = NULL, $dbpassword = NULL, $db = NULL, $dbprefix = NULL)
    {
    
    // If $projectno is set, the request is then for details of a single project listed in the array otherwise, list details for every project in the array.
    
    if(isset($projectno))
    {
    echo "Project ID: $projectno <br />\n";
    echo "Project Name: ".$userprojectsarr[$projectno][name]." <br />\n";
    
    	if(isset($dbhosturl))
    	{	$this->connecttodb ($dbhosturl, $dbusername, $dbpassword, $db);
    		$query = "SELECT * from ".$db_prefix."users WHERE userid = '$userprojectsarr[$projectno][userid]' ";
    		$result = mysql_query($query);
    
    
    			while ($row = mysql_fetch_array($result)) 
    			{
    				$userprojectsarr[$projectno][username] = $row[username];
    			}
    	
    	unset($query);
    	unset($result);
    	
    
    	echo "Project started by: ".$userprojectsarr[$projectno][username]." <br />\n";
    	}
    	
    echo "Project started on: ".$userprojectsarr[$projectno][started]." <br />\n";
    
    echo "Network ID's with access to this project: ";
    $ntids = count($userprojectsarr[$projectno][networkids]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$projectno][networkids][$x])) {echo $userprojectsarr[$projectno][networkids][$x].", ";}}
    echo " <br />\n";
    
    echo "Users with access to this project: ";
    $ntids = count($userprojectsarr[$projectno][userperms]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$projectno][userperms][$x])) {echo $userprojectsarr[$projectno][userperms][$x].", ";}}
    echo " <br />\n";
    
    echo "Users banned from this project: ";
    $ntids = count($userprojectsarr[$projectno][bannedusers]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$projectno][bannedusers][$x])) {echo $userprojectsarr[$projectno][bannedusers][$x].", ";}}
    echo " <br />\n";
    
    echo "Project Setings: ";
    $ntids = count($userprojectsarr[$projectno][settings]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$projectno][settings][$x])) {echo $userprojectsarr[$projectno][settings][$x].", ";}}
    echo " <br />\n";
    
    echo " <br />\n";
    
    
    }
    else
    {
    	foreach ($userprojectsarr as $value) {
    	    if(!is_array($value)) {
    		echo "Project ID: $value <br />\n";
    		echo "Project Name: ".$userprojectsarr[$value][name]." <br />\n";
    		
    	if(isset($dbhosturl))
    	{	$this->connecttodb ($dbhosturl, $dbusername, $dbpassword, $db);
    		$query = "SELECT * from ".$db_prefix."users WHERE userid = '$userprojectsarr[$projectno][userid]' ";
    		$result = mysql_query($query);
    
    
    			while ($row = mysql_fetch_array($result)) 
    			{
    				$userprojectsarr[$value][username] = $row[username];
    			}
    	
    	unset($query);
    	unset($result);
    	
    
    	echo "Project started by: ".$userprojectsarr[$value][username]." <br />\n";
    	}
    	
    echo "Project started on: ".$userprojectsarr[$value][started]." <br />\n";
    
    echo "Network ID's with access to this project: ";
    $ntids = count($userprojectsarr[$value][networkids]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$value][networkids][$x])) {echo $userprojectsarr[$value][networkids][$x].", ";}}
    echo " <br />\n";
    
    echo "Users with access to this project: ";
    $ntids = count($userprojectsarr[$value][userperms]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$value][userperms][$x])) {echo $userprojectsarr[$value][userperms][$x].", ";}}
    echo " <br />\n";
    
    echo "Users banned from this project: ";
    $ntids = count($userprojectsarr[$value][bannedusers]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$value][bannedusers][$x])) {echo $userprojectsarr[$value][bannedusers][$x].", ";}}
    echo " <br />\n";
    
    echo "Project Setings: ";
    $ntids = count($userprojectsarr[$value][settings]); 
    for($x=-1;$x<$ntids;$x++) {if(!empty($userprojectsarr[$value][settings][$x])) {echo $userprojectsarr[$value][settings][$x].", ";}}
    echo " <br />\n";
    
    echo " <br />\n";
    
    		
    		}
    
    	}
    
    }
    
    }
    
    
    
    
    // List the retrieved project files from getprojectfiles() 
    function listprojectfiles ($projectfilesarr, $projectno = NULL, $dbhosturl = NULL, $dbusername = NULL, $dbpassword = NULL, $db = NULL, $dbprefix = NULL)
    {
    
    // If $projectno is set, the request is then for the files of a single project listed in the array otherwise, list files for every project in the array.
    
    	if(isset($projectno))
    	{
    
    	foreach ($projectfilesarr[$projectno][files] as $key => $value) 
    	{
    	echo "<table>";
    	echo "<tr><td>Filename</td><td>File Variables</td><td>File Code</td><td>Created on</td><td>Created By</td><td>Networks</td><td>Users</td><td>Banned Users</td><td>Classes</td><td></td>";
    	echo "<tr><td>";
    	echo "".$projectfilesarr[$projectno][files];
    	}
    
    	}
    	else
    	{
    	
    
    
    	}
    }
    
    
    
    
    
    
    
    
    
    
    
    
    }
    
    
    
    
    ?>
    
    PHP:
     
    bweb11, Aug 16, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sounds more like a code sniplet library and not a 'generator'

    Can you be more specific on what you need help with?
     
    kblessinggr, Aug 16, 2009 IP
  3. bweb11

    bweb11 Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    With everything, i don't mean i'm stuck, just people to help me complete the script, and trust me, it's a generator.
     
    bweb11, Aug 16, 2009 IP
  4. pepprs

    pepprs Peon

    Messages:
    195
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you need help, and this is an generator. This is all i can understand. Please be specific on what the script does and what you want it to do.
     
    pepprs, Aug 16, 2009 IP