From: hickert Date: Thu, 4 May 2006 08:01:44 +0000 (+0000) Subject: Udpated Summary tab X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f782b994036279feb5adb34c55da1416f5612882;p=gosa.git Udpated Summary tab git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3198 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/fai/class_faiSummaryTab.inc b/plugins/admin/fai/class_faiSummaryTab.inc index 59b645fdc..2bfc22726 100644 --- a/plugins/admin/fai/class_faiSummaryTab.inc +++ b/plugins/admin/fai/class_faiSummaryTab.inc @@ -20,45 +20,35 @@ class faiSummaryTab extends plugin{ - var $Classes = array(); - var $Release = ""; - var $Releases= array(); - var $Result = array(); - var $objs = array(); - var $ObjectList = ""; - - var $FAIclass; - var $attributes = array("FAIclass"); - - var $is_dialog = false; - - var $InitCalled = false; + var $Classes = array(); + var $Release = ""; + var $Releases = array(); + var $Result = array(); + var $objs = array(); + var $ObjectList = ""; + var $is_dialog = false; + var $InitCalled = false; + var $usedClasses = array(); function faiSummaryTab($config,$dn) { plugin::plugin($config,$dn); /* Base object configuration */ - $this->objs = array( "FAIscript" => array( "Image" =>"images/fai_script.png", - "Tree" =>"ou=scripts,") , - "FAIhook" => array( "Image" =>"images/fai_hook.png" , - "Tree" =>"ou=hooks,"), - "FAIvariable" => array( "Image" =>"images/fai_variable.png", - "Tree" =>"ou=variables,") , - "FAItemplate" => array( "Image" =>"images/fai_template.png", - "Tree" =>"ou=templates,") , - "FAIpartitionTable" => array( "Image" =>"images/fai_partitionTable.png", - "Tree" =>"ou=disk,") , - "FAIpackageList" => array( "Image" =>"images/fai_packages.png", - "Tree" =>"ou=packages,") , - "FAIprofile" => array( "Image" =>"images/fai_profile.png", - "Tree" =>"ou=profiles,")); + $this->objs = array( + "FAIscript" => array( "Image" =>"images/fai_script.png", "Name"=>_("Scripts") ,"Tree" =>"ou=scripts,") , + "FAIhook" => array( "Image" =>"images/fai_hook.png" , "Name"=>_("Hooks") ,"Tree" =>"ou=hooks,"), + "FAIvariable" => array( "Image" =>"images/fai_variable.png", "Name"=>_("Variables") ,"Tree" =>"ou=variables,") , + "FAItemplate" => array( "Image" =>"images/fai_template.png", "Name"=>_("Templates") ,"Tree" =>"ou=templates,") , + "FAIpartitionTable" => array( "Image" =>"images/fai_partitionTable.png","Name"=>_("Partition table") ,"Tree" =>"ou=disk,") , + "FAIpackageList" => array( "Image" =>"images/fai_packages.png", "Name"=>_("Package list") ,"Tree" =>"ou=packages,") , + "FAIprofile" => array( "Image" =>"images/fai_profile.png", "Name"=>_("Profiles") ,"Tree" =>"ou=profiles,")); } + /* Init the fai tree with objects. If this method is called, all assigned classes and the release name - will be read from parent object. - */ + will be read from parent object. */ function init() { $this->InitCalled = true; @@ -92,15 +82,44 @@ class faiSummaryTab extends plugin{ /* Set all available releases */ $this->Releases = array_flip($this->getBranches()); + $this->usedClasses = array(); /* Check the configuration */ if(count($this->Classes) && (!empty($this->Release))){ foreach($this->Classes as $class){ - $this->Result[$class] = $this->resolveObject($class); + $this->resolveObject($class); } } } + + /* Capture posts, and call opnen close tag */ + function save_object() + { + $once = true; + foreach($_POST as $name => $value ){ + + /* check for open tag request */ + if(preg_match("/^open_/",$name) && $once){ + $once = false; + $value = preg_replace("/^open_/","",$name); + $value = preg_replace("/_.*$/","",$value); + $this->Result[$value]['Open'] =true ; + } + /* Check for close tag request */ + if(preg_match("/^close_/",$name) && $once){ + $once = false; + $value = preg_replace("/^close_/","",$name); + $value = preg_replace("/_.*$/","",$value); + unset($this->Result[$value]['Open']); + } + if(preg_match("/^reloadList/",$name)){ + $this->InitCalled = false; + } + } + } + + /* returns an array with all possibly release types */ function getBranches($base = false,$prefix = "") { @@ -121,7 +140,8 @@ class faiSummaryTab extends plugin{ return($ret); } - /* Thsi function calls all nescessary functions to generate the fai class summary tree */ + + /* This function calls all nescessary functions to generate the fai class summary tree */ function execute() { /* Check if we must (re)init the this tab */ @@ -136,6 +156,7 @@ class faiSummaryTab extends plugin{ return($smarty->fetch (get_template_path('faiSummary.tpl', TRUE, dirname(__FILE__)))); } + /* Create output of from resolved fai objects */ function createSummary($data) { @@ -150,48 +171,127 @@ class faiSummaryTab extends plugin{ /* walk through all classes */ foreach($data as $key => $entry){ + + $image = "".$this->objs[$key]["; - /* Check every kind of object type */ - foreach($this->objs as $ok => $obj){ - - /* check of objectType is used */ - if(isset($entry[$ok])){ - $str.=""; - - /* Show open or close icon */ - if( ! $entry[$ok]['Open'] ){ - $str .= " "; - $str .=" "; - $str .= "".$entry[$ok]['Name'].""; - $str .= " ".$entry[$ok]['String1']; - }else{ - $str .= " "; - $str .=" "; - $str .= "".$entry[$ok]['Name'].""; - $str .= " ".$entry[$ok]['String1']; - if(!empty($entry[$ok]['String2'])){ - $str .= "".$entry[$ok]['String2']; + $str.=""; + if(!isset($entry['Open'])){ + $str .= " "; + $str .= $image." "; + $str .= "".$this->objs[$key]['Name'].""; + }else{ + $str .= " "; + $str .= $image." "; + $str .= "".$this->objs[$key]['Name'].""; + + /* Display FAItemplate FAIhook FAIscript entries */ + if(in_array($key,array("FAItemplate","FAIhook","FAIscript"))){ + + if($key == "FAIscript"){ + krsort($entry['Entries']); + foreach($entry['Entries'] as $scripts){ + ksort($scripts); + foreach($scripts as $script){ + $script['cn'][0] = "(".$script['FAIpriority'][0].") ".$script['cn'][0]; + $tmp[$script['cn'][0]] = $script; + } + } + $entry['Entries'] = $tmp; + } + + foreach($entry['Entries'] as $cn => $data){ + $str .=""; + $str .= ""; + $str .= $image." ".$data['cn'][0]; + if(isset($data['description'][0])){ + $str .= " [".$data['description'][0]."]"; } + $str .=""; + } + } - if(isset($data[$key][$ok]['data'])){ - $str.=$this->createSummary($data[$key][$ok]['data']); + /* Create variable entries */ + if(in_array($key,array("FAIvariable"))) { + foreach($entry['Entries'] as $cn => $data){ + $str .=""; + $str .= $image." ".$data['cn'][0]; + if(isset($data['description'][0])){ + $str .= " [".$data['description'][0]."] "; } + $str .=" = '".$data['FAIvariableContent'][0]."'"; + } + } + + /* Create packagelist entries */ + if(in_array($key,array("FAIpackageList"))) { + ksort($entry['Entries']); + foreach($entry['Entries'] as $cn => $data){ + $str .=""; + $str .= $image." ".$data; + } + } + + /* Create partition table entries */ + if(in_array($key,array("FAIpartitionTable"))) { + foreach($entry['Entries'] as $cn => $data){ + $str .=""; + $str .= $image." ".$data['name']; + ksort($data['partitions']); + $str .= " + + + + + + + + + "; + + $i = 0; + foreach($data['partitions'] as $key => $part){ + $i ++; + + if($i%2 == 1){ + $c = " class='rowxp1'"; + $d = " class='list1' style='border:0px;'"; + }else{ + $c = " class='rowxp0'"; + $d = " class='list0' style='border:0px;'"; + } + + $str.=" + + + + + + + + "; + } + $str .="
"._("No.").""._("Name").""._("FS options").""._("Mount options").""._("Size in MB").""._("Mount point").""._("Type")."
".$i."".$part['cn'][0]."".$part['FAIfsType'][0]."".$part['FAIfsOptions'][0]."".$part['FAIpartitionSize'][0]."".$part['FAImountPoint'][0]."".$part['FAIpartitionType'][0]."
"; } - $str .=""; } } + $str.="" ; } $str .=""; return($str); } + /* resolve specified object to append it to our object tree */ function resolveObject($class) { $ldap = $this->config->get_ldap_link(); $dn = $this->Releases [$this->Release]; $res = array(); + + if(in_array($class,$this->usedClasses)) return; + $this->usedClasses[] = $class; + /* Try to fetch all types of fai objects with the given cn */ foreach($this->objs as $key => $obj){ @@ -200,85 +300,48 @@ class faiSummaryTab extends plugin{ $ldap->ls("(&(objectClass=".$key.")(cn=".$class."))",$obj['Tree'].$dn,array("*")); while($attrs = $ldap->fetch()){ switch($key){ - case "FAIprofile": $tmp = $this->prepare_FAIprofile($attrs);break; - case "FAIscript": $tmp = $this->prepare_FAIscript($attrs);break; - case "FAIhook": $tmp = $this->prepare_FAIhook($attrs);break; - case "FAIvariable": $tmp = $this->prepare_FAIvariable($attrs);break; - case "FAItemplate": $tmp = $this->prepare_FAItemplate($attrs);break; - case "FAIpackageList": $tmp = $this->prepare_FAIpackageList($attrs);break; - case "FAIpartitionTable": $tmp = $this->prepare_FAIpartitionTable($attrs);break; - default : $tmp = array(); print_red(sprintf(_("Undefined FAI object '%s'."),$key)); - } - if(isset($tmp['Name'])){ - $res[$key] = $tmp ; + case "FAIprofile": $this->prepare_FAIprofile($attrs);break; + case "FAIscript": $this->prepare_FAIscript($attrs);break; + case "FAIhook": $this->prepare_FAIhook($attrs);break; + case "FAIvariable": $this->prepare_FAIvariable($attrs);break; + case "FAItemplate": $this->prepare_FAItemplate($attrs);break; + case "FAIpackageList": $this->prepare_FAIpackageList($attrs);break; + case "FAIpartitionTable": $this->prepare_FAIpartitionTable($attrs);break; } } } return($res); } + /* Prepare fai script */ function prepare_FAIscript($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; + if(isset($this->Result['FAIscript']['Entries'])){ + $current = $this->Result['FAIscript']['Entries']; }else{ - $res['String1'] = ""; + $current = array(); } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - - /* get subentries */ $ldap = $this->config->get_ldap_link(); $ldap->cd($data['dn']); - $ldap->search("(&(objectClass=FAIscriptEntry)(FAIpriority=*))",array("cn","description","FAIpriority")); - $scripts = array(); - - /* Create an array which is sortable by priority */ + $ldap->search("(objectClass=FAIscriptEntry)",array("cn","description","FAIpriority")); while($attrs = $ldap->fetch()){ - $scripts[$attrs['FAIpriority'][0]][] = $attrs; - } - - /* Sort by priority */ - ksort($scripts); - - /* append them to our list */ - $image = " "; - - foreach($scripts as $prio => $script){ - foreach($script as $attrs){ - $res['String2'] .=""; - if(isset($attrs['description'][0])){ - $res['String2'] .= $image.$attrs['FAIpriority'][0]." - ".$attrs['cn'][0]." [".$attrs['description'][0]."]
"; - }else{ - $res['String2'] .= $image.$attrs['FAIpriority'][0]." - ".$attrs['cn'][0]."
"; - } - $res['String2'] .="
"; - } + $current[$attrs['FAIpriority'][0]][$attrs['cn'][0]] = $attrs; } - return($res); + $this->Result['FAIscript']['Entries'] = $current ; } + /* Prepare fai script */ function prepare_FAIpartitionTable($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; + if(isset($this->Result['FAIpartitionTable']['Entries'])){ + $current = $this->Result['FAIpartitionTable']['Entries']; }else{ - $res['String1'] = ""; + $current = array(); } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - /* get subentries */ + /* get subentries */ $ldap = $this->config->get_ldap_link(); $ldap->cd($data['dn']); $ldap->search("(objectClass=FAIpartitionDisk)",array("cn","description")); @@ -286,8 +349,13 @@ class faiSummaryTab extends plugin{ /* Create an array which is sortable by priority */ while($attrs = $ldap->fetch()){ - $disks[$attrs['cn'][0]] = $attrs; - $disks[$attrs['cn'][0]]['partitions'] = array(); + if(isset($attrs['description'][0])){ + $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]." [".$attrs['description'][0]."]"; + }else{ + $disks[$attrs['cn'][0]]['name'] = $attrs['cn'][0]; + } + $disks[$attrs['cn'][0]]['dn'] = $attrs['dn']; + $disks[$attrs['cn'][0]]['partitions'] = array(); } /* Sort by priority */ @@ -301,317 +369,85 @@ class faiSummaryTab extends plugin{ $disks[$key]['partitions'][$attrs['cn'][0]] = $attrs; } } - - - $image = " "; - foreach($disks as $disk){ - $res['String2'] .= "
"; - $res['String2'] .= $image."".$disk['cn'][0] .""; - - if(isset($disk['description'][0])){ - $res['String2'] .= " [".$disk['description'][0]."]" ; - } - $res['String2'] .= "
"; - - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $i = 0; - foreach($disk['partitions'] as $partition){ - $i = !$i; - if($i){ - $c = " class='rowxp1'"; - $d = " class='list1' style='border:0px;'"; - }else{ - $c = " class='rowxp0'"; - $d = " class='list0' style='border:0px;'"; - } - - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - $res['String2'] .= ""; - } - $res['String2'] .= "
"._("No.").""._("Name").""._("FS options").""._("Mount options").""._("Size in MB").""._("Mount point").""._("Type")."
".$partition['FAIpartitionNr'][0]."".$partition['cn'][0]."".$partition['FAIfsType'][0]."".$partition['FAIfsOptions'][0]."".$partition['FAIpartitionSize'][0]."".$partition['FAImountPoint'][0]."".$partition['FAIpartitionType'][0]."
"; - } - - return($res); + $this->Result['FAIpartitionTable']['Entries'] = $disks; } /* Create template entry */ function prepare_FAItemplate($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; - }else{ - $res['String1'] = ""; + $current = array(); + if(isset($this->Result['FAItemplate']['Entries'])){ + $current = $this->Result['FAItemplate']['Entries']; } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - /* get subentries */ $ldap = $this->config->get_ldap_link(); $ldap->cd($data['dn']); $ldap->search("(objectClass=FAItemplateEntry)",array("cn","description")); - $scripts = array(); - - /* append them to our list */ - $image = " "; - - /* Create an array which is sortable by priority */ while($attrs = $ldap->fetch()){ - $res['String2'] .=""; - if(isset($attrs['description'][0])){ - $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]"; - }else{ - $res['String2'] .= $image.$attrs['cn'][0]; - } - $res['String2'] .="
"; + $current[$attrs['cn'][0]] = $attrs; } - return($res); + $this->Result['FAItemplate']['Entries'] = $current ; } /* Create a package list */ function prepare_FAIpackageList($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; - }else{ - $res['String1'] = ""; + $current = array(); + if(isset($this->Result['FAIpackageList']['Entries'])){ + $current = $this->Result['FAIpackageList']['Entries']; } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - - /* append them to our list */ - $image = " "; - - /* add selected packages to our list */ - if(isset($data['FAIpackage']['count'])) { + if(isset($data['FAIpackage'])){ unset($data['FAIpackage']['count']); - foreach($data['FAIpackage'] as $entry){ - $res['String2'].= $image.$entry."
"; - } + foreach($data['FAIpackage'] as $pkg){ + $current[$pkg] = $pkg; + } } - return($res); + $this->Result['FAIpackageList']['Entries'] = $current ; } /* Create a variable entry */ function prepare_FAIvariable($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; - }else{ - $res['String1'] = ""; + $current = array(); + if(isset($this->Result['FAIvariable']['Entries'])){ + $current = $this->Result['FAIvariable']['Entries']; } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - - /* get subentries */ $ldap = $this->config->get_ldap_link(); $ldap->cd($data['dn']); $ldap->search("(objectClass=FAIvariableEntry)",array("cn","description","FAIvariableContent")); - $scripts = array(); - - /* append them to our list */ - $image = " "; - - /* Create an array which is sortable by priority */ while($attrs = $ldap->fetch()){ - if(isset($attrs['description'][0])){ - $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]"; - }else{ - $res['String2'] .= $image.$attrs['cn'][0]; - } - if(isset($attrs['FAIvariableContent'][0])){ - $res['String2'] .= " \"".$attrs['FAIvariableContent'][0]."\" "; - } - $res['String2'] .= "
"; - + $current[$attrs['cn'][0]] = $attrs; } - return($res); + $this->Result['FAIvariable']['Entries'] = $current ; } /* Create a hook entry */ function prepare_FAIhook($data) { - /* Set basic attributes */ - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; - }else{ - $res['String1'] = ""; + $current = array(); + if(isset($this->Result['FAIhook']['Entries'])){ + $current = $this->Result['FAIhook']['Entries']; } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - - /* get subentries */ $ldap = $this->config->get_ldap_link(); $ldap->cd($data['dn']); $ldap->search("(objectClass=FAIhookEntry)",array("cn","description")); - $scripts = array(); - - /* append them to our list */ - $image = " "; - - /* Create an array which is sortable by priority */ while($attrs = $ldap->fetch()){ - $res['String2'] .=""; - if(isset($attrs['description'][0])){ - $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]
"; - }else{ - $res['String2'] .= $image.$attrs['cn'][0]."
"; - } - $res['String2'] .="
"; + $current[$attrs['cn'][0]] = $attrs; } - return($res); + $this->Result['FAIhook']['Entries'] = $current ; } + /* Create a new Profile entry */ function prepare_FAIprofile($data) { - /* initialise basics */ - $res = array(); - $res['Name'] = $data['cn'][0]; - if(isset($data['description'][0])){ - $res['String1'] = $data['description'][0]; - }else{ - $res['String1'] = ""; - } - $res['Open'] = false; - $res['id'] = ($_SESSION['faiSummaryTab']['UniqueID'] ++); - $res['Resolved']= true; - $res['String2'] = ""; - - /* Append empty data objects named by member classes */ - $res['data'] = array(); - if(isset($data['FAIclass'][0])){ - $tmp = split("\ ",$data['FAIclass'][0]); - foreach($tmp as $class){ - $res['data'][trim($class)] = array(); - } - } - return($res); - } - - - - /* Open the tag with the given id .. - so the entries of this tag will be shown */ - function openTag($data, $id) - { - /* Walk through objects */ - if(!count($data)) return(array()); - foreach($data as $key => $dat){ - - /* Check all types of objects (FAIhook, FAIscript ..)*/ - foreach($this->objs as $ok => $obj){ - - /* If this type of object is assigned */ - if(isset($dat[$ok])){ - - /* check given id */ - if($dat[$ok]['id'] == $id ){ - - /* Id was $id so set this leaf to open */ - $data[$key][$ok]['Open'] = true; - - /* Check if the sub leafs are already readed - if not, resolve the classes and append them to our tree */ - if(isset($dat[$ok]['data'])){ - - foreach($data[$key][$ok]['data'] as $key1 => $dat1){ - if(!count($dat1)){ - $tmp = $this->resolveObject($key1); - foreach($tmp as $r => $e) - $data[$key][$ok]['data'][$key1][$r] = $e; - } - } - } - } - /* Search sub tags for given id $id */ - if(isset($data[$key][$ok]['data'])){ - $data[$key][$ok]['data'] = $this->openTag($data[$key][$ok]['data'],$id); - } - } - } - } - return($data); - } - - /* Walk through all tags and close tag with id = $id*/ - function closeTag($data, $id) - { - $found = false; - - /* The parameter data is given as specified */ - // ClassName ['FAIprofile']['data'] - - /* Walk through all given classes */ - foreach($data as $key => $dat){ - - /* Walk through all possible objectClasses */ - foreach($this->objs as $ok => $obj){ - - /* If class is set, check if id matches */ - if(isset($dat[$ok])){ - if($dat[$ok]['id'] == $id ){ - $data[$key][$ok]['Open'] = false; - } - - /* Check subobjects for $id */ - if(isset($dat[$ok]['data'])){ - $data[$key][$ok]['data'] = $this->closeTag( $data[$key][$ok]['data'], $id); - } - } - } - } - return($data); - } - - /* Capture posts, and call opnen close tag */ - function save_object() - { - $once = true; - foreach($_POST as $name => $value ){ - - /* check for open tag request */ - if(preg_match("/^open_/",$name) && $once){ - $once = false; - $value = preg_replace("/^open_/","",$name); - $value = preg_replace("/_.*$/","",$value); - $this->Result = $this->openTag($this->Result,$value); - } - /* Check for close tag request */ - if(preg_match("/^close_/",$name) && $once){ - $once = false; - $value = preg_replace("/^close_/","",$name); - $value = preg_replace("/_.*$/","",$value); - $this->Result = $this->closeTag($this->Result,$value); - } - if(preg_match("/^reloadList/",$name)){ - $this->InitCalled = false; - } + $classes = split("\ ",$data['FAIclass'][0]); + foreach($classes as $class){ + $class = trim($class); + $this->resolveObject($class); } } }