Jump to content

Client Summary - Custom Field


Bertie

Recommended Posts

Hi all,

 

We have created a 'Custom Client Field' which works great and shows up on the "Profile" section of any of the clients. But we would like this specific field to show up on the Client Summary page. On the Clients Information section if possible just under the phone number.

 

What is the best way of doing that if it's possible?

 

Any help will be appreciated.

Link to comment
Share on other sites

We have created a 'Custom Client Field' which works great and shows up on the "Profile" section of any of the clients. But we would like this specific field to show up on the Client Summary page. On the Clients Information section if possible just under the phone number.

What is the best way of doing that if it's possible?

you're in luck - that's one of the few admin pages that uses a template (/admin/templates/blend (or v4)/clientsummary.tpl), so there's no need for an action hook as the profile page already has the custom field information you want...

 

                    <tr><td>{$_ADMINLANG.fields.phonenumber}</td><td>{$clientsdetails.phonenumber}</td></tr>
                   <tr><td>Custom Field</td><td>{$clientsdetails.customfields1}</td></tr>

you might need to throw a {debug} into the template code to find out the specific name of the $clientsdetails variable to use (it's going to be customfieldsX where X is a number), but I think if you only have 1 client custom field, the above should work. :idea:

 

A0ZNXmz.png

Link to comment
Share on other sites

you're in luck - that's one of the few admin pages that uses a template (/admin/templates/blend (or v4)/clientsummary.tpl), so there's no need for an action hook as the profile page already has the custom field information you want...

 

                    <tr><td>{$_ADMINLANG.fields.phonenumber}</td><td>{$clientsdetails.phonenumber}</td></tr>
                   <tr><td>Custom Field</td><td>{$clientsdetails.customfields1}</td></tr>

you might need to throw a {debug} into the template code to find out the specific name of the $clientsdetails variable to use (it's going to be customfieldsX where X is a number), but I think if you only have 1 client custom field, the above should work. :idea:

 

A0ZNXmz.png

 

Thanks, managed to get it working.

 

Is there a way to get that said custom field on the client area but not allowed to be edited by the client? I know the taking the tick out of "admin only" would allow it display on the clients view. But then this field becomes editable by them.

Link to comment
Share on other sites

Is there a way to get that said custom field on the client area but not allowed to be edited by the client? I know the taking the tick out of "admin only" would allow it display on the clients view. But then this field becomes editable by them.

as you say, you could untick the "admin only" checkbox and then in clientareadetails.tpl, change...

 

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.input} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}

to...

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.value} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}

basically, you're just changing $customfield.input to $customfield.value - and that, as the code suggests, just displays the current content of the customfields and doesn't provide the user with an option to edit them.... though you may need to adjust the layout to suit the output.

 

Je4YqmM.png

Link to comment
Share on other sites

  • 2 months later...
Is there a way to edit the "Your Info" box on the clients area to add their client ID? Would be handy to be able to display their client ID on the main page when they are logged in.

you'd have to use an action hook - similar to the one I posted here... and then adjust for wherever you want to add the ID number.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   $client = Menu::context('client');

   if($client->companyname != ""){
       $name = '<strong>'.$client->companyname.'</strong>';
   } else {
   $name = '<strong>'.$client->fullname.'</strong>';
   }
   $address1 = $client->address1;
   if($client->address2 != ""){
       $address2 = '<br>'.$client->address2;
   } else {
       $address2='';
   }
   $city = ' '.$client->city;
   $state = '<br>'.$client->state;
   $postcode = '<br>'.$client->postcode;
   $country = '<br>'.$client->countryname;
   $clientid = '<br>Client Number: '.$client->id;
   $address_new = $name.'<p>'.$address1.$address2.$postcode.$city.$state.$country.$clientid.'</p>';

   if (!is_null($primarySidebar->getChild('Client Details'))) {
                    $primarySidebar->getChild('Client Details')
                                    ->setBodyHtml($address_new);
   }
}); 

Link to comment
Share on other sites

you'd have to use an action hook - similar to the one I posted here... and then adjust for wherever you want to add the ID number.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   $client = Menu::context('client');

   if($client->companyname != ""){
       $name = '<strong>'.$client->companyname.'</strong>';
   } else {
   $name = '<strong>'.$client->fullname.'</strong>';
   }
   $address1 = $client->address1;
   if($client->address2 != ""){
       $address2 = '<br>'.$client->address2;
   } else {
       $address2='';
   }
   $city = ' '.$client->city;
   $state = '<br>'.$client->state;
   $postcode = '<br>'.$client->postcode;
   $country = '<br>'.$client->countryname;
   $clientid = '<br>Client Number: '.$client->id;
   $address_new = $name.'<p>'.$address1.$address2.$postcode.$city.$state.$country.$clientid.'</p>';

   if (!is_null($primarySidebar->getChild('Client Details'))) {
                    $primarySidebar->getChild('Client Details')
                                    ->setBodyHtml($address_new);
   }
}); 

 

Hi,

 

Thanks for that - It works but for some reason the clients full name has now vanished? It's just left the company name, address and the client number. Also there is a gap between the postcode/state line and the country. So now there's a bit of a white gap after the state and then it shows the country.

Edited by Bertie
Link to comment
Share on other sites

Thanks for that - It works but for some reason the clients full name has now vanished? It's just left the company name, address and the client number. Also there is a gap between the postcode/state line and the country. So now there's a bit of a white gap after the state and then it shows the country.

