PDA

View Full Version : Can I change a cpnav group phrase by php ?


EquinoxWorld
08-01-2011, 09:23 PM
Hello everyone, I have been trying to figure out how I can change a phrase that belongs to a cpnav subgroup which would be triggered by a click or "save" from the user. Allow me to elaborate...

I have this before:

http://aniworlds.net/gallery/files/2/screencpnav_group.png

When the user goes to contest 1 for the first time and configures the initial options, specifying a name (in this case for example: Signature Of The Week), etc, after clicking "save" at the bottom of the page, I want the "Contest 1" subgroup to change to the name the user specified in said options; like so:

https://vborg.vbsupport.ru/

If anyone has any ideas or information that might be useful please do share your thoughts. Any feedback is good feedback. :) Thanks for your time everyone.

P.S.: FYI I edited the phrase manually this time to show what I wanted .

kh99
08-01-2011, 09:27 PM
How is that menu being created?

EquinoxWorld
08-01-2011, 09:33 PM
How is that menu being created?


By the xml file I created that I included in xml directory in includes .... pardon my redundancy. :)

--------------- Added 1312238087 at 1312238087 ---------------

here you go:

<?xml version="1.0" encoding="ISO-8859-1"?>

<navgroups product="oftw" master="true">

<navgroup text="Conests Of The Week" permissions="" hr="true" displayorder="105">

<navoption displayorder="10">
<phrase>cotw_cpnav_name</phrase>
<link>options.php?dogroup=oftw.options_main</link>
</navoption>

<navoption displayorder="10">
<phrase>cotw_cpnav_contest1</phrase>
<link>options.php?dogroup=oftw.options1</link>
</navoption>


<navoption displayorder="10">
<phrase>cotw_cpnav_contest2</phrase>
<link>options.php?dogroup=oftw.options2</link>
</navoption>


<navoption displayorder="10">
<phrase>cotw_cpnav_contest3</phrase>
<link>options.php?dogroup=oftw.options3</link>
</navoption>



</navgroup>

</navgroups>

--------------- Added 1312238404 at 1312238404 ---------------

if you mean how I changed it that time I did it manually going to phrase manager , etc, etc, for the effects to demonstrate what I wanted to be done but via php user submission not phrase manager.

nhawk
08-01-2011, 09:40 PM
Save the new phrase in the database phrase table.

$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "phrase
SET text = '" . $newtext . "'
WHERE varname = '" . $yourphrasename . "'
");

At least I think that will work. It might not if the xml file is read every time the menu is loaded. I haven't checked.

EquinoxWorld
08-01-2011, 09:57 PM
Save the new phrase in the database phrase table.

$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "phrase
SET text = '" . $newtext . "'
WHERE varname = '" . $yourphrasename . "'
");

At least I think that will work. It might not if the xml file is read every time the menu is loaded. I haven't checked.

I am taking a look at the phrase tables now, didn't think about setting it from the database..what about if they rebuild the bitfields for any reason, as you said if it's in the file would it stay the same??

Testing now... :)

--------------- Added 1312240116 at 1312240116 ---------------

OK well it changed it in the table but not in the actual menu...weird...

I refresh the page and it still says Contest 2

I am using this file to test and I can verify it changes the phrase text because I see it in the SQL table in phpmyadmin.

<?php
require_once('./global.php');


$yourphrasename = 'cotw_cpnav_contest2';

$newtext = 'Avatar Of The Week';


$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "phrase
SET text = '" . $newtext . "'
WHERE varname = '" . $yourphrasename . "'

");

?>

--------------- Added 1312240360 at 1312240360 ---------------

And I can also verify that the phrase changed because I see it in the phrase manager... still same though in the actual menu in admin cp, still reads: Contest 2...

Adrian Schneider
08-01-2011, 10:20 PM
Typically you'd use a "Manage Contests" link, rather than having dynamic navigation (vBulletin wasn't really built for that).

Updating the phrase works (ideally as a translation*) as well.

If you want to do it dynamically, create a new plugin at the admin_index_navigation hook with something like this:

$newnavigation = array();

foreach ($navigation as $grouporder => $groups)
{
foreach ($groups as $groupname => $contents)
{
$newnavigation[$grouporder][$groupname] = array(
'group' => $contents['group'],
'options' => array()
);
foreach ($contents['options'] as $linkorder => $linkinfo)
{
list($text, $link) = each($linkinfo);
if ($groupname == 'Group Name' and $text == 'Old Text')
{
$text = 'New Title';
$link['text'] = $text;
}
$newnavigation[$grouporder][$groupname]['options'][$linkorder][$text] = $link;
}
}
}

