Code

Added
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 10 Mar 2006 07:31:33 +0000 (07:31 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 10 Mar 2006 07:31:33 +0000 (07:31 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2836 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_plugin.inc
plugins/admin/departments/class_departmentGeneric.inc

index be887cf55e9d4ca66520c6f92f0640d14cc17e5d..b34fc5ed0993957d3fbee336e4631902c9f1ede0 100644 (file)
@@ -638,6 +638,14 @@ class plugin
     $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
     $new[$dst_name]= $dst_val;
 
+    /* Check if this is a department.
+     * If it is a dep. && there is a , override in his ou 
+     *  change \2C to , again, else this entry can't be saved ...
+     */
+    if((isset($new['ou'])) &&( preg_match("/\\\\2C/",$new['ou']))){
+      $new['ou'] = preg_replace("/\\\\2C/",",",$new['ou']);
+    }
+
     /* Save copy */
     $ldap->connect();
     $ldap->cd($this->config->current['BASE']);
index e7eb59c681edad82459ec85969c2432145540360..a04e44da1530fa48d54132e5fff150eaabc37600 100644 (file)
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
+ */
 
 class department extends plugin
 {
-  /* department attributes */
-  var $ou= "";
-  var $description= "";
-  var $base= "";
-  var $st= "";
-  var $l= "";
-  var $postalAddress= "";
-  var $businessCategory= "";
-  var $telephoneNumber= "";
-  var $facsimileTelephoneNumber= "";
-  var $orig_dn= "";
+       /* department attributes */
+       var $ou= "";
+       var $description= "";
+       var $base= "";
+       var $st= "";
+       var $l= "";
+       var $postalAddress= "";
+       var $businessCategory= "";
+       var $telephoneNumber= "";
+       var $facsimileTelephoneNumber= "";
+       var $orig_dn= "";
 
        var $rec_dst=false;     // Destination for recursive move
        var $rec_src=false;     // Source for recursive move 
@@ -41,283 +41,292 @@ class department extends plugin
                return $this->rec_cpy;
        }
 
-  /* Headpage attributes */
-  var $last_dep_sorting= "invalid";
-  var $departments= array();
+       /* Headpage attributes */
+       var $last_dep_sorting= "invalid";
+       var $departments= array();
 
-  /* attribute list for save action */
-  var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
+       /* attribute list for save action */
+       var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
                        "telephoneNumber", "facsimileTelephoneNumber");
-  var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
-
-  function department ($config, $dn)
-  {
-
-         plugin::plugin($config, $dn);
-         $this->is_account= TRUE;
-         $this->ui= get_userinfo();
-         $this->dn= $dn;
-         $this->orig_dn= $dn;
-         $this->config= $config;
-
-         /* Set base */
-         if ($this->dn == "new"){
-                 $ui= get_userinfo();
-                 if(isset($_SESSION['depfilter']['depselect'])){
-                         $this->base = $_SESSION['depfilter']['depselect'];
-                 }else{
-                         $this->base= dn2base($ui->dn);
-                 }
-         } else {
-                 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
-         }
-         /* set permissions */
-         $ui= get_userinfo();
-         $acl= get_permissions ($ui->dn, $ui->subtreeACL);
-         $this->acl= get_module_permission($acl, "department", $ui->dn);
-  }
-
-  function execute()
-  {
-         /* Call parent execute */
-         plugin::execute();
-
-         /* Reload departments */
-         $this->config->departments= get_departments($this->dn);
-         $this->config->make_idepartments();
-         $smarty= get_smarty();
-
-
-         /* Base select dialog */
-         $once = true;
-         foreach($_POST as $name => $value){
-                 if(preg_match("/^chooseBase/",$name) && $once){
-                         $once = false;
-                         $this->dialog = new baseSelectDialog($this->config);
-                         $this->dialog->setCurrentBase($this->base);
-                 }
-         }
-
-         /* Dialog handling */
-         if(is_object($this->dialog)){
-                 /* Must be called before save_object */
-                 $this->dialog->save_object();
-
-                 if($this->dialog->isClosed()){
-                         $this->dialog = false;
-                 }elseif($this->dialog->isSelected()){
-                         $this->base = $this->dialog->isSelected();
-                         $this->dialog= false;
-                 }else{
-                         return($this->dialog->execute());
-                 }
-         }
-
-         /* Hide all departments, that are subtrees of this department */
-         $bases        = $this->config->idepartments;
-         if(($this->dn == "new")||($this->dn == "")){
-               $tmp = $bases;
-         }else{
-                 $tmp  = array();      
-                 foreach($bases as $dn=>$base){
-                         $fixed = str_replace("/","\\",$this->dn);
-                         /* Only attach departments which are not a subtree of this one */
-                         if(!preg_match("/".$fixed."/",$dn)){
-                                 $tmp[$dn]=$base;
-                         }
-                 }
-               }
-         $smarty->assign("bases", $tmp);
-
-         foreach ($this->attributes as $val){
-                 $smarty->assign("$val", $this->$val);
-                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
-         }
-         $smarty->assign("base_select", $this->base);
-         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
-  }
-
-  function clear_fields()
-  {
-         $this->dn= "";
-         $this->base= "";
-         $this->acl= "#none#";
-
-         foreach ($this->attributes as $val){
-                 $this->$val= "";
-         }
-  }
-
-
-  function remove_from_parent()
-  {
-         $ldap= $this->config->get_ldap_link();
-         $ldap->cd ($this->dn);
-         $ldap->recursive_remove();
-
-         /* Optionally execute a command after we're done */
-       $this->handle_post_events('remove');
-  }
-
-
-  /* Save data to object */
-  function save_object()
-  {
-       if (isset($_POST['base'])){
-               plugin::save_object();
-
-               /* Save base, since this is no LDAP attribute */
-               if (chkacl($this->acl, "create") == ""){
-                       $this->base= $_POST['base'];
+       var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
+
+       function department ($config, $dn)
+       {
+
+               plugin::plugin($config, $dn);
+               $this->is_account= TRUE;
+               $this->ui= get_userinfo();
+               $this->dn= $dn;
+               $this->orig_dn= $dn;
+               $this->config= $config;
+
+               /* Set base */
+               if ($this->dn == "new"){
+                       $ui= get_userinfo();
+                       if(isset($_SESSION['depfilter']['depselect'])){
+                               $this->base = $_SESSION['depfilter']['depselect'];
+                       }else{
+                               $this->base= dn2base($ui->dn);
+                       }
+               } else {
+                       $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
                }
+               /* set permissions */
+               $ui= get_userinfo();
+               $acl= get_permissions ($ui->dn, $ui->subtreeACL);
+               $this->acl= get_module_permission($acl, "department", $ui->dn);
        }
-  }
 
+       function execute()
+       {
+               /* Call parent execute */
+               plugin::execute();
+
+               /* Reload departments */
+               $this->config->departments= get_departments($this->dn);
+               $this->config->make_idepartments();
+               $smarty= get_smarty();
+
+
+               /* Base select dialog */
+               $once = true;
+               foreach($_POST as $name => $value){
+                       if(preg_match("/^chooseBase/",$name) && $once){
+                               $once = false;
+                               $this->dialog = new baseSelectDialog($this->config);
+                               $this->dialog->setCurrentBase($this->base);
+                       }
+               }
 
-  /* Check values */
-  function check()
-  {
-       $message= array();
+               /* Dialog handling */
+               if(is_object($this->dialog)){
+                       /* Must be called before save_object */
+                       $this->dialog->save_object();
+
+                       if($this->dialog->isClosed()){
+                               $this->dialog = false;
+                       }elseif($this->dialog->isSelected()){
+                               $this->base = $this->dialog->isSelected();
+                               $this->dialog= false;
+                       }else{
+                               return($this->dialog->execute());
+                       }
+               }
 
-       /* Permissions for that base? */
-//     $this->dn= "ou=$this->ou,".$this->base;
-       if (chkacl($this->acl, "create") != ""){
-               $message[]= _("You have no permissions to create a department on this 'Base'.");
-       }
+               /* Hide all departments, that are subtrees of this department */
+               $bases  = $this->config->idepartments;
+               if(($this->dn == "new")||($this->dn == "")){
+                       $tmp = $bases;
+               }else{
+                       $tmp    = array();      
+                       foreach($bases as $dn=>$base){
+                               $fixed = str_replace("/","\\",$this->dn);
+                               /* Only attach departments which are not a subtree of this one */
+                               if(!preg_match("/".$fixed."/",$dn)){
+                                       $tmp[$dn]=$base;
+                               }
+                       }
+               }
+               $smarty->assign("bases", $tmp);
 
-       /* Check for presence of this department */
-       $ldap= $this->config->get_ldap_link();
-       $attrs= $ldap->cat ($this->dn);
-       if ($this->orig_dn == "new" && !($attrs === FALSE)){
-               $message[]= _("Department with that 'Name' already exists.");
-       } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
-               $message[]= _("Department with that 'Name' already exists.");
+               foreach ($this->attributes as $val){
+                       $smarty->assign("$val", $this->$val);
+                       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
+               }
+               $smarty->assign("base_select", $this->base);
+               return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
        }
 
-       /* All required fields are set? */
-       if ($this->ou == ""){
-               $message[]= _("Required field 'Name' is not set.");
-       }
-       if ($this->description == ""){
-               $message[]= _("Required field 'Description' is not set.");
-       }
+       function clear_fields()
+       {
+               $this->dn= "";
+               $this->base= "";
+               $this->acl= "#none#";
 
-       /* Validate and modify - or: spaghetti rules! */
-       if ($this->ou == "incoming"){
-               $message[]= _("The field 'Name' contains the reserved word 'incoming'.".
-                               " Please choose another name.");
-       }
-       if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
-               $message[]= _("The field 'Name' contains invalid characters.");
+               foreach ($this->attributes as $val){
+                       $this->$val= "";
+               }
        }
-       if (!is_phone_nr($this->telephoneNumber)){
-               $message[]= _("The field 'Phone' contains an invalid phone number.");
+
+
+       function remove_from_parent()
+       {
+               $ldap= $this->config->get_ldap_link();
+               $ldap->cd ($this->dn);
+               $ldap->recursive_remove();
+
+               /* Optionally execute a command after we're done */
+               $this->handle_post_events('remove');
        }
-       if (!is_phone_nr($this->facsimileTelephoneNumber)){
-               $message[]= _("The field 'Fax' contains an invalid phone number.");
+
+
+       /* Save data to object */
+       function save_object()
+       {
+               if (isset($_POST['base'])){
+                       plugin::save_object();
+
+                       /* Save base, since this is no LDAP attribute */
+                       if (chkacl($this->acl, "create") == ""){
+                               $this->base= $_POST['base'];
+                       }
+               }
        }
 
-       return $message;
-  }
 
+       /* Check values */
+       function check()
+       {
+               $message= array();
+
+               /* Permissions for that base? */
+               //      $this->dn= "ou=$this->ou,".$this->base;
+               if (chkacl($this->acl, "create") != ""){
+                       $message[]= _("You have no permissions to create a department on this 'Base'.");
+               }
+
+               /* Check for presence of this department */
+               $ldap= $this->config->get_ldap_link();
+               $attrs= $ldap->cat ($this->dn);
+               if ($this->orig_dn == "new" && !($attrs === FALSE)){
+                       $message[]= _("Department with that 'Name' already exists.");
+               } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
+                       $message[]= _("Department with that 'Name' already exists.");
+               }
+
+               /* All required fields are set? */
+               if ($this->ou == ""){
+                       $message[]= _("Required field 'Name' is not set.");
+               }
+               if ($this->description == ""){
+                       $message[]= _("Required field 'Description' is not set.");
+               }
+
+               /* Validate and modify - or: spaghetti rules! */
+               if ($this->ou == "incoming"){
+                       $message[]= _("The field 'Name' contains the reserved word 'incoming'.".
+                                       " Please choose another name.");
+               }
+               if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
+                       $message[]= _("The field 'Name' contains invalid characters.");
+               }
+               if (!is_phone_nr($this->telephoneNumber)){
+                       $message[]= _("The field 'Phone' contains an invalid phone number.");
+               }
+               if (!is_phone_nr($this->facsimileTelephoneNumber)){
+                       $message[]= _("The field 'Fax' contains an invalid phone number.");
+               }
+
+               return $message;
+       }
 
-  /* Save to LDAP */
-  function save()
-  {
-       plugin::save();
 
-       /* Write back to ldap */
-       $ldap= $this->config->get_ldap_link();
-       $ldap->cat($this->dn);
-       $a= $ldap->fetch();
-       $ldap->cd($this->dn);
-       if (count($a)){
-               $this->cleanup();
-$ldap->modify ($this->attrs); 
+       /* Save to LDAP */
+       function save()
+       {
+               plugin::save();
+
+               /* Write back to ldap */
+               $ldap= $this->config->get_ldap_link();
+               $ldap->cat($this->dn);
+               $a= $ldap->fetch();
+               $ldap->cd($this->dn);
+               if (count($a)){
+                       $this->cleanup();
+                       $ldap->modify ($this->attrs); 
+
+                       $this->handle_post_events('modify');
+               } else {
+                       $ldap->add($this->attrs);
+                       $this->handle_post_events('add');
+               }
+               show_ldap_error($ldap->get_error());
 
-               $this->handle_post_events('modify');
-       } else {
-               $ldap->add($this->attrs);
-               $this->handle_post_events('add');
+               /* Optionally execute a command after we're done */
+               $this->postcreate();
        }
-       show_ldap_error($ldap->get_error());
 
-       /* Optionally execute a command after we're done */
-       $this->postcreate();
-  }
+       /* Move/Rename complete trees */
+       function recursive_move($src_dn, $dst_dn,$force = false)
+       {
+               if(! $force){
 
-  /* Move/Rename complete trees */
-  function recursive_move($src_dn, $dst_dn,$force = false)
-  {
-         if(! $force){
+                       $this->rec_cpy  = true;
+                       $this->rec_src  = $src_dn;
+                       $this->rec_dst  = $dst_dn;
 
-                 $this->rec_cpy        = true;
-                 $this->rec_src        = $src_dn;
-                 $this->rec_dst        = $dst_dn;
+                       $smarty = get_smarty();
 
-                 $smarty = get_smarty();
-               
                        $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove");
-       
-                 $display =  $smarty->fetch(get_template_path("recursive_moce.tpl",TRUE));
-                 return($display);
-                 exit();
-         }else{
-                 if(!$this->rec_cpy){ 
-                       return;
-
-                 }
-                 $src_dn = $this->rec_src;
-                 $dst_dn = $this->rec_dst;
-                echo "<font style='font-size:11px;'><h4>".
-              sprintf(_("Moving %s in %s"),"<br><i>".$src_dn."</i><br>","<br><i>".$dst_dn."</i><br>")."</h4>";
-
-
-                 /* Check if the destination entry exists */
-                 $ldap= $this->config->get_ldap_link();
-
-                 /* Check if destination exists - abort */
-                 $ldap->cat($dst_dn);
-                 if ($ldap->fetch()){
-                         trigger_error("recursive_move $dst_dn already exists.",
-                                         E_USER_WARNING);
+
+                       $display =  $smarty->fetch(get_template_path("recursive_moce.tpl",TRUE));
+                       return($display);
+                       exit();
+               }else{
+                       if(!$this->rec_cpy){ 
+                               return;
+                       }
+
+                       $src_dn = $this->rec_src;
+                       $dst_dn = $this->rec_dst;
+
+                       echo "<font style='font-size:11px;'><h4>".
+                               sprintf(_("Moving %s in %s"),"<br><i>".$src_dn."</i><br>","<br><i>".$dst_dn."</i><br>")."</h4>";
+
+
+                       /* Check if the destination entry exists */
+                       $ldap= $this->config->get_ldap_link();
+
+                       /* Check if destination exists - abort */
+                       $ldap->cat($dst_dn);
+                       if ($ldap->fetch()){
+                               trigger_error("recursive_move $dst_dn already exists.",
+                                               E_USER_WARNING);
                                echo "recursive_move :$dst_dn already exists.<br>"; 
-                         return (FALSE);
-                 }
-
-                 /* Perform a search for all objects to be moved */
-                 $objects= array();
-                 $ldap->cd($src_dn);
-                 $ldap->search("(objectClass=*)", array("dn"));
-                 while($attrs= $ldap->fetch()){
-                         $dn= $attrs['dn'];
-                         $objects[$dn]= strlen($dn);
-                 }
-
-                 /* Sort objects by indent level */
-                 asort($objects);
-                 reset($objects);
-
-                 /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
-                 foreach ($objects as $object => $len){
-                         $src= $object;
-                         $dst= preg_replace("/$src_dn$/", "$dst_dn", $object);
-                               echo "Moving    <b>".$src."</b>  to  <b>".$dst."</b><br>";
-                         if (!$this->copy($src, $dst)){
-                                 return (FALSE);
-                         }
-                 }
-
-                 /* Remove src_dn */
-                 $ldap->cd($src_dn);
-                 $ldap->recursive_remove();
-
-                 $this->rec_src = $this->rec_dst = "";
-                 $this->rec_cpy =false;
+                               return (FALSE);
+                       }
+       
+                       /* Perform a search for all objects to be moved */
+                       $objects= array();
+                       $ldap->cd($src_dn);
+                       $ldap->search("(objectClass=*)", array("dn"));
+                       while($attrs= $ldap->fetch()){
+                               $dn= $attrs['dn'];
+                               $objects[$dn]= strlen($dn);
+                       }
+
+                       /* Sort objects by indent level */
+                       asort($objects);
+                       reset($objects);
+
+                       /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
+                       foreach ($objects as $object => $len){
+
+                               
+                               $src= str_replace("\\","\\\\",$object);
+                               $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
+                               $dst= str_replace($src_dn,$dst_dn,$object);
+
+                               echo "Moving    <b>".$src."</b>  to  <b>".$dst."</b><br>";
+                               
+                               if (!$this->copy($src, $dst)){
+                                       echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),$src)."</font>";
+                                       return (FALSE);
+                               }
+                       }
+
+                       /* Remove src_dn */
+                       $ldap->cd($src_dn);
+                       
+                       echo "<br><b>"._("Complete")."</b>";
+
+                       $ldap->recursive_remove();
+                       $this->rec_src = $this->rec_dst = "";
+                       $this->rec_cpy =false;
                        echo "</font>";
-                 return (TRUE);
-         }
-  }
+                       return (TRUE);
+               }
+       }
 
 
 }