Code

Replaced a couple of normalizePreg
[gosa.git] / gosa-core / plugins / admin / ogroups / class_ogroupManagement.inc
index f9fac4e4ff5c50ee3ddb4f4f238a80c0ee133a3c..978bc0c87f4f8284b4ff00386eb5dce4f18a3fc4 100644 (file)
@@ -36,6 +36,9 @@ class ogroupManagement extends plugin
   var $DivListOGroup    = NULL;
   var $start_pasting_copied_objects = FALSE;
 
+  var $dns = array();
+  var $acl_module   = array("ogroups");  
+
   function ogroupManagement (&$config, $dn= NULL)
   {
     /* Include config object */
@@ -44,7 +47,7 @@ class ogroupManagement extends plugin
 
     /* Copy & Paste enabled ?
      */
-    if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE'] ))){
+    if ($this->config->get_cfg_value("copyPaste") == "true"){
       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
     }
 
@@ -61,7 +64,7 @@ class ogroupManagement extends plugin
       Variable intialisation && Check posts for commands  
      ****************/
 
-    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/","/^item_selected/","/^remove_multiple_ogroups/"));
+    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/","/^item_selected/","/^remove_multiple_ogroups/","/^menu_action/"));
 
     $smarty     = get_smarty();
     $s_action   = "";
@@ -133,26 +136,31 @@ class ogroupManagement extends plugin
     }
 
     /* Hanlde notification event requests */
-    if(isset($_POST['menu_action']) && preg_match("/^trigger_event_DaemonEvent_notify/",$_POST['menu_action'])){
-      $s_action = "notify";
+    if(isset($_POST['menu_action']) && preg_match("/^event/",$_POST['menu_action'])){
+      $s_action = $_POST['menu_action'];
     }
 
+
     /********************
       Create notification event
      ********************/
 
-    if($s_action == "notify"){
-
+    if(preg_match("/^event_/",$s_action) && class_available("DaemonEvent")){
       $ids = $this->list_get_selected_items();
       $uids = array();
       foreach($ids as $id){
         $uids[] = $this->ogrouplist[$id]['cn'][0];
       }
       if(count($uids)){
-        $this->ogroup= new DaemonEvent_notify($this->config);
-        $this->ogroup->add_targets($uids);
+        $events = DaemonEvent::get_event_types(USER_EVENT);
+        $event = preg_replace("/^event_/","",$s_action);
+        if(isset($events['BY_CLASS'][$event])){
+          $type = $events['BY_CLASS'][$event];
+          $this->ogroup = new $type['CLASS_NAME']($this->config);
+          $this->ogroup->add_targets($uids);
+          $this->ogroup->set_type(TRIGGERED_EVENT);
+        }
       }
-
     }
 
     /* Abort event dialog */
@@ -165,8 +173,7 @@ class ogroupManagement extends plugin
       $o_queue = new gosaSupportDaemon();
       $o_queue->append($this->ogroup);
       if($o_queue->is_error()){
-        msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
-              $o_queue->get_error()),ERROR_DIALOG);
+        msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
       }else{
         $this->ogroup = FALSE;
       }
@@ -212,28 +219,43 @@ class ogroupManagement extends plugin
      ********************/
     if ($s_action=="del_multiple"){
       $ids = $this->list_get_selected_items();
+
       if(count($ids)){
+        $this->dns = array();
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->ogrouplist[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
+          $acl = $this->ui->get_permissions($dn, "users/user");
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
           }
-          $this->dns[$id] = $dn;
         }
-        $dns_names = "<br><pre>";
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names .= $dn."\n";
+
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
-        $dns_names .="</pre>";
-        /* Lock the current entry, so nobody will edit it during deletion */
-        if (count($this->dns) == 1){
-          $smarty->assign("info",     sprintf(_("You're about to delete the following object entry %s"), @LDAP::fix($dns_names)));
-        } else {
-          $smarty->assign("info",     sprintf(_("You're about to delete the following object entries %s"), @LDAP::fix($dns_names)));
+
+        if(count($this->dns)){
+
+          /* Check locks */
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
+
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            $dns_names[] = @LDAP::fix($dn);
+          }
+
+          add_lock ($this->dns, $this->ui->dn);
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("info", msgPool::deleteInfo($dns_names,_("object group")));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
         }
-        $smarty->assign("multiple", true);
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       }
     }
 
@@ -260,13 +282,14 @@ class ogroupManagement extends plugin
 
           /* Normally this shouldn't be reached, send some extra
              logs to notify the administrator */
-          msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), INFO_DIALOG);
+          msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
           new log("security","ogroups/".get_class($this),$dn,array(),"Tried to trick deletion.");
         }
