diff --git a/action.php b/action.php new file mode 100644 index 0000000..650110d --- /dev/null +++ b/action.php @@ -0,0 +1,126 @@ +num_rows > 0) + { + mysqli_query($conn, "UPDATE users SET name = '" . $name . "', phone = '" . $phone . "', status = '" . $status . "', created_at = NOW() WHERE email = '" . $email . "'"); + } + else + { + mysqli_query($conn, "INSERT INTO users (name, email, phone, created_at, updated_at, status) VALUES ('" . $name . "', '" . $email . "', '" . $phone . "', NOW(), NOW(), '" . $status . "')"); + + } + } + + // Close opened CSV file + fclose($csvFile); + + header("Location: index.php"); + + } + else + { + echo "Please select valid file"; + } + } + +} +elseif ($action=='remove') +{ + $sql="DELETE from importation where id=".$id; + + mysqli_query($conn, $sql); + + header("Location: index.php"); +} + +?> \ No newline at end of file diff --git a/db.php b/db.php new file mode 100644 index 0000000..a4ac4c7 --- /dev/null +++ b/db.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/index.php b/index.php index 6c32a7d..d0a71fe 100644 --- a/index.php +++ b/index.php @@ -64,6 +64,11 @@ Exports AidImpact + @@ -76,28 +81,54 @@ - +
+
+
+
+ + +
+
+ +
+
+
-
+
+ + + + +
+ + + + +

+ + +
+
+Records: in sec
+ +
+ + + +
© 2004-2017 Oleg Savchuk
+ + +
+

Access protected by password

+
+ + + +
+
+ +
+

DB Connection Settings

