Code

Fix for #144
[gosa.git] / trunk / gosa-core / include / class_MultiSelectWindow.inc
index 5d60c5a647a768d00efe75fa23e68168606689e1..8aae53bb7bfeb252dd8a5075c0e565db29e0e272 100644 (file)
 
 define ("SEPERATOR", 1002);
 
+/*! \brief Class to generate MultiSelectWindow
+ *
+ * Base class for multi selection/divList classes in a plugin.
+ */
 class MultiSelectWindow{
 
        var $bool_DisplayAlpahabet      = false;
@@ -66,6 +70,10 @@ class MultiSelectWindow{
   var $footer = "";
   var $post_id    = "1 2 3";
 
+  /*! \brief If this is set to TRUE the Draw() function returns a smarty object */
+  var $DrawReturnsSmartyObject = FALSE;
+  
+
        function ClearElementsList()
        {
     $ui =get_userinfo();
@@ -81,14 +89,15 @@ class MultiSelectWindow{
     $this->HideFilterPart = $bool;
   }
 
+  /*! \brief Set the height of the divlist */
   function SetHeight($height)
   { 
     $this->DivHeight=$height;
   }
 
        /* Adds a regex input field to the current dialog */
-       function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png")
-       {
+       function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png", $return_array=FALSE)
+  {
                $arr = array();
 
                /* Check if the given input field name was already used 
@@ -104,8 +113,13 @@ class MultiSelectWindow{
                $arr['name']            = $name;
                $arr['string']          = $string;
                $arr['image']           = $image;       
-               $arr['connAlpha']       = $conn;                // Connect with alphabet select 
-               $this->array_Regexes[] = $arr;
+    $arr['connAlpha']  = $conn;                // Connect with alphabet select
+    if (!$return_array) { 
+       $this->array_Regexes[] = $arr;
+    }
+    else {
+      return($arr);
+    }
        }
 
 
@@ -164,64 +178,70 @@ class MultiSelectWindow{
                $this->is_headpage = true;
        }
 
-       /* Sets the List internal name (not displayed anywhere) 
-          it is used to identify every single list
+       /* \brief Sets the List internal name (not displayed anywhere) 
+    
+     It is used to identify every single list.
         */     
        function SetTitle($str)
        {
                $this->string_Title = $str;
        }
 
-       /* Set the list header string  */
+       /*! \brief Set the list header string  */
        function SetListHeader($str)
        {
                $this->string_ListHeader = $str;
        }
 
-       /* This sets the list description which is the first gray bar on top of the list */
+       /*! \brief This sets the list description which is the first gray bar on top of the list */
        function SetSummary($str)
        {
                $this->string_Summary = $str;
        }
 
-       /* If the save button is enabled, you can change its caption with this function */      
+  /*! \brief Change the caption of the save button (if it is enabled) */
        function SetSaveButtonString($str)
        {
                $this->SaveButtonString = $str;
        }
 
-       /* If the close button is enabled, you can change its caption with this function */     
+  /*! \brief Change the caption of the close button (if it is enabled) */
        function SetCloseButtonString($str)
        {
                $this->CloseButtonString = $str;
        }
 
-       /* With this function you can change the text of the information box */
+  /*! \brief Change the text of the information box */
        function SetInformation($str)
        {
                $this->string_Information = $str;
        }
 
-       /* Display the alphabet selection box*/
+  /*! \brief Toggle the alphabet selection display */
        function EnableAplhabet($bool)
        {
                $this->bool_DisplayAlpahabet = $bool;
        }
 
-       /* Add additional header col */
+       /*! \brief Add additional header col */
        function AddHeader($arr)
        {
                $this->array_Header[] = $arr;
        }
 
-       /* add additional List element */
+       /*! \brief Add additional List element */
        function AddElement($arr)
        {
                $this->array_Elements[] = $arr;
        }
 
 
-  /* Return default header part. With back, home and root icons and department selection */
+  /*! \brief Return default header part.
+   * Returns the default header part (with back, home and root icons and
+   * department selection)
+   *
+   * \param boolean 'seperator' Show a seperator between each button (default: true)
+   * */
   function get_default_header($seperator= TRUE)
   {
     $enable_back = TRUE;
@@ -278,8 +298,10 @@ class MultiSelectWindow{
     return ($listhead);
   }
 
-       /* Add a checkbox to the filter element,
-          the name specifies an existing class var to store the 'selection' */
+  /*! \brief Add a checkbox to the filter element
+   *
+   * \param string 'name' specifies an existing class var to store the 'selection'
+   * */
        function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
        {
                $arr = array();
@@ -307,7 +329,7 @@ class MultiSelectWindow{
        }
 
 
-       /* Hides or unhides the checkbox with the given name */
+       /*! \brief Hides or unhides the checkbox with the given name */
        function DisableCheckBox($name,$HideShow = false)
        {
                foreach($this->array_Checkboxes as $key => $chkbox){
@@ -318,7 +340,7 @@ class MultiSelectWindow{
        }
 
 
-       /* Returns true if the close button was pressed */
+       /*! \brief Returns true if the close button was pressed */
        function isClosed()
        {
                return($this->is_closed);
@@ -330,19 +352,19 @@ class MultiSelectWindow{
   }
 
 
-       /* Enable the close button */
+       /*! \brief Enable the close button */
        function EnableCloseButton($bool)
        {
                $this->bool_DisplayCloseButton = $bool;
        }
 
-       /* Enable the save button on the bottom of the list*/
+       /*! \brief Enable the save button on the bottom of the list*/
        function EnableSaveButton ($bool)
        {
                $this->bool_DisplaySaveButton = $bool;
        }
 
-  /* Add a list specific filter object to position 
+  /*! \brief Add a list specific filter object to position 
       1 on top of Information 
       2 Between Information && Filter
       3 Below the Filter Part */
@@ -356,7 +378,60 @@ class MultiSelectWindow{
     $this->IgnoreAccount = !$ignore;
   }
 
-       /* Draw the list with all list elements and filters */
+  function GetCheckbox($box, $start_table=FALSE)
+  {
+    $ret = "";
+               $boxClick = " onClick='document.mainform.submit();' ";
+               if($box['name'] == SEPERATOR){
+                               $ret = "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
+                               return($ret);
+                       }
+
+    
+    /* Skip disabled boxes */
+               if(!$box['enabled']) return;
+
+               /* Check if box is checked */
+               if($box['default'] == true){
+                   $ret .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
+               }else{
+                   $ret .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
+    }
+
+    return($ret);
+  }
+
+  function GetRegex($regex, $draw_line=TRUE)
+  {
+      $ret = "";
+      $line_css = "";
+      if ($draw_line) {
+        $line_css = "solid #B0B0B0;";
+      }
+                       $ret="<table summary=\"\" style=\"width:100%;border-top:1px $line_css\">
+                               <tr>
+                               <td>
+                               <label for=\"".$regex['name']."\">
+                               <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
+                               </label>
+                               </td>
+                               <td width=\"99%\">
+                               <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
+                               value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\"> 
+                               </td>
+                               </tr>
+                               </table>";
+
+      return($ret);
+  }
+
+
+  /*! \brief Draw the list with all list elements and filters
+   *
+   * Returns a string with the HTML code that should be displayed.
+   * If this->DrawReturnsSmartyObject is TRUE (default: FALSE) it
+   * returns a smarty object.
+   * */
        function Draw()
        {
 
@@ -401,44 +476,17 @@ class MultiSelectWindow{
                /* Create checkboxes fields 
                 */
                $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=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
-                       }else{
-                               $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
-                       }
-               }
+    foreach($this->array_Checkboxes as $box){
+      $boxes .= $this->GetCheckbox($box);
+    }
                $smarty->assign("CheckBoxes", $boxes);
 
                /* Assign regex fields 
                 */
                $regexes = "";
-               foreach($this->array_Regexes as $regex){
-                       $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
-                               <tr>
-                               <td>
-                               <label for=\"".$regex['name']."\">
-                               <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
-                               </label>
-                               </td>
-                               <td width=\"99%\">
-                               <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
-                               value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\"> 
-                               </td>
-                               </tr>
-                               </table>";
-               }
+    foreach($this->array_Regexes as $regex){
+      $regexes .= $this->GetRegex($regex);
+    }
                $smarty->assign("regexes"                       , $regexes );
 
     /* Hide Filter Part if Requested or empty */
@@ -486,11 +534,16 @@ class MultiSelectWindow{
                $smarty->assign("filterName"    ,       $this->filterName);
                $smarty->assign("is_headpage"   ,       $this->is_headpage);
 
-               $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
-               return($display);
+    if (!$this->DrawReturnsSmartyObject) {
+      $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
+      return($display);
+    }
+    else {
+      return($smarty);
+    }
        }
 
-       /* Set the close var, which simulates the close button is pressed */
+  /*! \brief Set the close var (simulates a press of the the close button) */
        function Close()
        {
                $this->is_closed = true;
@@ -501,8 +554,10 @@ class MultiSelectWindow{
                $this->is_saved = true;
        }
 
-       /* Store all checkboxes/ regexes ... 
-          Store data also into a session var, to keep the checkboxes check after reload  */
+  /*! \brief Store all checkboxes/ regexes ... 
+   *
+   * Store data also into a session var, to keep the checkboxes check after reload
+   */
        function save_object()
        {
 
@@ -650,7 +705,12 @@ class MultiSelectWindow{
        }
 
 
-       /* this function adds the sub-departments of the current tree to the list */
+  /*! \brief Adds the sub-departments of the current tree to the list
+   *
+   *
+   * \param mixed 'base' use a certain base or FALSE if $this->selectedBase should
+   * be used (default).
+   */
        function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
        {
                $this->DepartmentsAdded = true;