vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Create pages for the AdminCP (https://vborg.vbsupport.ru/showthread.php?t=83122)

Dream 06-14-2005 10:00 PM

Create pages for the AdminCP
 
1 Attachment(s)
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.

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: example image

PHP Code:

print_cp_message('This is a control panel message box.'); 

Creating a redirection message: example image

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:
example

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)

Quote:

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 example

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)

Quote:

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 example

PHP Code:

print_input_row('Type your name''inputname'); 

Text area example

PHP Code:

print_textarea_row('This is a textarea row''inputname'); 

Yes / No radios example

PHP Code:

print_yes_no_row('Should I finish this how-to''radioname'); 

Yes / No / other radios example

PHP Code:

print_yes_no_other_row('What you think''inputname''maybe'); 

"Yes" radio example

PHP Code:

print_yes_row('Want it''inputname''nah'0); 

Multiple radios example

PHP Code:

print_radio_row('This is a radio row''inputname', array( 'ya' => 'ya'
'nah' => 'nah' )); 

Select example

PHP Code:

print_select_row('This is a select row''inputname', array(
 
'value1' => 'option1''value2' => 'option2')); 

Single checkbox example

PHP Code:

print_checkbox_row('This is a checkbox row''inputname'); 

Password example

PHP Code:

print_password_row('This is a password row''inputname'); 

Date example

PHP Code:

print_time_row('Date'); 



Other functions to use inside tables:

Description row example

PHP Code:

print_description_row('This is a description row'02'thead'); 

Two cell row example

PHP Code:

print_label_row('Left cell content''Right cell content'); 

Horizontal rule row example

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 example
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...

Marco van Herwaarden 06-15-2005 08:17 AM

Thanks,

Just 1 comment, "ignore_user_abort(true);" is not needed/wanted for most scripts.

Dream 06-15-2005 05:25 PM

Quote:

Originally Posted by MarcoH64
Thanks,

Just 1 comment, "ignore_user_abort(true);" is not needed/wanted for most scripts.

what does it do?

Andreas 06-15-2005 05:36 PM

Quote:

Originally Posted by Dream
what does it do?

http://www.php.net/manual/en/functio...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.)

Ron1n 06-18-2005 04:48 AM

whats the diff between print_cp_message and print_stop_message?

Dream 06-18-2005 05:41 PM

1 Attachment(s)
print_stop_message is just to get an error phrase name as parameter and call print_cp_message

from admincp/adminfunctions.php (3.5 beta 2)

Quote:

Halts execution and shows a message based upon a parsed phrase

After the first parameter, this function can take any number of additional
parameters, in order to replace {1}, {2}, {3},... {n} variable place holders
within the given phrase text. The parsed phrase is then passed to print_cp_message()

Note that a redirect can be performed if CP_REDIRECT is defined with a URL

* phrasename string Name of phrase (from the Error phrase group)
* param_2 string 1st variable replacement {1}
* param_3 string 2nd variable replacement {2}
* param_n string Nth variable replacement {n}

function print_stop_message( phrasename )


these images have nothing to do with this post

Rich 02-14-2006 02:06 PM

Edit: Figured it out.

jim6763nva 02-27-2006 10:12 AM

Dream,

Thank you very much for taking the time to put this tutorial together! This is a huge help to getting started making custom pages for the admincp. Hopefully you will continue adding more information to this.

Kudos! :)

Jim

Antivirus 03-31-2006 10:21 AM

Dream, this is a huge help, thanks! I am stumped however, on how to include 1 or more wysiwyg inputs in an admincp page. I know this is an unusual request, but for my next hack, it's required to enter content this way. Can you add this info to the tutorial please, or possibly write another tutorial dedicated to the wysiwyg?

Reven 03-31-2006 05:40 PM

It's great, but a lot of the links to the example images are being parsed as off-site links, such as http://attachment.php?attachmentid=whatever, instead of https://vborg.vbsupport.ru/attachmen...entid=whatever. Really annoying. Other than that, a great tutorial, which I will surely use at some point.

hangoutforums 04-01-2006 04:29 PM

to view the examples you can just view the attachments at the bottom of dream's post.

