Code

Updated New Device && opsi host
[gosa.git] / gosa-plugins / systems / admin / systems / class_systemManagement.inc
index f2c37eecf1fb58dad694940c67fa852bea23cce4..e6423173c36b632761505afbc960f606f857ac91 100644 (file)
@@ -221,7 +221,7 @@ class systems extends plugin
      ********************/
     if ($s_action=="gen_cd"){
       $this->dn= $this->terminals[$s_entry]['dn'];
-      session::set('objectinfo',$this->dn);
+      set_object_info($this->dn);
       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
     }
 
@@ -370,6 +370,19 @@ class systems extends plugin
                */
               $this->systab->was_activated = TRUE;
 
+              /* Assign some default values for opsi hosts 
+               */
+              if($this->systab instanceOf opsi_tabs){
+                $ldap = $this->config->get_ldap_link();
+                $ldap->cat($dn);
+                $source_attrs = $ldap->fetch();
+                foreach(array("macAddress" => "mac" ,"cn" => "hostId","description","description") as $src => $attr){
+                  if(isset($source_attrs[$src][0])){
+                    $this->systab->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
+                  }
+                }
+              }
+
               if($selected_group != "none"){
 
                 /*******
@@ -525,7 +538,7 @@ class systems extends plugin
       /* Check locking, save current plugin in 'back_plugin', so
          the dialog knows where to return. */
       if (($user= get_lock($this->dn)) != ""){
-        return(gen_locked_message ($user, $this->dn));
+        return(gen_locked_message ($user, $this->dn,TRUE));
       }
 
       /* Find out more about the object type */
@@ -540,12 +553,14 @@ class systems extends plugin
         if(!class_available("ArpNewDeviceTabs")){
           msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
         }else{
+          add_lock ($this->dn, $this->ui->dn);
           $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
         }
       }elseif($type == "NewDevice"){
         if(!class_available("SelectDeviceType")){
           msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
         }else{
+          add_lock ($this->dn, $this->ui->dn);
           $this->system_activation_object= array($this->dn);
           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
 
@@ -560,10 +575,10 @@ class systems extends plugin
         if(!class_available($tabclass)){
           msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
         }else{
+          add_lock ($this->dn, $this->ui->dn);
           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
           $this->systab->set_acl_base($this->dn);
-          session::set('objectinfo',$this->dn);
-          add_lock ($this->dn, $this->ui->dn);
+          set_object_info($this->dn);
         }
       }else{ 
         msg_dialog::display(_("Error"), _("Editing this type of object is not supported yet!"), ERROR_DIALOG);
@@ -590,7 +605,7 @@ class systems extends plugin
       $tabacl   = $ui->get_permissions($dn,$acl,"userPassword");
       if(preg_match("/w/",$tabacl)){
         $this->dn= $this->terminals[$s_entry]['dn'];
-        session::set('objectinfo',$this->dn);
+        set_object_info($this->dn);
         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
       }else{
         msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
@@ -701,7 +716,7 @@ class systems extends plugin
       }else{
         msg_dialog::display(_("Error"), _("Cannot determine object to change password!"), ERROR_DIALOG);
       }
-      session::un_set('objectinfo');
+      set_object_info();
     }
 
 
@@ -712,7 +727,7 @@ class systems extends plugin
     /* Delete terminal canceled? */
     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
       $this->remove_lock();
-      session::un_set('objectinfo');
+      set_object_info();
     }
 
 
@@ -863,7 +878,7 @@ class systems extends plugin
           $dns_names = array();
           foreach($this->dns as $dn){
             add_lock ($dn, $this->ui->dn);
-            $dns_names[] = @LDAP::fix($dn);
+            $dns_names[] = LDAP::fix($dn);
           }
 
           /* Lock the current entry, so nobody will edit it during deletion */
@@ -987,8 +1002,15 @@ class systems extends plugin
         $this->systab->save();
 
         /* Post handling for activated systems 
+            target opsi -> Remove source.
+            target gosa -> Activate system.
          */
-        if(isset($this->systab->was_activated) && $this->systab->was_activated){
+        if($this->systab instanceOf opsi_tabs && $this->systab->was_activated){
+          $ldap = $this->config->get_ldap_link();
+          $ldap->cd($this->config->current['BASE']);
+          $ldap->rmdir ($this->systab->dn);
+          @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,"Source removed: ".$this->systab->dn,"Opsi host activated.");
+        }elseif(isset($this->systab->was_activated) && $this->systab->was_activated){
           $this->activate_new_device($this->systab->dn);
         }
 
@@ -1000,7 +1022,7 @@ class systems extends plugin
 
           unset ($this->systab);
           $this->systab= NULL;
-          session::un_set('objectinfo');
+          set_object_info();
         }else{
       
           /* Reinitialize tab */
@@ -1026,7 +1048,7 @@ class systems extends plugin
         unset ($this->systab);
       }
       $this->systab= NULL;
-      session::un_set('objectinfo');
+      set_object_info();
     }
 
     /********************
@@ -1035,13 +1057,18 @@ class systems extends plugin
 
     /* Show tab dialog if object is present */
     if (isset($this->systab->config)){
+
+      if($this->systab instanceOf plugin && !($this->systab instanceOf tabs)){
+        $this->systab->save_object();
+      }
+
       $display= $this->systab->execute();
 
       /* Don't show buttons if tab dialog requests this */
 
       $dialog     = FALSE;
       $hide_apply = $this->dn == "new";
-      $hide_apply = ($this->dn == "new") || (preg_match("/".normalizePreg(get_ou("systemIncomingRDN"))."/",$this->dn));
+      $hide_apply = ($this->dn == "new") || (preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->dn));
       if(is_object($this->systab) && !isset($this->systab->by_object)){
         $dialog = TRUE;
         $hide_apply = TRUE;
@@ -1056,7 +1083,11 @@ class systems extends plugin
         $dialog = TRUE;
       }
 
-      if (!$dialog){
+      if(($this->systab instanceOf tabs || $this->systab instanceOf plugin) && $this->systab->read_only == TRUE){
+        $display.= "<p style=\"text-align:right\">
+          <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
+          </p>";
+      }elseif (!$dialog){
         $display.= "<p style=\"text-align:right\">\n";
         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
         $display.= "&nbsp;\n";
@@ -1261,7 +1292,7 @@ class systems extends plugin
       }
 
       /* Create a string containing the last part of the department. */
-      $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
+      $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(LDAP::fix($tmp)));
       if(empty($dn_name)){
         $dn_name = "/";
       }
@@ -1427,8 +1458,7 @@ class systems extends plugin
   {
     if (isset($this->systab->dn)){
       del_lock ($this->systab->dn);
-    }
-    if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+    }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
       del_lock($this->dn);
     }
     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
@@ -1565,7 +1595,7 @@ class systems extends plugin
         "C" => array("plugins/systems/images/select_component.png",_("Network device")),
         "P" => array("plugins/systems/images/select_printer.png",_("Printer")),
 
-        "W" => array("plugins/systems/images/select_winstation.png",_("Win workstation")),
+        "W" => array("plugins/systems/images/select_winstation.png",_("Windows workstation")),
 
         "L" => array("plugins/systems/images/select_workstation.png",_("Workstation")),
         "S" => array("plugins/systems/images/select_server.png",_("Server")),