Code

Updated environment multiple edit
[gosa.git] / gosa-core / plugins / personal / environment / class_environment.inc
index 3d5de28c2a84d43f9b54196535b5e2638637592b..34fe3338534034ca203c5293dd3771fb0dc8ef32 100644 (file)
@@ -80,6 +80,10 @@ class environment extends plugin
   var $OrigCn;
   var $add_del_printer_member_was_called = false;
 
+  var $multiple_support =TRUE;
+
+  var $use_gotoPrinter;
+
   function environment (&$config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
@@ -458,6 +462,12 @@ class environment extends plugin
         }
       }
     }
+  
+    /* Reset header toggle */
+    if($this->multiple_support_active){
+      $display = "";
+    }
+
     /* Account is Account : is_accounbt=true.
      * Else we won't reach this. 
      */
@@ -488,7 +498,9 @@ class environment extends plugin
       $smarty->assign("gotoPrinterACL","rw");
     }
 
-    if(empty($this->useProfile)){
+
+    $smarty->assign("useProfile",$this->useProfile);
+    if(empty($this->useProfile) && !$this->multiple_support_active){
       $smarty->assign("useProfileCHK","");
       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
@@ -560,6 +572,10 @@ class environment extends plugin
           unset($this->dialog);
           $this->dialog=FALSE;
           $this->is_dialog=false;
+
+          if($this->multiple_support_active){
+            $tmp['UsedByAllUsers'] = TRUE;
+          }
           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
         }
       }
@@ -603,10 +619,15 @@ class environment extends plugin
     }
 
     /* Append List to smarty*/
-    $ls = $this->printOutLogonScripts();
-    $smarty->assign("gotoLogonScripts",  $ls);
-    $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
-    $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
+    if($this->multiple_support_active){
+      $smarty->assign("gotoLogonScripts",  $this->gotoLogonScripts);
+      $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
+    }else{
+      $ls = $this->printOutLogonScripts();
+      $smarty->assign("gotoLogonScripts",  $ls);
+      $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
+      $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
+    }
 
     /* In this section server shares will be defined 
      * A user can select one of the given shares and a mount point
@@ -615,7 +636,6 @@ class environment extends plugin
 
     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
     if(!is_array($this->gotoShareSelections)){
-      print $this->gotoShareSelections;
       $this->gotoShareSelections = array();
     }
     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
@@ -652,6 +672,10 @@ class environment extends plugin
         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
+
+        if($this->multiple_support_active){
+          $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
+        }
       }
     }  
 
@@ -710,6 +734,16 @@ class environment extends plugin
         continue;
       } 
 
+      $color = "";
+      if($this->multiple_support_active){
+        if($this->gotoShares[$key]['UsedByAllUsers']){
+          $value .= "&nbsp;(<b>"._("Used by all users")."</b>)";
+        }else{
+          $color = "color: #999999;";
+          $value .= "&nbsp;(<b>"._("Used by some users")."</b>)";
+        }
+      }
+
       /* Check if entry starts with an ! */
       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
 
@@ -721,7 +755,7 @@ class environment extends plugin
           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
             title='"._("Reset password hash")."'>";
         }
-        $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
+        $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
       }else{
 
@@ -733,7 +767,7 @@ class environment extends plugin
         }
         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
           title='"._("Delete share entry")."'>";
-        $field1 = array("string" => $value);
+        $field1 = array("string" => $value , "attach" => "style='".$color."'");
         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
       }
       $divlistShares->AddEntry(array($field1,$field2));
@@ -787,6 +821,9 @@ class environment extends plugin
 
         if(is_array($a_tmp)){
           foreach($a_tmp as $name => $hotplug){
+            if($this->multiple_support_active){
+              $hotplug['UsedByAllUsers'] = TRUE;
+            }
             $this->gotoHotplugDevices[$name]= $hotplug; 
           }
         }
@@ -795,8 +832,13 @@ class environment extends plugin
         $this->is_dialog = false;
       }
     }
-    $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
-    $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
+
+    if($this->multiple_support_active){
+      $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
+    }else{
+      $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
+      $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
+    }
 
     /* Printer Assignment will managed below 
      * A printer can be assigned in two different ways and two different types
@@ -844,7 +886,9 @@ class environment extends plugin
               $type = "AddGroup";
             }
           }else{
-            if(isset($this->NewDeletedPrinters[$pname])){
+            if($this->multiple_support_active){
+              $type = "AddUser";
+            }elseif(isset($this->NewDeletedPrinters[$pname])){
               $type = "AddUser";
             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
               $type = "AddUser";
@@ -936,7 +980,19 @@ class environment extends plugin
       return($disp);
     }
 
+    /* Assign used attributes for multiple edit */
+    foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
+                  "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
+      $ubox ="use_".$box;
+      if(in_array($box,$this->multi_boxes)){
+        $smarty->assign($ubox,TRUE);
+      }else{
+        $smarty->assign($ubox,FALSE);
+      }
+    }
+
     /* Als smarty vars are set. Get smarty template and generate output */
+    $smarty->assign("multiple_support",$this->multiple_support_active);
     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
     return($display);
   }
@@ -1329,6 +1385,346 @@ class environment extends plugin
   }
 
 
+  function multiple_execute()
+  {
+    /* Reset header toggle */
+    $this->is_account = TRUE;
+    return($this->execute());
+  }
+
+
+    /* Initialize plugin with given atribute arrays
+   */
+  function init_multiple_support($attrs,$all)
+  {
+    plugin::init_multiple_support($attrs,$all);
+
+    /* Prepare Shares */
+    if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
+      unset($this->multi_attrs_all['gotoShare']['count']);
+      foreach($this->multi_attrs_all['gotoShare'] as $share){
+        $tmp = $tmp2 = array();
+        $tmp = split("\|",$share);
+        $tmp2['server']      =$tmp[0];
+        $tmp2['name']        =$tmp[1];
+
+        /* Decode base64 if needed */
+        if (!preg_match('%/%', $tmp[2])){
+          $tmp2['mountPoint']  =base64_decode($tmp[2]);
+        } else {
+          $tmp2['mountPoint']  =$tmp[2];
+        }
+
+        if(isset($tmp[3])){
+          $tmp2['PwdHash']  =$tmp[3];
+        }else{
+          $tmp2['PwdHash']  ="";
+        }
+        if(isset($tmp[4])){
+          $tmp2['Username']  =$tmp[4];
+        }else{
+          $tmp2['Username']  ="";
+        }
+        $tmp2['UsedByAllUsers'] = FALSE;
+        $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
+      }
+    }
+
+    /* Prepare Shares */
+    if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
+      unset($this->multi_attrs['gotoShare']['count']);
+      foreach($this->multi_attrs['gotoShare'] as $share){
+        $tmp = $tmp2 = array();
+        $tmp = split("\|",$share);
+        $tmp2['server']      =$tmp[0];
+        $tmp2['name']        =$tmp[1];
+
+        /* Decode base64 if needed */
+        if (!preg_match('%/%', $tmp[2])){
+          $tmp2['mountPoint']  =base64_decode($tmp[2]);
+        } else {
+          $tmp2['mountPoint']  =$tmp[2];
+        }
+
+        if(isset($tmp[3])){
+          $tmp2['PwdHash']  =$tmp[3];
+        }else{
+          $tmp2['PwdHash']  ="";
+        }
+        if(isset($tmp[4])){
+          $tmp2['Username']  =$tmp[4];
+        }else{
+          $tmp2['Username']  ="";
+        }
+        $tmp2['UsedByAllUsers'] = TRUE;
+        $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
+      }
+    }
+
+
+    /* prepare LogonScripts */
+    if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
+      unset($this->multi_attrs_all['gotoLogonScript']['count']);
+      foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
+        $tmp = $tmp2 = array();
+        $tmp = split("\|",$device);
+        $tmp2['LogonName']        = $tmp[0];
+        $tmp2['LogonPriority']    = $tmp[2];
+        if(preg_match("/O/i",$tmp[1])){
+          $tmp2['LogonOverload'] = "O";
+        }else{
+          $tmp2['LogonOverload'] = "";
+        }
+        if(preg_match("/L/i",$tmp[1])){
+          $tmp2['LogonLast'] = "L";
+        }else{
+          $tmp2['LogonLast'] = "";
+        }
+        $tmp2['LogonData']        = base64_decode($tmp[3]);
+        $tmp2['LogonDescription'] = $tmp[4];
+        $tmp2['UsedByAllUsers'] = FALSE;
+        $this->gotoLogonScripts[$tmp[0]]=$tmp2;
+      }
+    }
+
+    /* prepare LogonScripts */
+    if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
+      unset($this->multi_attrs['gotoLogonScript']['count']);
+      foreach($this->multi_attrs['gotoLogonScript'] as $device){
+        $tmp = $tmp2 = array();
+        $tmp = split("\|",$device);
+        $tmp2['LogonName']        = $tmp[0];
+        $tmp2['LogonPriority']    = $tmp[2];
+        if(preg_match("/O/i",$tmp[1])){
+          $tmp2['LogonOverload'] = "O";
+        }else{
+          $tmp2['LogonOverload'] = "";
+        }
+        if(preg_match("/L/i",$tmp[1])){
+          $tmp2['LogonLast'] = "L";
+        }else{
+          $tmp2['LogonLast'] = "";
+        }
+        $tmp2['LogonData']        = base64_decode($tmp[3]);
+        $tmp2['LogonDescription'] = $tmp[4];
+        $tmp2['UsedByAllUsers'] = TRUE;
+        $this->gotoLogonScripts[$tmp[0]]=$tmp2;
+      }
+    }
+
+    /* Prepare hotplugs */
+    if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
+        $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
+        if($ldap->count()){
+          $multi_attrs_all = $ldap->fetch();
+
+          if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
+            $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
+            $tmp2     = array();
+            $tmp2['name']         = $multi_attrs_all['cn'][0];
+            $tmp2['description']  = $tmp[0];
+            $tmp2['id']           = $tmp[1];
+            $tmp2['produkt']      = $tmp[2];
+            $tmp2['vendor']       = $tmp[3];
+            $tmp2['dn']           = $multi_attrs_all['dn'];
+            $tmp2['UsedByAllUsers'] = FALSE;
+            $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
+          }
+        }
+      }
+    }
+
+    /* Prepare hotplugs */
+    if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
+        $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
+        if($ldap->count()){
+          $multi_attrs = $ldap->fetch();
+
+          if(isset($multi_attrs['gotoHotplugDevice'][0])){
+            $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
+            $tmp2     = array();
+            $tmp2['name']         = $multi_attrs['cn'][0];
+            $tmp2['description']  = $tmp[0];
+            $tmp2['id']           = $tmp[1];
+            $tmp2['produkt']      = $tmp[2];
+            $tmp2['vendor']       = $tmp[3];
+            $tmp2['dn']           = $multi_attrs['dn'];
+            $tmp2['UsedByAllUsers'] = TRUE;
+            $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
+          }
+        }
+      }
+    }
+   $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
+    $this->gotoHotplugDevices = array_values($tmp);
+    for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
+      $chr = $this->gotoProfileFlags[$i];
+      $name = "gotoProfileFlag".$chr;
+      $this->$name=$chr;
+    }
+$this->update_kiosk_profiles();
+$this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
+
+    if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
+      $this->useProfile = true;
+    }else{
+      $this->useProfile = false;
+    }
+
+  }
+
+
+  function set_multi_edit_values($attrs)
+  {
+    $shares = $this->gotoShares;
+    $scripts= $this->gotoLogonScripts;
+    $plugs= $this->gotoHotplugDevices;
+    plugin::set_multi_edit_values($attrs);
+
+    $this->gotoShares = $shares;
+    $this->gotoLogonScripts = $scripts;
+    $this->gotoHotplugDevices = $plugs;
+
+    foreach($attrs['gotoShares'] as $name => $share){
+      if($share['UsedByAllUsers'] == TRUE){
+        $this->gotoShares[$name] = $share;
+      }
+    }
+    foreach($this->gotoShares as $name => $share){
+      if(!isset($attrs['gotoShares'][$name])){
+        unset($this->gotoShares[$name]);
+      }
+    }
+    foreach($attrs['gotoLogonScripts'] as $name => $script){
+      if($script['UsedByAllUsers'] == TRUE){
+        $this->gotoLogonScripts[$name] = $script;
+      }
+    }
+    foreach($this->gotoLogonScripts as $name => $script){
+      if(!isset($attrs['gotoLogonScripts'][$name])){
+        unset($this->gotoLogonScripts[$name]);
+      }
+    }
+    $tmp = array();
+    foreach($this->gotoHotplugDevices as $entry){
+      $tmp[$entry['dn']] = $entry;
+    }
+  
+    foreach($attrs['gotoHotplugDevices'] as $name => $plug){
+      if($plug['UsedByAllUsers'] == TRUE){
+        $tmp[$plug['dn']] = $plug;
+      }
+    }
+    foreach($tmp as $name => $plug){
+      $found = false;
+      foreach($attrs['gotoHotplugDevices'] as $test){
+        if($test['dn'] == $name){
+          $found = true;
+        }
+      }
+      if(!$found){
+        unset($tmp[$name]);
+      }
+    }
+  }
+
+
+    /* Return selected values for multiple edit */
+  function get_multi_edit_values()
+  {
+    $ret = plugin::get_multi_edit_values();
+    $ret['gotoShares'] = $this->gotoShares;
+    $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
+    $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
+  
+    if(in_array("gotoPrinter",$this->multi_boxes)){
+      $ret['gotoPrinter'] = $this->gotoPrinter;
+      $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
+      $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
+  
+      /* Force printer reset */
+      $ret['add_del_printer_member_was_called'] = TRUE;
+    }
+  
+    if(in_array("gotoProfileFlagL",$this->multi_boxes)){
+      $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
+    }
+
+    if(in_array("useProfile",$this->multi_boxes)){
+      $ret['useProfile']=$this->useProfile;
+      if(in_array("gotoProfileServer",$this->multi_boxes)){
+        $ret['gotoProfileServer']=$this->gotoProfileServer;
+      }
+      if(in_array("gotoProfileQuota",$this->multi_boxes)){
+        $ret['gotoProfileQuota']=$this->gotoProfileQuota;
+      }
+      if(in_array("gotoProfileFlagC",$this->multi_boxes)){
+        $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
+      }
+    }
+    if(in_array("gotoXResolution",$this->multi_boxes)){
+      $ret['gotoXResolution'] = $this->gotoXResolution;
+    }
+    if(in_array("kiosk_server",$this->multi_boxes)){
+      $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
+      $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
+    }
+    return($ret);
+  }
+
+
+  function multiple_save_object()
+  {
+    if(isset($_POST['environment_multiple_posted'])){
+      plugin::multiple_save_object();
+
+      
+      if(isset($_POST['useProfile'])){
+        $this->useProfile = true;
+      }else{
+        $this->useProfile = false;
+      }
+      if(isset($_POST['gotoProfileFlagC'])){
+        $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
+      }else{
+        $this->gotoProfileFlagC = false;
+      }
+
+      if(isset($_POST['gotoProfileFlagL'])){
+        $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
+      }else{
+        $this->gotoProfileFlagL = false;
+      }
+
+      foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
+                    "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
+        $uattr = "use_".$attr;
+        if(isset($_POST[$uattr])){
+          $this->multi_boxes[] = $attr;
+        }
+      }
+      if(isset($_POST['kiosk_server'])){
+        $tmp = $_POST['kiosk_server'];
+        if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
+          $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
+        }
+      }
+      if(isset($_POST['kiosk_profile'])){
+        $tmp = $_POST['kiosk_profile'];
+        if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
+          $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
+        }
+      }
+
+    }
+  }
+
   /* Return plugin informations for acl handling 
 #FIXME these ACLs should work for groups too */ 
   static function plInfo()