+
+
+
+
advanced settings
+ +
+ + +
+
+
+\n".mysqli_error($dbh1)."
\n$sql"); + return $sth; +} + +function db_array($sql, $dbh1=NULL, $skiperr=0, $isnum=0){#array of rows + $sth=db_query($sql, $dbh1, $skiperr, MYSQLI_USE_RESULT); + if (!$sth) return; + $res=array(); + if ($isnum){ + while($row=mysqli_fetch_row($sth)) $res[]=$row; + }else{ + while($row=mysqli_fetch_assoc($sth)) $res[]=$row; + } + mysqli_free_result($sth); + return $res; +} + +function db_row($sql){ + $sth=db_query($sql); + return mysqli_fetch_assoc($sth); +} + +function db_value($sql,$dbh1=NULL,$skiperr=0){ + $sth=db_query($sql,$dbh1,$skiperr); + if (!$sth) return; + $row=mysqli_fetch_row($sth); + return $row[0]; +} + +function get_identity($dbh1=NULL){ + $dbh1=db_checkconnect($dbh1); + return mysqli_insert_id($dbh1); +} + +function get_db_select($sel=''){ + global $DB,$SHOW_D; + if (is_array($_SESSION['sql_sd']) && $_REQUEST['db']!='*'){//check cache + $arr=$_SESSION['sql_sd']; + }else{ + $arr=db_array($SHOW_D,NULL,1); + if (!is_array($arr)){ + $arr=array( 0 => array('Database' => $DB['db']) ); + } + $_SESSION['sql_sd']=$arr; + } + return @sel($arr,'Database',$sel); +} + +function chset_select($sel=''){ + global $DBDEF; + $result=''; + if ($_SESSION['sql_chset']){ + $arr=$_SESSION['sql_chset']; + }else{ + $arr=db_array("show character set",NULL,1); + if (!is_array($arr)) $arr=array(array('Charset'=>$DBDEF['chset'])); + $_SESSION['sql_chset']=$arr; + } + + return @sel($arr,'Charset',$sel); +} + +function sel($arr,$n,$sel=''){ + foreach($arr as $a){ +# echo $a[0]; + $b=$a[$n]; + $res.=""; + } + return $res; +} + +function microtime_float(){ + list($usec,$sec)=explode(" ",microtime()); + return ((float)$usec+(float)$sec); +} + +/* page nav + $pg=int($_[0]); #current page + $all=int($_[1]); #total number of items + $PP=$_[2]; #number if items Per Page + $ptpl=$_[3]; #page url /ukr/dollar/notes.php?page= for notes.php + $show_all=$_[5]; #print Totals? +*/ +function get_nav($pg, $all, $PP, $ptpl, $show_all=''){ + $n=' '; + $sep=" $n|$n\n"; + if (!$PP) $PP=10; + $allp=floor($all/$PP+0.999999); + + $pname=''; + $res=''; + $w=array('Less','More','Back','Next','First','Total'); + + $sp=$pg-2; + if($sp<0) $sp=0; + if($allp-$sp<5 && $allp>=5) $sp=$allp-5; + + $res=""; + + if($sp>0){ + $pname=pen($sp-1,$ptpl); + $res.="$w[0]"; + $res.=$sep; + } + for($p_p=$sp;$p_p<$allp && $p_p<$sp+5;$p_p++){ + $first_s=$p_p*$PP+1; + $last_s=($p_p+1)*$PP; + $pname=pen($p_p,$ptpl); + if($last_s>$all){ + $last_s=$all; + } + if($p_p==$pg){ + $res.="$first_s..$last_s"; + }else{ + $res.="$first_s..$last_s"; + } + if($p_p+1<$allp) $res.=$sep; + } + if($sp+5<$allp){ + $pname=pen($sp+5,$ptpl); + $res.="$w[1]"; + } + $res.="
\n"; + + if($pg>0){ + $pname=pen($pg-1,$ptpl); + $res.="$w[2] $n|$n "; + $pname=pen(0,$ptpl); + $res.="$w[4]"; + } + if($pg>0 && $pg+1<$allp) $res.=$sep; + if($pg+1<$allp){ + $pname=pen($pg+1,$ptpl); + $res.="$w[3]"; + } + if ($show_all) $res.=" ($w[5] - $all) "; + + return $res; +} + +function pen($p,$np=''){ + return str_replace('%p%',$p, $np); +} + +function killmq($value){ + return is_array($value)?array_map('killmq',$value):stripslashes($value); +} + +function savecfg(){ + $v=$_REQUEST['v']; + $_SESSION['DB']=$v; + unset($_SESSION['sql_sd']); + + if ($_REQUEST['rmb']){ + $tm=time()+60*60*24*30; + newcookie("conn[db]", $v['db'],$tm); + newcookie("conn[user]",$v['user'],$tm); + newcookie("conn[pwd]", $v['pwd'],$tm); + newcookie("conn[host]",$v['host'],$tm); + newcookie("conn[port]",$v['port'],$tm); + newcookie("conn[chset]",$v['chset'],$tm); + }else{ + newcookie("conn[db]", FALSE,-1); + newcookie("conn[user]",FALSE,-1); + newcookie("conn[pwd]", FALSE,-1); + newcookie("conn[host]",FALSE,-1); + newcookie("conn[port]",FALSE,-1); + newcookie("conn[chset]",FALSE,-1); + } +} + +// Allow httponly cookies, or the password is stored plain text in a cookie +function newcookie($n,$v,$e){$x;return setcookie($n,$v,$e,$x,$x,!!$x,!$x);} + +//during login only - from cookies or use defaults; +function loadcfg(){ + global $DBDEF; + + if( isset($_COOKIE['conn']) ){ + $_SESSION['DB']=$_COOKIE['conn']; + }else{ + $_SESSION['DB']=$DBDEF; + } + if (!strlen($_SESSION['DB']['chset'])) $_SESSION['DB']['chset']=$DBDEF['chset'];#don't allow empty charset +} + +//each time - from session to $DB_* +function loadsess(){ + global $DB, $is_sm; + + $DB=$_SESSION['DB']; + + $rdb=$_REQUEST['db']; + if ($rdb=='*') $rdb=''; + if ($rdb) { + $DB['db']=$rdb; + } + if($_REQUEST['GoSQL']) $_SESSION['is_sm']=$_REQUEST['is_sm']+0; + $is_sm=$_SESSION['is_sm']+0; +} + +function print_export(){ + global $self,$xurl,$DB,$DUMP_FILE; + $t=$_REQUEST['rt']; + $l=($t)?"Table $t":"whole DB"; + print_header(); +?> +
+

Export

+
+ Structure
+ Data

+
 
+
+ + + + (to export as csv - go to 'show tables' and export just ONE table) + +
+
+
+
+
+ + + + + +

"Dump on Server" exports to file:

