Code

Updated in_array checks in GOsa.
[gosa.git] / gosa-core / plugins / personal / posix / class_posixAccount.inc
index af89c484aa01195d54eeb56ee4149e7b0268daa3..924153c380ddbd3f0ef8aaaf8eb959be936a84e5 100644 (file)
@@ -93,6 +93,10 @@ class posixAccount extends plugin
   var $multiple_support = TRUE;
   var $groupMembership_some = array();
 
+  // group SortableListing
+  var $groupList = null;
+  var $groupListData = null;
+
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
   function posixAccount (&$config, $dn= NULL, $parent =NULL)
@@ -105,6 +109,8 @@ class posixAccount extends plugin
     /* Load bases attributes */
     plugin::plugin($config, $dn, $parent);
 
+    $groupImage = image('plugins/groups/images/select_group.png');
+
     $this->trustModeDialog = new trustModeDialog($this->config, $this->dn, $parent);
     $this->trustModeDialog->setAcl('users/posixAccount');
 
@@ -128,7 +134,7 @@ class posixAccount extends plugin
 
       /* Correct is_account. shadowAccount is not required. */
       if (isset($this->attrs['objectClass']) &&
-          in_array ('posixAccount', $this->attrs['objectClass'])){
+          in_array_strict('posixAccount', $this->attrs['objectClass'])){
 
         $this->is_account= TRUE;
       }
@@ -156,14 +162,17 @@ class posixAccount extends plugin
       }
 
       /* Get group membership */
+      $this->groupListData = array();
       $ldap->cd($this->config->current['BASE']);
       $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("cn", "description"));
 
       while ($attrs= $ldap->fetch()){
         if (!isset($attrs["description"][0])){
           $entry= $attrs["cn"][0];
+          $this->groupListData[$ldap->getDN()] = array($groupImage, $attrs["cn"][0], "");
         } else {
           $entry= $attrs["cn"][0]." [".$attrs["description"][0]."]";
+          $this->groupListData[$ldap->getDN()] = array($groupImage, $attrs["cn"][0], $attrs["description"][0]);
         }
         $this->groupMembership[$ldap->getDN()]= $entry;
       }
@@ -217,7 +226,7 @@ class posixAccount extends plugin
     }
 
     /* Insert possibly missing loginShell */
-    if ($this->loginShell != "" && !in_array($this->loginShell, $this->loginShellList)){
+    if ($this->loginShell != "" && !in_array_strict($this->loginShell, $this->loginShellList)){
       $this->loginShellList[]= $this->loginShell;
     }
 
@@ -232,6 +241,19 @@ class posixAccount extends plugin
     asort ($this->secondaryGroups);
 
     $this->ui = get_userinfo();
+
+    // Create group-list
+    $this->groupList = new sortableListing(array(), array());
+    $this->groupList->setHeader(array(_("~"), _("Group"), _("Description")));
+    $this->groupList->setEditable(false);
+    $this->groupList->setDeleteable(true);
+    $this->groupList->setInstantDelete(false);
+    $this->groupList->setEditable(false);
+    $this->groupList->setReorderable(false);
+    $this->groupList->setDefaultSortColumn(1);
+    $this->groupList->setWidth("100%");
+    $this->groupList->setHeight("150px");
+    $this->groupList->setAcl("rwcdm");
   }
 
 
@@ -318,6 +340,14 @@ class posixAccount extends plugin
       $this->groupSelect= NULL;
     }
 
+    // Remove groups that were removed by list
+    $this->groupList->save_object();
+    $actionL = $this->groupList->getAction();
+    if($actionL['action'] == "delete") {
+        $key = $this->groupList->getData($actionL['targets'][0]);
+        $this->delGroup(array($key));
+    }
+
     // Remove groups from currently selected groups.
     if (isset($_POST['delete_groupmembership']) && 
         isset($_POST['group_list']) && count($_POST['group_list'])){
@@ -325,10 +355,22 @@ class posixAccount extends plugin
       $this->delGroup (get_post('group_list'));
     }
 
