Page 1 of 1

Blocks of coding

Posted: Fri Nov 27, 2009 6:59 pm
by CoolAsCarlito
I'm not sure what would be the best way to do this but I have all 3 blocks of code here in my division.php file. I have my main section that displays the divisions from the database but need to know how to link the Add New hyperlink to the add division block of code. Should I just make a function out of the add division code and then call it through the hyperlink?

Code: Select all

print '<h1 class=backstage>Division Management</h1><br />';
print '<h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br />';
  {
  $query = "SELECT * FROM efed_list_divisions ORDER BY `name`";
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
           
            print '<table width="100%" class="table1">';
            print '<tr class="rowheading">';
            print '<td>&nbsp;</td>';
            print '<td>Name</td>';
            print '</tr>';
         // Fetch and print all records.
         $i = 0;
         $current_row = 0;
         while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) )
         { 
            $current_row++; 
             $sClass = 'row2';
             if ($i ++ & 1)
             {
                 $sClass = 'row1';
             }
             printf ( "<tr class=\"%s\">", $sClass );
             print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>";
              printf ( "<td valign=\"top\">%s</td>", $row [name] );
             print '</tr>';
         }
         print '</table>';
     }
     else
     {
     print '<span>There are no divisions.</span><br />';
     }
     print '<br />';
returnmain();
}  

Add division form

Code: Select all

print '<h1 class=backstage>Division Management</h1><br />';
    print '<h2 class=backstage>Add New Division</h2><br />';
    print '<form name="adddivision" method="post" action="backstage.php" id="adddivision">';
    print '<table width="100%" class="table2">';
    print '<tr>';
    print '<td width=120 class=rowheading valign=center>Division Name:</td><td class=row3><input type=text name=divisionname class=fieldtext490></td>';
    print '</tr>';
    print '</table><br />';
    print '<input type="submit" value="Save Division" class="button" name="adddivision"></form><br />';
    print '<form method=POST><input type=hidden name=action value=division><input type=submit value="Return to Division List" class=button200></form><br />';
    print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>'
Edit division form

Code: Select all

print'<h1 class="backstage">Division Management</h1><br />';
    print'<h2 class="backstage">Edit Division</h2><br />';
    print'<form name="editdivision" method="post" action="backstage.php" id="editdivision">';
    print'<table width="100%" class="table2">';
    print'<tr>';
    print'<td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="division" class="fieldtext490" value=""></td>';
    print'</tr>';
    print'</table><br />';
    print'<center>';
    print'<input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br />';
    print'<input type="submit" value="Edit Division" class=button name="editdivision"><br /><br />';
    print'<input type="button" value="Return to Divisions List" class="button200"><br /><br />';
    returnmain();

Re: Blocks of coding

Posted: Fri Nov 27, 2009 8:25 pm
by daedalus__
you can't call a function through a link. that isn't how php works.

also whats this guy here for?

