Someone has to know this…….
I added a tab to the top level tabs within the control panel (through an extension hooking the “cp_display_page_navigation” hook.
I added a module which handles the administrative side of the functionality… basically allowing an admin to define the groups that have visibility to the tab which is created through the extension. This separates the administration of the functionality (located under Admin->Modules) from the actual execution of the rsync functionality (executed through an extension which makes the top level tab available to the member_groups which have been given privileges). If the link from the tab looks like …/index.php?S=0&=rsync How does that tie in… in other words, what php code do I need to add in order to populated the Tab (build the display page)….
someone has to know this…….
Ok, I figured out how it should look… The link has to point to S=0&C=modules&M=Rsync&P=display…. I have a display in the switch of the Rsync Module which will invoke the “display_rsync” function to build the page…. Now… onto the big question
How do I execute a script from within the generated page… I basically created a html page with a form with action = ‘/etc/local/bin/rsync_prod.sh’ and a button which submits the form…but…. when I click the button it treats it like a web page and prepends the site information so I get basically get a url which, of course, doesn’t work and is not what I want….
How can I execute a script from within the generated page? Thanks
The typical way would be- instead of adding a form inside a form, simply add your fields and then tap into a hook after (though nothing wrong with before) the entry is submitted.
So on a really simple one, my functions to add a tag and ‘ping’ google when a new entry was made looked like:
function activate_extension()
{
global $DB, $PREFS;
$DB->query($DB->insert_string('exp_extensions',
array('extension_id' => '',
'class' => "Map_pings",
'method' => "send_notice",
'hook' => "submit_new_entry_absolute_end",
'settings' => $this->settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
$DB->query($DB->insert_string('exp_extensions',
array('extension_id' => '',
'class' => "Map_pings",
'method' => "mping_body",
'hook' => "publish_form_new_tabs_block",
'settings' => $this->settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
$DB->query($DB->insert_string('exp_extensions',
array('extension_id' => '',
'class' => "Map_pings",
'method' => "mping_tab",
'hook' => "publish_form_new_tabs",
'settings' => $this->settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
// END
So it grabs the post data after the entry has been submitted and does- whatever you want with it.
Not dead sure I’m clear on everything that’s going on, but that’s a simple approach. Make sense?
Hey Robin, I figured out how to do this. I created both a module and an extension. The module handles setting up the data (which groups the tab shows up for, etc. The extension actually handles executing the shell script and displaying the log information. This works out well as the groups that have the privs to execute the shell script shouldn’t have access to the modules and they won’t be able to change the administrative settings for the extension functionality. Thanks
Ah- sounds like a good call. There are existing module/extension combos you can look at to see how they handle it. Solspace’s Tag module has an included extension that puts a tab on the publish page. And Fresh variables is a first party mod/ext combo. It doesn’t directly address the tab issue, but it’s a nice example of how to combine the two.
Sounds like you’ve got the gist, though!
Ok, I don’t have this quite right yet. Right now the code for the top level tab invokes ….. index.php?S=0&C=modules&M=Migration&P=display. This invokes the routine specified in the Migration Class Module switch statement for ‘display’.
function Migration_CP( $switch = TRUE )
{
global $IN;
if ($switch)
{
switch($IN->GBL('P'))
{
case 'insert' : $this->insert_migration();
break;
case 'update' : $this->update_migration();
break;
case 'display' : $this->display_migration();
break;
case 'execute_file' : $this->execute_file_migration();
break;
case 'execute_entry' : $this->execute_entry_migration();
break;
case 'delete_entry_log' : $this->delete_log('entry');
break;
case 'delete_file_log' : $this->delete_log('file');
break;
default : $this->migration_home();
break;
}
}
}
The issue that I have is the user groups that should have access to execute the migration functionality should not have access to the module pages within the control panel… Is is possible to change the call that is executed when the top level tab is clicked to something like ‘index.php?S=0&C=extensions&M=Migration&P=display’… basically invoking a procedure within the extension?? or can that code only be invoked through a hook… Problem that I have is I don’t see a hook to build a page for a top level tab…
Thanks
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.