Code

Added initial templatizing dialog. Rest will follow when there's time.
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 14 Apr 2008 13:28:56 +0000 (13:28 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 14 Apr 2008 13:28:56 +0000 (13:28 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10423 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/users/class_userManagement.inc
gosa-core/plugins/admin/users/templatize.tpl

index 7b9535cb4c9290d45c7063c74612d6ad471eaff5..6e30cb359b6eba8ca39fd618913674b327bcff35 100644 (file)
@@ -120,44 +120,51 @@ class userManagement extends plugin
       $s_tab = "user";
     }
 
-
-    /* handle C&P from layers menu */
-    if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
-      $s_action = "copy_multiple";
-    }
-    if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
-      $s_action = "cut_multiple";
-    }
-    if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
-      $s_action = "editPaste";
-    }
-
-    /* Create options */
-    if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_new"){
-      $s_action = "new";
-    }
-    if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_tplnew"){
-      $s_action = "new_tpl";
-    }
-    if(isset($_POST['menu_action']) && $_POST['menu_action'] == "multiple_edit"){
-      $s_action = "multiple_edit";
-    }
-
-    /* handle remove from layers menu */
-    if(isset($_POST['menu_action']) && preg_match("/^multiple_password_change/",$_POST['menu_action'])){
-      $s_action = "multiple_password_change";
-    }
-
-    /* handle remove from layers menu */
-    if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
-      $s_action = "del_multiple";
-    }
-    if(isset($_POST['menu_action']) && preg_match("/^templatize_multiple/",$_POST['menu_action'])){
-      $s_action = "templatize_multiple";
+    if (isset($_POST['menu_action'])){
+
+           /* handle C&P from layers menu */
+           if(preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
+             $s_action = "copy_multiple";
+           }
+           if(preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
+             $s_action = "cut_multiple";
+           }
+           if(preg_match("/^editPaste/",$_POST['menu_action'])){
+             $s_action = "editPaste";
+           }
+
+           /* Create options */
+           if($_POST['menu_action'] == "user_new"){
+             $s_action = "new";
+           }
+           if($_POST['menu_action'] == "user_tplnew"){
+             $s_action = "new_tpl";
+           }
+           if($_POST['menu_action'] == "multiple_edit"){
+             $s_action = "multiple_edit";
+           }
+
+           /* handle remove from layers menu */
+           if(preg_match("/^multiple_password_change/",$_POST['menu_action'])){
+             $s_action = "multiple_password_change";
+           }
+
+           /* handle remove from layers menu */
+           if(preg_match("/^remove_multiple/",$_POST['menu_action'])){
+             $s_action = "del_multiple";
+           }
+           if(preg_match("/^templatize_multiple/",$_POST['menu_action'])){
+             $s_action = "templatize_multiple";
+           }
+
+           if(preg_match("/^event/",$_POST['menu_action'])){
+             $s_action = $_POST['menu_action'];
+           }
     }
 
-    if(isset($_POST['menu_action']) && preg_match("/^event/",$_POST['menu_action'])){
-      $s_action = $_POST['menu_action'];
+    /* Use template */
+    if(isset($_POST['templatize_continue'])){
+      $s_action = "templatize_continue";
     }
 
 
@@ -438,15 +445,51 @@ class userManagement extends plugin
 
 
     /********************
-      Apply template to multiple entries requested, display confirm dialog
+      We want to create a new user, so fetch all available user templates 
      ********************/
 
+    /* Generate template list */
+    if ($s_action == "new" || $s_action == "create_user_from_tpl" || $s_action == "templatize_multiple"){
+
+      $this->templates= array();
+      $ldap= $this->config->get_ldap_link();
+
+      /* Create list of templates */
+      foreach ($this->config->departments as $key => $value){
+    
+        /* Get acls from different ou's */
+        $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
+        /* If creation of a new user is allowed, append this template */
+        if (preg_match("/c/",$acl)){
+          
+          /* Search all templates from the current dn */
+          $ldap->cd (get_people_ou().$value);
+          $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
+
+          /* Append */
+          if ($ldap->count() != 0){
+            while ($attrs= $ldap->fetch()){
+              $this->templates[$ldap->getDN()]=
+                $attrs['uid'][0]." - ".@LDAP::fix($key);
+            }
+           if ($s_action != "templatize_multiple"){
+                   $this->templates['none']= _("none");
+           }
+          }
+        }
+      }
+
+      /* Sort templates */
+      natcasesort ($this->templates);
+      reset ($this->templates);
+    }
+
+
+    /********************
+      Apply template to multiple entries requested, display confirm dialog
+     ********************/
 
-    # TODO: show dialog to choose
-    #       * template
-    #       * when the template is choosen refresh the list of
-    #         available attributes with a checkbox - everything checked
-    #       * when pressing apply do the stuff below
     if ($s_action=="templatize_multiple"){
       $ids = $this->list_get_selected_items();
       $this->dns = array();
@@ -461,20 +504,37 @@ class userManagement extends plugin
         }
       }
 
+      $smarty->assign("templates", $this->templates);
+
       return($smarty->fetch(get_template_path('templatize.tpl', TRUE)));
     }
 
