示例#1
0
文件: event.php 项目: epto/webgui8
function updateUserList() {
	global $DBH;
	global $WEBGUI;
	
	dbquery($DBH,"SELECT id,name, (SELECT name FROM `ewggroup` WHERE `ewguser`.`group`=`ewggroup`.`id` LIMIT 1) as 'group' FROM `ewguser` WHERE 1 ORDER BY `name` ASC");
	$WEBGUI['win']['data']['main']['usr'] = array();
	while($db=dbget($DBH)) $WEBGUI['win']['data']['main']['usr'][] = $db;
	}
示例#2
0
文件: webgui.php 项目: epto/webgui8
function WGAddToForm(&$obj,$type,$name,$caption,$value=null,$par=false) {
	global $ini;
	global $MODULES;
	global $DBH;
	$formTemplate=array();
	if (!is_array($par)) $par=array();
	$x=WGLang();
	$x=$_SERVER['DOCUMENT_ROOT'].'/etc/form/tpl-'.$x.'.json';
	if ($x!='_D_' and !file_exists($x)) $x=$_SERVER['DOCUMENT_ROOT'].'/etc/form/tpl-_D_.json';
	
	if ($par['dbquery'] and $par['val'] and $par['text']) {
		dbquery($DBH,$par['dbquery']);
		while($db=dbget($DBH)) {
			$par['v.'. @$db[ $par['val'] ] ] = @$db[ $par['text'] ];
			}
		}	
	
	if (file_exists($x)) {
		$formTemplate = @file_get_contents($x);
		if ($formTemplate!==false) $formTemplate=json_decode($formTemplate,true);
		if (!is_array($formTemplate)) $formTemplate=array();
		}
	
	if (isset($par['tpl'])) {
		if ($par['tpl']!='no') {
			if (isset($formTemplate[$par['tpl']])) $par=array_merge($formTemplate[$par['tpl']],$par);
			}
		} else {
			$x=strtoupper($type);
			if (isset($formTemplate[$x])) $par=array_merge($formTemplate[$x],$par);
		}
	
	if (isset($MODULES['form'][$type])) {
		$x = array(
			't'	=>	$type,
			'c'	=>	$caption,
			'n'	=>	$name,
			'r'	=>	$par['reg'] ? $par['reg'] : false,
			'f'	=>	$par['req']!=false,
			'par'=>	$par,
			'v'	=>	$value |=null ? $value : "",
			'h'	=> '')
			;
		
		$f = "EWGMOD_FORM_{$type}_OnCreate";
		$x = $f($x,$obj['html']);
		if ($x) $obj['obj'][]= $x;
		return;		
		}
	
	if ($obj['connect']===false) {
		$connect=false;
		} else {
			$connect=$obj['name'].'.'.$name;
		}
	
	$html=$obj['html'];
		
	$tv=' string text int float bool font color url image enum time date mail password send title info hidden hcolor captcha ';
	$dlg=' font color image ';
		
	if (strpos($type."\n",".dlg\n")===false) {
		$type=str_replace(' ','',$type);
		if (strpos($tv," $type ")===false) FatalError("Unknown form element type type: `$type` in `$caption`");
		$isDialog= strpos($dlg," $type ")!==false;
		} else {
		$isDialog=true;	
		}
	
	if ($type=='enum' and !is_array($par)) FatalError("Invalid enum in `$caption`");
	
	
	
	$hCls='EWGInputT'.htmlspecialchars($type,ENT_QUOTES); 
			
	if (strpos(' string int float url time date mail password hidden hcolor '," $type ")!==false) { //bool non setta a 0 
			
		$t='text';
		if (strpos(' hcolor '," $type ")!==false) $t=substr($type,1);
		if ($type=='password') $t='password';
		if ($type=='hidden') $t='hidden';
		if ($type=='bool') $t='checkbox';
		$h='<input type="'.$t.'" name="'.htmlspecialchars($name,ENT_QUOTES).'" class="'.$hCls.'" value="'.htmlspecialchars($value!==null ? $value : "",ENT_QUOTES).'" ';
		//
		if (isset($par['err'])) $h.='data-wgerr="'.htmlspecialchars($par['err'],ENT_QUOTES).'" ';
		if (isset($par['lmin'])) $h.='data-wglmin="'.htmlspecialchars($par['lmin'],ENT_QUOTES).'" ';
		if (isset($par['lmax'])) $h.='data-wglmax="'.htmlspecialchars($par['lmax'],ENT_QUOTES).'" ';
		if ($connect) $h.='data-wgconnect="'.htmlspecialchars($connect,ENT_QUOTES).'" ';
		if (@$par['fac']==0) $h.='data-wgreq="1" ';
		
		if ($type=='int') @$par['reg']='^[0-9]{1,16}$';
		if ($type=='float') @$par['reg']='^[0-9]{1,10}[\.]{1}[0-9]{1,8}|[0-9]{1,8}$';
		
		if ($type=='date') {
			$dm = isset($ini['webgui']['datemode']) ? $ini['webgui']['datemode'] : false;
			if (isset($par['mode'])) $dm=$par['mode'];
			if ($dm===false) $dm=='dmy';
			$dm = strtolower(trim($dm,' '));
			$dm=str_replace(array(' ','/','-','\''),'',$dm);
			if (strlen($dm)!=3) $dm='mdy';
			$t0=array();
			$t1=array();
			$t2=array();
			$jm = strlen($dm);
			for ($jj=0;$jj<$jm;$jj++) {
					$ch0 = $dm[$jj];
					if ($ch0=='d') {
					$t0[] = "DD";
					$t1[] = '([1-9]{1}|[012]{1}[0-9]{1}|3[01]{1})';	
					$t2[] = 0;
					}
					
				if ($ch0=='m') {
					$t0[] = "MM";
					$t1[] = '([1-9]{1}|0[1-9]{1}|1[012]{1})';
					$t2[] = 1;
					}
					
				if ($ch0=='y') {
					$t0[] = "YYYY";
					$t1[] = '([0-9]{4})';
					$t2[] = 2;
					}
				}
			
			@$par['reg']='^'.implode('\/',$t1).'$';
			$par['ord'] = $t2;
			if (!isset($par['placeholder'])) $par['placeholder']=implode('/',$t0);
			}
			
		if ($type=='time') {
			@$par['reg']='^([0-2]{0,1}[0-9]{1})\:([0-5]{0,1}[0-9]{1})$';
			if (!isset($par['placeholder'])) $par['placeholder']='HH:MM';
			}
		if ($type=='mail') @$par['reg']='^[^\"\&\!\'\`\?\^\#\+\@\s]{1,40}\@[a-zA-Z0-9\_\-\.]{1,40}\.[a-zA-Z]{2,6}$';
		if ($type=='url') @$par['reg']='^http[s]{0,1}\:\/\/[0-9a-zA-Z\_\-\.]{1,80}\.[a-zA-Z]{1,16}';
		
		if (isset($par['placeholder'])) $h.='placeholder="'.htmlspecialchars($par['placeholder'],ENT_QUOTES).'" ';			
		
		if (isset($par['reg'])) {
			$h.='data-wgreg="'.htmlspecialchars(trim($par['reg'],"\t\r\n "),ENT_QUOTES).'" ';
			}
		
		$h=trim($h,' ').'>';	
			
		if (isset($par['phpreg'])) $par['reg']=$par['phpreg'];
				
		$obj['obj'][]=array(
			'hid'=>	$type=='hidden',
			't'	=>	$type,
			'c'	=>	$caption,
			'n'	=>	$name,
			'r'	=>	$par['reg'] ? $par['reg'] : false,
			'f'	=>	$par['req']!=false,
			'par'=>	$par,
			'v'	=>	$value |=null ? $value : "",
			'h'	=> $html ? $h : false)
			;
		}
		
	if ($type=='enum') {
		if ($html) {
			$h='<select name="'.htmlspecialchars($name,ENT_QUOTES).'" class="'.$hCls.'"';
			if ($connect) $h.=' data-wgconnect="'.htmlspecialchars($connect,ENT_QUOTES).'"';
			$h.='>';
			foreach($par as $k => $v) {
				if (strpos($k,'.')===false) continue;
				list($fuffa,$k)=explode('.',$k,2);
				$h.='<option value="'.htmlspecialchars($k,ENT_QUOTES).'"'.( $k === $value ? ' default ': '').'>'.htmlspecialchars($v,ENT_QUOTES)."</option>\n";
				}
			$h.='</select>';
		} else $h=false;
		$obj['obj'][]=array(
			'c'	=>	$caption,
			'n'	=>	$name,
			'r'	=>	$par['reg'] ? $par['reg'] : false,
			'f'	=>	$par['req']!=false,
			'v'	=>	$value |=null ? $value : "",
			'h'	=> $h)
			;
		}
	
	if ($type=='captcha') {
		$capid=md5($obj['formID'].'/'.$name);
				
		if ($html) {
			$alfa="QWERTYUIPADYFHTLMNVX234679234679234679";
			$ecx=strlen($alfa)-1;
			$code='';
			for ($a=0;$a<6;$a++) $code.=$alfa[mt_rand(0,$ecx)];
			$code=strtolower($code);
			if (!is_array($_SESSION['EWGCaptcha'])) $_SESSION['EWGCaptcha']=array();
			$_SESSION['EWGCaptcha'][$capid]=$code;
			}
			
		if ($html) {
			$h='<div class="EWGCaptchaCont">';
			if ($par['placeholder']) $h.='<div class="EWGCaptchaInfo">'.nl2br(htmlspecialchars($par['placeholder'],ENT_QUOTES),false).'</div>';
			$h.='<img class="EWGCaptcha" data-wgspec="imgclr" src="/bin/php/captcha.php?id='.$capid.'&t='.crc32(microtime()).'"';
			if ($par['placeholder']) $h.=' title="'.htmlspecialchars($par['imgtext'],ENT_QUOTES).'"';
			$h.='>';
			$h.='<input class="EWGCaptchaInput" type="text" name="'.htmlspecialchars($name,ENT_QUOTES).'" class="'.$hCls.'"';
			$h.=' value="" data-wgsha1="'.sha1($code.$capid).'" data-wgsalt="'.$capid.'"';
			if ($connect) $h.=' data-wgconnect="'.htmlspecialchars($connect,ENT_QUOTES).'"';
			if ($par['err']) $h.=' data-wgerr="'.htmlspecialchars($par['err'],ENT_QUOTES).'"';
			$h.='></div>';
			} else {
			$h=false;
			}
			
		$obj['obj'][]=array(
			't'	=>	'captcha',
			'c'	=>	$caption,
			'n'	=>	$name,
			'cap'=> $capid,
			'ver'=>	$code,
			'h'	=> $h)
			;
		}
		
	if ($type=='text') {
		if ($html) {
			$h='<div class="EWGFormText">'.htmlspecialchars($caption,ENT_QUOTES).'</div>';
			$h.='<textarea name="'.htmlspecialchars($name,ENT_QUOTES).'" class="'.$hCls.'"';
			if ($par['height']) $h.=' style="height: '.intval($par['height']).'px;"';
			
			if (isset($par['err'])) $h.='data-wgerr="'.htmlspecialchars($par['err'],ENT_QUOTES).'" ';
			if (isset($par['lmin'])) $h.='data-wglmin="'.htmlspecialchars($par['lmin'],ENT_QUOTES).'" ';
			if (isset($par['lmax'])) $h.='data-wglmax="'.htmlspecialchars($par['lmax'],ENT_QUOTES).'" ';
			
			///if ($connect) $h.=' data-wgconnect="'.htmlspecialchars($connect,ENT_QUOTES).'"';
			//NON SUPPORTA WGCONNECT
			$h=trim($h,' ').'>';
			$h.=nl2br(htmlspecialchars($value!==null ? $value : "",ENT_QUOTES),false);
			$h.='</textarea>';
		} else $h=false;
		$obj['obj'][]=array(
			'c'	=>	' ',
			'n'	=>	$name,
			's'	=>	'EWGFormTextTD',
			'r'	=>	$par['reg'] ? $par['reg'] : false,
			'f'	=>	$par['req']!=false,
			'v'	=>	$value |=null ? $value : "",
			'h'	=> $h)
			;
		}
	
	if ($type=='info') {
		if ($html) {
			$h='<div class="EWGFormINFO">'.nl2br(htmlspecialchars($caption,ENT_QUOTES),false).'</div>';
			} else $h=false;
		$obj['obj'][]=array(
			'c'	=>	' ',
			's'	=>	'EWGFormINFOTD',
			'h'	=> $h)
			;
		}
	
	if ($type=='title') {
		if ($html) {
			$h='<div class="EWGFormTITLE">'.nl2br(htmlspecialchars($caption,ENT_QUOTES),false).'</div>';
			} else $h=false;
		$obj['obj'][]=array(
			'c'	=>	' ',
			's'	=>	'EWGFormTITLETD',
			'h'	=> $h)
			;
		}
	
	if ($type=='send') {
		if ($html) {
			$x= $caption!='' ? $caption : $value;
			if ($x=='') $ok='OK';
			$h='<input type="submit" class="EWGFormSend" value="'.htmlspecialchars($caption!='' ? $caption : $value,ENT_QUOTES).'" name="'.htmlspecialchars($name,ENT_QUOTES).'">';
			} else $h=false;
	
		$obj['obj'][]=array(
			'c'	=>	'',
			'n'	=>	$name,
			'r'	=>	$par['reg'] ? $par['reg'] : false,
			'f'	=>	$par['req']!=false,
			's'	=>	'EWGFormSendTD',
			'v'	=>	$value |=null ? $value : "",
			'h'	=> $h)
			;
							
		if (isset($par['action'])) $obj['actok'] = $par['action']; 
		if (isset($par['error'])) $obj['acterr'] = $par['error']; 
		}
		
	if ($isDialog!==false) {
		if ($html) {
		
			$h='<div data-wgdialog="'.htmlspecialchars($type,ENT_QUOTES).'" data-wgname="'.htmlspecialchars($name,ENT_QUOTES).'" data-wgdata="'.htmlspecialchars($connect,ENT_QUOTES).'"';
			if ($value!==null) {
				if (is_array($value)) {
					$h.=' data-wgvaluej="'.htmlspecialchars(json_encode($value),ENT_QUOTES).'"';
					} else {
					$h.=' data-wgvalue="'.htmlspecialchars($value,ENT_QUOTES).'"';	
					}
				}
			if (is_array($par)) {
				foreach($par as $k => $v) {
					if (strpos($k,'wg')===0 and preg_match('/^[a-z]{2,40}$/',$k)!=0) {
						$h.=" data-$k=\"".htmlspecialchars($v,ENT_QUOTES)."\"";
						}
					}
				}
		
		$h=trim($h,' ');
		$h.='></div>';
		
		} else $h=false;
		$obj['obj'][]=array(
			'c'	=>	$caption,
			'n'	=>	$name,
			'v'	=>	$value |=null ? $value : "",
			'f'	=>	$par['req']!=false,
			'h'	=> $h)
			;
		}
	}
示例#3
0
文件: libdb.php 项目: epto/webgui8
function dbexistsarr(&$hx,$tabe,$ary) {
	dbsearch($hx,$tabe,$ary,1);
	return dbget($hx);
	}