We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I have created a simple time tracker using the MODx manager tracking system.

    1. Create a folder in assets/files named "dev" (assets/files/dev) and make sure it has read/write/execute permissions for your PHP scripts.

    2. Create a new plugin, Time Tracker.

    3. In the plugin’s configuration tab, set your timezone. For example
    &timezone=Time Zone;text;Asia/Jerusalem

    See http://php.net/manual/en/timezones.php for a list of supported timezones.

    4. In the System Events tab, scroll down to the Manager Access Events section and check the OnManagerLogout box.

    5. Copy this code into the plugin code field:
    /* set the timezone to use for formatting the date and time of the log.
    * Use the Configuration tab to change your timezone setting 
    * See http://php.net/manual/en/timezones.php for a list of supported timezones.
    */
    date_default_timezone_set($timezone);
    $name = $_SESSION['mgrShortname'];
    $logintime = $_SESSION['modx.session.created.time'];
    $login = date('r', $logintime);
    $logout = date('r');
    $time = time() - $lastlogin;
    $minutes = round($time / 60);
    
    if(is_file('../assets/files/dev/' . $name . '_log.txt')) {
        $text = "\n\n" . 'Logged in: ' . $login  . "\n" . 'Logged out: ' . $logout . "\n"  . 'Time online: ' . $minutes . ' minutes';
    } else {
        $text = 'Logged in: ' . $login  . "\n" . 'Logged out: ' . $logout . "\n"  . 'Time online: ' . $minutes . ' minutes';
    }
    
    $handle = fopen('../assets/files/dev/' . $name . '_log.txt', 'a');
    fwrite($handle, $text);
    fclose($handle);


    Now when a manager user logs out, a file will be created using his username as the filename (admin_log.txt, for example) with this output:
    Logged in: Wed, 25 Nov 2009 12:27:50 +0200
    Logged out: Wed, 25 Nov 2009 12:36:58 +0200
    Time online: 9 minutes

    Logged in: Wed, 25 Nov 2009 12:31:35 +0200
    Logged out: Wed, 25 Nov 2009 12:41:12 +0200
    Time online: 10 minutes

    This is just the simple beginning of what will become a more comprehensive project management system, involving modules, snippets and more plugins.

    Suggestions and criticism welcomed!

      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