Code

Updated lsit summary, replaced text with images
[gosa.git] / plugins / admin / users / class_divListUsers.inc
index 55efed9eed4225a3b6ec9d7412eaafc0c89f0f5c..b1d5d201ee34d74f7f76b6531be681bc1999395e 100644 (file)
@@ -26,7 +26,7 @@ class divListUsers extends MultiSelectWindow
 
   function divListUsers ($config,$parent)
   {
-    MultiSelectWindow::MultiSelectWindow($config,"Users");
+    MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
     
     $this->parent       = $parent;
     $this->ui           = get_userinfo();
@@ -45,11 +45,22 @@ class divListUsers extends MultiSelectWindow
     $this->EnableCloseButton(false);
     $this->EnableSaveButton (false);
 
+    /* Dynamic action col, depending on snapshot icons */
+    $action_col_size = 104;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 38;
+    }
+
+    /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all' 
+               onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
     /* set Page header */
-    $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
+    $this->AddHeader(array("string"=> "&nbsp;",          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
-    $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:152px;'"));
-    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:132px;border-right:0px;text-align:right;'"));
+    $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
+    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
     
     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
@@ -60,31 +71,12 @@ class divListUsers extends MultiSelectWindow
 
     /* Add SubSearch checkbox */
     $this->AddCheckBox(SEPERATOR);
-    $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
+    $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
 
     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
   }
 
-  function GetSnapShotActions($dn)
-  {
-    $str = "";
-
-    if($this->parent->snapshotEnabled()){
-
-      $str .="<input class='center' type='image' src='images/snapshot.png'
-        alt='"._("Create snapshot")."' name='CreateSnapShot_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'>&nbsp;";
-
-      if(count($this->parent->Available_SnapsShots($dn))){
-        $str .="<input class='center' type='image' src='images/restore.png'
-          alt='"._("Restore snapshot")."' name='RestoreSnapShot_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
-      }else{
-        $str.= "<img src='images/empty.png' style='width:16px;' class='center'>&nbsp;";
-      }
-    }
-    return($str);
-  }
-
 
   function GenHeader()
   {
@@ -92,50 +84,99 @@ class divListUsers extends MultiSelectWindow
        which are shown in the listbox on top of the listbox
      */
     $options= "";
-    foreach ($this->config->idepartments as $key => $value){
-      if ($this->selectedBase == $key){
-        $options.= "<option selected='selected' value='$key'>$value</option>";
-      } else {
-        $options.= "<option value='$key'>$value</option>";
+
+    /* Get all departments within this subtree */ 
+    $base = $this->config->current['BASE'];
+
+    /* Add base */
+    $tmp = array();
+    $tmp[] = array("dn"=>$this->config->current['BASE']);
+    $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
+    
+    $deps = array();
+    foreach($tmp as $tm){
+      $deps[$tm['dn']] = $tm['dn'];
+    }    
+
+
+    /* Load possible departments */
+    $ui= get_userinfo();
+    $tdeps= $ui->get_module_departments("users");
+    $ids = $this->config->idepartments;
+    $first = "";
+    $found = FALSE;
+    foreach($ids as $dep => $name){
+      if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
+
+        /* Keep first base dn in mind, we could need this
+         *  info if no valid base was found
+         */
+        if(empty($first)) {
+          $first = $dep['dn'];
+        }
+
+        $value = $ids[$dep]; 
+        if ($this->selectedBase == $dep){
+          $found = TRUE;
+          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+        } else {
+          $options.= "<option value='".$dep."'>$value</option>";
+        }
       }
     }
 
-    /* Get copy & paste icon */ 
-    if($this->parent->CopyPasteHandler){
+    /* The currently used base is not visible with your acl setup.
+     * Set base to first useable base. 
+     */
+    if(!$found){
+      $this->selectedBase = $first;
+    }
+
+    /* Get copy & paste icon */
+    $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
+    $acl      = $ui->get_permissions($this->selectedBase,"users/user");
+    if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
     }else{
       $Copy_Paste ="";
     }
 
-    /* Create header with selected base */
-    $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
-      " <input class='center' type='image' src='images/list_root.png' align='middle' 
-      title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_back.png' 
-      title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_home.png' 
-      title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
-      " <input class='center' type='image' src='images/list_reload.png' align='middle' 
-      title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
-      " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+    /* Add default header */
+    $listhead = MultiSelectWindow::get_default_header();
+    
+    if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
+      $listhead .= $this->get_snapshot_header($this->selectedBase);
+    }
 
-    if($this->parent->snapshotEnabled()){
-      $listhead .= "  <input class='center' type='image' align='middle' src='images/restore.png'
-        title='"._("Restore snapshopts of already deleted objects")."' alt='"._("Restore")."' name='RestoreDeletedSnapShot'>".
-        " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
+    if(preg_match("/c/",$acl)) {
+      $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
+        title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;";
+      $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png' 
+        title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;";
     }
 
-    $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
-      title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
-      " <input class='center' type='image' align='middle' src='images/list_new.png' 
-      title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
-      $Copy_Paste.
-      " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
+    $listhead .= $Copy_Paste;
+    
+    $listhead .=
       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
-      title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
-      "</div>";
+      title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
 
+  
+    /* Multiple options */ 
+    $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
+        title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
+
+    /* Add multiple copy & cut icons */
+    if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
+      $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
+        title='"._("Copy selected user")."' alt='"._("Copy users")."' name='multiple_copy_users'>&nbsp;";
+      $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
+        title='"._("cut selected user")."' alt='"._("Cut users")."' name='multiple_cut_users'>&nbsp;";
+    }
+
+    $listhead .="</div>";;
     $this->SetListHeader($listhead);
   }
 
@@ -151,14 +192,23 @@ class divListUsers extends MultiSelectWindow
     /********************
       Variable init
      ********************/
+    
+    $num_users      = 0;
+    $num_templates  = 0;
 
     /* Variable initialation */
     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
-    $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
+    $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
+    /* Dynamic action col, depending on snapshot icons */
+    $action_col_size = 104;
+    if($this->parent->snapshotEnabled()){
+      $action_col_size += 38;
+    }
+
     /* Possilbe objectClass image combinations */  
     $possibleAccounts = array(
             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
@@ -192,56 +242,57 @@ class divListUsers extends MultiSelectWindow
       END :: Variable init
      ********************/
 
-    /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
-     * Read Sip Table for specified account (for each user with phoneAccount).
-     * Check the attributes ip port and regseconds.
-     * If regseconds is set and >0 , the phone is logged in.
-     * Else the phone is currently not logged.
-     * If we can't read any Data from the DB or there is no goFon DB specified
-     * show old style without status icons.
-     */
-    $r_db   =false;
-    $r_con  =false;
-    if (isset($_SESSION['config']->data['SERVERS']['FON'])){
-      $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
-      $r_con = false;
-      $r_db  = false;
-      if(is_callable("mysql_pconnect")){
-        $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
-        // Check if we are  connected correctly
-        if($r_con){
-          $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
-        }
-      }
-    }
-   
  
     /********************
       Append entries to divlist 
      ********************/
  
+    $ui = get_userinfo(); 
+  
     // Test Every Entry and generate divlist Array
     foreach($list as $key => $val){
 
       /* Create action icons */
-      $action = $this->GetSnapShotActions($val['dn']);
-      if($this->parent->CopyPasteHandler){
+      $action= "";
+
+      /* Add copy & cut icons */     
+      $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
+      $acl      = $ui->get_permissions($val['dn'],"users/user");
+      if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
         $action .= "<input class='center' type='image'
           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
         $action.= "<input class='center' type='image'
           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
       }
+
+      /* Generate edit icon */
       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
         name='user_edit_%KEY%' title='"._("Edit user")."'>";
-      $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
-        name='user_chgpw_%KEY%' title='"._("Change password")."'>";
-      $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
-        name='user_del_%KEY%' title='"._("Delete user")."'>";
 
+      /* Add Password change icon, if we are able to write users/password */
+      if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
+        $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
+          name='user_chgpw_%KEY%' title='"._("Change password")."'>";
+      }else{
+        $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
+          title='"._("You are not allowed to change the password for this user.")."'>";
+      }
+
+      /* Add snapshot icon */
+      if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+        $action.= $this->GetSnapShotActions($val['dn']);
+      }
+
+      /* Add remove icon, if we are allowed to remove the current user */
+      if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
+        $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
+          name='user_del_%KEY%' title='"._("Delete user")."'>";
+      }else{
+        $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
+          title='"._("You are not allowed to remove this user.")."'>";
+      }
 
       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
