Code

Updated gotomasses
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Feb 2008 13:29:27 +0000 (13:29 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Feb 2008 13:29:27 +0000 (13:29 +0000)
-Use an extra class for the target list dialog

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8987 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc
gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc [new file with mode: 0644]

index 88af593b728d3daccc39df0704df2f16585e7a15..90a6aecec564ff37b559fb2b49cd8a246a872e9b 100644 (file)
@@ -190,113 +190,28 @@ class DaemonEvent
   public function get_target_add_list()
   {
     $this->target_add_list_used = TRUE;
-    $smarty = get_smarty();
  
-    if($this->target_divlist == NULL){ 
-      $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargedtList","gotomasses");
-      $this->target_divlist->SetSummary(_("Targets"));
-      $this->target_divlist->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add and use the 'Use' button to accept."));
-      $this->target_divlist->EnableCloseButton(FALSE); 
-      $this->target_divlist->EnableSaveButton(FALSE);
-
-
-      /* Toggle all selected / deselected */
-      $chk = "<input type='checkbox' id='select_all' name='select_all'
-        onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
-
-      $this->target_divlist->EnableAplhabet(TRUE);
-  
-      /* set Page header */
-      $this->target_divlist->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
-      $this->target_divlist->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
-      $this->target_divlist->AddHeader(array("string"=>_("System / Department")));
-
-      //$name,$string,$value,$conn,$image="images/search.png") 
-      $this->target_divlist->AddRegex("regex" ,"regex"  ,"*"                , TRUE);
-      $this->target_divlist->AddRegex("ipfrom","ipfrom" ,"0.0.0.0"          , FALSE);
-      $this->target_divlist->AddRegex("ipto"  ,"ipto"   ,"255.255.255.255"  , FALSE);
-
-      $this->target_divlist->display_server       = TRUE;
-      $this->target_divlist->display_workstation  = TRUE;
-      $this->target_divlist->display_ogroup       = TRUE;
-      $this->target_divlist->filter_iprange       = FALSE;
-      $this->target_divlist->AddCheckBox("display_server","1"     ,_("Display server"),TRUE);
-      $this->target_divlist->AddCheckBox("display_workstation","1",_("Display workstation"),TRUE);
-      $this->target_divlist->AddCheckBox("display_ogroup","1"     ,_("Display object groups"),TRUE);
-      $this->target_divlist->AddCheckBox("filter_iprange","1"     ,_("Filter by IP range"),FALSE);
-
-    }
-    $this->target_divlist->ClearElementsList();
-
-    $modules = array("server","workstation");
-
-    /* Add base */
-    $tmp = array();
-    $base = $this->config->current['BASE'];
-    $tmp[] = array("dn"=>$this->config->current['BASE']);
-    $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base,
-                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
-
-    $deps = array();
-    foreach($tmp as $tm){
-      $deps[$tm['dn']] = $tm['dn'];
+    if(1 | $this->target_divlist == NULL){ 
+      $this->target_divlist = new EventTargetAddList($this->config,$this);
     }
-
-    $department = $departments = array();
-    $ui= get_userinfo();
-    $d = $ui->get_module_departments($modules);
-    foreach($d as $department){
-      $departments[$department] = $department;
-    }
-  
-     /* Load possible departments */
-    $ids = $this->config->idepartments;
-    $first = "";
-    $found = FALSE;
-    $options = array();
-    foreach($ids as $dep => $name){
-      if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
-
-        /* Keep first base dn in mind, we could need this
-         *  info if no valid base was found
-         */
-        if(empty($first)) {
-          $first = $dep['dn'];
-        }
-
-        $value = $ids[$dep];
-        if ($this->target_divlist->selectedBase == $dep){
-          $found = TRUE;
-          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
-        } else {
-          $options.= "<option value='".$dep."'>$value</option>";
-        }
-      }
-    }
-
-    $listhead = $this->target_divlist->get_default_header();
-
-    /* Add base selection */
-    $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
-      " <input class='center' type='image' src='images/list_submit.png' align='middle'
-      title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'>&nbsp;";
-
-    $this->target_divlist->SetListHeader($listhead);
-    $this->target_divlist->AddDepartments($this->target_divlist->selectedBase,2,1);
+    $this->target_divlist->execute();
 
     $_target_list = array();
     if($this->target_divlist->display_server){
-      $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=goServer))",
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=goServer))",
             "server",get_ou("serverou").$this->target_divlist->selectedBase,
             array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
     }
     if($this->target_divlist->display_workstation){
-      $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=gotoWorkstation))",
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=gotoWorkstation))",
             "workstation",get_ou("workstationou").$this->target_divlist->selectedBase,
             array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
     }
     if($this->target_divlist->display_ogroup){
-      $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(member=*)(objectClass=gosaGroupOfNames))",
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->target_divlist->regex.")(member=*)(objectClass=gosaGroupOfNames))",
             "ogroups",get_ou("ogroupou").$this->target_divlist->selectedBase,
             array("cn","objectClass","description","member"),GL_NONE));
     }
