Code

Some changes for branches
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 Jan 2006 14:58:37 +0000 (14:58 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 11 Jan 2006 14:58:37 +0000 (14:58 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2450 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_faiManagement.inc
plugins/admin/fai/faiNewBranch.tpl
plugins/admin/fai/headpage.tpl

index 17971a305dda1423d352b9bca4d7944e0c133f18..099905f380034c6620da3a3b0b0e79c3b5ed80d7 100644 (file)
@@ -93,13 +93,18 @@ class faiManagement extends plugin
 
                $display        = "";
                $smarty         = get_smarty();
-               $s_action       = "";
+               $smarty->assign("BranchName","");
+    $s_action  = "";
                $s_entry        = "";
                /* filter management 
                 * Filter will be changed if POST['regex'] or $_GET['search'] isset
                 * New Filter will be stored in session and is used to generate list contents
                 */     
                $faifilter = $_SESSION['faifilter'];
+    
+    if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
+      $faifilter['branch'] = $_POST['select_branch'];
+    }
 
                /* Filter is posted by apply button 
                 * Check every single chkbox 
@@ -115,11 +120,6 @@ class faiManagement extends plugin
                        }
                }
 
-    if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
-      $faifilter['branch'] = $_POST['select_branch'];
-    }
-    
-    $smarty->assign("select_branch",$_SESSION['faifilter']['branch']);
 
                /* Check ImageButton posts
                 * Create new tab ich new_xx is posted
@@ -154,16 +154,19 @@ class faiManagement extends plugin
                        }elseif(preg_match("/^entry_delete_.*/",$key)){
                                $s_entry = preg_replace("/^entry_delete_/","",$key);
                                $s_entry = preg_replace("/_.*$/","",$s_entry);
-                               $s_action = "delete";
-                       }elseif(preg_match("/dep_back.*/i",$key)){
-                $s_action="back";
-            }elseif(preg_match("/dep_home.*/i",$key)){
-                $s_action="home";
-            }elseif(preg_match("/dep_root.*/i",$key)){
-                $s_action="root";
-                       }
+        $s_action = "delete";
+      }elseif(preg_match("/dep_back.*/i",$key)){
+        $faifilter['branch'] = "main";
+        $s_action="back";
+      }elseif(preg_match("/dep_home.*/i",$key)){
+        $faifilter['branch'] = "main";
+        $s_action="home";
+      }elseif(preg_match("/dep_root.*/i",$key)){
+        $faifilter['branch'] = "main";
+        $s_action="root";
+      }
 
-               }
+    }
 
                if($s_action=="root"){
                        $faifilter['base']=($this->config->current['BASE']);
@@ -297,23 +300,24 @@ class faiManagement extends plugin
 
     /* Create new branch */
     if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
-      
+     
       /* Check branch name */
       $name = $_POST['BranchName'];
       $is_ok = true;
 
+      $smarty->assign("BranchName",$name);
                  $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
       
       /* Check used characters */
-      if(preg_match("/[^0-9a-z]/i",$name)){
+      if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
         print_red(_("Specified branch name is invalid."));
         $is_ok = false;
       }
    
       /* Check if this name is already in use */
-      if(!$this->CheckNewBranchName($_POST['BranchName'])){
+      if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
         print_red(_("This name is already in use."));
-        $this->is_ok = false;
+        $is_ok = false;
       }
      
       if($is_ok){
@@ -338,6 +342,7 @@ class faiManagement extends plugin
     /* Abort creating new branch */
     if(isset($_POST['CancelBranchName'])){
       $this->dispNewBranch = false;
+      $this->dispNewFreeze = false;
     }
 
     /* Open dialog to insert new branch name */
@@ -350,13 +355,13 @@ class faiManagement extends plugin
 
     /* Remove branch */
     if($s_action == "remove_branch"){
-      $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
+      $base= $faifilter['branch'];
       /* Load permissions for selected 'dn' and check if
          we're allowed to remove this 'dn' */
-      $acl= get_permissions ($base, $this->ui->subtreeACL);
+      $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
       $this->acl= get_module_permission($acl, "fai", $base);
       if (chkacl($this->acl, "delete") == ""){
-        $smarty->assign("warning", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $base));
+        $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $faifilter['branch']));
         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
       } else {
         print_red (_("You are not allowed to delete this user!"));
@@ -365,32 +370,40 @@ class faiManagement extends plugin
 
     /* Delete this entry */
     if(isset($_POST['delete_branch_confirm'])){
-      print "branch removed ";
-    }
+      $bb =  $faifilter['branch'];
+      if(!isset($ldap)){
+        $ldap = $this->config->get_ldap_link();
+      }
 
-    if($s_action == "freeze_branch"){
-      $this->dispNewFreeze = true;
-                 $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
-      return($display);
+      $br = $this->getBranches();
+
+      if(isset($br[$bb])){
+        $ldap->cd($bb);
+        $ldap->recursive_remove();
+        $faifilter['branch'] = "main";
+      }
     }
 
+
     if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
       /* Check branch name */
       $name = $_POST['BranchName'];
       $is_ok = true;
 
+      $smarty->assign("BranchName",$name);
+
                  $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
       
       /* Check used characters */
-      if(preg_match("/[^0-9a-z]/i",$name)){
+      if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
         print_red(_("Specified branch name is invalid."));
         $is_ok = false;
       }
    
       /* Check if this name is already in use */
-      if(!$this->CheckNewBranchName($_POST['BranchName'])){
+      if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
         print_red(_("This name is already in use."));
-        $this->is_ok = false;
+        $is_ok = false;
       }
      
       if($is_ok){
@@ -412,6 +425,11 @@ class faiManagement extends plugin
       }
     }
     
