HomeHelpTrac

source: tags/6.1/profile_poll.php @ 10242

Revision 10242, 6.8 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 . 'profiles.inc.php' );
24require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
25
26$ADMIN = member_auth( 1, false );
27$logged['admin'] = $ADMIN;
28
29// Check if moderator logged in.
30$moderator = member_auth(3, false);
31$logged['moderator'] = $moderator;
32// Give moderator all admin rights for this page.
33$ADMIN = $ADMIN || $moderator;
34
35if ( !$ADMIN )
36$logged['member'] = member_auth( 0 );
37
38// --------------- page variables and login
39
40$_page['name_index']    = 72;
41$_page['css_name']  = 'profile_poll.css';
42$_page['js_name']   = 'profile_poll.js';
43
44
45$_page['header'] = _t("_Polls");
46$_page['header_text'] = _t("_Polls");
47
48
49
50// --------------- handle post values
51
52    $member['ID'] = (int)$_COOKIE['memberID'];
53
54    if ( $_POST['question'] ) {
55        $poll_answers = '';
56        for ( $i = 0; $i < $_POST['next_val']; $i++ ) {
57            if ( $_POST[ 'v' . $i ] ) {
58                $poll_answers .= process_db_input($_POST[ 'v' . $i ], 1) . '<delim>';
59                $poll_results .= '0;';
60            }
61        }
62
63        if ( $poll_answers ) {
64            $query = "SELECT COUNT(*) FROM ProfilesPolls WHERE id_profile = '" . $member['ID'] . "'";
65            $polls_num = db_arr( $query );
66
67            $profile_poll_num = getParam("profile_poll_num");
68            if ( $profile_poll_num && $polls_num[0] < $profile_poll_num ) { // limit number of polls
69                $iAct = getParam("profile_poll_act") == 'on' ? 1 : 0;
70                $query = "INSERT INTO ProfilesPolls ( id_profile, poll_question, poll_answers, poll_results, poll_status, poll_approval )
71                VALUES ( '{$member['ID']}', '" . process_db_input($_POST['question'], 1) . "', '{$poll_answers}', '{$poll_results}', 'active', '{$iAct}')";
72                db_res( $query );
73                $message = _t("_poll created");
74            }
75        }
76    }
77
78// --------------- page components
79
80$_ni = $_page['name_index'];
81$_page_cont[$_ni]['page_main_code'] = ThisPageMainCode();
82
83// --------------- [END] page components
84
85
86PageCode();
87
88
89// --------------- page components functions
90
91/**
92 * page code function
93 */
94function ThisPageMainCode() {
95    global $logged;
96    global $member;
97
98    // create poll section -------------------------------------------------------------------
99    $ret .= '<div class="createPollSection">';
100
101    $query = "SELECT COUNT(`id_poll`) FROM `ProfilesPolls` WHERE `id_profile` = '{$member['ID']}'";
102    $ras_arr = db_arr( $query );
103
104    $polls_num = db_arr( $query );
105    $profile_poll_num = getParam("profile_poll_num");
106
107    if ( $profile_poll_num && $polls_num[0] < $profile_poll_num ) // limit number of polls
108        $ret .= ShowPollCreationForm();
109    else
110        $ret .= _t('_max_poll_reached');
111
112    $ret .= '</div>';
113
114    // show polls section --------------------------------------------------------------------
115    $ret .= '<div class="pollContainer" id="pol_container">';
116    $ret .= '<div class="clear_both"></div>';
117    $query = "SELECT `id_poll`, `poll_status` FROM `ProfilesPolls` WHERE `id_profile` = '{$member['ID']}'";
118    $polls_num = db_res( $query );
119
120    while( $poll_arr = mysql_fetch_array ( $polls_num ) ) {
121        $uID = $poll_arr['id_poll'];
122
123        $ret .= '<div id="pol_container_pol_' . $uID . '" class="controlsDiv">';
124        $ret .= ShowPoll( $uID );
125
126        $ret .= '<div class="innerControlBlock">';
127
128        //$ret .= '<div class="controlsHeader">' . _t('_controls') . ':</div>';
129
130        $sCurStatus = '';
131        $sCTStatus = '';
132        $status_change_to = '';
133        if ( 'active' == $poll_arr['poll_status'] ) {
134            $sCurStatus = _t('_Active');
135            $sCTStatus = _t('_Disabled');
136            $status_change_to = 'disabled';
137        } else {
138            $sCurStatus = _t('_Disabled');
139            $sCTStatus = _t('_Active');
140            $status_change_to = 'active';
141        }
142
143        $ret .= "<span id=\"poll_status_{$uID}\" style=\"padding: 0px 2px;\"></span>";
144
145        $ret .= '<span class="deleteDiv"><a href="#" onclick=" if ( window.confirm(\'' . _t('_are you sure?') . '\') ) { send_data( \'\', \'delete\', \'\', \'' . $uID . '\' ); del_question_bar( document.getElementById(\'pol_container\'), document.getElementById(\'pol_container_pol_' . $uID . '\') ); } return false;">'. _t('_delete') .'</a></span>';
146       
147        $ret .= '<script language="javascript">
148            poll_status_show( \'' . $uID . '\', \'poll_status_' . $uID . '\', \'' . $poll_arr['poll_status'] . '\', \'' . $status_change_to . '\', \'' . $sCurStatus . '\', \'' . $sCTStatus . '\' );
149                </script>';
150
151        $ret .= '</div>';
152
153        $ret .= '</div>';
154    }
155
156    // if no polls
157    if ( !$uID )
158        $ret .= _t_err('_no poll');
159    $ret .= '<div class="clear_both"></div>';
160    $ret .= '</div>';
161
162    return $ret;
163}
164
165function ShowPollCreationForm() {
166    ob_start();
167    ?>
168    <form id="poll" method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
169        <input id="next_val" name="next_val" type="hidden" value="1" />
170        <table id="questions">
171            <tr>
172                <th colspan="2"><?= _t('_create poll') ?></th>
173            </tr>
174            <tr>
175                <td class="form_label"><?= _t('_question') ?>:</td>
176                <td class="form_value">
177                    <input id="question" name="question">
178                </td>
179            </tr>
180            <tr>
181                <td class="form_label"><?= _t('_answer variants') ?>:</td>
182                <td class="form_value">
183                    <div id="questions_bar_cont"></div>
184                </td>
185            </tr>
186            <tr>
187                <td colspan="2" class="form_colspan">
188                <a href="javascript:void(0);"
189                  onclick="add_question_bar( 'questions_bar_cont', 'next_val', true ); return false;"><?= _t('_add answer') ?></a>
190                |
191                <a href="javascript:void(0);" onclick="document.getElementById('poll').submit(); return false;"><?= _t('_generate poll') ?></a>
192                </td>
193            </tr>
194        </table>
195    </form>
196    <script type="text/javascript">
197        add_question_bar( 'questions_bar_cont', 'next_val', false );
198        add_question_bar( 'questions_bar_cont', 'next_val', false );
199    </script>
200    <?
201   
202    return ob_get_clean();
203}
204
205?>
Note: See TracBrowser for help on using the repository browser.