From: cajus Date: Mon, 24 Aug 2009 16:46:11 +0000 (+0000) Subject: Added exporter X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=62c2547a71af33f8815bf3627822599c95153527;p=gosa.git Added exporter git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14122 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index 9ba7defd7..ecaaf244c 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -47,11 +47,15 @@ class listing { var $objectTypeCount= array(); var $copyPasteHandler= null; var $snapshotHandler= null; + var $exporter= array(); + var $exportColumns= array(); + var $showExporter= false; function listing($filename) { global $config; + global $class_mapping; // Initialize pid $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE)); @@ -75,6 +79,14 @@ class listing { $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink"); $this->registerElementFilter("link", "listing::filterLink"); $this->registerElementFilter("actions", "listing::filterActions"); + + // Load exporters + foreach($class_mapping as $class => $dummy) { + if (preg_match('/Exporter$/', $class)) { + $info= call_user_func(array($class, "getInfo")); + $this->exporter= array_merge($this->exporter, $info); + } + } } @@ -164,6 +176,15 @@ class listing { $this->categories= array($this->categories); } + // Evaluate columns to be exported + if (isset($this->xmlData['table']['column'])){ + foreach ($this->xmlData['table']['column'] as $index => $config) { + if (isset($config['export']) && $config['export'] == "true"){ + $this->exportColumns[]= $index; + } + } + } + return true; } @@ -171,6 +192,7 @@ class listing { function renderHeader() { $this->header= array(); + $this->plainHeader= array(); // Initialize sort? $sortInit= false; @@ -208,12 +230,14 @@ class listing { } else { $this->header[$index]= "colprops[$index].">"._($config['label']).""; } + $this->plainHeader[]= _($config['label']); } else { if ($sortable) { $this->header[$index]= "colprops[$index]."> $sorter"; } else { $this->header[$index]= "colprops[$index]."> "; } + $this->plainHeader[]= ""; } } } @@ -294,7 +318,7 @@ class listing { // Fill with contents, sort as configured foreach ($this->entries as $row => $entry) { - $trow ="\n"; + $trow= ""; // Render multi select if needed if ($this->multiSelect) { @@ -312,18 +336,18 @@ class listing { } $this->entries[$row]["_sort$index"]= $sort; } - $trow.="\n"; // Save rendered entry $this->entries[$row]['_rendered']= $trow; - - $alt++; } // Complete list by sorting entries for _sort$index and appending them to the output $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType); foreach ($entryIterator as $row => $entry){ + $alt++; + $result.="\n"; $result.= $entry['_rendered']; + $result.="\n"; } // Need to fill the list if it's not full (nobody knows why this is 22 ;-)) @@ -362,6 +386,12 @@ class listing { $result.= ""; + // Open export window? + if ($this->showExporter) { + $result.= ""; + $this->showExporter= false; + } + $smarty= get_smarty(); $smarty->assign("FILTER", $this->filter->render()); $smarty->assign("SIZELIMIT", print_sizelimit_warning()); @@ -417,6 +447,20 @@ class listing { } } + // Filter POST with "act" attributes -> posted from action menu + if (isset($_POST['act']) && $_POST['act'] != '') { + if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) { + $exporter= $this->exporter[$_POST['act']]; + $instance= new $exporter['class']($this->plainHeader, $this->entries, $this->exportColumns); + $type= call_user_func(array($exporter['class'], "getInfo")); + $type= $type[$_POST['act']]; + session::set('binarytype', $type['mime']); + session::set('binaryfile', $type['filename']); + session::set('binary', $instance->query()); + $this->showExporter= true; + } + } + // Filter GET with "act" attributes if (isset($_GET['act'])) { $key= validate($_GET['act']); @@ -910,7 +954,9 @@ class listing { // Filter POST with "act" attributes -> posted from action menu if (isset($_POST['act']) && $_POST['act'] != '') { - $result['action']= validate($_POST['act']); + if (!preg_match('/^export.*$/', $_POST['act'])){ + $result['action']= validate($_POST['act']); + } } // Drop targets if empty @@ -1272,7 +1318,9 @@ class listing { $result.= " "._("Export list")." "; diff --git a/gosa-core/include/exporter/class_cvsExporter.inc b/gosa-core/include/exporter/class_cvsExporter.inc new file mode 100644 index 000000000..110014f8b --- /dev/null +++ b/gosa-core/include/exporter/class_cvsExporter.inc @@ -0,0 +1,53 @@ + $dummy) { + $columns[]= $index; + } + } + + // Generate header + $this->result= "#"; + foreach ($columns as $index) { + if (isset($header[$index])){ + $this->result.= $header[$index].";"; + } else { + $this->result.= ";"; + } + } + $this->result= preg_replace('/;$/', '', $this->result)."\n"; + + // Append entries + foreach ($entries as $row) { + foreach ($columns as $index) { + if (isset($row["_sort$index"])){ + $this->result.= $row["_sort$index"].";"; + } else { + $this->result.= ";"; + } + } + $this->result= preg_replace('/;$/', '', $this->result)."\n"; + } + } + + + function query() + { + return $this->result; + } + + + static function getInfo() + { + return array("exportCVS" => array( "label" => _("CSV"), "image" => "plugins/lists/exportCSV.png", "class"=> "csvExporter", "mime" => "text/x-csv", "filename" => "export.csv" )); + } + +} + +?> diff --git a/gosa-core/plugins/admin/users/class_userManagement.inc b/gosa-core/plugins/admin/users/class_userManagement.inc index 1d128a6bb..3099387cd 100644 --- a/gosa-core/plugins/admin/users/class_userManagement.inc +++ b/gosa-core/plugins/admin/users/class_userManagement.inc @@ -988,40 +988,37 @@ class userManagement extends plugin $this->DivListUsers->setEntries($this->list); # FILTER Test ################################################# - ## Build filter - #if (!$this->filter) { - # $this->filter = new filter(get_template_path("user-filter.xml", true)); - # $this->filter->setObjectStorage(get_people_ou()); - #} - #$this->filter->update(); - #session::set('autocomplete', $this->filter); - #if (!$this->filter->isValid()){ - # msg_dialog::display(_("Filter error"), _("The filter is uncomplete!"), ERROR_DIALOG); - #} - - ## Build headpage - #if (!$this->headpage){ - # $this->headpage = new listing(get_template_path("user-list.xml", true)); - # $this->headpage->registerElementFilter("accountProperties", "userManagement::filterProperties"); - # $this->headpage->registerElementFilter("lockLabel", "userManagement::filterLockLabel"); - # $this->headpage->registerElementFilter("lockImage", "userManagement::filterLockImage"); - # $this->headpage->setCopyPasteHandler($this->CopyPasteHandler); - # $this->SnapshotHandler->setSnapshotBases($this->get_used_snapshot_bases()); - # $this->headpage->setSnapshotHandler($this->SnapshotHandler); - # $this->headpage->setFilter($this->filter); - #} - - ## Needs to be called before update! - #$action= $this->headpage->getAction(); - #if ($action['action'] != '') { - # echo "List detected action:"; - # print_a($action); - #} - - ## Refresh for filter - #$this->headpage->update(); - # - #return($this->headpage->render()); + # Build filter + if (!$this->filter) { + $this->filter = new filter(get_template_path("user-filter.xml", true)); + $this->filter->setObjectStorage(get_people_ou()); + } + $this->filter->update(); + session::set('autocomplete', $this->filter); + if (!$this->filter->isValid()){ + msg_dialog::display(_("Filter error"), _("The filter is uncomplete!"), ERROR_DIALOG); + } + + # Build headpage + if (!$this->headpage){ + $this->headpage = new listing(get_template_path("user-list.xml", true)); + $this->headpage->registerElementFilter("accountProperties", "userManagement::filterProperties"); + $this->headpage->registerElementFilter("lockLabel", "userManagement::filterLockLabel"); + $this->headpage->registerElementFilter("lockImage", "userManagement::filterLockImage"); + $this->headpage->setFilter($this->filter); + } + + # Needs to be called before update! + $action= $this->headpage->getAction(); + if ($action['action'] != '') { + echo "List detected action:"; + print_a($action); + } + + # Refresh for filter + $this->headpage->update(); + + return($this->headpage->render()); ################################################### FILTER Test return($this->DivListUsers->Draw());