Hide Modify Link - Plugin

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 2, 2015   (RSS)

By gregThomas - March 31, 2015

Hi mjftech,

The problem is that the listRow_actionLinks is designed for adding new links as opposed to editing or removing those that are already displayed for a certain user. You could try and remove edit link using str_replace:

function hideModifyLink($trStyle, $tableName, $record) {
//only run when saving records in certain tables
 if ($tableName == 'requisitions') {
 
  if (@$record['status'] && @$record['status'] == 3) { // if record is closed (3)
  
    //str_replace function goes in here
    $trStyle = str_replace("<a href=\"?menu={$tableName}&amp;action=edit&amp;num={$record['num']}\">modify</a>", '', $trStyle)
    
  }
 }
 //After you've updated the link, return it.
 return $trStyle;
}

This is just example code, so it might need some tweaking to get it to work with your plugin. So if the status and table are correct, the $trStyle variable gets updated to remove the modify link. Finally the $trStyle item is then returned. 

I'm wondering if a better option is to grey out records that have a status of 3 instead, you could do easily using this plugin:

http://www.interactivetools.com/add-ons/detail.php?Grey-Hidden-Records-1025

I think there could be unintended consequences to removing the modify link, for example what if someone accidentally selects the incorrect status.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Ryan - April 2, 2015

Hi Greg,

Thanks for that, have it working now!

I'm using this plugin as part of a basic ticket support system. I'm monitoring the assignedDate (when requests are assigned to an engineer) and the closedDate (when the engineer marks the request as closed) to report on the response time for each support request. So if users have the ability to modify a request after it's been closed these fields could be changed.

However you make a good point about users accidently closing records so I will allow admin users to modify the record and change the status back.

I'm using this plugin along with a variation of the Grey hidden records plugin that color codes the record rows based on their status, pending open or closed.

<?php
/*
Plugin Name: Hide Modify Link  
Description: Hide Modify Link when $record['status'] equals closed
Version: 1.00
Requires at least: 2.50
*/

//Add button to orders menu
addFilter('listRow_actionLinks',  'hideModifyLink', null, 3);

function hideModifyLink($trStyle, $tableName, $record) {
  global $CURRENT_USER;
 
 //Set modify link
 $modifyLink   = '?menu=' .htmlencode($tableName). "&amp;action=edit&amp;num=" . @$record['num'];

 //only works for certain tables and if the user is not an admin
 if (@$tableName == 'tickets' && !@$CURRENT_USER['isAdmin'])  {

  // and only if that status is set to closed (or in this case its value) 
  if (@$record['status'] && @$record['status'] == 3) { // if record is closed (3)
   
   //str_replace function finds modify link and replaces it with ""
   $trStyle = str_replace("<a href='$modifyLink'>" .t('modify'). "</a>\n", '', $trStyle);
 
    }
  }
  //After you've updated the link, return it.
  return $trStyle;
  }

?>

My only concern now is that engineers could change the ID's in the URL and still be able to modify the record after it's closed, but that's unlikely to happen.

Thanks again for your help.

Ryan