true,
'deleteServer' => true,
'editServer' => true
);
function __construct()
{
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
}
public function config( $params = false )
{
if( !$GLOBALS['phpgw']->acl->check('run',1,'admin') )
{
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
}
$GLOBALS['phpgw_info']['flags']['app_header'] = 'Configuração do Módulo';
$table_servers = "";
if( $_POST['back'] )
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
}
else
{
if( $_POST && $params == false )
{
$this->save($_POST);
}
$servers = $this->readFile();
if( count($servers) > 0 )
{
$serversTable = "";
foreach( $servers as $key => $value )
{
if( substr($key, 0, 11) == "ServersRest")
{
$table_servers .= "
";
$table_servers .= " ".$value['serverName']." | ";
$table_servers .= " ".$value['serverDescription']." | ";
$table_servers .= " ".$value['serverUrl']." | ";
$table_servers .= " ".$value['serverContext']." | ";
$table_servers .= " ".( ($value['serverStatus'] == 1 ) ? "Habilitado" : "Desabilitado" )." | ";
$table_servers .= " link('/index.php','menuaction=negrinha.uiconfig.editServer&serverID='.$value['serverID'].'')."'>Editar | ";
$table_servers .= " link('/index.php','menuaction=negrinha.uiconfig.deleteServer&serverID='.$value['serverID'].'')."'>Excluir | ";
$table_servers .= "
";
}
}
}
$GLOBALS['phpgw']->template->set_file(array('negrinha'=>'config.tpl'));
$GLOBALS['phpgw']->template->set_block('negrinha','pagina');
$GLOBALS['phpgw']->template->set_var( array(
'table_servers' => $table_servers,
'server_id' => (($params && is_array($params) ) ? $params['serverID'] : ""),
'server_name' => (($params && is_array($params) ) ? $params['serverName'] : ""),
'server_description' => (($params && is_array($params) ) ? $params['serverDescription'] : ""),
'server_url' => (($params && is_array($params) ) ? $params['serverUrl'] : ""),
'server_rest' => (($params && is_array($params) ) ? $params['serverContext'] : ""),
'selected_statusServer_true' => (($params && is_array($params) ) ? (($params['serverStatus'] == "0" ) ? "selected=true" : "") : ""),
'selected_statusServer_false' => (($params && is_array($params) ) ? (($params['serverStatus'] == "0" ) ? "selected=true" : "") : "")
));
$GLOBALS['phpgw']->template->pparse('out','pagina');
}
}
public function deleteServer()
{
if( $_GET['serverID'] )
{
$serverID = $_GET['serverID'];
$servers = $this->readFile();
foreach( $servers as $key => $value )
{
if( substr($key, 0, 11) == "ServersRest")
{
if( $value['serverID'] == $serverID )
{
unset( $servers[$key] );
}
}
}
if( !$this->writeFile($servers) )
echo "Error : Permission failure when trying to write in the file ";
else
$this->config();
}
}
public function editServer()
{
if($_GET['serverID'] )
{
$serverID = $_GET['serverID'];
$servers = $this->readFile();
foreach( $servers as $key => $value )
{
if( substr($key, 0, 11) == "ServersRest")
{
if( $value['serverID'] == $serverID )
{
$server = $servers[$key];
}
}
}
}
$this->config($server);
}
private function save($params)
{
$fileConfig = parse_ini_file( __DIR__ . '/../../prototype/config/REST.ini', true );
if( $params['server_id'] )
{
$serverID = $params['server_id'];
$fileConfig['ServersRest-'.$serverID]['serverID'] = $serverID;
$fileConfig['ServersRest-'.$serverID]['serverName'] = $params['server_name'];
$fileConfig['ServersRest-'.$serverID]['serverDescription'] = $params['server_description'];
$fileConfig['ServersRest-'.$serverID]['serverUrl'] = $params['server_url'];
$fileConfig['ServersRest-'.$serverID]['serverContext'] = $params['server_rest'];
$fileConfig['ServersRest-'.$serverID]['serverStatus'] = ( $params['server_status'] == 'true' ) ? "1" : "0";
}
else
{
$keys = array_keys($fileConfig);
foreach($keys as $k => $v)
{
if( substr($v, 0, 11) == "ServersRest")
$ID = $fileConfig[$v]['serverID'];
}
$serverID = ((int)$ID + 1);
if( strlen($serverID) <= 2 )
$serverID = ( strlen($serverID) > 1 ) ? "0".$serverID : "00".$serverID;
$fileConfig['ServersRest-'.$serverID]['serverID'] = $serverID;
$fileConfig['ServersRest-'.$serverID]['serverName'] = $params['server_name'];
$fileConfig['ServersRest-'.$serverID]['serverDescription'] = $params['server_description'];
$fileConfig['ServersRest-'.$serverID]['serverUrl'] = $params['server_url'];
$fileConfig['ServersRest-'.$serverID]['serverContext'] = $params['server_rest'];
$fileConfig['ServersRest-'.$serverID]['serverStatus'] = ( $params['server_status'] == 'true' ) ? "1" : "0";
}
$this->writeFile($fileConfig);
}
private function readFile()
{
$fileConfig = array();
if( file_exists(__DIR__ . '/../../prototype/config/REST.ini') )
{
$fileConfig = parse_ini_file( __DIR__ . '/../../prototype/config/REST.ini', true );
}
return $fileConfig;
}
private function writeFile($config)
{
$path = __DIR__ . '/../../prototype/config/REST.ini';
$content = "";
foreach( $config as $key => $value )
{
if(is_array($value))
{
$content .= "[".$key."]\n";
foreach( $value as $ikey => $ivalue )
$content .= $ikey ."=". $ivalue . "\n";
}
else
{
$content .= $key . "=" . $value . "\n";
}
}
if( file_put_contents($path, $content) === false)
{
return false;
}
return true;
}
}
?>