$navigation = $newnavigation;I've used "Your Group", "Old Text" and "New Title" as placeholders... you should edit them accordingly. You could also use this method to dynamically add to the navigation depending on what exists in the database.

EquinoxWorld
08-01-2011, 11:46 PM
Typically you'd use a "Manage Contests" link, rather than having dynamic navigation (vBulletin wasn't really built for that).

Updating the phrase works (ideally as a translation*) as well.

If you want to do it dynamically, create a new plugin at the admin_index_navigation hook with something like this:

$newnavigation = array();

foreach ($navigation as $grouporder => $groups)
{
foreach ($groups as $groupname => $contents)
{
$newnavigation[$grouporder][$groupname] = array(
'group' => $contents['group'],
'options' => array()
);
foreach ($contents['options'] as $linkorder => $linkinfo)
{
list($text, $link) = each($linkinfo);
if ($groupname == 'Group Name' and $text == 'Old Text')
{
$text = 'New Title';
$link['text'] = $text;
}
$newnavigation[$grouporder][$groupname]['options'][$linkorder][$text] = $link;
}
}
}

$navigation = $newnavigation;I've used "Your Group", "Old Text" and "New Title" as placeholders... you should edit them accordingly. You could also use this method to dynamically add to the navigation depending on what exists in the database.


Thanks for your replies everyone. I was successful now changing it from the php that nhawk gave ; the only reason it was not working before was because it needed to update the translated field not the actual text ( as suggested by Adrian ).

I created that plug-in although all the subnav options disappear. This is the plugin I used:

$newnavigation = array();

foreach ($navigation as $grouporder => $groups)
{
foreach ($groups as $groupname => $contents)
{
$newnavigation[$grouporder][$groupname] = array(
'group' => $contents['group'],
'options' => array()
);
foreach ($contents['options'] as $linkorder => $linkinfo)
{
list($text, $link) = each($linkinfo);
if ($groupname == 'Contests Of The Week' and $text == 'Contest 2')
{
$text = 'Avatar Of The Week';
$link['text'] = $text;
}
$newnavigation[$grouporder][$groupname]['options'][$linkorder][$text] = $link;
}
}
}

$navigation = $newnavigation

Also Adrian I am very much interested in this navigation , I would much rather have a link to manage contests for example than what I have now, just now quite sure how to go about it just yet. Would you happen to have any source of documentation for this by any chance?

Any help will be appreciated.

Adrian Schneider
08-02-2011, 01:27 AM
I don't have time today to try and get it working again, but that general structure worked for me with a quick test.

You'd just link to contests.php, which pulls a list of templates from the database with view/edit/delete (for example) options. Pretty standard stuff as far as admin pages go. You never see dynamic ones on the left (Style Manager vs. listing each style).

Look through some of the files under the admincp to see what I mean.

Cheers

EquinoxWorld
08-02-2011, 02:24 AM
Ok. I just got done reading this tutorial (https://vborg.vbsupport.ru/showthread.php?t=83122); which is a bit old but apparently still valid for what I want. How about this for what I want to accomplish...
I have this file which is used for one of the contest options for example. If the user has not entered a new name for the contest to "activate" it then he get's the form to enter the name if not he get's the rest of the options. Now with this when the user enters a name and saves the phrase will be changed and the other options would appear. My question would be how do I make the form "submit" button run the SQL commands to change the phrase once the user hit's said button?

Here's my code:

if ($_REQUEST['do'] == 'contest1')
{

if ($vbphrase['cotw_cpnav_contest1'] == 'Contest 1'){

print_cp_header();

print_form_header('cotw');
print_table_header($vbphrase['cotw_cpnav_contest1']);

print_input_row('Enter the name of your contest', 'inputname');

# table rows

print_submit_row("Submit!");

print_cp_footer();
}


else {
print_cp_header();

print_form_header('cotw');
print_table_header($vbphrase['cotw_cpnav_contest1']);

//HERE GOES ALL THE OTHER OPTIONS WHICH I HAVE YET TO PUT///JUST FOR EXAMPLE PURPOSES//
# table rows

print_submit_row("Submit!");

print_cp_footer();
}
}

P.S: Contest 1 is the default text for that phrase. Therefore if the script knows it's the default then it knows that the user has yet to name that contest.