CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
checkduplicates.php80 linesDownload Raw Back to public
1<?php 2@ini_set("display_errors","1");3@ini_set("display_startup_errors","1");4 5require_once("include/dbcommon.php");6header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 7 8$shortTableName = postvalue("tableName");9$table = GetTableByShort( $shortTableName );10if( !$table )11	exit(0);12 13$pageType = postvalue("pageType");14$pageName = postvalue("page");15$fieldName = postvalue("fieldName");16$fieldControlType = postvalue("fieldControlType");17$value = postvalue("value");18 19if( !Security::userHasFieldPermissions( $table, $fieldName, $pageType, $pageName, true ) )20	return;21 22$pSet = new ProjectSettings( $table, $pageType );23$denyChecking = $pSet->allowDuplicateValues( $fieldName );24 25$regEmailMode = false;26$regUsernameMode = false;27$userNameField = Security::usernameField();28if( Security::registerPage() && $table == Security::loginDataSource() ) {29	$regEmailMode = $fieldName == Security::emailField();30	$regUsernameMode = $fieldName == $userNameField;31	$denyChecking = $denyChecking && $fieldName != $userNameField && $fieldName != Security::emailField();32}33 34if( $denyChecking ) {35	$returnJSON = array( "success" => false, "error" => "Duplicated values are allowed" );36	echo printJSON( $returnJSON) ;37	return;38}39 40// set db connection41$_connection = $cman->byTable( $table );42$dataSource = getDataSource( $table, $pSet, $_connection );43$dc = new DsCommand();44 45$dc->totals = array();46$dc->totals[] = array(47	"total" => "count",48	"alias" => "count_".$fieldName,49	"field" => $fieldName,50);51 52$dc->filter = DataCondition::FieldEquals( $fieldName, $value, 0, dsCASE_DEFAULT ); 53 54// emails should always be compared case-insensitively55if( $regEmailMode ) {56	$dc->filter = DataCondition::FieldEquals( $fieldName, $value, 0, dsCASE_INSENSITIVE ); 57}58// username on register page59if( $regUsernameMode ) {60	$where = $_connection->comparisonSQL( $fieldSQL, $value, Security::caseInsensitiveUsername() );61	$dc->filter = DataCondition::FieldEquals( $fieldName, $value, 0, 62		Security::caseInsensitiveUsername() ? dsCASE_INSENSITIVE : dsCASE_STRICT );63}64 65$qResult = $dataSource->getTotals( $dc );66if( !$qResult ) {67	$returnJSON = array( "success" => false, "error" => "Error: Wrong SQL query" );68	echo printJSON( $returnJSON );69	return;70}71 72$hasDuplicates = false;73$data = $qResult->fetchAssoc();74if( $data )75	$hasDuplicates = $data[ "count_".$fieldName ] ? true : false;76 77$returnJSON = array( "success" => true, "hasDuplicates" => $hasDuplicates, "error" => "" );	78echo printJSON( $returnJSON );79return;80?>