3tl.tabbuilder /editor/action.php

Language PHP Lines 464
MD5 Hash 0221e1db61fe1d8d1c876bcfa49aa939 Estimated Cost $6,700 (why?)
Repository https://bitbucket.org/3tierlogic/3tl.tabbuilder.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php

	// includes
	require_once('config.php');
	require_once('functions.php');


	# WHAT TO DO...
	switch ( $_REQUEST['act'] )
	{


		############## CHECK USER TABS LIMIT #############

		case 'tabs_limit':
			$fbUserId = $_REQUEST['user_id'];
			$fbPageId = $_REQUEST['fan_page_id'];
			// get limit number
			$query = "SELECT tabs_limit FROM users WHERE fb_id = '".$fbUserId."' LIMIT 1 ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			$limit = mysql_result( $query, 0 );
			// get created tabs number
			$query = "SELECT COUNT(*) FROM pages WHERE type = 'tab' AND fan_page_id = '".$fbPageId."' ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			$tabsNumber = mysql_result( $query, 0 );
			// show result
			if ( $limit > $tabsNumber ) echo 'ok'; else echo 'limit';
			break;




		############### CHECK TAB NAME ################

		case 'check_tab_name':
			// check if a user already has a tab with a provided name
			$query = "SELECT name FROM pages WHERE user_id = '" . $_REQUEST['fb_user_id'] . "'
								AND BINARY name = '" . escapeStr( $_REQUEST['name'] ) . "' ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			if ( mysql_num_rows( $query ) == 0 ) echo 'ok';
			break;




		################# CREATE NEW TAB ################

		case 'create_tab':
			// before creating a new tab, we have to check, if such tab doesn't exist
			$query = "SELECT * FROM pages WHERE user_id = '".$_REQUEST['user_id']."'
								AND fan_page_id = '".$_REQUEST['page_id']."'
								AND app_id = '".$_REQUEST['app_id']."' LIMIT 1 ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			// no similar records found
			if ( ! mysql_num_rows( $query ) ) {
				$name = escapeStr( $_REQUEST['name'] );
				// add new tab into "pages" table
				mysql_query("INSERT INTO pages VALUES ( 0,
											'".$_REQUEST['user_id']."',
											'".$_REQUEST['page_id']."',
											'".$_REQUEST['app_id']."',
											'0', 'tab', '".$name."', '', '', '', '', '', '', '', '0', '0', '0', '0'
											);") or exit( mysql_error() );
				// get the added tab id
				$newTab = ars_getPageInfo();
				// create new record with campaign properties in "sp_campaign_info" table
				mysql_query("INSERT INTO sp_campaign_info VALUES (
											'".$newTab['id']."',
											'".$_REQUEST['partner_id']."',
											'', '', '', '', '', '', '', '', '',
											'', '', '', '', '', '', '', '', '', '',
											'', '', '', '', '', '', '', '', '', '',
											'', '', '', '-1',
											'".$name."'
											);") or exit( mysql_error() );
				// show the added tab id
				echo $newTab['id'];
			}
			break;




		################# RENAME TAB ##################

		case 'rename_tab':
			// change name
			mysql_query("UPDATE pages SET
										name = '". escapeStr( $_REQUEST['name'] ) ."'
										WHERE id = '".$_REQUEST['id']."' AND app_id = '".$_REQUEST['app_id']."'
										") or exit( mysql_error() );
			echo 'ok';
			break;




		################## DELETE PAGE ##################

		case 'delete_page':
			// delete page children
			ars_delete( $_REQUEST['id'], "parent_id" );
			// delete page itself
			ars_delete( $_REQUEST['id'] );
			// redirection
			header ( 'Location: dashboard.php' );
			break;




		################ AJAX PAGE LOAD #################

		case 'load_page':
			// get content
			$query = "SELECT * FROM pages WHERE id='".$_REQUEST['id']."' LIMIT 1 ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			$content = mysql_fetch_assoc( $query );
			// show the whole content
			echo $content['content_nonfans'];
			echo $content['content_fans'];
			echo $content['content_contest_fans'];
			echo $content['content_contest_form'];
			echo $content['content_contest_ugc_form'];
			echo $content['content_contest_ugc_gallery'];
			echo $content['content_contest_thank'];
			// delete all unused files
			ars_deleteUnusedFiles( $_REQUEST['id'] );
			break;




		################# AJAX PAGE SAVE #################

		case 'save_page':
			$cNonFans = ars_urldecode( $_REQUEST['content_nonfans'] );
			$cFans = ars_urldecode( $_REQUEST['content_fans'] );
			$cContestFans = ars_urldecode( $_REQUEST['content_contest_fans'] );
			$cContestForm = ars_urldecode( $_REQUEST['content_contest_form'] );
			$cContestUGCForm = ars_urldecode( $_REQUEST['content_contest_ugc_form'] );
			$cContestUGCGallery = ars_urldecode( $_REQUEST['content_contest_ugc_gallery'] );
			$cContestThank = ars_urldecode( $_REQUEST['content_contest_thank'] );
			mysql_query("UPDATE pages SET
										content_nonfans = '".$cNonFans."',
										content_fans = '".$cFans."',
										content_contest_fans = '".$cContestFans."',
										content_contest_form = '".$cContestForm."',
										content_contest_ugc_form = '".$cContestUGCForm."',
										content_contest_ugc_gallery = '".$cContestUGCGallery."',
										content_contest_thank = '".$cContestThank."',
										contest = '". $_REQUEST['contest'] ."',
										ugc = '". $_REQUEST['ugc'] ."',
										saved = '1'
										WHERE id = '".$_REQUEST['id']."'
										") or exit( mysql_error() );
			// delete all unused files
			ars_deleteUnusedFiles( $_REQUEST['id'] );
			// update contest properties
			mysql_query("UPDATE sp_campaign_info SET
										campaign_description = '". escapeStr( $_REQUEST['contest_descr'] ) ."',
										campaign_start_time = '". $_REQUEST['contest_start'] ."',
										campaign_end_time = '". $_REQUEST['contest_end'] ."',
										campaign_voting_start_time = '". $_REQUEST['contest_voting_start'] ."',
										campaign_voting_end_time = '". $_REQUEST['contest_voting_end'] ."',
										campaign_vote_frequency = '". $_REQUEST['contest_voting_times'] ."',
										campaign_is_check_reentry = '". $_REQUEST['contest_entries'] ."',
										campaign_is_allow_child = '". $_REQUEST['contest_age'] ."',
										campaign_update_time = NOW()
										WHERE campaign_sid = '".$_REQUEST['id']."'
										") or exit( mysql_error() );
			// if contest is enabled and contest create time is not set yet - save current datetime
			if ( $_REQUEST['contest'] == '1' ) {
				$query = "SELECT campaign_create_time FROM sp_campaign_info
									WHERE campaign_sid = '".$_REQUEST['id']."' LIMIT 1 ";
				$query = mysql_query( $query ) or exit( mysql_error() );
				$createTime = mysql_result( $query, 0 );
				if ( $createTime == '0000-00-00 00:00:00' ) {
					mysql_query("UPDATE sp_campaign_info SET
												campaign_create_time = NOW()
												WHERE campaign_sid = '".$_REQUEST['id']."'
												") or exit( mysql_error() );
				}
			}
			break;




		########## AJAX DEACTIVATE CONTEST FIELDS ###########

		// it is needed to check if a contest form field still exist;
		// fields will be activated later by "save_contest_config" case
		case 'deactivate_contest_fields':
			mysql_query("UPDATE sp_campaign_config SET cpfldcfg_is_valid = '0'
										WHERE campaign_sid = '".$_REQUEST['id']."'
										") or exit( mysql_error() );
			break;




		############# AJAX SAVE CONTEST CONFIG #############

		case 'save_contest_config':

			// field is stored for the first tme
			if ( $_REQUEST['config_id'] == '' ) {
				mysql_query("INSERT INTO sp_campaign_config VALUES ( 0,
											'',
											'".$_REQUEST['id']."',
											'".$_REQUEST['label']."',
											'".$_REQUEST['name']."',
											'',
											'".$_REQUEST['required']."',
											'', '', '', '', '',
											'".$_REQUEST['error']."',
											'', '', '', '', '', '', '', '1', NOW(), NOW()
											);") or exit( mysql_error() );
				// show added field id
				$query = "SELECT * FROM sp_campaign_config ORDER BY cpfldcfg_sid DESC LIMIT 1";
				$query = mysql_query( $query ) or exit( mysql_error() );
				echo mysql_result( $query, 0 );
			}
			// field has been already stored
			else {
				mysql_query("UPDATE sp_campaign_config SET
											cpfldcfg_label = '".$_REQUEST['label']."',
											cpfldcfg_var_name = '".$_REQUEST['name']."',
											cpfldcfg_is_mandatory = '".$_REQUEST['required']."',
											cpfldcfg_invalid_message = '".$_REQUEST['error']."',
											cpfldcfg_is_valid = '1',
											cpfldcfg_update_time = NOW()
											WHERE cpfldcfg_sid = '".$_REQUEST['config_id']."'
											") or exit( mysql_error() );
			}
			break;




		################ AJAX PAGE PUBLISH ###############

		case 'publish_page':
			$query = mysql_query("UPDATE pages SET published = '1' WHERE id = '".$_REQUEST['id']."' ")
								or exit( mysql_error() );
			break;




		############### AJAX PAGE UNPUBLISH ##############

		case 'unpublish_page':
			$query = mysql_query("UPDATE pages SET published = '0' WHERE id = '".$_REQUEST['id']."' ")
								or exit( mysql_error() );
			break;




		################ AJAX DELETE FILE ################

		case 'delete_file':
			ars_delete( $_REQUEST['id'] );
			break;




		############### AJAX GET ID BY NAME ###############

		case 'get_id_by_name':
			$query = "SELECT id FROM pages WHERE name='".$_REQUEST['name']."' ";
			$query = mysql_query( $query ) or exit( mysql_error() );
			echo mysql_result( $query, 0 );
			break;




		########### AJAX SAVE BACKGROUND IMAGE ###########

		case 'save_bg':
			if ( $_REQUEST['bgToUpdate'] )
				echo ars_updateFile( 'bgImage', $_REQUEST['bgToUpdate'] );
			else
				echo ars_uploadFile( 'bgImage', $_REQUEST['pageID'], 'bg' );
			break;




		############# AJAX ADD CONTENT IMAGE #############

		case 'content_image':
			if ( $_REQUEST['imageToUpdate'] )
				echo ars_updateFile( 'contentImage', $_REQUEST['imageToUpdate'] );
			else
				echo ars_uploadFile( 'contentImage', $_REQUEST['pageID'], 'attachment' );
			break;




		############ AJAX ADD CONTACT FORM #############

		case 'content_contact_form':
			if ( $_REQUEST['contactButtonToUpdate'] )
				echo ars_updateFile( 'contactButtonImage', $_REQUEST['contactButtonToUpdate'] );
			else
				echo ars_uploadFile( 'contactButtonImage', $_REQUEST['pageID'], 'attachment' );
			break;




		############ AJAX ADD EMAIL BUTTON #############

		case 'content_email':
			if ( $_REQUEST['emailToUpdate'] )
				echo ars_updateFile( 'emailButtonImage', $_REQUEST['emailToUpdate'] );
			else
				echo ars_uploadFile( 'emailButtonImage', $_REQUEST['pageID'], 'attachment' );
			break;




		############ AJAX ADD TWITTER SHARE ############

		case 'content_twitter_share':
			if ( $_REQUEST['twitterShareToUpdate'] )
				echo ars_updateFile( 'twitterShareButtonImage', $_REQUEST['twitterShareToUpdate'] );
			else
				echo ars_uploadFile( 'twitterShareButtonImage', $_REQUEST['pageID'], 'attachment' );
			break;




		########### AJAX ADD CONTEST BUTTON #############

		case 'contest_button':
			if ( $_REQUEST['contestBtnImageToUpdate'] )
				echo ars_updateFile( 'contestBtnImage', $_REQUEST['contestBtnImageToUpdate'] );
			else
				echo ars_uploadFile( 'contestBtnImage', $_REQUEST['pageID'], 'attachment' );
			break;




		########## AJAX ADD UGC CONTEST IMAGE ###########

		case 'contest_ugc_image':
			// one ugc entry can have only one photo form one user,
			// so if there's a photo with the id, we must update it
			$query = "SELECT * FROM pages WHERE type = 'ugc' AND saved = '0'
								AND parent_id = '".$_REQUEST['pageID']."' LIMIT 1";
			$query = mysql_query( $query ) or exit( mysql_error() );
			if ( mysql_num_rows( $query ) > 0 ) {
				$uploadedPhoto = mysql_fetch_assoc( $query );
				echo ars_updateFile( 'contestUGCUploadImg', $uploadedPhoto['id'] );
			} else {
				echo ars_uploadFile( 'contestUGCUploadImg', $_REQUEST['pageID'], 'ugc' );
			}
			break;




		######## AJAX VOTE FOR UGC CONTEST IMAGE #########

		case 'contest_ugc_image_vote':
			// get ugc_sid and ugc_campaign_sid from sp_campaign_ugc table
			$ugc_img_sid = getImgUgcSidAndCampaignSid( $_REQUEST['img_name'], 'img' );
			$ugc_campaign_sid = getImgUgcSidAndCampaignSid( $_REQUEST['img_name'], 'campaign' );
			// check voting ability
			$vAbility = checkVotingAbility( $ugc_campaign_sid, $_REQUEST['fb_user_id'], $ugc_img_sid );
			if ( $vAbility !== true ) {
				echo $vAbility;
			}
			else {
				mysql_query("INSERT INTO sp_campaign_ugc_vote VALUES ( 0,
											'".$ugc_img_sid."',
											'".$_REQUEST['fb_user_id']."',
											NOW(),
											'".$ugc_campaign_sid."',
											'".$_REQUEST['user_ip']."',
											''
											);") or exit( mysql_error() );
				echo 'ok';
			}
			break;




		########## AJAX ADD IMAGE TO COOL SLIDER #########

		case 'content_coolslider_image':
			echo ars_uploadFile( 'coolSliderImage', $_REQUEST['pageID'], 'attachment' );
			break;




		############ AJAX ADD FB POST TO FEED ############

		case 'content_fb_post_feed':
			// post image
			if ( $_REQUEST['postFeedImgToUpdate'] )
				echo ars_updateFile( 'postFeedImgImage', $_REQUEST['postFeedImgToUpdate'] );
			else
				echo ars_uploadFile( 'postFeedImgImage', $_REQUEST['pageID'], 'attachment' );
			// divider for parsing
			echo '|';
			// custom button
			if ( $_REQUEST['postFeedBtnToUpdate'] )
				echo ars_updateFile( 'postFeedBtnImage', $_REQUEST['postFeedBtnToUpdate'] );
			else
				echo ars_uploadFile( 'postFeedBtnImage', $_REQUEST['pageID'], 'attachment' );
			break;




		############## AJAX ADD FB INVITE ###############

		case 'content_invite':
			if ( $_REQUEST['inviteToUpdate'] )
				echo ars_updateFile( 'inviteBtnImage', $_REQUEST['inviteToUpdate'] );
			else
				echo ars_uploadFile( 'inviteBtnImage', $_REQUEST['pageID'], 'attachment' );
			break;




		################# GET RSS FEED #################

		case 'get_rss':
			echo file_get_contents( $_REQUEST['url'] );
			break;




		############ GET GOOGLE MAPS COORDS ############

		case 'get_gm_coords':
			$url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=';
			$url .= $_REQUEST['address'];
			$url = str_replace( ' ', '+', $url );
			echo file_get_contents( $url );
			break;


	} // switch


	// документ UTF-8
?>
Back to Top