@@ -307,58 +222,18 @@ class DaemonEvent
       $tmp[$key] = $object['cn'][0];
     }
     natcasesort($tmp);
-
-    foreach($tmp as $key => $dummy){
-
-      $obj = $this->_target_list[$key];
-
-      $name = $obj['cn'][0];
-      if(isset($obj['description'])){
-        $name .= "&nbsp;[".$obj['description'][0]."]";
-      }
-      if(isset($obj['macAddress'])){
-        $name .= "&nbsp;- ".$obj['macAddress'][0]."";
-      }
-      if(isset($obj['ipHostNumber'])){
-        $name .= "&nbsp;- ".$obj['ipHostNumber'][0]."";
-      }
-
-      $img ="";
-      if(in_array("goServer",$obj['objectClass'])){
-        $img = '<img class="center" src="images/select_server.png" alt="S" title="'._("Server").'">'; 
-
-        if($this->target_divlist->filter_iprange){
-          if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->target_divlist->ipfrom,$this->target_divlist->ipto,$obj['ipHostNumber'][0])) {
-            continue;
-          }
-        }        
-        if(!isset($this->server_list[$obj['dn']])){
-          continue;
-        }
-      }elseif(in_array("gotoWorkstation",$obj['objectClass'])){
-        $img = '<img class="center" src="images/select_workstation.png" alt="W" title="'._("Workstation").'">'; 
-        if($this->target_divlist->filter_iprange){
-          if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->target_divlist->ipfrom,$this->target_divlist->ipto,              $obj['ipHostNumber'][0])) {
-            continue;
-          }
-        }
-        if(!isset($this->workstation_list[$obj['dn']])){
-          continue;
-        }
-      }elseif(in_array("gosaGroupOfNames",$obj['objectClass'])){
-        $img = '<img class="center" src="images/select_ogroup.png" alt="O" title="'._("Object group").'">'; 
-      }
-
-      $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>");
-      $field2 = array("string" => $img);
-      $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'");
-      $this->target_divlist->AddElement(array($field1,$field2,$field3));
+    $tmp2 = array();
+    foreach($tmp as $key => $sort){
+      $tmp2[] = $this->_target_list[$key];
     }
 
-    $smarty->assign("divlist",$this->target_divlist->Draw());
+    $this->target_divlist->setEntries($tmp2);
 
+    $smarty = get_smarty();
+    $smarty->assign("divlist",$this->target_divlist->Draw());
     return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
   }
