HomeHelpTrac

source: tags/6.1/aemodule.php @ 10242

Revision 10242, 8.5 KB checked in by Alexander Trofimov, 3 years ago (diff)

dolphin 6.1.5, initial commit

Line 
1<?
2
3/***************************************************************************
4*                            Dolphin Smart Community Builder
5*                              -----------------
6*     begin                : Mon Mar 23 2006
7*     copyright            : (C) 2006 BoonEx Group
8*     website              : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21require_once( 'inc/header.inc.php' );
22require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
23require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );
24require_once( BX_DIRECTORY_PATH_INC . 'modules.inc.php' );
25require_once( BX_DIRECTORY_PATH_INC . 'membership_levels.inc.php' );
26require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
27
28$pageIndex = $_page['name_index'] = 23;
29
30
31$_page['header'] = _t('_Choose forum');
32
33$enable_ray = (getParam( 'enable_ray' ) == 'on');
34
35function LaunchRayChat()
36{
37    global $site;
38
39    $iId = (int)$_COOKIE['memberID'];
40    $sPassword = getPassword( $iId );
41    $aPostVals = array( 'module' => 'chat', 'app' => 'user', 'id' => $iId, 'password' => $sPassword );
42
43    Redirect( $site['url'] . 'ray/index.php', $aPostVals, 'get', 'Ray chat' );
44}
45
46function showError($errorMessage)
47{
48    global $pageIndex;
49    global $_page_cont;
50    global $_page;
51
52    //$_page['header_text'] = _t('_Module_access_error');
53    $_page['header_text'] = '';
54    $_page_cont[$pageIndex]['page_main_code'] = $errorMessage;
55    PageCode();
56}
57
58/**
59 *  A simple class-container of HTML hyperlink
60 */
61class CHyperLink
62{
63    var $linkReference;
64
65    var $linkDescription;
66
67    /**
68     * Returns properly constructed HTML code of hyperlink
69     *
70     * @return string HTML code
71     */
72    function GetHTMLcode()
73    {
74        $code = '<a href="'.addslashes(htmlspecialchars($this->linkReference)).'">';
75        if (strlen($this->linkDescription) > 0)
76        {
77            $code .= $this->linkDescription;
78        }
79        else
80        {
81            $code .= $this->linkReference;
82        }
83        $code .= '</a>';
84
85        return $code;
86    }
87
88    function CHyperLink($linkReference, $linkDescription)
89    {
90        $this->linkReference = $linkReference;
91        $this->linkDescription = $linkDescription;
92    }
93};
94
95/** //MOVE THIS FUNCTION TO utils.inc.php!!!
96 * Displays list of links, using current template
97 * (design.inc.php module should be included)
98 *
99 * @param string $pageHeaderText
100 *
101 * @param string $listHeaderText
102 *
103 * @param array of CHyperLink $links - array of URLs. Array length must be equal to $linksDescriptions length
104 *
105 * @return bool Returns true on success and false in case of any error
106 */
107function showLinksList($pageIndex, $pageHeaderText, $listHeaderText, $links)
108{
109    global $_page_cont;
110    global $_page;
111
112    if (! class_exists('CHyperLink'))
113    {
114        return false;
115    }
116
117    if ((! is_array($links)) || count($links) == 0)
118    {
119        return false;
120    }
121
122    $pageMainCode = '';
123    $_page['header_text'] = $pageHeaderText;
124    $pageMainCode .= $listHeaderText.'<br />';
125
126    foreach ($links as $hyperLink)
127    {
128        if (! is_a($hyperLink, 'CHyperLink'))
129        {
130            return false;
131        }
132        $pageMainCode .= $hyperLink->GetHTMLcode().'<br />';
133    }
134
135    $_page_cont[$pageIndex]['page_main_code'] = '<div align="center">'. $pageMainCode .'</div>';
136
137    PageCode();
138
139    return true;
140}
141
142$isAdmin = member_auth(1, false);
143$logged['admin'] = $isAdmin;
144if ($isAdmin)
145{
146    $adminName = $_COOKIE['adminID'];
147}
148else
149{
150    $isMember = member_auth(0, false);
151    $logged['member'] = $isMember;
152    if ($isMember)
153    {
154        $memberID = $_COOKIE['memberID'];
155    }
156}
157
158if (array_key_exists('ModuleName', $_GET))
159{
160
161    $moduleName = $_GET['ModuleName'];
162    $dbModuleName = process_db_input($_GET['ModuleName']);
163
164    // Ray support
165    if ($moduleName == 'ray')
166    {
167        if ($enable_ray)
168        {
169            if ($isMember)
170            {
171                $chechActionRes = checkAction($memberID, ACTION_ID_USE_RAY_CHAT);
172                if ($chechActionRes[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
173                {
174                    LaunchRayChat();
175                    checkAction($memberID, ACTION_ID_USE_RAY_CHAT, true);
176                }
177                else
178                {
179                    showError($chechActionRes[CHECK_ACTION_MESSAGE]);
180                }
181            }
182            else
183            {
184                showError(_t('_Please login before using Ray chat'));
185            }
186        }
187        else
188        {
189            showError(_t('_Ray is not enabled. Select <link> another module', $_SERVER['PHP_SELF']));
190        }
191        exit();
192    }
193    // end of Ray support
194
195    if ($isAdmin)
196    {
197        modules_login($adminName, $moduleName, 1);
198    }
199    else if ($isMember)
200    {
201        $memberID = $_COOKIE['memberID'];
202
203        // Extract module type from database by the module name, do not rely on GET,
204        // because it is a hole: user can crack membership restrictions
205        list($moduleType) = db_arr("SELECT `Type` FROM `Modules` WHERE `Name` = '{$dbModuleName}'");
206        if (strlen(trim($moduleType)) == 0)
207        {
208            showError(_t('_Invalid module name or invalid row in database') . 'ModuleName = "'.$moduleName.'"');
209        }
210
211        // If module is forum or chat, then check if member is allowed to use the module
212        switch ($moduleType)
213        {
214            case 'forum':
215                $check_res = checkAction($memberID, ACTION_ID_USE_FORUM);
216                if ($check_res[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
217                {
218                    showError($check_res[CHECK_ACTION_MESSAGE]);
219                    exit();
220                }
221                checkAction($memberID, ACTION_ID_USE_FORUM, true);
222                break;
223            case 'chat':
224                $check_res = checkAction($memberID, ACTION_ID_USE_CHAT);
225                if ($check_res[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
226                {
227                    showError($check_res[CHECK_ACTION_MESSAGE]);
228                    exit();
229                }
230                checkAction($memberID, ACTION_ID_USE_CHAT, true);
231                break;
232            default:
233                {
234                    showError(_t('_Unknown module type selected').": '".$moduleType."'");
235                }
236        }
237        modules_login($memberID, $moduleName, 0);
238    }
239    else
240    {
241        // If not a member and not an admin, so merely redirect to a module index page
242        if (is_array($mods) && array_key_exists($moduleName, $mods) &&
243            is_array($mods[$moduleName]) && array_key_exists('ModuleDirectory', $mods[$moduleName]))
244        {
245            Redirect($site['url'] . $mods[$moduleName]['ModuleDirectory']);
246        }
247        else
248        {
249            showError(_t('_Module directory was not set. Module must be re-configurated'));
250        }
251    }
252}
253else
254{
255    if (array_key_exists('ModuleType', $_GET))
256    {
257        $moduleType = $_GET['ModuleType'];
258        $dbModuleType = process_db_input($_GET['ModuleType']);
259
260        if (! in_array($moduleType, array('forum', 'chat')))
261        {
262            showError(_t('_Invalid module type selected.').'<br /><a href="'.$_SERVER['PHP_SELF'].'">'._t('_Select module type').'</a>');
263            exit();
264        }
265
266        // User should select certain module
267        $resModules = db_res("SELECT `Name`,
268                                     `ReadableName`
269                              FROM `Modules`
270                              WHERE `Type` = '{$dbModuleType}'");
271        $modulesLinks = array();
272        while ($arrModule = mysql_fetch_array($resModules))
273        {
274            $modulesLinks[] = new CHyperLink($_SERVER['PHP_SELF'].'?ModuleName='.$arrModule['Name'],
275                $arrModule['ReadableName']);
276        }
277
278        // Ray support
279        if ($moduleType == 'chat' && $enable_ray)
280        {
281            $modulesLinks[] = new CHyperLink($_SERVER['PHP_SELF'].'?ModuleName=ray', 'Ray');
282        }
283        // end of Ray support
284
285        switch (count($modulesLinks))
286        {
287            case 0:
288                showError(_t('_No modules of this type installed', $moduleType)); // ARGUMENT!
289                break;
290            case 1:
291                // Do not ask member if there is only one module
292                Redirect($modulesLinks[0]->linkReference, null, 'post');
293                break;
294            default:
295                showLinksList($pageIndex, _t('_Module selection'), _t('Choose module to log in'), $modulesLinks);
296        }
297    }
298    else
299    {
300        // User should select certain module type
301        $resModulesTypes = db_res("SELECT DISTINCT `Type`
302                                   FROM `Modules`");
303        $modulesTypesLinks = array();
304        while ($arrModulesType = mysql_fetch_array($resModulesTypes))
305        {
306            $modulesTypesLinks[] = new CHyperLink($_SERVER['PHP_SELF'].'?ModuleType='.$arrModulesType['Type'],
307                $arrModulesType['Type']);
308        }
309
310        switch (count($modulesTypesLinks))
311        {
312            case 0:
313                showError(_t('_No modules found', $moduleType)); // ARGUMENT!
314                break;
315            case 1:
316                // Do not ask member if there is only one type of modules
317                Redirect($modulesTypesLinks[0]->linkReference, null, 'post');
318                break;
319            default:
320                showLinksList($pageIndex, _t('_Module type selection'), _t('_Choose module type'), $modulesTypesLinks);
321        }
322    }
323}
324
325?>
Note: See TracBrowser for help on using the repository browser.