+    if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
+      $this->dispNewFreeze = true;
+                 $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
+      return($display);
+    }
 
     /* ENDE Branch handling 
      */
@@ -484,6 +502,14 @@ class faiManagement extends plugin
                if((isset($_POST['base']))&&($s_action=="")){
                        $faifilter['base']=$_POST['base'];
                }
+  
+
+    $br = $this->getBranches();
+    if(!isset($br[$faifilter['branch']])){
+      $faifilter['branch'] = "main";
+    }
+   
+    $smarty->assign("select_branch",$faifilter['branch']);
 
                /* remove double asterisks and save new filter */
                $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
@@ -756,6 +782,7 @@ class faiManagement extends plugin
                $smarty->assign("failist"               , $divlist->DrawList());
                $smarty->assign("regex"                 , $faifilter['regex']); 
                $smarty->assign("infoimage"             , get_template_path('images/info.png'));
+               $smarty->assign("branchimage"           , get_template_path('images/action.png'));
                $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
                $smarty->assign("alphabet"              , generate_alphabet());
                $smarty->assign("apply"                 , apply_filter());
@@ -933,8 +960,18 @@ class faiManagement extends plugin
                }
        }
 
-  function CheckNewBranchName($name){
-    if(in_array($name,$this->getBranches())) {
+  function CheckNewBranchName($name,$base){
+    $f = $_SESSION['faifilter']['branch'];
+
+    if($f == "main"){
+      $f = $_SESSION['faifilter']['base'];
+    } 
+    
+    if(in_array($name,$this->getBranches($f))) {
+      return(false);
+    }
+
+    if(empty($name)){
       return(false);
     }
     return(true);
index e3ec48045fda9142f81f3e2c2d1b48b1d440a77f..183c6a3e94475e436c91a057157b786feb508b95 100755 (executable)
@@ -22,7 +22,7 @@
    </tr>
    <tr>
      <td>
-      {t}Branch name{/t}&nbsp;<input type="text"        name="BranchName" value="" style="width:120px;">
+      {t}Branch name{/t}&nbsp;<input type="text"        name="BranchName" value="{$BranchName}" style="width:120px;">
      </td>
     </tr>
    </table>
index e8ccfbf03271d5530869bf6ad4aaaa7535f8c3d6..d035268f516cd077366b093ec3fd8c171c6b7335 100644 (file)
    </div>
    <br>
    <div class="contentboxh">
-    <p class="contentboxh"><img src="{$launchimage}" align="right" alt="[F]">{t}Filters{/t}</p>
+    <p class="contentboxh"><img src="{$branchimage}" align="right" alt="[F]">{t}Branches{/t}</p>
    </div>
    <div class="contentboxb" style="padding:3px;">
-       
+       {t}Selected branch{/t}&nbsp;
        <select name="select_branch" onChange="document.mainform.submit();">
                {html_options values=$branchKeys output=$branches selected=$select_branch}
        </select>
+       {if $select_branch != "main"}
        <br>
        {t}Delete this branch.{/t}
+       &nbsp;
        <input type="image" value="delete" name="remove_branch" src="images/edittrash.png"> 
+       {/if}   
        <br>
        {t}Create a new branch{/t}
+       &nbsp;
        <input type="image" value="delete" name="branch_branch" src="images/crossref.png">
        <br>
        {t}Freeze this{/t}
+       &nbsp;
        <input type="image" value="delete" name="freeze_branch" src="images/flag.png">
    </div>
    <br>