From e3add14892cc48b90e87cac1ffdc46fd5a4f460b Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Tue, 12 Jul 2011 12:02:57 -0400 Subject: [PATCH] BUG 0000 PM tables + Report tables have been unified - finished --- gulliver/system/class.controller.php | 2 +- .../engine/classes/model/AdditionalTables.php | 4 +- workflow/engine/controllers/pmTables.php | 18 +- workflow/engine/controllers/pmTablesProxy.php | 235 +++++++++++++++++- workflow/engine/menus/setup.php | 7 +- .../additionalTables/additionalTablesAjax.php | 194 +++++++-------- .../skinEngine/base/css/pmos-xtheme-gray.css | 6 + .../engine/templates/pmTables/export.html | 3 + workflow/engine/templates/pmTables/export.js | 169 +++++++++++++ workflow/engine/templates/pmTables/list.js | 216 +++++++++++++--- 10 files changed, 717 insertions(+), 137 deletions(-) create mode 100644 workflow/engine/templates/pmTables/export.html create mode 100644 workflow/engine/templates/pmTables/export.js diff --git a/gulliver/system/class.controller.php b/gulliver/system/class.controller.php index 703d5e252..2d7ee8364 100644 --- a/gulliver/system/class.controller.php +++ b/gulliver/system/class.controller.php @@ -18,7 +18,7 @@ class Controller */ private $__request__; - private $headPublisher; + protected $headPublisher; public $ExtVar = Array(); diff --git a/workflow/engine/classes/model/AdditionalTables.php b/workflow/engine/classes/model/AdditionalTables.php index dbfcc0da0..281cf2193 100644 --- a/workflow/engine/classes/model/AdditionalTables.php +++ b/workflow/engine/classes/model/AdditionalTables.php @@ -689,7 +689,8 @@ class AdditionalTables extends BaseAdditionalTables { $aData['className'] = $sClassName; $aData['connection'] = $connection; $aData['GUID'] = $sAddTabUid; - $aData['firstColumn'] = strtoupper($aFields[0]['FLD_NAME']); + + $aData['firstColumn'] = isset($aFields[0])? strtoupper($aFields[0]['FLD_NAME']) : strtoupper($aFields[1]['FLD_NAME']); $aData['totalColumns'] = count($aFields); $aData['useIdGenerator'] = 'false'; $oTP1 = new TemplatePower(PATH_TPL . 'additionalTables' . PATH_SEP . 'Table.tpl'); @@ -1201,6 +1202,7 @@ var additionalTablesDataDelete = function(sUID, sKeys) { function getAllData($sUID, $start=NULL, $limit=NULL) { $aData = $this->load($sUID, true); + $aData['DBS_UID'] = $aData['DBS_UID'] ? $aData['DBS_UID'] : 'workflow'; $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP; $sClassName = ($aData['ADD_TAB_CLASS_NAME'] != '' ? $aData['ADD_TAB_CLASS_NAME'] : $this->getPHPName($aData['ADD_TAB_NAME'])); diff --git a/workflow/engine/controllers/pmTables.php b/workflow/engine/controllers/pmTables.php index 2883135a5..9ef3c9571 100644 --- a/workflow/engine/controllers/pmTables.php +++ b/workflow/engine/controllers/pmTables.php @@ -35,6 +35,8 @@ class pmTables extends Controller $this->setJSVar('CONFIG', $Config); $this->setJSVar('PRO_UID', isset($_GET['PRO_UID'])? $_GET['PRO_UID'] : false); + $this->setJSVar('_PLUGIN_SIMPLEREPORTS', $this->_getSimpleReportPluginDef()); + //render content G::RenderPage('publish', 'extJs'); } @@ -117,7 +119,9 @@ class pmTables extends Controller $this->includeExtJS('pmTables/' . $jsFile, $this->debug); //fix for backware compatibility - $table['DBS_UID'] = $table['DBS_UID'] == null || $table['DBS_UID'] == '' ? 'workflow': $table['DBS_UID']; + if ($table) { + $table['DBS_UID'] = $table['DBS_UID'] == null || $table['DBS_UID'] == '' ? 'workflow': $table['DBS_UID']; + } $this->setJSVar('ADD_TAB_UID', $addTabUid); $this->setJSVar('PRO_UID', isset($_GET['PRO_UID'])? $_GET['PRO_UID'] : false); @@ -142,6 +146,18 @@ class pmTables extends Controller //g::pr($tableDef['FIELDS']); G::RenderPage('publish', 'extJs'); } + + function export($httpData) + { + $this->includeExtJS('pmTables/export', $this->debug); //adding a javascript file .js + $this->setView('pmTables/export'); //adding a html file .html. + + $toSend = Array(); + $toSend['UID_LIST'] = $httpData->id; + + $this->setJSVar('EXPORT_TABLES', $toSend); + G::RenderPage('publish', 'extJs'); + } /** diff --git a/workflow/engine/controllers/pmTablesProxy.php b/workflow/engine/controllers/pmTablesProxy.php index 417a70006..339b2d761 100644 --- a/workflow/engine/controllers/pmTablesProxy.php +++ b/workflow/engine/controllers/pmTablesProxy.php @@ -188,7 +188,7 @@ class pmTablesProxy extends HttpProxyController 'ADD_TAB_CLASS_NAME' => $repTabClassName, 'ADD_TAB_DESCRIPTION' => $data['REP_TAB_DSC'], 'ADD_TAB_PLG_UID' => '', - 'DBS_UID' => $data['REP_TAB_CONNECTION'], + 'DBS_UID' => ($data['REP_TAB_CONNECTION'] ? $data['REP_TAB_CONNECTION'] : 'workflow'), 'PRO_UID' => $data['PRO_UID'], 'ADD_TAB_TYPE' => $data['REP_TAB_TYPE'], 'ADD_TAB_GRID' => $data['REP_TAB_GRID'] @@ -425,8 +425,6 @@ class pmTablesProxy extends HttpProxyController /** * update pm tables record * @param string $httpData->id - * @param string $httpData->start - * @param string $httpData->limit */ public function dataUpdate($httpData) { @@ -458,6 +456,10 @@ class pmTablesProxy extends HttpProxyController $this->message = $result ? 'Updated Successfully' : 'Error Updating record'; } + /** + * remove a pm tables record + * @param string $httpData->id + */ public function dataDestroy($httpData) { require_once 'classes/model/AdditionalTables.php'; @@ -478,6 +480,217 @@ class pmTablesProxy extends HttpProxyController } + /** + * import a pm table + * @param string $httpData->id + */ + public function import($httpData) + { + require_once 'classes/model/AdditionalTables.php'; + + try { + + $overWrite = isset($_POST['form']['OVERWRITE'])? true: false; + + //save the file + if ($_FILES['form']['error']['FILENAME'] == 0) { + $PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP; + + $filename = $_FILES['form']['name']['FILENAME']; + $tempName = $_FILES['form']['tmp_name']['FILENAME']; + G::uploadFile($tempName, $PUBLIC_ROOT_PATH, $filename ); + + $fileContent = file_get_contents($PUBLIC_ROOT_PATH.$filename); + + if(strpos($fileContent, '-----== ProcessMaker Open Source Private Tables ==-----') !== false){ + $oMap = new aTablesMap(); + + $fp = fopen($PUBLIC_ROOT_PATH.$filename, "rb"); + $fsData = intval(fread($fp, 9)); //reading the metadata + $sType = fread($fp, $fsData); //reading string $oData + + require_once 'classes/model/AdditionalTables.php'; + $oAdditionalTables = new AdditionalTables(); + require_once 'classes/model/Fields.php'; + $oFields = new Fields(); + + while ( !feof($fp) ) { + switch($sType){ + case '@META': + $fsData = intval(fread($fp, 9)); + $METADATA = fread($fp, $fsData); + //print_r($METADATA); + break; + case '@SCHEMA': + + $fsUid = intval(fread($fp, 9)); + $uid = fread($fp, $fsUid); + + $fsData = intval(fread($fp, 9)); + $schema = fread($fp, $fsData); + $contentSchema = unserialize($schema); + //print_r($contentSchema); + + if($overWrite){ + $aTable = new additionalTables(); + try{ + $tRecord = $aTable->load($uid); + $aTable->deleteAll($uid); + } catch(Exception $e){ + $tRecord = $aTable->loadByName($contentSchema['ADD_TAB_NAME']); + if($tRecord[0]){ + $aTable->deleteAll($tRecord[0]['ADD_TAB_UID']); + } + } + } else { + #verify if exists some table with the same name + $aTable = new additionalTables(); + $tRecord = $aTable->loadByName("{$contentSchema['ADD_TAB_NAME']}%"); + + if($tRecord){ + $tNameOld = $contentSchema['ADD_TAB_NAME']; + $contentSchema['ADD_TAB_NAME'] = "{$contentSchema['ADD_TAB_NAME']}".sizeof($tRecord); + $contentSchema['ADD_TAB_CLASS_NAME'] = "{$contentSchema['ADD_TAB_CLASS_NAME']}".sizeof($tRecord); + $oMap->addRoute($tNameOld, $contentSchema['ADD_TAB_NAME']); + } + + } + + $sAddTabUid = $oAdditionalTables->create( + array( + 'ADD_TAB_NAME' => $contentSchema['ADD_TAB_NAME'], + 'ADD_TAB_CLASS_NAME' => $contentSchema['ADD_TAB_CLASS_NAME'], + 'ADD_TAB_DESCRIPTION' => $contentSchema['ADD_TAB_DESCRIPTION'], + 'ADD_TAB_SDW_LOG_INSERT' => $contentSchema['ADD_TAB_SDW_LOG_INSERT'], + 'ADD_TAB_SDW_LOG_UPDATE' => $contentSchema['ADD_TAB_SDW_LOG_UPDATE'], + 'ADD_TAB_SDW_LOG_DELETE' => $contentSchema['ADD_TAB_SDW_LOG_DELETE'], + 'ADD_TAB_SDW_LOG_SELECT' => $contentSchema['ADD_TAB_SDW_LOG_SELECT'], + 'ADD_TAB_SDW_MAX_LENGTH' => $contentSchema['ADD_TAB_SDW_MAX_LENGTH'], + 'ADD_TAB_SDW_AUTO_DELETE' => $contentSchema['ADD_TAB_SDW_AUTO_DELETE'], + 'ADD_TAB_PLG_UID' => $contentSchema['ADD_TAB_PLG_UID'] + ), + $contentSchema['FIELDS'] + ); + + + $aFields = array(); + foreach( $contentSchema['FIELDS'] as $iRow => $aRow ){ + unset($aRow['FLD_UID']); + $aRow['ADD_TAB_UID'] = $sAddTabUid; + $oFields->create($aRow); + // print_R($aRow); die; + $aFields[] = array( + 'sType' => $contentSchema['FIELDS'][$iRow]['FLD_TYPE'], + 'iSize' => $contentSchema['FIELDS'][$iRow]['FLD_SIZE'], + 'sFieldName' => $contentSchema['FIELDS'][$iRow]['FLD_NAME'], + 'bNull' => $contentSchema['FIELDS'][$iRow]['FLD_NULL'], + 'bAI' => $contentSchema['FIELDS'][$iRow]['FLD_AUTO_INCREMENT'], + 'bPrimaryKey' => $contentSchema['FIELDS'][$iRow]['FLD_KEY'] + ); + } + $oAdditionalTables->createTable($contentSchema['ADD_TAB_NAME'], 'wf', $aFields); + + for($i=1; $i <= count($contentSchema['FIELDS']); $i++){ + $contentSchema['FIELDS'][$i]['FLD_NULL'] = $contentSchema['FIELDS'][$i]['FLD_NULL'] == '1' ? 'on' : ''; + $contentSchema['FIELDS'][$i]['FLD_AUTO_INCREMENT'] = $contentSchema['FIELDS'][$i]['FLD_AUTO_INCREMENT'] == '1' ? 'on' : ''; + $contentSchema['FIELDS'][$i]['FLD_KEY'] = $contentSchema['FIELDS'][$i]['FLD_KEY'] == '1' ? 'on' : ''; + $contentSchema['FIELDS'][$i]['FLD_FOREIGN_KEY'] = $contentSchema['FIELDS'][$i]['FLD_FOREIGN_KEY'] == '1' ? 'on' : ''; + } + + $oAdditionalTables->createPropelClasses($contentSchema['ADD_TAB_NAME'], $contentSchema['ADD_TAB_CLASS_NAME'], $contentSchema['FIELDS'], $sAddTabUid); + + break; + case '@DATA': + $fstName = intval(fread($fp, 9)); + $tName = fread($fp, $fstName); + $fsData = intval(fread($fp, 9)); + $contentData = unserialize(fread($fp, $fsData)); + + $tName = $oMap->route($tName); + + $oAdditionalTables = new AdditionalTables(); + $tRecord = $oAdditionalTables->loadByName($tName); + + if($tRecord){ + foreach($contentData as $data){ + unset($data['DUMMY']); + $oAdditionalTables->saveDataInTable($tRecord[0]['ADD_TAB_UID'], $data); + } + } + break; + } + $fsData = intval(fread($fp, 9)); + if($fsData > 0){ + $sType = fread($fp, $fsData); + } else { + break; + } + } + + $this->success = true; + $this->message = 'File Imported "'.$filename.'" Successfully'; + + } else { + $this->success = false; + $this->message = 'INVALID_FILE'; + } + + } + } catch(Exception $e){ + $this->success = false; + $this->message = $e->getMessage(); + } + } + + + public function exportList() + { + require_once 'classes/model/AdditionalTables.php'; + + $oCriteria = new Criteria('workflow'); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_UID); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_NAME); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_DESCRIPTION); + $oCriteria->addSelectColumn("'".G::LoadTranslation('ID_ACTION_EXPORT')."' as 'CH_SCHEMA'"); + $oCriteria->addSelectColumn("'".G::LoadTranslation('ID_ACTION_EXPORT')."' as 'CH_DATA'"); + + $uids = explode(',',$_GET['id']); + + foreach ($uids as $UID){ + if (!isset($CC)){ + $CC = $oCriteria->getNewCriterion(AdditionalTablesPeer::ADD_TAB_UID, $UID ,Criteria::EQUAL); + }else{ + $CC->addOr($oCriteria->getNewCriterion(AdditionalTablesPeer::ADD_TAB_UID, $UID ,Criteria::EQUAL)); + } + } + $oCriteria->add($CC); + $oCriteria->addAnd($oCriteria->getNewCriterion(AdditionalTablesPeer::ADD_TAB_UID, '', Criteria::NOT_EQUAL)); + + $oDataset = AdditionalTablesPeer::doSelectRS ( $oCriteria ); + $oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + + $addTables = Array(); + while( $oDataset->next() ) { + $addTables[] = $oDataset->getRow(); + } + + return $addTables; + } + + public function updateTag($httpData) + { + require_once 'classes/model/AdditionalTables.php'; + $oAdditionalTables = new AdditionalTables(); + $uid = $_REQUEST['ADD_TAB_UID']; + $value = $_REQUEST['value']; + + $repTabData = array( + 'ADD_TAB_UID' => $uid, + 'ADD_TAB_TAG' => $value + ); + $oAdditionalTables->update($repTabData); + } + /** * - protected functions (non callable from controller outside) - */ @@ -708,3 +921,19 @@ class pmTablesProxy extends HttpProxyController } +class aTablesMap{ + var $aMap; + + function route($uid){ + if( isset($this->aMap[$uid]) ){ + return $this->aMap[$uid]; + } else { + return $uid; + } + } + + function addRoute($item, $equal){ + $this->aMap[$item] = $equal; + } + +} \ No newline at end of file diff --git a/workflow/engine/menus/setup.php b/workflow/engine/menus/setup.php index b1ca42772..9ef65b321 100644 --- a/workflow/engine/menus/setup.php +++ b/workflow/engine/menus/setup.php @@ -42,10 +42,10 @@ if ($RBAC->userCanAccess('PM_SETUP_ADVANCE') == 1) $G_TMP_MENU->AddIdRawOption('CLEAR_CACHE', 'clearCompiled', G::LoadTranslation('ID_CLEAR_CACHE'), 'icon-rebuild-clean.png', "", 'settings' ); if ($RBAC->userCanAccess('PM_SETUP') == 1) { - $G_TMP_MENU->AddIdRawOption('ADDITIONAL_TABLES', '../additionalTables/additionalTablesList', G::LoadTranslation('ID_ADDITIONAL_TABLES'), 'icon-tables.png','', 'settings'); - $G_TMP_MENU->AddIdRawOption('REPORT_TABLES', '../reportTables/main', 'Report Tables', 'icon-tables.png','', 'settings'); + //$G_TMP_MENU->AddIdRawOption('ADDITIONAL_TABLES', '../additionalTables/additionalTablesList', G::LoadTranslation('ID_ADDITIONAL_TABLES'), 'icon-tables.png','', 'settings'); + //$G_TMP_MENU->AddIdRawOption('REPORT_TABLES', '../reportTables/main', 'Report Tables', 'icon-tables.png','', 'settings'); - $G_TMP_MENU->AddIdRawOption('PM_TABLES', '../pmTables', 'PM Tables 2', 'icon-tables.png','', 'settings'); + $G_TMP_MENU->AddIdRawOption('PM_TABLES', '../pmTables', G::LoadTranslation('ID_ADDITIONAL_TABLES'), 'icon-tables.png','', 'settings'); } $G_TMP_MENU->AddIdRawOption('WEBSERVICES', 'webServices', G::LoadTranslation('ID_WEB_SERVICES'), 'icon-webservices.png', '', 'settings'); @@ -62,3 +62,4 @@ $G_TMP_MENU->AddIdRawOption('GROUPS', '../groups/groups', G::LoadTranslation('ID $G_TMP_MENU->AddIdRawOption('DEPARTAMENTS', '../departments/departments', G::LoadTranslation('ID_DEPARTMENTS_USERS'), '', '', 'users'); $G_TMP_MENU->AddIdRawOption('ROLES', '../roles/roles_List', G::LoadTranslation('ID_ROLES'), '', '', 'users'); $G_TMP_MENU->AddIdRawOption('AUTHSOURCES', '../authSources/authSources_List', G::LoadTranslation('ID_AUTH_SOURCES'), '', '', 'users'); + diff --git a/workflow/engine/methods/additionalTables/additionalTablesAjax.php b/workflow/engine/methods/additionalTables/additionalTablesAjax.php index 8b740ac99..103d14c0f 100644 --- a/workflow/engine/methods/additionalTables/additionalTablesAjax.php +++ b/workflow/engine/methods/additionalTables/additionalTablesAjax.php @@ -47,20 +47,20 @@ if(isset($_POST['action'])) { break; case 'exportexporView': - global $G_PUBLISH; - require_once ( 'classes/class.xmlfield_InputPM.php' ); - require_once 'classes/model/AdditionalTables.php'; - - $G_PUBLISH = new Publisher(); - - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_UID); - $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_NAME); - $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_DESCRIPTION); - $oCriteria->add(AdditionalTablesPeer::ADD_TAB_UID, '', Criteria::NOT_EQUAL); + global $G_PUBLISH; + require_once ( 'classes/class.xmlfield_InputPM.php' ); + require_once 'classes/model/AdditionalTables.php'; + + $G_PUBLISH = new Publisher(); + + $oCriteria = new Criteria('workflow'); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_UID); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_NAME); + $oCriteria->addSelectColumn(AdditionalTablesPeer::ADD_TAB_DESCRIPTION); + $oCriteria->add(AdditionalTablesPeer::ADD_TAB_UID, '', Criteria::NOT_EQUAL); - $G_PUBLISH->AddContent('propeltable', 'additionalTables/paged-table', 'additionalTables/additionalTablesExportList', $oCriteria); - G::RenderPage('publish', 'raw'); + $G_PUBLISH->AddContent('propeltable', 'additionalTables/paged-table', 'additionalTables/additionalTablesExportList', $oCriteria); + G::RenderPage('publish', 'raw'); break; case 'updatePageSize': G::LoadClass('configuration'); @@ -86,29 +86,29 @@ if(isset($_POST['action'])) { break; case 'doExport': - # @Author: Erik Amaru Ortiz - - require_once 'classes/model/AdditionalTables.php'; - - $tables = explode(',', $_POST['tables']); - $schema = explode(',', $_POST['schema']); - $data = explode(',', $_POST['data']); + # @Author: Erik Amaru Ortiz - G::LoadCLass('net'); - $net = new NET(G::getIpAddress()); - + require_once 'classes/model/AdditionalTables.php'; + + $tables = explode(',', $_POST['tables']); + $schema = explode(',', $_POST['schema']); + $data = explode(',', $_POST['data']); + + G::LoadCLass('net'); + $net = new NET(G::getIpAddress()); + G::LoadClass("system"); $META = " \n-----== ProcessMaker Open Source Private Tables ==-----\n". - " @Ver: 1.0 Oct-2009\n". - " @Processmaker version: ".System::getVersion()."\n". - " -------------------------------------------------------\n". - " @Export Date: ".date("l jS \of F Y h:i:s A")."\n". - " @Server address: ".getenv('SERVER_NAME')." (".getenv('SERVER_ADDR').")\n". - " @Client address: ".$net->hostname."\n". - " @Workspace: ".SYS_SYS."\n". - " @Export trace back:\n\n"; - + " @Ver: 1.0 Oct-2009\n". + " @Processmaker version: ".System::getVersion()."\n". + " -------------------------------------------------------\n". + " @Export Date: ".date("l jS \of F Y h:i:s A")."\n". + " @Server address: ".getenv('SERVER_NAME')." (".getenv('SERVER_ADDR').")\n". + " @Client address: ".$net->hostname."\n". + " @Workspace: ".SYS_SYS."\n". + " @Export trace back:\n\n"; + $EXPORT_TRACEBACK = Array(); $c = 0; @@ -117,34 +117,29 @@ if(isset($_POST['action'])) { $aTable = new additionalTables(); $tRecord = $aTable->load($uid); $oAdditionalTables = new additionalTables(); - $ocaux = $oAdditionalTables->getDataCriteria($uid); - - $rs = AdditionalTablesPeer::DoSelectRs ($ocaux); - $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); - - $rows = Array(); - while($rs->next()){ - $rows[] = $rs->getRow(); - } - - array_push($EXPORT_TRACEBACK, Array( - 'uid' => $uid, - 'name' => $tRecord['ADD_TAB_NAME'], - 'num_regs' => sizeof($rows), - 'schema' => in_array($uid, $schema)? 'yes': 'no', - 'data' => in_array($uid, $data)? 'yes': 'no' + $table = $oAdditionalTables->getAllData($uid); + + $rows = $table['rows']; + $count = $table['count']; + + array_push($EXPORT_TRACEBACK, Array( + 'uid' => $uid, + 'name' => $tRecord['ADD_TAB_NAME'], + 'num_regs' => sizeof($rows), + 'schema' => in_array($uid, $schema)? 'yes': 'no', + 'data' => in_array($uid, $data)? 'yes': 'no' // 'schema' => ($schema[$c]=='Export')? 'yes': 'no', -// 'data' => ($data[$c]=='Export')? 'yes': 'no' - )); - } +// 'data' => ($data[$c]=='Export')? 'yes': 'no' + )); + } $sTrace = "TABLE UID\t\t\t\tTABLE NAME\tREGS\tSCHEMA\tDATA\n"; foreach($EXPORT_TRACEBACK as $row){ - $sTrace .= "{$row['uid']}\t{$row['name']}\t\t{$row['num_regs']}\t{$row['schema']}\t{$row['data']}\n"; + $sTrace .= "{$row['uid']}\t{$row['name']}\t\t{$row['num_regs']}\t{$row['schema']}\t{$row['data']}\n"; } $META .= $sTrace; - + ///////////////EXPORT PROCESS $PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP; $filenameOnly = 'SYS-'.strtoupper(SYS_SYS)."_".date("Y-m-d").'_'.date("Hi").".pmt"; @@ -152,71 +147,70 @@ if(isset($_POST['action'])) { $fp = fopen( $filename, "wb"); $bytesSaved = 0; - $bufferType = '@META'; - $fsData = sprintf("%09d", strlen($META)); - $fsbufferType = sprintf("%09d", strlen($bufferType)); + $bufferType = '@META'; + $fsData = sprintf("%09d", strlen($META)); + $fsbufferType = sprintf("%09d", strlen($bufferType)); $bytesSaved += fwrite($fp, $fsbufferType); //writing the size of $oData $bytesSaved += fwrite($fp, $bufferType); //writing the $oData $bytesSaved += fwrite($fp, $fsData); //writing the size of $oData $bytesSaved += fwrite($fp, $META); //writing the $oData foreach($EXPORT_TRACEBACK as $record){ - + if($record['schema'] == 'yes'){ - $oAdditionalTables = new AdditionalTables(); - $aData = $oAdditionalTables->load($record['uid'], true); - - $bufferType = '@SCHEMA'; - $SDATA = serialize($aData); - $fsUid = sprintf("%09d", strlen($record['uid'])); - $fsData = sprintf("%09d", strlen ($SDATA)); + $oAdditionalTables = new AdditionalTables(); + $aData = $oAdditionalTables->load($record['uid'], true); + + $bufferType = '@SCHEMA'; + $SDATA = serialize($aData); + $fsUid = sprintf("%09d", strlen($record['uid'])); + $fsData = sprintf("%09d", strlen ($SDATA)); $fsbufferType = sprintf("%09d", strlen($bufferType)); $bytesSaved += fwrite($fp, $fsbufferType); //writing the size of $oData - $bytesSaved += fwrite($fp, $bufferType); //writing the $oData + $bytesSaved += fwrite($fp, $bufferType); //writing the $oData $bytesSaved += fwrite($fp, $fsUid ); //writing the size of xml file $bytesSaved += fwrite($fp, $record['uid'] ); //writing the xmlfile $bytesSaved += fwrite($fp, $fsData); //writing the size of xml file $bytesSaved += fwrite($fp, $SDATA); //writing the xmlfile - } - + } + if($record['data'] == 'yes'){ - //export data - $oAdditionalTables = new additionalTables(); - $ocaux = $oAdditionalTables->getDataCriteria($record['uid']); - $rs = AdditionalTablesPeer::DoSelectRs ($ocaux); - $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); - $rows = Array(); - while($rs->next()) $rows[] = $rs->getRow(); - - $bufferType = '@DATA'; - $SDATA = serialize($rows); - $fsUid = sprintf("%09d", strlen($record['name'])); - $fsData = sprintf("%09d", strlen ($SDATA)); - $fsbufferType = sprintf("%09d", strlen($bufferType)); - - $bytesSaved += fwrite($fp, $fsbufferType); //writing the size of $oData - $bytesSaved += fwrite($fp, $bufferType); //writing the $oData - $bytesSaved += fwrite($fp, $fsUid ); //writing the size of xml file - $bytesSaved += fwrite($fp, $record['name'] ); //writing the xmlfile - $bytesSaved += fwrite($fp, $fsData); //writing the size of xml file - $bytesSaved += fwrite($fp, $SDATA); //writing the xmlfile - + //export data + $oAdditionalTables = new additionalTables(); + $table = $oAdditionalTables->getAllData($uid); + + $rows = $table['rows']; + $count = $table['count']; + + $bufferType = '@DATA'; + $SDATA = serialize($rows); + $fsUid = sprintf("%09d", strlen($record['name'])); + $fsData = sprintf("%09d", strlen ($SDATA)); + $fsbufferType = sprintf("%09d", strlen($bufferType)); + + $bytesSaved += fwrite($fp, $fsbufferType); //writing the size of $oData + $bytesSaved += fwrite($fp, $bufferType); //writing the $oData + $bytesSaved += fwrite($fp, $fsUid ); //writing the size of xml file + $bytesSaved += fwrite($fp, $record['name'] ); //writing the xmlfile + $bytesSaved += fwrite($fp, $fsData); //writing the size of xml file + $bytesSaved += fwrite($fp, $SDATA); //writing the xmlfile + } } - fclose ($fp); - - $filenameLink = "doExport?f={$filenameOnly}"; - $aFields['SIZE'] = round(($bytesSaved/1024), 2)." Kb"; - $aFields['META'] = "
".$META."
"; - $aFields['FILENAME'] = $filenameOnly; - $aFields['FILENAME_LINK'] = $filenameLink; - - $G_PUBLISH = new Publisher(); - $G_PUBLISH->AddContent('xmlform', 'xmlform', 'additionalTables/doExport', '', $aFields, ''); - G::RenderPage('publish', 'raw'); - + fclose ($fp); + + $filenameLink = "../additionalTables/doExport?f={$filenameOnly}"; + $aFields['SIZE'] = round(($bytesSaved/1024), 2)." Kb"; + $aFields['META'] = "
".$META."
"; + $aFields['FILENAME'] = $filenameOnly; + $aFields['FILENAME_LINK'] = $filenameLink; + + $G_PUBLISH = new Publisher(); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'additionalTables/doExport', '', $aFields, ''); + G::RenderPage('publish', 'raw'); + break; } diff --git a/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css b/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css index 1e8eae447..f50764fcb 100644 --- a/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css +++ b/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css @@ -686,6 +686,12 @@ antes funcionaba. background-image:url( /images/icons_silk/sprites.png) !important; background-position:0 -5815px !important; } +.ICON_PM_TABLES{ + /*ss_database_table*/ + background-image:url( /images/icons_silk/sprites.png) !important; + background-position:0 -5815px !important; +} + .ICON_LANGUAGES{ /*ss_text_dropcaps*/ diff --git a/workflow/engine/templates/pmTables/export.html b/workflow/engine/templates/pmTables/export.html new file mode 100644 index 000000000..432f567b5 --- /dev/null +++ b/workflow/engine/templates/pmTables/export.html @@ -0,0 +1,3 @@ +
+
+
diff --git a/workflow/engine/templates/pmTables/export.js b/workflow/engine/templates/pmTables/export.js new file mode 100644 index 000000000..961945b8c --- /dev/null +++ b/workflow/engine/templates/pmTables/export.js @@ -0,0 +1,169 @@ +var store; +var cmodel; +var smodel; +var infoGrid; +var viewport; + +var cancelButton; +var exportButton; + +var w; + +Ext.onReady(function(){ + Ext.QuickTips.init(); + + var reader = new Ext.data.ArrayReader({}, [{name: 'action'}]); + + var comboStore = new Ext.data.Store({ + reader: reader, + data: Ext.grid.dummyData + }); + + exportButton = new Ext.Action({ + text: _('ID_EXPORT'), + iconCls: 'silk-add', + icon: '/images/export.png', + handler: ExportPMTables + }); + + cancelButton = new Ext.Action({ + text: _('ID_BACK'), + icon: '/images/back-icon.png', + handler: CancelExport + }); + + store = new Ext.data.GroupingStore( { + proxy : new Ext.data.HttpProxy({ + url: '../pmTablesProxy/exportList?id='+EXPORT_TABLES.UID_LIST + }), + reader : new Ext.data.JsonReader( { + root: '', + fields : [ + {name : 'ADD_TAB_UID'}, + {name : 'ADD_TAB_NAME'}, + {name : 'ADD_TAB_DESCRIPTION'}, + {name : 'CH_SCHEMA'}, + {name : 'CH_DATA'} + ] + }) + }); + + var action_edit = new Ext.form.ComboBox({ + typeAhead: true, + triggerAction: 'all', + mode: 'local', + store: comboStore, + displayField: 'action', + valueField: 'action' + }); + + cmodel = new Ext.grid.ColumnModel({ + defaults: { + width: 10, + sortable: true + }, + columns: [ + new Ext.grid.RowNumberer(), + //smodel, + {id:'ADD_TAB_UID', dataIndex: 'ADD_TAB_UID', hidden:true, hideable:false}, + {header: _('ID_NAME'), dataIndex: 'ADD_TAB_NAME', width: 20, align:'left'}, + {header: _('ID_DESCRIPTION'), dataIndex: 'ADD_TAB_DESCRIPTION', width: 50, hidden:false, align:'left'},//, + {header: _('ID_SCHEMA'), dataIndex: 'CH_SCHEMA', hidden: false, width: 20, editor: action_edit, align: 'center'}, + {header: 'DATA', dataIndex: 'CH_DATA', hidden: false, width: 20, editor: action_edit, align: 'center'} + ] + }); + + infoGrid = new Ext.grid.EditorGridPanel({ + store: store, + cm: cmodel, + width: 600, + height: 300, + title: _('ID_ADDITIONAL_TABLES') + ': ' +_('ID_TITLE_EXPORT_TOOL'), + frame: false, + clicksToEdit: 1, + id: 'infoGrid', + + sm: new Ext.grid.RowSelectionModel({singleSelect: false}), + tbar:[exportButton, {xtype: 'tbfill'} ,cancelButton],//'-', editButton, deleteButton,'-', dataButton,{xtype: 'tbfill'} , importButton, exportButton], + view: new Ext.grid.GroupingView({ + forceFit:true, + groupTextTpl: '{text}' + }) + }); + + infoGrid.store.load(); + + viewport = new Ext.Viewport({ + layout: 'fit', + autoScroll: false, + items: [ + infoGrid + ] + }); + +}); + +//Cancels Export View +CancelExport = function(){ + history.back(); +}; + +//Export Schema/Data from PM Tables +ExportPMTables = function(){ + iGrid = Ext.getCmp('infoGrid'); + var storeExport = iGrid.getStore(); + var UIDs = new Array(); + var SCHs = new Array(); + var DATs = new Array(); + for (var r=0; r'+tag+': '+ v : v; }}); cmodelColumns.push({header: 'Table Type', dataIndex: 'PRO_UID', width: 120, align:'left', renderer: function(v,p,r){ - color = r.get('PRO_UID') ? 'green' : 'blue'; - value = r.get('PRO_UID') ? 'Table' : 'Report'; + color = r.get('PRO_UID') ? 'blue' : 'green'; + value = r.get('PRO_UID') ? 'Report' : 'Table'; return ''+value+' '; }}); @@ -287,6 +324,18 @@ Ext.onReady(function(){ function (grid, rowIndex, evt) { var sm = grid.getSelectionModel(); sm.selectRow(rowIndex, sm.isSelected(rowIndex)); + + var rowsSelected = Ext.getCmp('infoGrid').getSelectionModel().getSelections(); + tag = rowsSelected[0].get('ADD_TAB_TAG'); + text = tag? 'Convert to native Report Table': 'Convert to Simple Report'; + if (externalOption) { + externalOption.setText(text); + if (rowsSelected[0].get('PRO_UID')) { + externalOption.setDisabled(false); + } else { + externalOption.setDisabled(true); + } + } }, this ); @@ -303,6 +352,7 @@ Ext.onReady(function(){ infoGrid ] }); + }); //Funtion Handles Context Menu Opening @@ -392,14 +442,104 @@ DeletePMTable = function() { //Load Import PM Table Form ImportPMTable = function(){ - location.href = 'additionalTablesToImport'; -}; + + var w = new Ext.Window({ + title: '', + width: 420, + height: 160, + modal: true, + autoScroll: false, + maximizable: false, + resizable: false, + items: [ + new Ext.FormPanel({ + /*renderTo: 'form-panel',*/ + id:'uploader', + fileUpload: true, + width: 400, + frame: true, + title: 'Import PM Table', + autoHeight: false, + bodyStyle: 'padding: 10px 10px 0 10px;', + labelWidth: 50, + defaults: { + anchor: '90%', + allowBlank: false, + msgTarget: 'side' + }, + items: [{ + xtype: 'fileuploadfield', + id: 'form-file', + emptyText: 'Select a .pmt file', + fieldLabel: _('ID_FILE'), + name: 'form[FILENAME]', + buttonText: '', + buttonCfg: { + iconCls: 'upload-icon' + } + }, { + xtype: 'checkbox', + fieldLabel: '', + boxLabel: 'Overwrite if exists?', + name: 'form[OVERWRITE]' + }], + buttons: [{ + text: _('ID_UPLOAD'), + handler: function(){ + var uploader = Ext.getCmp('uploader'); + + if(uploader.getForm().isValid()){ + uploader.getForm().submit({ + url: 'pmTablesProxy/import', + waitMsg: 'Uploading file...', + success: function(o, resp){ + w.close(); + infoGrid.store.reload(); + + PMExt.notify('IMPORT RESULT', resp.result.message); + }, + failure: function(o, resp){ + w.close(); + //alert('ERROR "'+resp.result.msg+'"'); + Ext.MessageBox.show({title: '', msg: resp.result.msg, buttons: + Ext.MessageBox.OK, animEl: 'mb9', fn: function(){}, icon: + Ext.MessageBox.ERROR}); + //setTimeout(function(){Ext.MessageBox.hide(); }, 2000); + } + }); + } + } + }/*,{ + text: 'Reset', + handler: function(){ + uploader = Ext.getCmp('uploader'); + uploader.getForm().reset(); + } + }*/,{ + text: TRANSLATIONS.ID_CANCEL, + handler: function(){ + w.close(); + } + }] + }) + ]/*, + listeners:{ + show:function() { + this.loadMask = new Ext.LoadMask(this.body, { + msg:'Loading. Please wait...' + }); + } + }*/ + }); + w.show(); +} //Load Export PM Tables Form ExportPMTable = function(){ iGrid = Ext.getCmp('infoGrid'); rowsSelected = iGrid.getSelectionModel().getSelections(); - location.href = 'additionalTablesToExport?sUID='+RetrieveRowsID(rowsSelected)+'&rand='+Math.random(); + //location.href = 'additionalTablesToExport?sUID='+RetrieveRowsID(rowsSelected)+'&rand='+Math.random(); + location.href = 'pmTables/export?id='+RetrieveRowsID(rowsSelected)+'&rand='+Math.random(); }; //Load PM TAble Data @@ -434,4 +574,24 @@ DoSearch = function(){ GridByDefault = function(){ searchText.reset(); infoGrid.store.load(); -}; \ No newline at end of file +}; + +function updateTag(value) +{ + var rowsSelected = Ext.getCmp('infoGrid').getSelectionModel().getSelections(); + + Ext.Ajax.request({ + url: 'pmTablesProxy/updateTag', + params: { + ADD_TAB_UID: rowsSelected[0].get('ADD_TAB_UID'), + value: rowsSelected[0].get('ADD_TAB_TAG') ? '': value + }, + success: function(resp){ + Ext.getCmp('infoGrid').store.reload(); + }, + failure: function(obj, resp){ + Ext.Msg.alert( _('ID_ERROR'), resp.result.msg); + } + }); +} +