-      $connected  = ""; // This string represents timestamp or offline status
-      $ip_port    = ""; // String that will represent ip : port of the connected phone
       if((in_array("goFonAccount"    ,$val['objectClass']))){
 
         /* Set defaults */
@@ -249,26 +300,6 @@ class divListUsers extends MultiSelectWindow
         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
         $fonac = preg_replace("/%title%/", "", $fonac);
 
-        /* Database connection is ok ?*/
-        if(($r_db)&&(is_callable("mysql_query"))){
-          $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
-          $mysql_entry = @mysql_fetch_row($res);
-          if(is_array($mysql_entry)){
-            if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
-              $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
-              $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
-              $fonac = preg_replace("/%KEY%/", "$key", $fonac);
-              $fonac = preg_replace("/%title%/", $connected, $fonac);
-              $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
-            }
-            if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
-              $connected = " | "._("Offline");
-              $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
-              $fonac = preg_replace("/%KEY%/", "$key", $fonac);
-              $fonac = preg_replace("/%title%/", $connected, $fonac);
-            }
-          }
-        }
       }else{
         $fonac=$empty;
       }
@@ -286,9 +317,11 @@ class divListUsers extends MultiSelectWindow
       if(in_array("gosaUserTemplate",$val['objectClass'])){
         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
+        $num_templates ++;
       }else{
         $s_img_create_from_template   = "";
         $tpl                          = $userimg;
+        $num_users ++;
       }
 
       /* Insert key into userimg */
@@ -302,16 +335,28 @@ class divListUsers extends MultiSelectWindow
       }
 
       /* Connect all images */
-      $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp".$netatalk;
+      $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
+
+      /* Cutted objects should be displayed in light grey */ 
+      if($this->parent->CopyPasteHandler){
+        foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
+          if($queue_data['dn'] == $val['dn']) {
+            $display = "<font color='#999999'>".$display."</font>";
+            break;
+          }
+        }
+      }
 
       /* Create each field */
+      $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+                      "attach" => "style='width:20px;'");
       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
-      $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
-      $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
+      $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
+      $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
-                      "attach" => "style='width:132px;border-right:0px;    text-align:right;'");
+                      "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
       /* Add to list */
-      $add = array($field1,$field2,$field3,$field4);
+      $add = array($field0,$field1,$field2,$field3,$field4);
       $this->AddElement($add);
 
       // Template or User
@@ -321,14 +366,24 @@ class divListUsers extends MultiSelectWindow
         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
       }
     }
-    
-    /* close database connection, if it was opened */
-    if(isset($r_con)){
-      if((is_callable("mysql_close"))&&($r_con)){
-        @mysql_close($r_con);
-      }
+
+
+    /* Create summary string for list footer */
+    $num_deps=0;
+    if(!$this->SubSearch){
+      $num_deps = count($this->Added_Departments);
     }
+    $num_users = count($list);
+
+    $num_user_str = _("Number of listed users");
+    $num_dep_str = _("Number of listed departments");
+
+    $str = "<img class='center' src='images/select_user.png'
+              title='".$num_user_str."' alt='".$num_user_str."'>&nbsp;".$num_users."&nbsp;&nbsp;&nbsp;&nbsp;";
+    $str.= "<img class='center' src='images/folder.png'
+              title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
 
+    $this->set_List_Bottom_Info($str);
   }
 
   function Save()