Code

Updated lsit summary, replaced text with images
[gosa.git] / plugins / admin / users / class_divListUsers.inc
index 0dec827bd6320b24f2bcda89404b1421d1db2674..b1d5d201ee34d74f7f76b6531be681bc1999395e 100644 (file)
@@ -51,10 +51,15 @@ class divListUsers extends MultiSelectWindow
       $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"=>_("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);
@@ -66,7 +71,7 @@ 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);
@@ -82,49 +87,65 @@ class divListUsers extends MultiSelectWindow
 
     /* Get all departments within this subtree */ 
     $base = $this->config->current['BASE'];
-    $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
-                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    /* 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;
-    foreach($deps as $dep){
-      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
+    $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['dn']]; 
-        if ($this->selectedBase == $dep['dn']){
-          $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
+        $value = $ids[$dep]; 
+        if ($this->selectedBase == $dep){
+          $found = TRUE;
+          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
         } else {
-          $options.= "<option value='".$dep['dn']."'>$value</option>";
+          $options.= "<option value='".$dep."'>$value</option>";
         }
       }
     }
 
-    /* Get copy & paste icon */ 
-    $acl = $ui->get_permissions($this->selectedBase,"users/user");
-    if(preg_match("/(c.*w|w.*c)/",$acl) &&  $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)){ 
+    if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
       $listhead .= $this->get_snapshot_header($this->selectedBase);
     }
 
@@ -140,9 +161,22 @@ class divListUsers extends MultiSelectWindow
     $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);
   }
 
@@ -158,6 +192,9 @@ class divListUsers extends MultiSelectWindow
     /********************
       Variable init
      ********************/
+    
+    $num_users      = 0;
+    $num_templates  = 0;
 
     /* Variable initialation */
     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
@@ -205,29 +242,6 @@ 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 
@@ -242,9 +256,9 @@ class divListUsers extends MultiSelectWindow
       $action= "";
 
       /* Add copy & cut icons */     
-
-      $acl = $ui->get_permissions($val['dn'],"users/user");
-      if(preg_match("/(c.*w|w.*c)/",$acl) && $this->parent->CopyPasteHandler){
+      $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'
@@ -265,7 +279,7 @@ class divListUsers extends MultiSelectWindow
       }
 
       /* Add snapshot icon */
-      if(preg_match("/(c.*w|w.*c)/",$acl)){
+      if(preg_match("/(c.*w|w.*c)/",$acl_all)){
         $action.= $this->GetSnapShotActions($val['dn']);
       }
 
@@ -279,8 +293,6 @@ class divListUsers extends MultiSelectWindow
       }
 
       /* 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 */
@@ -288,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;
       }
@@ -325,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 */
@@ -343,14 +337,26 @@ class divListUsers extends MultiSelectWindow
       /* Connect all images */
       $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:".$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
@@ -360,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()