Login   Register  
PHP Classes
elePHPant
Icontem

File: mru_sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Selifonov  >  MRU manager  >  mru_sample.php  >  Download  
File: mru_sample.php
Role: Example script
Content type: text/plain
Description: Using example
Class: MRU manager
Manage most recently user items in a MySQL table
Author: By
Last change:
Date: 2010-12-30 00:03
Size: 1,788 bytes
 

Contents

Class file image Download
<?PHP
/**
* @name mru_sample.php
* Demonstrates using of mru_manager.php
* PHP required: 5.2+
* Uses as_dbutiles.php module for MySQL data access
* @Author Alexander Selifonov, <alex [at] selifan {dot} ru>
* @Link: http://www.selifan.ru
* @license http://www.opensource.org/licenses/bsd-license.php    BSD
*
**/

$as_dbparam = array(
  
'server'=>'',
  
'dbname'=>'test',
  
'username'=>'',
  
'password'=>'',
#  'onconnect'=>"SET NAMES `cp1251`" # for MySQL5.x if You use windows-1251 charset in data
);

require_once(
'as_dbutils.php');

require_once(
'mru_manager.php');

$itemid = isset($_GET['itemid']) ? $_GET['itemid'] : '';

$options = array(
     
'tablename' => 'mru_tests'
    
,'mrulength' => 5
    
,'userid'    => 'test_user'
);
$mru = new CMRUManager($options);
$itmtype='tests';
$addtext '';
if(!empty(
$_GET['clearmru'])) {
    
$mru->ClearMRUData();
    
$addtext "MRU data cleared";
}
elseif(
$itemid$mru->RegisterEvent($itemid,$itmtype);

?>
<html>
<body><h3>MRU manager tests</h3>
<form name="mrutests" action="mru_sample.php" method="get">
<input type="text" name="itemid" cols="20" value="<?=$itemid?>" /> Item ID
<input type="submit" name="addmru" value="Register in MRU" /><br />
<input type="submit" name="clearmru" value="Clear MRU data" />
</form>
<?=$addtext?>
<hr />
Current MRU list:<br />
<table border=1><tr><td>No</td><td>Item ID</td><td>Builded URI</td><td>event time</td></tr>
<?php

    
# Print current MRU list ...
    
$events $mru->GetMRUList($itmtype'uri-to-open-doc.php?id={id}');
    
$num 1;
    foreach(
$events as $evt) {
        echo 
'<tr><td>' . ($num++)."</td><td>{$evt['itemid']}</td><td>{$evt['uri']}</td><td>{$evt['eventdate']}</td></tr>";
    }

?>
</table>
</body>
</html>