Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2011, 09:23 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Can I change a cpnav group phrase by php ?

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:



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:



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 .
Reply With Quote
  #2  
Old 08-01-2011, 09:27 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How is that menu being created?
Reply With Quote
  #3  
Old 08-01-2011, 09:33 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
How is that menu being created?

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

--------------- Added [DATE]1312238087[/DATE] at [TIME]1312238087[/TIME] ---------------

here you go:

PHP Code:
<?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 [DATE]1312238404[/DATE] at [TIME]1312238404[/TIME] ---------------

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.
Reply With Quote
  #4  
Old 08-01-2011, 09:40 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Save the new phrase in the database phrase table.

Code:
$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.
Reply With Quote
  #5  
Old 08-01-2011, 09:57 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
Save the new phrase in the database phrase table.

Code:
$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 [DATE]1312240116[/DATE] at [TIME]1312240116[/TIME] ---------------

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 Code:
<?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 [DATE]1312240360[/DATE] at [TIME]1312240360[/TIME] ---------------

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...
Reply With Quote
  #6  
Old 08-01-2011, 10:20 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

PHP Code:
$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.
Reply With Quote
Благодарность от:
nhawk
  #7  
Old 08-01-2011, 11:46 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
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:

PHP Code:
$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:

PHP Code:
$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.
Reply With Quote
  #8  
Old 08-02-2011, 01:27 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #9  
Old 08-02-2011, 02:24 AM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

PHP 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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:34 AM.


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.10061 seconds
  • Memory Usage 2,305KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (6)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete