Administration Section Development

Admin Section Development generally follows all the rules of a normal module with a few exceptions.

Firstly, 3 files are required to be there for all admin modules: a case file, a link file, and the module file itself.
Secondly, unlike normal modules, admin modules don't reside in individual directories, they all share the same directory.
Thirdly (and most importantly), there's a whole permissions system that has to be built into each module to stop people who shouldn't have access to them being able to run the scripts anyway.

This section of the guide will tell you the basics that you need to know to write an admin module. I'll cover each of the files, and what needs to be put in them.

The Link file

The link file doesn't contain much code. It is only there, really, to put the link in the admin menu.

The link file must be named links.linkname.php where linkname is the name of the link that you wish to use, and it must reside in the /admin/links directory. Inside the file, the code might look as follows:

<?php

/* Credits go here as usual */

if($radminsuper==1){
    adminmenu("admin.php?op=mainfunction", ""._LINKTEXT."", "image.gif");
}

?>


mainfunction is the name of the main function for your module. It Must be unique to all admin modules, so putting a start on it that reflects the title of your module is a good idea.

$radminsuper is the permission type that you have for the module. In this example, it's the superuser ($radminsuper), but there are other permissions you can add to this too.

The Module

Getting Started

You can name a module file whatever you like. As long as it resides in the /admin/modules directory and is different from the other file names in that directory.

A typical Admin module file might start as follows:

<?php

/* Comments Here as usual */

if(!eregi("admin.php", $_SERVER['PHP_SELF'])){
die("Access Denied...");
}

$result = $db->sql_query("select radminsuper from ".$prefix."_authors where aid='$aid'");
list($radminsuper) = $db->sql_fetchrow($result);
if ($radminsuper==1) {


This code looks in the authors table to see if you've got permissions to access that module (even if the link has allowed access to you). If not, then you don't get to run the functions, if you do however, access to the functions within is allowed

Adding Content to the Admin Module

This is the same as the normal modules. Anything goes - with the following difference.

There's a function you can call to show the Admin menu at the top - GraphicAdmin();

The switch function and it's contents

This, again, is much the same as the normal modules, except that all cases must be unique throughout the entire admin section. This is because of the way the admin file selects which module to run when a certain link is clicked.

The Case File

The case file is the file the admin section looks in when you clck a likn to see what file it's supposed to be pulling code from to run to load the correct page, or perform the correct function.

It's named case.modulename.php where modulename is the name of the module that it relates to, and resides in the /admin/case directory.

Inside this case file, there really only resides a switch function which lists all the cases for hte module, and ends with an include. An example case file switch function would look like this:

switch($op){

    case "mainfunction":
    case "function2":
    case "function3":
    include("admin/modules/modulename.php");

}


The $op variable must be $op throughout the entire admin section. It's how it works.

Languages in the admin section

As I said before, admin modules don't have individual language files, they share a common language file. This is found in the /admin/language directory. If you use this file when you're developing a module that you're going to distribute, make sure you only supply a lang-$language.txt file (not .php file) that has only your definitions in, so people can add these definitions to their files.

You do this because people have different modifications on their web sites, so everybody's language files have different definitions in them. Supplying the definitions in a text file allows them to just add the new ones in without having to search through the supplied one to find what you've added and add it to their own files.