Code

Added some features to multiSelectDialog
[gosa.git] / include / class_MultiSelectWindow.inc
index 80e6fe9b2dcd3616a0ab48c4bd2574c6831ea341..de36d8192271aa52a03f41a9f468962fe1bbcb4e 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+define ("SEPERATOR", 1002);
+
 class MultiSelectWindow{
 
        var $bool_DisplayAlpahabet      = false;
@@ -31,8 +33,10 @@ class MultiSelectWindow{
        function ClearElementsList()
        {
                $this->array_Elements = array();
+               #FIXME  print_sizelimit_warning() ? still missing
        }
 
+
        /* Adds a regex input field to the current dialog */
        function AddRegex($name,$string,$value,$conn,$image="images/search.png")
        {
@@ -127,25 +131,41 @@ class MultiSelectWindow{
 
        /* Add a checkbox to the filter element,
        the name specifies an existing class var to store the 'selection' */
-       function AddCheckBox($name,$value,$string,$default)
+       function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
        {
                $arr = array();
        
-               /* Check if there was already a variable 
-                       for this dialog which we should use instead of the default*/
-               if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
-                       $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
-                       $this->$name = $arr['default'];
+               if($name == SEPERATOR){
+                       $arr['name'] = SEPERATOR;
                }else{
-                       $arr['default'] = $default;
+                       /* Check if there was already a variable 
+                          for this dialog which we should use instead of the default*/
+                       if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
+                               $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
+                               $this->$name = $arr['default'];
+                       }else{
+                               $arr['default'] = $default;
+                       }
+                       $arr['name']    = $name;
+                       $arr['string']  = $string;
+                       $arr['value']   = $value;
+                       $arr['enabled'] = true;
                }
-
-               $arr['name']    = $name;
-               $arr['string']  = $string;
-               $arr['value']   = $value;
                $this->array_Checkboxes[] = $arr;
        }
 
+       /* Hides or unhides the checkbox with the given name */
+       function DisableCheckBox($name,$HideShow = false)
+       {
+               foreach($this->array_Checkboxes as $key => $chkbox){
+                       if($chkbox['name'] == $name){
+                               $this->array_Checkboxes[$key]['enabled'] = $HideShow;
+                       }
+               }
+       }
+
+       
+
        /* Returns true if the close button was pressed */
        function isClosed()
        {
@@ -193,6 +213,16 @@ class MultiSelectWindow{
                $boxes = "";
                $boxClick = " onClick='document.mainform.submit();' ";
                foreach($this->array_Checkboxes as $box){
+
+                       if($box['name'] == SEPERATOR){
+                               $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
+                               continue;
+                       }
+
+                       /* Skip disabled boxes */
+                       if(!$box['enabled']) continue;
+
+                       /* Check if box is checked */
                        if($box['default'] == true){
                                $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick.">&nbsp;".$box['string']."<br>";
                        }else{
@@ -225,12 +255,13 @@ class MultiSelectWindow{
          */    
                $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
                $smarty->assign("alphabet",             generate_alphabet());
-
                $smarty->assign("Header"                        , $this->string_ListHeader );
                $smarty->assign("Summary"                       , $this->string_Summary);
                $smarty->assign("Title"                         , $this->string_Title);
                $smarty->assign("Information"           , $this->string_Information);
-
+               
+               /* Check for exeeded sizelimit */
+               $smarty->assign("hint"                          , print_sizelimit_warning());
                $smarty->assign("DivList"                       , $divlist->DrawList());
 
 
@@ -326,11 +357,8 @@ class MultiSelectWindow{
        }
 
        /* this function adds the sub-departments of the current tree to the list */
-       function AddDepartments($base = false)
+       function AddDepartments($base = false,$numtabs = 3)
        {
-               
-               #FIXME the num of header cols must match the num of entry cols .        
-       
                /* check for a valid base */
                if(!$base){
                        if(!isset($_SESSION['CurrentMainBase'])){
@@ -383,11 +411,23 @@ class MultiSelectWindow{
                                }
                        }
 
+                       
                        /* Add to divlist */
-                       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
-                       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
-                       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
-                       $this->AddElement(array($field1,$field2,$field3));
+                       $row = array();
+                       $row[] = $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
+                       $row[] = $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
+
+                       if($numtabs > 2){       
+                               for($i = 2 ; $i <$numtabs;$i++){
+                                       if($i ==($numtabs-1)){
+                                               $row[] = array("string"=>"&nbsp;","attach" => "style='width:60px;border-right:0px;text-align:right;'");
+                                       }else{
+                                               $row[] = array("string"=>"&nbsp;");
+                                       }
+                               }
+                       }
+
+                       $this->AddElement($row);
                }
        }
 }