This is a really useful tutorial, thanks

antialiasis 05-02-2006 10:16 PM

Does anybody have a guide like this for making Mod CP pages? I'm a bit confused...

melefire 05-20-2006 07:22 PM

thanks, very useful

-=Sniper=- 05-20-2006 08:07 PM

excellent, try to keep it updated :)

rogersnm 05-22-2006 05:18 PM

Hey can anybody answer this?

https://vborg.vbsupport.ru/showthread.php?t=116382

Kirk Y 05-27-2006 03:16 AM

Is it just me, or does adminfunctions.php not exist?

Adrian Schneider 05-27-2006 04:04 AM

Quote:

Originally Posted by acidburn0520
Is it just me, or does adminfunctions.php not exist?

It is in the /includes directory.

Kirk Y 05-27-2006 04:15 PM

Ah-ha! Thanks. Is there some easier way to get the information that Dream got from adminfunctions.php without having to read through all the file's code?

Quarterbore 11-20-2006 02:42 AM

HOW TO ADD CHECK BOXES!

Disclaimer: There may be better ways to do this but I searched quite a bit and finally hacked this together using some basic PHP!

About this example: In this example I am going to work with results from a database query. This is a worst case example (I think) so anybody should be able to figure it out for a simpler case.

Page 1: This is the form that the Admin Adds the data to!

PHP Code:


$cell
[1] = 'This is a Demo!<dfn> Imagine you had a list of options (usergroups perhaps).</dfn>';

        
//Following is an example of data already saved (perhaps called back from a database)
        
$selected_OPTIONS 'Radio|Power Brakes|V8|4x4';

        
//Following is a query to get a list of ALL options that are possible
        
$checkboxs_get mysql_query("
                SELECT option, optionid, display
                FROM " 
TABLE_PREFIX "demo
                ORDER BY display

        //Need to Start to Build the Checkbox DIV
        
$checkbox_options = '<div align="left">';

        //Loop through the Possibilities from the database
       while (
$checkbox = mysql_fetch_array($checkboxs_get))
    {
          //  If the checkbox was selected before, we need to define 
$checkboxselected
          if (in_array(trim(
$checkbox[option]), $selected_types))
         { 
$checkboxselected = "checked=\"checked\""; }

          
// Need to create this option for the checkbox list
          
$checkbox_options .='<input type="checkbox" name="option[]" value="' $checkbox[optionid] . '"' $checkboxselected '>' .  $checkbox[option] . '<br />'
    
          
// Need to clear the $checkboxselected for the next pass!
          
$checkboxselected ='';
    }

        
// Need to Close the Checklist DIV
        
$checkbox_options .='</div>';

$cell[2] = $checkbox_options;

print_cells_row($cell); 

Page Two - This is the page that receives the data!

PHP Code:

foreach($_POST['option'] as $value) {
$selected_options .= $value;
$selected_options .= '|';
}
// From Here you would likely want to save the data in your database!

$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "demo SET options = '$selected_options' WHERE some_field = $something"); 


jerudc 12-14-2006 02:57 PM

you can use can_administer() to check
the following bitfield permissions

[ismoderator] => 1
[cancontrolpanel] => 2
[canadminsettings] => 4
[canadminstyles] => 8
[canadminlanguages] => 16
[canadminforums] => 32
[canadminthreads] => 64
[canadmincalendars] => 128
[canadminusers] => 256
[canadminpermissions] => 512
[canadminfaq] => 1024
[canadminimages] => 2048
[canadminbbcodes] => 4096
[canadmincron] => 8192
[canadminmaintain] => 16384
[canadminupgrade] => 32768
[canadminplugins] => 65536

Naxon 06-26-2007 12:03 PM

ok, Thank's, But how can I save it into the DB and use it on the tamplates? (Like FORUMDISPLAY).

cassis2k 06-27-2007 01:54 PM

excellent, thank's

Mythotical 07-20-2007 04:14 AM

Is there a way to add an image to the right of an input row some how?

Here is my input row:
PHP Code:

print_input_row("Image""image"$sponsors['image'], $htmlise true$size 35$maxlength 100$direction ''$inputclass false); 

