View Full Version : forums problems please help
im tring to get other conditions to forums and i got little problem
i copied part of code from forum.php (admincp dir)
any way i have tried to do something like :
$forumid = "3"; // just exsample
$forum = fetch_foruminfo($forumid);
$DB_site->query(fetch_query_sql($forum, 'forum', "WHERE forumid=$forumid"));
and i got this error :
Invalid SQL: UPDATE forum SET
### UPDATE QUERY GENERATED BY fetch_query_sql() ###
forumid = '3',
styleid = '0',
title = 'warcraft privte forum',
description = '',
options = '3783',
displayorder = '1',
daysprune = '30',
newpostemail = '',
newthreademail = '',
parentid = '-1',
parentlist = '3,-1',
password = '',
link = '',
childlist = '3,-1',
depth = '0',
permissions = 'Array',
active = '1',
allowposting = '1',
cancontainthreads = '1',
moderatenewpost = '0',
moderatenewthread = '0',
moderateattach = '0',
allowbbcode = '1',
allowimages = '1',
allowhtml = '0',
allowsmilies = '1',
allowicons = '1',
allowratings = '1',
countposts = '0',
canhavepassword = '0',
indexposts = '0',
styleoverride = '0',
showonforumjump = '0',
warnall = '0'
WHERE forumid=3
mysql error: Unknown column 'depth' in 'field list'
now i cant find depth on forum table on db
on forum.php this query works fine so what might be the problem ?
please help...
Andreas
01-17-2005, 05:09 PM
Well, $forum in forum.php is not initialized using fetch_foruminfo().
Better use
$forum = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum WHERE forumid = " . intval($forumid));
as fetch_foruminfo() will generate extra-keys (like depth, allowbbcode, etc.) in the array.
line 86 :
$forum = fetch_foruminfo($forumid);
and i need this values cuse i want to edit forum settings....
only from other script then f.php
so any other idea ?
Andreas
01-17-2005, 10:15 PM
You are right that forum.php does use fetch_foruminfo(), but array $forum in the handler for do=update consists only of certain keys of this array (defined by the forum constructed in the handler for do=add/edit).
And that's the point: If you use the array returned by fetch_foruminfo() directly it will contain keys that do not exist as columns in table forum, which causes problems in fetch_query_sql() as it will just use all keys in the given array to construct the query.
You are right that forum.php does use fetch_foruminfo(), but array $forum in the handler for do=update consists only of certain keys of this array (defined by the forum constructed in the handler for do=add/edit).
And that's the point: If you use the array returned by fetch_foruminfo() directly it will contain keys that do not exist as columns in table forum, which causes problems in fetch_query_sql() as it will just use all keys in the given array to construct the query.
well this is what i looking for the update and edit
i want to do=edit
its will give me alll forumid=3 options and i will change what i want
and $_Post['do'] = update
same forum.php is doing only from another script
thats why i used fetch_foruminfo() to get the info same as forum.php does
got my point ?
Andreas
01-17-2005, 10:23 PM
Yes, I do understand what you want.
But you can't use the array returned by fetch_foruminfo() as input for fetch_query_sql() directly, as it does contain additional keys :)
What exactly do you want to change?
so how would i get allowbbcode and allowhtml and other ++++ that forum info contains ?
i want to be able to edit this options and to update them
but not from forum.php...?
hmm ok, ill try to explain some more
as part of my next version to my team hack
i want every team to have a privte forum
so i add teamid to forum table
deafult is 0
if teamid = 0 means that forum is regular forum
if teamid !=0 means its privte forum that belong to some team,
now i allredy did most of file edits
so on forum edit via forum.php you wont see forums that their teamid!=0
now im making a script that will make same options to all of forums
that their teamid !=0 so if ill do allow html
its will edit all forums that their teamid !=0
so i made a while loop for update
the only problem atm is to update the info.. same as forum.php does
i copied most of the code from their (the code that used in edit) also readed it few times
and i still cant find the problem. why its not get updated
so i decided to first make a static forum - with out the while loop (forumid : 3)
but on forum i cant update the info...
thats why im tring only to read the info and update it
to the rest i can take care...
Andreas
01-17-2005, 10:58 PM
*** Untested ***
if (!functions_exists('array_intersect_key') {
function array_intersect_key() {
$numArgs = func_num_args();
if (2 <= $numArgs) {
$arrays =& func_get_args();
for ($idx = 0; $idx < $numArgs; $idx++) {
if (! is_array($arrays[$idx])) {
trigger_error('Parameter ' . ($idx+1) . ' is not an array', E_USER_ERROR);
return false;
}
}
foreach ($arrays[0] as $key => $val) {
for ($idx = 1; $idx < $numArgs; $idx++) {
if (! array_key_exists($key, $arrays[$idx])) {
unset($arrays[0][$key]);
}
}
}
return $arrays[0];
}
trigger_error('Not enough parameters; two arrays expected', E_USER_ERROR);
return false;
}
}
$forum = fetch_foruminfo($forumid);
$forum['allowbbcode'] = false;
$forumoptions = convert_array_to_bits(array_intersect_key($forum, $_FORUMOPTIONS), $_FORUMOPTIONS);
$DB_site->query("UPDATE " . TABLE_PREFIX . "forum SET options=$forumoptions WHERE forumid=$forumid");
But I think it is by far easier to just execute a query which directly changes what you want to change:
now im making a script that will make same options to all of forums
that their teamid !=0 so if ill do allow html
its will edit all forums that their teamid !=0
UPDATE forum SET options=options+256 WHERE teamid != 0 AND NOT (options&256)
Don't forget to call build_forum_permissions() afterwards.
hmm
few qustion :
1. what the function array_intersect_key() should do ?
2. why to use
$forumoptions = convert_array_to_bits(array_intersect_key($forum, $_FORUMOPTIONS), $_FORUMOPTIONS);
if you got $options defined from the edit part ?
3. why did you added 256 to options on db ?
btw thank you very much for helping me out
Andreas
01-17-2005, 11:09 PM
1. array_intersect_key() creates the intersect of n arrays, eg. an array containing the values from array1 whose keys are present in all other arrays
2. Well, in an external script you don't have $options ... (or I am completely misunderstanding you)
3. 256 = 9th bit = allow HTML as defined in init.php
ok you got me wrong
i want to do new file f3.php
forumid = 3
so when i click on edit i get all of forum options
same as on forum.php only here forumid is defined
so i copy the things i wanted like
print_yes_no_row($vbphrase['allow_html'], 'options[allowhtml]', $forum['allowhtml']);
print_yes_no_row($vbphrase['allow_bbcode'], 'options[allowbbcode]', $forum['allowbbcode']);
and on save its goes to
$_POST['do'] = 'update'
and on that i got
globalize($_POST, array(
'forumid' => INT,
'private' => INT,
'applypwdtochild' => INT,
'forum',
'options'
));
so $options is defined...
hmm got me now ?
Andreas
01-17-2005, 11:18 PM
Aaaah :)
So actually you are cloning forum.php but restricted to certain forums.
So why do you use $forum = fetch_foruminfo()?
$forum will be defined by the form in add/edit.
can it be that im stupid ?
damnn your right...
thank you very much mate
i will report on progress
damnn i still dont understand how i didnt saw it
thanx
MiZ :)
1 more qustion ...
does build_forum_permissions(); affect all forums ?
cuse after i use the clone script i need to go to my other forums via forum.php
and do edit and update or its wont show them
not on index
and on forumdisplay im getting no premission error...
Andreas
01-17-2005, 11:28 PM
Yes it does affect all forums.
so its ++++ing something up... cuse in order to see other forums i need to do rebuild forum information via Update Counters on admin cp
and idea what might be the problem ?
nvm
build_forum_permissions();
was inside the while loop and thats what ++++ed the things up
thank u very much for help
:)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.