Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Can I allow editing of only recent entries?

phpMyEdit General     Can I allow editing of only recent entries?
Odoslať novú tému   Odpovedať na tému    
 
trister     Založený: 01.12.2010   Príspevky: 15  
Príspevok Zaslal: 2011-11-17 10:19
Návrat hore  Odpovedať s citátom     

I want to allow editing of the last 100 entries in my table.

I think this might be a trigger-related problem.
Anyone has any ideas (and maybe post a sample trigger code) on how I can do this neatly?

I could do it with php but phpMyEdit always amazes me :)

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2011-11-17 17:34
Návrat hore  Odpovedať s citátom     

Assuming the unique record identifier is a numeric auto-increment field, query for the MAX value, subtract 100 from the result, and then create a filter for phpMyEdit.

http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.filters.html

Possibly something like:
Kód:
$qry = 'SELECT MAX(id) FROM `table`';
if(!$row = @mysql_fetch_row(@mysql_query($qry))){
   die('Query failed: '.$qry);
}
$x = $row[0] - 100;
$opts['filters'] = 'id > "'.$x.'"';


 
trister     Založený: 01.12.2010   Príspevky: 15  
Príspevok Zaslal: 2011-11-21 07:42
Návrat hore  Odpovedať s citátom     

Thanks for the quick reply.

I think this code just displays the last 100 entries.

My request (that I think it wasn't so clear :P ) is that I want to view everything but allow editing of only the last 100 entries.

Thanks again :)

 
trister     Založený: 01.12.2010   Príspevky: 15  
Príspevok Zaslal: 2012-01-20 12:17
Návrat hore  Odpovedať s citátom     

To answer to my question :P :

You must create a trigger.
--------------
The fields that you'll use (read or write) inside the trigger MUST BE NOT Read Only (so do not use input='R')
--------------
A counter measure (that I found in these forums) for not being able to use input='R' is this :

Kód:
//Reset New values to Old values (This userlevel can't change number & year
if($newvals['number'] != $oldvals['number']) $newvals['number'] = $oldvals['number'];
if($newvals['year'] != $oldvals['year']) $newvals['year'] = $oldvals['year'];

--------------

Add the line to your main phpmyedit file :
Kód:

$opts['triggers']['update']['before'] = './trigger_last_entries.php'; // ['pre'] doesn't work

---------------
trigger_last_entries.php:

Kód:
<?php
$query2 = "SELECT MAX(number) as maxnum FROM entries;

if($data=$this->MyQuery($query2)){

   $result = mysql_fetch_array($data);
   $last_number = $result[0];
      
   $trigger_error_message="<h2><font color=red>You can't change old values </font></h2>";
   $this_number   =$oldvals['number'];

         if($this_number>($last_number-100)){  //allow editing of only the last 100 entries
            return true;
         } else {
               echo $trigger_error_message;
               return false; // Don't allow the update
         }
}else{
   print "<h2><font color=red> There was an connection error </font></h2>";
   echo "\n".'<p>'.mysql_error().'</p>';
}
echo  $trigger_error_message."<br>Maybe SQL error";

return false; // Do not allow edit on SQL error

?>



The above code is based on some older posts with minor changes





[/code]


Naposledy upravil trister dňa 2012-01-24 00:49, celkom upravené 1 krát

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov