Code

Updated hotplug hanlding for users
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Oct 2007 11:40:30 +0000 (11:40 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Oct 2007 11:40:30 +0000 (11:40 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7469 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/personal/environment/class_environment.inc
plugins/personal/environment/class_hotplugDialog.inc
plugins/personal/environment/environment.tpl
plugins/personal/environment/hotplugDialogNew.tpl [deleted file]

index aafbd288d3993965c2ac0700094a420919fefbd4..9d618039e01b61ea49e26b081859fad4a14e7c67 100644 (file)
@@ -68,7 +68,7 @@ class environment extends plugin
 
   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
 
-  var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDevice",
+  var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
       "gotoXResolution","gotoProfileQuota",
       "gotoLogonScripts","gotoLogonScript",
       "gotoPrinter", "gosaDefaultPrinter",
@@ -120,37 +120,22 @@ class environment extends plugin
       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
         $ldap->cat(base64_decode($this->attrs['gotoHotplugDeviceDN'][$i]));
         $attrs = $ldap->fetch(); 
-        $this->gotoHotplugDevices[$attrs['cn'][0]] = array('name' => $attrs['cn'][0], 'id' => rand(1,10));
+
+        if(isset($attrs['gotoHotplugDevice'][0])){
+          $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
+          $tmp2     = array();
+          $tmp2['name']         = $attrs['cn'][0];
+          $tmp2['description']  = $tmp[0];
+          $tmp2['id']           = $tmp[1];
+          $tmp2['produkt']      = $tmp[2];
+          $tmp2['vendor']       = $tmp[3];
+          $tmp2['dn']           = $attrs['dn'];
+          $this->gotoHotplugDevices[] = $tmp2; 
+        }
       }
     }
-  
-
-#   /* prepare hotplugs */
-#   if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
-#     unset($this->attrs['gotoHotplugDevice']['count']);
-#     foreach($this->attrs['gotoHotplugDevice'] as $device){
-#       $tmp = $tmp2 = array();
-#       $tmp = split("\|",$device);
-#       $tmp2['name']        = $tmp[0]; 
-#       $tmp2['description'] = $tmp[1]; 
-#       $tmp2['id']          = $tmp[2]; 
-#
-#       /* Produkt ID */
-#       if(!isset($tmp[3])){
-#         $tmp[3] = "";
-#       }
-#       /* Vendor ID */
-#       if(!isset($tmp[4])){
-#         $tmp[4] = "";
-#       }
-#
-#       $tmp2['produkt']     = $tmp[3]; 
-#       $tmp2['vendor']      = $tmp[4];
-#
-#       $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
-#     }
-#   }
 
     /* prepare LogonScripts */
     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
       unset($this->attrs['gotoLogonScript']['count']);