-        /* Remove lock file after successfull deletion */
-        del_lock ($dn);
-        unset($this->dns[$key]);
       }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -276,10 +299,10 @@ class ogroupManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_ogroup_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -305,14 +328,14 @@ class ogroupManagement extends plugin
 
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->dn),_("object group")));
         $smarty->assign("multiple", false);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
         /* Obviously the user isn't allowed to delete. Show message and
            clean session. */
-        msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), INFO_DIALOG);
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
       }
     }
 
@@ -339,12 +362,12 @@ class ogroupManagement extends plugin
 
         /* Normally this shouldn't be reached, send some extra
            logs to notify the administrator */
-        msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), INFO_DIALOG);
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
         new log("security","ogroups/".get_class($this),$dn,array(),"Tried to trick deletion.");
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -355,7 +378,7 @@ class ogroupManagement extends plugin
 
     /* Delete group canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -406,17 +429,23 @@ class ogroupManagement extends plugin
           /* Group has been saved successfully, remove lock from
              LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
 
           unset ($this->ogroup);
           $this->ogroup= NULL;
           session::un_set('objectinfo');
+        }else{
+
+          /* Reinitialize tab */
+          if($this->ogroup instanceof tabs){
+            $this->ogroup->re_init();
+          }
         }
       } else {
         /* Ok. There seem to be errors regarding to the tab data,
            show message and continue as usual. */
-        show_errors($message);
+        msg_dialog::displayChecks($message);
       }
     }
 
@@ -427,8 +456,7 @@ class ogroupManagement extends plugin
 
     /* Cancel dialogs */
     if ((isset($_POST['edit_cancel']))  && (isset($this->ogroup->dn))){
-      del_lock ($this->ogroup->dn);
-      unset ($this->ogroup);
+      $this->remove_lock();
       $this->ogroup= NULL;
       session::un_set('objectinfo');
     }
@@ -445,13 +473,13 @@ class ogroupManagement extends plugin
       /* Don't show buttons if tab dialog requests this */
       if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
         $display.= "<p style=\"text-align:right\">\n";
-        $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
+        $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
         $display.= "&nbsp;\n";
         if ($this->dn != "new"){
-          $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
+          $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
           $display.= "&nbsp;\n";
         }
-        $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
+        $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
         $display.= "</p>";
       }
       return ($display);
@@ -464,7 +492,7 @@ class ogroupManagement extends plugin
 
     /* Check if there is a snapshot dialog open */
     $base = $this->DivListOGroup->selectedBase;
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
       return($str);
     }
 
@@ -485,7 +513,7 @@ class ogroupManagement extends plugin
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
-    return(array(get_ou('ogroupou').$this->DivListOGroup->selectedBase));
+    return(array(get_ou('ogroupRDN').$this->DivListOGroup->selectedBase));
   }
 
   
@@ -495,16 +523,16 @@ class ogroupManagement extends plugin
     $temp= "";
 
     $conv= array(   
-        "U" => array("select_user.png"        ,_("User")        , "ogroup"),
-        "G" => array("select_groups.png"      ,_("Group")       , "ogroup"),
-        "A" => array("select_application.png" ,_("Application") , "ogroup"),
-        "D" => array("select_department.png"  ,_("Department")  , "ogroup"),
-        "S" => array("select_server.png"      ,_("Server")      , "ogroup"),
-        "F" => array("select_phone.png"       ,_("Phone")       , "phonequeue"),
-        "W" => array("select_workstation.png" ,_("Workstation") , "workstartup"),
-        "O" => array("select_winstation.png" ,_("Windows Install") , "ogroup"),
-        "T" => array("select_terminal.png"    ,_("Terminal")    , "termgroup"),
-        "P" => array("select_printer.png"     ,_("Printer")     , "ogroup"));
+        "U" => array("plugins/generic/images/head.png"        ,_("User")        , "ogroup"),
+        "G" => array("plugins/groups/images/groups.png"       ,_("Group")       , "ogroup"),
+        "A" => array("plugins/ogroups/images/application.png" ,_("Application") , "ogroup"),
+        "D" => array("plugins/departments/department.png"     ,_("Department")  , "ogroup"),
+        "S" => array("plugins/ogroups/images/server.png"      ,_("Server")      , "ogroup"),
+        "F" => array("plugins/ogroups/images/asterisk.png"    ,_("Phone")       , "phonequeue"),
+        "W" => array("plugins/ogroups/images/workstation.png" ,_("Workstation") , "workstartup"),
+        "O" => array("plugins/ogroups/images/winstation.png"  ,_("Windows Install") , "ogroup"),
+        "T" => array("plugins/ogroups/images/terminal.png"    ,_("Terminal")    , "termgroup"),
+        "P" => array("plugins/ogroups/images/printer.png"     ,_("Printer")     , "ogroup"));
 
     /* Assemble picture */
     $type= $input['gosaGroupObjects'][0];
