We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39184
    • 24 Posts
    @phacer: Thanks for this input. It put me on the right path and after seeing this I'm not sure why I was so stumped on this one. Of course, as with any progress comes another set of obstacles. Since you have had some experience here, at least more than me, I thought I would pose this question and get your thoughts.

    This script in conjunction with my code using the If plugin accomplishes the initial task. However, upon using it I realized that if an an alert was turned on and the user session had not expired or they did not clear their cache then they would not see the alert. So if a parent visited the website in the early morning and an alert was posted mid-morning it would never appear. I'm wondering what would be the best method on tracking this whole thing. In my mind it seems a special cookie could be created just for this alert with a short lifespan. Then again this maybe accomplished more easily with JQuery but I'm not sure about the security part. Any thoughts are welcome.

    Thanks again for the previous help!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I have a popup that is only displayed when a user logs in. I use a plugin to set a SESSION variable on login:
      <?php
      $_SESSION['loginmessage'] = 'true';


      Then I have a snippet to load the javascript for the popup. I get the message for the popup from a resource, since the client changes it a lot and that's the easiest way for him to change the message. I put the snippet at the bottom of the template where I want the message to appear; the javascript positions it and does all the styling and fade-out closing for me. It's just a JQuery UI dialog.

      <?php
      if(isset($_SESSION['loginmessage']) && $_SESSION['loginmessage'] == 'true') {
        $js = '
        <script type="text/javascript">
      	  $(function() {
      		  $( "#popupMessage" ).dialog({ 
      			   position: { my: "right bottom", at: "right bottom", of: window },
      			   hide: {effect: "fade", duration: 6000}
      		  });
      		  setTimeout(function(){ $("#popupMessage").dialog("close"); }, 8000);
      	  });
        </script>
        ';
        $modx->regClientScript($js);
        
        $document = $modx->getObject('modResource',array(
      	  'id' => 58
        ));
        
        $_SESSION['loginmessage'] = '';
        unset($_SESSION['loginmessage']);
        
        return $document->get('content');
      }
      return;
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 39184
        • 24 Posts
        Susan: Thanks for sharing and I will certainly mark this for research and implementation. The only issue is that I need any visitor to see the message not just logged in users. I've been looking at the Jquery Cookie Plugin and it seems to fit my need to create a simple cookie just for this pop up and use the Modx session for everything else.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In your case, I'd check the SESSION value and if it's empty/doesn't exist load the popup and set the SESSION value. Next page load, it sees the SESSION is set and doesn't load the popup. No plugin necessary.
          <?php
          if(isset($_SESSION['loginmessage']) && $_SESSION['loginmessage'] == 'true') {
              return;
          }
          $js = '
          <script type="text/javascript">
              $(function() {
          	$( "#popupMessage" ).dialog({ 
          		position: { my: "right bottom", at: "right bottom", of: window },
          		hide: {effect: "fade", duration: 6000}
          	});
          	setTimeout(function(){ $("#popupMessage").dialog("close"); }, 8000);
              });
          </script>
          ';
          $modx->regClientScript($js);
            
          $document = $modx->getObject('modResource',array(
              'id' => 58
          ));
            
          $_SESSION['loginmessage'] = 'true';
              
          return $document->get('content');
          
          [ed. note: sottwell last edited this post 13 years, 8 months ago.]
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org