Jump to content
Remitur

Welcome popup with trick of the day

Recommended Posts

Posted (edited)

Starting from the code provided by @brian! in this post: 

I realized a pop-up system which shows every time user log-in, but once a day (that's to say: if the user login 5 or more times in a day, the pop-up shows just one time, in order not to annoy him)

The pop-up shows to the user his previous log-in time, and one "trick of the day" (randomly chosen one) 

 

(IMHO, "trick of the day" is a great way to spread knowledge and marketing news without annoying the user)

The code, in form of a hook (note: line #35 is for testing purposes only: remove or comment it):

<?php

//Show modal popup to clients, with a welcome message and a random trick of the day 
//original code by brian! , modified by Remitur

function client_custom_headoutput_hook($vars) {

   $head_return = '';
   $head_return = '<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
   <script>
   $(document).ready(function() {
    
       $(\'#myModal\').appendTo("body");
       function show_modal(){
         $(\'#myModal\').modal();
       }
       window.setTimeout(show_modal, 100);
    
     $(".dismiss").click(function() {});
   });
   </script>';

   return $head_return;
}
add_hook("ClientAreaHeadOutput",1,"client_custom_headoutput_hook");

use Carbon\Carbon;

function client_custom_headeroutput_hook($vars) {

   $client = Menu::context('client');
   $lastlogin = Carbon::parse($client->lastLoginDate);
   $enddate = Carbon::parse($client->lastLoginDate)->addDays(1);
// next line is just for testing purposes: remove it!
   $enddate = Carbon::today();
   $today = Carbon::today();

   $templatefile = $vars['templatefile'];

   if (empty($client->id)) { return; }

   if ($today >= $enddate and $templatefile == "clientareahome") {

       $header_return = '';
       $header_return = '<div class="container">
       <div class="modal fade" id="myModal" role="dialog">
           <div class="modal-dialog modal-md">
               <div class="modal-content">
                   <div class="modal-header">
                       <button type="button" class="close" data-dismiss="modal">×</button>
                       <h4 class="modal-title"><i class="fa fa-thumbs-up fa-lg"></i>  '.Lang::trans('hello').', '.$client->firstname.'</h4>
                       <p>Your last login has been '.$lastlogin.'</p>
                   </div>
                   <div class="modal-body">
                       <p>Trick of the day:</p>
                       <p>'.Lang::trans ('tricks.'.rand(1,13)).'</p>
                   </div>
                   <div class="modal-footer">
                       <button type="button" class="btn btn-primary dismiss" data-dismiss="modal">'.Lang::trans('orderForm.close').'</button>
                   </div>
                   </div>
               </div>
           </div>
       </div>';

       return $header_return;
   }
}
add_hook("ClientAreaHeaderOutput",1,"client_custom_headeroutput_hook");

The tricks are provided as an array of language variables; here there're 13, I guess that 30 is the minimum reasonable number; more is better.

In the tricks you can provide also  internal and external links (just one here for example):

#====================== tricks for popup ============================================
 $_LANG['tricks']['1'] = "On DomainRegister you can register your own .com.br domain even if you have not a headquarter in Brazil";
 $_LANG['tricks']['2'] = "Interface on DomainRegister is available in three different languages (English, Italian and Slovenian): select your preferred one using the flags in the upper right corner ";
 $_LANG['tricks']['3'] = "On DomainRegister you can renew any domain up to 10 years in advance (even those for which a multi-year renewal is not envisaged)";
 $_LANG['tricks']['4'] = "If you manage a large number of domains, on DomainRegister you can create one or more DNS templates, to quickly implement complex DNS configurations for each single domain ";
 $_LANG['tricks']['5'] = "Using wildcard SSL certificates, with a single SSL certificate you can secure both your main domain and an unlimited number of subdomains on any number of different servers";
 $_LANG['tricks']['6'] = "<a href=\"https://domainregister.international/dns-service.php\" target=\"_blank\">DomainRegister's DNS service</a> (which is free for any domain registered through us) got 100% uptime... since 2011!";
 $_LANG['tricks']['7'] = "If you change the data of the registrant of a .com domain, you cannot transfer the domain for 60 days (sixty days lock)";
 $_LANG['tricks']['8'] = "With DomainRegister's Linux Pro hosting plan, you get your own, dedicate european IP for your site";
 $_LANG['tricks']['9'] = "DomainRegister's StarterMail starts with 5 email addresses and 5 GB archive space, and may be expanded up to 25 email addresses and 25 GB archive space; larger solutions are available upon request";
 $_LANG['tricks']['10'] = "Keep your domains and services safe by protecting them with 2FA authentication: on DomainRegister it's free!";
 $_LANG['tricks']['11'] = "trick 11";
 $_LANG['tricks']['12'] = "trick 12";
 $_LANG['tricks']['13'] = "trick 13";
 
 
 

 

Any idea to improve this hook is welcome!

 

 

20190622-screenshot.png

Edited by Remitur

Share this post


Link to post
Share on other sites

Hi Remitur,

20 minutes ago, Remitur said:

Any idea to improve this hook is welcome!

I think $client->lastLoginDay should really be $client->lastLoginDate ... from reference to the docs, I don't think lastLoginDay exists and will therefore always show the time & date of now, and not the actual date the client last logged in (note the login date of the client themselves logging in and not you logging in as admin as them).

also, when outputting that date, you could put it in the clients format by changing...

<p>Your last login has been '.$lastlogin.'</p>

to..

<p>Your last login has been '.fromMySQLDate($lastlogin,true,true).'</p>

I suppose that text, and tricks of the day should be language strings too... other than that, nice job. thanks.png

Share this post


Link to post
Share on other sites
 
 
 
6 hours ago, brian! said:

Hi Remitur,

I think $client->lastLoginDay should really be $client->lastLoginDate ... from reference to the docs, I don't think lastLoginDay exists

You're right!!!!!

Psychology of bug generation: read "Date", write "Day", think "I'll test it later"... 😂

Thank you for the fix, I was able to edit the original post which is now correct

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By MaikelVE
      Hi!
      Does anybody know how I can change this: 
      To this:
      Either via a hook or in what template do I need to look for this? (I'm also using the Lagom theme)
    • By mfoland
      So I'm working with the licensing addon, and attempting to figure out the hook part..
       
      add_hook('LicensingAddonVerify', 1, function($vars) { return [ 'Hash' => 'Hash Here', ]; } ); The hash actually shows in the license how it should, but I'm trying to do it since I make several softwares, and not only one, so what I'm trying to do is something like
      if ($productid == "prodID number") { add_hook('LicensingAddonVerify', 1, function($vars) { return [ 'Hash' => 'Hash Here', ]; } ); } else -- run get different product It doesn't retrieve the product id at all.. What am I missing here? The hash is basically there to tell the system if a new version has been released. 
       
      Thanks
    • By WHMCS Josh
      In the latest release, you may have noticed that the Request Cancellation link in the left sidebar has been removed for free and one time products and services.
      This change was made in response to a bug report relating to one time products not being automatically cancelled. There was some concern that allowing cancellation requests for free and one time items, which have no next due date, and therefore terminate immediately on the following cron run could lead to irrevocable data loss.
      It is important to note that this is only a visual change that removes the link to submit a cancellation request. Submitting a cancellation request for a free service is still possible. If you wish to restore the option to cancel free products, you can do so using a hook.
      I've prepared some sample code that uses the ClientAreaPrimarySidebar hook point to achieve this.
      Here is the code below:
      <?php /** * This hook restores the Request Cancellation sidebar option on free services * * @author WHMCS Josh * @see https://developers.whmcs.com/hooks-reference/client-area-interface/#clientareaprimarysidebar * @see https://developers.whmcs.com/advanced/db-interaction/ */ use WHMCS\Database\Capsule; use WHMCS\View\Menu\Item; add_hook('ClientAreaPrimarySidebar', 1, function($primarySidebar) { // Get the handle for the Service Details Overview sidebar $serviceDetailsOverview = $primarySidebar->getChild('Service Details Overview'); // Make sure the handle is not null if (!is_null($serviceDetailsOverview)) { // Make sure the ID is available if (!empty($_REQUEST['id'])) { $serviceId = (int) $_REQUEST['id']; // Check if this is a free service $billingCycle = Capsule::table('tblhosting') ->where('id', $serviceId) ->value('billingcycle'); if ($billingCycle === 'Free Account') { // Add the cancellation request menu item for the service to the sidebar $serviceDetailsOverview->addChild( 'freeServiceCancellationRequest', [ 'name' => 'CancellationRequest', 'label' => 'Request Cancellation', 'uri' => '/clientarea.php?action=cancel&id=' . $serviceId, 'order' => 90, ] ); } } } }); To install this, you can simply add the code to a file in your /includes/hooks directory such as /includes/hooks/free_product_cancellation_request.php.
      For convenience, I've attached the completed hook file to this post here: free_product_cancellation_requests.php
      Below is also a screenshot of how this looked on my test installation of WHMCS 7.7.0.

      Please note that this is being provided only as an example and is not guaranteed to work with future versions of WHMCS.
      Feel free to modify it to suit your needs and I hope it helps!
    • By Cubeboy
      I need to get rid of the date when I add files on the admin side.
       
      when I upload a file the a clients account in the admin section, it displays in the client area and it time stamps it. how can I remove the time stamp? OR remove the whole hook and add it back with my own var?
       
       
      <?php
      use WHMCS\View\Menu\Item;
      add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
      {
      $homePagePanels->removeChild('your files:dateadded');
      });
    • By sitesme
      Hi
      I need to add a code from a similar tool like Google Analytics into my WHMCS installation.
      I know how to add it in the header files but I was wondering if I could use a hook file to avoid the theme files to be overwritten. If so, could someone give me the exact hook code file syntax so I just add my code there?
      Thank you
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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