This is the code I need to show next to that:
PHP Code:

echo '<tr><td><img src="/sponsors/' $sponsors['image'] . '"></td></tr>'

Thanks
Steve

aggiefan 08-24-2007 11:17 PM

is there a way to restrict a dropdown to one part of the "print_cells_row"?

I'm looking to create a row with a few dropdowns in it...I can't seem to find anywhere where it says you can do that. Looks like you can only stack dropdowns on rows.

foxfirediego 10-24-2007 02:17 PM

first thank you very much for this article.. really handy!!

and some of the link attachment images are broken, check out wich one:
Text area -> attachment.php/?attachmentid=27190
https://vborg.vbsupport.ru/attachmen...chmentid=27190

Yes / No / other radios -> attachment.php/?attachmentid=27275
https://vborg.vbsupport.ru/attachmen...chmentid=27275

"Yes" radio -> attachment.php/?attachmentid=27276
https://vborg.vbsupport.ru/attachmen...chmentid=27276

Multiple radios -> attachment.php/?attachmentid=27273
https://vborg.vbsupport.ru/attachmen...chmentid=27273

Select -> attachment.php/?attachmentid=27189
https://vborg.vbsupport.ru/attachmen...chmentid=27189

Single checkbox -> attachment.php/?attachmentid=27270
https://vborg.vbsupport.ru/attachmen...chmentid=27270

Password -> attachment.php/?attachmentid=27272
https://vborg.vbsupport.ru/attachmen...chmentid=27272

Date -> attachment.php/?attachmentid=27274
https://vborg.vbsupport.ru/attachmen...chmentid=27274

Submit and reset buttons -> attachment.php/?attachmentid=27143
https://vborg.vbsupport.ru/attachmen...chmentid=27143

Dream 10-25-2007 03:05 AM

Thanks, this article is so old I can't remember how to do pages for the admincp anymore :P

j/k, but I have no intention of updating the images. they should be in this thread somewhere.

foxfirediego 10-25-2007 11:09 AM

Ok, sorry for that...
also, just for those that wonder, here is the code for hidden fields:
PHP Code:

construct_hidden_code('hiddeninputname'$variable); 


Dream 11-17-2007 10:14 AM

No problem, glad it was of help.

Anyone can take this article and redo it, add more info and repost it if they want. I won't be updating it.

WhaLberg 11-17-2007 10:27 AM

Quote:

PHP Code:

print_description_row('This is a description row'02'thead'); 


Just an additional note, you can also use this as:
PHP Code:

print_description_row('phrase'12optiontitle); 


vuiveclub 12-04-2007 08:27 AM

Where will the rows INSERT to?

Opserty 12-05-2007 02:53 PM

Quote:

Originally Posted by vuiveclub (Post 1394547)
Where will the rows INSERT to?

They don't insert any where....they just "print" (display) stuff.

Vi3t4Lov3 12-06-2007 01:13 AM

I have a list about 10000 title ...I want to made 20titles/ per ... how can I write it? can you help

Dream 12-06-2007 02:51 AM

sorry I did this two years ago, I don't remember.

Vi3t4Lov3 12-08-2007 02:17 AM

:( anyone can help me ...?

Opserty 12-09-2007 09:50 AM

Quote:

Originally Posted by Vi3t4Lov3 (Post 1397168)
:( anyone can help me ...?

Look in the PHP files that vBulletin does it in you answer will be in them.

ZomgStuff 12-12-2007 02:38 AM

Is there a way to add things to the mod cp?

The-Ensemble 12-25-2007 12:04 AM

Great article I'm going to find this VERY useful for hacks in the future, could you maybe update some of the links the ones to attachment.com dont work anymore.

C Braithwaite 08-22-2008 06:35 PM

awesome guide - really helped me! im sure there is more to learn, but i know exactly which direction to head now!

Vaupell 02-24-2009 05:25 PM

Thank you wery much for this article. :up:

TalkVirginia 03-16-2009 09:24 AM

Is there a function to show a row of 1 or more radio buttons, or do I need to control that manually?


All times are GMT. The time now is 11:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01714 seconds
  • Memory Usage 1,901KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (29)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete