+ Reply to Thread
Results 1 to 7 of 7

Thread: php alert system?

  1. #1
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    php alert system?

    I already have a fairly successful site running a free CRM system; however, many users are asking that it alerts them of pre-set events.

    I have a start time and duration (epoch values). Do I have to create a cron job running every few minutes or is there another way? I have no idea how to approach this from an AJAX point of view as my javascript experience is zero.

    Any guidance would be appreciated.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php alert system?

    1. How do you want them notified? Email? Alert/message/popup while they are viewing the site?
    2. Where are the 'events' stored? In a db for each user?
    Nothing is always absolutely so.

  3. #3
    xadrieth is offline x10Hosting Member xadrieth is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    62

    Re: php alert system?

    Hmmmm..

    you could could create a PHP file/class that checks for something, and have the MySQL database store the info for the events.

    It could work like this:
    PHP Code:
    $dbc = new mysqli('localhost''root''pw''freecrm');

    $dbc->query('SELECT * FROM crm_events WHERE event_over = \'0\';');

    while (
    $events $query->fetch_array(MYSQLI_ASSOC)) {
        if ((
    time() >= $events['time']) && ($events['even_over'] == 0)) {
            
    // run event
            
    $dbc->query('UPDATE crm_events SET event_over = \'1\' WHERE event_id = \'' .  $envents['event_id'] . '\';';
        }

    I dunno, something like that could work.

    Just be sure to put the function/class at the bottom/top of each page that way whenever the page is accessed, it executes the event early as possible.
    Last edited by xadrieth; 10-06-2009 at 05:28 PM.

  4. #4
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: php alert system?

    If your website generates enough hits, you can simply have a function called at the end of each or next-to-each view of the website and that goes through the event list and takes the required steps. It can also be called at the beginning of the pages.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  5. #5
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: php alert system?

    Quote Originally Posted by descalzo View Post
    1. How do you want them notified? Email? Alert/message/popup while they are viewing the site?
    2. Where are the 'events' stored? In a db for each user?
    In an ideal world, e-mail by default and pop-up if signed in.

    The events are stored in a table related to the contact/user parent table.

    Quote Originally Posted by xadrieth View Post
    Hmmmm..

    you could could create a PHP file/class that checks for something, and have the MySQL database store the info for the events.

    It could work like this:
    PHP Code:
    $dbc = new mysqli('localhost''root''pw''freecrm');

    $dbc->query('SELECT * FROM crm_events WHERE event_over = \'0\';');

    while (
    $events $query->fetch_array(MYSQLI_ASSOC)) {
        if ((
    time() >= $events['time']) && ($events['even_over'] == 0)) {
            
    // run event
            
    $dbc->query('UPDATE crm_events SET event_over = \'1\' WHERE event_id = \'' .  $envents['event_id'] . '\';';
        }

    I dunno, something like that could work.

    Just be sure to put the function/class at the bottom/top of each page that way whenever the page is accessed, it executes the event early as possible.
    I can sort of see where you're going with this, but do I need to add the additional "over" field - plus, doesn't this just update the status of an event - I can't see an action if even_overt ="1".

    Good start though.

    Quote Originally Posted by xav0989 View Post
    If your website generates enough hits, you can simply have a function called at the end of each or next-to-each view of the website and that goes through the event list and takes the required steps. It can also be called at the beginning of the pages.
    Hmm - not sure - I get quite a few but it varies considerably week-day to weekends. If I call a function with every page load, loading data for every user.. is that going to present a security risk???? (*head hurts*) Maybe not, I just need to get my head around that and the load on the server..

    An addition complication is that my system adjusts times according to timezone (set in user prefs) even though the epoch value remains constant. This is going to make life tricky.

    Thanks for the help so far.

  6. #6
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: php alert system?

    for the popup, just do a simple javascript alert("Hello world"); or a confirm if you want to have them redirected to a more in-depth detailed message.

    As you have said, you can create a cron to go off every 30mins or so, depending on how urgent it is to be close to the exact time.

  7. #7
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: php alert system?

    Simple solution, write a small class that can be called from page hits and then have a javascript loop reqest data using ajax from another standalone script using the same class :p

    If that didn't make sense :

    notification.class.php
    PHP Code:
    <?php

    ...

    public function 
    pageHitNotifiaction($userID) {
     ... 
    // call the checkNewNotifications($userID) using vars passed to the function
     
    return $new_notification_array;
    }

    public function 
    pageConfirmNotification($userID) {
     ... 
    // when the member/user has read/confirmed the notification
     
    ... // call the flagNotifiactionRead()
    }

    public function 
    ajaxHitNotifiaction() {
     
    $userID $_GET['uerID'];
     ... 
    // call the checkNewNotifications($userID) using $_GET vars
     
    echo $new_notifications;
    }

    public function 
    ajaxConfirmNotification() {
     
    $userID $_GET['uerID'];
     ... 
    // when the member/user has read/confirmed the notification
     
    ... // call the flagNotifiactionRead()
    }

    public function 
    cronHitNotifiaction() {
     ... 
    // use this to shoot off emails
    }


    private function 
    getNewNotifications($userID) {
     ... 
    // check and return any notification ids relevant to that user or what ever
    }

    private function 
    flagNotifiactionRead() {
     ... 
    // just add a boolean column to the event table that can be used to flag events as passed/read/notified
    }

    private function 
    sendAllEmailNotifications() {
     ... 
    // call this from a cron
    }

    ?>
    I would recomend some kind of que(major ball ache) if you have allot of these notifications to be sent out.
    I wrote a system a while back that ran off different actions from a que members inserted into. The actions had a execution time of anything from 5 secs to 120secs as they where curling another system, it got really complex, shiffting up php max execution time and predicting how long it was going to take to execute a action, then working out how many to run in each cron run. It also had notifications via email, x10forums private message and sms to a certain network

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. Replies: 0
    Last Post: 12-24-2008, 03:59 PM
  3. PHP and new accounts
    By idani in forum Free Hosting
    Replies: 1
    Last Post: 09-21-2008, 01:49 PM
  4. The History Of Gaming!
    By ashwinsinha in forum Gamer's Lounge
    Replies: 26
    Last Post: 03-29-2008, 05:54 PM
  5. Replies: 8
    Last Post: 12-03-2007, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers