PDA

View Full Version : moderate.php


sabret00the
06-07-2004, 07:21 PM
just a quick question, i was just reading the script (as i need to make a moderation script) and i'm left wondering, whehter or not this could've been done so much simpler than it was done by jelsoft?

NTLDR
06-07-2004, 07:27 PM
I guess it depends what your moderating. Personally I don't find moderate.php overly complex.

sabret00the
06-07-2004, 07:41 PM
i just want to take some text in a database and display it, with the options to leave it in the queue, authorise it or delete, i guess my limited knowledge of php is causing problems here, i dunno i just read the script and it seemed to be doing so much more than it needed to

i expected to see;

an if //moderation is on
and a while // to show the data and give the options to moderate it

and that's it really.

NTLDR
06-07-2004, 07:48 PM
You can probably get away with just adding a column to the table called visible and set it to either 1 (visible) or 0 (invisible/hidden) and add that to the where clause on the query.

eg to get all unmoderated items:

SELECT *
FROM tablename
WHERE visible = 0

sabret00the
06-07-2004, 07:51 PM
that''s how i've got the database set up, it's just a matter of getting the page in the admincp to moderate the items, i guess i'll have to stop being lazy and actually learn how to make an admincp page, to think all i need is;

text to moderate | option to approve | option to delete | option to do nothing

that has to be a pretty easy to do :D

sabret00the
07-03-2004, 08:52 PM
i hate the admin cp, it baffles me completely, everything is 20 times harder than coding for vB front end :( i just don't seem to be able to comprehend the coding, well i can kinda, i can read and understand what it's saying in the moderate.php but then it comes to applying that, it's practically impossible :(

* sabret00the goes for a breather before heading back in for round 3

Brad
07-03-2004, 09:00 PM
Just keep at it, the only way to learn is to get your hands dirty. That admin cp will look much harder to code for at first, because their is alot of extra code for html output.

sabret00the
07-04-2004, 12:44 PM
thanks for that, i'll keep at it :)

i think my main problem is how i would've gone about it and how vb went about doing it is so different, so i'm trying to think like someone else would and it's causing problems but i'll persevere(sp:?) :)

assassingod
07-04-2004, 12:51 PM
i hate the admin cp, it baffles me completely, everything is 20 times harder than coding for vB front end :(

That's weird becaues I find coding scripts for the Admin CP so much easier than the front-end. I love coding AdminCP scripts http://www.assassingod.com/images/love.gif

sabret00the
07-04-2004, 02:09 PM
well i strapped on my php hat and dove right in, and it's not proving to be all that hard, bar one line that refuses to work

print_label_row('<b> Posted: By </b>', iif($confession['userid'], "<a href=\"user.php?$session[sessionurl]do=viewuser&userid=$confession[userid]\" target=\"_blank\">$confession[username]</a>", "Anonymous"));


but i think it's cos the username is stored in teh user table and the left join on the confessions table i made for the array hates me, can i do it via a left join for the array or do i need to have that as a seperate query?

sabret00the
07-04-2004, 02:52 PM
one more thing :o

if
print_form_header('confessions_moderate', 'confessions');
sets the form action and name, how would i get the form to post to confessions_moderate.php?do=doconfessions ?

sabret00the
07-04-2004, 08:48 PM
*bump*

Andreas
07-04-2004, 09:09 PM
print_form_header('confessions_moderate', 'doconfessions');

sabret00the
07-04-2004, 09:15 PM
didn't work

Andreas
07-04-2004, 09:30 PM
Can't be ;)

Let's take a look at adminfunctions.php:


function print_form_header($phpscript = '', $do = '', $uploadform = false, $addtable = true, $name = 'cpform', $width = '90%', $target = '', $echobr = true, $method = 'post') {
...
construct_hidden_code('do', $do);
...
}

...

function construct_hidden_code($name, $value = '', $htmlise = 1)
...
$GLOBALS["_HIDDENFIELDS"]["$name"] = iif($htmlise, htmlspecialchars_uni($value), $value);
...
}

...

function print_submit_row($submitname = '', $resetname = '_default_', , $colspan = 2, $goback = '', $extra = '') {
...
print_table_footer($colspan, $tfoot, $tooltip);
}

...

function print_table_footer($colspan = 2, $rowhtml = '', $tooltip = '', $echoform = true) {
...
if ($echoform)
{
print_hidden_fields();
...
}
}

assassingod
07-04-2004, 09:37 PM
FWIW the second parameter in print_form_header should be the filename

sabret00the
07-04-2004, 09:39 PM
print_form_header('confessions_moderate', 'doconfessions', 'confessions');

is giving me

<!-- form started: 5 queries executed -->
<form action="confessions_moderate.php" enctype="multipart/form-data" name="cpform" method="post">
<br />

Andreas
07-04-2004, 09:43 PM
@assassingod
Nope. The 1st parameter should be the filename (without .php) and the 2nd should be the action.

@sabret00the
That's just fine. So where is the problem?

sabret00the
07-04-2004, 09:48 PM
because i want <form action="confessions_moderate.php?do=doconfessions"> :(

Andreas
07-04-2004, 09:51 PM
That's invalid (X)HTML.

The action (script) URL cannot contain parameters.

Why in hell would you need/want that?

sabret00the
07-04-2004, 09:59 PM
why would i want an admin script to be xhtml compliant?

besides surely that's the do as the second parameter in the function definition?

and the reason i would like it is because the form needs to get processed somehow and i got the main script/form as confessions_moderate.php and it has proved to work quicker if i put that part of the processing on another part of the script.

Andreas
07-04-2004, 10:13 PM
> why would i want an admin script to be xhtml compliant?
You want this so that compliant browsers can display the page. If there was a 101% compliant browser it would reject the page as being invalid ;)

