diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index 89746a993..bed55a74b 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -154,6 +154,7 @@ class page_chapters_ui extends e_admin_ui protected $batchDelete = false; protected $batchCopy = true; protected $batchLink = true; + protected $batchExport = true; protected $listQry = "SELECT a. *, CASE WHEN a.chapter_parent = 0 THEN a.chapter_order ELSE b.chapter_order + (( a.chapter_order)/1000) END AS Sort FROM `#page_chapters` AS a LEFT JOIN `#page_chapters` AS b ON a.chapter_parent = b.chapter_id "; protected $listOrder = 'Sort,chapter_order '; @@ -527,7 +528,8 @@ class page_admin_ui extends e_admin_ui protected $batchDelete = true; protected $batchCopy = true; protected $batchLink = true; - protected $batchFeaturebox = true; + protected $batchExport = true; + protected $batchFeaturebox = true; protected $sortField = 'page_order'; protected $orderStep = 10; //protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided. diff --git a/e107_admin/db.php b/e107_admin/db.php index 7bba0a173..3333ac0ca 100644 --- a/e107_admin/db.php +++ b/e107_admin/db.php @@ -1735,7 +1735,7 @@ function exportXmlFile($prefs,$tables=array(),$plugPrefs, $package=FALSE,$debug= } } - $mode = ($debug === true) ? "debug" : false; + $mode = ($debug === true) ? array( "debug" =>1) : null; if($xml->e107Export($prefs,$tables,$plugPrefs, $mode)) { diff --git a/e107_admin/links.php b/e107_admin/links.php index c846458bd..be65b43fa 100644 --- a/e107_admin/links.php +++ b/e107_admin/links.php @@ -887,7 +887,7 @@ class links_admin_form_ui extends e_admin_form_ui 'fields' => $controller->getFields(), // see e_admin_ui::$fields 'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref 'table_pre' => '', // markup to be added before opening table element - 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy()) : '', + 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch(array('delete'=>$controller->getBatchDelete(),'copy'=>$controller->getBatchCopy())) : '', 'fieldset_pre' => '', // markup to be added before opening fieldset element 'fieldset_post' => '', // markup to be added after closing fieldset element 'perPage' => $controller->getPerPage(), // if 0 - no next/prev navigation diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 0911ab03e..bf6e6bc6a 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -120,6 +120,7 @@ class news_cat_ui extends e_admin_ui protected $pid = "category_id"; protected $perPage = 0; //no limit protected $batchDelete = false; + protected $batchExport = true; protected $sortField = 'category_order'; protected $listOrder = "category_order ASC"; @@ -407,6 +408,7 @@ class news_admin_ui extends e_admin_ui protected $pid = "news_id"; protected $perPage = 10; //no limit protected $batchDelete = true; + protected $batchExport = true; protected $batchCopy = true; protected $batchLink = true; protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM `#news` AS n LEFT JOIN `#user` AS u ON n.news_author = u.user_id "; // without any Order or Limit. diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index bb5743575..d84e448d0 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -3658,7 +3658,8 @@ class ".$table." extends e_admin_ui protected \$pid = '".$vars['pid']."'; protected \$perPage = 10; protected \$batchDelete = true; - // protected \$batchCopy = true; + protected \$batchExport = true; + protected \$batchCopy = true; // protected \$sortField = 'somefield_order'; // protected \$orderStep = 10; // protected \$tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the \$fields below to enable. diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index 72d7e522b..a27f8be0d 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -2478,6 +2478,11 @@ class e_admin_controller_ui extends e_admin_controller */ protected $batchFeaturebox = false; + /** + * @var boolean + */ + protected $batchExport = false; + /** * @var array */ @@ -2559,6 +2564,11 @@ class e_admin_controller_ui extends e_admin_controller return $this->batchFeaturebox; } + public function getBatchExport() + { + return $this->batchExport; + } + public function getBatchOptions() { return $this->batchOptions; @@ -3126,6 +3136,16 @@ class e_admin_controller_ui extends e_admin_controller switch($trigger[0]) { + + case 'export': + $method = 'handle'.$this->getRequest()->getActionName().'ExportBatch'; + if(method_exists($this, $method)) // callback handling + { + $this->$method($selected); + } + + break; + case 'delete': //FIXME - confirmation popup //method handleListDeleteBatch(); for custom handling of 'delete' batch // if(empty($selected)) return $this; @@ -4523,7 +4543,7 @@ class e_admin_ui extends e_admin_controller_ui //$this->redirect(); } - /** TODO + /** * Batch copy trigger * @param array $selected * @return void @@ -4542,6 +4562,28 @@ class e_admin_ui extends e_admin_controller_ui $this->redirect(); } + + /** + * Batch Export trigger + * @param array $selected + * @return void + */ + protected function handleListExportBatch($selected) + { + // Batch Copy + $res = $this->getTreeModel()->export($selected); + // callback + // $this->afterCopy($res, $selected); + // move messages to default stack + $this->getTreeModel()->setMessages(); + // send messages to session + e107::getMessage()->moveToSession(); + // redirect + $this->redirect(); + } + + + /** * Batch URL trigger * @param array $selected @@ -5951,7 +5993,14 @@ class e_admin_form_ui extends e_form // ------------------------------------------ + $coreBatchOptions = array( + 'delete' => $controller->getBatchDelete(), + 'copy' => $controller->getBatchCopy(), + 'url' => $controller->getBatchLink(), + 'featurebox' => $controller->getBatchFeaturebox(), + 'export' => $controller->getBatchExport() + ); $options[$id] = array( @@ -5969,7 +6018,9 @@ class e_admin_form_ui extends e_form 'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref 'table_pre' => '', // markup to be added before opening table element // 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox()) : '', - 'table_post' => $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox(), $controller->getBatchOptions()), + + + 'table_post' => $this->renderBatch($coreBatchOptions, $controller->getBatchOptions()), 'fieldset_pre' => '', // markup to be added before opening fieldset element 'fieldset_post' => '', // markup to be added after closing fieldset element @@ -6264,15 +6315,17 @@ class e_admin_form_ui extends e_form // FIXME - use e_form::batchoptions(), nice way of buildig batch dropdown - news administration show_batch_options() - function renderBatch($allow_delete = false,$allow_copy= false, $allow_url=false, $allow_featurebox=false, $customBatchOptions=array()) + + /** + * @param array $options array of flags for copy, delete, url, featurebox, batch + * @param array $customBatchOptions + * @return string + */ + function renderBatch($options, $customBatchOptions=array()) { - - // $allow_copy = TRUE; - + $fields = $this->getController()->getFields(); - - - + if(!varset($fields['checkboxes'])) { $mes = e107::getMessage(); @@ -6283,7 +6336,7 @@ class e_admin_form_ui extends e_form // FIX - don't show FB option if plugin not installed if(!e107::isInstalled('featurebox')) { - $allow_featurebox = false; + $options['featurebox'] = false; } // TODO - core ui-batch-option class!!! REMOVE INLINE STYLE! @@ -6302,10 +6355,11 @@ class e_admin_form_ui extends e_form if(!$this->getController()->getTreeModel()->isEmpty()) { - $selectOpt .= ($allow_copy ? $this->option(LAN_COPY, 'copy', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); - $selectOpt .= ($allow_delete ? $this->option(LAN_DELETE, 'delete', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); - $selectOpt .= ($allow_url ? $this->option(LAN_UI_BATCH_CREATELINK, 'url', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); - $selectOpt .= ($allow_featurebox ? $this->option(LAN_PLUGIN_FEATUREBOX_BATCH, 'featurebox', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); + $selectOpt .= !empty($options['copy']) ? $this->option(LAN_COPY, 'copy', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''; + $selectOpt .= !empty($options['delete']) ? $this->option(LAN_DELETE, 'delete', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''; + $selectOpt .= !empty($options['export']) ? $this->option(LAN_UI_BATCH_EXPORT, 'export', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''; + $selectOpt .= !empty($options['url']) ? $this->option(LAN_UI_BATCH_CREATELINK, 'url', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''; + $selectOpt .= !empty($options['featurebox']) ? $this->option(LAN_PLUGIN_FEATUREBOX_BATCH, 'featurebox', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''; if(!empty($customBatchOptions)) { diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index 2331be6c2..c892fc5f7 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -1711,6 +1711,10 @@ class e_model extends e_object return e107::getParser()->parseTemplate($template, $parsesc, $this, $eVars); } + /** + * Export a Model configuration + * @return string + */ public function toXML() { $ret = "\n"; @@ -3706,4 +3710,32 @@ class e_admin_tree_model extends e_front_tree_model } return $ret; } + + + /** + * Export Selected Data + * @param $ids + * @return null + */ + public function export($ids) + { + $ids = e107::getParser()->filter($ids,'int'); + + if(empty($ids)) + { + return false; + } + + $idstr = implode(', ', $ids); + + $table = array($this->getModelTable()); + + $filename = "e107Export_" .$this->getModelTable()."_". date("YmdHi").".xml"; + $query = $this->getFieldIdName().' IN ('.$idstr.') '; // ORDER BY '.$this->getParam('db_order') ; + + e107::getXML()->e107Export(null,$table,null,array('file'=>$filename,'query'=>$query)); + + return null; + + } } diff --git a/e107_handlers/xml_class.php b/e107_handlers/xml_class.php index 5f736bbd3..af90ac3ae 100644 --- a/e107_handlers/xml_class.php +++ b/e107_handlers/xml_class.php @@ -869,10 +869,10 @@ class xmlClass * * @param array $prefs - see e_core_pref $aliases (eg. core, ipool etc) * @param array $tables - table names without the prefix - * @param boolean $debug [optional] + * @param array $options [optional] debug, return, query * @return string text / file for download */ - public function e107Export($xmlprefs, $tables, $plugPrefs, $mode = false) + public function e107Export($xmlprefs, $tables, $plugPrefs, $options = array()) { // error_reporting(0); $e107info = array(); @@ -904,7 +904,7 @@ class xmlClass { continue; } - elseif($mode === 'debug') + elseif(!empty($options['debug'])) { echo "
".htmlentities($text).""; return null; @@ -1016,8 +1017,10 @@ class xmlClass return true; } + $fileName = (!empty($options['file'])) ? $options['file'] : "e107Export_" . date("Y-m-d").".xml"; + header('Content-type: application/xml', TRUE); - header("Content-disposition: attachment; filename= e107Export_" . date("Y-m-d").".xml"); + header("Content-disposition: attachment; filename= ".$fileName); header("Cache-Control: max-age=30"); header("Pragma: public"); echo $text; diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php index 653349e0b..40979ed73 100644 --- a/e107_languages/English/admin/lan_admin.php +++ b/e107_languages/English/admin/lan_admin.php @@ -453,7 +453,8 @@ define("LAN_UI_DELETE_LABEL", "Confirm Delete"); define("LAN_UI_DELETE_WARNING", "You are about to delete [x] records. Please confirm to continue."); define("LAN_UI_BATCH_CREATELINK", "Create Link"); define("LAN_UI_DELETED", "[x] record(s) successfully deleted!"); -define("LAN_UI_DELETED_FAILED", "[x] records not found and not deleted!"); +define("LAN_UI_DELETED_FAILED", "[x] records not found and not deleted!");\ +define("LAN_UI_BATCH_EXPORT", "Export"); define("LAN_UI_USING_DATABASE_TABLE", "Using [x] database table"); define("LAN_UI_TOTAL_RECORDS", "Total Records: [x]");