-    /* Templates now! */
-    $smarty= get_smarty();
+    // Build group-list data
+    $dDisp = array();
+    $dData = array();
+
+    foreach($this->groupListData as $key => $value) {
+        $dData[$key] = $key;
+        $dDisp[$key] = array('data' => $value);
+    }
+
+    $this->groupList->setListData($dData, $dDisp);
+    $this->groupList->update();
 
+    /* Templates now! */
+    $smarty = get_smarty();
 
+    $smarty->assign("groupList", $this->groupList->render());
 
     // Handle trust mode dialog
     $trustModeDialog = $this->trustModeDialog->execute();
@@ -452,7 +494,7 @@ class posixAccount extends plugin
     $smarty->assign("force_idsACL", $this->getacl("uidNumber").$this->getacl("gidNumber"));
 
     foreach(array("primaryGroup","activate_shadowWarning","activate_shadowInactive","activate_shadowMin","activate_shadowMax","activate_shadowExpire","mustchangepassword") as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
@@ -462,7 +504,7 @@ class posixAccount extends plugin
 
     /* Load attributes and acl's */
     foreach($this->attributes as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
@@ -620,7 +662,7 @@ class posixAccount extends plugin
     if ($this->mustchangepassword){
       $this->shadowLastChange= (int)(date("U") / 86400) - $this->shadowMax - 1;
     } else {
-      $this->shadowLastChange= (int)(date("U") / 86400);
+#      $this->shadowLastChange= (int)(date("U") / 86400);
     }
     if (!$this->activate_shadowWarning){
       $this->shadowWarning= "0";
@@ -932,47 +974,47 @@ class posixAccount extends plugin
   function multiple_check()
   {
     $message = plugin::multiple_check();
-    if ($this->homeDirectory == "" && in_array("homeDirectory",$this->multi_boxes)){
+    if ($this->homeDirectory == "" && in_array_strict("homeDirectory",$this->multi_boxes)){
       $message[]= msgPool::required(_("Home directory"));
     }
-    if (!tests::is_path($this->homeDirectory) && in_array("homeDirectory",$this->multi_boxes)){
+    if (!tests::is_path($this->homeDirectory) && in_array_strict("homeDirectory",$this->multi_boxes)){
       $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
     }
 
     /* Check shadow settings, well I like spaghetties... */
-    if ($this->activate_shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+    if ($this->activate_shadowMin && in_array_strict("activate_shadowMin",$this->multi_boxes)){
       if (!tests::is_id($this->shadowMin)){
         $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
       }
     }
-    if ($this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+    if ($this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
       if (!tests::is_id($this->shadowMax)){
         $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
       }
     }
-    if ($this->activate_shadowWarning && in_array("activate_shadowWarning",$this->multi_boxes)){
+    if ($this->activate_shadowWarning && in_array_strict("activate_shadowWarning",$this->multi_boxes)){
       if (!tests::is_id($this->shadowWarning)){
         $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
       }
-      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+      if (!$this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
         $message[]= msgPool::depends("shadowWarning", "shadowMax");
       }
-      if ($this->shadowWarning > $this->shadowMax && in_array("activate_shadowWarning",$this->multi_boxes)){
+      if ($this->shadowWarning > $this->shadowMax && in_array_strict("activate_shadowWarning",$this->multi_boxes)){
         $message[]= msgPool::toobig("shadowWarning", "shadowMax");
       }
-      if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
+      if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array_strict("activate_shadowMin",$this->multi_boxes)){
         $message[]= msgPool::tosmall("shadowWarning", "shadowMin");
       }
     }
-    if ($this->activate_shadowInactive && in_array("activate_shadowInactive",$this->multi_boxes)){
+    if ($this->activate_shadowInactive && in_array_strict("activate_shadowInactive",$this->multi_boxes)){
       if (!tests::is_id($this->shadowInactive)){
         $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
       }
-      if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
+      if (!$this->activate_shadowMax && in_array_strict("activate_shadowMax",$this->multi_boxes)){
         $message[]= msgPool::depends("shadowInactive", "shadowMax");
       }
     }
-    if ($this->activate_shadowMin && $this->activate_shadowMax && in_array("activate_shadowMin",$this->multi_boxes)){
+    if ($this->activate_shadowMin && $this->activate_shadowMax && in_array_strict("activate_shadowMin",$this->multi_boxes)){
       if ($this->shadowMin > $this->shadowMax){
         $message[]= msgPool::toobig("shadowMin", "shadowMax");
       }
@@ -986,6 +1028,7 @@ class posixAccount extends plugin
   {
     /* include global link_info */
     $ldap= $this->config->get_ldap_link();
+    $groupImage = image("plugins/groups/images/select_group.png");
 
     /* Walk through groups and add the descriptive entry if not exists */
     foreach ($groups as $value){
@@ -993,6 +1036,7 @@ class posixAccount extends plugin
       if (!array_key_exists($value, $this->groupMembership)){
         $ldap->cat($value, array('cn', 'description', 'dn'));
         $attrs= $ldap->fetch();
+        $dsc = "&nbsp;";
         error_reporting (0);
         if (!isset($attrs['description'][0])){
           $entry= $attrs["cn"][0];
@@ -1004,6 +1048,20 @@ class posixAccount extends plugin
 
         if(obj_is_writable($attrs['dn'],"groups/group","memberUid")){
           $this->groupMembership[$attrs['dn']]= $entry;
+
+          /* Add new group to groupList */
+          $this->groupListData[$attrs['dn']] = array();
+          $this->groupListData[$attrs['dn']][] = $groupImage;
+          $this->groupListData[$attrs['dn']][] = $attrs['cn'][0];
+          if(isset($attrs["description"])) {
+            $this->groupListData[$attrs['dn']][] = $attrs['description'][0];
+          } else {
+            $this->groupListData[$attrs['dn']][] = "";
+          }
+          if($this->multiple_support_active) {
+            $this->groupListData[$attrs['dn']][] = _("all");
+          }
+
           if($this->multiple_support_active && isset($this->groupMembership_some[$attrs['dn']])){
             unset($this->groupMembership_some[$attrs['dn']]);
           }
@@ -1024,10 +1082,12 @@ class posixAccount extends plugin
     foreach($groups as $dn_to_del){
       if(isset($this->groupMembership[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
         unset($this->groupMembership[$dn_to_del]);
+        unset($this->groupListData[$dn_to_del]);
       }
       if($this->multiple_support_active){
         if(isset($this->groupMembership_some[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
           unset($this->groupMembership_some[$dn_to_del]);
+          unset($this->groupListData[$dn_to_del]);
         }
       }
     }
@@ -1079,21 +1139,17 @@ class posixAccount extends plugin
       }
     }
 
-    /* FIXME: NEED review of this section */
-    /* Need to check shadowExpire separately */
-
-    /* 
-     * If shadowExpire is not enabled in the template, it's a UNIX timestamp - so don't convert it to seconds.
-     * The check is a hack - if difference between timestamp generated above and here is max 1 day.
-     */
-    if(abs($this->shadowExpire - time())>86400) {
-      $this->shadowExpire= $this->convertToSeconds($this->shadowExpire);
-    }
-
     /* Only enable checkbox, if shadowExpire is in the future */
     if($this->shadowExpire > time()) {
       $this->activate_shadowExpire= "1";
     }
+
+    /* Convert shadowExpire for usage */
+    if ($this->shadowExpire == 0){
+      $this->shadowExpire= "";
+    } else {
+      $this->shadowExpire= date('d.m.Y', $this->shadowExpire * 60 * 60 * 24);
+    }
   }
 
   function convertToSeconds($val)
@@ -1269,7 +1325,12 @@ class posixAccount extends plugin
         }
     }
 
-
+    /* Convert shadowExpire for usage */
+    if ($this->shadowExpire == 0){
+      $this->shadowExpire= "";
+    } else {
+      $this->shadowExpire= date('d.m.Y', $this->shadowExpire * 60 * 60 * 24);
+    }
 
     $tmp = new trustModeDialog($this->config, $source['dn']);
     $this->trustModeDialog = new trustModeDialog($this->config, $this->dn);
@@ -1332,17 +1393,17 @@ class posixAccount extends plugin
     $ret['groupMembership']     = $this->groupMembership;
     $ret['groupMembership_some']= $this->groupMembership_some;
 
-    if(in_array("primaryGroup",$this->multi_boxes)){
+    if(in_array_strict("primaryGroup",$this->multi_boxes)){
       $ret['primaryGroup'] = $this->primaryGroup;
     }
     foreach(array("shadowWarning","shadowInactive","shadowMin","shadowMax", "shadowExpire") as $entry){
       $active = "activate_".$entry;
-      if(in_array($active,$this->multi_boxes)){
+      if(in_array_strict($active,$this->multi_boxes)){
         $ret[$entry] = $this->$entry;
         $ret[$active] = $this->$active;
       }
     }
-    if(in_array("mustchangepassword",$this->multi_boxes)){
+    if(in_array_strict("mustchangepassword",$this->multi_boxes)){
       $ret['mustchangepassword'] = $this->mustchangepassword;
     }
     return($ret);
@@ -1374,7 +1435,7 @@ class posixAccount extends plugin
       foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning") as $var) {
         if($this->acl_is_writeable($var)){
           $activate_var = "activate_".$var;
-          if(in_array($activate_var, $this->multi_boxes)){
+          if(in_array_strict($activate_var, $this->multi_boxes)){
             if(isset($_POST['activate_'.$var])){
               $this->$activate_var  = true;
               $this->$var      = get_post($var);
@@ -1387,7 +1448,7 @@ class posixAccount extends plugin
       }
 
       /* Restore shadow value, if the shadow attribute isn't used */
-      if(!in_array("activate_shadowExpire",$this->multi_boxes)){
+      if(!in_array_strict("activate_shadowExpire",$this->multi_boxes)){
         $this->shadowExpire = $expire_tmp;
       }
 
@@ -1417,6 +1478,9 @@ class posixAccount extends plugin
     plugin::init_multiple_support($attrs,$all);
     $this->trustModeDialog->init_multiple_support($attrs,$all);
 
+    // set header for multiple support
+    $this->groupList->setHeader(array(_("~"), _("Group"), _("Description"), _("Members")));
+
     /* Some dummy values */
     $groups_some = array();
     $groups_all  = array();
@@ -1424,6 +1488,8 @@ class posixAccount extends plugin
     $uids        = array();
     $first       = TRUE;
 
+    $groupImage = image('plugins/groups/images/select_group.png');
+
     /* Get all groups used by currently edited users */
     $uid_filter="";  
     for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){
@@ -1434,9 +1500,18 @@ class posixAccount extends plugin
     $uid_filter = "(&(objectClass=posixGroup)(|".$uid_filter."))";
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search($uid_filter,array("dn","cn","memberUid"));
+    $ldap->search($uid_filter,array("dn","cn","memberUid","description"));
     while($group = $ldap->fetch()){
       $groups_some[$group['dn']] = $group['cn'][0];
+
+      $desc = "&nbsp;";
+      if(isset($group['description'])) $desc = $group['description'][0];
+
+      $this->groupListData[$group['dn']] = array($groupImage,
+        $group['cn'][0],
+        $desc,
+        _("some"));
       for($i = 0 ; $i < $group['memberUid']['count'] ; $i++){
         $groups_uid[$group['dn']][] = $group['memberUid'][$i];
       }
@@ -1446,7 +1521,7 @@ class posixAccount extends plugin
     $groups_all = $groups_some;
     foreach($groups_all as $id => $group){
       foreach($uids as $uid){
-        if(!in_array($uid,$groups_uid[$id])){
+        if(!in_array_strict($uid,$groups_uid[$id])){
           unset($groups_all[$id]);
           break;
         }
@@ -1457,11 +1532,13 @@ class posixAccount extends plugin
     $this->groupMembership = $groups_all;
 
     /* Create an array of all grouops used by all users */
-    foreach( $groups_all as $dn => $cn){
-      if(isset($groups_some[$dn])){
+    foreach($groups_all as $dn => $cn) {
+      if(isset($groups_some[$dn])) {
         unset($groups_some[$dn]);
+        $this->groupListData[$dn][3] = _("all");
       }
     }
+
     $this->groupMembership_some = $groups_some;
     $this->primaryGroup = $this->gidNumber;