> besides surely that's the do as the second parameter in the function definition?
As I said, look at adminfunctions.php.

> and the reason i would like it is because the form needs to get processed somehow
Sure. And where's the problem in processing the form?

File demo.php

<?php
error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);

$phrasegroups = array();
$specialtemplates = array();

require_once('./global.php');

print_cp_header('AdminCP Demo');

if (!$_REQUEST['do']) {
$_REQUEST['do'] = 'showform';
}

if ($_REQUEST['do'] == 'showform') {
print_form_header('demo', 'processform');
print_table_header('Some foobar form');
print_input_row("Name","name","",0,50);
print_submit_row();
}

if ($_REQUEST['do'] == 'processform') {
print_cp_message("Hello $_REQUEST[name]");
}

print_cp_footer();

?>

assassingod
07-05-2004, 05:19 AM
@assassingod
Nope. The 1st parameter should be the filename (without .php) and the 2nd should be the action.

Oops, thanks for correcting me:)

sabret00the
07-05-2004, 06:49 AM
> why would i want an admin script to be xhtml compliant?
You want this so that compliant browsers can display the page. If there was a 101% compliant browser it would reject the page as being invalid ;)

> besides surely that's the do as the second parameter in the function definition?
As I said, look at adminfunctions.php.

> and the reason i would like it is because the form needs to get processed somehow
Sure. And where's the problem in processing the form?

File demo.php

<?php
error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);

$phrasegroups = array();
$specialtemplates = array();

require_once('./global.php');

print_cp_header('AdminCP Demo');

if (!$_REQUEST['do']) {
$_REQUEST['do'] = 'showform';
}

if ($_REQUEST['do'] == 'showform') {
print_form_header('demo', 'processform');
print_table_header('Some foobar form');
print_input_row("Name","name","",0,50);
print_submit_row();
}

if ($_REQUEST['do'] == 'processform') {
print_cp_message("Hello $_REQUEST[name]");
}

print_cp_footer();

?>
sorry kirby i seem to be annoying you but unless i'm reading something wrong

function print_form_header($phpscript = '', $do = '', $uploadform = false, $addtable = true, $name = 'cpform', $width = '90%', $target = '', $echobr = true, $method = 'post')

which would be the same as?
<form action="moderate.php?do=WHATEVER" name="confessions" method="post">

arghh i'm confusing myself it's too early.

basically, am i being told that it's impossible?

Andreas
07-05-2004, 09:05 AM
function print_form_header($phpscript = '', $do = '', $uploadform = false, $addtable = true, $name = 'cpform', $width = '90%', $target = '', $echobr = true, $method = 'post')

when called as

print_form_header('moderate', 'doconfessions');

generates


<form action="moderate.php" name="cpform" method="post">
...
<input type="hidden" name="do" value="doconfessions" />
</form>


> basically, am i being told that it's impossible?
Yes, this is not possible with the standard functions to create CP-forms, although you could do it manually.
But as I already said earlier, this is not needed and AFAIK it's not valid at all.

sabret00the
07-05-2004, 03:29 PM
thanks for your help kirby

sabret00the
07-05-2004, 04:05 PM
yay it's all working fine, my only problem now is this

print_label_row('<b> Posted: By </b>', iif($confession['userid'], "<a href=\"user.php?$session[sessionurl]do=viewuser&userid=$confession[userid]\" target=\"_blank\">$confession[username]</a>", "Anonymous")); well on that script anyway

Andreas
07-05-2004, 04:13 PM
Hmm ... what's the problem with this line (except that it should be &amp; to be XHTML compliant)?

sabret00the
07-05-2004, 04:23 PM
lol well basically it should do this in one line

if ($confession['userid']) {
echo('<a href=\"user.php?$session[sessionurl]do=viewuser&userid=$confession[userid]\" target=\"_blank\">$confession[username]</a>');
} else {
echo('Anonymous');
}

but all that's showing up is anonymous everytime

the query that makes the array is
$confessions=$DB_site->query("
SELECT confessions.confessionid, confessions.text
FROM " . TABLE_PREFIX . "confessions
LEFT JOIN user ON (user.userid = confessions.userid)
WHERE visible=0

while ($confession=$DB_site->fetch_array($confessions)) {

Andreas
07-05-2004, 05:20 PM
And where do you select a userid and username in your query? I can only see confessionid and text ...

sabret00the
07-05-2004, 07:15 PM
it's in the left join :ermm:

Andreas
07-05-2004, 07:33 PM
Nope. You make a join, but you don't select columns from the joined table ;)
If you want username and userid you should do

$confessions=$DB_site->query("
SELECT confessions.confessionid, confessions.text, confessions.userid, user.username
FROM " . TABLE_PREFIX . "confessions AS confessions
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = confessions.userid)
WHERE visible=0

while ($confession=$DB_site->fetch_array($confessions)) {

sabret00the
07-05-2004, 07:42 PM
ahhhh you're right such a stupid mistake

thank you so much, i'm so grateful for the help you've given me with this.