@@ -313,8 +298,6 @@ class environment extends plugin
   function execute()
   {
 
-  
-
     /* Call parent execute */
     plugin::execute();
     /* Log view */
@@ -749,12 +732,6 @@ class environment extends plugin
      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
      */
 
-    /* If there is a new entry wanted, open a new entry by initilising the dialog */
-    if((isset($_POST['gotoHotplugDeviceNew'])) && ($this->acl_is_writeable("gotoHotplugDevice"))){
-      $this->dialog = new hotplugDialog($this->config,$this->dn);
-      $this->is_dialog = true;
-    }
-
     /* We have to delete the selected hotplug from the list*/
     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
       if($this->acl_is_writeable("gotoHotplugDevice")){
@@ -770,7 +747,7 @@ class environment extends plugin
       foreach($this->gotoHotplugDevices as $plugs){
         $tmp[] = $plugs['name'];
       }
-      $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
+      $this->dialog = new hotplugDialog($this->config,$tmp);
       $this->is_dialog = true;
     }
 
@@ -1167,12 +1144,7 @@ class environment extends plugin
     /* Prepare HotPlug devices */
     $this->attrs['gotoHotplugDevice'] = array();
     foreach($this->gotoHotplugDevices as $name => $device){
-
-      $tmp= $device['name']."|".$device['description']."|".$device['id'];
-      if (isset($device['produkt']) && isset($device['vendor'])){
-        $tmp.= "|".$device['produkt']."|".$device['vendor'];
-      }
-      $this->attrs['gotoHotplugDevice'][]= $tmp;
+      $this->attrs['gotoHotplugDeviceDN'][]= base64_encode($device['dn']);
     }
 
     /* Prepare LogonScripts */
index 2e69647fb518be0db11cd87fc10f598739a1e8c0..a4b446b7bb1f674a8f066e2a8e3c690d1919bd81 100644 (file)
@@ -8,17 +8,6 @@ class hotplugDialog extends plugin
   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* attribute list for save action */
-  var $ignore_account       = TRUE;
-  var $attributes           = array("HOT_name","HOT_description","HOT_id","HOT_produkt","HOT_vendor");
-  var $objectclasses        = array("whatever");
-  var $use_existing         = false;  
-
-  var $HOT_name                 = "";
-  var $HOT_description          = "";
-  var $HOT_id                   = "0x0000";
-  var $HOT_produkt              = "";
-  var $HOT_vendor               = "";
-
   var $hotplugDevices           = ""; 
   var $hotplugDeviceList        = array(); 
   var $regex                    = "*";
@@ -26,202 +15,97 @@ class hotplugDialog extends plugin
   var $deplist                  = "/";
   var $skipThese                = array();
 
-  function hotplugDialog (&$config, $dn= NULL,$use_existing=false ,$skipThese = array())
+  function hotplugDialog (&$config,$skipThese = array())
   {
-    $this->use_existing = $use_existing;
-    $this->skipThese    = $skipThese;
-    plugin::plugin ($config, $dn);
-    $this->depselect = $this->config->current['BASE'];
+    $this->skipThese  = $skipThese;
+    $this->config     = $config;
+    $this->depselect  = $_SESSION['CurrentMainBase'];
   }
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
 
-    foreach($this->attributes as $s_attr){
-      $smarty->assign($s_attr,$this->$s_attr);
-    }
-
-    if($this->use_existing){
-
-      if(isset($_POST['dialogissubmitted'])){
-        $this->regex=$_POST['regexHot'];
-        $this->depselect = $_POST['depselectHot'];
-      }
-
-      if((isset($_GET['search']))&&(!empty($_GET['search']))){
-        $this->regex=$_GET['search']."*";
-        $this->regex=preg_replace("/\*\*/","*",$this->regex);
-      }
-
-      $this->deplist=$this->config->idepartments;
-
-      $this->hotplugDevices = $this->getHotplugs();
-      $smarty->assign("regexHot"    ,$this->regex);
-      $smarty->assign("deplistHot"  ,$this->deplist);
-      $smarty->assign("depselectHot",$this->depselect);
-      $smarty->assign("apply", apply_filter());
-      $smarty->assign("alphabet", generate_alphabet());
-      $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("tree_image", get_template_path('images/tree.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
-      $smarty->assign("deplist", $this->config->idepartments);
-
-
-      $smarty->assign("hotplugDevices",$this->hotplugDevices);
-      $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
-      $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
-    }else{
-      $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
-    }
-    return($display);
-  }
-
-  function remove_from_parent()
-  {
-    /* This cannot be removed... */
-  }
-
-
-  /* Save data to object */
-  function save_object()
-  {
     if(isset($_POST['dialogissubmitted'])){
-      plugin::save_object();
-      foreach($this->attributes as $s_attr){
-        if(isset($_POST[$s_attr])){
-          if(in_array($s_attr,array("HOT_produkt","HOT_vendor"))){
-            $this->$s_attr = strtolower(stripslashes($_POST[$s_attr]));
-          }else{
-            $this->$s_attr = stripslashes($_POST[$s_attr]);
-          }
-        }else{
-          $this->$s_attr = false;
-        }
-      }
+      $this->regex=$_POST['regexHot'];
+      $this->depselect = $_POST['depselectHot'];
     }
-  }
-
-
-  /* Check supplied data */
-  function check()
-  {
-    /* Call common method to give check the hook */
-    $message= plugin::check();
 
-    if(!$this->use_existing){
-
-      if(empty($this->HOT_name)||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
-        $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
-      }
-      if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description)){
-        $message[]=_("Invalid character in description. Please specify a valid description.");
-      }
-
-      if(empty($this->HOT_id) || preg_match("/[\|\*]/i",$this->HOT_id)){
-        $message[]=_("Please specify a valid iSerial.");
-      }
-      if(empty($this->HOT_vendor) || !$this->is_2byteHex($this->HOT_vendor)){
-        $message[]=_("Please specify a valid vendor ID. (2 byte hex like '0xFFFF')");
-      }
-      if(empty($this->HOT_produkt) || !$this->is_2byteHex($this->HOT_produkt)){
-        $message[]=_("Please specify a valid product ID. (2 byte hex like '0xFFFF')");
-      }
+    if((isset($_GET['search']))&&(!empty($_GET['search']))){
+      $this->regex=$_GET['search']."*";
+      $this->regex=preg_replace("/\*\*/","*",$this->regex);
+    }
 
-      $ldap = $this->config->get_ldap_link();
-      $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
-      if($ldap->count()){
-        $message[]=_("An Entry with this name already exists.");
-      }
+    $this->deplist=$this->config->idepartments;
 
-    }else{
-      if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
-        $message[] = _("Please select an entry or press cancel.");
-      }
-    }
+    $this->hotplugDevices = $this->getHotplugs();
+    $smarty->assign("regexHot"    ,$this->regex);
+    $smarty->assign("deplistHot"  ,$this->deplist);
+    $smarty->assign("depselectHot",$this->depselect);
+    $smarty->assign("apply", apply_filter());
+    $smarty->assign("alphabet", generate_alphabet());
+    $smarty->assign("search_image", get_template_path('images/search.png'));
+    $smarty->assign("tree_image", get_template_path('images/tree.png'));
+    $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
+    $smarty->assign("deplist", $this->config->idepartments);
 
