source: sandbox/2.5.1-evolucao/home.php @ 7673

Revision 7673, 6.9 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare                                                               *
4        * http://www.egroupware.org                                                *
5        * The file written by Joseph Engo <jengo@phpgroupware.org>                 *
6        * This file modified by Greg Haygood <shrykedude@bellsouth.net>            *
7        * --------------------------------------------                             *
8        *  This program is free software; you can redistribute it and/or modify it *
9        *  under the terms of the GNU General Public License as published by the   *
10        *  Free Software Foundation; either version 2 of the License, or (at your  *
11        *  option) any later version.                                              *
12        \**************************************************************************/
13        $phpgw_info = array();
14        $current_url = substr($_SERVER["SCRIPT_NAME"], 0, strpos($_SERVER["SCRIPT_NAME"],'home.php'));
15
16        if (!is_file('header.inc.php'))
17        {
18                Header('Location: '.$current_url.'setup/index.php');
19                exit;
20        }
21
22        $GLOBALS['sessionid'] = @$_GET['sessionid'] ? $_GET['sessionid'] : @$_COOKIE['sessionid'];
23        if (!isset($GLOBALS['sessionid']) || !$GLOBALS['sessionid'])
24        {
25                Header('Location: '.$current_url.'login.php?cd=10');
26                exit;
27        }
28
29        $GLOBALS['phpgw_info']['flags'] = array(
30                'noheader'                => True,
31                'nonavbar'                => True,
32                'currentapp'              => 'home',
33                'enable_network_class'    => True,
34                'enable_contacts_class'   => True,
35                'enable_nextmatchs_class' => True
36        );
37        include('header.inc.php');
38       
39        //detect browser
40        require_once('phpgwapi/inc/class.browser.inc.php');
41       
42        $ifMobile       = false;
43        $browser        = new browser();
44       
45       
46        switch( $browser->get_platform() )
47        {
48                case browser::PLATFORM_IPHONE:
49                case browser::PLATFORM_IPOD:
50                case browser::PLATFORM_IPAD:
51                case browser::PLATFORM_BLACKBERRY:
52                case browser::PLATFORM_ANDROID:                                         
53                        $ifMobile = false;
54                        break;                 
55        }
56       
57        if( $ifMobile )
58        {
59                if( $_GET['dont_redirect_if_moble'] != 1 )
60                {
61                        $GLOBALS['phpgw']->redirect('/mobile/index.php');
62                        exit;                   
63                }
64        }
65       
66       
67        $GLOBALS['phpgw_info']['flags']['app_header']=lang('home');
68
69        // Commented by alpeb: The following prevented anonymous users to get a home page. Perhaps it was done with anonymous users such as the ones
70        // used by  wiki and sitemgr in mind. However, if you mark a normal user as anonymous just to avoid being shown in sessions and access log (like you would for an admin that doesn't want to be noticed), the user won't be able to login anymore. That's why I commented the code.
71        /*if ($GLOBALS['phpgw']->session->session_flags == 'A')
72        {
73                if ($_SERVER['HTTP_REFERER'] && strstr($_SERVER['HTTP_REFERER'],'home.php') === False)
74                {
75                        $GLOBALS['phpgw']->redirect($_SERVER['HTTP_REFERER']);
76                }
77                else
78                {
79                        // redirect to the login-page, better then giving an empty page
80                        $GLOBALS['phpgw']->redirect('login.php');
81                }
82                exit;
83        }*/
84
85        if ($GLOBALS['phpgw_info']['server']['force_default_app'] && $GLOBALS['phpgw_info']['server']['force_default_app'] != 'user_choice')
86        {
87                $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] = $GLOBALS['phpgw_info']['server']['force_default_app'];
88        }
89
90        if ($_GET['cd']=='yes' && $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] &&
91                $GLOBALS['phpgw_info']['user']['apps'][$GLOBALS['phpgw_info']['user']['preferences']['common']['default_app']])
92        {
93                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/' . $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] . '/' . 'index.php'));
94        }
95        else
96        {
97                $GLOBALS['phpgw']->common->phpgw_header();
98                echo parse_navbar();
99        }
100
101        // Default Applications (Home Page)
102        $default_apps = Array(                 
103                        'workflow',                     
104                        'expressoMail1_2',
105                        'calendar',
106                        'news_admin'
107                );
108        $sorted_apps = array();
109        $user_apps = $GLOBALS['phpgw_info']['user']['apps'];
110        @reset($user_apps);
111        $default_apps_count = count($default_apps);
112        for($i = 0; $i < $default_apps_count;++$i) {
113                if(array_key_exists($default_apps[$i], $user_apps)){
114                        $sorted_apps[] = $default_apps[$i];
115                }               
116        }
117       
118        foreach($GLOBALS['phpgw_info']['user']['apps'] as $i => $p) {
119                $sorted_apps[] = $p['name'];
120        }
121
122        $portal_oldvarnames = array('mainscreen_showevents', 'homeShowEvents','homeShowLatest','mainscreen_showmail','mainscreen_showbirthdays','mainscreen_show_new_updated');
123        $done = array();
124        // Display elements, within appropriate table cells     
125        @reset($sorted_apps);
126        $idx = 1;
127        echo "<table width='100%' cellpadding=5>";
128        foreach($sorted_apps as $appname)
129        {
130                if((int)$done[$appname] == 1 || empty($appname)){
131                        continue;
132                }
133                $varnames = $portal_oldvarnames;
134                $varnames[] = 'homepage_display';
135                $thisd = 0;
136                $tmp = '';
137
138                foreach($varnames as $varcheck)
139                {
140
141                        /*if($appname == 'expressoMail1_2') {
142                                $tmp = $appname;
143                                $appname = 'expressoMail';
144                        }*/
145
146                        if(array_search($appname, $default_apps) !== False){
147                                $thisd = 1;
148                                break;
149                        }
150                        if($GLOBALS['phpgw_info']['user']['preferences'][$appname][$varcheck]=='True') {
151                                $thisd = 1;
152                                break;
153                        }
154                        else  {
155                                $_thisd = (int)$GLOBALS['phpgw_info']['user']['preferences'][$appname][$varcheck];
156                                if($_thisd > 0) {
157                                        $thisd = $_thisd;
158                                        break;
159                                }
160                        }
161                }
162
163               if($thisd > 0)
164                {
165                        if($tmp) {
166                $appname = $tmp;
167                                $tmp = '';
168                        }
169                        if($idx == 0) {
170                                print '<tr>';
171                        }
172                        print '<td style="vertical-align:top;" width="45%">';
173                        $GLOBALS['phpgw']->hooks->single('home',$appname);
174                        print '</td>';
175
176                        if($idx == 2){
177                                $idx = 0;
178                                print '</tr>';
179                        }
180                        ++$idx;
181                        $neworder[] = $appname;
182                }
183                $done[$appname] = 1;
184        }
185        print '</table>';
186
187        $GLOBALS['phpgw']->common->phpgw_footer();
188?>
Note: See TracBrowser for help on using the repository browser.