PDA

View Full Version : Create pages for the AdminCP


Dream
15 Jun 2005, 08:19
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) (http://www.vbulletin.org/forum/showthread.php?t=82698) thread.


Basic AdminCP page code:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------




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 (http://www.vbulletin.org/forum/showpost.php?p=667189&postcount=4).

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



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



(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 (http://www.vbulletin.org/forum/attachment.php?attachmentid=27194)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Creating a redirection message: example image (http://www.vbulletin.org/forum/attachment.php?attachmentid=27195)

In this example the page will be redirected to Google in 10 seconds.


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------






Creating a table: example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27302)

The standard table has 2 columns.



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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 example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27301)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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 example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27142)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Text area example (http://attachment.php?attachmentid=27190)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Yes / No radios example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27144)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Yes / No / other radios example (http://attachment.php?attachmentid=27275)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



"Yes" radio example (http://attachment.php?attachmentid=27276)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Multiple radios example (http://attachment.php?attachmentid=27273)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Select example (http://attachment.php?attachmentid=27189)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Single checkbox example (http://attachment.php?attachmentid=27270)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Password example (http://attachment.php?attachmentid=27272)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Date example (http://attachment.php?attachmentid=27274)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





Other functions to use inside tables:

Description row example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27187)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Two cell row example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27188)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Horizontal rule row example (http://www.vbulletin.org/forum/attachment.php?attachmentid=27271)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Get next alternating row class (alt1/alt2)



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------





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 (http://attachment.php?attachmentid=27143)


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Submit only


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------










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
15 Jun 2005, 10:17
Thanks,

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

Dream
15 Jun 2005, 19:25
Thanks,

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

what does it do?

Andreas
15 Jun 2005, 19:36
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.)

Ron1n
18 Jun 2005, 06:48
whats the diff between print_cp_message and print_stop_message?

Dream
18 Jun 2005, 19:41
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)

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
14 Feb 2006, 16:06
Edit: Figured it out.

jim6763nva
27 Feb 2006, 12:12
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
31 Mar 2006, 12:21
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
31 Mar 2006, 19:40
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 http://www.vbulletin.org/forum/attachment.php?attachmentid=whatever. Really annoying. Other than that, a great tutorial, which I will surely use at some point.

hangoutforums
01 Apr 2006, 18:29
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
03 May 2006, 00:16
Does anybody have a guide like this for making Mod CP pages? I'm a bit confused...

melefire
20 May 2006, 21:22
thanks, very useful

-=Sniper=-
20 May 2006, 22:07
excellent, try to keep it updated :)

rogersnm
22 May 2006, 19:18
Hey can anybody answer this?

http://www.vbulletin.org/forum/showthread.php?t=116382

Kirk Y
27 May 2006, 05:16
Is it just me, or does adminfunctions.php not exist?

Adrian Schneider
27 May 2006, 06:04
Is it just me, or does adminfunctions.php not exist?
It is in the /includes directory.

Kirk Y
27 May 2006, 18:15
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
20 Nov 2006, 04:42
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!



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

jerudc
14 Dec 2006, 16:57
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
26 Jun 2007, 14:03
ok, Thank's, But how can I save it into the DB and use it on the tamplates? (Like FORUMDISPLAY).

cassis2k
27 Jun 2007, 15:54
excellent, thank's

Steve M
20 Jul 2007, 06:14
Is there a way to add an image to the right of an input row some how?

Here is my input row:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Thanks
Steve

aggiefan
25 Aug 2007, 01:17
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
24 Oct 2007, 16:17
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
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27190

Yes / No / other radios -> attachment.php/?attachmentid=27275
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27275

"Yes" radio -> attachment.php/?attachmentid=27276
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27276

Multiple radios -> attachment.php/?attachmentid=27273
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27273

Select -> attachment.php/?attachmentid=27189
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27189

Single checkbox -> attachment.php/?attachmentid=27270
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27270

Password -> attachment.php/?attachmentid=27272
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27272

Date -> attachment.php/?attachmentid=27274
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27274

Submit and reset buttons -> attachment.php/?attachmentid=27143
http://www.vbulletin.org/forum/attachment.php/?attachmentid=27143

Dream
25 Oct 2007, 05:05
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
25 Oct 2007, 13:09
Ok, sorry for that...
also, just for those that wonder, here is the code for hidden fields:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

Dream
17 Nov 2007, 12:14
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
17 Nov 2007, 12:27
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


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


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

vuiveclub
04 Dec 2007, 10:27
Where will the rows INSERT to?

Opserty
05 Dec 2007, 16:53
Where will the rows INSERT to?

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

Vi3t4Lov3
06 Dec 2007, 03:13
I have a list about 10000 title ...I want to made 20titles/ per ... how can I write it? can you help

Dream
06 Dec 2007, 04:51
sorry I did this two years ago, I don't remember.

Vi3t4Lov3
08 Dec 2007, 04:17
:( anyone can help me ...?

Opserty
09 Dec 2007, 11:50
:( anyone can help me ...?

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

ZomgStuff
12 Dec 2007, 04:38
Is there a way to add things to the mod cp?

The-Ensemble
25 Dec 2007, 02:04
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
22 Aug 2008, 20:35
awesome guide - really helped me! im sure there is more to learn, but i know exactly which direction to head now!

Vaupell
24 Feb 2009, 19:25
Thank you wery much for this article. :up:

TalkVirginia
16 Mar 2009, 11:24
Is there a function to show a row of 1 or more radio buttons, or do I need to control that manually?

TalkVirginia
27 Mar 2009, 06:46
how would you handle the formatting of a string with commas? Also how would you word wrap a long label, such as the function print_input_row?

Davidinh
19 Dec 2010, 23:47
i need insert a field for file upload (in admincp custom page)
so, what code do i use (let it show browser button)
it upload into database as blob stype
i already tried print_input_row but it's missing a browser button (unable to load file from computer)

any help or suggestion will be appreciated

Sincerely,

Never mind, i found it from images.php
it uses the code as


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



hope someone needed .... but that for the template in admincp page .... about coding for file upload that it's up to you or you own your way :))