Code: Select all

 
 print '<h1 class=backstage>Division Management</h1><br />';
 print '<h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br />';
   {    <!--------------------------------------------------------------------------------------------- what's this?
   $query = "SELECT * FROM efed_list_divisions ORDER BY `name`";
      $result = mysql_query ( $query ); // Run The Query
      $rows = mysql_num_rows($result);
      if ($rows > 0)
      {
 
im surprised that isn't throwing an error

im not seeing any code that 'adds a division' either.

i just see some forms. html forms. printed by... php...

.......?

Re: Blocks of coding

Posted: Fri Nov 27, 2009 8:38 pm
by CoolAsCarlito
Okay I fixed the extra braces however I don't have the form submission code in there yet just the forms themselves. I'm just trying to figure out what I have to do all of that coding to make it to where as soon as that Add New link is pressed it goes to that form.

Re: Blocks of coding

Posted: Fri Nov 27, 2009 8:48 pm
by daedalus__
uh okay. im kinda boxing with shadows here but ill try to knock this out

check it out

i have a page

LIST_DIVISIONS.HTML

Code: Select all

 
<h1 class=backstage>Division Management</h1><br />
<h2 class=backstage>Divisions :: <a href="add_division.html">Add New</a></h2><br />
<?php list_all_divisions(); ?>
 
when the user clicks add divisions it takes them to the page to add divisions

ADD_DIVISIONS.HTML

Code: Select all

 
<form method="post" action="process.php">
<!-- .........dadada yada inputs and crap -->
<input type="submit" value="Add Division" />
</form>
 
when the user clicks the add division button it directs them to process.php

PROCESS.PHP

Code: Select all

 
$sql = 'INSERT INTO division (name) VALUES (' . oh_lord_please_escape_me_jesus($_POST['name']) . ')';
$result = mysql_query($sql);
echo $result;  // <- PROBABLY INVALID SYNTAX
 
follow?

Re: Blocks of coding

Posted: Fri Nov 27, 2009 8:54 pm
by CoolAsCarlito
Now I have to figure out how to do that with just one page.

Re: Blocks of coding

Posted: Fri Nov 27, 2009 9:08 pm
by daedalus__
okay. why though?

its roughly like this:

Code: Select all

 
 
if ($_POST) //if post data exists
{
    process_the_form();
    include(thank_you_message.php);
}
else
{
    include(form.html);
}
 

Re: Blocks of coding

Posted: Mon Nov 30, 2009 5:04 pm
by CoolAsCarlito
I came up with something after doing some more research. I think I like this one a little bit more. Easier for me to write for future uses and understand. However I'm still not getting the add new division form to load. Here's the new code and my ajaxpage function is below that.

Code: Select all

 
<?php
if ($option == 0 )
{
    print '<h1 class=backstage>Division Management</h1><br />';
print "<h2 class=\"backstage\">Divisions :: <a href=\"#\" onclick=\"ajaxpage('division', '1'); return false;\">Add New</a></h2><br />";
  {
  $query = "SELECT * FROM efed_list_divisions ORDER BY `name`";
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
           
            print '<table width="100%" class="table1">';
            print '<tr class="rowheading">';
            print '<td>&nbsp;</td>';
            print '<td>Name</td>';
            print '</tr>';
         // Fetch and print all records.
         $i = 0;
         $current_row = 0;
         while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) )
         { 
            $current_row++; 
             $sClass = 'row2';
             if ($i ++ & 1)
             {
                 $sClass = 'row1';
             }
             printf ( "<tr class=\"%s\">", $sClass );
             print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>";
              printf ( "<td valign=\"top\">%s</td>", $row [name] );
             print '</tr>';
         }
         print '</table>';
     }
     else
     {
     print '<span>There are no divisions.</span><br />';
     }
     print '<br />';
returnmain();
}
} elseif ( $option == 1)
{
    print '<h1 class=backstage>Division Management</h1><br />';
    print '<h2 class=backstage>Add New Division</h2><br />';
    print '<form name="adddivision" method="post" action="backstage.php" id="adddivision">';
    print '<table width="100%" class="table2">';
    print '<tr>';
    print '<td width=120 class=rowheading valign=center>Division Name:</td><td class=row3><input type=text name=divisionname class=fieldtext490></td>';
    print '</tr>';
    print '</table><br />';
    print '<input type="submit" value="Save Division" class="button" name="adddivision"></form><br />';
    print '<form method=POST><input type=hidden name=action value=division><input type=submit value="Return to Division List" class=button200></form><br />';
    print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>';
 
} elseif ( $option == 2)
{
    print'<h1 class="backstage">Division Management</h1><br />';
    print'<h2 class="backstage">Edit Division</h2><br />';
    print'<form name="editdivision" method="post" action="backstage.php" id="editdivision">';
    print'<table width="100%" class="table2">';
    print'<tr>';
    print'<td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="division" class="fieldtext490" value=""></td>';
    print'</tr>';
    print'</table><br />';
    print'<center>';
    print'<input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br />';
    print'<input type="submit" value="Edit Division" class=button name="editdivision"><br /><br />';
    print'<input type="button" value="Return to Divisions List" class="button200"><br /><br />';
    returnmain();
 
}
?>

Code: Select all

var loadedobjects=""
var rootdomain="http://"+window.location.hostname
 
function ajaxpage(url, containerid)
{
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject)
    {
        // if IE
        try
        {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e)
        {
            try
            {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e)
            {
            }
        }
    }
    else
    {
        return false
    }
 
    page_request.onreadystatechange=function()
    {
        loadpage(page_request, containerid)
    }
 
    page_request.open('GET', url, true)
    page_request.send(null)
}
 
function loadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
}
 
