Add UCP Module for Custom Profile Fields

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Fri Feb 28, 2014 12:13 am

Hi John, forgive me but you will have to explain how to do so. Do I need to use phpmyadmin or something? I can access it but have never really used it before.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Fri Feb 28, 2014 5:54 am

Yes use phpmyadmin, select your db and export.
Then you can select the tables and save them to your computer.
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Fri Feb 28, 2014 10:36 am

PM Sent. :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Sat Mar 01, 2014 10:13 am

Thanks, here the results:
ucp_profile_corrado.php

Code: Select all

<?php
/**
*
* @package ucp
* @version $Id: ucp_profile_corrado.php 2014-02-26 22:0:00Z Forumhulp.com $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @package module_install
*/
if (!defined('IN_PHPBB'))
{
   exit;
}

class ucp_profile_corrado
{
    var $u_action;

    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;

        $submit = (isset($_POST['submit'])) ? true : false;
        if ($submit)
        {
            $sql_ary = array(
                'pf_year'       => request_var('year', 1900),
                'pf_production'    => request_var('production', ''),
                'pf_style'        => request_var('style', 0),
                'pf_colour'     => request_var('colour', 0));

            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' 
                    SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
                    WHERE user_id = ' . $user->data['user_id'];
            $db->sql_query($sql);
        }
        
        $sql = 'SELECT pf_year, pf_production, pf_style, pf_colour FROM ' . PROFILE_FIELDS_DATA_TABLE . ' WHERE user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        
        $selectyear = '';
        $sql = 'SELECT p.option_id + 1 AS option_id, p.lang_value, pl.lang_name, pl.lang_explain FROM ' . PROFILE_FIELDS_LANG_TABLE . ' p
                LEFT JOIN ' . PROFILE_FIELDS_TABLE . ' d ON (d.field_id = p.field_id)
                LEFT JOIN ' . LANG_TABLE . ' l ON (l.lang_id = p.lang_id)
                LEFT JOIN ' . PROFILE_LANG_TABLE . ' pl ON (l.lang_id = p.lang_id AND pl.field_id = p.field_id)
                WHERE d.field_name = "year" AND l.lang_iso = "' . $user->data['user_lang'] . '" ORDER BY p.option_id';
        $result = $db->sql_query($sql);
        while ($row1 = $db->sql_fetchrow($result))
        {
            $selected = ($row['pf_year'] == $row1['option_id']) ? ' selected="selected"': '';
            $selectyear .= '<option value="' . $row1['option_id']. '"' . $selected. '>' . $row1['lang_value'] . '</option>'; 
            $year_name = $row1['lang_name'];
            $year_name_explain = $row1['lang_explain'];            
        }

        $sql = 'SELECT pl.lang_name, pl.lang_explain FROM ' . PROFILE_LANG_TABLE . ' pl
                LEFT JOIN ' . PROFILE_FIELDS_TABLE . ' p ON (p.field_id = pl.field_id) 
                LEFT JOIN ' . LANG_TABLE . ' l ON (l.lang_id = pl.lang_id)
                WHERE p.field_name = "production" AND l.lang_iso = "' . $user->data['user_lang'] . '"';
        $result = $db->sql_query($sql);
        $row1 = $db->sql_fetchrow($result);
        $production_name = $row1['lang_name'];
        $production_name_explain = $row1['lang_explain'];            
            
        $selectstyle = '';
        $sql = 'SELECT p.option_id + 1 AS option_id, p.lang_value, pl.lang_name, pl.lang_explain FROM ' . PROFILE_FIELDS_LANG_TABLE . ' p
                LEFT JOIN ' . PROFILE_FIELDS_TABLE . ' d ON (d.field_id = p.field_id)
                LEFT JOIN ' . LANG_TABLE . ' l ON (l.lang_id = p.lang_id)
                LEFT JOIN ' . PROFILE_LANG_TABLE . ' pl ON (l.lang_id = p.lang_id AND pl.field_id = p.field_id)
                WHERE d.field_name = "style" AND l.lang_iso = "' . $user->data['user_lang'] . '" ORDER BY p.option_id';
        $result = $db->sql_query($sql);
        while ($row1 = $db->sql_fetchrow($result))
        {
            $selected = ($row['pf_style'] == $row1['option_id']) ? ' selected="selected"': '';
            $selectstyle .= '<option value="' . $row1['option_id'] . '"' . $selected. '>' . $row1['lang_value'] . '</option>'; 
            $style_name = $row1['lang_name'];
            $style_name_explain = $row1['lang_explain'];            
        }
        
