Code

Added user selection
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 16 Sep 2010 11:38:58 +0000 (11:38 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 16 Sep 2010 11:38:58 +0000 (11:38 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19706 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/Device.tpl
gosa-plugins/goto/admin/systems/goto/Device/class_Device.inc

index 3a99b999f2d20a4b7f193901aa87ee594d9d1c49..d07dfeecf7248a3298ee5585aba3f4ce87dd1e41 100644 (file)
                     <td><LABEL for='seeAlso'>{t}See also{/t}</LABEL></td>
                     <td> <input type="text" name="seeAlso" value="{$seeAlso}"></td>
                 </tr>
+                <tr>
+                </tr>
                 <tr>
                     <td><LABEL for='owner'>{t}Owner{/t}</LABEL></td>
-                    <td> <input type="text" name="owner" value="{$owner}"></td>
+                    <td>
+                        <input type="text" name="owner" value="{$owner_name}" 
+                            title="{$owner}" disabled style="width:120%;">
+
+                        {image path="images/lists/edit.png" action="editOwner" acl=$ownerACL}
+                        {if $owner!=""}
+                            {image path="images/info_small.png" title="{$owner}" acl=$ownerACL}
+                            {image path="images/lists/trash.png" action="removeOwner" acl=$ownerACL}
+                        {/if}
+                 </td>
                 </tr>
             </table>
         </td>
             <table>
                 <tr>
                     <td><LABEL for='manager'>{t}Manager{/t}</LABEL></td>
-                    <td> <input type="text" name="manager" value="{$manager}"></td>
+                    <td>
+                        <input type="text" name="manager" value="{$manager_name}" 
+                            title="{$manager}" disabled style="width:120%;">
+
+                        {image path="images/lists/edit.png" action="editManager" acl=$managerACL}
+                        {if $manager!=""}
+                            {image path="images/info_small.png" title="{$manager}" acl=$managerACL}
+                            {image path="images/lists/trash.png" action="removeManager" acl=$managerACL}
+                        {/if}
+                 </td>
                 </tr>
                 <tr>
                     <td><LABEL for='deviceUUID'>{t}Device UUID{/t}</LABEL></td>
index be4276193ba65c56931123c529e3d038d8a51a74..f336a2738c244a276f3d1d108e6700461b2511ff 100644 (file)
@@ -30,6 +30,8 @@ class Device extends plugin
 
     public $base = "";
     public $orig_dn ="";
+    
+    private $resolvedNamesCache = array();
 
     function __construct(&$config, $dn)
     {
@@ -38,20 +40,92 @@ class Device extends plugin
         $this->orig_dn = $this->dn;
     }
 
+
     function execute()
     {
         plugin::execute();    
+
+        if($this->dialog instanceOf singleUserSelect) return($this->dialog->execute());
+
+
         $smarty = get_smarty();
+
+        // Assign ACL settings 
+        $plInfo = $this->plInfo();
+        foreach($plInfo['plProvidedAcls'] as $name => $desc){
+            $smarty->assign("{$name}ACL", $this->getacl($name));
+        }
+    
+        // Assign just user names instead of the complete dn.
+        $smarty->assign("owner_name", $this->getUserName($this->owner));
+        $smarty->assign("manager_name", $this->getUserName($this->manager));
+
         foreach($this->attributes as $attr){
             $smarty->assign($attr, $this->$attr);
         }
         return($smarty->fetch(get_template_path('goto/Device/Device.tpl', TRUE)));
     }
 
+   
+    /*! \brief  Detect an object's name by querying the ldap
+     *           for the object's cn.
+     * @param   String  The object's dn to query for.
+     */ 
+    function getUserName($dn)
+    {   
+        // First asked the cache if we've already queried this name.
+        if(isset($this->resolvedNamesCache[$dn])) {
+            return($this->resolvedNamesCache[$dn]);
+        }
 
-    function save()
+        // Try to detect the object's name via ldap search.
+        $ldap = $this->config->get_ldap_link();
+        $this->resolvedNamesCache[$dn] = "";
+        if(!empty($dn)){
+            $ldap->cat($dn, array('cn'));
+            if($ldap->count()){
+                $attrs = $ldap->fetch();
+                $this->resolvedNamesCache[$dn] = $attrs['cn'][0];
+                return( $attrs['cn'][0]);
+            }else{
+                $this->resolvedNamesCache[$dn] = "("._("unknown")."!): ".$dn;
+            }
+        }
+        return($this->resolvedNamesCache[$dn]);
+    }   
+    
+    function save_object()
     {
+        plugin::save_object();
 
+        if(isset($_POST['editOwner'])){
+            $this->currentUserSelect = "owner";
+            $this->dialog = new singleUserSelect($this->config, get_userinfo());
+        }
+        if(isset($_POST['editManager'])){
+            $this->currentUserSelect = "manager";
+            $this->dialog = new singleUserSelect($this->config, get_userinfo());
+        }
+        if($this->dialog && $this->dialog instanceOf singleUserSelect && count($this->dialog->detectPostActions())){
+            $users = $this->dialog->detectPostActions();
+            if(isset($users['action']) && $users['action'] == 'userSelected' && isset($users['targets']) && count($users['targets'])){
+                $headpage = $this->dialog->getHeadpage();
+                $dn = $users['targets'][0];
+                $attr = $this->currentUserSelect;
+                $this->$attr = $dn;
+                $this->dialog = NULL;
+            }
+        }
+        if(isset($_POST['add_users_cancel'])){
+            $this->dialog = NULL;
+        }
+        
+    }
+
+
+    function save()
+    {
         plugin::save();
 
         // Append and remove dynmic object classes