custom button in cmsb to perform custom action

4 posts by 3 authors in: Forums > CMS Builder
Last Post: March 1, 2013   (RSS)

Hi, 

This is possible, but will require a custom plugin. I've created a very basic plugin that demonstrates how you could do it:

<?php
/*
Plugin Name: Test Plugin - 
Description: test plugin
Version: 1.00
Requires at least: 2.50
*/


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

//Send update on link click
pluginAction_addHandlerAndLink('Send an update e-mail', 'sendUpdate', true);

addAction('record_preedit', 'sendUpdate', null, 0);



// add "create record here" link
function dispatch_order($actionLink, $tableName, $record) {
  global $schema;



  // Add a line with the url for each section
  if (@$tableName == 'orders') { $actionLink .= '<a target="_blank" href="?sendMessage=true&menu='.$tableName.'&action=edit&num='.$record['num'].'" >Test link</a>'; }


  return $actionLink;
}


//Function for sending message
function sendUpdate(){

  if(@$_REQUEST['menu'] = 'orders' && @$_REQUEST['sendMessage'] == 'true'){

    /*
    *
    * YOUR SCRIPT WOULD GO HERE
    *
    *
    */

    alert('Message sent to'.$_REQUEST['num']);

  }
}

This is example code, so you will need to modify it to work with your site.

So this plugin will add a link called 'test link' to the actions area of a section list page. In this example it only adds the link when the table name is orders. 

I've set up the link so that it will edit a record, but also passes the variable sendMessage in the URL as well. 

Then I added another plugin hook called record_preedit. When a record is edited, it will launch the function sendUpdate, this function will check if the sendMessage variable is in the URL, and that we are on the orders menu.

Finally, an alert message will display at the top of the page that says 'Message sent to ' and the record number.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Dave - February 25, 2013

Hi zaba, 

And here's a more low-tech solution as well so you have some options.  Just add a new separator field in the Section Editor and enter this for HTML:<tr>

 <td colspan='2'>
   <?php if (!$GLOBALS['RECORD']): ?>
      Save record first to send email.
    <?php else: ?>
      <a href="/script.php?<?php echo $GLOBALS['RECORD']['num']; ?>">Send email</a>
    <?php endif ?>
  </td>
</tr>

Then either redirect or link people back to the edit page when you are done: 

/cmsAdmin/admin.php?menu=orders&action=edit&num=123

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By zaba - March 1, 2013

Thanks guys,

I decided to go for Daves Simpler option, by adding the class"button" to the a href I was able to format it like the buttons in the cms.

I also added in my script an Update Table Orders to change the status to dispatched before returning back to the cms page from whence I came (and thus showing it as dispatched).

It all works a charm.

Really thanks very much for your suggestions.