'; $info[$field]['width']=400; $info[$field]['height']=100; break; case 'date': $info[$field]['inputtype']='date'; break; case 'time': $info[$field]['inputtype']='time'; break; case 'datetime': $info[$field]['inputtype']='datetime'; break; default: $info[$field]['inputtype']='text'; $info[$field]['width']=200; break; } } if(!strlen($info[$field]['inputtype'])){return "Unknown inputtype for fieldname ".$field;} //set a few special fields switch ($info[$field]['inputtype']){ //Checkbox case 'date': $styles['width']='80px'; $styles['font-size']='9pt'; $styles['font-family']='arial'; $info[$field]['mask']='^[0-9]{1,2}[\-\/][0-9]{1,2}[\-\/][0-9]{2,4}$'; $info[$field]['maskmsg']="Invalid date format (MM-DD-YYYY)"; //if(!isset($info[$field]['value'])){$info[$field]['value']=date("m-d-Y");} unset($info[$field]['height']); break; case 'text': unset($info[$field]['height']); break; case 'password': unset($info[$field]['height']); $info[$field]['onfocus']="this.select();"; break; case 'file': if(!isset($info[$field]['width']) || $info[$field]['width']==0){$info[$field]['width']=300;} unset($info[$field]['height']); break; case 'select': unset($info[$field]['height']); if(isset($info[$field]['width']) && (!isNum($info[$field]['width']) || $info[$field]['width']==0)){unset($info[$field]['width']);} break; case 'combo': unset($info[$field]['height']); if($params['-table']=='_fielddata' && $field=='behavior'){ $info[$field]['tvals']=wasqlGetBehaviors(); $info[$field]['dvals']=wasqlGetBehaviors(); } break; case 'multiselect': unset($info[$field]['height']); if(isset($info[$field]['width']) && (!isNum($info[$field]['width']) || $info[$field]['width']==0)){unset($info[$field]['width']);} $info[$field]['name'] = "{$field}[]"; break; case 'time': unset($info[$field]['height']); unset($info[$field]['width']); break; case 'color': unset($info[$field]['height']); $info[$field]['width']=80; break; } //set tag name if(!isset($info[$field]['name'])){$info[$field]['name']=$field;} //set displayname if(!isset($info[$field]['displayname']) || !strlen($info[$field]['displayname'])){$info[$field]['displayname']=ucfirst($field);} //set the width and height in the style attribute // style="width:100px;height:100px;font-size: if(isset($params['style'])){ $setstyles=split(';',$params['style']); foreach($setstyles as $setstyle){ $parts=split(':',$setstyle); $key=trim($parts[0]); $styles[$key]=trim($parts[1]); } unset($setstyles); } $stylekeys=array('width','height'); foreach($stylekeys as $stylekey){ if(!isset($styles[$stylekey]) && isset($info[$field][$stylekey]) && $info[$field][$stylekey] != 0){ $styles[$stylekey]=$info[$field][$stylekey] . 'px'; } } $info[$field]['style']=setStyleAttribues($styles); //Build the HTML tag //change the required attribute to _required since it messes up HTML5 if(isNum($info[$field]['required']) && $info[$field]['required']==1){ unset($info[$field]['required']); $info[$field]['_required']=1; } $tag=''; switch ($info[$field]['inputtype']){ //Checkbox - NOTE: use arrayColumns function to order vertically rather than horizontally. case 'checkbox': $selections=getDBFieldSelections($info[$field]); if(is_array($selections['tvals'])){ $name=$info[$field]['name']; $tval_count=count($selections['tvals']); $group_id="group_{$info[$field]['name']}"; if(isset($params['checkclass']) && isset($params['checkclasschecked'])){ $checkclass=$params['checkclass']; $checkclasschecked=$params['checkclasschecked']; } if(isset($params['-formname'])){$group_id .= "_{$params['-formname']}";} //show Select All if((!isset($params['-all']) || $params['-all'] != 0) && $tval_count > 1 && isNum($info[$field]['width']) && $tval_count > (integer)$info[$field]['width']){ if(isset($params['checkclass']) && isset($params['checkclasschecked'])){ $tag .= '
'."\n"; } else{ $tag .= '
'."\n"; } } $width=(integer)$info[$field]['width']; if($width==0){$width=1;} $tval_cols=arrayColumns($selections['tvals'],$width); if(is_array($selections['dvals']) && count($selections['dvals'])==count($selections['tvals'])){ $dval_cols=arrayColumns($selections['dvals'],$width); } else{$dval_cols=$tval_cols;} //put them in a table so the checkboxes line up if multiple lines $tag .= ''."\n"; $tag .= ' '."\n"; $onclick=isset($info[$field]['onclick'])?$info[$field]['onclick'].';':''; $tcount_all=count($tval_cols); foreach($tval_cols as $colindex=>$tvals){ $tag .= ' '."\n"; } $tag .= ' '."\n"; $tag .= '
'."\n"; $tcount=count($tvals); for($x=0;$x<$tcount;$x++){ $tval=$tval_cols[$colindex][$x]; $dval=$dval_cols[$colindex][$x]; $check_id="{$name}_{$colindex}-{$x}"; $ischecked=array(); if(isset($params['-formname'])){$check_id .= "_{$params['-formname']}";} $tag .= '
'."\n"; if(isset($params['checkclass']) && isset($params['checkclasschecked'])){ $tag .= ' '; $tag .= $dval; $tag .= ''; } $tag .= '
'."\n"; } $tag .= '
'."\n"; } break; case 'color': $tag .= ''; $tag .= ' '; if(strlen($info[$field]['name'])){ $colorbox=$info[$field]['name'] . '_boxdiv'; $colordiv=$info[$field]['name'] . '_imgdiv'; $colorid=$info[$field]['name'] . '_inpdiv'; } else{ $colorbox=$field . '_boxdiv'; $colordiv=$field . '_imgdiv'; $colorid=$field . '_inpdiv'; } $tag .= ' '."\n"; $tag .= ' '."\n"; $tag .= '
'; $tag .= '
'."\n"; break; case 'combo': //editable selection list if(!isset($info[$field]['width'])){$info[$field]['width']=140;} if(strlen($info[$field]['name'])){ $inputid="combo_" . $info[$field]['name']; $comboid="comboselect_" . $info[$field]['name']; } else{ $inputid="combo_" . $field; $comboid="comboselect_" . $field; } $tag .= ''."\n"; $tag .= ' '."\n"; $tag .= ' '."\n"; $tag .= ' '."\n"; $tag .= '
'."\n"; $tag .= '
'."\n"; $selections=getDBFieldSelections($info[$field]); $width=strlen($info[$field]['width'])?$info[$field]['width']:140; $tag .= '
'."\n"; if(is_array($selections['tvals'])){ for($x=0;$x'.$selections['dvals'][$x].'
'."\n"; } } $tag .= '
'."\n"; $tag .= '
'."\n"; break; case 'date': $name=$info[$field]['name']; $tagopts=$info[$field]; if(isset($params['-value'])){$tagopts['-value']=$params['-value'];} elseif(isset($params[$field])){$tagopts['-value']=$params[$field];} elseif(isset($info[$field]['value'])){$tagopts['-value']=$info[$field]['value'];} elseif(isset($_REQUEST[$field])){$tagopts['-value']=$_REQUEST[$field];} $tag .= buildFormCalendar($name,$tagopts); break; case 'datetime': $name=$info[$field]['name']; //date part $tagopts=array(); //check for value if(isset($params['-value'])){$tagopts['-value']=$params['-value'];} elseif(isset($params[$field])){$tagopts['-value']=$params[$field];} elseif(isset($info[$field]['value'])){$tagopts['-value']=$info[$field]['value'];} elseif(isset($_REQUEST[$field])){$tagopts['-value']=$_REQUEST[$field];} $tag .= buildFormCalendar("{$name}[]",$tagopts); //time part $tagopts=array(); //check for value if(isset($params['-value'])){$tagopts['-value']=$params['-value'];} elseif(isset($params[$field])){$tagopts['-value']=$params[$field];} elseif(isset($info[$field]['value'])){$tagopts['-value']=$info[$field]['value'];} elseif(isset($_REQUEST[$field])){$tagopts['-value']=$_REQUEST[$field];} //set prefix to formname if(isset($params['-formname'])){$tagopts['-prefix']=$params['-formname'];} //check for required if(isset($info[$field]['_required']) && $info[$field]['_required'] ==1){ $tagopts['-required']=1; if(!isset($tagopts['-value'])){ $tagopts['-value']=date('h:i:s'); } } $tag .= buildFormTime($info[$field]['name'],$tagopts); break; //File case 'file': //set path of where to store this file in $name=$info[$field]['name']; $path=$info[$field]['defaultval']; if(preg_match('/^\<\?(.+?)\?\>$/is',$path)){$path = trim(evalPHP($path));} if(!strlen($path)){$path='/files';} if(isset($_REQUEST["{$name}_path"]) && strlen($_REQUEST["{$name}_path"])){$path=$_REQUEST["{$name}_path"];} $tag .= ''."\n"; //remove style attribute since it is not supported unset($info[$field]['style']); $info[$field]['size']=intval((string)$info[$field]['width']/8); //autonumber on upload - appends unix timestamp to filename if(isset($info[$field]['autonumber']) || $info[$field]['tvals'] == 'autonumber' || $info[$field]['behavior'] == 'autonumber'){ $tag .= ''."\n"; } //if a value exists then display it as a link with a remove checkbox if($params['-editmode'] && strlen($info[$field]['value']) && $info[$field]['value'] != $info[$field]['defaultval']){ $val=encodeHtml($info[$field]['value']); $tag .= '
'."\n"; $tag .= ''.$val.''."\n"; $tag .= ' Remove'."\n"; $tag .= ''."\n"; $tag .= '
'."\n"; } //exit; //file tag $tag .= ''."\n"; $tag .= ''."\n"; } $selected=0; for($x=0;$x'."\n"; } $tag .= ''."\n"; $tag .= buildOnLoad("initBehaviors()"); if($selected==1 && isset($params['-formname']) && isset($info[$field]['onchange'])){ $fname=strlen($info[$field]['name'])?$info[$field]['name']:$field; $fieldstr="document.{$params['-formname']}.{$fname}."; $onchange=preg_replace('/this\./',$fieldstr,$info[$field]['onchange']); $tag .= buildOnLoad($onchange); } } break; //Password case 'password': $tag .= ''.$selections['dvals'][$x]; $tag .= ''."\n"; if(isset($info[$field]['width']) && isFactor(intval($x+1),(int)$info[$field]['width'])){ $tag .= ' '."\n".' '; } } $tag .= ' '."\n"; $tag .= ''."\n"; $tag .= buildOnLoad("setRadioLabel('{$info[$field]['name']}');"); } break; //Select case 'select': $selections=getDBFieldSelections($info[$field]); //if($field=='user_id'){echo "selections" . printValue($info[$field]);} if(is_array($selections['tvals'])){ $tag .= ''."\n"; } for($x=0;$x'."\n"; } $tag .= ''."\n"; if($selected==1 && isset($params['-formname']) && isset($info[$field]['onchange'])){ $fname=strlen($info[$field]['name'])?$info[$field]['name']:$field; $fieldstr="document.{$params['-formname']}.{$fname}."; $onchange=preg_replace('/this\./',$fieldstr,$info[$field]['onchange']); $tag .= buildOnLoad($onchange); } } break; case 'textarea': $end_div=0; //add a behavior for css, js if(!strlen($info[$field]['behavior']) && strlen($info[$field]['value'])){ //echo $info[$field]['value'];exit; if(stringContains($info[$field]['value'],'/*filetype:css*/')){ $info[$field]['behavior']='csseditor'; } elseif(stringContains($info[$field]['value'],'/*filetype:js*/')){ $info[$field]['behavior']='jseditor'; } elseif(stringContains($info[$field]['value'],'/*filetype:php*/')){ $info[$field]['behavior']='phpeditor'; } elseif(stringContains($info[$field]['value'],'/*filetype:pl*/')){ $info[$field]['behavior']='perleditor'; } elseif(stringContains($info[$field]['value'],'/*filetype:rb*/')){ $info[$field]['behavior']='rubyeditor'; } elseif(stringContains($info[$field]['value'],'/*filetype:xml*/')){ $info[$field]['behavior']='xmleditor'; } } if(strlen($info[$field]['behavior']) && $info[$field]['behavior']=='nowrap'){ $info[$field]['behavior']=''; $info[$field]['wrap']="off"; } if(strlen($info[$field]['behavior'])){ $info[$field]['_behavior']=$info[$field]['behavior']; if(preg_match('/(editor|tinymce)$/i',$info[$field]['behavior'])){ $tag .= '
'."\n"; $end_div=1; } } //pass behavior as a hidden field if(strlen($info[$field]['_behavior'])){ $tag .= ''."\n"; } $tag .= '
'."\n"; $rtn .= getDBFieldTag($fldopts); $rtn .= ''."\n"; $editlist++; continue; } $val=isset($rec[$fld])?$rec[$fld]:null; if($fld=='password'){ $val=preg_replace('/./','*',$val); } //relate? if(isset($params[$fld."_relate"])){ $relflds=preg_split('/[\,\ \;\:]+/',$params[$fld."_relate"]); $rvals=array(); foreach($relflds as $relfld){ if(isset($rec["{$fld}_ex"][$relfld])){$rvals[]=$rec["{$fld}_ex"][$relfld];} } $val=count($rvals)?implode(' ',$rvals):$val; } //eval? if(isset($params[$fld."_eval"])){ $evalstr=$params[$fld."_eval"]; foreach($list[0] as $xfld=>$xval){ if(is_array($xfld) || is_array($xval)){continue;} $replace='%'.$xfld.'%'; $evalstr=str_replace($replace,$rec[$xfld],$evalstr); } $val=evalPHP(''); } //checkmark? if(isset($params[$fld."_checkmark"])){ $img=$val==1?'checkmark.png':'x.png'; $val=''; } //link, check, or image? if(isset($params[$fld."_link"]) && $params[$fld."_link"]==1){$val=''.$val.'';} elseif(isset($params['-href'])){ $href=$params['-href']; foreach($list[0] as $xfld=>$xval){ if(is_array($xfld) || is_array($xval)){continue;} $replace='%'.$xfld.'%'; $href=str_replace($replace,$rec[$xfld],$href); } $val=''.$val.''; } elseif(isset($params[$fld."_href"])){ $href=$params[$fld."_href"]; foreach($list[0] as $xfld=>$xval){ if(is_array($xfld) || is_array($xval)){continue;} $replace='%'.$xfld.'%'; $href=str_replace($replace,$rec[$xfld],$href); } $val=''.$val.''; } elseif(isset($params[$fld."_onclick"])){ $href=$params[$fld."_onclick"]; foreach($list[0] as $xfld=>$xval){ if(is_array($xfld) || is_array($xval)){continue;} $replace='%'.$xfld.'%'; //echo "replacing {$replace} with {$rec[$xfld]}
\n"; $href=str_replace($replace,$rec[$xfld],$href); } $val=''.$val.''; } elseif(isset($params[$fld."_check"]) && $params[$fld."_check"]==1){ if($val==0){$val='';} elseif($val==1){$val='
';} } elseif(isset($params[$fld."_image"]) && $params[$fld."_image"]==1){ $val='
'; } elseif(isset($params[$fld."_dateformat"]) && strlen($params[$fld."_dateformat"])){ $val=date($params[$fld."_dateformat"],strtotime($val)); } elseif(isset($params[$fld."_dateage"]) && $params[$fld."_dateage"]==1){ if(isNum($rec["{$fld}_utime"])){ $age=time()-$rec["{$fld}_utime"]; $val=verboseTime($age); } else{$val='';} } if(isNum($val)){$params[$fld."_align"]="right";} //write the cell with any custom attributes $rtn .= "\t\t\n"; } $rtn .= "\t\n"; } $rtn .= ''."\n"; if(isset($params['-sumfields']) && is_array($params['-sumfields'])){ $rtn .= ' '."\n"; foreach($fields as $fld){ if(isset($sums[$fld])){$val=$sums[$fld];} else{$val='';} $rtn .= ' '.$val.''."\n"; } $rtn .= ' '."\n"; } $rtn .= "\n"; if($listform==1){ if($editlist > 0){$rtn .= buildFormSubmit("Update");} $rtn .= $customcode; $rtn .= buildFormEnd(); } else{$rtn .= $customcode;} if(isset($params['-table']) && $params['-table']=='_cron'){$rtn .= ''."\n";} return $rtn; } /* listDBResults - return an html table of records */ function listDBResults($query='',$params=array()){ //info: return the results of listDBRecords based on query passed in $params['-query']=$query; return listDBRecords($params); } /* getDBTables - returns an array of tables in current database */ function getDBTables($dbname='',$force=0){ return databaseTables($dbname,$force); } //----------------------- function isDBReservedWord($word=''){ //info: return 1 if word is a reserved database word.. ie - dont use it $word=trim($word); //return 1 if word starts with a number since those fields are not allowed in xml if(preg_match('/^[0-9]/',$word)){return true;} $reserved=array( 'action','add','all','allfields','alter','and','as','asc','auto_increment','between','bigint','bit','binary','blob','both','by', 'cascade','char','character','change','check','column','columns','create', 'data','database','databases','date','datetime','day','day_hour','day_minute','day_second','dayofweek','dec','decimal','default','delete','desc','describe','distinct','double','drop','escaped','enclosed', 'enum','explain','fields','float','float4','float8','foreign','from','for','full', 'grant','group','having','hour','hour_minute','hour_second', 'ignore','in','index','infile','insert','int','integer','interval','int1','int2','int3','int4','int8','into','is','inshift','in1', 'join','key','keys','leading','left','like','lines','limit','lock','load','long','longblob','longtext', 'match','mediumblob','mediumtext','mediumint','middleint','minute','minute_second','mod','month', 'natural','numeric','no','not','null','on','option','optionally','or','order','outer','outfile', 'partial','precision','primary','procedure','privileges', 'read','real','references','rename','regexp','repeat','replace','restrict','rlike', 'select','set','show','smallint','sql_big_tables','sql_big_selects','sql_select_limit','sql_log_off','straight_join','starting', 'table','tables','terminated','text','time','timestamp','tinyblob','tinytext','tinyint','trailing','to', 'use','using','unique','unlock','unsigned','update','usage', 'values','varchar','varying','varbinary','with','write','where', 'year','year_month','zerofill' ); if(in_array($word,$reserved)){return true;} return false; } //--------------- function isDBStage(){ global $databaseCache; //info: returns true if you are in the staging database if(isset($databaseCache['isDBStage'])){return $databaseCache['isDBStage'];} global $CONFIG; if(isset($CONFIG['dbstage']) && preg_match('/^(1|true|yes)$/',$CONFIG['dbstage'])){ $rtn = 1; $databaseCache['isDBStage']=$rtn; return $rtn; } $xset=settingsValues(0); $rtn=0; if(isset($xset['wasql_synchronize_master']) && $xset['wasql_synchronize_master']==$CONFIG['dbname']){$rtn = 1;} $databaseCache['isDBStage']=$rtn; return $rtn; } //--------------- function isDBTable($table='',$force=0){ global $databaseCache; $table=strtolower($table); if(isset($databaseCache['isDBTable'][$table])){return $databaseCache['isDBTable'][$table];} $databaseCache['isDBTable']=array(); $table_parts=preg_split('/\./', $table); $dbname=''; if(count($table_parts) > 1){ $dbname=array_shift($table_parts); //$table=implode('.',$table_parts); } //info: returns true if $table is valid $tables=getDBTables($dbname,$force); $databaseCache['isDBTable'][$table]=false; foreach($tables as $ctable){ $ctable=strtolower($ctable); if(strlen($dbname)){$ctable="{$dbname}.{$ctable}";} $databaseCache['isDBTable'][$ctable]=true; } return $databaseCache['isDBTable'][$table]; } //--------------- function truncateDBTable($table){ //info: removes all records in specified table and resets the auto-incriment field to zero if(is_array($table)){$tables=$table;} else{$tables=array($table);} foreach($tables as $table){ if(!isDBTable($table)){return "No such table: {$table}.";} $result=executeSQL("truncate {$table}"); if(isset($result['error'])){ return $result['error']; } } return 1; } /* ############################################################################ Database Independant function calls - currently supports MySQL and MS SQL ############################################################################ */ //------------------ function databaseAffectedRows(){ global $dbh; //Open a connection to a dabase Server - supports multiple database types if(isMysqli()){return mysqli_affected_rows($dbh);} elseif(isMysql()){return mysql_affected_rows();} elseif(isMssql()){ $val = null; $res = databaseQuery('SELECT @@rowcount as rows'); if ($row = mssql_fetch_row($res)) { $val = trim($row[0]); } mssql_free_result($res); return $val; } return null; } //------------------ function databaseConnect($host,$user,$pass,$dbname=''){ //Open a connection to a dabase Server - supports multiple database types if(isMysqli()){return mysqli_connect($host, $user, $pass, $dbname);} elseif(isMysql()){return mysql_connect($host, $user, $pass);} elseif(isMssql()){return mssql_connect($host, $user, $pass);} return null; } //------------------ function databaseDescribeTable($table){ global $databaseCache; $cachekey=strtolower($table); if(isset($databaseCache['databaseDescribeTable'][$cachekey])){ return $databaseCache['databaseDescribeTable'][$cachekey]; } $recs=array(); if(isMysqli() || isMysql()){ $recs=getDBRecords(array('-query'=>"desc {$table}")); } elseif(isMssql()){ $trecs=getDBRecords(array('-query'=>"exec sp_columns [{$table}]")); //echo printValue($trecs); foreach($trecs as $trec){ $rec=array( 'field' => $trec['column_name'], 'type' => preg_match('/char$/i',$trec['type_name'])?"{$trec['type_name']}({$trec['precision']})":"{$trec['type_name']}", 'null' => $trec['is_nullable'] ); $recs[]=$rec; } } $databaseCache['databaseDescribeTable'][$cachekey]=$recs; return $recs; } //------------------ function databaseError(){ //Returns the text of the error message from previous MySQL operation - supports multiple database types global $dbh; if(isMysqli()){ if(!$dbh){return 'connection failure';} return mysqli_error($dbh); } elseif(isMysql()){return mysql_error();} elseif(isMssql()){ $err=mysql_error(); $info=@mysql_info(); if(strlen($info)){ $err .= "
\n". mysql_info(); } return $err; } return null; } //------------------ function databaseEscapeString($str){ global $dbh; if(isMysqli()){ $str = function_exists('mysqli_real_escape_string')?mysqli_real_escape_string($dbh,$str):mysqli_escape_string($dbh,$str); } elseif(isMysql()){ $str = function_exists('mysql_real_escape_string')?mysql_real_escape_string($str):mysql_escape_string($str); } else{ //MS SQL does not have a specific escape string function $str = str_replace("'","''",$str); } return $str; } //------------------ function databaseFetchAssoc($query_result){ //Returns an associative array of the current row in the result - supports multiple database types if(isMysqli()){return mysqli_fetch_assoc($query_result);} elseif(isMysql()){return mysql_fetch_assoc($query_result);} elseif(isMssql()){return mssql_fetch_assoc($query_result);} return null; } //------------------ function databaseFetchObject($query_result){ //Fetch row as object - supports multiple database types global $dbh; if(isMysqli()){return mysqli_fetch_object($dbh,$query_result);} elseif(isMysql()){return mysql_fetch_object($query_result);} elseif(isMssql()){return mssql_fetch_object($query_result);} return null; } //------------------ function databaseFetchRow($query_result){ //Get a result row as an enumerated array - supports multiple database types if(isMysqli()){return mysqli_fetch_row($query_result);} elseif(isMysql()){return mysql_fetch_row($query_result);} elseif(isMssql()){return mssql_fetch_row($query_result);} return null; } //------------------ function databaseFieldFlags($query_result,$i=-1){ //Returns the length of the specified field - supports multiple database types global $dbh; if(isMysqli()){return mysqli_field_flags($dbh,$query_result,$i);} elseif(isMysql()){return mysql_field_flags($query_result,$i);} elseif(isMssql()){ return null; return mssql_field_flags($query_result,$i); } return null; } //------------------ function databaseFieldLength($query_result,$i=-1){ //Returns the length of the specified field - supports multiple database types global $dbh; if(isMysqli()){return mysqli_field_len($dbh,$query_result,$i);} elseif(isMysql()){return mysql_field_len($query_result,$i);} elseif(isMssql()){return mssql_field_length($query_result,$i);} return null; } //------------------ function databaseFieldName($query_result,$i=-1){ //Get the name of the specified field in a result - supports multiple database types global $dbh; //mysqli does not have a mysqli_field_name function if(isMysqli()){return abort("mysqli_field_name does not exist!");} elseif(isMysql()){return mysql_field_name($query_result,$i);} elseif(isMssql()){return mssql_field_name($query_result,$i);} return null; } //------------------ function databaseFieldType($query_result,$i=-1){ //Get the type of the specified field in a result - supports multiple database types global $dbh; if(isMysqli()){return mysqli_field_type($dbh,$query_result,$i);} elseif(isMysql()){return mysql_field_type($query_result,$i);} elseif(isMssql()){return mssql_field_type($query_result,$i);} return null; } //------------------ function databaseFreeResult($query_result){ //Free result memory - supports multiple database types global $dbh; if(!is_resource($query_result)){return;} if(isMysqli()){return mysqli_free_result($dbh,$query_result);} elseif(isMysql()){return mysql_free_result($query_result);} elseif(isMssql()){return mssql_free_result($query_result);} return null; } //------------------ function databaseIndexes($table){ //Get the ID generated in the last query - supports multiple database types if(isMysqli() || isMysql()){ return getDBRecords(array('-query'=>"show index from {$table}")); } elseif(isSqlite()){return array();} elseif(isMssql()){ $query='SELECT sys.tables.object_id, sys.tables.name as table_name, sys.columns.name as column_name, sys.indexes.name as index_name, sys.indexes.is_unique, sys.indexes.is_primary_key FROM sys.tables, sys.indexes, sys.index_columns, sys.columns WHERE (sys.tables.object_id = sys.indexes.object_id AND sys.tables.object_id = sys.index_columns.object_id AND sys.tables.object_id = sys.columns.object_id AND sys.indexes.index_id = sys.index_columns.index_id AND sys.index_columns.column_id = sys.columns.column_id) AND sys.tables.name = '."'{$table}'"; return getDBRecords(array('-query'=>$query)); } return null; } //------------------ function databaseInsertId(){ //Get the ID generated in the last query - supports multiple database types global $dbh; if(isMysqli()){return mysqli_insert_id($dbh);} elseif(isMysql()){return mysql_insert_id();} elseif(isSqlite()){return sqlite_last_insert_rowid();} elseif(isMssql()){ //MSSQL does not have an insert_id function like mysql does $id = null; $res = databaseQuery('SELECT @@identity AS id'); if ($row = mssql_fetch_row($res)) { $id = trim($row[0]); } mssql_free_result($res); return $id; } return null; } //------------------ function databaseListDbs(){ global $dbh; if(isMysqli()){return mysqli_list_dbs($dbh);} elseif(isMysql()){return mysql_list_dbs($dbh);} elseif(isMssql()){ //http://osdir.com/ml/php.database/2002-09/msg00287.html return databaseQuery("exec sp_databases"); } return null; } //------------------ function databaseListProcesses(){ global $dbh; if(isMysqli()){return mysqli_list_processes($dbh);} elseif(isMysql()){return mysql_list_processes();} elseif(isMssql()){ //not sure how for MS SQL return null; } return null; } //------------------ function databaseNumFields($query_result){ //Free result memory - supports multiple database types if(isMysqli()){return mysqli_num_fields($query_result);} elseif(isMysql()){return mysql_num_fields($query_result);} elseif(isMssql()){return mssql_num_fields($query_result);} return null; } //------------------ function databaseNumRows($query_result){ //Free result memory - supports multiple database types if(isMysqli()){return mysqli_num_rows($query_result);} elseif(isMysql()){return mysql_num_rows($query_result);} elseif(isMssql()){return mssql_num_rows($query_result);} return null; } //------------------ function databasePrimaryKeyFieldString(){ if(isMysqli() || isMysql()){return "int(11) NOT NULL Primary Key auto_increment";} elseif(isMssql()){return "INT NOT NULL IDENTITY(1,1)";} } //------------------ function databaseQuery($query){ //Free result memory - supports multiple database types global $dbh; if(isMysqli()){return mysqli_query($dbh,$query);} elseif(isMysql()){return mysql_query($query);} elseif(isMssql()){return mssql_query($query);} } //------------------ function databaseRestoreDb(){ global $CONFIG; return databaseSelectDb($CONFIG['dbname']); } //------------------ function databaseSelectDb($dbname){ global $CONFIG; global $dbh; if(!strlen($dbname)){return false;} if(isset($CONFIG['_current_dbname_']) && $dbname === $CONFIG['_current_dbname_']){return true;} global $dbh; //Free result memory - supports multiple database types if(isMysqli()){$rtn = mysqli_select_db($dbh,$dbname);} elseif(isMysql()){$rtn = mysql_select_db($dbname);} elseif(isMssql()){$rtn = mssql_select_db($dbname);} if($rtn){$CONFIG['_current_dbname_']=$dbname;} return $rtn; } //------------------ function databaseTables($dbname='',$force=0){ global $databaseCache; global $CONFIG; $dbcachekey=strlen($dbname)?strtolower($dbname):$CONFIG['dbname']; if(!$force && isset($databaseCache['databaseTables'][$dbcachekey])){ return $databaseCache['databaseTables'][$dbcachekey]; } //returns array of user tables - supports multiple database types $tables=array(); //set query string if(isMysqli() || isMysql()){ $query = "SHOW TABLES"; if(strlen($dbname)){$query .= " from {$dbname}";} } elseif(isMssql()){ global $CONFIG; $query = "select name from sysobjects where xtype = 'U';"; } else{return null;} //run query $query_result=@databaseQuery($query); if(!$query_result){return $query . databaseError();} //build tables array while ($row = databaseFetchRow($query_result)) { array_push($tables,$row[0]); } databaseFreeResult($query_result); //return sorted tables array sort($tables); $databaseCache['databaseTables'][$dbcachekey]=$tables; return $tables; } //------------------ function databaseVersion(){ //Returns an associative array of the current row in the result - supports multiple database types if(isMysqli() || isMysql()){ $recs=getDBRecords(array('-query'=>"select version() as version")); if(isset($recs[0]['version'])){return $recs[0]['version'];} return printValue($recs); } elseif(isMssql()){ $recs=getDBRecords(array('-query'=>"select @@version as version")); if(isset($recs[0]['version'])){return $recs[0]['version'];} return printValue($recs); } return null; } //------------------ function databaseType(){ //Returns an associative array of the current row in the result - supports multiple database types if(isMysql()){return 'Mysql';} elseif(isMysqli()){return 'Mysqli';} elseif(isMssql()){return 'MS SQL';} elseif(isSqlite()){return 'SQLite';} return 'Unknown'; } //------------------ function isMysql(){ global $CONFIG; $dbtype=strtolower(trim($CONFIG['dbtype'])); if($dbtype=='mysql'){return true;} return false; } //------------------ function isMysqli(){ global $CONFIG; $dbtype=strtolower(trim($CONFIG['dbtype'])); if($dbtype=='mysqli'){return true;} return false; } //------------------ function isSqlite(){ global $CONFIG; $dbtype=strtolower(trim($CONFIG['dbtype'])); if($dbtype=='sqlite'){return true;} return false; } //------------------ function isMssql(){ global $CONFIG; $dbtype=strtolower(trim($CONFIG['dbtype'])); if($dbtype=='mssql'){return true;} return false; } //------------------ function isODBC(){ global $CONFIG; $dbtype=strtolower(trim($CONFIG['dbtype'])); if($dbtype=='odbc'){return true;} return false; } /** * setDBSettings - sets a value in the settings table * @param key_name string * @param key_value string * @param user_id int - optional. defaults to current USER id or 0 * @return *

