Back to vBulletin 3 Articles

Create pages for the AdminCP
by Dream 15 Jun 2005
Rating: (2 votes - 5.00 average)

I was going to spend some time researching this, so I figured I could help some people save time by writing it down.

This is not a full tutorial, more of a kick-off, and its aimed at developers.


How to add a link to the AdminCP left side navigation:

Please refer to KirbyDE's [How to] Add entries to AdminCP Navigation Menu (in 3.5) thread.


Basic AdminCP page code:

PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
@
set_time_limit(0);
 
// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('style');
$specialtemplates = array('products');
 
// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/adminfunctions_template.php');
 
print_cp_header();
 
 
 
 
 
 
 
 
 
print_cp_footer();
?>

This is the basic code. Its already password protected, so if you create a myscript.php with that code and upload to the "admincp" folder, you can call it from a browser and it will ask for the admin password.

You can use "ignore_user_abort(true);" as described in this post

Spoiler (click to open)


Quote by Dream
what does it do?
http://www.php.net/manual/en/function.ignore-user-abort.php

In other words: If this is set to true the script will continue to run until it's normal end even if the user gets disconnected (network outage, hit stop in browser, etc.)

Close
.

You can use can_administer() to check for admin permissions, 'canadminstyles' in this case:

PHP Code:
 // ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminstyles'))
{
    
print_cp_no_permission();

(gonna add the permissions list here)

(to-do: describe print_cp_header() optional parameters title, onload, headinsert, marginwidth and bodyattributes defined in adminfunctions.php)

You can put anything you like inside the html page. vBulletin has a good number of standard functions that builds the html code for you. These functions can be found in "admincp/adminfunctions.php" (thanks Zero Tolerance for pointing it out). Im going to describe them in this how-to as time lets me.



Creating a message box with a "go back" link:

PHP Code:
print_cp_message('This is a control panel message box.'); 
Creating a redirection message:

In this example the page will be redirected to Google in 10 seconds.
PHP Code:
print_cp_message('This is a control panel message box.''http://google.com'
10); 



Creating a table:


The standard table has 2 columns.

PHP Code:
print_table_start();
 
print_table_header("Table Title");
 
 echo 
'<tr><td class="alt1" colspan="2">table content</td></tr>';
 
 
print_table_footer(2''''0); 
An empty "print_table_footer" adds a "</form>" after closing the table.


Function "print_table_footer" parameters (from adminfunctions.php)

Prints a closing table tag and closes the form tag if it is open

*
colspan integer Column span of the optional table row to be printed
*
rowhtml string If specified, creates an additional table row with this code as its contents
*
tooltip string Tooltip for optional table row
*
echoform boolean Whether or not to close the <form> tag

function print_table_footer( colspan, rowhtml, tooltip, echoform )



Creating a form:

vBulletin has standard functions to build forms. You call "print_form_header()", which opens the form and table tags, call a few functions to build the form inputs, and then close the form with a submit button row.

An empty form

PHP Code:
print_form_header('myscript');
print_table_header('Empty Form');

# table rows

print_submit_row("Submit!"); 
Function "print_form_header" parameters (from adminfunctions.php)

Prints the standard form header, setting target script and action to perform

* phpscript string PHP script to which the form will submit (ommit file suffix)
* do string 'do' action for target script
* uploadform boolean Whether or not to include an encoding type for the form (for file uploads)
* addtable boolean Whether or not to add a <table> to give the form structure
* name string Name for the form - <form name="$name" ... >
* width string Width for the <table> - default = '90%'
* target string Value for 'target' attribute of form
* echobr boolean Whether or not to place a <br /> before the opening form tag
* method string Form method (GET / POST)

function print_form_header( phpscript, do, uploadform, addtable, name, width, target, echobr, method )



Input functions for a table:

Here I'll use common examples, but each function has a set of parameters that should be read in "admincp/adminfunctions.php" if you are going to use them.

Text input

PHP Code:
print_input_row('Type your name''inputname'); 
Text area http://attachment.php?attachmentid=27190

PHP Code:
print_textarea_row('This is a textarea row''inputname'); 
Yes / No radios

PHP Code:
print_yes_no_row('Should I finish this how-to''radioname'); 
Yes / No / other radios http://attachment.php?attachmentid=27275

PHP Code:
print_yes_no_other_row('What you think''inputname''maybe'); 
"Yes" radio http://attachment.php?attachmentid=27276

PHP Code:
print_yes_row('Want it''inputname''nah'0); 
Multiple radios http://attachment.php?attachmentid=27273

PHP Code:
print_radio_row('This is a radio row''inputname', array( 'ya' => 'ya'
'nah' => 'nah' )); 
Select http://attachment.php?attachmentid=27189

PHP Code:
print_select_row('This is a select row''inputname', array(
 
'value1' => 'option1''value2' => 'option2')); 
Single checkbox http://attachment.php?attachmentid=27270

PHP Code:
print_checkbox_row('This is a checkbox row''inputname'); 
Password http://attachment.php?attachmentid=27272

PHP Code:
print_password_row('This is a password row''inputname'); 
Date http://attachment.php?attachmentid=27274

PHP Code:
print_time_row('Date'); 


Other functions to use inside tables:

Description row

PHP Code:
print_description_row('This is a description row'02'thead'); 
Two cell row

PHP Code:
print_label_row('Left cell content''Right cell content'); 
Horizontal rule row

PHP Code:
print_hr_row(); 
Get next alternating row class (alt1/alt2)

PHP Code:
fetch_row_bgclass(); 


Submit / Reset buttons row:


This closes the form and table tags, so you don't have to use "print_table_footer" with it.

Submit and reset buttons http://attachment.php?attachmentid=27143
PHP Code:
print_submit_row("Submit!"); 
Submit only
PHP Code:
print_submit_row("Submit!"0); 




seems I underestimated the ammount of work. should I bother finishing this? gotta work on this more later anyway.

trying to keep the second post for myself... nope automerges

not sure the best formatting... playing around...
Attached Thumbnails
Click image for larger version
Name:	print_input_row.gif
Views:	819
Size:	1.2 KB
ID:	27142   Click image for larger version
Name:	print_submit_row.gif
Views:	407
Size:	2.0 KB
ID:	27143   Click image for larger version
Name:	print_yes_no_row.gif
Views:	512
Size:	1.4 KB
ID:	27144   Click image for larger version
Name:	print_description_row.gif
Views:	644
Size:	2.4 KB
ID:	27187  

Click image for larger version
Name:	print_label_row.gif
Views:	594
Size:	1.1 KB
ID:	27188   Click image for larger version
Name:	print_select_row.gif
Views:	396
Size:	1.5 KB
ID:	27189   Click image for larger version
Name:	print_textarea_row.gif
Views:	443
Size:	2.4 KB
ID:	27190   Click image for larger version
Name:	print_cp_message.gif
Views:	1114
Size:	8.3 KB
ID:	27194  

Click image for larger version
Name:	print_cp_message_redir.gif
Views:	891
Size:	5.2 KB
ID:	27195   Click image for larger version
Name:	table_complete.gif
Views:	408
Size:	3.0 KB
ID:	27197  

Similar Mods

GTCustom Pages - Create Custom Pages With Ease vBulletin 3.5 Add-ons

vblts.ru supports vBulletin®, 2022-2024