+
  
   public function save_object()
   {
diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc b/gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc
new file mode 100644 (file)
index 0000000..4d68d62
--- /dev/null
@@ -0,0 +1,230 @@
+<?php
+
+class EventTargetAddList extends MultiSelectWindow
+{
+  public $display_server = TRUE;
+  public $display_workstation = TRUE;
+  public $display_ogroup = TRUE;
+  public $filter_iprange = FALSE;
+
+  public $regex  = "*";
+  public $ipfrom = "0.0.0.0";
+  public $ipto   = "*";
+  public $_target_list = array();
+
+  public $workstation_list = array();
+  public $server_list = array();
+
+
+  function __construct(&$config,$parent)
+  {
+    MultiSelectWindow::MultiSelectWindow($config, "EventTargetAddList", 
+        array("server",
+          "workstation",
+          "ogroup"));
+
+    $this->parent       = $parent;
+    $this->ui           = get_userinfo();
+
+
+    $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargedtList","gotomasses");
+    $this->SetSummary(_("Targets"));
+    $this->EnableCloseButton(FALSE);
+    $this->EnableSaveButton(FALSE);
+
+    $this->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add   and use the 'Use' button to accept."));
+
+    /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all'
+      onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
+    $this->EnableAplhabet(TRUE);
+
+    /* set Page header */
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
+    $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
+    $this->AddHeader(array("string"=>_("System / Department")));
+
+    //$name,$string,$value,$conn,$image="images/search.png")
+    $this->AddRegex("regex" ,"regex"  ,"*"                , TRUE);
+    $this->AddRegex("ipfrom","ipfrom" ,"0.0.0.0"          , FALSE);
+    $this->AddRegex("ipto"  ,"ipto"   ,"255.255.255.255"  , FALSE);
+
+    $this->AddCheckBox("display_server","1"     ,_("Display server"),TRUE);
+    $this->AddCheckBox("display_workstation","1",_("Display workstation"),TRUE);
+    $this->AddCheckBox("display_ogroup","1"     ,_("Display object groups"),TRUE);
+    $this->AddCheckBox("filter_iprange","1"     ,_("Filter by IP range"),FALSE);
+
+
+
+    /* Create a list of servers
+     */
+    $tmp = get_sub_list("(&(macAddress=*)(objectClass=goServer))",
+          "server",get_ou("serverou"),$config->current['BASE'],
+          array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH);
+    foreach($tmp as $server){
+      $this->server_list[$server['dn']] = $server;
+    }
+
+    /* Create a list of workstations
+     */
+    $tmp = get_sub_list("(&(macAddress=*)(objectClass=gotoWorkstation))",
+          "server",get_ou("workstationou"),$config->current['BASE'],
+          array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH);
+    foreach($tmp as $server){
+      $this->workstation_list[$server['dn']] = $server;
+    }
+
+  }
+
+
+  function execute()
+  {
+    $this->ClearElementsList();
+    $this->AddDepartments($this->selectedBase,2,1);
+    $this->GenHeader();
+  }
+
+
+  function GenHeader()
+  {
+    $modules = array("server","workstation");
+
+    /* Add base */
+    $tmp = array();
+    $base = $this->config->current['BASE'];
+    $tmp[] = array("dn"=>$this->config->current['BASE']);
+    $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base,
+          array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
+
+    $deps = array();
+    foreach($tmp as $tm){
+      $deps[$tm['dn']] = $tm['dn'];
+    }
+
+    $department = $departments = array();
+    $ui= get_userinfo();
+    $d = $ui->get_module_departments($modules);
+    foreach($d as $department){
+      $departments[$department] = $department;
+    }
+
+    /* Load possible departments */
+    $ids = $this->config->idepartments;
+    $first = "";
+    $found = FALSE;
+    $options = array();
+    foreach($ids as $dep => $name){
+      if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
+
+        /* Keep first base dn in mind, we could need this
+         *  info if no valid base was found
+         */
+        if(empty($first)) {
+          $first = $dep['dn'];
+        }
+
+        $value = $ids[$dep];
+        if ($this->selectedBase == $dep){
+          $found = TRUE;
+          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+        } else {
+          $options.= "<option value='".$dep."'>$value</option>";
+        }
+      }
+    }
+
+    $listhead = $this->get_default_header();
+
+    /* Add base selection */
+    $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
+      " <input class='center' type='image' src='images/list_submit.png' align='middle'
+      title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'>&nbsp;";
+
+    $this->SetListHeader($listhead);
+
+  }
+
+
+  function setEntries($list)
+  {
+
+
+    $_target_list = array();
+    if($this->display_server){
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->regex.")(objectClass=goServer))",
+            "server",get_ou("serverou").$this->selectedBase,
+            array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
+    }
+    if($this->display_workstation){
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->regex.")(objectClass=gotoWorkstation))",
+            "workstation",get_ou("workstationou").$this->selectedBase,
+            array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
+    }
+    if($this->display_ogroup){
+      $_target_list = array_merge($_target_list,
+            get_list("(&(cn=".$this->regex.")(member=*)(objectClass=gosaGroupOfNames))",
+            "ogroups",get_ou("ogroupou").$this->selectedBase,
+            array("cn","objectClass","description","member"),GL_NONE));
+    }
+    $this->_target_list = $_target_list;
+
+    $tmp = array();
+    foreach($this->_target_list as $key => $object){
+      $tmp[$key] = $object['cn'][0];
+    }
+    natcasesort($tmp);
+
+    foreach($tmp as $key => $obj){
+
+      $obj = $this->_target_list[$key];
+      $name = $obj['cn'][0];
+      if(isset($obj['description'])){
+        $name .= "&nbsp;[".$obj['description'][0]."]";
+      }
+      if(isset($obj['macAddress'])){
+        $name .= "&nbsp;- ".$obj['macAddress'][0]."";
+      }
+      if(isset($obj['ipHostNumber'])){
+        $name .= "&nbsp;- ".$obj['ipHostNumber'][0]."";
+      }
+
+      $img ="";
+      if(in_array("goServer",$obj['objectClass'])){
+        $img = '<img class="center" src="images/select_server.png" alt="S" title="'._("Server").'">';
+
+        if($this->filter_iprange){
+          if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto,             $obj['ipHostNumber'][0])) {
+            continue;
+          }
+        }
+        if(!isset($this->server_list[$obj['dn']])){
+          continue;
+        }
+      }elseif(in_array("gotoWorkstation",$obj['objectClass'])){
+        $img = '<img class="center" src="images/select_workstation.png" alt="W" title="'._("Workstation").'">';
+        if($this->filter_iprange){
+          if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto,$obj['ipHostNumber'][0])) {
+            continue;
+          }
+        }
+        if(!isset($this->workstation_list[$obj['dn']])){
+          continue;
+        }
+      }elseif(in_array("gosaGroupOfNames",$obj['objectClass'])){
+        $img = '<img class="center" src="images/select_ogroup.png" alt="O" title="'._("Object group").'">';
+      }
+
+      $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>",
+                      "attach" => "style='width:20px;'");
+      $field2 = array("string" => $img,
+                      "attach" => "style='width:20px;'");
+      $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'");
+      $this->AddElement(array($field1,$field2,$field3));
+    }
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>