From e6466474b1a13f1d55048f27401ccaea3cec1990 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Fri, 19 Jan 2018 12:27:47 +0200 Subject: [PATCH] Fixed missing placeholder strings for views in compiler --- README.md | 4 +- admin/README.txt | 4 +- admin/access.xml | 2 - admin/helpers/compiler.php | 2 +- admin/helpers/compiler/c_Fields.php | 26 +- admin/helpers/compiler/e_Interpretation.php | 31 +- admin/helpers/compiler/f_Infusion.php | 147 +- admin/helpers/componentbuilder.php | 1408 ++++++++--------- .../en-GB/en-GB.com_componentbuilder.ini | 4 - .../en-GB/en-GB.com_componentbuilder.sys.ini | 4 - componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 704 +-------- 12 files changed, 814 insertions(+), 1524 deletions(-) diff --git a/README.md b/README.md index 1a5b2d5eb..5b96e453a 100644 --- a/README.md +++ b/README.md @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 17th January, 2018 ++ *Last Build*: 19th January, 2018 + *Version*: 2.6.12 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **181174** ++ *Line count*: **180462** + *Field count*: **1573** + *File count*: **1160** + *Folder count*: **186** diff --git a/admin/README.txt b/admin/README.txt index 1a5b2d5eb..5b96e453a 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 17th January, 2018 ++ *Last Build*: 19th January, 2018 + *Version*: 2.6.12 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **181174** ++ *Line count*: **180462** + *Field count*: **1573** + *File count*: **1160** + *Folder count*: **186** diff --git a/admin/access.xml b/admin/access.xml index 9224fdb5d..a27e152b2 100644 --- a/admin/access.xml +++ b/admin/access.xml @@ -261,8 +261,6 @@ - - diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index 32ebd78fa..c460f0b13 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -65,7 +65,7 @@ class Compiler extends Infusion { // to check the compiler speed $this->time_start = microtime(true); - // first we run the perent constructor + // first we run the perent constructors if (parent::__construct($config)) { // set temp directory diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 6d30f7308..b1d3f468f 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -375,33 +375,19 @@ class Fields extends Structure /** * set the Field set of a view * - * @param array $view The view data - * @param string $component The component name + * @param array $view The view data + * @param string $component The component name + * @param string $viewName The single view name + * @param string $listViewName The list view name * * @return string The fields set in xml * */ - public function setFieldSet($view, $component) + public function setFieldSet($view, $component, $viewName, $listViewName) { // setup the fieldset of this view if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields)) { - // setup the list view and single view name - $listViewName = ComponentbuilderHelper::safeString($view['settings']->name_list); - $viewName = ComponentbuilderHelper::safeString($view['settings']->name_single); - // set some place holder for this view - $this->placeholders['###view###'] = $viewName; - $this->placeholders['###VIEW###'] = strtoupper($viewName); - $this->placeholders['###View###'] = ucfirst($viewName); - $this->placeholders['[[[view]]]'] = $this->placeholders['###view###']; - $this->placeholders['[[[VIEW]]]'] = $this->placeholders['###VIEW###']; - $this->placeholders['[[[View]]]'] = $this->placeholders['###View###']; - $this->placeholders['###views###'] = $listViewName; - $this->placeholders['###VIEWS###'] = strtoupper($listViewName); - $this->placeholders['###Views###'] = ucfirst($listViewName); - $this->placeholders['[[[views]]]'] = $this->placeholders['###views###']; - $this->placeholders['[[[VIEWS]]]'] = $this->placeholders['###VIEWS###']; - $this->placeholders['[[[Views]]]'] = $this->placeholders['###Views###']; // add metadata to the view if (isset($view['metadata']) && $view['metadata']) { @@ -753,8 +739,6 @@ class Fields extends Structure // count the static field created $this->fieldCount++; } - // just to be safe, lets clear the view placeholders - $this->clearFromPlaceHolders('view'); // return the set return $this->xmlPrettyPrint($XML, 'fieldset'); } diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 9e6bd2de5..d85b00c5e 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -3339,8 +3339,7 @@ class Interpretation extends Fields $path = '/administrator/components/com_' . $this->fileContentStatic['###component###'] . '/assets/js/' . $view['settings']->code . '.js'; } // add script to file - $this->fileContentDynamic[$view['settings']->code]['###' . $TARGET . '_JAVASCRIPT_FILE###'] - = $this->setPlaceholders($view['settings']->javascript_file, $this->placeholders); + $this->fileContentDynamic[$view['settings']->code]['###' . $TARGET . '_JAVASCRIPT_FILE###'] = $this->setPlaceholders($view['settings']->javascript_file, $this->placeholders); // add script to view return PHP_EOL . PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Add View JavaScript File" . PHP_EOL . "\t\t" . $this->setIncludeLibScript($path); } @@ -8104,36 +8103,10 @@ class Interpretation extends Fields $query .= PHP_EOL . "\t\treturn false;"; $query .= PHP_EOL . "\t}"; - // set some placeholders just incase - if (!isset($this->placeholders['###view###']) && !isset($this->placeholders['[[[view]]]'])) - { - $this->placeholders['###view###'] = $viewName_single; - $this->placeholders['[[[view]]]'] = $viewName_single; - $_viewSet = true; - } - if (!isset($this->placeholders['###views###']) && !isset($this->placeholders['[[[views]]]'])) - { - $this->placeholders['###views###'] = $viewName_list; - $this->placeholders['[[[views]]]'] = $viewName_list; - $_viewsSet = true; - } - // add getExImPortHeaders - $query .= $this->getCustomScriptBuilder('php_import_headers', 'import_' . $viewName_list, PHP_EOL . PHP_EOL, null, true, + $query .= $this->getCustomScriptBuilder('php_import_headers', 'import_' . $viewName_list, PHP_EOL . PHP_EOL, null, true, // set a default script for those with no custom script PHP_EOL . PHP_EOL . $this->setPlaceholders(ComponentbuilderHelper::getImportScripts('headers'), $this->placeholders)); - - // remove place holders if not needed (to not be suprized) - if (isset($_viewSet)) - { - unset($this->placeholders['###view###']); - unset($this->placeholders['[[[view]]]']); - } - if (isset($_viewsSet)) - { - unset($this->placeholders['###views###']); - unset($this->placeholders['[[[views]]]']); - } } return $query; } diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php index 790495e89..8465dbf8f 100644 --- a/admin/helpers/compiler/f_Infusion.php +++ b/admin/helpers/compiler/f_Infusion.php @@ -236,14 +236,25 @@ class Infusion extends Interpretation // start dynamic build foreach ($this->componentData->admin_views as $view) { - // just to be safe, lets clear the view placeholders - $this->clearFromPlaceHolders('view'); // set the target $this->target = 'admin'; $this->lang = 'admin'; - // set main keys - $viewName_single = ComponentbuilderHelper::safeString($view['settings']->name_single); - $viewName_list = ComponentbuilderHelper::safeString($view['settings']->name_list); + + // set single view + if (isset($view['settings']->name_single)) + { + $viewName_single = ComponentbuilderHelper::safeString($view['settings']->name_single); + } + + // set list view + if (isset($view['settings']->name_list)) + { + $viewName_list = ComponentbuilderHelper::safeString($view['settings']->name_list); + } + + // set the view placeholders + $this->setViewPlaceholders($view['settings']); + // set site edit view array if (isset($view['edit_create_site_view']) && $view['edit_create_site_view']) { @@ -258,36 +269,14 @@ class Infusion extends Interpretation // set view array $viewarray[] = "\t\t\t\t'" . $viewName_single . "' => '" . $viewName_list . "'"; // set the view names - if ($view['settings']->name_single != 'null') + if (isset($view['settings']->name_single) && $view['settings']->name_single != 'null') { - // ###VIEW### <<>> - $viewName_u = ComponentbuilderHelper::safeString($view['settings']->name_single, 'U'); - $this->fileContentDynamic[$viewName_single]['###VIEW###'] = $viewName_u; - $this->fileContentDynamic[$viewName_list]['###VIEW###'] = $viewName_u; - - // ###View### <<>> - $viewName_f = ComponentbuilderHelper::safeString($view['settings']->name_single, 'F'); - $this->fileContentDynamic[$viewName_single]['###View###'] = $viewName_f; - $this->fileContentDynamic[$viewName_list]['###View###'] = $viewName_f; - - // ###view### <<>> - $this->fileContentDynamic[$viewName_single]['###view###'] = $viewName_single; - $this->fileContentDynamic[$viewName_list]['###view###'] = $viewName_single; - - // set some place holder for the views - $this->placeholders['###view###'] = $viewName_single; - $this->placeholders['###View###'] = $viewName_f; - $this->placeholders['###VIEW###'] = $viewName_u; - $this->placeholders['[[[view]]]'] = $viewName_single; - $this->placeholders['[[[View]]]'] = $viewName_f; - $this->placeholders['[[[VIEW]]]'] = $viewName_u; - // set license per view if needed $this->setLockLicensePer($viewName_single, $this->target); $this->setLockLicensePer($viewName_list, $this->target); // ###FIELDSETS### <<>> - $this->fileContentDynamic[$viewName_single]['###FIELDSETS###'] = $this->setFieldSet($view, $this->fileContentStatic['###component###']); + $this->fileContentDynamic[$viewName_single]['###FIELDSETS###'] = $this->setFieldSet($view, $this->fileContentStatic['###component###'], $viewName_single, $viewName_list); // ###ACCESSCONTROL### <<>> $this->fileContentDynamic[$viewName_single]['###ACCESSCONTROL###'] = $this->setFieldSetAccessControl($viewName_single); @@ -391,35 +380,15 @@ class Infusion extends Interpretation } } // set the views names - if ($view['settings']->name_list != 'null') + if (isset($view['settings']->name_list) && $view['settings']->name_list != 'null') { $this->lang = 'admin'; - // ###VIEWS### <<>> - $viewsName_u = ComponentbuilderHelper::safeString($view['settings']->name_list, 'U'); - $this->fileContentDynamic[$viewName_list]['###VIEWS###'] = $viewsName_u; - $this->fileContentDynamic[$viewName_single]['###VIEWS###'] = $viewsName_u; - // ###Views### <<>> - $viewsName_f = ComponentbuilderHelper::safeString($view['settings']->name_list, 'F'); - $this->fileContentDynamic[$viewName_list]['###Views###'] = $viewsName_f; - $this->fileContentDynamic[$viewName_single]['###Views###'] = $viewsName_f; - - // ###views### <<>> - $this->fileContentDynamic[$viewName_list]['###views###'] = $viewName_list; - $this->fileContentDynamic[$viewName_single]['###views###'] = $viewName_list; // ###ICOMOON### <<>> $this->fileContentDynamic[$viewName_list]['###ICOMOON###'] = $view['icomoon']; - // set some place holder for the views - $this->placeholders['###views###'] = $viewName_list; - $this->placeholders['###Views###'] = $viewsName_f; - $this->placeholders['###VIEWS###'] = $viewsName_u; - $this->placeholders['[[[views]]]'] = $viewName_list; - $this->placeholders['[[[Views]]]'] = $viewsName_f; - $this->placeholders['[[[VIEWS]]]'] = $viewsName_u; - // set the export/import option - if (isset($view['port']) && $view['port']) + if (isset($view['port']) && $view['port'] || 1 == $view['settings']->add_custom_import) { $this->eximportView[$viewName_list] = true; if (1 == $view['settings']->add_custom_import) @@ -1083,6 +1052,82 @@ class Infusion extends Interpretation return false; } + /** + * Set the view place holders to global scope + * + * @param object $view The view settings + * + * @ return void + */ + protected function setViewPlaceholders(&$view) + { + // just to be safe, lets clear previous view placeholders + $this->clearFromPlaceHolders('view'); + + // ###VIEW### <<>> + if (isset($view->name_single)) + { + // set main keys + $viewName_single = ComponentbuilderHelper::safeString($view->name_single); + $viewName_u = ComponentbuilderHelper::safeString($view->name_single, 'U'); + $viewName_f = ComponentbuilderHelper::safeString($view->name_single, 'F'); + + // set some place holder for the views + $this->placeholders['###view###'] = $viewName_single; + $this->placeholders['###View###'] = $viewName_f; + $this->placeholders['###VIEW###'] = $viewName_u; + $this->placeholders['[[[view]]]'] = $viewName_single; + $this->placeholders['[[[View]]]'] = $viewName_f; + $this->placeholders['[[[VIEW]]]'] = $viewName_u; + } + + // ###VIEWS### <<>> + if (isset($view->name_list)) + { + $viewName_list = ComponentbuilderHelper::safeString($view->name_list); + $viewsName_u = ComponentbuilderHelper::safeString($view->name_list, 'U'); + $viewsName_f = ComponentbuilderHelper::safeString($view->name_list, 'F'); + + // set some place holder for the views + $this->placeholders['###views###'] = $viewName_list; + $this->placeholders['###Views###'] = $viewsName_f; + $this->placeholders['###VIEWS###'] = $viewsName_u; + $this->placeholders['[[[views]]]'] = $viewName_list; + $this->placeholders['[[[Views]]]'] = $viewsName_f; + $this->placeholders['[[[VIEWS]]]'] = $viewsName_u; + } + + // ###view### <<>> + if (isset($viewName_single)) + { + $this->fileContentDynamic[$viewName_single]['###view###'] = $viewName_single; + $this->fileContentDynamic[$viewName_single]['###VIEW###'] = $viewName_u; + $this->fileContentDynamic[$viewName_single]['###View###'] = $viewName_f; + + if (isset($viewName_list)) + { + $this->fileContentDynamic[$viewName_list]['###view###'] = $viewName_single; + $this->fileContentDynamic[$viewName_list]['###VIEW###'] = $viewName_u; + $this->fileContentDynamic[$viewName_list]['###View###'] = $viewName_f; + } + } + + // ###views### <<>> + if (isset($viewName_list)) + { + $this->fileContentDynamic[$viewName_list]['###views###'] = $viewName_list; + $this->fileContentDynamic[$viewName_list]['###VIEWS###'] = $viewsName_u; + $this->fileContentDynamic[$viewName_list]['###Views###'] = $viewsName_f; + + if (isset($viewName_single)) + { + $this->fileContentDynamic[$viewName_single]['###views###'] = $viewName_list; + $this->fileContentDynamic[$viewName_single]['###VIEWS###'] = $viewsName_u; + $this->fileContentDynamic[$viewName_single]['###Views###'] = $viewsName_f; + } + } + } + /** * Build the lang values and insert to fiel * diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index ea0eb5ad2..16bdd3081 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -157,7 +157,709 @@ abstract class ComponentbuilderHelper } return $object; } - + + public static function getImportScripts($type, $fieldName = false) + { + // if field name is passed the convert to type + if ($fieldName) + { + $fieldNames = array( + 'php_import_display' => 'display', + 'php_import_setdata' => 'setdata', + 'php_import_save' => 'save', + 'html_import_view' => 'view', + 'php_import' => 'import', + 'php_import_ext' => 'ext', + 'php_import_headers' => 'headers' + ); + // first check if the field name is found + if (isset($fieldNames[$type])) + { + $type = $fieldNames[$type]; + } + else + { + return ''; + } + } + $script = array(); + if ('display' === $type) + { + // set the display script + $script['display'][] = "\tprotected \$headerList;"; + $script['display'][] = "\tprotected \$hasPackage = false;"; + $script['display'][] = "\tprotected \$headers;"; + $script['display'][] = "\tprotected \$hasHeader = 0;"; + $script['display'][] = "\tprotected \$dataType;"; + $script['display'][] = "\n\tpublic function display(\$tpl = null)"; + $script['display'][] = "\t{"; + $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t// Include helper submenu"; + $script['display'][] = "\t\t\t###-#-#-Component###Helper::addSubmenu('import');"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t\$paths = new stdClass;"; + $script['display'][] = "\t\t\$paths->first = '';"; + $script['display'][] = "\t\t\$state = \$this->get('state');"; + $script['display'][] = "\n\t\t\$this->paths = &\$paths;"; + $script['display'][] = "\t\t\$this->state = &\$state;"; + $script['display'][] = "\t\t// get global action permissions"; + $script['display'][] = "\t\t\$this->canDo = ###-#-#-Component###Helper::getActions('import');"; + $script['display'][] = "\n\t\t// We don't need toolbar in the modal window."; + $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t\$this->addToolbar();"; + $script['display'][] = "\t\t\t\$this->sidebar = JHtmlSidebar::render();"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// get the session object"; + $script['display'][] = "\t\t\$session = JFactory::getSession();"; + $script['display'][] = "\t\t// check if it has package"; + $script['display'][] = "\t\t\$this->hasPackage \t= \$session->get('hasPackage', false);"; + $script['display'][] = "\t\t\$this->dataType \t= \$session->get('dataType', false);"; + $script['display'][] = "\t\tif(\$this->hasPackage && \$this->dataType)"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t\$this->headerList \t= json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false),true);"; + $script['display'][] = "\t\t\t\$this->headers \t\t= ###-#-#-Component###Helper::getFileHeaders(\$this->dataType);"; + $script['display'][] = "\t\t\t// clear the data type"; + $script['display'][] = "\t\t\t\$session->clear('dataType');"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// Check for errors."; + $script['display'][] = "\t\tif (count(\$errors = \$this->get('Errors'))){"; + $script['display'][] = "\t\t\tthrow new Exception(implode(".'"\n", $errors), 500);'; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// Display the template"; + $script['display'][] = "\t\tparent::display(\$tpl);"; + $script['display'][] = "\t}"; + } + elseif ('setdata' === $type) + { + // set the setdata script + $script['setdata'] = array(); + $script['setdata'][] = "\t/**"; + $script['setdata'][] = "\t* Set the data from the spreadsheet to the database"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t* @param string \$package Paths to the uploaded package file"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t* @return boolean false on failure"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t**/"; + $script['setdata'][] = "\tprotected function setData(\$package,\$table,\$target_headers)"; + $script['setdata'][] = "\t{"; + $script['setdata'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$target_headers))"; + $script['setdata'][] = "\t\t{"; + $script['setdata'][] = "\t\t\t// make sure the file is loaded\t\t"; + $script['setdata'][] = "\t\t\tJLoader::import('PHPExcel', JPATH_COMPONENT_ADMINISTRATOR . '/helpers');"; + $script['setdata'][] = "\t\t\t\$jinput = JFactory::getApplication()->input;"; + $script['setdata'][] = "\t\t\tforeach(\$target_headers as \$header)"; + $script['setdata'][] = "\t\t\t{"; + $script['setdata'][] = "\t\t\t\t\$data['target_headers'][\$header] = \$jinput->getString(\$header, null);"; + $script['setdata'][] = "\t\t\t}"; + $script['setdata'][] = "\t\t\t// set the data"; + $script['setdata'][] = "\t\t\tif(isset(\$package['dir']))"; + $script['setdata'][] = "\t\t\t{"; + $script['setdata'][] = "\t\t\t\t\$inputFileType = PHPExcel_IOFactory::identify(\$package['dir']);"; + $script['setdata'][] = "\t\t\t\t\$excelReader = PHPExcel_IOFactory::createReader(\$inputFileType);"; + $script['setdata'][] = "\t\t\t\t\$excelReader->setReadDataOnly(true);"; + $script['setdata'][] = "\t\t\t\t\$excelObj = \$excelReader->load(\$package['dir']);"; + $script['setdata'][] = "\t\t\t\t\$data['array'] = \$excelObj->getActiveSheet()->toArray(null, true,true,true);"; + $script['setdata'][] = "\t\t\t\t\$excelObj->disconnectWorksheets();"; + $script['setdata'][] = "\t\t\t\tunset(\$excelObj);"; + $script['setdata'][] = "\t\t\t\treturn \$this->save(\$data,\$table);"; + $script['setdata'][] = "\t\t\t}"; + $script['setdata'][] = "\t\t}"; + $script['setdata'][] = "\t\treturn false;"; + $script['setdata'][] = "\t}"; + } + elseif ('headers' === $type) + { + $script['headers'] = array(); + $script['headers'][] = "\t/**"; + $script['headers'][] = "\t* Method to get header."; + $script['headers'][] = "\t*"; + $script['headers'][] = "\t* @return mixed An array of data items on success, false on failure."; + $script['headers'][] = "\t*/"; + $script['headers'][] = "\tpublic function getExImPortHeaders()"; + $script['headers'][] = "\t{"; + $script['headers'][] = "\t\t// Get a db connection."; + $script['headers'][] = "\t\t\$db = JFactory::getDbo();"; + $script['headers'][] = "\t\t// get the columns"; + $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__###-#-#-component###_###-#-#-view###\");"; + $script['headers'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$columns))"; + $script['headers'][] = "\t\t{"; + $script['headers'][] = "\t\t\t// remove the headers you don't import/export."; + $script['headers'][] = "\t\t\tunset(\$columns['asset_id']);"; + $script['headers'][] = "\t\t\tunset(\$columns['checked_out']);"; + $script['headers'][] = "\t\t\tunset(\$columns['checked_out_time']);"; + $script['headers'][] = "\t\t\t\$headers = new stdClass();"; + $script['headers'][] = "\t\t\tforeach (\$columns as \$column => \$type)"; + $script['headers'][] = "\t\t\t{"; + $script['headers'][] = "\t\t\t\t\$headers->{\$column} = \$column;"; + $script['headers'][] = "\t\t\t}"; + $script['headers'][] = "\t\t\treturn \$headers;"; + $script['headers'][] = "\t\t}"; + $script['headers'][] = "\t\treturn false;"; + $script['headers'][] = "\t}"; + } + elseif ('save' === $type) + { + $script['save'] = array(); + $script['save'][] = "\t/**"; + $script['save'][] = "\t* Save the data from the file to the database"; + $script['save'][] = "\t*"; + $script['save'][] = "\t* @param string \$package Paths to the uploaded package file"; + $script['save'][] = "\t*"; + $script['save'][] = "\t* @return boolean false on failure"; + $script['save'][] = "\t*"; + $script['save'][] = "\t**/"; + $script['save'][] = "\tprotected function save(\$data,\$table)"; + $script['save'][] = "\t{"; + $script['save'][] = "\t\t// import the data if there is any"; + $script['save'][] = "\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']))"; + $script['save'][] = "\t\t{"; + $script['save'][] = "\t\t\t// get user object"; + $script['save'][] = "\t\t\t\$user \t\t= JFactory::getUser();"; + $script['save'][] = "\t\t\t// remove header if it has headers"; + $script['save'][] = "\t\t\t\$id_key \t= \$data['target_headers']['id'];"; + $script['save'][] = "\t\t\t\$published_key \t= \$data['target_headers']['published'];"; + $script['save'][] = "\t\t\t\$ordering_key \t= \$data['target_headers']['ordering'];"; + $script['save'][] = "\t\t\t// get the first array set"; + $script['save'][] = "\t\t\t\$firstSet = reset(\$data['array']);"; + $script['save'][] = ""; + $script['save'][] = "\t\t\t// check if first array is a header array and remove if true"; + $script['save'][] = "\t\t\tif(\$firstSet[\$id_key] == 'id' || \$firstSet[\$published_key] == 'published' || \$firstSet[\$ordering_key] == 'ordering')"; + $script['save'][] = "\t\t\t{"; + $script['save'][] = "\t\t\t\tarray_shift(\$data['array']);"; + $script['save'][] = "\t\t\t}"; + $script['save'][] = "\t\t\t"; + $script['save'][] = "\t\t\t// make sure there is still values in array and that it was not only headers"; + $script['save'][] = "\t\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_###-#-#-component###') && \$user->authorise('core.import', 'com_###-#-#-component###'))"; + $script['save'][] = "\t\t\t{"; + $script['save'][] = "\t\t\t\t// set target."; + $script['save'][] = "\t\t\t\t\$target\t= array_flip(\$data['target_headers']);"; + $script['save'][] = "\t\t\t\t// Get a db connection."; + $script['save'][] = "\t\t\t\t\$db = JFactory::getDbo();"; + $script['save'][] = "\t\t\t\t// set some defaults"; + $script['save'][] = "\t\t\t\t\$todayDate\t\t= JFactory::getDate()->toSql();"; + $script['save'][] = "\t\t\t\t// get global action permissions"; + $script['save'][] = "\t\t\t\t\$canDo\t\t\t= ###-#-#-Component###Helper::getActions(\$table);"; + $script['save'][] = "\t\t\t\t\$canEdit\t\t= \$canDo->get('core.edit');"; + $script['save'][] = "\t\t\t\t\$canState\t\t= \$canDo->get('core.edit.state');"; + $script['save'][] = "\t\t\t\t\$canCreate\t\t= \$canDo->get('core.create');"; + $script['save'][] = "\t\t\t\t\$hasAlias\t\t= \$this->getAliasesUsed(\$table);"; + $script['save'][] = "\t\t\t\t// prosses the data"; + $script['save'][] = "\t\t\t\tforeach(\$data['array'] as \$row)"; + $script['save'][] = "\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\$found = false;"; + $script['save'][] = "\t\t\t\t\tif (isset(\$row[\$id_key]) && is_numeric(\$row[\$id_key]) && \$row[\$id_key] > 0)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// raw items import & update!"; + $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t\$query"; + $script['save'][] = "\t\t\t\t\t\t\t->select('version')"; + $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__###-#-#-component###_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->where(\$db->quoteName('id') . ' = '. \$db->quote(\$row[\$id_key]));"; + $script['save'][] = "\t\t\t\t\t\t// Reset the query using our newly populated query object."; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; + $script['save'][] = "\t\t\t\t\t\t\$found = \$db->getNumRows();"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t"; + $script['save'][] = "\t\t\t\t\tif(\$found && \$canEdit)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// update item"; + $script['save'][] = "\t\t\t\t\t\t\$id \t\t= \$row[\$id_key];"; + $script['save'][] = "\t\t\t\t\t\t\$version\t= \$db->loadResult();"; + $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; + $script['save'][] = "\t\t\t\t\t\t\$query \t\t= \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t\$fields \t= array();"; + $script['save'][] = "\t\t\t\t\t\t// Fields to update."; + $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; + $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update modified"; + $script['save'][] = "\t\t\t\t\t\t\tif ('modified_by' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update modified"; + $script['save'][] = "\t\t\t\t\t\t\tif ('modified' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update version"; + $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = (int) \$version + 1;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// verify publish authority"; + $script['save'][] = "\t\t\t\t\t\t\tif ('published' == \$target[\$key] && !\$canState)"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// set to update array"; + $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$cell;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$db->quote(\$cell);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . \" = ''\";"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// load the defaults"; + $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified_by') . ' = ' . \$db->quote(\$user->id);"; + $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified') . ' = ' . \$db->quote(\$todayDate);"; + $script['save'][] = "\t\t\t\t\t\t// Conditions for which records should be updated."; + $script['save'][] = "\t\t\t\t\t\t\$conditions = array("; + $script['save'][] = "\t\t\t\t\t\t\t\$db->quoteName('id') . ' = ' . \$id"; + $script['save'][] = "\t\t\t\t\t\t);"; + $script['save'][] = "\t\t\t\t\t\t"; + $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__###-#-#-component###_'.\$table))->set(\$fields)->where(\$conditions);"; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\telseif (\$canCreate)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// insert item"; + $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; + $script['save'][] = "\t\t\t\t\t\t\$columns \t= array();"; + $script['save'][] = "\t\t\t\t\t\t\$values \t= array();"; + $script['save'][] = "\t\t\t\t\t\t\$version\t= false;"; + $script['save'][] = "\t\t\t\t\t\t// Insert columns. Insert values."; + $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; + $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// remove id"; + $script['save'][] = "\t\t\t\t\t\t\tif ('id' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update created"; + $script['save'][] = "\t\t\t\t\t\t\tif ('created_by' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update created"; + $script['save'][] = "\t\t\t\t\t\t\tif ('created' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// Make sure the alias is incremented"; + $script['save'][] = "\t\t\t\t\t\t\tif ('alias' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = \$this->getAlias(\$cell,\$table);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update version"; + $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = 1;"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$version = true;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// set to insert array"; + $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$cell;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$db->quote(\$cell);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \"''\";"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// load the defaults"; + $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created_by';"; + $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$user->id);"; + $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created';"; + $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$todayDate);"; + $script['save'][] = "\t\t\t\t\t\tif (!\$version)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\$columns[] \t= 'version';"; + $script['save'][] = "\t\t\t\t\t\t\t\$values[] \t= 1;"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// Prepare the insert query."; + $script['save'][] = "\t\t\t\t\t\t\$query"; + $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__###-#-#-component###_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->columns(\$db->quoteName(\$columns))"; + $script['save'][] = "\t\t\t\t\t\t\t->values(implode(',', \$values));"; + $script['save'][] = "\t\t\t\t\t\t// Set the query using our newly populated query object and execute it."; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$done = \$db->execute();"; + $script['save'][] = "\t\t\t\t\t\tif (\$done)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\$aId = \$db->insertid();"; + $script['save'][] = "\t\t\t\t\t\t\t// make sure the access of asset is set"; + $script['save'][] = "\t\t\t\t\t\t\t###-#-#-Component###Helper::setAsset(\$aId,\$table);"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\telse"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\treturn false;"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t}"; + $script['save'][] = "\t\t\t\treturn true;"; + $script['save'][] = "\t\t\t}"; + $script['save'][] = "\t\t}"; + $script['save'][] = "\t\treturn false;"; + $script['save'][] = "\t}"; + } + elseif ('view' === $type) + { + $script['view'] = array(); + $script['view'][] = ""; + $script['view'][] = ""; + $script['view'][] = "\n
"; + $script['view'][] = "
\" method=\"post\" name=\"adminForm\" id=\"adminForm\" class=\"form-horizontal form-validate\">"; + $script['view'][] = ""; + $script['view'][] = "\n\tsidebar)) : ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t\tsidebar; ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t"; + $script['view'][] = ""; + $script['view'][] = "\n\thasPackage && ###-#-#-Component###Helper::checkArray(\$this->headerList) && ###-#-#-Component###Helper::checkArray(\$this->headers)) : ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\theaderList as \$name => \$title): ?>"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t\" onclick=\"Joomla.continueImport()\" />"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t\t 'upload')); ?>"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\tstate->get('import.directory'); ?>\" />"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton3()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = ""; + $script['view'][] = "\n\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton4()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t"; + $script['view'][] = ""; + $script['view'][] = "
"; + } + elseif ('import' === $type) + { + $script['import'] = array(); + $script['import'][] = "\t/**"; + $script['import'][] = "\t * Import an spreadsheet from either folder, url or upload."; + $script['import'][] = "\t *"; + $script['import'][] = "\t * @return boolean result of import"; + $script['import'][] = "\t *"; + $script['import'][] = "\t */"; + $script['import'][] = "\tpublic function import()"; + $script['import'][] = "\t{"; + $script['import'][] = "\t\t\$this->setState('action', 'import');"; + $script['import'][] = "\t\t\$app \t\t= JFactory::getApplication();"; + $script['import'][] = "\t\t\$session \t= JFactory::getSession();"; + $script['import'][] = "\t\t\$package \t= null;"; + $script['import'][] = "\t\t\$continue\t= false;"; + $script['import'][] = "\t\t// get import type"; + $script['import'][] = "\t\t\$this->getType = \$app->input->getString('gettype', NULL);"; + $script['import'][] = "\t\t// get import type"; + $script['import'][] = "\t\t\$this->dataType\t= \$session->get('dataType_VDM_IMPORTINTO', NULL);"; + $script['import'][] = "\n\t\tif (\$package === null)"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\tswitch (\$this->getType)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\tcase 'folder':"; + $script['import'][] = "\t\t\t\t\t// Remember the 'Import from Directory' path."; + $script['import'][] = "\t\t\t\t\t\$app->getUserStateFromRequest(\$this->_context . '.import_directory', 'import_directory');"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromFolder();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'upload':"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUpload();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'url':"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUrl();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'continue':"; + $script['import'][] = "\t\t\t\t\t\$continue \t= true;"; + $script['import'][] = "\t\t\t\t\t\$package\t= \$session->get('package', null);"; + $script['import'][] = "\t\t\t\t\t\$package\t= json_decode(\$package, true);"; + $script['import'][] = "\t\t\t\t\t// clear session"; + $script['import'][] = "\t\t\t\t\t\$session->clear('package');"; + $script['import'][] = "\t\t\t\t\t\$session->clear('dataType');"; + $script['import'][] = "\t\t\t\t\t\$session->clear('hasPackage');"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tdefault:"; + $script['import'][] = "\t\t\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_NO_IMPORT_TYPE_FOUND'));"; + $script['import'][] = "\n\t\t\t\t\treturn false;"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t// Was the package valid?"; + $script['import'][] = "\t\tif (!\$package || !\$package['type'])"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\tif (in_array(\$this->getType, array('upload', 'url')))"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\t\$this->remove(\$package['packagename']);"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\n\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));"; + $script['import'][] = "\t\t\treturn false;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t"; + $script['import'][] = "\t\t// first link data to table headers"; + $script['import'][] = "\t\tif(!\$continue){"; + $script['import'][] = "\t\t\t\$package\t= json_encode(\$package);"; + $script['import'][] = "\t\t\t\$session->set('package', \$package);"; + $script['import'][] = "\t\t\t\$session->set('dataType', \$this->dataType);"; + $script['import'][] = "\t\t\t\$session->set('hasPackage', true);"; + $script['import'][] = "\t\t\treturn true;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t// set the data"; + $script['import'][] = "\t\t\$headerList = json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false), true);"; + $script['import'][] = "\t\tif (!\$this->setData(\$package,\$this->dataType,\$headerList))"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\t// There was an error importing the package"; + $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_ERROR');"; + $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; + $script['import'][] = "\t\t\tif (\$back)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\t\$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; + $script['import'][] = "\t\t\t\t\$session->clear('backto_VDM_IMPORT');"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t\t\$result = false;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\telse"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\t// Package imported sucessfully"; + $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::sprintf('COM_###-#-#-COMPONENT###_IMPORT_SUCCESS', \$package['packagename']);"; + $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; + $script['import'][] = "\t\t\tif (\$back)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t \$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; + $script['import'][] = "\t\t\t \$session->clear('backto_VDM_IMPORT');"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t\t\$result = true;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\n\t\t// Set some model state values"; + $script['import'][] = "\t\t\$app->enqueueMessage(\$msg);"; + $script['import'][] = "\n\t\t// remove file after import"; + $script['import'][] = "\t\t\$this->remove(\$package['packagename']);"; + $script['import'][] = "\t\t\$session->clear(\$this->getType.'_VDM_IMPORTHEADERS');"; + $script['import'][] = "\t\treturn \$result;"; + $script['import'][] = "\t}"; + } + elseif ('ext' === $type) + { + $script['ext'][] = "\t/**"; + $script['ext'][] = "\t * Check the extension"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t * @param string \$file Name of the uploaded file"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t * @return boolean True on success"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t */"; + $script['ext'][] = "\tprotected function checkExtension(\$file)"; + $script['ext'][] = "\t{"; + $script['ext'][] = "\t\t// check the extention"; + $script['ext'][] = "\t\tswitch(strtolower(pathinfo(\$file, PATHINFO_EXTENSION)))"; + $script['ext'][] = "\t\t{"; + $script['ext'][] = "\t\t\tcase 'xls':"; + $script['ext'][] = "\t\t\tcase 'ods':"; + $script['ext'][] = "\t\t\tcase 'csv':"; + $script['ext'][] = "\t\t\treturn true;"; + $script['ext'][] = "\t\t\tbreak;"; + $script['ext'][] = "\t\t}"; + $script['ext'][] = "\t\treturn false;"; + $script['ext'][] = "\t}"; + } + // return the needed script + if (isset($script[$type])) + { + return str_replace('-#-#-', '', implode("\n",$script[$type])); + } + return false; + } + /** * Run Global Updater if any are set * @@ -935,709 +1637,7 @@ abstract class ComponentbuilderHelper } return false; } - - public static function getImportScripts($type, $fieldName = false) - { - // if field name is passed the convert to type - if ($fieldName) - { - $fieldNames = array( - 'php_import_display' => 'display', - 'php_import_setdata' => 'setdata', - 'php_import_save' => 'save', - 'html_import_view' => 'view', - 'php_import' => 'import', - 'php_import_ext' => 'ext', - 'php_import_headers' => 'headers' - ); - // first check if the field name is found - if (isset($fieldNames[$type])) - { - $type = $fieldNames[$type]; - } - else - { - return ''; - } - } - $script = array(); - if ('display' === $type) - { - // set the display script - $script['display'][] = "\tprotected \$headerList;"; - $script['display'][] = "\tprotected \$hasPackage = false;"; - $script['display'][] = "\tprotected \$headers;"; - $script['display'][] = "\tprotected \$hasHeader = 0;"; - $script['display'][] = "\tprotected \$dataType;"; - $script['display'][] = "\n\tpublic function display(\$tpl = null)"; - $script['display'][] = "\t{"; - $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t// Include helper submenu"; - $script['display'][] = "\t\t\t###-#-#-Component###Helper::addSubmenu('import');"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t\$paths = new stdClass;"; - $script['display'][] = "\t\t\$paths->first = '';"; - $script['display'][] = "\t\t\$state = \$this->get('state');"; - $script['display'][] = "\n\t\t\$this->paths = &\$paths;"; - $script['display'][] = "\t\t\$this->state = &\$state;"; - $script['display'][] = "\t\t// get global action permissions"; - $script['display'][] = "\t\t\$this->canDo = ###-#-#-Component###Helper::getActions('import');"; - $script['display'][] = "\n\t\t// We don't need toolbar in the modal window."; - $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t\$this->addToolbar();"; - $script['display'][] = "\t\t\t\$this->sidebar = JHtmlSidebar::render();"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// get the session object"; - $script['display'][] = "\t\t\$session = JFactory::getSession();"; - $script['display'][] = "\t\t// check if it has package"; - $script['display'][] = "\t\t\$this->hasPackage \t= \$session->get('hasPackage', false);"; - $script['display'][] = "\t\t\$this->dataType \t= \$session->get('dataType', false);"; - $script['display'][] = "\t\tif(\$this->hasPackage && \$this->dataType)"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t\$this->headerList \t= json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false),true);"; - $script['display'][] = "\t\t\t\$this->headers \t\t= ###-#-#-Component###Helper::getFileHeaders(\$this->dataType);"; - $script['display'][] = "\t\t\t// clear the data type"; - $script['display'][] = "\t\t\t\$session->clear('dataType');"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// Check for errors."; - $script['display'][] = "\t\tif (count(\$errors = \$this->get('Errors'))){"; - $script['display'][] = "\t\t\tthrow new Exception(implode(".'"\n", $errors), 500);'; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// Display the template"; - $script['display'][] = "\t\tparent::display(\$tpl);"; - $script['display'][] = "\t}"; - } - elseif ('setdata' === $type) - { - // set the setdata script - $script['setdata'] = array(); - $script['setdata'][] = "\t/**"; - $script['setdata'][] = "\t* Set the data from the spreadsheet to the database"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t* @param string \$package Paths to the uploaded package file"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t* @return boolean false on failure"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t**/"; - $script['setdata'][] = "\tprotected function setData(\$package,\$table,\$target_headers)"; - $script['setdata'][] = "\t{"; - $script['setdata'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$target_headers))"; - $script['setdata'][] = "\t\t{"; - $script['setdata'][] = "\t\t\t// make sure the file is loaded\t\t"; - $script['setdata'][] = "\t\t\tJLoader::import('PHPExcel', JPATH_COMPONENT_ADMINISTRATOR . '/helpers');"; - $script['setdata'][] = "\t\t\t\$jinput = JFactory::getApplication()->input;"; - $script['setdata'][] = "\t\t\tforeach(\$target_headers as \$header)"; - $script['setdata'][] = "\t\t\t{"; - $script['setdata'][] = "\t\t\t\t\$data['target_headers'][\$header] = \$jinput->getString(\$header, null);"; - $script['setdata'][] = "\t\t\t}"; - $script['setdata'][] = "\t\t\t// set the data"; - $script['setdata'][] = "\t\t\tif(isset(\$package['dir']))"; - $script['setdata'][] = "\t\t\t{"; - $script['setdata'][] = "\t\t\t\t\$inputFileType = PHPExcel_IOFactory::identify(\$package['dir']);"; - $script['setdata'][] = "\t\t\t\t\$excelReader = PHPExcel_IOFactory::createReader(\$inputFileType);"; - $script['setdata'][] = "\t\t\t\t\$excelReader->setReadDataOnly(true);"; - $script['setdata'][] = "\t\t\t\t\$excelObj = \$excelReader->load(\$package['dir']);"; - $script['setdata'][] = "\t\t\t\t\$data['array'] = \$excelObj->getActiveSheet()->toArray(null, true,true,true);"; - $script['setdata'][] = "\t\t\t\t\$excelObj->disconnectWorksheets();"; - $script['setdata'][] = "\t\t\t\tunset(\$excelObj);"; - $script['setdata'][] = "\t\t\t\treturn \$this->save(\$data,\$table);"; - $script['setdata'][] = "\t\t\t}"; - $script['setdata'][] = "\t\t}"; - $script['setdata'][] = "\t\treturn false;"; - $script['setdata'][] = "\t}"; - } - elseif ('headers' === $type) - { - $script['headers'] = array(); - $script['headers'][] = "\t/**"; - $script['headers'][] = "\t* Method to get header."; - $script['headers'][] = "\t*"; - $script['headers'][] = "\t* @return mixed An array of data items on success, false on failure."; - $script['headers'][] = "\t*/"; - $script['headers'][] = "\tpublic function getExImPortHeaders()"; - $script['headers'][] = "\t{"; - $script['headers'][] = "\t\t// Get a db connection."; - $script['headers'][] = "\t\t\$db = JFactory::getDbo();"; - $script['headers'][] = "\t\t// get the columns"; - $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__###-#-#-component###_###-#-#-view###\");"; - $script['headers'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$columns))"; - $script['headers'][] = "\t\t{"; - $script['headers'][] = "\t\t\t// remove the headers you don't import/export."; - $script['headers'][] = "\t\t\tunset(\$columns['asset_id']);"; - $script['headers'][] = "\t\t\tunset(\$columns['checked_out']);"; - $script['headers'][] = "\t\t\tunset(\$columns['checked_out_time']);"; - $script['headers'][] = "\t\t\t\$headers = new stdClass();"; - $script['headers'][] = "\t\t\tforeach (\$columns as \$column => \$type)"; - $script['headers'][] = "\t\t\t{"; - $script['headers'][] = "\t\t\t\t\$headers->{\$column} = \$column;"; - $script['headers'][] = "\t\t\t}"; - $script['headers'][] = "\t\t\treturn \$headers;"; - $script['headers'][] = "\t\t}"; - $script['headers'][] = "\t\treturn false;"; - $script['headers'][] = "\t}"; - } - elseif ('save' === $type) - { - $script['save'] = array(); - $script['save'][] = "\t/**"; - $script['save'][] = "\t* Save the data from the file to the database"; - $script['save'][] = "\t*"; - $script['save'][] = "\t* @param string \$package Paths to the uploaded package file"; - $script['save'][] = "\t*"; - $script['save'][] = "\t* @return boolean false on failure"; - $script['save'][] = "\t*"; - $script['save'][] = "\t**/"; - $script['save'][] = "\tprotected function save(\$data,\$table)"; - $script['save'][] = "\t{"; - $script['save'][] = "\t\t// import the data if there is any"; - $script['save'][] = "\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']))"; - $script['save'][] = "\t\t{"; - $script['save'][] = "\t\t\t// get user object"; - $script['save'][] = "\t\t\t\$user \t\t= JFactory::getUser();"; - $script['save'][] = "\t\t\t// remove header if it has headers"; - $script['save'][] = "\t\t\t\$id_key \t= \$data['target_headers']['id'];"; - $script['save'][] = "\t\t\t\$published_key \t= \$data['target_headers']['published'];"; - $script['save'][] = "\t\t\t\$ordering_key \t= \$data['target_headers']['ordering'];"; - $script['save'][] = "\t\t\t// get the first array set"; - $script['save'][] = "\t\t\t\$firstSet = reset(\$data['array']);"; - $script['save'][] = ""; - $script['save'][] = "\t\t\t// check if first array is a header array and remove if true"; - $script['save'][] = "\t\t\tif(\$firstSet[\$id_key] == 'id' || \$firstSet[\$published_key] == 'published' || \$firstSet[\$ordering_key] == 'ordering')"; - $script['save'][] = "\t\t\t{"; - $script['save'][] = "\t\t\t\tarray_shift(\$data['array']);"; - $script['save'][] = "\t\t\t}"; - $script['save'][] = "\t\t\t"; - $script['save'][] = "\t\t\t// make sure there is still values in array and that it was not only headers"; - $script['save'][] = "\t\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_###-#-#-component###') && \$user->authorise('core.import', 'com_###-#-#-component###'))"; - $script['save'][] = "\t\t\t{"; - $script['save'][] = "\t\t\t\t// set target."; - $script['save'][] = "\t\t\t\t\$target\t= array_flip(\$data['target_headers']);"; - $script['save'][] = "\t\t\t\t// Get a db connection."; - $script['save'][] = "\t\t\t\t\$db = JFactory::getDbo();"; - $script['save'][] = "\t\t\t\t// set some defaults"; - $script['save'][] = "\t\t\t\t\$todayDate\t\t= JFactory::getDate()->toSql();"; - $script['save'][] = "\t\t\t\t// get global action permissions"; - $script['save'][] = "\t\t\t\t\$canDo\t\t\t= ###-#-#-Component###Helper::getActions(\$table);"; - $script['save'][] = "\t\t\t\t\$canEdit\t\t= \$canDo->get('core.edit');"; - $script['save'][] = "\t\t\t\t\$canState\t\t= \$canDo->get('core.edit.state');"; - $script['save'][] = "\t\t\t\t\$canCreate\t\t= \$canDo->get('core.create');"; - $script['save'][] = "\t\t\t\t\$hasAlias\t\t= \$this->getAliasesUsed(\$table);"; - $script['save'][] = "\t\t\t\t// prosses the data"; - $script['save'][] = "\t\t\t\tforeach(\$data['array'] as \$row)"; - $script['save'][] = "\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\$found = false;"; - $script['save'][] = "\t\t\t\t\tif (isset(\$row[\$id_key]) && is_numeric(\$row[\$id_key]) && \$row[\$id_key] > 0)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// raw items import & update!"; - $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t\$query"; - $script['save'][] = "\t\t\t\t\t\t\t->select('version')"; - $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__###-#-#-component###_'.\$table))"; - $script['save'][] = "\t\t\t\t\t\t\t->where(\$db->quoteName('id') . ' = '. \$db->quote(\$row[\$id_key]));"; - $script['save'][] = "\t\t\t\t\t\t// Reset the query using our newly populated query object."; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; - $script['save'][] = "\t\t\t\t\t\t\$found = \$db->getNumRows();"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t"; - $script['save'][] = "\t\t\t\t\tif(\$found && \$canEdit)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// update item"; - $script['save'][] = "\t\t\t\t\t\t\$id \t\t= \$row[\$id_key];"; - $script['save'][] = "\t\t\t\t\t\t\$version\t= \$db->loadResult();"; - $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; - $script['save'][] = "\t\t\t\t\t\t\$query \t\t= \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t\$fields \t= array();"; - $script['save'][] = "\t\t\t\t\t\t// Fields to update."; - $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; - $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update modified"; - $script['save'][] = "\t\t\t\t\t\t\tif ('modified_by' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update modified"; - $script['save'][] = "\t\t\t\t\t\t\tif ('modified' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update version"; - $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = (int) \$version + 1;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// verify publish authority"; - $script['save'][] = "\t\t\t\t\t\t\tif ('published' == \$target[\$key] && !\$canState)"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// set to update array"; - $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$cell;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$db->quote(\$cell);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . \" = ''\";"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// load the defaults"; - $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified_by') . ' = ' . \$db->quote(\$user->id);"; - $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified') . ' = ' . \$db->quote(\$todayDate);"; - $script['save'][] = "\t\t\t\t\t\t// Conditions for which records should be updated."; - $script['save'][] = "\t\t\t\t\t\t\$conditions = array("; - $script['save'][] = "\t\t\t\t\t\t\t\$db->quoteName('id') . ' = ' . \$id"; - $script['save'][] = "\t\t\t\t\t\t);"; - $script['save'][] = "\t\t\t\t\t\t"; - $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__###-#-#-component###_'.\$table))->set(\$fields)->where(\$conditions);"; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\telseif (\$canCreate)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// insert item"; - $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; - $script['save'][] = "\t\t\t\t\t\t\$columns \t= array();"; - $script['save'][] = "\t\t\t\t\t\t\$values \t= array();"; - $script['save'][] = "\t\t\t\t\t\t\$version\t= false;"; - $script['save'][] = "\t\t\t\t\t\t// Insert columns. Insert values."; - $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; - $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// remove id"; - $script['save'][] = "\t\t\t\t\t\t\tif ('id' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update created"; - $script['save'][] = "\t\t\t\t\t\t\tif ('created_by' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update created"; - $script['save'][] = "\t\t\t\t\t\t\tif ('created' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// Make sure the alias is incremented"; - $script['save'][] = "\t\t\t\t\t\t\tif ('alias' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = \$this->getAlias(\$cell,\$table);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update version"; - $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = 1;"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$version = true;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// set to insert array"; - $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$cell;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$db->quote(\$cell);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \"''\";"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// load the defaults"; - $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created_by';"; - $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$user->id);"; - $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created';"; - $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$todayDate);"; - $script['save'][] = "\t\t\t\t\t\tif (!\$version)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\$columns[] \t= 'version';"; - $script['save'][] = "\t\t\t\t\t\t\t\$values[] \t= 1;"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// Prepare the insert query."; - $script['save'][] = "\t\t\t\t\t\t\$query"; - $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__###-#-#-component###_'.\$table))"; - $script['save'][] = "\t\t\t\t\t\t\t->columns(\$db->quoteName(\$columns))"; - $script['save'][] = "\t\t\t\t\t\t\t->values(implode(',', \$values));"; - $script['save'][] = "\t\t\t\t\t\t// Set the query using our newly populated query object and execute it."; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$done = \$db->execute();"; - $script['save'][] = "\t\t\t\t\t\tif (\$done)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\$aId = \$db->insertid();"; - $script['save'][] = "\t\t\t\t\t\t\t// make sure the access of asset is set"; - $script['save'][] = "\t\t\t\t\t\t\t###-#-#-Component###Helper::setAsset(\$aId,\$table);"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\telse"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\treturn false;"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t}"; - $script['save'][] = "\t\t\t\treturn true;"; - $script['save'][] = "\t\t\t}"; - $script['save'][] = "\t\t}"; - $script['save'][] = "\t\treturn false;"; - $script['save'][] = "\t}"; - } - elseif ('view' === $type) - { - $script['view'] = array(); - $script['view'][] = ""; - $script['view'][] = ""; - $script['view'][] = "\n
"; - $script['view'][] = "
\" method=\"post\" name=\"adminForm\" id=\"adminForm\" class=\"form-horizontal form-validate\">"; - $script['view'][] = ""; - $script['view'][] = "\n\tsidebar)) : ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t\tsidebar; ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t"; - $script['view'][] = ""; - $script['view'][] = "\n\thasPackage && ###-#-#-Component###Helper::checkArray(\$this->headerList) && ###-#-#-Component###Helper::checkArray(\$this->headers)) : ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\theaderList as \$name => \$title): ?>"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t\" onclick=\"Joomla.continueImport()\" />"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t\t 'upload')); ?>"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\tstate->get('import.directory'); ?>\" />"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton3()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = ""; - $script['view'][] = "\n\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton4()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t"; - $script['view'][] = ""; - $script['view'][] = "
"; - } - elseif ('import' === $type) - { - $script['import'] = array(); - $script['import'][] = "\t/**"; - $script['import'][] = "\t * Import an spreadsheet from either folder, url or upload."; - $script['import'][] = "\t *"; - $script['import'][] = "\t * @return boolean result of import"; - $script['import'][] = "\t *"; - $script['import'][] = "\t */"; - $script['import'][] = "\tpublic function import()"; - $script['import'][] = "\t{"; - $script['import'][] = "\t\t\$this->setState('action', 'import');"; - $script['import'][] = "\t\t\$app \t\t= JFactory::getApplication();"; - $script['import'][] = "\t\t\$session \t= JFactory::getSession();"; - $script['import'][] = "\t\t\$package \t= null;"; - $script['import'][] = "\t\t\$continue\t= false;"; - $script['import'][] = "\t\t// get import type"; - $script['import'][] = "\t\t\$this->getType = \$app->input->getString('gettype', NULL);"; - $script['import'][] = "\t\t// get import type"; - $script['import'][] = "\t\t\$this->dataType\t= \$session->get('dataType_VDM_IMPORTINTO', NULL);"; - $script['import'][] = "\n\t\tif (\$package === null)"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\tswitch (\$this->getType)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\tcase 'folder':"; - $script['import'][] = "\t\t\t\t\t// Remember the 'Import from Directory' path."; - $script['import'][] = "\t\t\t\t\t\$app->getUserStateFromRequest(\$this->_context . '.import_directory', 'import_directory');"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromFolder();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'upload':"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUpload();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'url':"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUrl();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'continue':"; - $script['import'][] = "\t\t\t\t\t\$continue \t= true;"; - $script['import'][] = "\t\t\t\t\t\$package\t= \$session->get('package', null);"; - $script['import'][] = "\t\t\t\t\t\$package\t= json_decode(\$package, true);"; - $script['import'][] = "\t\t\t\t\t// clear session"; - $script['import'][] = "\t\t\t\t\t\$session->clear('package');"; - $script['import'][] = "\t\t\t\t\t\$session->clear('dataType');"; - $script['import'][] = "\t\t\t\t\t\$session->clear('hasPackage');"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tdefault:"; - $script['import'][] = "\t\t\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_NO_IMPORT_TYPE_FOUND'));"; - $script['import'][] = "\n\t\t\t\t\treturn false;"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t// Was the package valid?"; - $script['import'][] = "\t\tif (!\$package || !\$package['type'])"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\tif (in_array(\$this->getType, array('upload', 'url')))"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\t\$this->remove(\$package['packagename']);"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\n\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));"; - $script['import'][] = "\t\t\treturn false;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t"; - $script['import'][] = "\t\t// first link data to table headers"; - $script['import'][] = "\t\tif(!\$continue){"; - $script['import'][] = "\t\t\t\$package\t= json_encode(\$package);"; - $script['import'][] = "\t\t\t\$session->set('package', \$package);"; - $script['import'][] = "\t\t\t\$session->set('dataType', \$this->dataType);"; - $script['import'][] = "\t\t\t\$session->set('hasPackage', true);"; - $script['import'][] = "\t\t\treturn true;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t// set the data"; - $script['import'][] = "\t\t\$headerList = json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false), true);"; - $script['import'][] = "\t\tif (!\$this->setData(\$package,\$this->dataType,\$headerList))"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\t// There was an error importing the package"; - $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_ERROR');"; - $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; - $script['import'][] = "\t\t\tif (\$back)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\t\$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; - $script['import'][] = "\t\t\t\t\$session->clear('backto_VDM_IMPORT');"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t\t\$result = false;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\telse"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\t// Package imported sucessfully"; - $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::sprintf('COM_###-#-#-COMPONENT###_IMPORT_SUCCESS', \$package['packagename']);"; - $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; - $script['import'][] = "\t\t\tif (\$back)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t \$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; - $script['import'][] = "\t\t\t \$session->clear('backto_VDM_IMPORT');"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t\t\$result = true;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\n\t\t// Set some model state values"; - $script['import'][] = "\t\t\$app->enqueueMessage(\$msg);"; - $script['import'][] = "\n\t\t// remove file after import"; - $script['import'][] = "\t\t\$this->remove(\$package['packagename']);"; - $script['import'][] = "\t\t\$session->clear(\$this->getType.'_VDM_IMPORTHEADERS');"; - $script['import'][] = "\t\treturn \$result;"; - $script['import'][] = "\t}"; - } - elseif ('ext' === $type) - { - $script['ext'][] = "\t/**"; - $script['ext'][] = "\t * Check the extension"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t * @param string \$file Name of the uploaded file"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t * @return boolean True on success"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t */"; - $script['ext'][] = "\tprotected function checkExtension(\$file)"; - $script['ext'][] = "\t{"; - $script['ext'][] = "\t\t// check the extention"; - $script['ext'][] = "\t\tswitch(strtolower(pathinfo(\$file, PATHINFO_EXTENSION)))"; - $script['ext'][] = "\t\t{"; - $script['ext'][] = "\t\t\tcase 'xls':"; - $script['ext'][] = "\t\t\tcase 'ods':"; - $script['ext'][] = "\t\t\tcase 'csv':"; - $script['ext'][] = "\t\t\treturn true;"; - $script['ext'][] = "\t\t\tbreak;"; - $script['ext'][] = "\t\t}"; - $script['ext'][] = "\t\treturn false;"; - $script['ext'][] = "\t}"; - } - // return the needed script - if (isset($script[$type])) - { - return str_replace('-#-#-', '', implode("\n",$script[$type])); - } - return false; - } - + /** * set the session defaults if not set **/ diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index e570ca705..43e0fdf2d 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -4119,10 +4119,6 @@ COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_STATE="Joomla Components Edit State" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_STATE_DESC="Allows the users in this group to update the state of the joomla component" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_VERSION="Joomla Components Edit Version" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_VERSION_DESC="Allows users in this group to edit versions of version joomla components" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EXPORT="Joomla Components Export" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EXPORT_DESC="Allows the users in this group to export export joomla components" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_IMPORT="Joomla Components Import" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_IMPORT_DESC="Allows the users in this group to import import joomla components" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_N_ITEMS_ARCHIVED="%s Joomla Components archived." COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_N_ITEMS_ARCHIVED_1="%s Joomla Component archived." COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_N_ITEMS_CHECKED_IN_0="No Joomla Component successfully checked in." diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini b/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini index 34db21cf3..558ce49a2 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini @@ -506,10 +506,6 @@ COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_STATE="Joomla Components Edit State" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_STATE_DESC="Allows the users in this group to update the state of the joomla component" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_VERSION="Joomla Components Edit Version" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EDIT_VERSION_DESC="Allows users in this group to edit versions of version joomla components" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EXPORT="Joomla Components Export" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_EXPORT_DESC="Allows the users in this group to export export joomla components" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_IMPORT="Joomla Components Import" -COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_IMPORT_DESC="Allows the users in this group to import import joomla components" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_SUBMENU="Joomla Components Submenu" COM_COMPONENTBUILDER_JOOMLA_COMPONENTS_SUBMENU_DESC="Allows the users in this group to update the submenu of the joomla component" COM_COMPONENTBUILDER_JOOMLA_COMPONENT_BACKUP_BUTTON_ACCESS="Joomla Component Backup Button Access" diff --git a/componentbuilder.xml b/componentbuilder.xml index a257e8b78..3db462a41 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 17th January, 2018 + 19th January, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index 20043b8c9..d79f95257 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -720,709 +720,7 @@ abstract class ComponentbuilderHelper } return false; } - - public static function getImportScripts($type, $fieldName = false) - { - // if field name is passed the convert to type - if ($fieldName) - { - $fieldNames = array( - 'php_import_display' => 'display', - 'php_import_setdata' => 'setdata', - 'php_import_save' => 'save', - 'html_import_view' => 'view', - 'php_import' => 'import', - 'php_import_ext' => 'ext', - 'php_import_headers' => 'headers' - ); - // first check if the field name is found - if (isset($fieldNames[$type])) - { - $type = $fieldNames[$type]; - } - else - { - return ''; - } - } - $script = array(); - if ('display' === $type) - { - // set the display script - $script['display'][] = "\tprotected \$headerList;"; - $script['display'][] = "\tprotected \$hasPackage = false;"; - $script['display'][] = "\tprotected \$headers;"; - $script['display'][] = "\tprotected \$hasHeader = 0;"; - $script['display'][] = "\tprotected \$dataType;"; - $script['display'][] = "\n\tpublic function display(\$tpl = null)"; - $script['display'][] = "\t{"; - $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t// Include helper submenu"; - $script['display'][] = "\t\t\t###-#-#-Component###Helper::addSubmenu('import');"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t\$paths = new stdClass;"; - $script['display'][] = "\t\t\$paths->first = '';"; - $script['display'][] = "\t\t\$state = \$this->get('state');"; - $script['display'][] = "\n\t\t\$this->paths = &\$paths;"; - $script['display'][] = "\t\t\$this->state = &\$state;"; - $script['display'][] = "\t\t// get global action permissions"; - $script['display'][] = "\t\t\$this->canDo = ###-#-#-Component###Helper::getActions('import');"; - $script['display'][] = "\n\t\t// We don't need toolbar in the modal window."; - $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t\$this->addToolbar();"; - $script['display'][] = "\t\t\t\$this->sidebar = JHtmlSidebar::render();"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// get the session object"; - $script['display'][] = "\t\t\$session = JFactory::getSession();"; - $script['display'][] = "\t\t// check if it has package"; - $script['display'][] = "\t\t\$this->hasPackage \t= \$session->get('hasPackage', false);"; - $script['display'][] = "\t\t\$this->dataType \t= \$session->get('dataType', false);"; - $script['display'][] = "\t\tif(\$this->hasPackage && \$this->dataType)"; - $script['display'][] = "\t\t{"; - $script['display'][] = "\t\t\t\$this->headerList \t= json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false),true);"; - $script['display'][] = "\t\t\t\$this->headers \t\t= ###-#-#-Component###Helper::getFileHeaders(\$this->dataType);"; - $script['display'][] = "\t\t\t// clear the data type"; - $script['display'][] = "\t\t\t\$session->clear('dataType');"; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// Check for errors."; - $script['display'][] = "\t\tif (count(\$errors = \$this->get('Errors'))){"; - $script['display'][] = "\t\t\tthrow new Exception(implode(".'"\n", $errors), 500);'; - $script['display'][] = "\t\t}"; - $script['display'][] = "\n\t\t// Display the template"; - $script['display'][] = "\t\tparent::display(\$tpl);"; - $script['display'][] = "\t}"; - } - elseif ('setdata' === $type) - { - // set the setdata script - $script['setdata'] = array(); - $script['setdata'][] = "\t/**"; - $script['setdata'][] = "\t* Set the data from the spreadsheet to the database"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t* @param string \$package Paths to the uploaded package file"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t* @return boolean false on failure"; - $script['setdata'][] = "\t*"; - $script['setdata'][] = "\t**/"; - $script['setdata'][] = "\tprotected function setData(\$package,\$table,\$target_headers)"; - $script['setdata'][] = "\t{"; - $script['setdata'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$target_headers))"; - $script['setdata'][] = "\t\t{"; - $script['setdata'][] = "\t\t\t// make sure the file is loaded\t\t"; - $script['setdata'][] = "\t\t\tJLoader::import('PHPExcel', JPATH_COMPONENT_ADMINISTRATOR . '/helpers');"; - $script['setdata'][] = "\t\t\t\$jinput = JFactory::getApplication()->input;"; - $script['setdata'][] = "\t\t\tforeach(\$target_headers as \$header)"; - $script['setdata'][] = "\t\t\t{"; - $script['setdata'][] = "\t\t\t\t\$data['target_headers'][\$header] = \$jinput->getString(\$header, null);"; - $script['setdata'][] = "\t\t\t}"; - $script['setdata'][] = "\t\t\t// set the data"; - $script['setdata'][] = "\t\t\tif(isset(\$package['dir']))"; - $script['setdata'][] = "\t\t\t{"; - $script['setdata'][] = "\t\t\t\t\$inputFileType = PHPExcel_IOFactory::identify(\$package['dir']);"; - $script['setdata'][] = "\t\t\t\t\$excelReader = PHPExcel_IOFactory::createReader(\$inputFileType);"; - $script['setdata'][] = "\t\t\t\t\$excelReader->setReadDataOnly(true);"; - $script['setdata'][] = "\t\t\t\t\$excelObj = \$excelReader->load(\$package['dir']);"; - $script['setdata'][] = "\t\t\t\t\$data['array'] = \$excelObj->getActiveSheet()->toArray(null, true,true,true);"; - $script['setdata'][] = "\t\t\t\t\$excelObj->disconnectWorksheets();"; - $script['setdata'][] = "\t\t\t\tunset(\$excelObj);"; - $script['setdata'][] = "\t\t\t\treturn \$this->save(\$data,\$table);"; - $script['setdata'][] = "\t\t\t}"; - $script['setdata'][] = "\t\t}"; - $script['setdata'][] = "\t\treturn false;"; - $script['setdata'][] = "\t}"; - } - elseif ('headers' === $type) - { - $script['headers'] = array(); - $script['headers'][] = "\t/**"; - $script['headers'][] = "\t* Method to get header."; - $script['headers'][] = "\t*"; - $script['headers'][] = "\t* @return mixed An array of data items on success, false on failure."; - $script['headers'][] = "\t*/"; - $script['headers'][] = "\tpublic function getExImPortHeaders()"; - $script['headers'][] = "\t{"; - $script['headers'][] = "\t\t// Get a db connection."; - $script['headers'][] = "\t\t\$db = JFactory::getDbo();"; - $script['headers'][] = "\t\t// get the columns"; - $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__###-#-#-component###_###-#-#-view###\");"; - $script['headers'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$columns))"; - $script['headers'][] = "\t\t{"; - $script['headers'][] = "\t\t\t// remove the headers you don't import/export."; - $script['headers'][] = "\t\t\tunset(\$columns['asset_id']);"; - $script['headers'][] = "\t\t\tunset(\$columns['checked_out']);"; - $script['headers'][] = "\t\t\tunset(\$columns['checked_out_time']);"; - $script['headers'][] = "\t\t\t\$headers = new stdClass();"; - $script['headers'][] = "\t\t\tforeach (\$columns as \$column => \$type)"; - $script['headers'][] = "\t\t\t{"; - $script['headers'][] = "\t\t\t\t\$headers->{\$column} = \$column;"; - $script['headers'][] = "\t\t\t}"; - $script['headers'][] = "\t\t\treturn \$headers;"; - $script['headers'][] = "\t\t}"; - $script['headers'][] = "\t\treturn false;"; - $script['headers'][] = "\t}"; - } - elseif ('save' === $type) - { - $script['save'] = array(); - $script['save'][] = "\t/**"; - $script['save'][] = "\t* Save the data from the file to the database"; - $script['save'][] = "\t*"; - $script['save'][] = "\t* @param string \$package Paths to the uploaded package file"; - $script['save'][] = "\t*"; - $script['save'][] = "\t* @return boolean false on failure"; - $script['save'][] = "\t*"; - $script['save'][] = "\t**/"; - $script['save'][] = "\tprotected function save(\$data,\$table)"; - $script['save'][] = "\t{"; - $script['save'][] = "\t\t// import the data if there is any"; - $script['save'][] = "\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']))"; - $script['save'][] = "\t\t{"; - $script['save'][] = "\t\t\t// get user object"; - $script['save'][] = "\t\t\t\$user \t\t= JFactory::getUser();"; - $script['save'][] = "\t\t\t// remove header if it has headers"; - $script['save'][] = "\t\t\t\$id_key \t= \$data['target_headers']['id'];"; - $script['save'][] = "\t\t\t\$published_key \t= \$data['target_headers']['published'];"; - $script['save'][] = "\t\t\t\$ordering_key \t= \$data['target_headers']['ordering'];"; - $script['save'][] = "\t\t\t// get the first array set"; - $script['save'][] = "\t\t\t\$firstSet = reset(\$data['array']);"; - $script['save'][] = ""; - $script['save'][] = "\t\t\t// check if first array is a header array and remove if true"; - $script['save'][] = "\t\t\tif(\$firstSet[\$id_key] == 'id' || \$firstSet[\$published_key] == 'published' || \$firstSet[\$ordering_key] == 'ordering')"; - $script['save'][] = "\t\t\t{"; - $script['save'][] = "\t\t\t\tarray_shift(\$data['array']);"; - $script['save'][] = "\t\t\t}"; - $script['save'][] = "\t\t\t"; - $script['save'][] = "\t\t\t// make sure there is still values in array and that it was not only headers"; - $script['save'][] = "\t\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_###-#-#-component###') && \$user->authorise('core.import', 'com_###-#-#-component###'))"; - $script['save'][] = "\t\t\t{"; - $script['save'][] = "\t\t\t\t// set target."; - $script['save'][] = "\t\t\t\t\$target\t= array_flip(\$data['target_headers']);"; - $script['save'][] = "\t\t\t\t// Get a db connection."; - $script['save'][] = "\t\t\t\t\$db = JFactory::getDbo();"; - $script['save'][] = "\t\t\t\t// set some defaults"; - $script['save'][] = "\t\t\t\t\$todayDate\t\t= JFactory::getDate()->toSql();"; - $script['save'][] = "\t\t\t\t// get global action permissions"; - $script['save'][] = "\t\t\t\t\$canDo\t\t\t= ###-#-#-Component###Helper::getActions(\$table);"; - $script['save'][] = "\t\t\t\t\$canEdit\t\t= \$canDo->get('core.edit');"; - $script['save'][] = "\t\t\t\t\$canState\t\t= \$canDo->get('core.edit.state');"; - $script['save'][] = "\t\t\t\t\$canCreate\t\t= \$canDo->get('core.create');"; - $script['save'][] = "\t\t\t\t\$hasAlias\t\t= \$this->getAliasesUsed(\$table);"; - $script['save'][] = "\t\t\t\t// prosses the data"; - $script['save'][] = "\t\t\t\tforeach(\$data['array'] as \$row)"; - $script['save'][] = "\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\$found = false;"; - $script['save'][] = "\t\t\t\t\tif (isset(\$row[\$id_key]) && is_numeric(\$row[\$id_key]) && \$row[\$id_key] > 0)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// raw items import & update!"; - $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t\$query"; - $script['save'][] = "\t\t\t\t\t\t\t->select('version')"; - $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__###-#-#-component###_'.\$table))"; - $script['save'][] = "\t\t\t\t\t\t\t->where(\$db->quoteName('id') . ' = '. \$db->quote(\$row[\$id_key]));"; - $script['save'][] = "\t\t\t\t\t\t// Reset the query using our newly populated query object."; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; - $script['save'][] = "\t\t\t\t\t\t\$found = \$db->getNumRows();"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t"; - $script['save'][] = "\t\t\t\t\tif(\$found && \$canEdit)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// update item"; - $script['save'][] = "\t\t\t\t\t\t\$id \t\t= \$row[\$id_key];"; - $script['save'][] = "\t\t\t\t\t\t\$version\t= \$db->loadResult();"; - $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; - $script['save'][] = "\t\t\t\t\t\t\$query \t\t= \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t\$fields \t= array();"; - $script['save'][] = "\t\t\t\t\t\t// Fields to update."; - $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; - $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update modified"; - $script['save'][] = "\t\t\t\t\t\t\tif ('modified_by' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update modified"; - $script['save'][] = "\t\t\t\t\t\t\tif ('modified' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update version"; - $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = (int) \$version + 1;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// verify publish authority"; - $script['save'][] = "\t\t\t\t\t\t\tif ('published' == \$target[\$key] && !\$canState)"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// set to update array"; - $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$cell;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$db->quote(\$cell);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . \" = ''\";"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// load the defaults"; - $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified_by') . ' = ' . \$db->quote(\$user->id);"; - $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified') . ' = ' . \$db->quote(\$todayDate);"; - $script['save'][] = "\t\t\t\t\t\t// Conditions for which records should be updated."; - $script['save'][] = "\t\t\t\t\t\t\$conditions = array("; - $script['save'][] = "\t\t\t\t\t\t\t\$db->quoteName('id') . ' = ' . \$id"; - $script['save'][] = "\t\t\t\t\t\t);"; - $script['save'][] = "\t\t\t\t\t\t"; - $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__###-#-#-component###_'.\$table))->set(\$fields)->where(\$conditions);"; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\telseif (\$canCreate)"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t// insert item"; - $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; - $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; - $script['save'][] = "\t\t\t\t\t\t\$columns \t= array();"; - $script['save'][] = "\t\t\t\t\t\t\$values \t= array();"; - $script['save'][] = "\t\t\t\t\t\t\$version\t= false;"; - $script['save'][] = "\t\t\t\t\t\t// Insert columns. Insert values."; - $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; - $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// remove id"; - $script['save'][] = "\t\t\t\t\t\t\tif ('id' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update created"; - $script['save'][] = "\t\t\t\t\t\t\tif ('created_by' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update created"; - $script['save'][] = "\t\t\t\t\t\t\tif ('created' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// Make sure the alias is incremented"; - $script['save'][] = "\t\t\t\t\t\t\tif ('alias' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = \$this->getAlias(\$cell,\$table);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// update version"; - $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = 1;"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$version = true;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\t// set to insert array"; - $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$cell;"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$db->quote(\$cell);"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; - $script['save'][] = "\t\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; - $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \"''\";"; - $script['save'][] = "\t\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// load the defaults"; - $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created_by';"; - $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$user->id);"; - $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created';"; - $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$todayDate);"; - $script['save'][] = "\t\t\t\t\t\tif (!\$version)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\$columns[] \t= 'version';"; - $script['save'][] = "\t\t\t\t\t\t\t\$values[] \t= 1;"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t\t// Prepare the insert query."; - $script['save'][] = "\t\t\t\t\t\t\$query"; - $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__###-#-#-component###_'.\$table))"; - $script['save'][] = "\t\t\t\t\t\t\t->columns(\$db->quoteName(\$columns))"; - $script['save'][] = "\t\t\t\t\t\t\t->values(implode(',', \$values));"; - $script['save'][] = "\t\t\t\t\t\t// Set the query using our newly populated query object and execute it."; - $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; - $script['save'][] = "\t\t\t\t\t\t\$done = \$db->execute();"; - $script['save'][] = "\t\t\t\t\t\tif (\$done)"; - $script['save'][] = "\t\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\t\t\$aId = \$db->insertid();"; - $script['save'][] = "\t\t\t\t\t\t\t// make sure the access of asset is set"; - $script['save'][] = "\t\t\t\t\t\t\t###-#-#-Component###Helper::setAsset(\$aId,\$table);"; - $script['save'][] = "\t\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t\telse"; - $script['save'][] = "\t\t\t\t\t{"; - $script['save'][] = "\t\t\t\t\t\treturn false;"; - $script['save'][] = "\t\t\t\t\t}"; - $script['save'][] = "\t\t\t\t}"; - $script['save'][] = "\t\t\t\treturn true;"; - $script['save'][] = "\t\t\t}"; - $script['save'][] = "\t\t}"; - $script['save'][] = "\t\treturn false;"; - $script['save'][] = "\t}"; - } - elseif ('view' === $type) - { - $script['view'] = array(); - $script['view'][] = ""; - $script['view'][] = ""; - $script['view'][] = "\n
"; - $script['view'][] = "
\" method=\"post\" name=\"adminForm\" id=\"adminForm\" class=\"form-horizontal form-validate\">"; - $script['view'][] = ""; - $script['view'][] = "\n\tsidebar)) : ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t\tsidebar; ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t"; - $script['view'][] = ""; - $script['view'][] = "\n\thasPackage && ###-#-#-Component###Helper::checkArray(\$this->headerList) && ###-#-#-Component###Helper::checkArray(\$this->headers)) : ?>"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\theaderList as \$name => \$title): ?>"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t\" onclick=\"Joomla.continueImport()\" />"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t\t 'upload')); ?>"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\tstate->get('import.directory'); ?>\" />"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton3()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = ""; - $script['view'][] = "\n\t\t"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t\t\t"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\t"; - $script['view'][] = "\t\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton4()\" />    (.csv .xls .ods)"; - $script['view'][] = "\t\t\t\t
"; - $script['view'][] = "\t\t\t
"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t"; - $script['view'][] = "\t"; - $script['view'][] = ""; - $script['view'][] = "
"; - } - elseif ('import' === $type) - { - $script['import'] = array(); - $script['import'][] = "\t/**"; - $script['import'][] = "\t * Import an spreadsheet from either folder, url or upload."; - $script['import'][] = "\t *"; - $script['import'][] = "\t * @return boolean result of import"; - $script['import'][] = "\t *"; - $script['import'][] = "\t */"; - $script['import'][] = "\tpublic function import()"; - $script['import'][] = "\t{"; - $script['import'][] = "\t\t\$this->setState('action', 'import');"; - $script['import'][] = "\t\t\$app \t\t= JFactory::getApplication();"; - $script['import'][] = "\t\t\$session \t= JFactory::getSession();"; - $script['import'][] = "\t\t\$package \t= null;"; - $script['import'][] = "\t\t\$continue\t= false;"; - $script['import'][] = "\t\t// get import type"; - $script['import'][] = "\t\t\$this->getType = \$app->input->getString('gettype', NULL);"; - $script['import'][] = "\t\t// get import type"; - $script['import'][] = "\t\t\$this->dataType\t= \$session->get('dataType_VDM_IMPORTINTO', NULL);"; - $script['import'][] = "\n\t\tif (\$package === null)"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\tswitch (\$this->getType)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\tcase 'folder':"; - $script['import'][] = "\t\t\t\t\t// Remember the 'Import from Directory' path."; - $script['import'][] = "\t\t\t\t\t\$app->getUserStateFromRequest(\$this->_context . '.import_directory', 'import_directory');"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromFolder();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'upload':"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUpload();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'url':"; - $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUrl();"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tcase 'continue':"; - $script['import'][] = "\t\t\t\t\t\$continue \t= true;"; - $script['import'][] = "\t\t\t\t\t\$package\t= \$session->get('package', null);"; - $script['import'][] = "\t\t\t\t\t\$package\t= json_decode(\$package, true);"; - $script['import'][] = "\t\t\t\t\t// clear session"; - $script['import'][] = "\t\t\t\t\t\$session->clear('package');"; - $script['import'][] = "\t\t\t\t\t\$session->clear('dataType');"; - $script['import'][] = "\t\t\t\t\t\$session->clear('hasPackage');"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\n\t\t\t\tdefault:"; - $script['import'][] = "\t\t\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_NO_IMPORT_TYPE_FOUND'));"; - $script['import'][] = "\n\t\t\t\t\treturn false;"; - $script['import'][] = "\t\t\t\t\tbreak;"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t// Was the package valid?"; - $script['import'][] = "\t\tif (!\$package || !\$package['type'])"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\tif (in_array(\$this->getType, array('upload', 'url')))"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\t\$this->remove(\$package['packagename']);"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\n\t\t\t\$app->setUserState('com_###-#-#-component###.message', JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));"; - $script['import'][] = "\t\t\treturn false;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t"; - $script['import'][] = "\t\t// first link data to table headers"; - $script['import'][] = "\t\tif(!\$continue){"; - $script['import'][] = "\t\t\t\$package\t= json_encode(\$package);"; - $script['import'][] = "\t\t\t\$session->set('package', \$package);"; - $script['import'][] = "\t\t\t\$session->set('dataType', \$this->dataType);"; - $script['import'][] = "\t\t\t\$session->set('hasPackage', true);"; - $script['import'][] = "\t\t\treturn true;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\t// set the data"; - $script['import'][] = "\t\t\$headerList = json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false), true);"; - $script['import'][] = "\t\tif (!\$this->setData(\$package,\$this->dataType,\$headerList))"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\t// There was an error importing the package"; - $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::_('COM_###-#-#-COMPONENT###_IMPORT_ERROR');"; - $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; - $script['import'][] = "\t\t\tif (\$back)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t\t\$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; - $script['import'][] = "\t\t\t\t\$session->clear('backto_VDM_IMPORT');"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t\t\$result = false;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\t\telse"; - $script['import'][] = "\t\t{"; - $script['import'][] = "\t\t\t// Package imported sucessfully"; - $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::sprintf('COM_###-#-#-COMPONENT###_IMPORT_SUCCESS', \$package['packagename']);"; - $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; - $script['import'][] = "\t\t\tif (\$back)"; - $script['import'][] = "\t\t\t{"; - $script['import'][] = "\t\t\t \$app->setUserState('com_###-#-#-component###.redirect_url', 'index.php?option=com_###-#-#-component###&view='.\$back);"; - $script['import'][] = "\t\t\t \$session->clear('backto_VDM_IMPORT');"; - $script['import'][] = "\t\t\t}"; - $script['import'][] = "\t\t\t\$result = true;"; - $script['import'][] = "\t\t}"; - $script['import'][] = "\n\t\t// Set some model state values"; - $script['import'][] = "\t\t\$app->enqueueMessage(\$msg);"; - $script['import'][] = "\n\t\t// remove file after import"; - $script['import'][] = "\t\t\$this->remove(\$package['packagename']);"; - $script['import'][] = "\t\t\$session->clear(\$this->getType.'_VDM_IMPORTHEADERS');"; - $script['import'][] = "\t\treturn \$result;"; - $script['import'][] = "\t}"; - } - elseif ('ext' === $type) - { - $script['ext'][] = "\t/**"; - $script['ext'][] = "\t * Check the extension"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t * @param string \$file Name of the uploaded file"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t * @return boolean True on success"; - $script['ext'][] = "\t *"; - $script['ext'][] = "\t */"; - $script['ext'][] = "\tprotected function checkExtension(\$file)"; - $script['ext'][] = "\t{"; - $script['ext'][] = "\t\t// check the extention"; - $script['ext'][] = "\t\tswitch(strtolower(pathinfo(\$file, PATHINFO_EXTENSION)))"; - $script['ext'][] = "\t\t{"; - $script['ext'][] = "\t\t\tcase 'xls':"; - $script['ext'][] = "\t\t\tcase 'ods':"; - $script['ext'][] = "\t\t\tcase 'csv':"; - $script['ext'][] = "\t\t\treturn true;"; - $script['ext'][] = "\t\t\tbreak;"; - $script['ext'][] = "\t\t}"; - $script['ext'][] = "\t\treturn false;"; - $script['ext'][] = "\t}"; - } - // return the needed script - if (isset($script[$type])) - { - return str_replace('-#-#-', '', implode("\n",$script[$type])); - } - return false; - } - + /** * set the session defaults if not set **/