root/tags/omega-1.0.0-rc3/gui/include/layout-functions.php

Revision 830, 4.6 KB (checked in by rats, 15 months ago)

Fixed #738: ispcp.conf does not exist and other issues on /bin/sh use!

Line 
1<?php
2/**
3 * ispCP ω (OMEGA) a Virtual Hosting Control System
4 *
5 * @copyright     2001-2006 by moleSoftware GmbH
6 * @copyright     2006-2007 by ispCP | http://isp-control.net
7 * @link         http://isp-control.net
8 * @author         ispCP Team (2007)
9 *
10 * @license
11 *   This program is free software; you can redistribute it and/or modify it under
12 *   the terms of the MPL General Public License as published by the Free Software
13 *   Foundation; either version 1.1 of the License, or (at your option) any later
14 *   version.
15 *   You should have received a copy of the MPL Mozilla Public License along with
16 *   this program; if not, write to the Open Source Initiative (OSI)
17 *   http://opensource.org | osi@opensource.org
18 */
19
20if (isset($_SESSION['user_id'])) {
21    if (!isset($_SESSION['logged_from']) && !isset($_SESSION['logged_from_id'])) {
22        list($user_def_lang, $user_def_layout) = get_user_gui_props($sql, $_SESSION['user_id']);
23
24        $_SESSION['user_theme'] = $user_def_layout;
25        $_SESSION['user_def_lang'] = $user_def_lang;
26    }
27}
28
29// THEME_COLOR managment stuff.
30
31function get_user_gui_props(&$sql, $user_id) {
32    global $cfg;
33
34    $query = <<<SQL_QUERY
35        select
36            lang, layout
37        from
38            user_gui_props
39        where
40            user_id = ?
41SQL_QUERY;
42
43    $rs = exec_query($sql, $query, array($user_id));
44
45    if ($rs->RecordCount() == 0 || (empty($rs->fields['lang']) && empty($rs->fields['layout']))) {
46        // values for user id, some default stuff
47        return array($cfg['USER_INITIAL_LANG'], $cfg['USER_INITIAL_THEME']);
48    }
49    else if (empty($rs->fields['lang'])) {
50        return array($cfg['USER_INITIAL_LANG'], $rs->fields['layout']);
51    }
52    else if (empty($rs->fields['layout'])) {
53        return array($rs->fields['lang'], $cfg['USER_INITIAL_THEME']);
54    }
55    else {
56        return array($rs->fields['lang'], $rs->fields['layout']);
57    }
58}
59
60function gen_page_message(&$tpl) {
61    if (!isset($_SESSION['user_page_message'])) {
62        $tpl->assign('PAGE_MESSAGE', '');
63        $tpl->assign('MESSAGE', '');
64    } else {
65        $tpl->assign('MESSAGE', $_SESSION['user_page_message']);
66        unset($_SESSION['user_page_message']);
67    }
68}
69
70function check_language_exist($lang_table) {
71    global $sql;
72
73    $tables = $sql->MetaTables();
74    $nlang = count($tables);
75    for ($i = 0 ; $i < $nlang; $i++) {
76        $data = $tables[$i];
77        if ($data == $lang_table) {
78            return true;
79        }
80    }
81    return false;
82}
83
84function set_page_message($message) {
85    if (isset($_SESSION['user_page_message']))
86        $_SESSION['user_page_message'] .= "<br><br>$message<br><br>";
87    else
88        $_SESSION['user_page_message'] = $message;
89}
90
91function get_menu_vars($menu_link) {
92    global $sql;
93
94    $user_id = $_SESSION['user_id'];
95
96    $query = <<<SQL_QUERY
97        SELECT
98            customer_id, fname, lname, firm, zip, city, country, email, phone, fax, street1, street2
99        FROM
100            admin
101        WHERE
102            admin_id = ?
103SQL_QUERY;
104
105    $rs = exec_query($sql, $query, array($user_id));
106
107    $search = array();
108    $replace = array();
109
110    $search [] = '{uid}';
111    $replace[] = $_SESSION['user_id'];
112    $search [] = '{uname}';
113    $replace[] = $_SESSION['user_logged'];
114    $search [] = '{cid}';
115    $replace[] = $rs->fields['customer_id'];
116    $search [] = '{fname}';
117    $replace[] = $rs->fields['fname'];
118    $search [] = '{lname}';
119    $replace[] = $rs->fields['lname'];
120    $search [] = '{company}';
121    $replace[] = $rs->fields['firm'];
122    $search [] = '{zip}';
123    $replace[] = $rs->fields['zip'];
124    $search [] = '{city}';
125    $replace[] = $rs->fields['city'];
126    $search [] = '{country}';
127    $replace[] = $rs->fields['country'];
128    $search [] = '{email}';
129    $replace[] = $rs->fields['email'];
130    $search [] = '{phone}';
131    $replace[] = $rs->fields['phone'];
132    $search [] = '{fax}';
133    $replace[] = $rs->fields['fax'];
134    $search [] = '{street1}';
135    $replace[] = $rs->fields['street1'];
136    $search [] = '{street2}';
137    $replace[] = $rs->fields['street2'];
138
139    $query = <<<SQL_QUERY
140        SELECT
141            domain_name, domain_admin_id
142        FROM
143            domain
144        WHERE
145            domain_admin_id = ?
146SQL_QUERY;
147
148    $rs = exec_query($sql, $query, array($user_id));
149
150    $search [] = '{domain_name}';
151    $replace[] = $rs->fields['domain_name'];
152
153    $menu_link = str_replace($search, $replace, $menu_link);
154    return $menu_link;
155}
156
157// curently not being used because there's only one layout/theme
158function gen_def_layout(&$tpl, $user_def_layout) {
159    $layouts = array('blue', 'green', 'red', 'yellow');
160
161    foreach ($layouts as $layout) {
162        if ($layout === $user_def_layout) {
163            $selected = 'selected';
164        } else {
165            $selected = '';
166        }
167
168        $tpl->assign(
169            array('LAYOUT_VALUE' => $layout,
170                'LAYOUT_SELECTED' => $selected,
171                'LAYOUT_NAME' => $layout
172                )
173            );
174
175        $tpl->parse('DEF_LAYOUT', '.def_layout');
176    }
177}
178
179?>
Note: See TracBrowser for help on using the browser.