to get the client's name back...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   $client = Menu::context('client');

   if($client->companyname != ""){
       $name = '<strong>'.$client->companyname.'</strong><br><i>'.$client->fullname.'</i>';        
   } else {
   $name = '<strong>'.$client->fullname.'</strong>';
   }
   $address1 = $client->address1;
   if($client->address2 != ""){
       $address2 = '<br>'.$client->address2;
   } else {
       $address2='';
   }
   $city = '<br>'.$client->city;
   $state = ', '.$client->state;
   $postcode = ', '.$client->postcode;
   $country = '<br>'.$client->countryname;
   $clientid = '<br>Client Number: '.$client->id;
   $address_new = $name.'<p>'.$address1.$address2.$city.$state.$postcode.$country.$clientid.'</p>';

   if (!is_null($primarySidebar->getChild('Client Details'))) {
                    $primarySidebar->getChild('Client Details')
                                    ->setBodyHtml($address_new);
   }
}); 

to modify the rest is just a case of changing the output and/or it's order... it should look fairly similar to the default output now though.

Link to comment
Share on other sites

to get the client's name back...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   $client = Menu::context('client');

   if($client->companyname != ""){
       $name = '<strong>'.$client->companyname.'</strong><br><i>'.$client->fullname.'</i>';        
   } else {
   $name = '<strong>'.$client->fullname.'</strong>';
   }
   $address1 = $client->address1;
   if($client->address2 != ""){
       $address2 = '<br>'.$client->address2;
   } else {
       $address2='';
   }
   $city = '<br>'.$client->city;
   $state = ', '.$client->state;
   $postcode = ', '.$client->postcode;
   $country = '<br>'.$client->countryname;
   $clientid = '<br>Client Number: '.$client->id;
   $address_new = $name.'<p>'.$address1.$address2.$city.$state.$postcode.$country.$clientid.'</p>';

   if (!is_null($primarySidebar->getChild('Client Details'))) {
                    $primarySidebar->getChild('Client Details')
                                    ->setBodyHtml($address_new);
   }
}); 

to modify the rest is just a case of changing the output and/or it's order... it should look fairly similar to the default output now though.

 

Hi Brian,

 

Thank you very much - Works great!

Link to comment
Share on other sites

as you say, you could untick the "admin only" checkbox and then in clientareadetails.tpl, change...

 

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.input} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}

to...

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.value} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}

basically, you're just changing $customfield.input to $customfield.value - and that, as the code suggests, just displays the current content of the customfields and doesn't provide the user with an option to edit them.... though you may need to adjust the layout to suit the output.

 

Je4YqmM.png

 

Just trying to adjust this if possible - Basically added another custom field for a mobile number as WHMCS only allow 1 phone number. But with the said code being used, it won't allow the user to be able to edit the mobile number custom field due to the other custom field being non-editable by the client. If someone could put me in the right direction that would be fantastic.

Link to comment
Share on other sites

Just trying to adjust this if possible - Basically added another custom field for a mobile number as WHMCS only allow 1 phone number. But with the said code being used, it won't allow the user to be able to edit the mobile number custom field due to the other custom field being non-editable by the client. If someone could put me in the right direction that would be fantastic.

then you'll need to get the customfield id value for the mobile phone cf and alter the line...

{$customfield.value} {$customfield.description}

to...

{if $customfield.id eq '1'}{$customfield.input}{else}{$customfield.value}{/if} {$customfield.description}

just change the value of '1' to whatever the id value is for your mobile field and that should be editable, the rest should be readonly.

Link to comment
Share on other sites

then you'll need to get the customfield id value for the mobile phone cf and alter the line...

{$customfield.value} {$customfield.description}

to...

{if $customfield.id eq '1'}{$customfield.input}{else}{$customfield.value}{/if} {$customfield.description}

just change the value of '1' to whatever the id value is for your mobile field and that should be editable, the rest should be readonly.

 

Thanks, that works a treat.

 

Thanks again for all of the help with this.

Link to comment
Share on other sites

  • 3 weeks later...

Just noticed this with a client changing their details themselves. The field that can't be edited by them, when they make changes to any of the other fields - It actually wipes the uneditable field from both the client view/admin panel - Is there a way to stop that?

Link to comment
Share on other sites

2 hours ago, Bertie said:

Just noticed this with a client changing their details themselves. The field that can't be edited by them, when they make changes to any of the other fields - It actually wipes the uneditable field from both the client view/admin panel - Is there a way to stop that?

i've just tested this on a v7.3 dev... you're right...damn v7.3... :mad:

https://youtu.be/sPbjPOgRtyA

so i'd forget about using $customfield.value...

On 9/22/2017 at 8:42 AM, Bertie said:

{if $customfield.id eq '1'}{$customfield.input}{else}{$customfield.value}{/if} {$customfield.description}

and try this instead...

{if $customfield.id eq '1'}{$customfield.input}{else}{$customfield.input|replace:'>':' readonly>'}{/if} {$customfield.description}

i've tested this locally, CF#1 would be editable and any other CF will be readonly - the readonly customfields are no longer losing their values when other fields are updated... :idea:

Link to comment
Share on other sites

15 hours ago, brian! said:

i've just tested this on a v7.3 dev... you're right...damn v7.3... :mad:

https://youtu.be/sPbjPOgRtyA

so i'd forget about using $customfield.value...

and try this instead...


{if $customfield.id eq '1'}{$customfield.input}{else}{$customfield.input|replace:'>':' readonly>'}{/if} {$customfield.description}

i've tested this locally, CF#1 would be editable and any other CF will be readonly - the readonly customfields are no longer losing their values when other fields are updated... :idea:

 

Yep, that works great - Thanks again. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated