BUG 6212 Skin Importing feature

Ready to import skins... Just left to enable NEW and Delete
This commit is contained in:
Hugo Loza
2011-07-21 18:37:03 -04:00
parent 65b5a2cc1d
commit d248f79754
2 changed files with 217 additions and 10 deletions

View File

@@ -1,13 +1,13 @@
<?php <?php
if (!isset($_REQUEST ['action'])) { if (!isset($_REQUEST ['action'])) {
$res ['success'] = 'failure'; $res ['success'] = false;
$res ['message'] = 'You may request an action'; $res ['message'] = 'You may request an action';
print G::json_encode($res); print G::json_encode($res);
die (); die ();
} }
if (!function_exists($_REQUEST ['action'])) { if (!function_exists($_REQUEST ['action'])) {
$res ['success'] = 'failure'; $res ['success'] = false;
$res ['message'] = 'The requested action doesn\'t exists'; $res ['message'] = 'The requested action doesn\'t exists';
print G::json_encode($res); print G::json_encode($res);
die (); die ();
@@ -61,6 +61,100 @@ function createSkin($baseSkin='classic') {
} }
function importSkin() {
try {
if (!isset($_FILES['uploadedFile'])) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')) );
}
$uploadedInstances = count($_FILES['uploadedFile']['name']);
$sw_error = false;
$sw_error_exists = isset($_FILES['uploadedFile']['error']);
$emptyInstances = 0;
$quequeUpload = array();
// upload files & check for errors
$tmp = $_FILES['uploadedFile']['tmp_name'];
$items = stripslashes($_FILES['uploadedFile']['name']);
if ($sw_error_exists)
$up_err = $_FILES['uploadedFile']['error'];
else
$up_err= ( file_exists($tmp) ? 0 : 4);
if ($items == "" || $up_err == 4) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')) );
}
if ($up_err == 1 || $up_err == 2) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_SIZE_ERROR')) );
//$errors[$i]='miscfilesize';
}
if ($up_err == 3) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_PART_ERROR')) );
//$errors[$i]='miscfilepart';
}
if (!@is_uploaded_file($tmp)) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_NOT_UPLOADED')) );
//$errors[$i]='uploadfile';
}
$fileInfo = pathinfo($items);
$validType = array('tar', 'gz');
if (!in_array($fileInfo['extension'], $validType)) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_TYPE_ERROR')) );
//$errors[$i]='wrongtype';
}
$filename = $items;
$tempPath = PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP;
G::verifyPath($tempPath, true);
$tempName = $tmp;
G::uploadFile($tempName, $tempPath, $filename);
G::LoadThirdParty('pear/Archive', 'Tar');
$tar = new Archive_Tar($tempPath . $filename);
$aFiles = $tar->listContent();
$swConfigFile = false;
foreach ($aFiles as $key => $val) {
if (basename($val['filename']) == 'config.xml') {
$skinName = dirname($val['filename']);
$skinArray = explode("/", $skinName);
if (count($skinArray) == 1) {
$swConfigFile = true;
}
}
}
if (!$swConfigFile) {
@unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
throw ( new Exception(G::LoadTranslation('ID_SKIN_CONFIGURATION_MISSING')) );
}
if (is_dir(PATH_CUSTOM_SKINS . $skinName)) {
if ((isset($_REQUEST['overwrite_files'])) && ($_REQUEST['overwrite_files'] == 'on')) {
G::rm_dir(PATH_CUSTOM_SKINS . $skinName, false);
} else {
throw ( new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')) );
}
}
$res = $tar->extract(PATH_CUSTOM_SKINS);
if (!$res) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_ERROR_EXTRACTING')) );
}
//Delete Temporal
@unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
$response['success'] = true;
$response['message'] = G::LoadTranslation('ID_SKIN_SUCCESSFUL_IMPORTED');
print_r(G::json_encode($response));
} catch (Exception $e) {
$response['success'] = false;
$response['message'] = $e->getMessage();
$response['error'] = $e->getMessage();
print_r(G::json_encode($response));
}
}
function exportSkin($skinToExport) { function exportSkin($skinToExport) {
try { try {
if (!isset($_REQUEST['SKIN_FOLDER_ID'])) { if (!isset($_REQUEST['SKIN_FOLDER_ID'])) {
@@ -95,7 +189,7 @@ function exportSkin($skinToExport) {
$tar->_compress = false; $tar->_compress = false;
addTarFolder($tar, $skinFolder, PATH_CUSTOM_SKINS); addTarFolder($tar, $skinFolder, PATH_CUSTOM_SKINS);
$response['success'] = true; $response['success'] = true;
$response['message'] = $skinTar; $response['message'] = $skinTar;

View File

@@ -101,8 +101,8 @@ Ext.onReady(function(){
importButton = new Ext.Action({ importButton = new Ext.Action({
text: _('ID_IMPORT'), text: _('ID_IMPORT'),
iconCls: 'button_menu_ext ss_sprite ss_basket_put', iconCls: 'button_menu_ext ss_sprite ss_basket_put',
//handler: CopyButtonAction, handler: importSkin,
disabled: true disabled: false
}); });
exportButton = new Ext.Action({ exportButton = new Ext.Action({
text: _('ID_EXPORT'), text: _('ID_EXPORT'),
@@ -371,7 +371,120 @@ onMessageContextMenu = function (grid, rowIndex, e) {
//Do Nothing Function //Do Nothing Function
DoNothing = function(){}; DoNothing = function(){};
importSkin = function(){
importDialog = new Ext.Window( {
id: "importDialog",
title:_('ID_UPLOAD'),
autoCreate: true,
modal:true,
width:400,
autoHeight:true,
shadow:true,
minWidth:100,
minHeight:50,
proxyDrag: true,
resizable: true,
keys: {
key: 27,
fn : function(){
importDialog.hide();
}
},
items:[
{
xtype:'form',
autoScroll:true,
autoHeight:true,
id:"uploadform",
fileUpload:true,
labelWidth:90,
url:'skin_Ajax',
tooltip:"Max File Size <strong>XXX MB</strong><br />Max Post Size<strong>XXX MB</strong><br />",
frame:false,
items:[
{
xtype:"displayfield",
value:"Max File Size <strong>XXX MB</strong><br />Max Post Size<strong>XXX MB</strong><br />"
},
{
xtype:"fileuploadfield",
fieldLabel:"File ",
id:"uploadedFile",
name:"uploadedFile",
width:100,
buttonOnly:false
},
{
xtype:"checkbox",
fieldLabel:"Overwrite",
name:"overwrite_files",
checked:true
}
],
buttons:[
{
text:_('ID_SAVE'),
handler: function() {
//statusBarMessage( _('ID_UPLOADING_FILE'), true, true );
importDialog.getEl().mask(_('ID_SKIN_IMPORTING'));
form = Ext.getCmp("uploadform").getForm();
//Ext.getCmp("uploadform").getForm().submit();
//console.log(form);
//console.log(form.url);
Ext.getCmp("uploadform").getForm().submit({
//reset: true,
reset: false,
success: function(form, action) {
store.reload();
Ext.getCmp("importDialog").destroy();
},
failure: function(form, action) {
Ext.getCmp("importDialog").destroy();
if( !action.result ) {
Ext.MessageBox.alert("error", _('ID_ERROR'));
return;
}
Ext.MessageBox.alert("error", action.result.error);
},
scope: Ext.getCmp("uploadform"),
// add some vars to the request, similar to hidden fields
params: {
option: "standardupload",
action: "importSkin",
requestType: "xmlhttprequest",
confirm: "true"
}
});
}
},
{
text:_('ID_CANCEL'),
handler: function() {
Ext.getCmp("importDialog").destroy();
}
}
]
}
]
});
// importDialog.doLayout();
// recalculate
// Window size
//importDialog.syncSize();
// center the window
//importDialog.center();
importDialog.on( 'hide', function() {
importDialog.destroy(true);
} );
importDialog.show();
};
exportSkin = function(){ exportSkin = function(){
viewport.getEl().mask(_('ID_SKIN_EXPORTING')); viewport.getEl().mask(_('ID_SKIN_EXPORTING'));
rowSelected = infoGrid.getSelectionModel().getSelected(); rowSelected = infoGrid.getSelectionModel().getSelected();
@@ -381,7 +494,7 @@ exportSkin = function(){
params: { params: {
action: 'exportSkin', action: 'exportSkin',
SKIN_FOLDER_ID: rowSelected.data.SKIN_FOLDER_ID SKIN_FOLDER_ID: rowSelected.data.SKIN_FOLDER_ID
}, },
success: function(r,o){ success: function(r,o){
viewport.getEl().unmask(); viewport.getEl().unmask();
var resp = Ext.util.JSON.decode(r.responseText); var resp = Ext.util.JSON.decode(r.responseText);
@@ -433,8 +546,8 @@ DoSearch = function(){
infoGrid.store.load({ infoGrid.store.load({
params: { params: {
textFilter: searchText.getValue() textFilter: searchText.getValue()
} }
}); });
}; };
//Edit Calendar Action //Edit Calendar Action
@@ -454,7 +567,7 @@ DeleteButtonAction = function(){
params: { params: {
action: 'canDeleteCalendar', action: 'canDeleteCalendar',
CAL_UID: rowSelected.data.CALENDAR_UID CAL_UID: rowSelected.data.CALENDAR_UID
}, },
success: function(r,o){ success: function(r,o){
viewport.getEl().unmask(); viewport.getEl().unmask();
var resp = Ext.util.JSON.decode(r.responseText); var resp = Ext.util.JSON.decode(r.responseText);
@@ -468,7 +581,7 @@ DeleteButtonAction = function(){
params: { params: {
action: 'deleteCalendar', action: 'deleteCalendar',
CAL_UID: rowSelected.data.CALENDAR_UID CAL_UID: rowSelected.data.CALENDAR_UID
}, },
success: function(r,o){ success: function(r,o){
viewport.getEl().unmask(); viewport.getEl().unmask();
editButton.disable(); editButton.disable();