        $colourstyle = '';
        $sql = 'SELECT p.option_id + 1 AS option_id, p.lang_value, pl.lang_name, pl.lang_explain FROM ' . PROFILE_FIELDS_LANG_TABLE . ' p
                LEFT JOIN ' . PROFILE_FIELDS_TABLE . ' d ON (d.field_id = p.field_id)
                LEFT JOIN ' . LANG_TABLE . ' l ON (l.lang_id = p.lang_id)
                LEFT JOIN ' . PROFILE_LANG_TABLE . ' pl ON (l.lang_id = p.lang_id AND pl.field_id = p.field_id)
                WHERE d.field_name = "colour" AND l.lang_iso = "' . $user->data['user_lang'] . '" ORDER BY p.option_id';
        $result = $db->sql_query($sql);
        while ($row1 = $db->sql_fetchrow($result))
        {
            $selected = ($row['pf_colour'] == $row1['option_id']) ? ' selected="selected"': '';
            $colourstyle .= '<option value="' . $row1['option_id'] . '"' . $selected. '>' . $row1['lang_value'] . '</option>'; 
            $colour_name = $row1['lang_name'];
            $colour_name_explain = $row1['lang_explain'];            
        }
        
        $template->assign_vars(array(
            'YEAR'             => $selectyear,
            'YEAR_NAME'        => $year_name,
            'YEAR_NAME_EX'    => $year_name_explain,
            'PRODUCTION'     => $row['pf_production'],
            'PRODUCTION_NAME'    => $production_name,
            'PRODUCTION_NAME_EX'    => $production_name_explain,
            'STYLE'            => $selectstyle,
            'STYLE_NAME'    => $style_name,
            'STYLE_NAME_EX'    => $style_name_explain,
            'COLOUR'        => $colourstyle,
            'COLOUR_NAME'    => $colour_name,
            'COLOUR_NAME_EX'    => $colour_name_explain
            )
        );    
    
    
        // Set desired template
        $this->tpl_name = 'ucp_corrado';
        $this->page_title = 'UCP_CORRADO_' . strtoupper($mode);
    }
}
ucp_corrado.html

Code: Select all

<!-- INCLUDE ucp_header.html -->

<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<script type="text/javascript" src="highslide/highslide.config.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />

<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}>

<h2>{L_TITLE}</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
   <p>{L_PROFILE_INFO_NOTICE}</p>

   <fieldset>
   <!-- IF ERROR --><p class="error">{ERROR}</p><!-- ENDIF -->

<h3>Corrado G60 Details</h3>
<p>These details should reflect the Corrado G60 that you currently use on the road, or off the road if it's your only project/vehicle. <a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here</a> to find <span class="blue"><strong>Year of Manufacture</strong></span> / <span class="green"><strong>Production Number</strong></span></p>

<dl>
<dt><label for="year">{YEAR_NAME}:</label>
<br /><span>{YEAR_NAME_EX}</span></dt>
<dd><select id="year" name="year">{YEAR}</select><!-- &nbsp;<a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here to find Year of Manufacture</a> -->
</dd>
</dl>

<dl>
<dt><label for="production">{PRODUCTION_NAME}:</label>
<br /><span>{PRODUCTION_NAME_EX}</span></dt>
<dd><input id="production" name="production" value="{PRODUCTION}" /></dd>
</dl>

<dl>
<dt><label for="style">{STYLE_NAME}:</label>
<br /><span>{STYLE_NAME_EX}</span></dt>
<dd><select id="style" name="style">{STYLE}</select></dd>
</dl>

<dl>
<dt><label for="colour">{COLOUR_NAME}:</label>
<br /><span>{COLOUR_NAME_EX}</span></dt>
<dd><select id="colour" name="colour">{COLOUR}</select></dd>
</dl>

<dl><strong>Click <a href="http://www.corradog60.com/images/corrado_g60_boot_sticker.png" style="width: 100px; height:66px;" alt="Corrado G60 | Colour Code Sticker" title="Corrado G60 | Colour Code Sticker" class="highslide" onclick="return hs.expand(this, config1 )">HERE</a> to find <span class="red">Colour Code</span> using sticker found on rear panel within boot/trunk.</strong></dl>

   </fieldset>

   <span class="corners-bottom"><span></span></span></div>