-    return ($message);
-  }
 
-  function is_2byteHex($str)
-  {
-    return empty($str) || preg_match("/^(0x|x|)[a-f0-9][a-f0-9][a-f0-9][a-f0-9]/i",$str);
+    $smarty->assign("hotplugDevices",$this->hotplugDevices);
+    $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
+    $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
+    return($display);
   }
-  
-
 
 
   /* Save to LDAP */
   function save()
   {
-    /* return generated entry from input fields*/
-    if(!$this->use_existing){
-      $a_return=array();
-      $a_return[$this->HOT_name]['name']        = $this->HOT_name; 
-      $a_return[$this->HOT_name]['description'] = $this->HOT_description; 
-      $a_return[$this->HOT_name]['id']          = $this->HOT_id;
-      $a_return[$this->HOT_name]['produkt']     = $this->HOT_produkt;
-      $a_return[$this->HOT_name]['vendor']      = $this->HOT_vendor;
-      return($a_return); 
-    }else{
-      $entries = array();
-      foreach($_POST['hotplugName'] as $name){
-        $entries[$name] = $this->hotplugDeviceList[$name];
-      }
-      return $entries;
+    $entries = array();
+    foreach($_POST['hotplugName'] as $name){
+      $entries[$name] = $this->hotplugDeviceList[$name];
     }
+    return $entries;
   }
 
-  function getHotplugs(){
+  function getHotplugs()
+  {
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->depselect);
-
-    $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
+    $ldap->search("(&(objectClass=gotoDevice)(|(cn=".$this->regex.")(description=".$this->regex.")))",array("gotoHotplugDevice","cn","dn")); 
 
     $a_return = array();  
     $this->hotplugDeviceList = array();
     while($attr = $ldap->fetch()){
-      if(isset($attr['gotoHotplugDevice'])){
-        unset($attr['gotoHotplugDevice']['count']);
-        foreach($attr['gotoHotplugDevice'] as $device){
-          $tmp =$tmp2= array();
-          $tmp = split("\|",$device);
+
+      if(isset($attr['gotoHotplugDevice'][0])){
+
+        $hot_plug = $attr['gotoHotplugDevice'][0];
+        $tmp      = preg_split("/\|/",$hot_plug);
+        $tmp2     = array();
           
-          if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
-  
-            if(in_array($tmp[0],$this->skipThese)) continue;
-
-            $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
-            
-            $tmp2['name']         = $tmp[0];
-            $tmp2['description']  = $tmp[1];
-            $tmp2['id']           = $tmp[2];
-
-            /* Produkt ID */
-            if(!isset($tmp[3])){
-              $tmp[3] = "";
-            }
-            /* Vendor ID */
-            if(!isset($tmp[4])){
-              $tmp[4] = "";
-            }
-
-            $tmp2['produkt']      = $tmp[3];
-            $tmp2['vendor']       = $tmp[4];
-
-            $this->hotplugDeviceList[$tmp[0]]=$tmp2;
-          }
+        if(in_array($attr['cn'][0],$this->skipThese)){
+          continue;
         }
+
+        $tmp2['name']         = $attr['cn'][0];
+        $tmp2['description']  = $tmp[0];
+        $tmp2['id']           = $tmp[1];
+        $tmp2['produkt']      = $tmp[2];
+        $tmp2['vendor']       = $tmp[3];
+        $tmp2['dn']           = $attr['dn'];
+
+        $a_return[$attr['cn'][0]]= $attr['cn'][0]." [".$tmp[0]."] ".$tmp[1];
+
+        $this->hotplugDeviceList[$attr['cn'][0]]=$tmp2;
       }
     }
-  return($a_return);
+    return($a_return);
   }
-
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 391e3acdbd87774e1efb3067a31fc9fdc4a2ffc5..9cd024de5ab397c623434bde83a090ac7c514f37 100644 (file)
     </tr>
     <tr>
      <td>
-{render acl=$gotoHotplugDeviceACL}
-      <input type="submit" name="gotoHotplugDeviceNew" value="{t}New{/t}">
-{/render}
 {render acl=$gotoHotplugDeviceACL}
       <input type="submit" name="gotoHotplugDeviceUse" value="{t}Existing{/t}">
 {/render}
diff --git a/plugins/personal/environment/hotplugDialogNew.tpl b/plugins/personal/environment/hotplugDialogNew.tpl
deleted file mode 100644 (file)
index 93a3b12..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<h2><img class="center" alt="" src="images/hotplug.png" align="middle">&nbsp;{t}Create new hotplug entry{/t}</h2>
-       
-       <input type="hidden" name="dialogissubmitted" value="1">
-       
-<table width="100%" summary="">
- <tr>
-  <td width="50%" style="vertical-align:top">
-       <table summary="{t}Create new hotplug device{/t}" style="border-right:1px solid #B0B0B0;width:100%">
-               <tr>
-                       <td><LABEL for="HOT_name">{t}Device name{/t}</LABEL>{$must}
-                       </td>
-                       <td>    
-                               <input type="text" size=40 value="{$HOT_name}" name="HOT_name" id="HOT_name">
-                       </td>
-               </tr>
-               <tr>
-                       <td><LABEL for="HOT_description">{t}Description{/t}</LABEL>
-                       </td>
-                       <td>
-                               <input type="text" size=40 value="{$HOT_description}" name="HOT_description" id="HOT_description">
-                       </td>
-               </tr>
-       </table>
-   </td>
-   <td style="vertical-align:top">
-       <table summary="">
-               <tr>
-                       <td><LABEL for="HOT_id">{t}Serial number{/t}&nbsp;{t}(iSerial){/t}</LABEL>{$must}
-                       </td>
-                       <td>
-                               <input type="text" value="{$HOT_id}" name="HOT_id" id="HOT_id">
-                       </td>
-                       <td colspan="2">&nbsp;</td>
-               </tr>
-               <tr>
-                       <td><LABEL for="HOT_vendor">{t}Vendor-ID{/t}&nbsp;{t}(idVendor){/t}</LABEL>{$must}
-                       </td>
-                       <td>
-                               <input type="text" value="{$HOT_vendor}" name="HOT_vendor" id="HOT_vendor">
-                       </td>
-               </tr>
-               <tr>
-                       <td><LABEL for="HOT_produkt">{t}Product-ID{/t}&nbsp;{t}(idProduct){/t}</LABEL>{$must}
-                       </td>
-                       <td>
-                               <input type="text" value="{$HOT_produkt}" name="HOT_produkt" id="HOT_produkt">
-                       </td>
-               </tr>
-       </table>
-</table>
-       <p class="seperator">&nbsp;</p>
-       <p align="right">
-       <input type="submit" name="HotPlugSave"         value="{t}Save{/t}">
-       <input type="submit" name="HotPlugCancel"       value="{t}Cancel{/t}">
-       </p>
-<script language="JavaScript" type="text/javascript">
-  <!-- // First input field on page
-       focus_field('HOT_name');
-  -->
-</script>
-