Project

General

Profile

1 560 Ruebenwurz
<?php
2 1375 FrankH
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          WebsiteBaker Project
7 1714 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1375 FrankH
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13 1457 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1714 Luisehahne
 * @description
16 1375 FrankH
 */
17 560 Ruebenwurz
18
// Must include code to stop this file being access directly
19 1538 Luisehahne
/* -------------------------------------------------------- */
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23 1714 Luisehahne
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24 1538 Luisehahne
}
25
/* -------------------------------------------------------- */
26 560 Ruebenwurz
27 1079 Ruebenwurz
//overwrite php.ini on Apache servers for valid SESSION ID Separator
28
if(function_exists('ini_set')) {
29
	ini_set('arg_separator.output', '&amp;');
30
}
31 1582 Luisehahne
32 1584 Luisehahne
// load module language file
33
$lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php';
34
require_once(!file_exists($lang) ? (dirname(__FILE__)) . '/languages/EN.php' : $lang );
35
36 1553 Luisehahne
include_once(WB_PATH.'/framework/functions.php');
37 1079 Ruebenwurz
38 1553 Luisehahne
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? '#'.SEC_ANCHOR.$section['section_id'] : '' );
39
40 560 Ruebenwurz
//Delete all form fields with no title
41 1553 Luisehahne
$sql  = 'DELETE FROM `'.TABLE_PREFIX.'mod_form_fields` ';
42
$sql .= 'WHERE page_id = '.(int)$page_id.' ';
43
$sql .=   'AND section_id = '.(int)$section_id.' ';
44
$sql .=   'AND title=\'\' ';
45
if( !$database->query($sql) ) {
46
// error msg
47
}
48 560 Ruebenwurz
49 1714 Luisehahne
50 560 Ruebenwurz
?>
51 1585 Luisehahne
<table summary="" width="100%" cellpadding="0" cellspacing="0" border="0">
52 560 Ruebenwurz
<tr>
53 1585 Luisehahne
	<td align="left" width="50%">
54 1079 Ruebenwurz
		<input type="button" value="<?php echo $TEXT['ADD'].' '.$TEXT['FIELD']; ?>" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/form/add_field.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>';" style="width: 100%;" />
55 560 Ruebenwurz
	</td>
56 1585 Luisehahne
	<td align="right" width="50%">
57 1079 Ruebenwurz
		<input type="button" value="<?php echo $TEXT['SETTINGS']; ?>" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/form/modify_settings.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>';" style="width: 100%;" />
58 560 Ruebenwurz
	</td>