@usage setDBSettings($key_name,$key_value,$userid);

*/ function setDBSettings($name,$value,$userid){ global $USER; if(!isNum($userid)){ $userid=setValue(array($USER['_id'],0)); } $rec=getDBRecord(array('-table'=>"_settings",'key_name'=>$name,'user_id'=>$userid)); if(is_array($rec)){ return editDBRecord(array('-table'=>"_settings",'-where'=>"_id={$rec['_id']}",'key_value'=>$value)); } else{ return addDBRecord(array('-table'=>"_settings",'key_name'=>$name,'user_id'=>$userid,'key_value'=>$value)); } } /** * getDBSettings - retrieves a value in the settings table * @param key_name string * @param user_id int - optional. defaults to current USER id or 0 * @param collapse boolean - optional. defaults to false. If true, collapses XML array results * @return if key_value is xml it returns an array, otherwise a string *

@usage $val=getDBSettings($key_name,$userid);

*/ function getDBSettings($name,$userid,$collapse=0){ global $USER; if(!isNum($userid)){ $userid=setValue(array($USER['_id'],0)); } $settings=null; $rec=getDBRecord(array('-table'=>"_settings",'key_name'=>$name,'user_id'=>$userid)); if(is_array($rec)){ if(isXML($rec['key_value'])){ $settings = xml2Array($rec['key_value']); if($collapse && is_array($settings['request'])){ $settings=$settings['request']; if(is_array($settings)){ foreach($settings as $key=>$val){ if(isset($settings[$key]['values']) && is_array($settings[$key]['values'])){ $settings[$key]=$settings[$key]['values']; } } } } } else{$settings=$rec['key_value'];} } return $settings; } //----------------------- function showDBCronPanel($ajax=0,$frequency=60){ //exclude: true //info: shows the cron panel and updates automatically //usage: echo showDBCronPanel $rtn=''; if($ajax==0){ $rtn .= '
'."\n"; $rtn .= '
'."\n"; $rtn .= '
Cron Information Panel
'."\n"; $rtn .= '
'."\n"; } //show date updated $rtn .= '
'.date("F j, Y, g:i a").'
'.$frequency.'
'."\n"; $rtn .= '
'."\n"; $recs=getDBRecords(array('-table'=>"_cron")); //collect some stats $stats=array('cron_pid'=>array(),'active'=>0,'running'=>array()); foreach($recs as $rec){ if($rec['active']==1){$stats['active']+=1;} if($rec['running']==1){$stats['running'][]=$rec;} $stats['cron_pid'][$rec['cron_pid']]+=1; if(!isset($stats['lastrun']) || $rec['run_date_utime'] > $stats['lastrun']['run_date_utime']){$stats['lastrun']=$rec;} } //how many crons are running? if(!count($stats['cron_pid'])){ $rtn .= '
WARNING! NO cron servers are listening. At least one cron server must be running in order for cron jobs to work.
'."\n"; } else{ $rtn .= '
'.count($stats['cron_pid']).' Cron servers listening
'."\n"; } //last run if(is_array($stats['lastrun'])){ $elapsed=time()-$stats['lastrun']['run_date_utime']; $rtn .= '
"'.$stats['lastrun']['name'].'" ran '.verboseTime($elapsed).' ago
'."\n"; } //running crons list if(count($stats['running'])){ $rtn .= '
'.count($recs).' Cron Jobs Running
'."\n"; foreach($stats['running'] as $rec){ $rtn .= '
'."\n"; $rtn .= " {$rec['_id']}. {$rec['name']}"; $rtn .= '
'."\n"; } } else{$rtn .= '
NO Cron Jobs Running
'."\n";} $frequency=$frequency*1000; $sort=encodeURL($_REQUEST['_sort']); $rtn .= ' ' . buildOnLoad("initBehaviors();scheduleAjaxGet('cronpanel','php/index.php','cronpanel','_action=cronpanel&_sort={$sort}&freq={$frequency}',{$frequency},1);"); if($ajax==0){ $rtn .= '
'."\n"; $rtn .= '
'."\n"; } return $rtn; } ?>
Fatal error: Call to undefined function isDBTable() in /home/janda23/wasql_revu/php/user.php on line 9