</div>

<fieldset class="submit-buttons">
   {S_HIDDEN_FIELDS}<input type="reset" value="{L_RESET}" name="reset" class="button2" />&nbsp; 
   <input type="submit" name="submit" value="{L_SUBMIT}" class="button1" />
   {S_FORM_TOKEN}
</fieldset>
</form>

<!-- INCLUDE ucp_footer.html -->
Why you need the highslide script?
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Sat Mar 01, 2014 7:11 pm

I'll have a go with that right now :) The highslide is for the links that pop up pictures. 8-)

PS: Is there any need for bits like this in the php now?
'pf_year' => request_var('year', 1900),
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Sat Mar 01, 2014 7:33 pm

Good finding, as you are using dropdowns for the yearfield set it to 0.
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Sat Mar 01, 2014 8:17 pm

Like this John?
'pf_year' => request_var('year', 0),

Just managed to add language edits for the title etc, struggled a bit as I had loads of different ucp_corrado.php/ucp_profile_corrado.php files, all with different attempts at this :lol: I've sorted it though and so far it seems to be working ok. Just about to check that the 'Submit' works properly and updates the memberlist with the custom profile fields etc.

While I'm doing that, just another quick one...
If I wanted to add all of the fields again (Duplicates but with _b on the end of the names) for example "year_b", would I be ok to basically copy each find of the field already there "year"
Reason being that some people have two cars that they want to add in their profiles.

I think it's pretty much done now though John, thank you. I'll just test it fully, and the above additions I can probably manage myself.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Sat Mar 01, 2014 8:30 pm

Yes, the 0 stand for the select text in the dropdown.

Delete all language corrado files and keep one.

And yes you can copy the year part en change year tot year_b and add the appropriate template variable.
Think its better to have names for the field so you know what it is for.

Project succeeded.
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Sun Mar 02, 2014 10:10 pm

Great stuff. 8-) Do you know if there is any more old/not needed code in the php John? If not then it's cool, it does the job and works well so far anyway. :D Thanks again, much appreciated.
John P wrote:Project succeeded.
Yep. So if anybody else wants to split any custom profile fields from the 'Profile' tab to a new one for specific custom profile fields, then read from here viewtopic.php?f=71&t=2220591#p13564406 to see how to achieve this. Read carefully all the way to the end of page 3 and you will get this working. Thanks to John for the help.

Neil.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields [SOLVED]

Post by John P » Sun Mar 02, 2014 11:43 pm

Thanks, there Is no more old code not needed anymore.

Have fun!!
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields [SOLVED]

Post by Volksdevil » Thu Mar 06, 2014 5:12 pm

John, just noticed quite an urgent issue.

If I've filled in the fields on the new tab we created and sumbit, everything seems fine.

But if I go to the standard/core 'Profile' tab, and hit submit there...The fields in the New tab we created have all reset/require filling in again. :cry:

Also, I notice that on the standard/core 'Profile' tab, when you visit it, the link is example.com/ucp.php?i=173 and when you press submit, you get the confirmation screen via example.com/ucp.php?i=profile&mode=profile_info
Information

Your profile has been updated.

Return to the User Control Panel
When submitting the New tab we made, there's no confirmation screen, and the page just very quickly reloads.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

cedricthecat
Registered User
Posts: 212
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Add UCP Module for Custom Profile Fields

Post by cedricthecat » Wed Jan 14, 2015 11:01 pm

Hi Neil

Ref the post above - did you get this sorted? (ie the issue of resetting of data)

I've been looking for a solution to pretty much the same problem as you originally had for ages. We have so many CPF's that I needed to split them into a number of pages/tabs in the UCP. I managed to come up with what seemed to be a solution, and created new CPF modules which I was able to tie into new pages, and happily set about doing the html for these, only to find when I tested them, I had the same problem as you finally hit! Basically, with (say) 20 CPF's split over four modules, even if all of these were originally populated, if I edited one on the first page (so CPF's number 1 to 5) then although this edit would be saved, all the other CPF's (6 to 20) would be reset! :evil:

The submission is working OK, and I'm getting confirmation, it just seems as though if a CPF is not on the submitted form, then the system doesn't know how to handle it and thus returns it to default....

Locked

Return to “[3.0.x] MOD Writers Discussion”