Jump to content

Welcome popup with trick of the day


Remitur

Recommended Posts

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
Link to comment
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

Link to comment
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

 

Link to comment
Share on other sites

  • 2 years later...
  • 4 months later...

One question on this @brian! & @Remitur

The fromMySQLDate($lastlogin just grabs the last login date and time, which is of course "now", when they login - so how can we show the previous login date (i.e. the one before the current one?)

Do we have to use this:

https://github.com/damianharouff/whmcshook-recordlogin/blob/master/ipxcore-addUserIPtoTable.php

 

 

 

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.

×
×
  • 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