@@ -516,7 +544,7 @@ class ogroupManagement extends plugin
       $p1['lnk']= $conv[$type[0]][2];
       $html_object_1 = "<input type='image' name='".$p1['lnk']."_group_edit_%KEY' ";
     } else {
-      $p1['pic']= "empty.png";
+      $p1['pic']= "images/empty.png";
       $p1['tit']= "";
       $p1['alt']= "";
       $p1['lnk']= "";//$conv[$type[0]][2];
@@ -530,7 +558,7 @@ class ogroupManagement extends plugin
       $p2['lnk']= $conv[$type[1]][2];
       $html_object_2 = "<input type='image' name='".$p2['lnk']."_group_edit_%KEY' ";
     } else {
-      $p2['pic']= "empty.png";
+      $p2['pic']= "images/empty.png";
       $p2['alt']= "";
       $p2['tit']= "";
       $p2['lnk']= ""; //$conv[$type[0]][2];
@@ -538,9 +566,9 @@ class ogroupManagement extends plugin
     }
     
     $temp = $html_object_1." class='center' id='iconA".preg_replace("/_/","",$p1['lnk']."_group_edit_%KEY")."' 
-      src='images/".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
+      src='".$p1['pic']."' alt='".$p1['alt']."' title='".$p1['tit']."'>";
     $temp.= $html_object_2." class='center' id='iconB".preg_replace("/_/","",$p2['lnk']."_group_edit_%KEY")."' 
-      src='images/".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
+      src='".$p2['pic']."' alt='".$p2['alt']."' title='".$p2['tit']."'>";
     return ($temp);
   }
 
@@ -573,9 +601,9 @@ class ogroupManagement extends plugin
     $filter= "(&(cn=$Regex)(objectClass=gosaGroupOfNames)(|$filter))";
 
     if($this->DivListOGroup->SubSearch){
-      $res= get_sub_list($filter, "ogroups",get_ou('ogroupou'), $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
+      $res= get_sub_list($filter, "ogroups",get_ou('ogroupRDN'), $base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
     }else{
-      $res= get_sub_list($filter, "ogroups",get_ou('ogroupou'), get_ou('ogroupou').$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
+      $res= get_sub_list($filter, "ogroups",get_ou('ogroupRDN'), get_ou('ogroupRDN').$base, array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT );
     }
 
     $this->ogrouplist= $res;
@@ -616,13 +644,20 @@ class ogroupManagement extends plugin
       return("");
     }
 
+    $ui = get_userinfo();
+
     /* Add a single entry to queue */
     if($s_action == "cut" || $s_action == "copy"){
 
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
       $dn = $this->ogrouplist[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"ogrouptabs","OGROUPTABS","ogroups");
+      if($s_action == "copy" && $ui->is_copyable($dn,"ogroups","ogroup")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"ogrouptabs","OGROUPTABS","ogroups");
+      }
+      if($s_action == "cut" && $ui->is_cutable($dn,"ogroups","ogroup")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"ogrouptabs","OGROUPTABS","ogroups");
+      }
     }
 
 
@@ -636,10 +671,10 @@ class ogroupManagement extends plugin
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->ogrouplist[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && $ui->is_copyable($dn,"ogroups","ogroup")){ 
           $this->CopyPasteHandler->add_to_queue($dn,"copy","ogrouptabs","OGROUPTABS","ogroups");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && $ui->is_cutable($dn,"ogroups","ogroup")){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","ogrouptabs","OGROUPTABS","ogroups");
         }
       }
@@ -654,8 +689,8 @@ class ogroupManagement extends plugin
     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
 
       /* Get dialog */
-      $data = $this->CopyPasteHandler->execute();
       $this->CopyPasteHandler->SetVar("base",$this->DivListOGroup->selectedBase);
+      $data = $this->CopyPasteHandler->execute();
 
       /* Return dialog data */
       if(!empty($data)){
@@ -670,11 +705,29 @@ class ogroupManagement extends plugin
   }
 
 
+  function remove_lock()
+  {
+    if (isset($this->apptabs->dn)){
+      del_lock ($this->apptabs->dn);
+    }
+    if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+      del_lock($this->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock($this->dns);
+    }
+  }
+
+
   function save_object()
   {
     $this->DivListOGroup->save_object();
+    if(is_object($this->CopyPasteHandler)){
+      $this->CopyPasteHandler->save_object();
+    }
   }
 
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: