Code

Corrected path
[gosa.git] / gosa-core / plugins / personal / environment / class_environment.inc
index 25de2cb6d07c2c8f585989c147c199e71c12db16..fe0be1d0189676b5814ecc3a5a10bf11e00b7fde 100644 (file)
@@ -82,6 +82,8 @@ class environment extends plugin
 
   var $multiple_support =TRUE;
 
+  var $use_gotoPrinter;
+
   function environment (&$config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
@@ -137,7 +139,7 @@ class environment extends plugin
             $this->gotoHotplugDevices[] = $tmp2; 
           }
         }else{
-          print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
+          msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
         }
       }
     }
@@ -232,7 +234,7 @@ class environment extends plugin
         }
         //natcasesort($this->gotoXResolutions);
       }else{
-        print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
+        msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
       }
     }
 
@@ -283,8 +285,9 @@ class environment extends plugin
       $error = true;
     }
     if($error && !empty($this->gotoKioskProfile)){
-      print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
-            $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
+      $this->gotoKioskProfile_Server ="none";
+      $this->gotoKioskProfile_Profile="";
+      msg_dialog::display(_("Warning"), sprintf(_("Kiosk profile '%s' located on server '%s' is not available anymore. Kiosk profile will be disabled!"), $this->gotoKioskProfile_Profile, $this->gotoKioskProfile_Server), WARNING_DIALOG);
     }
   }
 
@@ -318,7 +321,7 @@ class environment extends plugin
     }
 
     /* Are we editing from MyAccount and not editing a user */
-    $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
+    $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
 
     /* Check profile server */
     if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
@@ -329,14 +332,12 @@ class environment extends plugin
           $new = key($this->gotoProfileServers);
 
           /* Another profile server found */
-          print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
-                $this->gotoProfileServer,$new));
+          msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
         }else{
 
           /* No other profile servers found */
-          print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
-                $this->gotoProfileServer));
-          $this->gotoProfileServer = "";
+          msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
+          $this->gotoProfileServer = "none";
         }
       }
     }    
@@ -496,7 +497,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)));
@@ -553,7 +556,7 @@ class environment extends plugin
     if(isset($_POST['LogonSave'])){
 
       if(!$this->acl_is_writeable("gotoLogonScript")){
-        print_red(_("You are not allowed to write Logon scripts."));
+        msg_dialog::display(_("Permission error"), _("You have no permission to modify logon scripts!"), ERROR_DIALOG);
         unset($this->dialog);
         $this->dialog=FALSE;
         $this->is_dialog=false;
@@ -561,13 +564,17 @@ class environment extends plugin
         $this->dialog->save_object();
         if(count($this->dialog->check())!=0){
           foreach($this->dialog->check() as $msg){
-            print_red($msg);
+            msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
           }
         }else{
           $tmp = $this->dialog->save();
           unset($this->dialog);
           $this->dialog=FALSE;
           $this->is_dialog=false;
+
+          if($this->multiple_support_active){
+            $tmp['UsedByAllUsers'] = TRUE;
+          }
           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
         }
       }
@@ -611,10 +618,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
@@ -634,11 +646,11 @@ class environment extends plugin
 
       /* We assign a share to this user, if we don't know where to mount the share */
       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
-        print_red(_("You must select a valid share."));
+        msg_dialog::display(_("Error"), _("Please select a valid share!"), ERROR_DIALOG);
       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
-        print_red(_("You must specify a valid mount point."));
+        msg_dialog::display(_("Error"), _("Please specify a valid mount point!"), ERROR_DIALOG);
       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
-        print_red(_("Spaces are not allowed in the mount path!"));
+        msg_dialog::display(_("Error"), _("You cannot use spaces in the mount path!"), ERROR_DIALOG);
       }elseif(!(
             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
@@ -649,7 +661,7 @@ class environment extends plugin
             preg_match("/^%/",$_POST['gotoShareMountPoint'])
             )
           ){
-        print_red(_("You must specify a valid mount point.")); 
+        msg_dialog::display(_("Error"), _("Please specify a valid mount point!"), ERROR_DIALOG);
       }else{
         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
         $s_mount = $_POST['gotoShareMountPoint'];
@@ -800,7 +812,7 @@ class environment extends plugin
       $this->dialog->save_object();
       if(count($this->dialog->check())!=0){
         foreach($this->dialog->check() as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $this->dialog->save_object();
@@ -808,6 +820,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; 
           }
         }
@@ -816,8 +831,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
@@ -843,7 +863,7 @@ class environment extends plugin
       if(count($this->dialog->check())!=0){
         $tmp = $this->dialog->check();
         foreach($tmp as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         } 
       }else{
         $this->dialog->save_object();
@@ -865,7 +885,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";
@@ -937,7 +959,7 @@ class environment extends plugin
 
     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
       if($this->is_group){
-        print_red(_("GOsa default printer flag is not allowed within groups."));
+        msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
       }else{
         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
           $this->gosaDefaultPrinter= "";
@@ -957,6 +979,17 @@ 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__)));
@@ -1009,7 +1042,7 @@ class environment extends plugin
     /* Get all Posted vars 
      * Setup checkboxes 
      */
-    $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
+    $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
     if(isset($_POST['iamposted'])){
 
       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
@@ -1426,15 +1459,136 @@ class environment extends plugin
         $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);
+    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;
@@ -1445,6 +1599,37 @@ class environment extends plugin
         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]);
+      }
+    }
   }
 
 
@@ -1453,10 +1638,102 @@ class environment extends plugin
   {
     $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_check() 
+  {
+    $message = plugin::multiple_check();
+    $this->detect_grouptype();
+
+    if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
+      $message[]=_("Please set a valid profile quota size.");
+    }
+    return($message);
+  }
+
+
+  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()