khanat-opennel-code/code/web/public_php/ams/func/delete_plugin.php

55 lines
1.9 KiB
PHP
Raw Normal View History

2014-06-13 11:51:49 +00:00
<?php
/**
* This function is used in deleting plugins.
* It removes the plugin from the codebase as well as
* from the Database. When user request to delete a plugin
2014-09-03 05:06:43 +00:00
* id of that plugin is sent in $_GET global variable.
*
* @author Shubham Meena, mentored by Matthew Lagoe
2014-06-13 11:51:49 +00:00
*/
function delete_plugin() {
2014-09-03 05:06:43 +00:00
2014-06-13 11:51:49 +00:00
// if logged in
if ( WebUsers :: isLoggedIn() ) {
2014-09-03 05:06:43 +00:00
2014-06-13 11:51:49 +00:00
if ( isset( $_GET['id'] ) )
{
// id of plugin to delete after filtering
$id = filter_var( $_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
2014-09-03 05:06:43 +00:00
2014-06-13 11:51:49 +00:00
$db = new DBLayer( 'lib' );
$sth = $db -> selectWithParameter( "FileName", "plugins", array( 'id' => $id ), "Id=:id" );
$name = $sth -> fetch();
2014-09-03 05:06:43 +00:00
2014-06-13 11:51:49 +00:00
if ( is_dir( "$name[FileName]" ) )
{
// removing plugin directory from the code base
2014-07-07 08:26:58 +00:00
if ( Plugincache::rrmdir( "$name[FileName]" ) )
2014-06-13 11:51:49 +00:00
{
$db -> delete( 'plugins', array( 'id' => $id ), "Id=:id" );
2014-09-03 05:06:43 +00:00
//if result successfull redirect and show success message
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
2014-06-13 11:51:49 +00:00
header( "Location: index.php?page=plugins&result=2" );
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2014-09-03 05:06:43 +00:00
}
2014-06-13 11:51:49 +00:00
else
{
2014-09-03 05:06:43 +00:00
// if result unsuccessfull redirect and show error message
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
2014-06-13 11:51:49 +00:00
header( "Location: index.php?page=plugins&result=0" );
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2014-09-03 05:06:43 +00:00
}
}
}
2014-06-13 11:51:49 +00:00
else
{
2014-09-03 05:06:43 +00:00
// if result unsuccessfull redirect and show error message
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
2014-06-13 11:51:49 +00:00
header( "Location: index.php?page=plugins&result=0" );
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2014-09-03 05:06:43 +00:00
}
}
}