~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/admin/.svn/text-base/TopNavigation.ascx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) [2007] Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
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.
9
 
 |
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.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 
21
 
 | Author: Mike Lasky (mlasky@novell.com)
22
 
 |***************************************************************************/
23
 
 
24
 
 
25
 
 
26
 
namespace Novell.iFolderWeb.Admin
27
 
{
28
 
        using System;
29
 
        using System.Collections;
30
 
        using System.Data;
31
 
        using System.Drawing;
32
 
        using System.Net;
33
 
        using System.Resources;
34
 
        using System.Web;
35
 
        using System.Web.Services.Protocols;
36
 
        using System.Web.UI;
37
 
        using System.Web.UI.WebControls;
38
 
        using System.Web.UI.HtmlControls;
39
 
        using System.Xml;
40
 
 
41
 
        /// <summary>
42
 
        ///Summary description for TopNavigation.
43
 
        /// </summary>
44
 
        public class TopNavigation : System.Web.UI.UserControl
45
 
        {
46
 
                #region Class Members
47
 
 
48
 
                /// <summary>
49
 
                /// Enumeration of page tabs.
50
 
                /// </summary>
51
 
                public enum PageTabs
52
 
                {
53
 
                        /// <summary>
54
 
                        /// User tab
55
 
                        /// </summary>
56
 
                        Users,
57
 
 
58
 
                        /// <summary>
59
 
                        /// iFolders tab
60
 
                        /// </summary>
61
 
                        iFolders,
62
 
 
63
 
                        /// <summary>
64
 
                        /// System tab
65
 
                        /// </summary>
66
 
                        System,
67
 
 
68
 
                        /// <summary>
69
 
                        /// Servers tab
70
 
                        /// </summary>
71
 
                        Servers,
72
 
 
73
 
                        /// <summary>
74
 
                        /// Reports tab
75
 
                        /// </summary>
76
 
                        Reports
77
 
                }
78
 
 
79
 
                /// <summary>
80
 
                /// Resource Manager
81
 
                /// </summary>
82
 
                private ResourceManager rm;
83
 
 
84
 
 
85
 
                /// <summary>
86
 
                /// Anchor controls.
87
 
                /// </summary>
88
 
                protected HtmlAnchor UserLink;
89
 
 
90
 
                /// <summary>
91
 
                /// Anchor controls.
92
 
                /// </summary>
93
 
                protected HtmlAnchor iFolderLink;
94
 
 
95
 
                /// <summary>
96
 
                /// Anchor controls.
97
 
                /// </summary>
98
 
                protected HtmlAnchor ServerLink;
99
 
 
100
 
                /// <summary>
101
 
                /// Anchor controls.
102
 
                /// </summary>
103
 
                protected HtmlAnchor SystemLink;
104
 
 
105
 
                /// <summary>
106
 
                /// Anchor controls.
107
 
                /// </summary>
108
 
                protected HtmlAnchor ReportsLink;
109
 
 
110
 
 
111
 
                /// <summary>
112
 
                /// Error panel control.
113
 
                /// </summary>
114
 
                protected HtmlGenericControl ErrorPanel;
115
 
 
116
 
                /// <summary>
117
 
                /// Error message control.
118
 
                /// </summary>
119
 
                protected Label ErrorMsg;
120
 
                
121
 
                // <summary>
122
 
                /// Message panel control.
123
 
                /// </summary>
124
 
                protected HtmlGenericControl MessagePanel;
125
 
 
126
 
                /// <summary>
127
 
                /// Error message control.
128
 
                /// </summary>
129
 
                protected Label InfoMsg;
130
 
 
131
 
                /// <summary>
132
 
                /// Breadcrumb control.
133
 
                /// </summary>
134
 
                protected DataList BreadCrumbs;
135
 
                
136
 
                /// <summary>
137
 
                /// Footer control panel 
138
 
                /// </summary>
139
 
                protected Footer footer;
140
 
 
141
 
                #endregion
142
 
 
143
 
                #region Properties
144
 
 
145
 
                /// <summary>
146
 
                /// Gets or sets the bread crumb list.
147
 
                /// </summary>
148
 
                private ArrayList CrumbList
149
 
                {
150
 
                        get { return ViewState[ "BreadCrumbs" ] as ArrayList; }
151
 
                        set { ViewState[ "BreadCrumbs" ] = value; }
152
 
                }
153
 
 
154
 
                #endregion
155
 
 
156
 
                #region Private Methods
157
 
 
158
 
                /// <summary>
159
 
                /// Creates a data source of breadcrumbs.
160
 
                /// </summary>
161
 
                /// <returns>A DataView item containing breadcrumbs</returns>
162
 
                private DataView CreateDataSource()
163
 
                {
164
 
                        DataTable dt = new DataTable();
165
 
                        DataRow dr;
166
 
 
167
 
                        dt.Columns.Add( new DataColumn( "CrumbField", typeof( string ) ) );
168
 
                        dt.Columns.Add( new DataColumn( "LinkField", typeof( string ) ) );
169
 
 
170
 
                        foreach( BreadCrumbInfo bci in CrumbList )
171
 
                        {
172
 
                                dr = dt.NewRow();
173
 
                                dr[ 0 ] = bci.Crumb;
174
 
                                dr[ 1 ] = bci.CrumbUri;
175
 
                                dt.Rows.Add( dr );
176
 
                        }
177
 
 
178
 
                        // Build the data view from the table.
179
 
                        return new DataView( dt );
180
 
                }
181
 
 
182
 
                /// <summary>
183
 
                /// Page_Load()
184
 
                /// </summary>
185
 
                /// <param name="sender"></param>
186
 
                /// <param name="e"></param>
187
 
                private void Page_Load(object sender, System.EventArgs e)
188
 
                {
189
 
                        // localization
190
 
                        rm = Application[ "RM" ] as ResourceManager;
191
 
 
192
 
                        // Hide the error panel if previously visible.
193
 
                        if ( ErrorPanel.Visible )
194
 
                        {
195
 
                                ErrorPanel.Visible = false;
196
 
                        }
197
 
                        
198
 
                        if ( MessagePanel.Visible )
199
 
                        {
200
 
                                ErrorPanel.Visible = false;
201
 
                        }
202
 
 
203
 
                        if ( !IsPostBack )
204
 
                        {
205
 
                                // Initially hide the error panel.
206
 
                                ErrorPanel.Visible = false;
207
 
                                MessagePanel.Visible = false;
208
 
 
209
 
                                Control body = Page.FindControl( "users" );
210
 
                                if ( body != null )
211
 
                                {
212
 
                                        UserLink.HRef = null;
213
 
                                        iFolderLink.HRef = "iFolders.aspx";
214
 
                                        ServerLink.HRef = "Servers.aspx";
215
 
                                        SystemLink.HRef = "SystemInfo.aspx";
216
 
                                        ReportsLink.HRef = "Reports.aspx";
217
 
                                }
218
 
                                else
219
 
                                {
220
 
                                        body = Page.FindControl( "ifolders" );
221
 
                                        if ( body != null )
222
 
                                        {
223
 
                                                UserLink.HRef = "Users.aspx";
224
 
                                                iFolderLink.HRef = null;
225
 
                                                ServerLink.HRef = "Servers.aspx";
226
 
                                                SystemLink.HRef = "SystemInfo.aspx";
227
 
                                                ReportsLink.HRef = "Reports.aspx";
228
 
                                        }
229
 
                                        else
230
 
                                        {
231
 
                                                body = Page.FindControl( "system" );
232
 
                                                if ( body != null )
233
 
                                                {
234
 
                                                        UserLink.HRef = "Users.aspx";
235
 
                                                        iFolderLink.HRef = "iFolders.aspx";
236
 
                                                        ServerLink.HRef = "Servers.aspx";
237
 
                                                        SystemLink.HRef = null;
238
 
                                                        ReportsLink.HRef = "Reports.aspx";
239
 
                                                }
240
 
                                                else
241
 
                                                {
242
 
                                                        body = Page.FindControl( "server" );
243
 
                                                        if ( body != null )
244
 
                                                        {
245
 
                                                                UserLink.HRef = "Users.aspx";
246
 
                                                                iFolderLink.HRef = "iFolders.aspx";
247
 
                                                                ServerLink.HRef = null;
248
 
                                                                SystemLink.HRef = "SystemInfo.aspx";
249
 
                                                                ReportsLink.HRef = "Reports.aspx";
250
 
                                                        }
251
 
                                                        else
252
 
                                                        {
253
 
                                                                
254
 
                                                                body = Page.FindControl( "report" );
255
 
                                                                if ( body != null )
256
 
                                                                {
257
 
                                                                        UserLink.HRef = "Users.aspx";
258
 
                                                                        iFolderLink.HRef = "iFolders.aspx";
259
 
                                                                        ServerLink.HRef = "Servers.aspx";
260
 
                                                                        SystemLink.HRef = "SystemInfo.aspx";
261
 
                                                                        ReportsLink.HRef = null;
262
 
                                                                }
263
 
                                                                else
264
 
                                                                {
265
 
                                                                        UserLink.HRef = "Users.aspx";
266
 
                                                                        iFolderLink.HRef = "iFolders.aspx";
267
 
                                                                        ServerLink.HRef = "Servers.aspx";
268
 
                                                                        SystemLink.HRef = "SystemInfo.aspx";
269
 
                                                                        ReportsLink.HRef = "Reports.aspx";
270
 
                                                                }
271
 
                                                        }
272
 
                                                }
273
 
                                        }
274
 
                                }
275
 
 
276
 
                                // Initialize the state variables.
277
 
                                BreadCrumbs.RepeatColumns = 0;
278
 
                                CrumbList = new ArrayList();
279
 
                        }
280
 
                }
281
 
 
282
 
                #endregion
283
 
 
284
 
                #region Protected Methods
285
 
 
286
 
                /// <summary>
287
 
                /// Get a Localized String
288
 
                /// </summary>
289
 
                /// <param name="key">Key to the localized string.</param>
290
 
                /// <returns>Localized string.</returns>
291
 
                protected string GetString( string key )
292
 
                {
293
 
                        return rm.GetString( key );
294
 
                }
295
 
 
296
 
                #endregion
297
 
 
298
 
                #region Public Methods
299
 
 
300
 
                /// <summary>
301
 
                /// Adds a bread crumb to the bread crumb list.
302
 
                /// </summary>
303
 
                /// <param name="crumb"></param>
304
 
                /// <param name="link"></param>
305
 
                public void AddBreadCrumb( string crumb, string link )
306
 
                {
307
 
                        if ( crumb.Length > 128 )
308
 
                        {
309
 
                                crumb = crumb.Substring( 0, 128 );
310
 
                        }
311
 
 
312
 
                        CrumbList.Add( new BreadCrumbInfo( crumb, link ) );
313
 
                        ++BreadCrumbs.RepeatColumns;
314
 
                        BreadCrumbs.DataSource = CreateDataSource();
315
 
                        BreadCrumbs.DataBind();
316
 
                }
317
 
 
318
 
                /// <summary>
319
 
                /// Adds a bread crumb to the bread crumb list.
320
 
                /// </summary>
321
 
                /// <param name="crumbs"></param>
322
 
                /// <param name="links"></param>
323
 
                public void AddBreadCrumb( string[] crumbs, string[] links )
324
 
                {
325
 
                        for ( int i = 0; i < crumbs.Length; ++i )
326
 
                        {
327
 
                                AddBreadCrumb( crumbs[ i ], links[ i ] );
328
 
                        }
329
 
                }
330
 
 
331
 
 
332
 
                /// <summary>
333
 
                /// Gets the exception message from the Exception object.
334
 
                /// </summary>
335
 
                /// <param name="e"></param>
336
 
                /// <returns></returns>
337
 
                public string ExceptionMessage( Exception e )
338
 
                {
339
 
                        string type = GetExceptionType( e );
340
 
 
341
 
                        switch ( type )
342
 
                        {
343
 
                                case "AuthorizationException":
344
 
                                        return GetString( "ERRORNOTADMINISTRATOR" );
345
 
 
346
 
                                case "AuthenticationException":
347
 
                                        return GetString( "ERRORAUTHENTICATIONFAILED" );
348
 
 
349
 
                                case "iFolderDoesNotExistException":
350
 
                                        return GetString( "ERRORIFOLDERDOESNOTEXIST" );
351
 
 
352
 
                                case "MemberDoesNotExistException":
353
 
                                        return GetString( "ERRORMEMBERDOESNOTEXIST" );
354
 
 
355
 
                                case "UserDoesNotExistException":
356
 
                                        return GetString( "ERRORUSERDOESNOTEXIST" );
357
 
 
358
 
                                case "LockException":
359
 
                                        return GetString( "ERRORLOCKEXCEPTION" );
360
 
 
361
 
                                case "AccessException":
362
 
                                        return GetString( "ERRORACCESSEXCEPTION" );
363
 
 
364
 
                                case "ArgumentException":
365
 
                                        return e.Message;
366
 
 
367
 
                                default:
368
 
                                        return type;
369
 
                        }
370
 
                }
371
 
 
372
 
                /// <summary>
373
 
                /// Gets the exception type from the specified exception.
374
 
                /// </summary>
375
 
                /// <param name="e"></param>
376
 
                /// <returns></returns>
377
 
                public static string GetExceptionType( Exception e )
378
 
                {
379
 
                        string type = e.GetType().Name;
380
 
 
381
 
        
382
 
                if ( e is SoapException )
383
 
                        {
384
 
                                try
385
 
                                {
386
 
                                        XmlNode node = ( e as SoapException ).Detail.SelectSingleNode( "OriginalException" );
387
 
                                        if ( node == null )
388
 
                                        {
389
 
                                                // try inside the <detail> tags
390
 
                                                node = ( e as SoapException ).Detail.SelectSingleNode( "*/OriginalException" );
391
 
                                        }
392
 
 
393
 
                                        if ( node != null )
394
 
                                        {
395
 
                                                type = node.Attributes.GetNamedItem( "type" ).Value;
396
 
                                                type = type.Substring( type.LastIndexOf( "." ) + 1 );
397
 
                                        }
398
 
                                }
399
 
                                catch {}
400
 
                        }
401
 
                        else if ( e is WebException )
402
 
                        {
403
 
                                type = (e as WebException ).Status.ToString();
404
 
 
405
 
                                if ( ( e as WebException ).Status == WebExceptionStatus.ProtocolError )
406
 
                                {
407
 
                                        HttpWebResponse response = ( e as WebException ).Response as HttpWebResponse;
408
 
                                        type = response.StatusDescription;
409
 
                                }
410
 
                        }
411
 
 
412
 
                        return type;
413
 
                }
414
 
 
415
 
                /// <summary>
416
 
                /// Sets the active page tab for utility pages that are used by multiple root pages.
417
 
                /// </summary>
418
 
                /// <param name="page"></param>
419
 
                public void SetActivePageTab( PageTabs page )
420
 
                {
421
 
                        Control body;
422
 
 
423
 
                        switch( page )
424
 
                        {
425
 
                                case PageTabs.iFolders:
426
 
                                        body = Page.FindControl( "ifolders" );
427
 
                                        if ( body != null )
428
 
                                        {
429
 
                                                UserLink.HRef = "Users.aspx";
430
 
                                                iFolderLink.HRef = null;
431
 
                                                ServerLink.HRef = "Servers.aspx";
432
 
                                                SystemLink.HRef = "SystemInfo.aspx";
433
 
                                                ReportsLink.HRef = "Reports.aspx";
434
 
                                        }
435
 
                                        break;
436
 
 
437
 
                                case PageTabs.Servers:
438
 
                                        body = Page.FindControl( "servers" );
439
 
                                        if ( body != null )
440
 
                                        {
441
 
                                                UserLink.HRef = "Users.aspx";
442
 
                                                iFolderLink.HRef = "iFolders.aspx";
443
 
                                                ServerLink.HRef = null;
444
 
                                                SystemLink.HRef = "SystemInfo.aspx";
445
 
                                                ReportsLink.HRef = "Reports.aspx";
446
 
                                        }
447
 
                                        break;
448
 
 
449
 
                                case PageTabs.System:
450
 
                                        body = Page.FindControl( "system" );
451
 
                                        if ( body != null )
452
 
                                        {
453
 
                                                UserLink.HRef = "Users.aspx";
454
 
                                                iFolderLink.HRef = "iFolders.aspx";
455
 
                                                ServerLink.HRef = "Servers.aspx";
456
 
                                                SystemLink.HRef = null;
457
 
                                                ReportsLink.HRef = "Reports.aspx";
458
 
                                        }
459
 
                                        break;
460
 
 
461
 
                                case PageTabs.Users:
462
 
                                        body = Page.FindControl( "users" );
463
 
                                        if ( body != null )
464
 
                                        {
465
 
                                                UserLink.HRef = null;
466
 
                                                iFolderLink.HRef = "iFolders.aspx";
467
 
                                                ServerLink.HRef = "Servers.aspx";
468
 
                                                SystemLink.HRef = "SystemInfo.aspx";
469
 
                                                ReportsLink.HRef = "Reports.aspx";
470
 
                                        }
471
 
                                        break;
472
 
 
473
 
                                case PageTabs.Reports:
474
 
                                        body = Page.FindControl( "reports" );
475
 
                                        if ( body != null )
476
 
                                        {
477
 
                                                UserLink.HRef = "Users.aspx";
478
 
                                                iFolderLink.HRef = "iFolders.aspx";
479
 
                                                ServerLink.HRef = "Servers.aspx";
480
 
                                                SystemLink.HRef = "SystemInfo.aspx";
481
 
                                                ReportsLink.HRef = null;
482
 
                                        }
483
 
                                        break;
484
 
                        }
485
 
                }
486
 
 
487
 
                /// <summary>
488
 
                /// Shows up an error below the banner.
489
 
                /// </summary>
490
 
                /// <param name="msg"></param>
491
 
                public void ShowInfo( string msg )
492
 
                {
493
 
                        InfoMsg.Text = String.Format( msg );
494
 
                        MessagePanel.Visible = true;
495
 
                }
496
 
 
497
 
                /// <summary>
498
 
                /// Shows up an error below the banner.
499
 
                /// </summary>
500
 
                /// <param name="msg"></param>
501
 
                public void ShowError( string msg )
502
 
                {
503
 
                        ErrorMsg.Text = String.Format( GetString( "ERRORTEMPLATE" ), msg );
504
 
                        ErrorPanel.Visible = true;
505
 
                }
506
 
 
507
 
                /// <summary>
508
 
                /// Shows up an error below the banner.
509
 
                /// </summary>
510
 
                /// <param name="ex"></param>
511
 
                public void ShowError( Exception ex )
512
 
                {
513
 
                        ShowError( ExceptionMessage( ex ) );
514
 
                }
515
 
 
516
 
                /// <summary>
517
 
                /// Shows up an error below the banner.
518
 
                /// </summary>
519
 
                /// <param name="msg"></param>
520
 
                /// <param name="ex"></param>
521
 
                public void ShowError( string msg, Exception ex )
522
 
                {
523
 
                        ShowError( String.Format( "{0} {1}", msg, ExceptionMessage( ex ) ) );
524
 
                }
525
 
 
526
 
                /// <summary>
527
 
                /// Determines whether to show exception detail based on the type of exception.
528
 
                /// </summary>
529
 
                /// <param name="e"></param>
530
 
                /// <returns></returns>
531
 
                public bool ShowExceptionDetail( Exception e )
532
 
                {
533
 
                        switch ( GetExceptionType( e ) )
534
 
                        {
535
 
                                case "AuthorizationException":
536
 
                                case "AuthenticationException":
537
 
                                case "iFolderDoesNotExistException":
538
 
                                case "MemberDoesNotExistException":
539
 
                                case "UserDoesNotExistException":
540
 
                                case "LockException":
541
 
                                case "AccessException":
542
 
                                case "ArgumentException":
543
 
                                        return false;
544
 
 
545
 
                                default:
546
 
                                        return true;
547
 
                        }
548
 
                }
549
 
 
550
 
                public void AddHelpLink(string PageName)
551
 
                {
552
 
                        //string code = Session["language"] as string;
553
 
                        // Pass this page information to create the help link
554
 
                        footer.AddHelpLink(PageName);
555
 
                }
556
 
 
557
 
                #endregion
558
 
 
559
 
                #region Web Form Designer generated code
560
 
 
561
 
                /// <summary>
562
 
                /// OnInit()
563
 
                /// </summary>
564
 
                /// <param name="e"></param>
565
 
                override protected void OnInit(EventArgs e)
566
 
                {
567
 
                        //
568
 
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
569
 
                        //
570
 
                        InitializeComponent();
571
 
                        base.OnInit(e);
572
 
                }
573
 
                
574
 
                /// <summary>
575
 
                ///             Required method for Designer support - do not modify
576
 
                ///             the contents of this method with the code editor.
577
 
                /// </summary>
578
 
                /// this.Load += new System.EventHandler(this.Page_Load);
579
 
                private void InitializeComponent()
580
 
                {
581
 
                        this.Load += new System.EventHandler(this.Page_Load);
582
 
                }
583
 
 
584
 
                #endregion
585
 
 
586
 
                #region BreadCrumbInfo
587
 
 
588
 
                /// <summary>
589
 
                /// Contains bread crumb information.
590
 
                /// </summary>
591
 
                [ Serializable() ]
592
 
                private class BreadCrumbInfo
593
 
                {
594
 
                        #region Class Members
595
 
                        
596
 
                        /// <summary>
597
 
                        /// The bread crumb label.
598
 
                        /// </summary>
599
 
                        public string Crumb;
600
 
 
601
 
                        /// <summary>
602
 
                        /// The uri associated with the crumb.
603
 
                        /// </summary>
604
 
                        public string CrumbUri;
605
 
 
606
 
                        #endregion
607
 
 
608
 
                        #region Constructor
609
 
 
610
 
                        /// <summary>
611
 
                        /// Constructor
612
 
                        /// </summary>
613
 
                        /// <param name="crumb"></param>
614
 
                        /// <param name="crumbUri"></param>
615
 
                        public BreadCrumbInfo( string crumb, string crumbUri )
616
 
                        {
617
 
                                Crumb = crumb;
618
 
                                CrumbUri = crumbUri;
619
 
                        }
620
 
 
621
 
                        #endregion
622
 
                }
623
 
 
624
 
                #endregion
625
 
        }
626
 
}