Navigation:  "The Jet Engine" PHP Application Framework > Creating a Jet Engine Application > Required Files >

admin.php

Previous pageReturn to chapter overviewNext page

admin.php

 

This is your admin module.   The main Jet Admin program (also named "admin.php", but in the root directory) will automatically include this file for you.

 

How you structure this file is completely up to you.   Essentially, this is the "brains" of your application's back end.  What the program (admin.php) will do automatically is this:

 

1.It will "include" this file for you.

 

2.It will create a drop-down menu for you based on your menu definition, so that your users can access your functions.

 

3.It will add new inputs to the main configuration settings screen, based on your settings definition, so that your users can access your functions.

 

4.It will initialize your application's admin object by calling "new"

 

5.It will call methods in your admin object that correspond to the "action" parameter sent in the URL parameters

       This means that all you need to do is create methods that match your links.  ie: admin.php?admin=legal&action=sue_me would look for an object method called "sue_me" in the "legal" admin.php module.

 

6.It provides some vehicles for your program to display it's output within it's own (very nice) design.

 

 

An well commented example is given below.   In this example, the initialization procedure branches out and does specific tasks depending on what the "action" was ... "action" being a query string paramater that was specified in the URL or from a form submission. In all cases, we call the admin_output($title,$html) function to display something to the user. This integrates your output into the admin.php design.  You do not need to specify <html> ... <body> .... in your output, just the core output of your function (ie:your forms, messages, etc).  Stylesheets and core javascripts are preloaded for you.   If you need additional style definitions or javascripts, feel free to include those tags with your output as needed.

 

 


 

<?php

 

  class blog {

 

      var $output;

 

      function blog() {

 

          // Put any initializer logic in here.

 

      }

 

 

   // -------------------------------------------------------------------------------

   /*

       "index" -- The default "action".  This is called when no other action is specified.

 

       Typically, use the "index" method to draw your main admin screen.

       In this simple example, we create a left menu listing all of the blog articles

       and on the right side, an iframe that we'll edit the articles in.  This keeps

       everything nicely on the same page.  Visually, it's easy for an end user to

       navigate around and be productive.

   */

   // -------------------------------------------------------------------------------

 

      function index() {

 

          global $config;

          global $oSQL;

          global $SCRIPT_NAME;

 

          // Will appear accross the top of the admin "work area"

          $title = "Blog Admin";

 

          // List Articles

          $SQL = "SELECT * FROM blog_articles ORDER BY post_date DESC";

          $articles = $oSQL->search( array("SQL"=>$SQL) );

 

          $article_list = '';

 

          foreach ( $articles as $article ) {

                 $article_list .= "

                &#183; <a href='$SCRIPT_NAME?admin=blog&action=edit_article&rowid=$article[rowid]' target='main'>$article[title]</a> <br />

             ";

          }

 

          $top_left = "

 

               <fieldset>

                   <legend>Blog Articles</legend>

                   $article_list

               </fieldset>

 

               <a href='$SCRIPT_NAME?admin=blog&action=edit_article' target='main'>Write New Article</a>

 

          ";

 

          $admin_html = "

           

             

 

          ";

 

 

          admin_output( array(

              "title"       => "Blog Admin",

              "html"        => $admin_html,

              "top_left"    => $top_left,

              "bottom_left" => '&nbsp;',

          ));

 

      }

 

 

 

 

   // -------------------------------------------------------------------------------

   // Edit (or create) a specific blog article

   // In this case, a user clicked on a link from the main screen.  As you'll notice

   // all of those links have "edit_article" as their action.  The program automatically

   // calls this function, which very simply draws an edit form.

   // -------------------------------------------------------------------------------

 

      function edit_article( $message ) {

 

            global $SCRIPT_NAME;

            global $oSQL;

            global $jet;

 

            $record = new Record( array("Parent"=>$oSQL, "Table"=>"blog_articles", "Schema"=>"blog_articles", "Lookup"=>1, "rowid"=>$jet->CGI['rowid']) );

 

            // Set a few defaults //

            if ( empty($record->data['post_date']) ) { $record->data['post_date'] = time(); }

            $record->update_values($record->data);

 

            $formarray = $record->generate_form();

 

            $entry_rows = '';

            while ( list ($prompt, $fieldinput) = each ($formarray) ) {

               // If it's the textarea, make it span the row //

               if ( eregi("textarea", $fieldinput) ) {

                   $entry_rows .= "<tr><td colspan='2'>$prompt<br />$fieldinput</td></tr>\n";

               }

               else {

                   $entry_rows .= "<tr><td>$prompt</td><td>$fieldinput</td></tr>\n";

               }

            }

 

            $output = "

 

                <center>

                <form action='$SCRIPT_NAME' method='post'>

                  <table>

                     $entry_rows

                     <tr>

                       <td colspan='2' align='center'>

                         <input type='submit' value='Save Article'>

                         <input type='hidden' name='admin' value='blog' />

                         <input type='hidden' name='action' value='save_article' />

                       </td>

                    </tr>

                  </table>

                </form>

                </center>

 

            ";

           

            admin_output( array(

                  "title"       => "Edit Article",

                  "html"        => $output,

                  "status_bar"  => $message,

            ));

      }

 

 

   // -------------------------------------------------------------------------------

   // Save Blog Article

   // -------------------------------------------------------------------------------

      function save_article() {

 

            global $SCRIPT_NAME;

            global $iSQL;

            global $jet;

 

            $record = new Record( array("Parent"=>$iSQL, "Table"=>"blog_articles", "Schema"=>"blog_articles", "Lookup"=>1, "rowid"=>$jet->CGI['rowid']) );

 

            if ( $record->update_values( $jet->CGI ) ) {

 

               if ( $record->save() ) {

                   

                    $output = "ARTICLE SAVED!";

               }

 

               else {

                    $output = "An error occurred while updating this article: " . $record->error_text;

               }

 

            }

            else {

               $output = "An error occurred while saving this article: " . $record->error_text;

            }

 

            $this->edit_article($output);

 

      }

 

  } // end class

 

 

 

 

      .... other methods elimited from this example to save space.   You get the idea

 

}

 


This help file was created with an unregistered evaluation copy of Help & Manual. © EC Software. All rights reserved. This message will not appear if you compile this help file with the registered version of Help & Manual.