Hide Modify Link - Plugin

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

By Ryan - March 24, 2015

Hi, I was trying to create a plugin that would allow me to hide the modify link next to records that have a status field set to closed.

I been trying to use the hook listRow_actionLinks but with no luck.

Has anyone done anything like this before?

<?php
/*
Plugin Name: Hide Modify Link
Author: RD
Description: Hide Modify Link
Version: 1.00
Requires at least: 2.03
*/


addFilter('listRow_actionLinks',      'hideModifyLink', null, 3);

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)
  
   $showModify = false; 
   
  }
 }
}

?>

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