From 33eeabb42dcafad4f9eb040cc887c2a0fc44c428 Mon Sep 17 00:00:00 2001 From: cajus Date: Tue, 18 Aug 2009 13:36:12 +0000 Subject: [PATCH] * Fixed copy/paste detection * Added copy/paste to the XML based lists git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14084 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_listing.inc | 120 ++++++++++++++++++++++++++-- gosa-core/include/class_plugin.inc | 6 +- 2 files changed, 118 insertions(+), 8 deletions(-) diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index e9cc5d9eb..63124a194 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -45,6 +45,7 @@ class listing { var $pid; var $objectTypes= array(); var $objectTypeCount= array(); + var $CopyPasteHandler= null; function listing($filename) @@ -76,6 +77,12 @@ class listing { } + function setCopyPasteHandler($handler) + { + $this->CopyPasteHandler= &$handler; + } + + function registerElementFilter($name, $call) { if (!isset($this->filters[$name])) { @@ -113,9 +120,13 @@ class listing { "objectClass" => $data['OC'], "image" => $data['IMG']); } + $this->categories= array(); if (isset($this->xmlData['definition']['objectType'])) { foreach ($this->xmlData['definition']['objectType'] as $index => $otype) { $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index]; + if (isset($this->xmlData['definition']['objectType'][$index]['category'])){ + $this->categories[]= $this->xmlData['definition']['objectType'][$index]['category']; + } } } @@ -128,6 +139,9 @@ class listing { // Assign headline/module $this->headline= _($this->xmlData['definition']['label']); $this->module= $this->xmlData['definition']['module']; + if (!is_array($this->categories)){ + $this->categories= array($this->categories); + } return true; } @@ -186,7 +200,11 @@ class listing { function render() { -echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; +echo "snapshot handler, daemon handler
"; + // Check for exeeded sizelimit + if (($message= check_sizelimit()) != ""){ + return($message); + } // Initialize list $result= ""; @@ -303,6 +321,7 @@ echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; $smarty= get_smarty(); $smarty->assign("FILTER", $this->filter->render()); + $smarty->assign("SIZELIMIT", print_sizelimit_warning()); $smarty->assign("LIST", $result); // Assign navigation elements @@ -671,8 +690,15 @@ echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; #echo "actiontriggers: snapshot missing
"; } if ($action['type'] == "copypaste") { - #TODO - #echo "actiontriggers: copypaste missing
"; + + $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']); + $category= $class= null; + if ($objectType) { + $category= $objectType['category']; + $class= $objectType['class']; + } + + $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class); } if ($action['type'] == "daemon") { #TODO @@ -913,8 +939,7 @@ echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; // Check for special types switch ($action['type']) { case 'copypaste': - #TODO - #echo "actionmenu: copypaste missing
"; + $result.= $this->renderCopyPasteMenu($separator); break; case 'snapshot': @@ -1072,6 +1097,91 @@ echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; return $departments; } + + function renderCopyPasteMenu($separator, $copy= true, $cut= true) + { + // We can only provide information if we've got a copypaste handler + // instance + if(!(isset($this->CopyPasteHandler) && is_object($this->CopyPasteHandler))){ + return ""; + } + + // Presets + $result= ""; + $read= $paste= false; + $ui= get_userinfo(); + + // Switch flags to on if there's at least one category which allows read/paste + foreach($this->categories as $category){ + $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category)); + $paste= $paste || $ui->is_pasteable($this->base, $category) == 1; + } + + + // Draw entries that allow copy and cut + if($read){ + + // Copy entry + if($copy){ + $result.= " "._("Copy").""; + $separator= ""; + } + + // Cut entry + if($cut){ + $result.= " "._("Cut").""; + $separator= ""; + } + } + + // Draw entries that allow pasting entries + if($paste){ + if($this->CopyPasteHandler->entries_queued()){ + $result.= " "._("Paste").""; + }else{ + $result.= " "._("Paste").""; + } + } + + return($result); + } + + + function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true) + { + // We can only provide information if we've got a copypaste handler + // instance + if(!(isset($this->CopyPasteHandler) && is_object($this->CopyPasteHandler))){ + return ""; + } + + // Presets + $ui = get_userinfo(); + $result = ""; + + // Render cut entries + if($cut){ + if($ui->is_cutable($dn, $category, $class)){ + $result .= ""; + }else{ + $result.=" "; + } + } + + // Render copy entries + if($copy){ + if($ui->is_copyable($dn, $category, $class)){ + $result.= ""; + }else{ + $result.=" "; + } + } + + return($result); + } + } ?> diff --git a/gosa-core/include/class_plugin.inc b/gosa-core/include/class_plugin.inc index aaf246229..4d8f82a59 100644 --- a/gosa-core/include/class_plugin.inc +++ b/gosa-core/include/class_plugin.inc @@ -2068,10 +2068,10 @@ class plugin /* Check permissions for each category, if there is at least one category which support read or paste permissions for the given base, then display the specific actions. */ - $readable = $pasteable = TRUE; + $readable = $pasteable = false; foreach($category as $cat){ - $readable |= $ui->get_category_permissions($base,$cat); - $pasteable|= $ui->is_pasteable($base,$cat); + $readable= $readable || preg_match('/r/', $ui->get_category_permissions($base, $cat)); + $pasteable= $pasteable || $ui->is_pasteable($base, $cat) == 1; } if(($cut || $copy) && isset($this->CopyPasteHandler) && is_object($this->CopyPasteHandler)){ -- 2.30.2