59
</tr>
60
</table>
61
62
<br />
63
64
<h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$TEXT['FIELD']; ?></h2>
65
<?php
66
67
// Loop through existing fields
68 1553 Luisehahne
$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_form_fields` ';
69
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
70
$sql .= 'ORDER BY `position` ASC';
71
if($query_fields = $database->query($sql)) {
72
	if($query_fields->numRows() > 0) {
73
		$num_fields = $query_fields->numRows();
74
		$row = 'a';
75 560 Ruebenwurz
		?>
76 1584 Luisehahne
		<table summary="" width="100%" cellpadding="2" cellspacing="0" border="0">
77 1582 Luisehahne
		<thead>
78 1553 Luisehahne
			<tr style="background-color: #dddddd; font-weight: bold;">
79 1582 Luisehahne
				<th width="20" style="padding-left: 5px;">&nbsp;</th>
80
				<th width="30" style="text-align: right;">ID</th>
81
				<th width="400"><?php print $TEXT['FIELD']; ?></th>
82
				<th width="175"><?php print $TEXT['TYPE']; ?></th>
83
				<th width="100"><?php print $TEXT['REQUIRED']; ?></th>
84
				<th width="175">
85 560 Ruebenwurz
				<?php
86 1553 Luisehahne
					echo $TEXT['MULTISELECT'];
87
				?>
88 1582 Luisehahne
				</th>
89
				<th width="175" colspan="3">
90 1553 Luisehahne
				<?php
91
					echo $TEXT['ACTIONS'];
92
				?>
93 1582 Luisehahne
				</th>
94 1553 Luisehahne
			</tr>
95 1582 Luisehahne
		</thead>
96
		<tbody>
97 1553 Luisehahne
		<?php
98
		while($field = $query_fields->fetchRow(MYSQL_ASSOC)) {
99
			?>
100
			<tr class="row_<?php echo $row; ?>">
101
				<td style="padding-left: 5px;">
102
					<a href="<?php echo WB_URL; ?>/modules/form/modify_field.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>&amp;field_id=<?php echo $admin->getIDKEY($field['field_id']); ?>" title="<?php echo $TEXT['MODIFY']; ?>">
103
						<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="^" />
104
					</a>
105
				</td>
106
				<td style="text-align: right;">
107
					<a href="<?php echo WB_URL; ?>/modules/form/modify_field.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>&amp;field_id=<?php echo $admin->getIDKEY($field['field_id']); ?>">
108
						<?php echo $field['field_id']; ?>
109
					</a>
110
				</td>
111
				<td>
112
					<a href="<?php echo WB_URL; ?>/modules/form/modify_field.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>&amp;field_id=<?php echo $admin->getIDKEY($field['field_id']); ?>">
113
						<?php echo $field['title']; ?>
114
					</a>
115
				</td>
116
				<td>
117
					<?php
118
					if($field['type'] == 'textfield') {
119
						echo $TEXT['SHORT_TEXT'];
120
					} elseif($field['type'] == 'textarea') {
121
						echo $TEXT['LONG_TEXT'];
122
					} elseif($field['type'] == 'heading') {
123
						echo $TEXT['HEADING'];
124
					} elseif($field['type'] == 'select') {
125
						echo $TEXT['SELECT_BOX'];
126
					} elseif($field['type'] == 'checkbox') {
127
						echo $TEXT['CHECKBOX_GROUP'];
128
					} elseif($field['type'] == 'radio') {
129
						echo $TEXT['RADIO_BUTTON_GROUP'];
130
					} elseif($field['type'] == 'email') {
131
						echo $TEXT['EMAIL_ADDRESS'];
132
					}
133
					?>
134
				</td>
135 1582 Luisehahne
				<td style="text-align: center;">
136 1553 Luisehahne
				<?php
137
				if ($field['type'] != 'group_begin') {
138
					if($field['required'] == 1) { echo $TEXT['YES']; } else { echo $TEXT['NO']; }
139 560 Ruebenwurz
				}
140
				?>
141 1553 Luisehahne
				</td>
142
				<td>
143
				<?php
144
				if ($field['type'] == 'select') {
145
					$field['extra'] = explode(',',$field['extra']);
146
					 if($field['extra'][1] == 'multiple') { echo $TEXT['YES']; } else { echo $TEXT['NO']; }
147
				}
148
				?>
149
				</td>
150 1582 Luisehahne
				<td width="20" style="text-align: center;">
151 1553 Luisehahne
				<?php if($field['position'] != 1) { ?>
152
					<a href="<?php echo WB_URL; ?>/modules/form/move_up.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>&amp;field_id=<?php echo $admin->getIDKEY($field['field_id']); ?>" title="<?php echo $TEXT['MOVE_UP']; ?>">
153
						<img src="<?php echo THEME_URL; ?>/images/up_16.png" border="0" alt="^" />
154
					</a>
155
				<?php } ?>
156
				</td>
157 1582 Luisehahne
				<td width="20" style="text-align: center;">
158 1553 Luisehahne
				<?php if($field['position'] != $num_fields) { ?>
159
					<a href="<?php echo WB_URL; ?>/modules/form/move_down.php?page_id=<?php echo $page_id; ?>&amp;section_id=<?php echo $section_id; ?>&amp;field_id=<?php echo $admin->getIDKEY($field['field_id']); ?>" title="<?php echo $TEXT['MOVE_DOWN']; ?>">
160
						<img src="<?php echo THEME_URL; ?>/images/down_16.png" border="0" alt="v" />
161
					</a>
162
				<?php } ?>
163
				</td>
164 1582 Luisehahne
				<td width="20" style="text-align: center;">
165 1553 Luisehahne
<?php
166
				$url = (WB_URL.'/modules/form/delete_field.php?page_id='.$page_id.'&amp;section_id='.$section_id.'&amp;field_id='.$admin->getIDKEY($field['field_id']))
167 1582 Luisehahne
?>
168 1714 Luisehahne
					<a href="javascript:confirm_link('<?php echo url_encode($TEXT['ARE_YOU_SURE']); ?>','<?php echo $url; ?>');" title="<?php echo $TEXT['DELETE']; ?>">
169 1553 Luisehahne
						<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
170
					</a>
171
				</td>
172
			</tr>
173 1582 Luisehahne
<?php
174 1553 Luisehahne
			// Alternate row color
175
			if($row == 'a') {
176
				$row = 'b';
177
			} else {
178
				$row = 'a';
179 560 Ruebenwurz
			}
180 1553 Luisehahne
		}
181 1582 Luisehahne
?>
182
		</tbody>
183 1553 Luisehahne
		</table>
184 560 Ruebenwurz
		<?php
185 1553 Luisehahne
	} else {
186
		echo $TEXT['NONE_FOUND'];
187 560 Ruebenwurz
	}
188
}
189 1714 Luisehahne
// Query overview submissions table
190
/*
191
*/
192
$sql  = 'SELECT `perpage_submissions` FROM `'.TABLE_PREFIX.'mod_form_settings`  ';
193
$sql .= 'WHERE `section_id` = '.(int)$section_id.' ';
194
//$sql .= 'ORDER BY `submitted_when` ASC ';
195
$limit = $database->get_one($sql);
196 560 Ruebenwurz
197 1714 Luisehahne
$page = 1;
198
if(isset($_GET['page']) && is_numeric(trim($_GET['page'])))
199
{
200
	$page = intval(mysql_real_escape_string($_GET['page']));
201
}
202 560 Ruebenwurz
203 1714 Luisehahne
// How many adjacent pages should be shown on each side?
204
$adjacents = 1;
205 560 Ruebenwurz
206 1714 Luisehahne
$startrow = ($page * $limit) - ($limit);
207
208 1584 Luisehahne
$sql  = 'SELECT s.*, u.`display_name`, u.`email` ';
209 1582 Luisehahne
$sql .=            'FROM `'.TABLE_PREFIX.'mod_form_submissions` s ';
210
$sql .= 'LEFT OUTER JOIN `'.TABLE_PREFIX.'users` u ';
211
$sql .= 'ON u.`user_id` = s.`submitted_by` ';
212
$sql .= 'WHERE s.`section_id` = '.(int)$section_id.' ';
213 1714 Luisehahne
$sql .= 'ORDER BY s.`submitted_when` DESC ';
214
//$sql .= "LIMIT $startrow,$limit ";
215 1582 Luisehahne
216 1553 Luisehahne
if($query_submissions = $database->query($sql)) {
217 1714 Luisehahne
    $totalrows = $query_submissions->numRows();
218
219
// set template file and assign module and template block
220
	$oTpl = new Template(dirname(__FILE__).'/htt','keep');
221
	$oTpl->set_file('page', 'OverviewSubmission.htt');
222
	$oTpl->debug = false; // false, true
223
	$oTpl->set_block('page', 'main_block', 'main');
224
// generell vars
225
	$oTpl->set_var(array(
226
		'TEXT_SUBMISSIONS' => $TEXT['SUBMISSIONS'],
227
		'WB_URL' => WB_URL,
228
		'THEME_URL' => THEME_URL,
229
		'MESSAGE_VALUE' => '',
230
		'PAGINATION' => '',
231
		'PAGE_ID' => $page_id,
232
		'SECTION_ID' => $section_id,
233
		'TEXT_SUBMITTED' => $TEXT['SUBMITTED'],
234
		'TEXT_USER' => $TEXT['USER'],
235
		'TEXT_EMAIL' => $TEXT['EMAIL'],
236
		'MOD_FORM_FROM' => $MOD_FORM['FROM'],
237
		'TEXT_NONE_FOUND' => '',
238 1724 Luisehahne
		'SUBMISSION_ID' => '',
239
		'SUBMISSION_CREATE_WHEN' => '',
240
		'SUBMISSION_BY' => '',
241
		'SUBMISSION_EMAIL' => '',
242
		'loop_submmission' => '',
243 1714 Luisehahne
		)
244
	);
245
246 1724 Luisehahne
//	$oTpl->set_block('main_block', 'language_list_block', 'language_list');
247
	$oTpl->set_block('main_block', 'loop_submmission_block', 'loop_submmission');
248 1553 Luisehahne
	if($query_submissions->numRows() > 0) {
249 1714 Luisehahne
//print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
250
//print_r( $_SERVER ); print '</pre>'; // flush ();sleep(10); die();
251
		if($startrow > 0  ){
252
			$query_submissions->seekRow($startrow);
253
		} else {
254
			$query_submissions->rewind();
255
		}
256 1553 Luisehahne
		// List submissions
257 1714 Luisehahne
        $currentrow = 0;
258 1553 Luisehahne
		$row = 'a';
259 1724 Luisehahne
//    	$oTpl->set_block('main_block', 'loop_submmission_block', 'loop_submmission');
260 1714 Luisehahne
		while($submission = $query_submissions->fetchRow(MYSQL_ASSOC) )
261
        {
262
			$currentrow++;
263 1584 Luisehahne
	        $submission['display_name'] = (($submission['display_name']!=null) ? $submission['display_name'] : '');
264
			$sBody = $submission['body'];
265
			$regex = "/[a-z0-9\-_]?[a-z0-9.\-_]+[a-z0-9\-_]?@[a-z0-9.-]+\.[a-z]{2,}/iU";
266
			preg_match ($regex, $sBody, $output);
267 1624 Luisehahne
// workout if output is empty
268
			$submission['email'] = (isset($output['0']) ? $output['0'] : '');
269 1714 Luisehahne
			$querystr = 'page='.$page.'&amp;page_id='.$page_id.'&amp;section_id='.$section_id.'&amp;submission_id='.$admin->getIDKEY($submission['submission_id']);
270
			$row = $row=='a' ? 'b' : 'a';
271
272
			$oTpl->set_var('ROW_BIT',$row);
273
			$oTpl->set_var('QUERYSTR', $querystr);
274
			$oTpl->set_var('TEXT_ARE_YOU_SURE', url_encode($TEXT['ARE_YOU_SURE']));
275
			$oTpl->set_var('SUBMISSION_IDKEY', $admin->getIDKEY($submission['submission_id']));
276
			$oTpl->set_var('TEXT_DELETE', $TEXT['DELETE']);
277
			$oTpl->set_var('PAGE', $page);
278
			$oTpl->set_var('TEXT_OPEN', $TEXT['OPEN']);
279
			$oTpl->set_var('SUBMISSION_ID', $submission['submission_id']);
280
			$oTpl->set_var('SUBMISSION_CREATE_WHEN', gmdate(DATE_FORMAT.', '.TIME_FORMAT, $submission['submitted_when']+TIMEZONE ));
281
			$oTpl->set_var('SUBMISSION_BY', $submission['display_name']);
282
			$oTpl->set_var('SUBMISSION_EMAIL', $submission['email']);
283
284
			$oTpl->parse('loop_submmission', 'loop_submmission_block', true);
285
286
			if ($currentrow==$limit) { break;}
287 560 Ruebenwurz
		}
288 1714 Luisehahne
        $script_name = $_SERVER['SCRIPT_NAME'];
289
        //include_once((dirname(__FILE__)) .'/DiggPagination.php');
290
        $pagination = m_form_DiggPagination::Pager($page,$totalrows,$limit,$adjacents,$script_name);
291
    	$oTpl->set_var(array(
292
    		'PAGINATION' => $pagination,
293
    		)
294
    	);
295
296 1553 Luisehahne
	} else {
297 1724 Luisehahne
    	$oTpl->set_block('loop_submmission_block', '');
298
		$oTpl->set_var('TEXT_NONE_FOUND', $TEXT['NONE_FOUND']);
299 1714 Luisehahne
    }
300 1582 Luisehahne
} else {
301
	echo $database->get_error().'<br />';
302
	echo $sql;
303 1714 Luisehahne
304 1582 Luisehahne
}
305 1714 Luisehahne
306
// Parse template object
307
$oTpl->parse('main', 'main_block', false);
308
$output = $oTpl->finish($oTpl->parse('output', 'page'));
309
unset($oTpl);
310
print $output;
311
$output = '';