-# TODO: apply after we pressed some button
-#      foreach ($this->dns as $dn){
-#
-#        echo "Template test with '$dn'<br>";
-#        $template_dn= "cn=super44 super44,ou=people,dc=gonicus,dc=de";
-#        $usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
-#        $usertab->adapt_from_template($template_dn, array("sn", "givenName", "uid"));
-#        $usertab->save();
-#        unset ($usertab);
-#        $usertab= NULL;
-#      }
+    /* Perform templatizing after the button has been pressed */
+    if ($s_action == "templatize_continue"){
+
+      $acl = $this->ui->get_permissions($_POST['template'], "users/user");
+
+      /* Template readable? */
+      if (preg_match('/r/', $acl)){
+       $template_dn= $_POST['template'];
+
+        foreach ($this->dns as $dn){
+         $acl = $this->ui->get_permissions($_POST['template'], "users/user");
+         if (preg_match('/w/', $acl)){
+                 $usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
+                 $usertab->adapt_from_template($template_dn, array("sn", "givenName", "uid"));
+                 $usertab->save();
+                 unset ($usertab);
+                 $usertab= NULL;
+         } else {
+                 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to modify object '%s'!"), $dn), ERROR_DIALOG);
+          }
+        }
+      } else {
+       msg_dialog::display(_("Permission error"), _("You have no permission to use this template!"), ERROR_DIALOG);
+      }
+
+    }
 
 
     /********************
@@ -720,45 +780,6 @@ class userManagement extends plugin
     }
 
 
-    /********************
-      We want to create a new user, so fetch all available user templates 
-     ********************/
-
-    /* Generate template list */
-    if (($s_action=="new")||($s_action=="create_user_from_tpl")){
-
-      $this->templates= array();
-      $ldap= $this->config->get_ldap_link();
-
-      /* Create list of templates */
-      foreach ($this->config->departments as $key => $value){
-    
-        /* Get acls from different ou's */
-        $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
-        /* If creation of a new user is allowed, append this template */
-        if (preg_match("/c/",$acl)){
-          
-          /* Search all templates from the current dn */
-          $ldap->cd (get_people_ou().$value);
-          $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
-
-          /* Append */
-          if ($ldap->count() != 0){
-            while ($attrs= $ldap->fetch()){
-              $this->templates[$ldap->getDN()]=
-                $attrs['uid'][0]." - ".@LDAP::fix($key);
-            }
-            $this->templates['none']= _("none");
-          }
-        }
-      }
-
-      /* Sort templates */
-      natcasesort ($this->templates);
-      reset ($this->templates);
-    }
-
 
     /********************
       Create a new user,template, user from template 
index 3288ebf2bb9763d8eb9cc31c6c82c8520f358209..8e38f9fe9dd21d61e1bdf5808466f457e2ff93bf 100644 (file)
@@ -1,5 +1,5 @@
 <div style="font-size:18px;">
-  {t}Applying a template to users{/t}
+  {t}Applying a template{/t}
 </div>
 
 <p>
@@ -7,15 +7,15 @@
 </p>
 
 <p class="seperator">&nbsp;</p>
-
 <br>
 
+{if $templates}
 <table summary="" style="vertical-align:top; text-align:left;" cellpadding=4 border=0>
   <tr>
     <td><b><LABEL for="template">{t}Template{/t}</LABEL></b></td>
     <td>
       <select size="1" name="template" id="template">
-       {html_options options=$templates selected=$template}
+       {html_options options=$templates}
       </select>
     </td>
   </tr>
 
 <br>
 <p class="plugbottom">
-  <input type=submit name="template_continue" value="{msgPool type=applyButton}">
+  <input type=submit name="templatize_continue" value="{msgPool type=applyButton}">
   &nbsp;
   <input type=submit name="edit_cancel" value="{msgPool type=cancelButton}">
 </p>
 
+{else}
+
+{t}No templates available!{/t}
+
+<p class="plugbottom">
+  <input type=submit name="edit_cancel" value="{msgPool type=cancelButton}">
+</p>
+{/if}
 
 
 <!-- Place cursor -->