Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Sunday, October 18, 2026
About Us
O nás
Magazine
Magazín
Open Source
Otvorený softvér
CVS
CVS
Services
Služby
Index  »  Projects  »  phpMyEdit  »  Forum  »  Can I allow editing of only recent entries?

phpMyEdit General     Can I allow editing of only recent entries?
Post new topic   Reply to topic    
 
trister     Joined: 01 Dec 2010   Posts: 15  
Post Posted: 2011-11-17 10:19
Back to top  Reply with quote     

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     Joined: 10 Feb 2003   Posts: 1013   Location: Denver, Colorado (USA)
Post Posted: 2011-11-17 17:34
Back to top  Reply with quote     

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:
Code:
$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     Joined: 01 Dec 2010   Posts: 15  
Post Posted: 2011-11-21 07:42
Back to top  Reply with quote     

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     Joined: 01 Dec 2010   Posts: 15  
Post Posted: 2012-01-20 12:17
Back to top  Reply with quote     

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 :

Code:
//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 :
Code:

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

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

Code:
<?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]


Last edited by trister on 2012-01-24 00:49, edited 1 time in total

 
Post new topic   Reply to topic    

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Odkazový formulár · Application form · Prihláška
Report bug on PLATON.SK website · Upozorniť na chybu na PLATON.SK webstránke · Terms of use · Podmienky použitia · Privacy policy · Ochrana osobných údajov