function loadobjs()
{
    if (!document.getElementById)
    return
    for (i=0; i<arguments.length; i++)
    {
        var file=arguments[i]
        var fileref=""
        if (loadedobjects.indexOf(file)==-1)
        { 
            //Check to see if this object has not already been added to page before proceeding
            if (file.indexOf(".js")!=-1)
            {
                //If object is a js file
                fileref=document.createElement('script')
                fileref.setAttribute("type","text/javascript");
                fileref.setAttribute("src", file);
            }
            else if (file.indexOf(".css")!=-1)
            {
                //If object is a css file
                fileref=document.createElement("link")
                fileref.setAttribute("rel", "stylesheet");
                fileref.setAttribute("type", "text/css");
                fileref.setAttribute("href", file);
            }
        }
        if (fileref!="")
        {
            document.getElementsByTagName("head").item(0).appendChild(fileref)
            loadedobjects+=file+" " //Remember this object as being already added to page
        }
    }
}

Re: Blocks of coding

Posted: Mon Nov 30, 2009 8:10 pm
by daedalus__
have you disabled error messages?

you enclosed every line of code except for the top two in the first if statement in { }

why?

also you are mixing xmlhttp requests with forms. like you are trying to use xmlhttp requests for a front controller or something. if you are going to have a page that uses ajax for half its requests then forms for the other half i dont understand the point of using ajax in the first place.

where is $option defined? how is it passed to the php script?

when you call ajaxpage here:

Code: Select all

 
<a href=\"#\" onclick=\"ajaxpage('division', '1'); return false;\">
 
you are passing the url 'division' and container '1'. is there a container with the id 1? does the url division exist?

Code: Select all

 
print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>";
 
you are passing three parameters to a function that only requires two parameters.

you are utilizing xmlhttp requests poorly and im wondering if you fully understand the concept.

imagine that your xmlhttp object is a little web browser, you tell it to load 'divisions.php', the server processes the .php page and returns the same text to xmlhttp object that it would return to your web browser.

so you would have to say something like

Code: Select all

 
ajaxpage('divisions.php?option=1', 'content');
 
then in divisions.php

Code: Select all

 
$option = $_GET['option'];
 
if ($option == 1)
{...
..etc...
..}
 
then divisions.php would return whatever text the script output to your xmlhttp object and you would append it to or replace the content div or whatever.

you should probably read some more tutorials about ajax.

Re: Blocks of coding

Posted: Mon Nov 30, 2009 8:32 pm
by CoolAsCarlito
Didn't work. Let me post some of my other scripts so you understand how I'm doing things.

backstage.php (main file)

Code: Select all

