1
/****************************************************************************
3
| Copyright (c) [2007] Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Mike Lasky (mlasky@novell.com)
22
|***************************************************************************/
26
using System.Collections;
27
using System.ComponentModel;
30
using System.Resources;
32
using System.Web.SessionState;
33
using System.Web.Services.Protocols;
35
using System.Web.UI.WebControls;
36
using System.Web.UI.HtmlControls;
38
namespace Novell.iFolderWeb.Admin
41
/// Summary description for iFolders.
43
public class iFolders : System.Web.UI.Page
48
/// iFolder list data grid column indices.
50
private const int iFolderIDColumn = 0;
51
private const int iFolderDisabledColumn = 1;
52
private const int iFolderCheckColumn = 2;
53
private const int iFolderTypeColumn = 3;
54
private const int iFolderNameColumn = 4;
55
private const int iFolderOwnerColumn = 5;
56
private const int iFolderSizeMemberCountColumn = 6;
57
private const int iFolderLastModifiedColumn = 7;
60
/// iFolder list display types.
62
private enum ListDisplayType
70
/// iFolder Connection
72
private iFolderAdmin web;
77
private ResourceManager rm;
81
/// Top navigation panel control.
83
protected TopNavigation TopNav;
87
/// Control that checks or unchecks all of the ifolders in the current view.
89
protected CheckBox AlliFoldersCheckBox;
93
/// iFolder list controls.
95
protected DataGrid iFolderList;
98
/// iFolder list footer control.
100
protected ListFooter iFolderListFooter;
106
protected iFolderSearch iFolderSearch;
110
/// Delete ifolder button control.
112
protected Button DeleteButton;
115
/// Disable ifolder button control.
117
protected Button DisableButton;
120
/// Enable ifolder button control.
122
protected Button EnableButton;
125
/// Create ifolder button control.
127
protected Button CreateButton;
130
/// iFolder list view tab controls.
132
protected LinkButton AlliFoldersLink;
135
/// iFolder list view tab controls.
137
protected LinkButton OrphanediFoldersLink;
140
/// iFolder list view tab controls.
142
protected HtmlGenericControl CurrentTab;
149
/// Gets or sets the ifolders that are checked in the list.
151
private Hashtable CheckediFolders
153
get { return ViewState[ "CheckediFolders" ] as Hashtable; }
154
set { ViewState[ "CheckediFolders" ] = value; }
158
/// Gets or sets the active ifolder tab.
160
private ListDisplayType ActiveiFolderTab
162
get { return ( ListDisplayType )ViewState[ "ActiveTab" ]; }
163
set { ViewState[ "ActiveTab" ] = value; }
167
/// Gets or sets the current iFolder offset.
169
private int CurrentiFolderOffset
171
get { return ( int )ViewState[ "CurrentiFolderOffset" ]; }
172
set { ViewState[ "CurrentiFolderOffset" ] = value; }
176
/// Gets or sets the total number of iFolders contained in
179
private int TotaliFolders
181
get { return ( int )ViewState[ "TotaliFolders" ]; }
182
set { ViewState[ "TotaliFolders" ] = value; }
187
#region Private Methods
190
/// Builds the breadcrumb list for this page.
192
private void BuildBreadCrumbList()
194
TopNav.AddBreadCrumb( GetString( "IFOLDERS" ), null );
195
// Pass this page information to create the help link
196
TopNav.AddHelpLink(GetString("IFOLDERS"));
200
/// Creates a list of iFolders where the user is a member.
202
/// <returns>A DataView object containing the iFolder list.</returns>
203
private DataView CreateiFolderList()
205
DataTable dt = new DataTable();
208
dt.Columns.Add( new DataColumn( "VisibleField", typeof( bool ) ) );
209
dt.Columns.Add( new DataColumn( "IDField", typeof( string ) ) );
210
dt.Columns.Add( new DataColumn( "OwnerIDField", typeof( string ) ) );
211
dt.Columns.Add( new DataColumn( "SharedField", typeof( bool ) ) );
212
dt.Columns.Add( new DataColumn( "DisabledField", typeof( bool ) ) );
213
dt.Columns.Add( new DataColumn( "EncryptedField", typeof( bool ) ) );
214
dt.Columns.Add( new DataColumn( "NameField", typeof( string ) ) );
215
dt.Columns.Add( new DataColumn( "OwnerNameField", typeof( string ) ) );
216
dt.Columns.Add( new DataColumn( "MemberCountField", typeof( string ) ) );
217
dt.Columns.Add( new DataColumn( "LastModifiedField", typeof( string ) ) );
218
dt.Columns.Add( new DataColumn( "SizeField", typeof( string ) ) );
220
// Get the iFolder list for this user.
224
switch(ActiveiFolderTab)
226
case ListDisplayType.Orphaned:
227
list = web.GetOrphanediFolders(iFolderSearch.SearchOperation,
228
( iFolderSearch.SearchName == String.Empty) ? "*" : iFolderSearch.SearchName,
229
CurrentiFolderOffset,
230
iFolderList.PageSize);
233
case ListDisplayType.All:
235
list = web.GetiFoldersByName(iFolderSearch.SearchOperation,
236
( iFolderSearch.SearchName == String.Empty) ? "*" : iFolderSearch.SearchName,
237
CurrentiFolderOffset,iFolderList.PageSize);
242
foreach( iFolder folder in list.Items )
244
bool encrypted = false;
246
iFolder ifolder = web.GetiFolder(folder.ID);
247
string EncryptionAlgorithm = ifolder.EncryptionAlgorithm;
248
if(!(EncryptionAlgorithm == null || (EncryptionAlgorithm == String.Empty)))
250
// It is an encrypted ifolder
257
dr[ 2 ] = folder.OwnerID;
258
dr[ 3 ] = ( folder.MemberCount > 1 ) ? true : false;
259
dr[ 4 ] = !folder.Enabled;
260
dr[ 5 ] = ( encrypted ) ? true : false;
261
dr[ 6 ] = folder.Name;
262
dr[ 7 ] = folder.OwnerFullName;
263
dr[ 8 ] = folder.MemberCount.ToString();
264
dr[ 9 ] = Utils.ToDateTimeString( "d", folder.LastModified );
269
// If the page size is not full, finish it with empty entries.
270
for ( int i = dt.Rows.Count; i < iFolderList.PageSize; ++i )
274
dr[ 1 ] = String.Empty;
275
dr[ 2 ] = String.Empty;
279
dr[ 6 ] = String.Empty;
280
dr[ 7 ] = String.Empty;
281
dr[ 8 ] = String.Empty;
282
dr[ 9 ] = String.Empty;
287
// Remember the total number of users.
288
TotaliFolders = list.Total;
290
// Build the data view from the table.
291
return new DataView( dt );
295
/// Gets the iFolders for the current user.
297
private void GetiFolders()
299
// Create a data source containing the iFolders.
300
iFolderList.DataSource = CreateiFolderList();
301
iFolderList.DataBind();
302
SetPageButtonState();
308
/// <param name="sender"></param>
309
/// <param name="e"></param>
310
private void Page_Load( object sender, System.EventArgs e )
313
web = Session[ "Connection" ] as iFolderAdmin;
316
rm = Application[ "RM" ] as ResourceManager;
320
// Initialize the localized fields.
321
DeleteButton.Text = GetString( "DELETE" );
322
DisableButton.Text = GetString( "DISABLE" );
323
EnableButton.Text = GetString( "ENABLE" );
324
CreateButton.Text = GetString( "CREATE" );
326
AlliFoldersLink.Text = GetString( "ALL" );
327
OrphanediFoldersLink.Text = GetString( "ORPHANED" );
329
// Initialize state variables.
330
CurrentiFolderOffset = 0;
332
AlliFoldersCheckBox.Checked = false;
333
CheckediFolders = new Hashtable();
335
//Set the active ifolder tab
336
ActiveiFolderTab = ListDisplayType.All;
339
// Set the active ifolder display tab
340
SetActiveiFolderListTab( ActiveiFolderTab );
346
/// <param name="sender"></param>
347
/// <param name="e"></param>
348
private void Page_PreRender(object sender, EventArgs e)
350
BuildBreadCrumbList();
355
/// Enables or disables the ifolder action buttons.
357
private void SetActionButtons()
359
Hashtable ht = CheckediFolders;
360
DeleteButton.Enabled = ( ht.Count > 0 ) ? true : false;
361
DisableButton.Enabled = ht.ContainsValue( Boolean.FalseString );
362
EnableButton.Enabled = ht.ContainsValue( Boolean.TrueString );
366
/// Sets the active ifolder list display tab.
368
/// <param name="activeTab"></param>
369
/// <returns>The active list tab.</returns>
370
private void SetActiveiFolderListTab( ListDisplayType activeTab )
372
ActiveiFolderTab = activeTab;
373
CurrentTab.ID = activeTab.ToString();
377
/// Sets the page button state of the ifolder list.
379
private void SetPageButtonState()
381
iFolderListFooter.SetPageButtonState(
383
CurrentiFolderOffset,
385
GetString( "IFOLDERS" ),
386
GetString( "IFOLDER" ) );
390
/// Sets the ifolder synchronization status on all selected ifolders.
392
/// <param name="syncStatus">If true then all selected ifolders will be enabled.</param>
393
private void SetSelectediFolderStatus( bool syncStatus )
395
foreach( string ifolderID in CheckediFolders.Keys )
397
// Don't set the status if already set.
398
if ( CheckediFolders[ ifolderID ] as string != syncStatus.ToString() )
400
iFolderPolicy policy = Utils.GetiFolderPolicyObject( ifolderID );
401
policy.Locked = syncStatus;
404
web.SetiFolderPolicy( policy );
406
catch ( Exception ex )
408
TopNav.ShowError( GetString( "ERRORCANNOTSETIFOLDERSTATUS" ), ex );
414
// Clear the checked members.
415
CheckediFolders.Clear();
416
AlliFoldersCheckBox.Checked = false;
418
// Set the action buttons.
421
// Rebind the data source with the new data.
427
#region Protected Methods
430
/// Event handler that gets called when the all ifolders tab is clicked.
432
/// <param name="sender"></param>
433
/// <param name="e"></param>
434
protected void AlliFolders_Clicked( Object sender, EventArgs e )
436
SetActiveiFolderListTab( ListDisplayType.All );
437
CreateButton.Enabled = true;
443
/// Event handler that gets called when the orphaned ifolders tab is clicked.
445
/// <param name="sender"></param>
446
/// <param name="e"></param>
447
protected void OrphanediFolders_Clicked( Object sender, EventArgs e )
449
SetActiveiFolderListTab( ListDisplayType.Orphaned );
450
CreateButton.Enabled = false;
455
/// Gets the image representing the iFolder type.
457
/// <param name="disabled"></param>
458
/// <param name="shared"></param>
459
/// <returns></returns>
460
protected string GetiFolderImage( object disabled, object shared , object encrypted)
463
return "images/ifolder_16-gray.gif";
464
else if( (bool) encrypted)
465
return "images/encrypt_ilock2_16.gif";
467
return ( bool )shared ? "images/ifolder_user_16.gif" : "images/ifolder.png";
471
/// Returns the checked state for the specified member.
473
/// <param name="id">ID of the ifolder</param>
474
/// <returns>True if ifolder is checked.</returns>
475
protected bool GetMemberCheckedState( Object id )
477
return CheckediFolders.ContainsKey( id ) ? true : false;
481
/// Gets the navigation url for the owner of the ifolder if the owner
482
/// is not the current user.
484
/// <param name="ownerID">The ID of the owner of the ifolder.</param>
485
/// <returns>The URL to navigate to the owner of the ifolder.</returns>
486
protected string GetOwnerUrl( Object ownerID )
488
return String.Format( "UserDetails.aspx?id={0}", ownerID );
492
/// Get a Localized String
494
/// <param name="key"></param>
495
/// <returns></returns>
496
protected string GetString( string key )
498
return rm.GetString( key );
502
/// Event handler that gets called when the check all iFolders checkbox is selected.
504
/// <param name="source"></param>
505
/// <param name="e"></param>
506
protected void OnAlliFoldersChecked( object source, EventArgs e )
508
CheckBox checkBox = source as CheckBox;
509
foreach( DataGridItem item in iFolderList.Items )
511
// In order to be checked, the row must not be empty.
512
string ifolderID = item.Cells[ 0 ].Text;
513
if ( ifolderID != " " )
515
if ( checkBox.Checked )
517
CheckediFolders[ ifolderID ] = item.Cells[ iFolderDisabledColumn ].Text;
521
// Remove this ifolder the list.
522
CheckediFolders.Remove( ifolderID );
527
// Set the action buttons appropriately.
530
// Rebind the data source with the new data.
535
/// Event handler that gets called with the create ifolder button is clicked.
537
/// <param name="source"></param>
538
/// <param name="e"></param>
539
protected void OnCreateButton_Click( object source, EventArgs e )
541
Page.Response.Redirect( "CreateiFolder.aspx", true );
545
/// Event handler that gets called with the delete ifolder button is clicked.
547
/// <param name="source"></param>
548
/// <param name="e"></param>
549
protected void OnDeleteButton_Click( object source, EventArgs e )
551
foreach( string ifolderID in CheckediFolders.Keys )
555
web.DeleteiFolder( ifolderID );
557
catch ( Exception ex )
559
TopNav.ShowError( GetString( "ERRORCANNOTDELETEIFOLDER" ), ex );
564
// Clear the checked members.
565
CheckediFolders.Clear();
566
AlliFoldersCheckBox.Checked = false;
568
// Set the action buttons.
571
// Rebind the data source with the new data.
576
/// Event handler that gets called with the disable ifolder button is clicked.
578
/// <param name="source"></param>
579
/// <param name="e"></param>
580
protected void OnDisableButton_Click( object source, EventArgs e )
582
SetSelectediFolderStatus( true );
586
/// Event handler that gets called with the enable ifolder button is clicked.
588
/// <param name="source"></param>
589
/// <param name="e"></param>
590
protected void OnEnableButton_Click( object source, EventArgs e )
592
SetSelectediFolderStatus( false );
596
/// Event handler that gets called when an ifolder is checked.
598
/// <param name="source"></param>
599
/// <param name="e"></param>
600
protected void OniFolderChecked( object source, EventArgs e )
602
// Get the data grid row for this member.
603
CheckBox checkBox = source as CheckBox;
604
DataGridItem item = checkBox.Parent.Parent as DataGridItem;
605
string ifolderID = item.Cells[ iFolderIDColumn ].Text;
606
if ( ifolderID != " " )
608
// iFolder is being added.
609
if ( checkBox.Checked )
611
CheckediFolders[ ifolderID ] = item.Cells[ iFolderDisabledColumn ].Text;
615
// Remove this ifolder from the list.
616
CheckediFolders.Remove( ifolderID );
620
// Set the ifolder action buttons.
625
/// Event handler that gets called when the ifolder search button is clicked.
627
/// <param name="source"></param>
628
/// <param name="e"></param>
629
protected void OnSearchButton_Click( object source, EventArgs e )
631
// Always search from the beginning.
632
CurrentiFolderOffset = 0;
637
/// Event that first when the PageFirstButton is clicked.
639
/// <param name="source"></param>
640
/// <param name="e"></param>
641
protected void PageFirstButton_Click( object source, ImageClickEventArgs e)
643
// Set to get the first ifolders.
644
CurrentiFolderOffset = 0;
649
/// Event that first when the PagePreviousButton is clicked.
651
/// <param name="source"></param>
652
/// <param name="e"></param>
653
protected void PagePreviousButton_Click( object source, ImageClickEventArgs e)
655
CurrentiFolderOffset -= iFolderList.PageSize;
656
if ( CurrentiFolderOffset < 0 )
658
CurrentiFolderOffset = 0;
661
// Rebind the data source with the new data.
666
/// Event that first when the PageNextButton is clicked.
668
/// <param name="source"></param>
669
/// <param name="e"></param>
670
protected void PageNextButton_Click( object source, ImageClickEventArgs e)
672
CurrentiFolderOffset += iFolderList.PageSize;
674
// Rebind the data source with the new data.
679
/// Event that first when the PageLastButton is clicked.
681
/// <param name="source"></param>
682
/// <param name="e"></param>
683
protected void PageLastButton_Click( object source, ImageClickEventArgs e)
685
CurrentiFolderOffset = ( ( TotaliFolders - 1 ) / iFolderList.PageSize ) * iFolderList.PageSize;
687
// Rebind the data source with the new data.
693
#region Web Form Designer generated code
698
/// <param name="e"></param>
699
override protected void OnInit(EventArgs e)
702
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
704
InitializeComponent();
709
/// Required method for Designer support - do not modify
710
/// the contents of this method with the code editor.
712
private void InitializeComponent()
714
if ( !Page.IsPostBack )
716
// Set the render event to happen only on page load.
717
Page.PreRender += new EventHandler( Page_PreRender );
720
iFolderListFooter.PageFirstClick += new ImageClickEventHandler( PageFirstButton_Click );
721
iFolderListFooter.PagePreviousClick += new ImageClickEventHandler( PagePreviousButton_Click );
722
iFolderListFooter.PageNextClick += new ImageClickEventHandler( PageNextButton_Click );
723
iFolderListFooter.PageLastClick += new ImageClickEventHandler( PageLastButton_Click );
725
iFolderSearch.Click += new System.EventHandler( OnSearchButton_Click );
726
this.Load += new System.EventHandler(this.Page_Load);