+
+
+name).(($i<$fn-1)?",":"")); + } + ex_w($D); + while($row=mysqli_fetch_row($sth)) ex_w(to_csv_row($row)); + mysqli_free_result($sth); + }else{ + ex_start('.sql'); + ex_hdr($ctp?$ctp:'text/plain',"$DB[db]".(($ct==1&&$t[0])?".$t[0]":(($ct>1)?'.'.$ct.'tables':'')).".sql$aext"); + ex_w("-- phpMiniAdmin dump $VERSION$D-- Datetime: ".date('Y-m-d H:i:s')."$D-- Host: $DB[host]$D-- Database: $DB[db]$D$D"); + if ($DB['chset']) ex_w("/*!40030 SET NAMES $DB[chset] */;$D"); + $ex_super && ex_w("/*!40030 SET GLOBAL max_allowed_packet=16777216 */;$D$D"); + ex_w("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;$D$D"); + + $sth=db_query("show full tables from `$DB[db]`"); + while($row=mysqli_fetch_row($sth)){ + if (!$rt||array_key_exists($row[0],$th)) do_export_table($row[0],$row[1],$MAXI); + } + + ex_w("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;$D$D"); + ex_w("$D-- phpMiniAdmin dump end$D"); + } + ex_end(); + if (!$ex_issrv) exit; + $out_message='Export done successfully'; +} + +function do_export_table($t='',$tt='',$MAXI=838860){ + global $D,$ex_issrv; + @set_time_limit(600); + + if($_REQUEST['s']){ + $sth=db_query("show create table `$t`"); + $row=mysqli_fetch_row($sth); + $ct=preg_replace("/\n\r|\r\n|\n|\r/",$D,$row[1]); + ex_w("DROP TABLE IF EXISTS `$t`;$D$ct;$D$D"); + } + + if ($_REQUEST['d']&&$tt!='VIEW'){//no dump for views + $exsql=''; + ex_w("/*!40000 ALTER TABLE `$t` DISABLE KEYS */;$D"); + $sth=db_query("select * from `$t`",NULL,0,MYSQLI_USE_RESULT); + while($row=mysqli_fetch_row($sth)){ + $values=''; + foreach($row as $v) $values.=(($values)?',':'').dbq($v); + $exsql.=(($exsql)?',':'')."(".$values.")"; + if (strlen($exsql)>$MAXI) { + ex_w("INSERT INTO `$t` VALUES $exsql;$D");$exsql=''; + } + } + mysqli_free_result($sth); + if ($exsql) ex_w("INSERT INTO `$t` VALUES $exsql;$D"); + ex_w("/*!40000 ALTER TABLE `$t` ENABLE KEYS */;$D$D"); + } + if (!$ex_issrv) flush(); +} + +function ex_hdr($ct,$fn){ + global $ex_issrv; + if ($ex_issrv) return; + header("Content-type: $ct"); + header("Content-Disposition: attachment; filename=\"$fn\""); +} +function ex_start($ext){ + global $ex_isgz,$ex_gz,$ex_tmpf,$ex_issrv,$ex_f,$DUMP_FILE; + if ($ex_isgz){ + $ex_tmpf=($ex_issrv?export_fname($DUMP_FILE,true).$ext:tmp_name()).'.gz'; + if (!($ex_gz=gzopen($ex_tmpf,'wb9'))) die("Error trying to create gz tmp file"); + }else{ + if ($ex_issrv) { + if (!($ex_f=fopen(export_fname($DUMP_FILE,true).$ext,'wb'))) die("Error trying to create dump file"); + } + } +} +function ex_w($s){ + global $ex_isgz,$ex_gz,$ex_issrv,$ex_f; + if ($ex_isgz){ + gzwrite($ex_gz,$s,strlen($s)); + }else{ + if ($ex_issrv){ + fwrite($ex_f,$s); + }else{ + echo $s; + } + } +} +function ex_end(){ + global $ex_isgz,$ex_gz,$ex_tmpf,$ex_issrv,$ex_f; + if ($ex_isgz){ + gzclose($ex_gz); + if (!$ex_issrv){ + readfile($ex_tmpf); + unlink($ex_tmpf); + } + }else{ + if ($ex_issrv) fclose($ex_f); + } +} + +function print_import(){ + global $self,$xurl,$DB,$DUMP_FILE; + print_header(); +?> +
+

Import DB

+
+
+
+
+
+
+ + +
+


+ +
+ '(? '(? '\*\/', + '#' => '[\r\n]+', + '--' => '[\r\n]+', + ); + if ( $aCLOSE[$ochar] && preg_match("/(".$aCLOSE[$ochar].")/", $str, $m, PREG_OFFSET_CAPTURE, $pos ) ) { + $clchar=$m[1][0]; + $clpos=$m[1][1]; + $sl=strlen($m[2][0]); + if ($ochar=="'" && $sl){ + if ($sl % 2){ #don't count as CLOSE char if number of slashes before ' ODD + list($clchar, $clpos)=get_close_char($str, $clpos+strlen($clchar), $ochar); + }else{ + $clpos+=strlen($clchar)-1;$clchar="'";#correction + } + } + } + return array($clchar, $clpos); +} + +function do_one_sql($sql){ + global $last_sth,$last_sql,$MAX_ROWS_PER_PAGE,$page,$is_limited_sql,$last_count,$IS_COUNT; + $sql=trim($sql); + $sql=preg_replace("/;$/","",$sql); + if ($sql){ + $last_sql=$sql;$is_limited_sql=0; + $last_count=NULL; + if (preg_match("/^select/i",$sql) && !preg_match("/limit +\d+/i", $sql)){ + if ($IS_COUNT){ + #get total count + $sql1='select count(*) from ('.$sql.') ___count_table'; + $last_count=db_value($sql1,NULL,'noerr'); + } + $offset=$page*$MAX_ROWS_PER_PAGE; + $sql.=" LIMIT $offset,$MAX_ROWS_PER_PAGE"; + $is_limited_sql=1; + } + $last_sth=db_query($sql,0,'noerr'); + return $last_sth; + } + return 1; +} + +function do_sht(){ + global $SHOW_T; + $cb=$_REQUEST['cb']; + if (!is_array($cb)) $cb=array(); + $sql=''; + switch ($_REQUEST['dosht']){ + case 'exp':$_REQUEST['t']=join(",",$cb);print_export();exit; + case 'drop':$sq='DROP TABLE';break; + case 'trunc':$sq='TRUNCATE TABLE';break; + case 'opt':$sq='OPTIMIZE TABLE';break; + } + if ($sq){ + foreach($cb as $v){ + $sql.=$sq." $v;\n"; + } + } + if ($sql) do_sql($sql); + do_sql($SHOW_T); +} + +function to_csv_row($adata){ + global $D; + $r=''; + foreach ($adata as $a){ + $r.=(($r)?",":"").qstr($a); + } + return $r.$D; +} +function qstr($s){ + $s=nl2br($s); + $s=str_replace('"','""',$s); + return '"'.$s.'"'; +} + +function get_rand_str($len){ + $result=''; + $chars=preg_split('//','ABCDEFabcdef0123456789'); + for($i=0;$i<$len;$i++) $result.=$chars[rand(0,count($chars)-1)]; + return $result; +} + +function check_xss(){ + global $self; + if ($_SESSION['XSS']!=trim($_REQUEST['XSS'])){ + unset($_SESSION['XSS']); + header("location: $self"); + exit; + } +} + +function rw($s){#for debug + echo hs(var_dump($s))."
\n"; +} + +function tmp_name() { + if ( function_exists('sys_get_temp_dir')) return tempnam(sys_get_temp_dir(),'pma'); + + if( !($temp=getenv('TMP')) ) + if( !($temp=getenv('TEMP')) ) + if( !($temp=getenv('TMPDIR')) ) { + $temp=tempnam(__FILE__,''); + if (file_exists($temp)) { + unlink($temp); + $temp=dirname($temp); + } + } + return $temp ? tempnam($temp,'pma') : null; +} + +function hs($s){ + return htmlspecialchars($s, ENT_COMPAT|ENT_HTML401,'UTF-8'); +} +function eo($s){//echo+escape + echo hs($s); +} +function ue($s){ + return urlencode($s); +} + +function b64e($s){ + return base64_encode($s); +} +function b64u($s){ + return ue(base64_encode($s)); +} +function b64d($s){ + return base64_decode($s); +} +?>