<?php
    ob_start("ob_gzhandler");  // cache system
 
    require "backstageconfig.php";
    require "backstagefunctions.php";
 
    if ((!empty($_POST)) && (isset($_POST['action']))) 
    {
        $action=$_POST{'action'};
    } 
    else
    {
        $action="mainmenu";
    }
 
    if ((isset($_POST['uname'])) && (isset($_POST['pword'])))
    {
        $uname=$_POST{'uname'};
        $pword=md5($_POST{'pword'});
        validate($fedid, $uname, $pword, 0, 0, $cookiedomain, $cookiepath, $admincssfile);
        $action="mainmenu";
    }
    elseif ((!(isset($_COOKIE['uname']))) && (!(isset($_COOKIE['pword']))))
    {
        require_once "backstage_libs/login.php";
        login($admincssfile,$fed,$url);
    }
    else
    {
        $uname=$_COOKIE["uname"];
        $pword=$_COOKIE["pword"];
        validate($fedid, $uname, $pword, 0, 0, $cookiedomain, $cookiepath, $admincssfile);
 
        if (isset($_POST['newdefaultcharacterid']))
        {
            $newdefaultcharacterid = (integer)$_POST["newdefaultcharacterid"];
            $query = "UPDATE
                    efed_handler
                SET
                    default_char_id = '$newdefaultcharacterid'
                WHERE
                    login = '$uname' and
                    fed_id = '$fedid'"; 
            mysql_db_query($dbname, $query) or Die (mysql_error());
        }
    }
 
    $query = "SELECT
            h.id as userid,
            h.surname as surname,
            h.firstname as firstname,
            h.isadmin as isadmin,
            newscat.id as defaultcategoryid,
            bio.id as defaultcharacterid,
            bio.style_id as styleid,
            bio.username as defaultcharacterusername,
            bio.charactername as defaultcharactername,
            styles.name as style
        FROM
            efed_handler as h
        LEFT JOIN
            efed_bio as bio
        ON
            (
                h.default_char_id = bio.id and
                bio.fed_id = '$fedid'
            )
        LEFT JOIN
            efed_list_styles as styles
        ON
            (
                bio.style_id = styles.id and
                bio.fed_id = '$fedid'
            )
        LEFT JOIN
            efed_list_newscategory as newscat
        ON
            (
                h.default_news_id = newscat.id and
                newscat.fed_id = '$fedid'
            )
        WHERE
            h.login = '$uname' and
            h.password = '$pword' and
            h.fed_id = '$fedid'"; 
    $result = mysql_query ($query); 
    while ($row = mysql_fetch_assoc($result)) 
    {
        $fieldarray=array('userid','surname','firstname','isadmin','defaultcharacterid','defaultcharacterusername','defaultcharactername','defaultcategoryid','styleid','username','style','charactername');
        foreach ($fieldarray as $fieldlabel)
        {
            if (isset($row[$fieldlabel])) 
            { 
                $$fieldlabel=$row[$fieldlabel];
                $$fieldlabel=cleanquerydata($$fieldlabel);
            }
        }
    }
 
    if ($action != "logout")
    {
        headercode($fedid,$admincssfile,$userid,$isadmin,$defaultcharacterid,$defaultcharacterusername,$defaultcharactername,$surname,$firstname,$action,$dirpath,$folder,$headshot,$bioheadheight,$bioheadwidth,$surname,$firstname,$forums);
    }
    else
    {
        headercode($fedid,$admincssfile,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
    }
    // print "<center>\n";
 
    switch ($action)    
    {
        case "mainmenu":
            mainscreen();
            print "</div>\n";
            footercode();
            break;
 
        case "login":
            require_once "backstage_libs/login.php";
            login($admincssfile,$fed,$url);
            break;
 
        case "handler":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/handler.php";
                handler($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$ip); 
            }
            break;
 
        case "character":
            require_once "backstage_libs/character.php";
            character($fedid,$uname,$pword,$userid,$dirpath,$isadmin,$admincssfile,$dbname,$sortorderarray,$iframe,$defaultcharacterid,$styleid,$defaultcharacterusername,$heatmetersenabled,$heatmeters);
            break;
 
        case "newscategory":
            if ($isadmin == "1") 
            {
                require_once "backstage_libs/newscategory.php";
                newscategory($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$targetarray); 
            }
            break;
 
        case "news":
            require_once "backstage_libs/news.php";
            news($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$defaultcategoryid,$ip,$defaultcharacterid,$defaultcharactername);
            break;
 
        case "content":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/content.php";
                content($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "template":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/template.php";
                template($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "biolayout":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/biolayout.php";
                biolayout($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "quotes":
            require_once "backstage_libs/quotes.php";
            quotes($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$defaultcharacterid,$defaultcharactername);
            break;
 
        case "alliesrivals":
            require_once "backstage_libs/alliesrivals.php";
            alliesrivals($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$numalliesrivals,$defaultcharacterid,$defaultcharactername,$defaultcharacterusername);
            break;
 
        case "roleplay":
            require_once "backstage_libs/roleplay.php";
            roleplay($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$defaultcharacterid,$defaultcharactername);
            break;
 
        case "champions":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/champions.php";
                champions($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "title":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/title.php";
                title($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "titlehistory":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/titlehistory.php";
                titlehistory($uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "division":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/division.php";
                division($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
 
        case "eventname":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/eventname.php";
                eventname($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname); 
            }
            break;
        
        case "matchtypes":
            if ($isadmin == "1") 
            {
                require_once "backstage_libs/matchtypes.php";
                matchtypes($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$url);
            }
            break;    
 
        case "eventbooker":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/eventbooker.php";
                eventbooker($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot); 
            }
            break;
 
        case "submitmatch":
            require_once "backstage_libs/submitmatch.php";
            submitmatch($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot);
            break;
 
        case "submitseg":
            require_once "backstage_libs/submitseg.php";
            submitseg($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot);
            break;
 
        case "resultscompilation":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/resultscompilation.php";
                resultscompilation($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot); 
            }
            break;
 
        case "resultsediting":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/resultsediting.php";
                resultsediting($uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot,$url); 
            }
            break;
 
        case "menustructures":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/menustructures.php";
                menustructures($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$headshot,$url); 
            }
            break;
 
        case "arenas":
            if ($isadmin == "1") 
            { 
                require_once "backstage_libs/arenas.php";
                arenas($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$url); 
            }
            break;
 
        case "manageapplications":
            if ($isadmin == "1") 
            {
                require_once "backstage_libs/manageapplications.php";
                manageapplications($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$url);
            }
            break;
            
        case "directory":
            if ($isadmin == "1") 
            {
                require_once "backstage_libs/directory.php";
                directory($fedid,$uname,$pword,$userid,$isadmin,$admincssfile,$dbname,$dirpath,$url);
            }
            break;            
            
        case "logout":
            SetCookie ("uname", "");
            SetCookie ("pword", "");
            require_once "backstage_libs/login.php";
            login($admincssfile,$fed,$url);
            break;
 
        default:
            print "Default Screen<br />";
            footercode();
            break;
    }
    exit;
?>
And then the only other part you really need to see that is important to figuring out my issue is the function headercode.

Code: Select all

function headercode($fedid,$admincssfile,$userid,$isadmin,$defaultcharacterid,$defaultcharacterusername,$defaultcharactername,$surname,$firstname,$action,$dirpath,$folder,$headshot,$bioheadheight,$bioheadwidth,$surname,$firstname,$forums)
{
    if (isset($_POST['option'])) { $option=$_POST['option']; }
 
    // print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 
    print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n";
    print "\"http://www.w3.org/TR/html4/loose.dtd\">\n";
    print "<html>\n";
    print "<head>\n";
    print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
    print "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n";
    print "<meta http-equiv=\"Content-Language\" content=\"en-us\">\n";
    print "<meta name=\"language\" content=\"en-us\">\n";
    print "<title>Backstage V2 Administration Console</title>\n";
 
    print "<link rel=\"stylesheet\" href=\"".$admincssfile."\" type=\"text/css\" media=\"screen\">\n";
    $admincssfile = str_replace(".css", "_print.css", "$admincssfile");
    print "<link rel=\"stylesheet\" href=\"".$admincssfile."\" type=\"text/css\" media=\"print\">\n";
 
    print "<script src=\"/jscripts/scriptaculous/prototype.js\" type=\"text/javascript\"></script>\n";
    print "<script src=\"/jscripts/scriptaculous/scriptaculous.js\" type=\"text/javascript\"></script>\n";
    print "<script type=\"text/javascript\" src=\"./jscripts/ajax.js\"></script>\n";
 
    print "</head>\n";
    print "<body>\n";
    print "<div id=container>\n";
    print "<div class=header>";
    print "<form method=POST name=changedefaultcharacter>\n";
    print "<input type=hidden name=action value=mainmenu>\n";
    print "<input type=hidden name=newdefaultcharacterid value=0>\n";
    print "</form>\n";
 
    print "<script type=\"text/javascript\" language=\"javascript\">\n"; 
    print "function executeformchangedefaultcharacter(newdefaultcharacterid) {\n";
    print "document.changedefaultcharacter.newdefaultcharacterid.value = newdefaultcharacterid;\n";
    print "document.changedefaultcharacter.submit();\n";
    print "}\n";
    print "</script>\n";
 
    if ((isset($userid)) && ($userid > "0"))
    {
        print "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"95%\">\n";
        print "<tr>\n";
        if ($defaultcharacterid > "0")
        {
            if (file_exists("$dirpath/backstage_rosterheadshot.php"))
            {
                print "<td width=".($bioheadwidth+10)." align=center><a target=_blank href=".$folder."/bio.php?username=".$defaultcharacterusername."><img src=\"/backstage_rosterheadshot.php?username=".$defaultcharacterusername."\" border=0  hspace=5 vspace=5 /></a></td>\n";         
            }
            elseif (file_exists("$dirpath$headshot/$defaultcharacterusername.jpg"))
            {
                print "<td width=".($bioheadwidth+10)." align=center><a target=_blank href=".$folder."/bio.php?username=".$defaultcharacterusername."><img src=".$headshot."/".$defaultcharacterusername.".jpg border=0 hspace=5 vspace=5 /></a></td>\n";
            }
            elseif (file_exists("$dirpath$headshot/$defaultcharacterusername.gif"))
            {
                print "<td width=".($bioheadwidth+10)." align=center><a target=_blank href=".$folder."/bio.php?username=".$defaultcharacterusername."><img src=".$headshot."/".$defaultcharacterusername.".gif border=0 hspace=5 vspace=5 /></a></td>\n";
            }
            else
            {
                print "<td width=".($bioheadwidth+10)." align=center><a target=_blank href=".$folder."/bio.php?username=".$defaultcharacterusername."><img src=".$headshot."/default.jpg border=0 hspace=5 vspace=5 /></a></td>\n";
            }
        }
        else
        {
                print "<td width=".($bioheadwidth+10)." align=center><img src=".$headshot."/default.jpg border=0 hspace=5 vspace=5 /></td>\n";
        }
 
        if ($isadmin == "1")
        {
            $query = "SELECT
                    bio.id
                FROM
                    efed_bio as bio
                WHERE
                    bio.fed_id = '$fedid'"; 
            $result = mysql_query ($query); 
            $totalnumcharacters = mysql_num_rows($result);
    
            $query = "SELECT
                    c.id
                FROM
                    efed_handler_characters as c
                INNER JOIN
                    efed_handler as h
                ON
                    (
                        h.id = c.handler_id
                    )
                WHERE
                    h.fed_id = '$fedid'"; 
        }
        else
        {   
            $query = "SELECT
                    c.id
                FROM
                    efed_handler_characters as c
                INNER JOIN
                    efed_handler as h
                ON
                    (
                        h.id = c.handler_id
                    )
                WHERE
                    h.id = '$userid' and
                    h.fed_id = '$fedid'"; 
        }
        $result = mysql_query ($query); 
        $numavailablecharacters = mysql_num_rows($result);
        if (($numavailablecharacters > "1") || (($isadmin == "1") && (isset($totalnumcharacters)) && ($totalnumcharacters > "0")))
        {
            print "<td>";
            print "<form method=POST name=changecharacter>\n";
            print "<select name=newdefaultcharacterid class=dropdown onChange=\"executeformchangedefaultcharacter(document.changecharacter.newdefaultcharacterid.value);\">";
 
            if ($defaultcharacterid > "0")
            {
                print "<option value=".$defaultcharacterid.">".$defaultcharactername;
            }
            else
            {
                print "<option value=0>- Select -";
            }
 
            if ($isadmin == "1")
            {
                $query = "SELECT
                        bio.id as getcharacterid,
                        bio.charactername as getcharacter
                    FROM
                        efed_bio as bio
                    WHERE
                        bio.id <> '$defaultcharacterid' and
                        bio.status_id = '1' and
                        bio.fed_id = '$fedid'
                    ORDER BY
                        bio.charactername"; 
            }
            else
            {
                $query = "SELECT
                        bio.id as getcharacterid,
                        bio.charactername as getcharacter
                    FROM
                        efed_bio as bio
                    INNER JOIN
                        efed_handler_characters as c
                    ON
                        (
                            bio.id = c.bio_id                       
                        )
                    INNER JOIN
                        efed_handler as h
                    ON
                        (
                            h.id = c.handler_id
                        )
                    WHERE
                        h.id = '$userid' and
                        c.bio_id <> '$defaultcharacterid' and
                        bio.status_id = '1' and
                        bio.fed_id = '$fedid' and
                        h.fed_id = '$fedid'
                    ORDER BY
                        bio.charactername"; 
            }
            $result = mysql_query ($query); 
            $numrows = mysql_num_rows ($result);
            if ($numrows > 0)
            {
                if ($isadmin == "1")
                {
                    print "<option value=0>** Active Characters **";
                }
 
                while ($row = mysql_fetch_assoc($result))
                {
                    $fieldarray=array('getcharacterid','getcharacter');
                    foreach ($fieldarray as $fieldlabel)
                    {
                        if (isset($row[$fieldlabel])) 
                        { 
                            $$fieldlabel=$row[$fieldlabel];
                            $$fieldlabel=cleanquerydata($$fieldlabel);
                        }
                    }
                    print "<option value=".$getcharacterid.">".$getcharacter;
                }
            }
 
            if ($isadmin == "1")
            {
                $query = "SELECT
                        bio.id as getcharacterid,
                        bio.charactername as getcharacter
                    FROM
                        efed_bio as bio
                    WHERE
                        bio.id <> '$defaultcharacterid' and
                        bio.status_id = '2' and
                        bio.fed_id = '$fedid'
                    ORDER BY
                        bio.charactername"; 
            }
            else
            {
                $query = "SELECT
                        bio.id as getcharacterid,
                        bio.charactername as getcharacter
                    FROM
                        efed_bio as bio
                    INNER JOIN
                        efed_handler_characters as c
                    ON
                        (
                            bio.id = c.bio_id                       
                        )
                    INNER JOIN
                        efed_handler as h
                    ON
                        (
                            h.id = c.handler_id
                        )
                    WHERE
                        h.id = '$userid' and
                        c.bio_id <> '$defaultcharacterid' and
                        bio.status_id = '2' and
                        bio.fed_id = '$fedid'
                    ORDER BY
                        bio.charactername"; 
            }
            $result = mysql_query ($query); 
            $numrows = mysql_num_rows($result);
            if ($numrows > "0")
            {
                print "<option value=0>** Inactive Characters **";  
                while ($row = mysql_fetch_assoc($result))
                {
                    $fieldarray=array('getcharacterid','getcharacter');
                    foreach ($fieldarray as $fieldlabel)
                    {
                        if (isset($row[$fieldlabel])) 
                        { 
                            $$fieldlabel=$row[$fieldlabel];
                            $$fieldlabel=cleanquerydata($$fieldlabel);
                        }
                    }
                    print "<option value=".$getcharacterid.">".$getcharacter;
                }
            }
            print "</select>\n";
            print "</form>\n";
            print "</td>\n";
        }
        else
        {
            print "<td>".$defaultcharactername."</td>\n";
        }
 
        print "<td width=40% valign=bottom align=right>\n";
        print "<a href=\"#\" onClick=\"executeform('mainmenu','0');\">Home</a> | ";
        print "<a href=\"#\" onClick=\"executeform('logout','0');\">Logout</a> | ";
        print "<a target=\"_blank\" href=\"http://www.gcwonline.net/forums\">Forums</a> | ";
        print "<a target=\"_blank\" href=\"http://www.gcwonline.net/writing\">Writing Guide</a>";
        print "</td>\n";
        print "</tr>\n";
        print "</table>\n";
        print "</div>\n";
 
        print "<div id=container2>\n";
 
        print "<div id=nav>";
        print "<form method=POST name=mainmenu>\n";
        print "<input type=hidden name=action value=0>\n";
        print "<input type=hidden name=option value=0>\n";
        print "</form>\n";
 
        print "<script type=\"text/javascript\" language=\"javascript\">\n"; 
        print "function executeform(action,option) {\n";
        print "document.mainmenu.action.value = action;\n";
        print "document.mainmenu.option.value = option;\n";
        print "document.mainmenu.submit();\n";
        print "}\n";
        print "</script>\n";
 
        if ((isset($userid)) && ($userid > "0") && ($defaultcharacterid > "0"))
        {
            print "<h1>Character</h1>\n";
            print "<ul>\n";
            print "<li";
            if (($action == "character") && ((isset($option)) && ($option == "2"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('character','2');\">Bio</a></li>\n";
            print "<li";
            if (($action == "alliesrivals") && ((isset($option)) && ($option == "0"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('alliesrivals','0');\">Allies</a></li>\n";
            print "<li";
            if (($action == "alliesrivals") && ((isset($option)) && ($option == "1"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('alliesrivals','1');\">Rivals</a></li>\n";
            print "<li";
            if ($action == "quotes") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('quotes','0');\">Quotes</a></li>\n";
            print "</ul>\n";
 
            print "<h1>Submit</h1>\n";
            print "<ul>\n";
            print "<li";
            if ($action == "roleplay") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('roleplay','0');\">Roleplay</a></li>\n";
            print "<li";
            if ($action == "news") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('news','0');\">News</a></li>\n";
            print "<li";
            if ($action == "submitmatch") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('submitmatch','0');\">Match</a></li>\n";
            print "<li";
            if ($action == "submitseg") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('submitseg','0');\">Seg</a></li>\n";
            print "</ul>\n";
        }
        
        if ((isset($isadmin)) && ($isadmin == "1"))
        {
            print "<h1>Fed Head</h1>\n";
            print "<ul>\n";
            print "<li";
            if ($action == "directory") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('directory','0');\">Directory</a></li>\n";
        }    
 
        if ((isset($isadmin)) && ($isadmin == "1"))
        {
            print "<h1>Booking</h1>\n";
            print "<ul>\n";
            print "<li";
            if ($action == "champions") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('champions','0');\">Champions</a></li>\n";
            print "<li";
            if ($action == "eventbooker") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('eventbooker','0');\">Booker</a></li>\n";
            print "<li";
            if (($action == "resultscompilation") && ((isset($option)) && ($option == "0"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('resultscompilation','0');\">Compiler</a></li>\n";
            print "<li";
            if (($action == "resultscompilation") && ((isset($option)) && ($option == "1"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('resultscompilation','1');\">Archives</a></li>\n";
            print "</ul>\n";
 
            print "<h1>Fed Admin</h1>\n";
            print "<ul>\n";
            print "<li";
            if ($action == "handler") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('handler','0');\">Handlers</a></li>\n";
            print "<li";
            if (($action == "character") && ((isset($option)) && ($option == "1"))) { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('character','1');\">Characters</a></li>\n";
            print "<li";
            if ($action == "manageapplications") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('manageapplications','0');\">Applications</a></li>\n";
            print "<li";
            if ($action == "eventname") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('eventname','0');\">Event Names</a></li>\n";
            print "<li";
            if ($action == "title") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('title','0');\">Title Names</a></li>\n";
            print "<li";
            if ($action == "division") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('division','0');\">Divisions</a></li>\n";
            print "<li";
            if ($action == "matchtypes") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('matchtypes','0');\">Match Types</a></li>\n";
            print "<li";
            if ($action == "arenas") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('arenas','0');\">Arenas</a></li>\n";
            print "</ul>\n";
 
            print "<h1>Site Admin</h1>\n";
            print "<ul>\n";
            print "<li";
            if ($action == "template") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('template','0');\">Templates</a></li>\n";
            print "<li";
            if ($action == "content") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('content','0');\">Content</a></li>\n";
            print "<li";
            if ($action == "biolayout") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('biolayout','0');\">Bio Configuration</a></li>\n";
            print "<li";
            if ($action == "newscategory") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('newscategory','0');\">News Categories</a></li>\n";
            print "<li";
            if ($action == "menustructures") { print " class=active"; }
            print "><a href=\"#\" onClick=\"executeform('menustructures','0');\">Menus</a></li>\n";
            print "</ul>\n";
        }
        print "</div>\n";
    }
 
    print "<div id=content>\n";
}

Re: Blocks of coding

Posted: Tue Dec 01, 2009 3:43 pm
by CoolAsCarlito
Here's an update on my divisions.php file. However its still not loading the add new form.

Code: Select all

<?php
 
if ($option == 0 )
{
    print '<h1 class=backstage>Division Management</h1><br />';
print "<h2 class=\"backstage\">Divisions :: <a href=\"#\" onclick=\"ajaxpage('backstage_libs/division.php', '1'); return false;\">Add New</a></h2><br />";
  {
  $query = "SELECT * FROM efed_list_divisions";
     $result = mysql_query ( $query ); // Run The Query
     $rows = mysql_num_rows($result);
     if ($rows > 0)
     {
           
            print '<table width="100%" class="table1">';
            print '<tr class="rowheading">';
            print '<td>&nbsp;</td>';
            print '<td>Name</td>';
            print '</tr>';
         // Fetch and print all records.
         $i = 0;
         $current_row = 0;
         while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) )
         { 
            $current_row++; 
             $sClass = 'row2';
             if ($i ++ & 1)
             {
                 $sClass = 'row1';
             }
             printf ( "<tr class=\"%s\">", $sClass );
             print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('backstage_libs/division.php', '2'); return false;\">Edit</a></td>";
              printf ( "<td valign=\"top\">%s</td>", $row [name] );
             print '</tr>';
         }
         print '</table>';
     }
     else
     {
     print '<span>There are no divisions.</span><br />';
     }
     print '<br />';
returnmain();
}
} elseif ( $option == 1)
{
    print '<h1 class=backstage>Division Management</h1><br />';
    print '<h2 class=backstage>Add New Division</h2><br />';
    print '<form name="adddivision" method="post" action="backstage.php" id="adddivision">';
    print '<table width="100%" class="table2">';
    print '<tr>';
    print '<td width=120 class=rowheading valign=center>Division Name:</td><td class=row3><input type=text name=divisionname class=fieldtext490></td>';
    print '</tr>';
    print '</table><br />';
    print '<input type="submit" value="Save Division" class="button" name="adddivision"></form><br />';
    print '<form method=POST><input type=hidden name=action value=division><input type=submit value="Return to Division List" class=button200></form><br />';
    print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>';
 
} elseif ( $option == 2)
{
    print'<h1 class="backstage">Division Management</h1><br />';
    print'<h2 class="backstage">Edit Division</h2><br />';
    print'<form name="editdivision" method="post" action="backstage.php" id="editdivision">';
    print'<table width="100%" class="table2">';
    print'<tr>';
    print'<td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="division" class="fieldtext490" value=""></td>';
    print'</tr>';
    print'</table><br />';
    print'<center>';
    print'<input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br />';
    print'<input type="submit" value="Edit Division" class=button name="editdivision"><br /><br />';
    print'<input type="button" value="Return to Divisions List" class="button200"><br /><br />';
    returnmain();
 
}
?>

Re: Blocks of coding

Posted: Wed Dec 02, 2009 5:08 pm
by CoolAsCarlito
Anybody have any other good suggestions?