1 Star 0 Fork 1

weigaolei/phpsqliteadmin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.php 153.88 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880
<?php
if (version_compare(phpversion(), '5.2.4', '<')) {
die('Your PHP version is PHP '.phpversion().', which is too old. You need at least PHP 5.2.4.');
}
if(strpos(ini_get('variables_order'),'G') === false || strpos(ini_get('variables_order'),'P') === false ||
strpos(ini_get('variables_order'),'C') === false || strpos(ini_get('variables_order'),'S') === false) {
die('The php configuration <em>variables_order</em> needs to include G, P, C and S. The current value is "'.ini_get('variables_order').'". Please check the php configuration (php.ini).');
}
# REMOVE_FROM_BUILD
// include default configuration and language
include './phpliteadmin.config.sample.php';
include './languages/lang_en.php';
// setup class autoloading
function pla_autoload($classname)
{
$classfile = __DIR__ . '/classes/' . $classname . '.php';
if (is_readable($classfile)) {
include $classfile;
return true;
}
return false;
}
spl_autoload_register('pla_autoload');
# END REMOVE_FROM_BUILD
//- Initialization
// load optional configuration file
$config_filename = './phpliteadmin.config.php';
if (is_readable($config_filename))
{
include_once $config_filename;
}
//constants 1
define("PROJECT", "phpLiteAdmin");
define("VERSION", "1.9.9-dev");
define("FORCETYPE", false); //force the extension that will be used (set to false in almost all circumstances except debugging, possible values: false, "PDO", "SQLite3", "SQLiteDatabase")
define("SYSTEMPASSWORD", $password); // Makes things easier.
define('PROJECT_URL','https://www.phpliteadmin.org/');
define('DONATE_URL','https://www.phpliteadmin.org/donate/');
define('VERSION_CHECK_URL','https://www.phpliteadmin.org/current_version.php');
define('PROJECT_BUGTRACKER_LINK','<a href="https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open" target="_blank">https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open</a>');
define('PROJECT_INSTALL_LINK','<a href="https://bitbucket.org/phpliteadmin/public/wiki/Installation" target="_blank">https://bitbucket.org/phpliteadmin/public/wiki/Installation</a>');
// up here, we don't output anything. debug output might appear here which is catched by ob and thrown later
ob_start();
// Resource output (css and javascript files)
// we get out of the main code as soon as possible, without inizializing the session
if (isset($_GET['resource']))
{
Resources::output($_GET['resource']);
exit();
}
// don't mess with this - required for the login session
ini_set('session.cookie_httponly', '1');
if(!session_start())
{
die("Could not start a new session. Check your php setup regarding sessions.");
}
// version-number added so after updating, old session-data is not used anylonger
// cookies names cannot contain symbols, except underscores
define("COOKIENAME", preg_replace('/[^a-zA-Z0-9_]/', '_', $cookie_name . '_' . VERSION) );
$params = new GetParameters();
if($debug==true)
{
ini_set("display_errors", 1);
error_reporting(E_STRICT | E_ALL);
} else
{
@ini_set("display_errors", 0);
}
// start the timer to record page load time
$pageTimer = new MicroTimer();
// load language file
if($language != 'en') {
$temp_lang=$lang;
if(is_file('languages/lang_'.$language.'.php'))
include('languages/lang_'.$language.'.php');
elseif(is_file('lang_'.$language.'.php'))
include('lang_'.$language.'.php');
$lang = array_merge($temp_lang, $lang);
unset($temp_lang);
}
// stripslashes if MAGIC QUOTES is turned on
// This is only a workaround. Please better turn off magic quotes!
// This code is from http://php.net/manual/en/security.magicquotes.disabling.php
if (is_callable('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
foreach($process as $key => $val) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
//data types array
$sqlite_datatypes = array("INTEGER", "REAL", "TEXT", "BLOB","NUMERIC","BOOLEAN","DATETIME");
//available SQLite functions array (don't add anything here or there will be problems)
$sqlite_functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper");
//- Support functions
// for php < 5.6.0
if(!function_exists('hash_equals'))
{
function hash_equals($str1, $str2)
{
if(strlen($str1) != strlen($str2))
return false;
else {
$res = $str1 ^ $str2;
$ret = 0;
for($i = strlen($res) - 1; $i >= 0; $i--)
$ret |= ord($res[$i]);
return !$ret;
}
}
}
// workaround if mbsting extension is missing. Sure this means no multibyte support.
if(!function_exists('mb_strlen'))
{
function mb_strlen($s)
{
return strlen($s);
}
}
if(!function_exists('mb_substr'))
{
function mb_substr($s, $start, $length=null, $encoding=null)
{
return substr($s, $start, null === $length ? 2147483647 : $length);
}
}
// no other mbstring functions used so far
//function that allows SQL delimiter to be ignored inside comments or strings
function explode_sql($delimiter, $sql)
{
$ign = array('"' => '"', "'" => "'", "/*" => "*/", "--" => "\n"); // Ignore sequences.
$out = array();
$last = 0;
$slen = strlen($sql);
$dlen = strlen($delimiter);
$i = 0;
while($i < $slen)
{
// Split on delimiter
if($slen - $i >= $dlen && substr($sql, $i, $dlen) == $delimiter)
{
array_push($out, substr($sql, $last, $i - $last));
$last = $i + $dlen;
$i += $dlen;
continue;
}
// Eat comments and string literals
foreach($ign as $start => $end)
{
$ilen = strlen($start);
if($slen - $i >= $ilen && substr($sql, $i, $ilen) == $start)
{
$i+=strlen($start);
$elen = strlen($end);
while($i < $slen)
{
if($slen - $i >= $elen && substr($sql, $i, $elen) == $end)
{
// SQL comment characters can be escaped by doubling the character. This recognizes and skips those.
if($start == $end && $slen - $i >= $elen*2 && substr($sql, $i, $elen*2) == $end.$end)
{
$i += $elen * 2;
continue;
}
else
{
$i += $elen;
continue 3;
}
}
$i++;
}
continue 2;
}
}
$i++;
}
if($last < $slen)
array_push($out, substr($sql, $last, $slen - $last));
return $out;
}
//function to scan entire directory tree and subdirectories
function dir_tree($dir)
{
$path = array();
$stack = array($dir);
while($stack)
{
$thisdir = array_pop($stack);
if($dircont = scandir($thisdir))
{
$i=0;
while(isset($dircont[$i]))
{
if($dircont[$i] !== '.' && $dircont[$i] !== '..')
{
$current_file = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
if(is_file($current_file))
{
$path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
}
elseif (is_dir($current_file))
{
$path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
$stack[] = $current_file;
}
}
$i++;
}
}
}
return $path;
}
//the function echo the help [?] links to the documentation
function helpLink($name)
{
global $lang;
return "<a href='?help=1' onclick='openHelp(\"".$name."\"); return false;' class='helpq' title='".$lang['help'].": ".$name."' target='_blank'><span>[?]</span></a>";
}
// function to encode value into HTML just like htmlentities, but with adjusted default settings
function htmlencode($value, $flags=ENT_QUOTES, $encoding ="UTF-8")
{
return htmlentities($value, $flags, $encoding);
}
// reduce string chars
function subString($str)
{
global $charsNum, $params;
if($charsNum > 10 && (!isset($params->fulltexts) || !$params->fulltexts) && mb_strlen($str)>$charsNum)
{
$str = mb_substr($str, 0, $charsNum).'...';
}
return $str;
}
// marks searchwords and htmlencodes correctly
function markSearchWords($input, $field, $search)
{
$output = htmlencode($input);
if(isset($search['values'][$field]) && is_array($search['values'][$field]))
{
// build one regex that matches (all) search words
$regex = '/';
$vali=0;
foreach($search['values'][$field] as $searchValue)
{
if($search['operators'][$field] =='LIKE' || $search['operators'][$field] == 'LIKE%')
$regex .= '(?:'.($searchValue[0]=='%'?'':'^'); // does the searchvalue have to occur at the start?
$regex .= preg_quote(trim($searchValue,'%'),'/'); // the search value
if($search['operators'][$field] =='LIKE' || $search['operators'][$field] == 'LIKE%')
$regex .= (substr($searchValue,-1)=='%'?'':'$').')'; // does the searchvalue have to occur at the end?
if($vali++<count($search['values'][$field]))
$regex .= '|'; // there is another search value, so we add a |
}
$regex .= '/u';
// LIKE operator is not case sensitive, others are
if($search['operators'][$field] =='LIKE' || $search['operators'][$field] == 'LIKE%')
$regex.= 'i';
// split the string into parts that match and should be highlighted and parts in between
// $fldBetweenParts: the parts that don't match (might contain empty strings)
$fldBetweenParts = preg_split($regex, $input);
// $fldFoundParts[0]: the parts that match
preg_match_all($regex, $input, $fldFoundParts);
// stick the parts together
$output = '';
foreach($fldBetweenParts as $index => $betweenPart)
{
$output .= htmlencode($betweenPart); // part that does not match (might be empty)
if(isset($fldFoundParts[0][$index]))
$output .= '<u class="found">'.htmlencode($fldFoundParts[0][$index]).'</u>'; // the part that matched
}
}
return $output;
}
// checks the (new) name of a database file
function checkDbName($name)
{
global $allowed_extensions;
$info = pathinfo($name);
if(isset($info['extension']) && !in_array($info['extension'], $allowed_extensions))
{
return false;
} else
{
return (!is_file($name) && !is_dir($name));
}
}
// check whether a path is a db managed by this tool
// requires that $databases is already filled!
// returns the key of the db if managed, false otherwise.
function isManagedDB($path)
{
global $databases;
foreach($databases as $db_key => $database)
{
if($path === $database['path'])
{
// a db we manage. Thats okay.
// return the key.
return $db_key;
}
}
// not a db we manage!
return false;
}
// from a typename of a colun, get the type of the column's affinty
// see https://www.sqlite.org/datatype3.html section 2.1 for rules
function get_type_affinity($type)
{
if (preg_match("/INT/i", $type))
return "INTEGER";
else if (preg_match("/(?:CHAR|CLOB|TEXT)/i", $type))
return "TEXT";
else if (preg_match("/BLOB/i", $type) || $type=="")
return "NONE";
else if (preg_match("/(?:REAL|FLOA|DOUB)/i", $type))
return "REAL";
else
return "NUMERIC";
}
// Returns a file size limit in bytes based on the PHP upload_max_filesize
// post_max_size and memory_limit. Returns -1 in case of no limit.
function fileUploadMaxSize()
{
$max1 = parseSize(ini_get('post_max_size'));
$max2 = parseSize(ini_get('upload_max_filesize'));
$max3 = parseSize(ini_get('memory_limit'));
if($max1>0 && ($max1<=$max2 || $max2==0) && ($max1<=$max3 || $max3==-1))
return $max1;
elseif($max2>0 && ($max2<=$max1 || $max1==0) && ($max2<=$max3 || $max3==-1))
return $max2;
elseif($max3>-1 && ($max3<=$max1 || $max1==0) && ($max3<=$max2 || $max2==0))
return $max3;
else
return -1; // no limit
}
// Parses given size string like "12M" into number of bytes
// based on https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Utility%21Bytes.php/function/Bytes%3A%3AtoInt/8.2.x
function parseSize($size)
{
// Remove the non-unit characters from the size.
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
// Remove the non-numeric characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size);
if ($unit)
{
// Find the position of the unit in the ordered string which is the power
// of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
}
else {
return round($size);
}
}
//- Check user authentication, login and logout
$auth = new Authorization(); //create authorization object
// check if user has attempted to log out
if (isset($_GET['logout']))
$auth->revoke();
// check if user has attempted to log in
else if (isset($_POST['login']) && isset($_POST['password']))
{
$attempt = $auth->attemptGrant($_POST['password'], isset($_POST['remember']));
$params->redirect( $attempt ? array():array('failed'=>'1') );
}
//- Actions on database files and bulk data
if ($auth->isAuthorized())
{
//- Create a new database
if(isset($_POST['new_dbname']))
{
if($_POST['new_dbname']=='')
$params->redirect(array('table'=>null), $lang['err'].': '.$lang['db_blank']);
else
{
$str = preg_replace('@[^\w\-.]@u','', $_POST['new_dbname']);
$dbname = $str;
$dbpath = $str;
if(checkDbName($dbname))
{
$tdata = array();
$tdata['name'] = $dbname;
$tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath;
if(isset($_POST['new_dbtype']))
$tdata['type'] = $_POST['new_dbtype'];
else
$tdata['type'] = 3;
$td = new Database($tdata);
$td->query("VACUUM");
} else
{
if(is_file($dbname) || is_dir($dbname))
$params->redirect(array('view'=>'structure'),$lang['err'].': '.sprintf($lang['db_exists'], htmlencode($dbname)));
else
$params->redirect(array('view'=>'structure'),$lang['extension_not_allowed'].': '.implode(', ', array_map('htmlencode', $allowed_extensions)).'<br />'.$lang['add_allowed_extension']);
}
}
}
//- Scan a directory for databases
if($directory!==false)
{
if($directory[strlen($directory)-1]==DIRECTORY_SEPARATOR) //if user has a trailing slash in the directory, remove it
$directory = substr($directory, 0, strlen($directory)-1);
if(is_dir($directory)) //make sure the directory is valid
{
if($subdirectories===true)
$arr = dir_tree($directory);
else
$arr = scandir($directory);
$databases = array();
$j = 0;
for($i=0; $i<sizeof($arr); $i++) //iterate through all the files in the databases
{
if($subdirectories===false)
$arr[$i] = $directory.DIRECTORY_SEPARATOR.$arr[$i];
if(@!is_file($arr[$i])) continue;
$con = file_get_contents($arr[$i], NULL, NULL, 0, 60);
if(strpos($con, "** This file contains an SQLite 2.1 database **", 0)!==false || strpos($con, "SQLite format 3", 0)!==false)
{
$databases[$j]['path'] = $arr[$i];
if($subdirectories===false)
$databases[$j]['name'] = basename($arr[$i]);
else
$databases[$j]['name'] = $arr[$i];
$databases[$j]['writable'] = is_writable($databases[$j]['path']);
$databases[$j]['writable_dir'] = is_writable(dirname($databases[$j]['path']));
$databases[$j]['readable'] = is_readable($databases[$j]['path']);
$j++;
}
}
// 22 August 2011: gkf fixed bug #50.
sort($databases);
if(isset($tdata))
{
foreach($databases as $db_id => $database)
{
if($database['path'] === $tdata['path'])
{
$currentDB = $database;
$params->database = $database['path'];
break;
}
}
}
}
else //the directory is not valid - display error and exit
{
echo "<div class='confirm' style='margin:20px;'>".$lang['not_dir']."</div>";
exit();
}
}
else
{
for($i=0; $i<sizeof($databases); $i++)
{
if(!file_exists($databases[$i]['path']))
{
// the file does not exist and will be created when clicked, if permissions allow to
$databases[$i]['writable'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['readable'] = is_writable(dirname($databases[$i]['path']));
}
else
{
$databases[$i]['writable'] = is_writable($databases[$i]['path']);
$databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['readable'] = is_readable($databases[$i]['path']);
}
}
sort($databases);
}
// we now have the $databases array set. Check whether selected DB is a managed Db (is in this array)
if(!isset($currentDB) && (isset($_GET['database']) || isset($_POST['database']) ) )
{
$selected_db = ( isset($_POST['database']) ? $_POST['database'] : $_GET['database'] );
$db_key = isManagedDB($selected_db);
if($db_key!==false) {
$currentDB = $databases[$db_key];
$params->database = $databases[$db_key]['path'];
}
}
//- Delete an existing database
if(isset($_GET['database_delete']))
{
$dbpath = $_POST['database_delete'];
// check whether $dbpath really is a db we manage
$checkDB = isManagedDB($dbpath);
if($checkDB !== false)
{
unlink($dbpath);
unset($params->database);
unset($currentDB);
unset($databases[$checkDB]);
} else die($lang['err'].': '.$lang['delete_only_managed']);
}
//- Rename an existing database
if(isset($_GET['database_rename']))
{
$oldpath = $_POST['oldname'];
$newpath = $_POST['newname'];
$oldpath_parts = pathinfo($oldpath);
$newpath_parts = pathinfo($newpath);
// only rename?
$newpath = $oldpath_parts['dirname'].DIRECTORY_SEPARATOR.basename($_POST['newname']);
if($newpath != $_POST['newname'] && $subdirectories)
{
// it seems that the file should not only be renamed but additionally moved.
// we need to make sure it stays within $directory...
$new_realpath = realpath($newpath_parts['dirname']).DIRECTORY_SEPARATOR;
$directory_realpath = realpath($directory).DIRECTORY_SEPARATOR;
if(strpos($new_realpath, $directory_realpath)===0)
{
// its okay, the new directory is within $directory
$newpath = $_POST['newname'];
}
else $params->redirect(array('view'=>'rename'), $lang['err'].': '.$lang['db_moved_outside']);
}
if(checkDbName($newpath))
{
$checkDB = isManagedDB($oldpath);
if($checkDB !==false )
{
rename($oldpath, $newpath);
$databases[$checkDB]['path'] = $newpath;
$databases[$checkDB]['name'] = basename($newpath);
$currentDB = $databases[$checkDB];
$params->database = $databases[$checkDB]['path'];
$params->redirect(array('view'=>'rename'), sprintf($lang['db_renamed'], htmlencode($oldpath))." '".htmlencode($newpath)."'.");
}
else $params->redirect(array('view'=>'rename'), $lang['err'].': '.$lang['rename_only_managed']);
}
else
{
if(is_file($newpath) || is_dir($newpath))
$params->redirect(array('view'=>'rename'), $lang['err'].": " . sprintf($lang['db_exists'], htmlencode($newpath)));
else
$params->redirect(array('view'=>'rename'), $lang['err'].": " . $lang['extension_not_allowed'].': '.implode(', ', array_map('htmlencode', $allowed_extensions)).'<br />'.$lang['add_allowed_extension']);
}
}
//- Export (download a dump) an existing database
if(isset($_POST['export']))
{
ob_end_clean();
$export_filename = str_replace(array("\r", "\n"), '',$_POST['filename']); // against http header injection (php < 5.1.2 only)
if($_POST['export_type']=="sql")
{
header('Content-Type: text/sql');
header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";');
if(isset($_POST['tables']))
$tables = $_POST['tables'];
else
{
$tables = array();
$tables[0] = $_POST['single_table'];
}
$drop = isset($_POST['drop']);
$structure = isset($_POST['structure']);
$data = isset($_POST['data']);
$transaction = isset($_POST['transaction']);
$comments = isset($_POST['comments']);
$db = new Database($currentDB);
$db->export_sql($tables, $drop, $structure, $data, $transaction, $comments);
}
else if($_POST['export_type']=="csv")
{
header("Content-type: application/csv");
header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";');
header("Pragma: no-cache");
header("Expires: 0");
if(isset($_POST['tables']))
$tables = $_POST['tables'];
else
{
$tables = array();
$tables[0] = $_POST['single_table'];
}
$field_terminate = $_POST['export_csv_fieldsterminated'];
$field_enclosed = $_POST['export_csv_fieldsenclosed'];
$field_escaped = $_POST['export_csv_fieldsescaped'];
$null = $_POST['export_csv_replacenull'];
$crlf = isset($_POST['export_csv_crlf']);
$fields_in_first_row = isset($_POST['export_csv_fieldnames']);
$db = new Database($currentDB);
$db->export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row);
}
exit();
}
//- Import a file into an existing database
if(isset($_POST['import']))
{
$db = new Database($currentDB);
$db->registerUserFunction($custom_functions);
if($_POST['import_type']=="sql")
{
$data = file_get_contents($_FILES["file"]["tmp_name"]);
$importSuccess = $db->import_sql($data);
}
else
{
$field_terminate = $_POST['import_csv_fieldsterminated'];
$field_enclosed = $_POST['import_csv_fieldsenclosed'];
$field_escaped = $_POST['import_csv_fieldsescaped'];
$null = $_POST['import_csv_replacenull'];
$fields_in_first_row = isset($_POST['import_csv_fieldnames']);
if(isset($_POST['single_table']) && $_POST['single_table']!='')
$table = $_POST['single_table'];
else
{
$table = basename($_FILES["file"]["name"],".csv");
$i="";
while($db->getTypeOfTable($table.$i)!="")
{
if($i=="")
$i=2;
else
$i++;
}
$table = $table.$i;
}
$importSuccess = $db->import_csv($_FILES["file"]["tmp_name"], $table, $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row);
}
}
//- Download (backup) a database file (as SQLite file, not as dump)
if(isset($_GET['download']) && isManagedDB($_GET['download'])!==false)
{
ob_end_clean();
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.basename($_GET['download']).'";');
header("Pragma: no-cache");
header("Expires: 0");
readfile($_GET['download']);
exit;
}
//- Select database (from session or first available)
if(!isset($currentDB) && count($databases)>0)
{
//set the current database to the first existing one in the array (default)
$currentDB = reset($databases);
$params->database = $currentDB['path'];
}
if(isset($currentDB))
{
//- Open database (creates a Database object)
$db = new Database($currentDB); //create the Database object
$db->registerUserFunction($custom_functions);
}
// collect parameters early, just once
$target_table = isset($_GET['table']) ? $_GET['table'] : null;
// are we working on a view? let's check once here
$target_table_type = !is_null($target_table) ? $db->getTypeOfTable($target_table) : null;
if(is_null($target_table_type) && !is_null($target_table))
$params->redirect(array('table'=>null), $lang['err'].': '.sprintf($lang['tbl_inexistent'], htmlencode($target_table)));
$params->table = $target_table;
// initialize / change fulltexts and numrows parameter
if(isset($_GET['fulltexts']))
$params->fulltexts = ($_GET['fulltexts'] ? 1 : 0);
else
$params->fulltexts = 0;
if(isset($_GET['numRows']) && intval($_GET['numRows'])>0)
$params->numRows = intval($_GET['numRows']);
else
$params->numRows = $rowsNum;
//- Switch on $_GET['action'] for operations without output
if(isset($_GET['action']) && isset($_GET['confirm']))
{
switch($_GET['action'])
{
//- Table actions
//- Create table (=table_create)
case "table_create":
$num = intval($_POST['rows']);
$name = $_POST['tablename'];
$primary_keys = array();
for($i=0; $i<$num; $i++)
{
if($_POST[$i.'_field']!="" && isset($_POST[$i.'_primarykey']))
{
$primary_keys[] = $_POST[$i.'_field'];
}
}
$query = "CREATE TABLE ".$db->quote($name)." (";
for($i=0; $i<$num; $i++)
{
if($_POST[$i.'_field']!="")
{
$query .= $db->quote($_POST[$i.'_field'])." ";
$query .= $_POST[$i.'_type']." ";
if(isset($_POST[$i.'_primarykey']))
{
if(count($primary_keys)==1)
{
$query .= "PRIMARY KEY ";
if(isset($_POST[$i.'_autoincrement']) && $db->getType() != "SQLiteDatabase")
$query .= "AUTOINCREMENT ";
}
$query .= "NOT NULL ";
}
if(!isset($_POST[$i.'_primarykey']) && isset($_POST[$i.'_notnull']))
$query .= "NOT NULL ";
if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr')
$query .= "DEFAULT ".$_POST[$i.'_defaultoption']." ";
elseif($_POST[$i.'_defaultoption']=='expr')
$query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") ";
elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined')
{
$typeAffinity = get_type_affinity($_POST[$i.'_type']);
if(($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC") && is_numeric($_POST[$i.'_defaultvalue']))
$query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." ";
else
$query .= "DEFAULT ".$db->quote($_POST[$i.'_defaultvalue'])." ";
}
$query = substr($query, 0, -1);
$query .= ", ";
}
}
if (count($primary_keys)>1)
{
$compound_key = "";
foreach ($primary_keys as $primary_key)
{
$compound_key .= ($compound_key=="" ? "" : ", ") . $db->quote($primary_key);
}
$query .= "PRIMARY KEY (".$compound_key."), ";
}
$query = substr($query, 0, -2);
$query .= ")";
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['tbl']." '".htmlencode($_POST['tablename'])."' ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(($result===false ? array() : array('action'=>'column_view', 'table'=>$name) ), $completed);
break;
//- Empty table (=table_empty)
case "table_empty":
if(isset($_GET['pk']))
$tables = json_decode($_GET['pk']);
else
$tables=array($_GET['table']);
$query1 = "BEGIN; ";
foreach($tables as $table)
{
if($db->getTypeOfTable($table)=='table')
$query1 .= "DELETE FROM ".$db->quote_id($table)."; ";
}
$query1 .= "COMMIT; ";
$result1=$db->multiQuery($query1);
if($result1 === false)
$completed = $db->getError(true);
if(isset($_POST['vacuum']) && $_POST['vacuum'])
{
$query2 = "VACUUM;";
$result2 = $db->query($query2);
}
else
$query2 = "";
if($result1 !== false)
$completed = $lang['tbl']." '".htmlencode(implode(', ',$tables))."' ".$lang['emptied'].".<br/><span style='font-size:11px;'>".htmlencode($query1)."<br />".htmlencode($query2)."</span>";
if(count($tables)==1)
$action = array('action'=>'row_view');
else
$action = array();
$params->redirect(($result1===false ? array() : $action ), $completed);
break;
//- Create view (=view_create)
case "view_create":
$query = "CREATE VIEW ".$db->quote($_POST['viewname'])." AS ".$_POST['select'];
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['view']." '".htmlencode($_POST['viewname'])."' ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(($result===false ? array() : array('action'=>'column_view', 'table'=>$_POST['viewname']) ), $completed);
break;
//- Drop table (or view) (=table_drop)
case "table_drop":
if(isset($_GET['pk']))
$tables = json_decode($_GET['pk']);
else
$tables=array($_GET['table']);
$query1 = "BEGIN; ";
foreach($tables as $table)
{
if($db->getTypeOfTable($table)=='table')
$query1 .= "DROP TABLE ".$db->quote_id($table)."; ";
else
$query1 .= "DROP VIEW ".$db->quote_id($table)."; ";
}
$query1 .= "COMMIT; ";
$result1=$db->multiQuery($query1);
if($result1 === false)
$completed = $db->getError(true);
if(isset($_POST['vacuum']) && $_POST['vacuum'])
{
$query2 = "VACUUM;";
$result2 = $db->query($query2);
}
else
$query2 = "";
if($result1 !== false)
{
$target_table = null;
$completed = $lang['tbl'].' / '.$lang['view']." '".htmlencode(implode(', ',$tables))."' ".$lang['dropped'].".<br/><span style='font-size:11px;'>".htmlencode($query1)."<br />".htmlencode($query2)."</span>";;
}
$params->redirect(array('table'=>null), $completed);
break;
//- Rename table (=table_rename)
case "table_rename":
$query = "ALTER TABLE ".$db->quote_id($_GET['table'])." RENAME TO ".$db->quote($_POST['newname']);
$type = $db->getTypeOfTable($_GET['table']);
if($db->getVersion()==3 && $type=='table' // SQLite 3 can rename tables, not views
// In SQL(ite) table names are case-insensitve, so changing is not supported by SQLite.
// But table names are stored and displayed case sensitive, so we use the workaround for case sensitive renaming.
&& !($_GET['table'] !== $_POST['newname'] && strtolower($_GET['table']) === strtolower($_POST['newname']))
)
$result = $db->query($query, true);
else
// Workaround can rename tables of sqlite2 and views of both sqlite versions. Can also do case sensitive renames.
$result = $db->query($query, false);
if($result === false)
$completed = $db->getError(true);
else
{
$completed = $lang['tbl']." '".htmlencode($_GET['table'])."' ".$lang['renamed']." '".htmlencode($_POST['newname'])."'.<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$target_table = $_POST['newname'];
}
$params->redirect(array('action'=>'row_view', 'table'=>$_POST['newname']), $completed);
break;
//- Search table (=table_search)
case "table_search":
$searchValues = array();
$searchOperators = array();
$tableInfo = $db->getTableInfo($target_table);
$j = 0;
$whereExpr = array();
for($i=0; $i<sizeof($tableInfo); $i++)
{
$field = $tableInfo[$i][1];
$operator = $_POST['field_'.$i.'_operator'];
$searchOperators[$field] = $operator;
$value = $_POST['field_'.$i.'_value'];
if($value!="" || $operator=="!= ''" || $operator=="= ''" || $operator == 'IS NULL' || $operator == 'IS NOT NULL')
{
if($operator=="= ''" || $operator=="!= ''" || $operator == 'IS NULL' || $operator == 'IS NOT NULL')
$whereExpr[$j] = $db->quote_id($field)." ".$operator;
else{
if($operator == "LIKE%"){
$operator = "LIKE";
if(!preg_match('/(^%)|(%$)/', $value)) $value = '%'.$value.'%';
$searchValues[$field] = array($value);
$valueQuoted = $db->quote($value);
}
elseif($operator == 'IN' || $operator == 'NOT IN')
{
$value = trim($value, '() ');
$values = explode(',',$value);
$values = array_map('trim', $values, array_fill(0,count($values),' \'"'));
if($operator == 'IN')
$searchValues[$field] = $values;
$values = array_map(array($db, 'quote'), $values);
$valueQuoted = '(' .implode(', ', $values) . ')';
}
else
{
$searchValues[$field] = array($value);
$valueQuoted = $db->quote($value);
}
$whereExpr[$j] = $db->quote_id($field)." ".$operator." ".$valueQuoted;
}
$j++;
}
}
$searchWhere = '';
if(sizeof($whereExpr)>0)
{
$searchWhere .= " WHERE ".$whereExpr[0];
for($i=1; $i<sizeof($whereExpr); $i++)
{
$searchWhere .= " AND ".$whereExpr[$i];
}
}
$searchID = md5($searchWhere);
$_SESSION[COOKIENAME.'search'][$searchID] = array(
'where' => $searchWhere,
'values' => $searchValues,
'operators' => $searchOperators
);
$params->redirect(array('action'=>'table_search','search'=>$searchID));
break;
//- Row actions
//- Create row (=row_create)
case "row_create":
$completed = "";
$num = $_POST['newRows'];
$z = 0;
$error = false;
$tableInfo = $db->getTableInfo($target_table);
for($i=0; $i<$num; $i++)
{
if(!isset($_POST[$i.":ignore"]))
{
$query_cols = "";
$query_vals = "";
$all_default = true;
for($j=0; $j<sizeof($tableInfo); $j++)
{
$null = isset($_POST[$j."_null"][$i]);
$type = strtoupper($tableInfo[$j]['type']);
$typeAffinity = get_type_affinity($type);
if(!$null && isset($_POST[$i.":".$j]))
$value = $_POST[$i.":".$j];
else
$value = "";
if(preg_match('/^BLOB/', $type) && !$hexblobs)
{
if($_FILES[$i.":".$j]["error"] == UPLOAD_ERR_OK && is_file($_FILES[$i.":".$j]["tmp_name"]))
$blobFiles[$j] = $_FILES[$i.":".$j]["tmp_name"];
else
$blobFiles[$j] = null;
}
elseif($value===$tableInfo[$j]['dflt_value'])
{
// if the value is the default value, skip it
continue;
}
$all_default = false;
$query_cols .= $db->quote_id($tableInfo[$j]['name']).",";
$function = $_POST["function_".$j][$i];
if($function!="")
$query_vals .= $function."(";
if(preg_match('/^BLOB/', $type) && !$hexblobs)
$query_vals .= ':blobval'.$j;
elseif(preg_match('/^BLOB/', $type) && $hexblobs)
$query_vals .= 'X'.$db->quote($value);
elseif(($typeAffinity=="TEXT" || $typeAffinity=="NONE") && !$null)
$query_vals .= $db->quote($value);
elseif(($typeAffinity=="INTEGER" || $typeAffinity=="REAL"|| $typeAffinity=="NUMERIC") && $value=="")
$query_vals .= "NULL";
elseif($null)
$query_vals .= "NULL";
else
$query_vals .= $db->quote($value);
if($function!="")
$query_vals .= ")";
$query_vals .= ",";
}
$query = "INSERT INTO ".$db->quote_id($target_table);
if(!$all_default)
{
$query_cols = substr($query_cols, 0, strlen($query_cols)-1);
$query_vals = substr($query_vals, 0, strlen($query_vals)-1);
$query.=" (". $query_cols . ") VALUES (". $query_vals. ")";
} else {
$query .= " DEFAULT VALUES";
}
if(isset($blobFiles))
{
// blob files need to be done using a prepared statement because the query size would be too large
$handle = $db->prepareQuery($query);
foreach($blobFiles as $j=>$filename)
$db->bindValue($handle, ':blobval'.$j, file_get_contents($filename), 'blob');
$result1 = $db->executePrepared($handle, false);
}
else
$result1 = $db->query($query);
if($result1===false)
$error = true;
$completed .= "<span style='font-size:11px;'>".htmlencode($query)."</span><br/>";
$z++;
}
}
if($error)
$completed = $db->getError(true) . $completed;
else
$completed = $z." ".$lang['rows']." ".$lang['inserted'].".<br/><br/>".$completed;
$params->redirect(array('action'=>'row_view'), $completed);
break;
//- Delete row (=row_delete)
case "row_delete":
$pks = json_decode($_GET['pk']);
$query = "DELETE FROM ".$db->quote_id($target_table)." WHERE (".$db->wherePK($target_table,json_decode($pks[0])).")";
for($i=1; $i<sizeof($pks); $i++)
{
$query .= " OR (".$db->wherePK($target_table,json_decode($pks[$i])).")";
}
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = sizeof($pks)." ".$lang['rows']." ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(array('action'=>'row_view'), $completed);
break;
//- Edit row (=row_edit)
case "row_edit":
$pks = json_decode($_GET['pk']);
$z = 0;
$tableInfo = $db->getTableInfo($target_table);
if(isset($_POST['new_row']))
$completed = "";
else
$completed = sizeof($pks)." ".$lang['rows']." ".$lang['affected'].".<br/><br/>";
for($i=0; $i<sizeof($pks); $i++)
{
if(isset($_POST['new_row']))
{
$query_cols = "";
$query_vals = "";
$all_default = true;
for($j=0; $j<sizeof($tableInfo); $j++)
{
$null = isset($_POST[$j."_null"][$i]);
$type = strtoupper($tableInfo[$j]['type']);
$typeAffinity = get_type_affinity($type);
if(!$null)
{
if(preg_match('/^BLOB/', $type) && !$hexblobs)
{
if(isset($_POST["row_".$i."_field_".$j."_blob_use"]) && $_POST["row_".$i."_field_".$j."_blob_use"]=='old')
{
$select = 'SELECT '.$db->quote_id($tableInfo[$j]['name']).' AS \'blob\' FROM '.$db->quote_id($target_table).' WHERE '.$db->wherePK($target_table, json_decode($pks[$i]));
$bl = $db->select($select);
$blobFiles[$j] = $bl['blob'];
unset($bl);
}
else
{
if($_FILES[$i.":".$j]["error"] == UPLOAD_ERR_OK && is_file($_FILES[$i.":".$j]["tmp_name"]))
$blobFiles[$j] = file_get_contents($_FILES[$i.":".$j]["tmp_name"]);
else
$blobFiles[$j] = null;
}
}
else
$value = $_POST[$j][$i];
}
else
$value = "";
if(!preg_match('/^BLOB/', $type) && $value===$tableInfo[$j]['dflt_value'])
{
// if the value is the default value, skip it
continue;
}
$all_default = false;
$query_cols .= $db->quote_id($tableInfo[$j]['name']).",";
$function = $_POST["function_".$j][$i];
if($function!="")
$query_vals .= $function."(";
if(preg_match('/^BLOB/', $type) && !$hexblobs)
$query_vals .= ':blobval'.$j;
elseif(preg_match('/^BLOB/', $type) && $hexblobs)
$query_vals .= 'X'.$db->quote($value);
elseif(($typeAffinity=="TEXT" || $typeAffinity=="NONE") && !$null)
$query_vals .= $db->quote($value);
elseif(($typeAffinity=="INTEGER" || $typeAffinity=="REAL"|| $typeAffinity=="NUMERIC") && $value=="")
$query_vals .= "NULL";
elseif($null)
$query_vals .= "NULL";
else
$query_vals .= $db->quote($value);
if($function!="")
$query_vals .= ")";
$query_vals .= ",";
}
$query = "INSERT INTO ".$db->quote_id($target_table);
if(!$all_default)
{
$query_cols = substr($query_cols, 0, strlen($query_cols)-1);
$query_vals = substr($query_vals, 0, strlen($query_vals)-1);
$query.=" (". $query_cols . ") VALUES (". $query_vals. ")";
} else {
$query .= " DEFAULT VALUES";
}
if(isset($blobFiles))
{
// blob files need to be done using a prepared statement because the query size would be too large
$handle = $db->prepareQuery($query);
foreach($blobFiles as $j=>$blobval)
$db->bindValue($handle, ':blobval'.$j, $blobval, 'blob');
$result1 = $db->executePrepared($handle, false);
}
else
$result1 = $db->query($query);
if($result1===false)
$error = true;
$z++;
}
else
{
$query = "UPDATE ".$db->quote_id($target_table)." SET ";
for($j=0; $j<sizeof($tableInfo); $j++)
{
$type = strtoupper($tableInfo[$j]['type']);
$function = $_POST["function_".$j][$i];
$null = isset($_POST[$j."_null"][$i]);
// if the old BLOB value is chosen to be kept, just skip this column
if(!$null && preg_match('/^BLOB/', $type) && isset($_POST["row_".$i."_field_".$j."_blob_use"]) && $_POST["row_".$i."_field_".$j."_blob_use"]=='old')
continue;
if(!$null && preg_match('/^BLOB/', $type) && !$hexblobs)
{
if($_FILES[$i.":".$j]["error"] == UPLOAD_ERR_OK && is_file($_FILES[$i.":".$j]["tmp_name"]))
$blobFiles[$j] = $_FILES[$i.":".$j]["tmp_name"];
else
$blobFiles[$j] = null;
}
$query .= $db->quote_id($tableInfo[$j]['name'])."=";
if($function!="")
$query .= $function."(";
if($null)
$query .= "NULL";
else
{
if(preg_match('/^BLOB/', $type) && !$hexblobs)
$query .= ':blobval'.$j;
elseif(preg_match('/^BLOB/', $type) && $hexblobs)
$query .= 'X'.$db->quote($_POST[$j][$i]);
else
$query .= $db->quote($_POST[$j][$i]);
}
if($function!="")
$query .= ")";
$query .= ", ";
}
$query = substr($query, 0, -2);
$query .= " WHERE ".$db->wherePK($target_table, json_decode($pks[$i]));
if(isset($blobFiles))
{
// blob files need to be done using a prepared statement because the query size would be too large
$handle = $db->prepareQuery($query);
foreach($blobFiles as $j=>$filename)
$db->bindValue($handle, ':blobval'.$j, file_get_contents($filename), 'blob');
$result1 = $db->executePrepared($handle, false);
}
else
$result1 = $db->query($query);
if($result1===false)
{
$error = true;
}
}
$completed .= "<span style='font-size:11px;'>".htmlencode($query)."</span><br/>";
}
if($error)
$completed = $db->getError(true) . $completed;
elseif(isset($_POST['new_row']))
$completed = $z." ".$lang['rows']." ".$lang['inserted'].".<br/><br/>".$completed;
$params->redirect(array('action'=>'row_view'), $completed);
break;
case "row_get_blob":
$blobVal = $db->select("SELECT ".$db->quote_id($_GET['column'])." AS 'blob' FROM ".$db->quote_id($target_table)." WHERE ".$db->wherePK($target_table, json_decode($_GET['pk'])));
$filename = 'download';
if(function_exists('getimagesizefromstring')) // introduced in PHP 5.4.0
$imagesize = getimagesizefromstring($blobVal['blob']);
if(isset($imagesize) && $imagesize!==false && isset($imagesize['mime']))
$mimetype = $imagesize['mime'];
elseif(class_exists('finfo')) // included since php 5.3.0, but might be disabled on Windows
{
$finfo = new finfo(FILEINFO_MIME);
$mimetype = $finfo->buffer($blobVal['blob']);
}
else
$mimetype = "application/octet-stream";
if(isset($imagesize) && $imagesize!==false && isset($imagesize[2]))
$extension = image_type_to_extension($imagesize[2]);
else
$extension = '.blob';
ob_end_clean();
header('Content-Length: '.strlen($blobVal['blob']));
header("Content-type: ".$mimetype);
if(isset($_GET['download_blob']) && $_GET['download_blob'])
header('Content-Disposition: attachment; filename="'.$filename.$extension.'";');
header("Pragma: no-cache");
header("Expires: 0");
echo $blobVal['blob'];
exit;
break;
//- Column actions
//- Create column (=column_create)
case "column_create":
$num = intval($_POST['rows']);
for($i=0; $i<$num; $i++)
{
if($_POST[$i.'_field']!="")
{
$query = "ALTER TABLE ".$db->quote_id($target_table)." ADD ".$db->quote($_POST[$i.'_field'])." ";
$query .= $_POST[$i.'_type']." ";
if(isset($_POST[$i.'_primarykey']))
$query .= "PRIMARY KEY ";
if(isset($_POST[$i.'_notnull']))
$query .= "NOT NULL ";
if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr')
$query .= "DEFAULT ".$_POST[$i.'_defaultoption']." ";
elseif($_POST[$i.'_defaultoption']=='expr')
$query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") ";
elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined')
{
$typeAffinity = get_type_affinity($_POST[$i.'_type']);
if(($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC") && is_numeric($_POST[$i.'_defaultvalue']))
$query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." ";
else
$query .= "DEFAULT ".$db->quote($_POST[$i.'_defaultvalue'])." ";
}
if($db->getVersion()==3 &&
($_POST[$i.'_defaultoption']=='defined' || $_POST[$i.'_defaultoption']=='none' || $_POST[$i.'_defaultoption']=='NULL')
// Sqlite3 cannot add columns with default values that are not constant
&& !isset($_POST[$i.'_primarykey'])
// sqlite3 cannot add primary key columns
&& (!isset($_POST[$i.'_notnull']) || $_POST[$i.'_defaultoption']!='none')
// SQLite3 cannot add NOT NULL columns without DEFAULT even if the table is empty
)
// use SQLITE3 ALTER TABLE ADD COLUMN
$result = $db->query($query, true);
else
// use ALTER TABLE workaround
$result = $db->query($query, false);
if($result===false)
$error = true;
}
}
if($error)
$completed = $db->getError(true);
else
$completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered'].".";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Delete column (=column_delete)
case "column_delete":
$pks = explode(":", $_GET['pk']);
$query = "ALTER TABLE ".$db->quote_id($target_table).' DROP '.$db->quote_id($pks[0]);
for($i=1; $i<sizeof($pks); $i++)
{
$query .= ", DROP ".$db->quote_id($pks[$i]);
}
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered'].".";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Add a primary key (=primarykey_add)
case "primarykey_add":
$pks = explode(":", $_GET['pk']);
$query = "ALTER TABLE ".$db->quote_id($target_table).' ADD PRIMARY KEY ('.$db->quote_id($pks[0]);
for($i=1; $i<sizeof($pks); $i++)
{
$query .= ", ".$db->quote_id($pks[$i]);
}
$query .= ")";
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered'].".";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Edit column (=column_edit)
case "column_edit":
$query = "ALTER TABLE ".$db->quote_id($target_table).' CHANGE '.$db->quote_id($_POST['oldvalue'])." ".$db->quote($_POST['0_field'])." ".$_POST['0_type'];
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered'].".";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Delete trigger (=trigger_delete)
case "trigger_delete":
$query = "DROP TRIGGER ".$db->quote_id($_GET['pk']);
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['trigger']." '".htmlencode($_GET['pk'])."' ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Delete index (=index_delete)
case "index_delete":
$query = "DROP INDEX ".$db->quote_id($_GET['pk']);
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['index']." '".htmlencode($_GET['pk'])."' ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Create trigger (=trigger_create)
case "trigger_create":
$str = "CREATE TRIGGER ".$db->quote($_POST['trigger_name']);
if($_POST['beforeafter']!="")
$str .= " ".$_POST['beforeafter'];
$str .= " ".$_POST['event']." ON ".$db->quote_id($target_table);
if(isset($_POST['foreachrow']))
$str .= " FOR EACH ROW";
if($_POST['whenexpression']!="")
$str .= " WHEN ".$_POST['whenexpression'];
$str .= " BEGIN";
$str .= " ".$_POST['triggersteps'];
$str .= " END";
$query = $str;
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['trigger']." ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
$params->redirect(array('action'=>'column_view'), $completed);
break;
//- Create index (=index_create)
case "index_create":
$num = $_POST['num'];
if($_POST['name']=="")
{
$completed = $lang['blank_index'];
}
else if($_POST['0_field']=="")
{
$completed = $lang['one_index'];
}
else
{
$str = "CREATE ";
if($_POST['duplicate']=="no")
$str .= "UNIQUE ";
$str .= "INDEX ".$db->quote($_POST['name'])." ON ".$db->quote_id($target_table)." (";
$str .= $db->quote_id($_POST['0_field']).$_POST['0_order'];
for($i=1; $i<$num; $i++)
{
if($_POST[$i.'_field']!="")
$str .= ", ".$db->quote_id($_POST[$i.'_field']).$_POST[$i.'_order'];
}
$str .= ")";
if(isset($_POST['where']) && $_POST['where']!='')
$str.=" WHERE ".$_POST['where'];
$query = $str;
$result = $db->query($query);
if($result === false)
$completed = $db->getError(true);
else
$completed = $lang['index']." ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>";
}
$params->redirect(array('action'=>'column_view'), $completed);
break;
}
}
}
// if not in debug mode, destroy all output until here
if($debug)
$bufferedOutput = ob_get_contents();
ob_end_clean();
//- HTML: output starts here
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $language; ?>" lang="<?php echo $language; ?>">
<head>
<!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> -->
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<link rel="shortcut icon" href="?resource=favicon" />
<title><?php echo PROJECT ?></title>
<?php
//- HTML: css/theme include
if(isset($_GET['theme'])) $theme = basename($_GET['theme']);
// allow themes to be dropped in subfolder "themes"
if(is_file('themes/'.$theme)) $theme = 'themes/'.$theme;
if (file_exists($theme))
// an external stylesheet exists - import it
echo "<link href='{$theme}' rel='stylesheet' type='text/css' />", PHP_EOL;
else
// only use the default stylesheet if an external one does not exist
echo "<link href='?resource=css' rel='stylesheet' type='text/css' />", PHP_EOL;
// HTML: output help text, then exit
if(isset($_GET['help']))
{
//help section array
$help = array($lang['help1'] => sprintf($lang['help1_x'], PROJECT, PROJECT, PROJECT));
for($i=2; isset($lang['help'.$i]); $i++)
$help[$lang['help'.$i]]=$lang['help'.$i.'_x'];
?>
</head>
<body style="direction:<?php echo $lang['direction']; ?>;">
<div id='help_container'>
<?php
echo "<div class='help_list'>";
echo "<span style='font-size:18px;'>".PROJECT." v".VERSION." ".$lang['help_doc']."</span><br/><br/>";
foreach((array)$help as $key => $val)
{
echo "<a href='#".$key."'>".$key."</a><br/>";
}
echo "</div>";
echo "<br/><br/>";
foreach((array)$help as $key => $val)
{
echo "<div class='help_outer'>";
echo "<a class='headd' name='".$key."'>".$key."</a>";
echo "<div class='help_inner'>";
echo $val;
echo "</div>";
echo "<a class='help_top' href='#top'>".$lang['back_top']."</a>";
echo "</div>";
}
?>
</div>
</body>
</html>
<?php
exit();
}
if($auth->isAuthorized())
{
//- Javascript include
?>
<!-- JavaScript Support -->
<script type='text/javascript' src='?resource=javascript'></script>
<script type="text/javascript">
var fileUploadMaxSize = <?php echo fileUploadMaxSize(); ?>;
var fileUploadMaxSizeErrorMsg = '<?php echo $lang['err'].': \n'.$lang['max_file_size']; ?>';
</script>
<!-- SQL code editor with Syntax Highlighting etc. -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.24.2/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.24.2/addon/hint/show-hint.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.24.2/codemirror.min.js"></script>
<!-- Codemirror 5.24.2 does not yet include the SQLite support that we wrote, so we fetch changed files from rawgit for the time being-->
<script src="https://cdn.rawgit.com/codemirror/CodeMirror/c4387d6073b15ccf0f32773eb71a54f3b694f2f0/mode/sql/sql.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.24.2/addon/hint/show-hint.min.js"></script>
<script src="https://cdn.rawgit.com/codemirror/CodeMirror/65c70cf5d18ac3a0c1a3fe717d90a81ff823aa9f/addon/hint/sql-hint.js"></script>
<?php
}
?>
</head>
<body style="direction:<?php echo $lang['direction']; ?>;">
<?php
// if in debug mode, ouput all output that has been generated above now
if($debug)
echo $bufferedOutput;
if(ini_get("register_globals") == "on" || ini_get("register_globals")=="1") //check whether register_globals is turned on - if it is, we need to not continue
{
echo "<div class='confirm' style='margin:20px;'>".$lang['bad_php_directive']."</div>";
echo "</body></html>";
exit();
}
//- HTML: login screen if not authorized, exit
if(!$auth->isAuthorized())
{
echo "<div id='loginBox'>";
echo "<h1><span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span></h1>";
echo "<div style='padding:15px; text-align:center;'>";
if (isset($_GET['failed']))
echo "<span class='warning'>".$lang['passwd_incorrect']."</span><br/><br/>";
echo $params->getForm();
echo $lang['passwd'].": <input type='password' name='password' autofocus='autofocus'/><br/>";
echo "<label><input type='checkbox' name='remember' value='yes' checked='checked'/> ".$lang['remember']."</label><br/><br/>";
echo "<input type='submit' value='".$lang['login']."' class='btn'/>";
echo "<input type='hidden' name='login' value='true' />";
echo "</form>";
echo "</div>";
echo "</div>";
echo "<br/>";
echo "<div style='text-align:center;'>";
echo "<span style='font-size:11px;'>".$lang['powered']." <a href='".PROJECT_URL."' target='_blank' style='font-size:11px;'>".PROJECT."</a> | ";
printf($lang['page_gen'], $pageTimer);
echo "</span></div>";
echo "</body></html>";
exit();
}
//- User is authorized, display the main application
if(count($databases)==0) // the database array is empty, offer to create a new database
{
//- HTML: form to create a new database, exit
if($directory!==false && is_writable($directory) && (is_executable($directory) || DIRECTORY_SEPARATOR === '\\'))
{
echo "<div class='confirm' style='margin:20px;'>";
printf($lang['no_db'], PROJECT, PROJECT);
echo "</div>";
//if the user has performed some action, show the resulting message
if(isset($_GET['message']) && isset($_SESSION[COOKIENAME.'messages'][$_GET['message']]))
{
echo "<div class='confirm' style='margin:10px 20px;'>";
echo $_SESSION[COOKIENAME.'messages'][$_GET['message']];
echo "</div><br />";
unset($_SESSION[COOKIENAME.'messages'][$_GET['message']]);
}
echo "<fieldset style='margin:15px;'><legend><b>".$lang['db_create']."</b></legend>";
echo $params->getForm(array('table'=>null), 'post', false, 'create_database');
echo "<input type='text' name='new_dbname' style='width:150px;'/> ";
if(class_exists('SQLiteDatabase') && (class_exists('SQLite3') || class_exists('PDO')))
{
echo "<select name='new_dbtype' class='newDbType'>";
echo "<option value='3'>SQLite 3</option>";
echo "<option value='2'>SQLite 2</option>";
echo "</select>";
}
echo "<input type='submit' value='".$lang['create']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
}
elseif($directory!==false && !is_executable($directory) && DIRECTORY_SEPARATOR === '/')
{
echo "<div class='confirm' style='margin:20px;'>";
echo $lang['err'].": ".sprintf($lang['dir_not_executable'], PROJECT, $directory);
echo "</div><br/>";
}
else
{
echo "<div class='confirm' style='margin:20px;'>";
echo $lang['err'].": ".sprintf($lang['no_db2'], PROJECT);
echo "</div><br/>";
}
exit();
}
//- HTML: sidebar
echo '<table class="body_tbl" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="left_td" style="width:100px; padding:9px 2px 9px 9px;">';
echo "<div id='leftNav'>";
echo "<h1><a href='".$params->getURL()."'>";
echo "<span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span>";
echo "</a></h1>";
echo "<div id='headerlinks'>";
echo "<a href='javascript:void' onclick='openHelp(\"top\");'>".$lang['docu']."</a> | ";
echo "<a href='https://www.gnu.org/licenses/gpl.html' target='_blank'>".$lang['license']."</a> | ";
echo "<a href='".PROJECT_URL."' target='_blank'>".$lang['proj_site']."</a>";
echo "</div>";
//- HTML: database list
$db->print_db_list();
echo "<fieldset style='margin:15px;'><legend>";
echo "<a href='".$params->getURL(array('table'=>null))."'";
if (!$target_table)
echo " class='active_table'";
$name = $currentDB['name'];
if(strlen($name)>25)
$name = "...".substr($name, strlen($name)-22, 22);
echo ">".htmlencode($name)."</a>";
echo "</legend>";
//- HTML: table list
$tables = $db->getTables(true, false);
foreach($tables as $tableName => $tableType)
{
echo "<span class='sidebar_table'>";
echo $params->getLink(array('action'=>'column_view', 'table'=>$tableName), "[".$lang[$tableType=='table'?'tbl':'view']."]");
echo "</span> ";
echo $params->getLink(array('action'=>'row_view', 'table'=>$tableName), htmlencode($tableName),
($target_table == $tableName ? 'active_table' : '') );
echo "<br/>";
}
if(count($tables)==0)
echo $lang['no_tbl'];
echo "</fieldset>";
//- HTML: form to create a new database
if($directory!==false && is_writable($directory))
{
echo "<fieldset style='margin:15px;'><legend><b>".$lang['db_create']."</b> ".helpLink($lang['help2'])."</legend>";
echo $params->getForm(array('table'=>null), 'post', false, 'create_database');
echo "<input type='text' name='new_dbname' style='width:150px;'/>";
if(class_exists('SQLiteDatabase') && (class_exists('SQLite3') || class_exists('PDO')))
{
echo "<select name='new_dbtype' class='newDbType'>";
echo "<option value='3'>SQLite 3</option>";
echo "<option value='2'>SQLite 2</option>";
echo "</select>";
}
echo "<input type='submit' value='".$lang['create']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
}
echo "<div style='text-align:center;'>";
echo $params->getForm(array(),'get');
echo "<input type='submit' value='".$lang['logout']."' name='logout' class='btn'/>";
echo "</form>";
echo "</div>";
echo "</div>";
echo '</td><td valign="top" id="main_column" class="right_td" style="padding:9px 2px 9px 9px;">';
//- HTML: breadcrumb navigation
echo $params->getLink(array('table'=>null), htmlencode($currentDB['name']));
if ($target_table)
echo " &rarr; ".$params->getLink(array('action'=>'row_view'), htmlencode($target_table));
echo "<br/><br/>";
//- Show the various tab views for a table
if($target_table)
{
//- HTML: tabs
echo $params->getLink(array('action'=>'row_view'), $lang['browse'],
(in_array($_GET['action'], array('row_view', 'row_editordelete') ) ? 'tab_pressed' : 'tab'));
echo $params->getLink(array('action'=>'column_view'), $lang['struct'],
(in_array($_GET['action'], array('column_view', 'column_edit', 'column_confirm', 'primarykey_add', 'column_create', 'index_create', 'index_delete', 'trigger_create', 'trigger_delete') ) ? 'tab_pressed' : 'tab'));
echo $params->getLink(array('action'=>'table_sql'), $lang['sql'],
($_GET['action']=="table_sql" ? 'tab_pressed' : 'tab'));
echo $params->getLink(array(
'action' => 'table_search',
'oldSearch' => (isset($_GET['search'])?$_GET['search']:null)
), $lang['srch'], ($_GET['action']=="table_search" ? 'tab_pressed' : 'tab'));
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('action'=>'row_create'), $lang['insert'],
($_GET['action']=="row_create" ? 'tab_pressed' : 'tab'));
echo $params->getLink(array('action'=>'table_export'), $lang['export'],
($_GET['action']=="table_export" ? 'tab_pressed' : 'tab'));
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('action'=>'table_import'), $lang['import'],
($_GET['action']=="table_import" ? 'tab_pressed' : 'tab'));
if($db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('action'=>'table_rename'), $lang['rename'],
($_GET['action']=="table_rename" ? 'tab_pressed' : 'tab'));
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo $params->getLink(array('action'=>'table_confirm','action2'=>'table_empty'), $lang['empty'],
(isset($_GET['action2']) && $_GET['action2']=="table_empty" ? 'tab_pressed empty' : 'tab empty'));
echo $params->getLink(array('action'=>'table_confirm','action2'=>'table_drop'), $lang['drop'],
(isset($_GET['action2']) && $_GET['action2']=="table_drop" ? 'tab_pressed drop' : 'tab drop'));
} elseif($db->isWritable() && $db->isDirWritable()) {
echo $params->getLink(array('action'=>'table_confirm','action2'=>'table_drop'), $lang['drop'],
(isset($_GET['action2']) && $_GET['action2']=="table_drop" ? 'tab_pressed drop' : 'tab drop'));
}
}
else
//- Show the various tab views for a database
{
$view = isset($_GET['view']) ? $_GET['view'] : 'structure';
echo $params->getLink(array('view'=>'structure'), $lang['struct'], ($view=="structure" ? 'tab_pressed': 'tab') );
echo $params->getLink(array('view'=>'sql'), $lang['sql'], ($view=="sql" ? 'tab_pressed': 'tab') );
echo $params->getLink(array('view'=>'export'), $lang['export'], ($view=="export" ? 'tab_pressed': 'tab') );
if($db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('view'=>'import'), $lang['import'], ($view=="import" ? 'tab_pressed': 'tab') );
if($db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('view'=>'vacuum'), $lang['vac'], ($view=="vacuum" ? 'tab_pressed': 'tab') );
if($directory!==false && is_writable($directory))
{
echo $params->getLink(array('view'=>'rename'), $lang['db_rename'], ($view=="rename" ? 'tab_pressed': 'tab') );
echo $params->getLink(array('view'=>'delete'), "<span>".$lang['db_del']."</span>", ($view=="delete" ? 'tab_pressed delete_db': 'tab delete_db') );
}
}
echo "<div style='clear:both;'></div>";
echo "<div id='main'>";
//- HTML: confirmation panel
//if the user has performed some action, show the resulting message
if(isset($_GET['message']) && isset($_SESSION[COOKIENAME.'messages'][$_GET['message']]))
{
echo "<div class='confirm'>";
echo $_SESSION[COOKIENAME.'messages'][$_GET['message']];
echo "</div><br />";
unset($_SESSION[COOKIENAME.'messages'][$_GET['message']]);
}
//- Switch on $_GET['action'] for operations with output
if(isset($_GET['action']) && !isset($_GET['confirm']))
{
switch($_GET['action'])
{
//- Table actions
//- Confirm table action (=table_confirm)
case "table_confirm":
if(isset($_GET['check']))
$pks = $_GET['check'];
elseif(isset($_GET['table']))
$pks = array($_GET['table']);
else $pks = array();
if(sizeof($pks)==0) //nothing was selected so show an error
{
echo "<div class='confirm'>";
echo $lang['err'].": ".$lang['no_sel'];
echo "</div>";
echo "<br/><br/>";
echo $params->getLink(array(), $lang['return']);
}
else
{
echo $params->getForm(array('action'=>$_GET['action2'], 'confirm'=>'1', 'pk'=>json_encode($pks)));
echo "<div class='confirm'>";
printf($lang['ques_'.$_GET['action2']], htmlencode(implode(', ',$pks)), htmlencode($target_table));
echo "<br/><br/>";
echo "<input type='checkbox' name='vacuum' checked='checked'/> ".$lang['vac_on_empty']."<br/><br/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
if(count($pks)==1)
$action = array('action'=>'row_view');
else
$action = array('table'=>null);
echo $params->getLink($action, $lang['cancel']);
echo "</div>";
}
break;
//- Create table (=table_create)
case "table_create":
$query = "SELECT name FROM sqlite_master WHERE type='table' AND name=".$db->quote($_GET['tablename']);
$results = $db->selectArray($query);
if(sizeof($results)>0)
$exists = true;
else
$exists = false;
echo "<h2>".$lang['create_tbl'].": '".htmlencode($_GET['tablename'])."'</h2>";
if($_GET['tablefields']=="" || intval($_GET['tablefields'])<=0)
echo $lang['specify_fields'];
else if($_GET['tablename']=="")
echo $lang['specify_tbl'];
else if($exists)
echo $lang['tbl_exists'];
else
{
$num = intval($_GET['tablefields']);
$name = $_GET['tablename'];
echo $params->getForm(array('action'=>'table_create', 'confirm'=>'1'));
echo "<input type='hidden' name='tablename' value='".htmlencode($name)."'/>";
echo "<input type='hidden' name='rows' value='".$num."'/>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
$headings = array($lang['fld'], $lang['type'], $lang['prim_key']);
if($db->getType() != "SQLiteDatabase") $headings[] = $lang['autoincrement'];
$headings[] = $lang['not_null'];
$headings[] = $lang['def_val'];
for($k=0; $k<count($headings); $k++)
echo "<td class='tdheader'>" . $headings[$k] . "</td>";
echo "</tr>";
for($i=0; $i<$num; $i++)
{
$tdWithClass = "<td class='td" . ($i%2 ? "1" : "2") . "'>";
echo "<tr>";
echo $tdWithClass;
echo "<input type='text' name='".$i."_field' style='width:200px;'/>";
echo "</td>";
echo $tdWithClass;
echo "<select name='".$i."_type' id='i".$i."_type' onchange='toggleAutoincrement(".$i.");'>";
foreach ($sqlite_datatypes as $t) {
echo "<option value='".htmlencode($t)."'>".htmlencode($t)."</option>";
}
echo "</select>";
echo "</td>";
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_primarykey' id='i".$i."_primarykey' onclick='toggleNull(".$i."); toggleAutoincrement(".$i.");'/> ".$lang['yes']."</label>";
echo "</td>";
if($db->getType() != "SQLiteDatabase")
{
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_autoincrement' id='i".$i."_autoincrement'/> ".$lang['yes']."</label>";
echo "</td>";
}
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_notnull' id='i".$i."_notnull'/> ".$lang['yes']."</label>";
echo "</td>";
echo $tdWithClass;
echo "<select name='".$i."_defaultoption' id='i".$i."_defaultoption' onchange=\"if(this.value!='defined' && this.value!='expr') document.getElementById('i".$i."_defaultvalue').value='';\">";
echo "<option value='none'>".$lang['none']."</option><option value='defined'>".$lang['as_defined'].":</option><option>NULL</option><option>CURRENT_TIME</option><option>CURRENT_DATE</option><option>CURRENT_TIMESTAMP</option><option value='expr'>".$lang['expression'].":</option>";
echo "</select>";
echo "<input type='text' name='".$i."_defaultvalue' id='i".$i."_defaultvalue' style='width:100px;' onchange=\"if(document.getElementById('i".$i."_defaultoption').value!='expr') document.getElementById('i".$i."_defaultoption').value='defined';\"/>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='6'>";
echo "<input type='submit' value='".$lang['create']."' class='btn'/> ";
echo $params->getLink(array(), $lang['cancel']);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
if($db->getType() != "SQLiteDatabase") echo "<script type='text/javascript'>window.onload=initAutoincrement;</script>";
}
break;
//- Perform SQL query on table (=table_sql)
case "table_sql":
if(isset($_POST['query']) && $_POST['query']!="")
{
$delimiter = $_POST['delimiter'];
$queryStr = $_POST['queryval'];
//save the queries in history if necessary
if($maxSavedQueries!=0 && $maxSavedQueries!=false)
{
if(!isset($_SESSION[COOKIENAME.'query_history']))
$_SESSION[COOKIENAME.'query_history'] = array();
$_SESSION[COOKIENAME.'query_history'][md5(strtolower($queryStr))] = $queryStr;
if(sizeof($_SESSION[COOKIENAME.'query_history']) > $maxSavedQueries)
array_shift($_SESSION[COOKIENAME.'query_history']);
}
$query = explode_sql($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter
for($i=0; $i<sizeof($query); $i++) //iterate through the queries exploded by the delimiter
{
if(str_replace(" ", "", str_replace("\n", "", str_replace("\r", "", $query[$i])))!="") //make sure this query is not an empty string
{
$queryTimer = new MicroTimer();
$table_result = $db->query($query[$i]);
echo "<div class='confirm'>";
echo "<b>".htmlencode($query[$i])."</b>";
if($table_result === NULL || $table_result === false)
{
echo "<br /><b>".$lang['err'].": ".htmlencode($db->getError())."</b></div>";
}
echo "</div><br/>";
if($row = $db->fetch($table_result, 'num'))
{
for($j=0; $j<sizeof($row);$j++)
$headers[$j] = $db->getColumnName($table_result,$j);
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
for($j=0; $j<sizeof($headers); $j++)
{
echo "<td class='tdheader'>";
echo htmlencode($headers[$j]);
echo "</td>";
}
echo "</tr>";
$rowCount = 0;
for(; $rowCount==0 || $row = $db->fetch($table_result, 'num'); $rowCount++)
{
$tdWithClass = "<td class='td".($rowCount%2 ? "1" : "2")."'>";
echo "<tr>";
for($z=0; $z<sizeof($headers); $z++)
{
echo $tdWithClass;
if($row[$z]==="")
echo "&nbsp;";
elseif($row[$z]===NULL)
echo "<i class='null'>NULL</i>";
else
echo htmlencode(subString($row[$z]));
echo "</td>";
}
echo "</tr>";
}
$queryTimer->stop();
echo "</table><br/><br/>";
if($table_result !== NULL && $table_result !== false)
{
echo "<div class='confirm' style='margin-bottom: 2em'>";
if($rowCount>0 || $db->getAffectedRows()==0)
{
printf($lang['show_rows'], $rowCount);
}
if($db->getAffectedRows()>0 || $rowCount==0)
{
echo $db->getAffectedRows()." ".$lang['rows_aff']." ";
}
printf($lang['query_time'], $queryTimer);
echo "</div>";
}
}
}
}
}
else
{
$delimiter = ";";
$queryStr = "SELECT * FROM ".$db->quote_id($target_table)." WHERE 1";
}
echo "<fieldset>";
echo "<legend><b>".sprintf($lang['run_sql'],htmlencode($db->getName()))."</b></legend>";
echo $params->getForm(array('action'=>'table_sql'));
if(isset($_SESSION[COOKIENAME.'query_history']) && sizeof($_SESSION[COOKIENAME.'query_history'])>0)
{
echo "<b>".$lang['recent_queries']."</b><ul>";
foreach($_SESSION[COOKIENAME.'query_history'] as $key => $value)
echo "<li><a onclick='sqleditorSetValue(this.textContent); return false;' href='#'>".htmlencode($value)."</a></li>";
echo "</ul><br/><br/>";
}
echo "<div style='float:left; width:70%;'>";
echo "<textarea style='width:97%; height:300px;' name='queryval' id='queryval' cols='50' rows='8'>".htmlencode($queryStr)."</textarea>";
echo "<script>sqleditor(document.getElementById('queryval'),".json_encode($db->getTableDefinitions()).",'".htmlencode($target_table)."');</script>";
echo "</div>";
echo "<div style='float:left; width:28%; padding-left:10px;'>";
echo $lang['fields']."<br/>";
echo "<select multiple='multiple' style='width:100%;' id='fieldcontainer'>";
$tableInfo = $db->getTableInfo($target_table);
for($i=0; $i<sizeof($tableInfo); $i++)
{
echo "<option value='".htmlencode($tableInfo[$i][1])."'>".htmlencode($tableInfo[$i][1])."</option>";
}
echo "</select>";
echo "<input type='button' value='&lt;&lt;' onclick='moveFields();' class='btn'/>";
echo "</div>";
echo "<div style='clear:both;'></div>";
echo $lang['delimit']." <input type='text' name='delimiter' value='".htmlencode($delimiter)."' style='width:50px;'/> ";
echo "<input type='submit' name='query' value='".$lang['go']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
break;
//- Export table (=table_export)
case "table_export":
echo $params->getForm();
echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>".$lang['export']."</b></legend>";
echo "<input type='hidden' value='".htmlencode($target_table)."' name='single_table'/>";
echo "<label><input type='radio' name='export_type' checked='checked' value='sql' onclick='toggleExports(\"sql\");'/> ".$lang['sql']."</label>";
echo "<br/><label><input type='radio' name='export_type' value='csv' onclick='toggleExports(\"csv\");'/> ".$lang['csv']."</label>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px;' id='exportoptions_sql'><legend><b>".$lang['options']."</b></legend>";
echo "<label><input type='checkbox' checked='checked' name='structure'/> ".$lang['export_struct']."</label> ".helpLink($lang['help5'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='data'/> ".$lang['export_data']."</label> ".helpLink($lang['help6'])."<br/>";
echo "<label><input type='checkbox' name='drop'/> ".$lang['add_drop']."</label> ".helpLink($lang['help7'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='transaction'/> ".$lang['add_transact']."</label> ".helpLink($lang['help8'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='comments'/> ".$lang['comments']."</label> ".helpLink($lang['help9'])."<br/>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px; display:none;' id='exportoptions_csv'><legend><b>".$lang['options']."</b></legend>";
echo "<div style='float:left;'>".$lang['fld_terminated']."</div>";
echo "<input type='text' value=';' name='export_csv_fieldsterminated' style='float:right;'/>";
echo "<div style='clear:both;'></div>";
echo "<div style='float:left;'>".$lang['fld_enclosed']."</div>";
echo "<input type='text' value='\"' name='export_csv_fieldsenclosed' style='float:right;'/>";
echo "<div style='clear:both;'></div>";
echo "<div style='float:left;'>".$lang['fld_escaped']."</div>";
echo "<input type='text' value='\' name='export_csv_fieldsescaped' style='float:right;'/>";
echo "<div style='clear:both;'></div>";
echo "<div style='float:left;'>".$lang['rep_null']."</div>";
echo "<input type='text' value='NULL' name='export_csv_replacenull' style='float:right;'/>";
echo "<div style='clear:both;'></div>";
echo "<label><input type='checkbox' name='export_csv_crlf'/> ".$lang['rem_crlf']."</label><br/>";
echo "<label><input type='checkbox' checked='checked' name='export_csv_fieldnames'/> ".$lang['put_fld']."</label>";
echo "</fieldset>";
echo "<div style='clear:both;'></div>";
echo "<br/><br/>";
echo "<fieldset><legend><b>".$lang['save_as']."</b></legend>";
$file = pathinfo($db->getPath());
$name = $file['filename'];
echo "<input type='text' name='filename' value='".htmlencode($name)."_".htmlencode($target_table)."_".date("Y-m-d").".dump' style='width:400px;'/> <input type='submit' name='export' value='".$lang['export']."' class='btn'/>";
echo "</fieldset>";
echo "</form>";
echo "<div class='confirm' style='margin-top: 2em'>".sprintf($lang['backup_hint'],
$params->getLink(array('download' => $currentDB['path'], 'token' => $_SESSION[COOKIENAME.'token']), $lang["backup_hint_linktext"], '', $lang['backup']))."</div>";
break;
//- Import table (=table_import)
case "table_import":
if(isset($_POST['import']))
{
echo "<div class='confirm'>";
if($importSuccess===true)
echo $lang['import_suc'];
else
echo $lang['err'].': '.htmlencode($importSuccess);
echo "</div><br/>";
}
echo $params->getForm(array('action' => 'table_import'), 'post', true);
echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>".$lang['import_into']." ".htmlencode($target_table)."</b></legend>";
echo "<label><input type='radio' name='import_type' checked='checked' value='sql' onclick='toggleImports(\"sql\");'/> ".$lang['sql']."</label>";
echo "<br/><label><input type='radio' name='import_type' value='csv' onclick='toggleImports(\"csv\");'/> ".$lang['csv']."</label>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px;' id='importoptions_sql'><legend><b>".$lang['options']."</b></legend>";
echo $lang['no_opt'];
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px; display:none;' id='importoptions_csv'><legend><b>".$lang['options']."</b></legend>";
echo "<input type='hidden' value='".htmlencode($target_table)."' name='single_table'/>";
echo "<div style='float:left;'>".$lang['fld_terminated']."</div>";
echo "<input type='text' value=';' name='import_csv_fieldsterminated' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_enclosed']."</div>";
echo "<input type='text' value='\"' name='import_csv_fieldsenclosed' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_escaped']."</div>";
echo "<input type='text' value='\' name='import_csv_fieldsescaped' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['rep_null']."</div>";
echo "<input type='text' value='NULL' name='import_csv_replacenull' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<label><input type='checkbox' checked='checked' name='import_csv_fieldnames'/> ".$lang['fld_names']."</label>";
echo "</fieldset>";
echo "<div style='clear:both;'></div>";
echo "<br/><br/>";
echo "<fieldset><legend><b>".$lang['import_f']."</b></legend>";
echo "<em>".$lang['max_file_size'].": ".number_format(fileUploadMaxSize()/1024/1024)." MiB</em> ".helpLink($lang['help11'])."<br />";
echo "<input type='file' value='".$lang['choose_f']."' name='file' style='background-color:transparent; border-style:none; margin:0; padding:0' onchange='checkFileSize(this)'/>";
echo "<input type='submit' value='".$lang['import']."' name='import' class='btn'/>";
echo "</fieldset>";
break;
//- Rename table (=table_rename)
case "table_rename":
echo $params->getForm(array('action'=>'table_rename', 'confirm'=>'1'));
printf($lang['rename_tbl'], htmlencode($target_table));
echo " <input type='text' name='newname' value='".htmlencode($target_table)."' style='width:200px;'/> <input type='submit' value='".$lang['rename']."' name='rename' class='btn'/>";
echo "</form>";
break;
//- Search table (=table_search)
case "table_search":
if(!isset($_GET['search']))
{
$tableInfo = $db->getTableInfo($target_table);
echo $params->getForm(array('action'=>'table_search', 'confirm'=>'1'));
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td class='tdheader'>".$lang['fld']."</td>";
echo "<td class='tdheader'>".$lang['type']."</td>";
echo "<td class='tdheader'>".$lang['operator']."</td>";
echo "<td class='tdheader'>".$lang['val']."</td>";
echo "</tr>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
$field = $tableInfo[$i][1];
$type = $tableInfo[$i]['type'];
$typeAffinity = get_type_affinity($type);
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
if(isset($_GET['oldSearch']) && isset($_SESSION[COOKIENAME.'search'][$_GET['oldSearch']]['values'][$field]))
$value = implode($_SESSION[COOKIENAME.'search'][$_GET['oldSearch']]['values'][$field], ",");
else
$value = '';
if(isset($_GET['oldSearch']) && isset($_SESSION[COOKIENAME.'search'][$_GET['oldSearch']]['operators'][$field]))
$operator = $_SESSION[COOKIENAME.'search'][$_GET['oldSearch']]['operators'][$field];
elseif($typeAffinity=="TEXT" || $typeAffinity=="NONE")
$operator = 'LIKE';
else
$operator = '=';
echo "<tr>";
echo $tdWithClassLeft;
echo htmlencode($field);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($type);
echo "</td>";
echo $tdWithClassLeft;
echo "<select name='field_".$i."_operator' onchange='checkLike(\"field_".$i."_value\", this.options[this.selectedIndex].value); '>";
$operators = array('=', '>', '>=', '<', '<=', "= ''", "!= ''", '!=', 'LIKE', 'LIKE%','NOT LIKE', 'IN', 'NOT IN', 'IS NULL', 'IS NOT NULL');
$operatorsDisplay = array('LIKE%' => 'LIKE %...%', 'IN'=>'IN (..., ...)', 'NOT IN'=>'NOT IN (..., ...)');
$operatorsNumbersOnly = array('>', '>=', '<', '<=');
$operatorsTextOnly = array("= ''", "!= ''");
foreach($operators as $op)
{
if($typeAffinity!="INTEGER" && $typeAffinity!="REAL" && $typeAffinity!="NUMERIC" && in_array($op, $operatorsNumbersOnly))
continue;
if($typeAffinity!="TEXT" && $typeAffinity!="NONE" && in_array($op, $operatorsTextOnly))
continue;
$display = (isset($operatorsDisplay[$op]) ? $operatorsDisplay[$op] : $op);
echo "<option value='".htmlencode($op)."'".($operator==$op?" selected='selected'":'').">".htmlencode($display)."</option>";
}
echo "</select>";
echo "</td>";
echo $tdWithClassLeft;
if($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC")
echo "<input type='text' id='field_".$i."_value' name='field_".$i."_value' value='".htmlencode($value)."'/>";
else
echo "<textarea id='field_".$i."_value' name='field_".$i."_value' rows='1' cols='60'>".htmlencode($value)."</textarea>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='4'>";
echo "<input type='submit' value='".$lang['srch']."' class='btn'/>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
break;
}
elseif(isset($_SESSION[COOKIENAME.'search'][$_GET['search']]))
{
$params->search = $_GET['search'];
$search = $_SESSION[COOKIENAME.'search'][$_GET['search']];
// NOTICE: we do not break here!! we just do the same now like row_view-action does
}
//- Row actions
//- View row (=row_view)
case "row_view":
if(!isset($_GET['startRow']))
$_GET['startRow'] = 0;
if(isset($_SESSION[COOKIENAME.'currentTable']) && $_SESSION[COOKIENAME.'currentTable']!=$target_table)
{
unset($_SESSION[COOKIENAME.'sortRows']);
unset($_SESSION[COOKIENAME.'orderRows']);
}
if(isset($_GET['viewtype']))
{
$_SESSION[COOKIENAME.'viewtype'] = $_GET['viewtype'];
}
//- Query execution
if(!isset($_GET['sort']))
$_GET['sort'] = NULL;
if(!isset($_GET['order']))
$_GET['order'] = NULL;
$numRows = $params->numRows;
$startRow = $_GET['startRow'];
if(isset($_GET['sort']))
{
$_SESSION[COOKIENAME.'sortRows'] = $_GET['sort'];
$_SESSION[COOKIENAME.'currentTable'] = $target_table;
}
if(isset($_GET['order']))
{
$_SESSION[COOKIENAME.'orderRows'] = $_GET['order'];
$_SESSION[COOKIENAME.'currentTable'] = $target_table;
}
$query = "SELECT * ";
// select the primary key column(s) last (ROWID if there is no PK).
// this will be used to identify rows, e.g. when editing/deleting rows
$primary_key = $db->getPrimaryKey($target_table);
foreach($primary_key as $pk)
{
$query.= ', '.$db->quote_id($pk);
$query.= ', typeof('.$db->quote_id($pk).')';
}
$query .= " FROM ".$db->quote_id($target_table);
$queryDisp = "SELECT * FROM ".$db->quote_id($target_table);
$queryCount = "SELECT COUNT(*) AS count FROM ".$db->quote_id($target_table);
$queryAdd = "";
if(isset($search) && isset($search['where']))
{
$queryAdd = $search['where'];
$queryCount .= $search['where'];
}
if(isset($_SESSION[COOKIENAME.'sortRows']))
$queryAdd .= " ORDER BY ".$db->quote_id($_SESSION[COOKIENAME.'sortRows']);
if(isset($_SESSION[COOKIENAME.'orderRows']))
$queryAdd .= " ".$_SESSION[COOKIENAME.'orderRows'];
$queryAdd .= " LIMIT ".$startRow.", ".$numRows;
$query .= $queryAdd;
$queryDisp .= $queryAdd;
$resultRows = $db->select($queryCount);
$totalRows = $resultRows['count'];
$shownRows = min($resultRows['count']-$startRow, $numRows);
//- HTML: pagination buttons
$lastPage = intval($totalRows / $params->numRows);
$remainder = intval($totalRows % $params->numRows);
if($remainder==0)
$remainder = $params->numRows;
echo "<div style=''>";
//previous button
if($_GET['startRow']>0)
{
echo "<div style='float:left;'>";
echo $params->getForm(array('action'=>$_GET['action']),'get');
echo "<input type='hidden' name='startRow' value='0'/>";
echo "<input type='submit' value='&larr;&larr;' class='btn'/> ";
echo "</form>";
echo "</div>";
echo "<div style='float:left; overflow:hidden; margin-right:20px;'>";
echo $params->getForm(array('action'=>$_GET['action']),'get');
echo "<input type='hidden' name='startRow' value='".max(0,intval($_GET['startRow']-$params->numRows))."'/>";
echo "<input type='submit' value='&larr;' class='btn'/> ";
echo "</form>";
echo "</div>";
}
//show certain number buttons
echo "<div style='float:left;'>";
echo $params->getForm(array('action'=>$_GET['action'], 'numRows'=>null),'get');
echo "<input type='submit' value='".$lang['show']." : ' name='show' class='btn'/> ";
echo "<input type='text' name='numRows' style='width:50px;' value='".$params->numRows."'/> ";
echo $lang['rows_records'];
if(intval($_GET['startRow']+$params->numRows) < $totalRows)
echo "<input type='text' name='startRow' style='width:90px;' value='".intval($_GET['startRow']+$params->numRows)."'/>";
else
echo "<input type='text' name='startRow' style='width:90px;' value='0'/> ";
echo $lang['as_a'];
echo " <select name='viewtype'>";
if(!isset($_SESSION[COOKIENAME.'viewtype']) || $_SESSION[COOKIENAME.'viewtype']=="table")
{
echo "<option value='table' selected='selected'>".$lang['tbl']."</option>";
echo "<option value='chart'>".$lang['chart']."</option>";
}
else
{
echo "<option value='table'>".$lang['tbl']."</option>";
echo "<option value='chart' selected='selected'>".$lang['chart']."</option>";
}
echo "</select>";
echo "</form>";
echo "</div>";
//next button
if(intval($_GET['startRow']+$params->numRows)<$totalRows)
{
echo "<div style='float:left; margin-left:20px; '>";
echo $params->getForm(array('action'=>$_GET['action']),'get');
echo "<input type='hidden' name='startRow' value='".intval($_GET['startRow']+$params->numRows)."'/>";
echo "<input type='submit' value='&rarr;' class='btn'/> ";
echo "</form>";
echo "</div>";
echo "<div style='float:left; '>";
echo $params->getForm(array('action'=>$_GET['action']),'get');
echo "<input type='hidden' name='startRow' value='".intval($totalRows-$remainder)."'/>";
echo "<input type='submit' value='&rarr;&rarr;' class='btn'/> ";
echo "</form>";
echo "</div>";
}
echo "<div style='clear:both;'></div>";
echo "</div>";
//- Show results
if($shownRows>0)
{
$queryTimer = new MicroTimer();
$table_result = $db->query($query);
$queryTimer->stop();
echo "<br/><div class='confirm'>";
echo "<b>".$lang['showing_rows']." ".$startRow." - ".($startRow + $shownRows-1).", ".$lang['total'].": ".$totalRows." ";
printf($lang['query_time'], $queryTimer);
echo "</b><br/>";
echo "<span style='font-size:11px;'>".htmlencode($queryDisp)."</span>";
echo "</div><br/>";
if($target_table_type == 'view')
{
echo sprintf($lang['readonly_tbl'], htmlencode($target_table))." <a href='https://en.wikipedia.org/wiki/View_(SQL)' target='_blank'>https://en.wikipedia.org/wiki/View_(SQL)</a>";
echo "<br/><br/>";
}
$tableInfo = $db->getTableInfo($target_table);
$pkFirstCol = sizeof($tableInfo)+1;
//- Table view
if(!isset($_SESSION[COOKIENAME.'viewtype']) || $_SESSION[COOKIENAME.'viewtype']=="table")
{
echo $params->getForm(array('action'=>'row_editordelete'), 'post', false, 'checkForm');
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td colspan='3' class='tdheader' style='text-align:center'>";
echo "<a href='".$params->getURL(array('action'=>$_GET['action'], 'fulltexts'=>($params->fulltexts?0:1) ))."' title='".$lang[($params->fulltexts?'no_full_texts':'full_texts')]."'>";
echo "<b>&".($params->fulltexts?'r':'l')."arr;</b>&nbsp;T&nbsp;<b>&".($params->fulltexts?'l':'r')."arr;</b></a>";
echo "</td>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
echo "<td class='tdheader'>";
if(isset($_SESSION[COOKIENAME.'sortRows']))
$orderTag = ($_SESSION[COOKIENAME.'sortRows']==$tableInfo[$i]['name'] && $_SESSION[COOKIENAME.'orderRows']=="ASC") ? "DESC" : "ASC";
else
$orderTag = "ASC";
echo $params->getLink(array('action'=>$_GET['action'], 'sort'=>$tableInfo[$i]['name'], 'order'=>$orderTag ), htmlencode($tableInfo[$i]['name']));
if(isset($_SESSION[COOKIENAME.'sortRows']) && $_SESSION[COOKIENAME.'sortRows']==$tableInfo[$i]['name'])
echo (($_SESSION[COOKIENAME.'orderRows']=="ASC") ? " <b>&uarr;</b>" : " <b>&darr;</b>");
echo "</td>";
}
echo "</tr>";
for($i=0; $row = $db->fetch($table_result, 'num'); $i++)
{
// -g-> $pk will always be the last columns in each row of the array because we are doing "SELECT *, PK_1, typeof(PK_1), PK2, typeof(PK_2), ... FROM ..."
$pk_arr = array();
for($col = $pkFirstCol; array_key_exists($col, $row); $col=$col+2)
{
// in $col we have the type and in $col-1 the value
if($row[$col]=='integer' || $row[$col]=='real')
// json encode as int or float, not string
$pk_arr[] = $row[$col-1]+0;
else
// encode as json string
$pk_arr[] = $row[$col-1];
}
$pk = json_encode($pk_arr);
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
echo "<tr>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo $tdWithClass;
echo "<input type='checkbox' name='check[]' value='".htmlencode($pk)."' id='check_".htmlencode($i)."'/>";
echo "</td>";
echo $tdWithClass;
// -g-> Here, we need to put the PK in as the link for both the edit and delete.
echo $params->getLink(array('action'=>'row_editordelete', 'pk'=>$pk, 'type'=>'edit'),"<span>".$lang['edit']."</span>",'edit', $lang['edit']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('action'=>'row_editordelete', 'pk'=>$pk, 'type'=>'delete'),"<span>".$lang['del']."</span>",'delete', $lang['del']);
echo "</td>";
} else {
echo "<td class='td".($i%2 ? "1" : "2")."' colspan='3'></td>";
}
for($j=0; $j<sizeof($tableInfo); $j++)
{
$typeAffinity = get_type_affinity($tableInfo[$j]['type']);
if($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC")
echo $tdWithClass;
else
echo $tdWithClassLeft;
if($row[$j]==="")
echo "&nbsp;";
elseif($row[$j]===NULL)
echo "<i class='null'>NULL</i>";
elseif(preg_match('/^BLOB/i', $tableInfo[$j]['type']) && !$hexblobs)
{
echo "<div style='float:left; text-align: left; padding-right:2em'>";
echo $params->getLink(array('action'=>'row_get_blob', 'confirm'=>1, 'pk'=>$pk, 'column'=>$tableInfo[$j]['name'], 'download_blob'=>1),$lang["download"]).' | ';
echo $params->getLink(array('action'=>'row_get_blob', 'confirm'=>1, 'pk'=>$pk, 'column'=>$tableInfo[$j]['name'], 'download_blob'=>0),$lang["open_in_browser"],'','','_blank');
echo "</div><div style='float:right; text-align: right'>";
echo 'Size: '.number_format(strlen($row[$j])).' Bytes';
echo "</div>";
}
elseif(preg_match('/^BLOB/i', $tableInfo[$j]['type']) && $hexblobs)
{
echo htmlencode(subString(bin2hex($row[$j])));
}
elseif(isset($search))
echo markSearchWords(subString($row[$j]),$tableInfo[$j]['name'], $search);
else
echo htmlencode(subString($row[$j]));
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo "<a onclick='checkAll()'>".$lang['chk_all']."</a> / <a onclick='uncheckAll()'>".$lang['unchk_all']."</a> <i>".$lang['with_sel'].":</i> ";
echo "<select name='type'>";
echo "<option value='edit'>".$lang['edit']."</option>";
echo "<option value='delete'>".$lang['del']."</option>";
echo "</select> ";
echo "<input type='submit' value='".$lang['go']."' name='massGo' class='btn'/>";
}
echo "</form>";
}
else
//- Chart view
{
if(!isset($_SESSION[COOKIENAME.$target_table.'chartlabels']))
{
// No label-column set. Try to pick a text-column as label-column.
for($i=0; $i<sizeof($tableInfo); $i++)
{
if(get_type_affinity($tableInfo[$i]['type'])=='TEXT')
{
$_SESSION[COOKIENAME.$target_table.'chartlabels'] = $i;
break;
}
}
}
if(!isset($_SESSION[COOKIENAME.$target_table.'chartlabels']))
// no text column found, use the first column
$_SESSION[COOKIENAME.$target_table.'chartlabels'] = 0;
if(!isset($_SESSION[COOKIENAME.$target_table.'chartvalues']))
{
// No value-column set. Pick the first numeric column if possible.
// If not possible, pick the first column that is not the label-column.
$potential_value_column = null;
for($i=0; $i<sizeof($tableInfo); $i++)
{
if($potential_value_column===null && $i != $_SESSION[COOKIENAME.$target_table.'chartlabels'])
// the first column (of any type) that is not the label-column
$potential_value_column = $i;
// check if the col is numeric
$typeAffinity = get_type_affinity($tableInfo[$i]['type']);
if($typeAffinity=='INTEGER' || $typeAffinity=='REAL' || $typeAffinity=='NUMERIC')
{
// this is defined as a numeric column, so prefer this as a value column over $potential_value_column
$_SESSION[COOKIENAME.$target_table.'chartvalues'] = $i;
break;
}
}
if(!isset($_SESSION[COOKIENAME.$target_table.'chartvalues']))
{
// we did not find a numeric column
if($potential_value_column!==null)
// use the $potential_value_column, i.e. the second column which is not the label-column
$_SESSION[COOKIENAME.$target_table.'chartvalues'] = $potential_value_column;
else
// it's hopeless, there is only 1 column
$_SESSION[COOKIENAME.$target_table.'chartvalues'] = 0;
}
}
if(!isset($_SESSION[COOKIENAME.'charttype']))
$_SESSION[COOKIENAME.'charttype'] = 'bar';
if(isset($_POST['chartsettings']))
{
$_SESSION[COOKIENAME.'charttype'] = $_POST['charttype'];
$_SESSION[COOKIENAME.$target_table.'chartlabels'] = $_POST['chartlabels'];
$_SESSION[COOKIENAME.$target_table.'chartvalues'] = $_POST['chartvalues'];
}
//- Chart javascript code
?>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart()
{
var data = new google.visualization.DataTable();
data.addColumn('string', '<?php echo $tableInfo[$_SESSION[COOKIENAME.$target_table.'chartlabels']]['name']; ?>');
data.addColumn('number', '<?php echo $tableInfo[$_SESSION[COOKIENAME.$target_table.'chartvalues']]['name']; ?>');
data.addRows([
<?php
for($i=0; $row = $db->fetch($table_result); $i++)
{
$label = str_replace("'", "", htmlencode($row[$_SESSION[COOKIENAME.$target_table.'chartlabels']]));
$value = htmlencode($row[$_SESSION[COOKIENAME.$target_table.'chartvalues']]);
if($value==NULL || $value=="")
$value = 0;
echo "['".$label."', ".$value."]";
if($i<$totalRows-1)
echo ",";
}
$height = ($totalRows+1) * 30;
if($height>1000)
$height = 1000;
else if($height<300)
$height = 300;
if($_SESSION[COOKIENAME.'charttype']=="pie")
$height = 800;
?>
]);
var chartWidth = document.getElementById("main_column").offsetWidth - document.getElementById("chartsettingsbox").offsetWidth - 100;
if(chartWidth>1000)
chartWidth = 1000;
var options =
{
'width':chartWidth,
'height':<?php echo $height; ?>,
'title':'<?php echo $tableInfo[$_SESSION[COOKIENAME.$target_table.'chartlabels']]['name']." vs ".$tableInfo[$_SESSION[COOKIENAME.$target_table.'chartvalues']]['name']; ?>'
};
<?php
if($_SESSION[COOKIENAME.'charttype']=="bar")
echo "var chart = new google.visualization.BarChart(document.getElementById('chart_div'));";
else if($_SESSION[COOKIENAME.'charttype']=="pie")
echo "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));";
else
echo "var chart = new google.visualization.LineChart(document.getElementById('chart_div'));";
?>
chart.draw(data, options);
}
</script>
<div id="chart_div" style="float:left;"><?php echo $lang['no_chart']; ?></div>
<?php
echo "<fieldset style='float:right; text-align:center;' id='chartsettingsbox'><legend><b>Chart Settings</b></legend>";
echo $params->getForm(array('action'=>$_GET['action']));
echo $lang['chart_type'].": <select name='charttype'>";
echo "<option value='bar'";
if($_SESSION[COOKIENAME.'charttype']=="bar")
echo " selected='selected'";
echo ">".$lang['chart_bar']."</option>";
echo "<option value='pie'";
if($_SESSION[COOKIENAME.'charttype']=="pie")
echo " selected='selected'";
echo ">".$lang['chart_pie']."</option>";
echo "<option value='line'";
if($_SESSION[COOKIENAME.'charttype']=="line")
echo " selected='selected'";
echo ">".$lang['chart_line']."</option>";
echo "</select>";
echo "<br/><br/>";
echo $lang['lbl'].": <select name='chartlabels'>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
if(isset($_SESSION[COOKIENAME.$target_table.'chartlabels']) && $_SESSION[COOKIENAME.$target_table.'chartlabels']==$i)
echo "<option value='".$i."' selected='selected'>".htmlencode($tableInfo[$i]['name'])."</option>";
else
echo "<option value='".$i."'>".htmlencode($tableInfo[$i]['name'])."</option>";
}
echo "</select>";
echo "<br/><br/>";
echo $lang['val'].": <select name='chartvalues'>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
if(isset($_SESSION[COOKIENAME.$target_table.'chartvalues']) && $_SESSION[COOKIENAME.$target_table.'chartvalues']==$i)
echo "<option value='".$i."' selected='selected'>".htmlencode($tableInfo[$i]['name'])."</option>";
else
echo "<option value='".$i."'>".htmlencode($tableInfo[$i]['name'])."</option>";
}
echo "</select>";
echo "<br/><br/>";
echo "<input type='submit' name='chartsettings' value='".$lang['update']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
echo "<div style='clear:both;'></div>";
//end chart view
}
}
else //no rows - do nothing
{
echo "<br/><div class='confirm'>";
if(isset($search) || $totalRows>0)
echo $lang['no_rows']."<br/><br/>";
elseif($target_table_type == 'table')
echo $lang['empty_tbl']." ".$params->getLink(array('action'=>'row_create'), $lang['click']) ." ".$lang['insert_rows'].'<br/><br/>';
echo "<span style='font-size:11px;'>".htmlencode($queryDisp)."</span>";
echo "</div><br/>";
}
if(isset($search))
echo "<br/><br/>".$params->getLink(array('action'=>'table_search','search'=>null,'oldSearch' => (isset($_GET['search'])?$_GET['search']:null)), $lang['srch_again']);
break;
//- Create new row (=row_create)
case "row_create":
echo $params->getForm(array('action'=>'row_create'), 'get');
echo $lang['restart_insert'];
echo " <select name='newRows'>";
for($i=1; $i<=40; $i++)
{
if(isset($_GET['newRows']) && $_GET['newRows']==$i)
echo "<option value='".$i."' selected='selected'>".$i."</option>";
else
echo "<option value='".$i."'>".$i."</option>";
}
echo "</select> ";
echo $lang['rows'];
echo " <input type='submit' value='".$lang['go']."' class='btn'/>";
echo "</form>";
echo "<br/>";
echo $params->getForm(array('action'=>'row_create','confirm'=>'1'), 'post', true);
$tableInfo = $db->getTableInfo($target_table);
if(isset($_GET['newRows']))
$num = $_GET['newRows'];
else
$num = 1;
echo "<input type='hidden' name='newRows' value='".$num."'/>";
for($j=0; $j<$num; $j++)
{
if($j>0)
echo "<label><input type='checkbox' value='ignore' name='".$j.":ignore' id='row_".$j."_ignore' checked='checked'/> ".$lang['ignore']."</label><br/>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td class='tdheader'>".$lang['fld']."</td>";
echo "<td class='tdheader'>".$lang['type']."</td>";
echo "<td class='tdheader'>".$lang['func']."</td>";
echo "<td class='tdheader'>Null</td>";
echo "<td class='tdheader'>".$lang['val']."</td>";
echo "</tr>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
$field = $tableInfo[$i]['name'];
$type = strtoupper($tableInfo[$i]['type']);
$typeAffinity = get_type_affinity($type);
if($tableInfo[$i]['dflt_value'] === "NULL")
$value = NULL;
elseif(preg_match('/^BLOB/', $type) && $hexblobs)
$value = htmlencode(bin2hex(trim(trim($tableInfo[$i]['dflt_value']), "'")));
else
$value = htmlencode(trim(trim($tableInfo[$i]['dflt_value']), "'"));
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
echo "<tr>";
echo $tdWithClassLeft;
echo htmlencode($field);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($type);
echo "</td>";
echo $tdWithClassLeft;
echo "<select name='function_".$i."[]' onchange='notNull(\"row_".$j."_field_".$i."_null\");'>";
echo "<option value=''>&nbsp;</option>";
foreach (array_merge($sqlite_functions, $custom_functions) as $f) {
echo "<option value='".htmlencode($f)."'>".htmlencode($f)."</option>";
}
echo "</select>";
echo "</td>";
echo $tdWithClassLeft;
if($tableInfo[$i]['notnull']==0)
{
if($value===NULL)
echo "<input type='checkbox' name='".$i."_null[]' id='row_".$j."_field_".$i."_null' checked='checked' onclick='disableText(this, \"row_".$j."_field_".$i."_value\");'/>";
else
echo "<input type='checkbox' name='".$i."_null[]' id='row_".$j."_field_".$i."_null' onclick='disableText(this, \"row_".$j."_field_".$i."_value\");'/>";
}
echo "</td>";
echo $tdWithClassLeft;
if($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC")
echo "<input type='text' id='row_".$j."_field_".$i."_value' name='".$j.":".$i."' value='".$value."' onblur='changeIgnore(this, \"row_".$j."_ignore\");' onclick='notNull(\"row_".$j."_field_".$i."_null\");'/>";
elseif(preg_match('/^BLOB/', $type) && !$hexblobs)
echo "<input type='file' id='row_".$j."_field_".$i."_value' name='".$j.":".$i."' onblur='changeIgnore(this, \"row_".$j."_ignore\");' onclick='notNull(\"row_".$j."_field_".$i."_null\");'/>";
else
echo "<textarea id='row_".$j."_field_".$i."_value' name='".$j.":".$i."' rows='5' cols='60' onclick='notNull(\"row_".$j."_field_".$i."_null\");' onblur='changeIgnore(this, \"row_".$j."_ignore\");'>".$value."</textarea>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='5'>";
echo "<input type='submit' value='".$lang['insert']."' class='btn'/>";
echo "</td>";
echo "</tr>";
echo "</table><br/>";
}
echo "</form>";
break;
//- Edit or delete row (=row_editordelete)
case "row_editordelete":
if(isset($_POST['check']))
$pks = $_POST['check'];
else if(isset($_GET['pk']))
$pks = array($_GET['pk']);
else $pks[0] = "";
$str = implode(', ', $pks);
if($str=="") //nothing was selected so show an error
{
echo "<div class='confirm'>";
echo $lang['err'].": ".$lang['no_sel'];
echo "</div>";
echo "<br/><br/>".$params->getLink(array('action'=>'row_view'),$lang['return']);
}
else
{
if((isset($_POST['type']) && $_POST['type']=="edit") || (isset($_GET['type']) && $_GET['type']=="edit")) //edit
{
echo $params->getForm(array('action'=>'row_edit', 'confirm'=>'1', 'pk'=>json_encode($pks)),'post',true);
$tableInfo = $db->getTableInfo($target_table);
$primary_key = $db->getPrimaryKey($target_table);
for($j=0; $j<sizeof($pks); $j++)
{
$query = "SELECT * FROM ".$db->quote_id($target_table)." WHERE " . $db->wherePK($target_table, json_decode($pks[$j]));
$result1 = $db->select($query, 'num');
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td class='tdheader'>".$lang['fld']."</td>";
echo "<td class='tdheader'>".$lang['type']."</td>";
echo "<td class='tdheader'>".$lang['func']."</td>";
echo "<td class='tdheader'>Null</td>";
echo "<td class='tdheader'>".$lang['val']."</td>";
echo "</tr>";
for($i=0; $i<sizeof($tableInfo); $i++)
{
$field = $tableInfo[$i]['name'];
$type = strtoupper($tableInfo[$i]['type']);
$typeAffinity = get_type_affinity($type);
$value = $result1[$i];
if(preg_match('/^BLOB/', $type) && $hexblobs)
$value = bin2hex($value);
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
echo "<tr>";
echo $tdWithClassLeft;
echo htmlencode($field);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($type);
echo "</td>";
echo $tdWithClassLeft;
echo "<select name='function_".$i."[]' onchange='notNull(\"row_".$j."_field_".$i."_null\");'>";
echo "<option value=''></option>";
foreach (array_merge($sqlite_functions, $custom_functions) as $f) {
echo "<option value='".htmlencode($f)."'>".htmlencode($f)."</option>";
}
echo "</select>";
echo "</td>";
echo $tdWithClassLeft;
if($tableInfo[$i]['notnull']==0)
{
if($value===NULL)
echo "<input type='checkbox' name='".$i."_null[]' id='row_".$j."_field_".$i."_null' checked='checked' onclick='disableText(this, \"row_".$j."_field_".$i."_value\");'/>";
else
echo "<input type='checkbox' name='".$i."_null[]' id='row_".$j."_field_".$i."_null' onclick='disableText(this, \"row_".$j."_field_".$i."_value\");'/>";
}
echo "</td>";
echo $tdWithClassLeft;
if($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC")
echo "<input type='text' id='row_".$j."_field_".$i."_value' name='".$i."[]' value='".htmlencode($value)."' onblur='changeIgnore(this, \"".$j."\", \"row_".$j."_field_".$i."_null\")' />";
elseif(preg_match('/^BLOB/', $type) && !$hexblobs)
{
if($value!==NULL)
{
echo "<input type='radio' name='row_".$j."_field_".$i."_blob_use' value='old' checked='checked'>";
echo $params->getLink(array('action'=>'row_get_blob', 'confirm'=>1, 'pk'=>$pks[$j], 'column'=>$field, 'download_blob'=>1),$lang["download"]).' | ';
echo $params->getLink(array('action'=>'row_get_blob', 'confirm'=>1, 'pk'=>$pks[$j], 'column'=>$field, 'download_blob'=>0),$lang["open_in_browser"],'','','_blank').'<br/>';
echo "<input type='radio' name='row_".$j."_field_".$i."_blob_use' value='new' id='row_".$j."_field_".$i."_blob_new'>";
}
echo "<input type='file' id='row_".$j."_field_".$i."_value' name='".$j.":".$i."'
onblur='changeIgnore(this, \"row_".$j."_ignore\");'
onchange='document.getElementById(\"row_".$j."_field_".$i."_blob_new\").checked=true;'
onclick='notNull(\"row_".$j."_field_".$i."_null\");'
".($value===NULL?" disabled='disabled'":"")."/>";
}
else
echo "<textarea id='row_".$j."_field_".$i."_value' name='".$i."[]' rows='1' cols='60' class='".htmlencode($field)."_textarea' onblur='changeIgnore(this, \"".$j."\", \"row_".$j."_field_".$i."_null\")'>".htmlencode($value)."</textarea>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='5'>";
// Note: the 'Save changes' button must be first in the code so it is the one used when submitting the form with the Enter key (issue #215)
echo "<input type='submit' value='".$lang['save_ch']."' class='btn'/> ";
echo "<input type='submit' name='new_row' value='".$lang['new_insert']."' class='btn'/> ";
echo $params->getLink(array('action'=>'row_view'), $lang['cancel']);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br/>";
}
echo "</form>";
}
else //delete
{
echo $params->getForm(array('action'=>'row_delete', 'confirm'=>'1', 'pk'=>json_encode($pks)));
echo "<div class='confirm'>";
printf($lang['ques_row_delete'], htmlencode($str), htmlencode($target_table));
echo "<br/><br/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
echo $params->getLink(array('action'=>'row_view'), $lang['cancel']);
echo "</div>";
}
}
break;
//- Column actions
//- View table structure (=column_view)
case "column_view":
$tableInfo = $db->getTableInfo($target_table);
echo $params->getForm(array('action'=>'column_confirm'), 'get', false, 'checkForm');
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
echo "<td colspan='3'></td>";
echo "<td class='tdheader'>".$lang['col']." #</td>";
echo "<td class='tdheader'>".$lang['fld']."</td>";
echo "<td class='tdheader'>".$lang['type']."</td>";
echo "<td class='tdheader'>".$lang['not_null']."</td>";
echo "<td class='tdheader'>".$lang['def_val']."</td>";
echo "<td class='tdheader'>".$lang['prim_key']."</td>";
echo "</tr>";
$noPrimaryKey = true;
for($i=0; $i<sizeof($tableInfo); $i++)
{
$colVal = $tableInfo[$i][0];
$fieldVal = $tableInfo[$i][1];
$typeVal = $tableInfo[$i]['type'];
$notnullVal = $tableInfo[$i][3];
$defaultVal = $tableInfo[$i][4];
$primarykeyVal = $tableInfo[$i][5];
if(intval($notnullVal)!=0)
$notnullVal = $lang['yes'];
else
$notnullVal = $lang['no'];
if(intval($primarykeyVal)!=0)
{
$primarykeyVal = $lang['yes'];
$noPrimaryKey = false;
}
else
$primarykeyVal = $lang['no'];
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
echo "<tr>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo $tdWithClass;
echo "<input type='checkbox' name='check[]' value='".htmlencode($fieldVal)."' id='check_".$i."'/>";
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('action'=>'column_edit', 'pk'=>$fieldVal),"<span>".$lang['edit']."</span>",'edit', $lang['edit']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('action'=>'column_confirm', 'action2'=>'column_delete', 'pk'=>$fieldVal),"<span>".$lang['del']."</span>",'delete', $lang['del']);
echo "</td>";
}
echo $tdWithClass;
echo htmlencode($colVal);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($fieldVal);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($typeVal);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($notnullVal);
echo "</td>";
echo $tdWithClassLeft;
if($defaultVal===NULL)
echo "<i class='null'>".$lang['none']."</i>";
elseif($defaultVal==="NULL")
echo "<i class='null'>NULL</i>";
else
echo htmlencode($defaultVal);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($primarykeyVal);
echo "</td>";
echo "</tr>";
}
echo "</table>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo "<a onclick='checkAll()'>".$lang['chk_all']."</a> / <a onclick='uncheckAll()'>".$lang['unchk_all']."</a> <i>".$lang['with_sel'].":</i> ";
echo "<select name='action2'>";
//echo "<option value='edit'>".$lang['edit']."</option>";
echo "<option value='column_delete'>".$lang['del']."</option>";
if($noPrimaryKey)
echo "<option value='primarykey_add'>".$lang['prim_key']."</option>";
echo "</select> ";
echo "<input type='submit' value='".$lang['go']."' name='massGo' class='btn'/>";
}
echo "</form>";
if($target_table_type == 'table' && $db->isWritable() && $db->isDirWritable())
{
echo "<br/>";
echo $params->getForm(array('action'=>'column_create'), 'get');
echo $lang['add']." <input type='text' name='tablefields' style='width:30px;' value='1'/> ".$lang['tbl_end']." <input type='submit' value='".$lang['go']."' name='addfields' class='btn'/>";
echo "</form>";
}
echo "<br/>";
echo "<br/>";
echo "<div class='confirm'>";
echo "<b>".$lang['query_used_'.$target_table_type]."</b><br/>";
echo "<span style='font-size:11px;'>";
echo nl2br(htmlencode($db->export_sql(array($target_table),false,true,false,false,false,false)));
echo "</span>";
echo "</div>";
echo "<br/>";
if($target_table_type != 'view')
{
echo "<br/><hr/><br/>";
$query = "PRAGMA index_list(".$db->quote_id($target_table).")";
$result = $db->selectArray($query);
if(sizeof($result)>0)
{
echo "<h2>".$lang['indexes'].":</h2>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td colspan='1'>";
echo "</td>";
echo "<td class='tdheader'>".$lang['name']."</td>";
echo "<td class='tdheader'>".$lang['unique']."</td>";
echo "<td class='tdheader'>".$lang['seq_no']."</td>";
echo "<td class='tdheader'>".$lang['col']." #</td>";
echo "<td class='tdheader'>".$lang['fld']."</td>";
echo "</tr>";
for($i=0; $i<sizeof($result); $i++)
{
if($result[$i]['unique']==0)
$unique = $lang['no'];
else
$unique = $lang['yes'];
$query = "PRAGMA index_info(".$db->quote_id($result[$i]['name']).")";
$info = $db->selectArray($query);
$span = sizeof($info);
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
$tdWithClassSpan = "<td class='td".($i%2 ? "1" : "2")."' rowspan='".$span."'>";
$tdWithClassLeftSpan = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;' rowspan='".$span."'>";
echo "<tr>";
echo $tdWithClassSpan;
echo $params->getLink(array('action'=>'index_delete', 'pk'=>$result[$i]['name']), "<span>".$lang['del']."</span>", 'delete', $lang['del']);
echo "</td>";
echo $tdWithClassLeftSpan;
echo $result[$i]['name'];
echo "</td>";
echo $tdWithClassLeftSpan;
echo $unique;
echo "</td>";
for($j=0; $j<$span; $j++)
{
if($j!=0)
echo "<tr>";
echo $tdWithClassLeft;
echo htmlencode($info[$j]['seqno']);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($info[$j]['cid']);
echo "</td>";
echo $tdWithClassLeft;
echo htmlencode($info[$j]['name']);
echo "</td>";
echo "</tr>";
}
}
echo "</table><br/><br/>";
}
$query = "SELECT * FROM sqlite_master WHERE type='trigger' AND tbl_name=".$db->quote($target_table)." ORDER BY name";
$result = $db->selectArray($query);
//print_r($result);
if(sizeof($result)>0)
{
echo "<h2>".$lang['triggers'].":</h2>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td colspan='1'>";
echo "</td>";
echo "<td class='tdheader'>".$lang['name']."</td>";
echo "<td class='tdheader'>".$lang['sql']."</td>";
echo "</tr>";
for($i=0; $i<sizeof($result); $i++)
{
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
echo "<tr>";
echo $tdWithClass;
echo $params->getLink(array('action'=>'trigger_delete', 'pk'=>$result[$i]['name']), "<span>".$lang['del']."</span>", 'delete', $lang['del']);
echo "</td>";
echo $tdWithClass;
echo htmlencode($result[$i]['name']);
echo "</td>";
echo $tdWithClass;
echo htmlencode($result[$i]['sql']);
echo "</td>";
}
echo "</table><br/><br/>";
}
if($db->isWritable() && $db->isDirWritable())
{
echo $params->getForm(array('action'=>'index_create'),'get');
echo "<br/><div class='tdheader'>";
echo $lang['create_index2']." <input type='text' name='numcolumns' style='width:30px;' value='1'/> ".$lang['cols']." <input type='submit' value='".$lang['go']."' name='addindex' class='btn'/>";
echo "</div>";
echo "</form>";
echo $params->getForm(array('action'=>'trigger_create'),'get');
echo "<br/><div class='tdheader'>";
echo $lang['create_trigger2']." <input type='submit' value='".$lang['go']."' name='addindex' class='btn'/>";
echo "</div>";
echo "</form>";
}
}
break;
//- Create column (=column_create)
case "column_create":
echo "<h2>".sprintf($lang['new_fld'],htmlencode($_GET['table']))."</h2>";
if($_GET['tablefields']=="" || intval($_GET['tablefields'])<=0)
echo $lang['specify_fields'];
else if($_GET['table']=="")
echo $lang['specify_tbl'];
else
{
$num = intval($_GET['tablefields']);
$name = $_GET['table'];
echo $params->getForm(array('action'=>'column_create', 'confirm'=>'1'));
echo "<input type='hidden' name='rows' value='".$num."'/>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
$headings = array($lang["fld"], $lang["type"], $lang["prim_key"]);
if($db->getType() != "SQLiteDatabase") $headings[] = $lang["autoincrement"];
$headings[] = $lang["not_null"];
$headings[] = $lang["def_val"];
for($k=0; $k<count($headings); $k++)
echo "<td class='tdheader'>" . $headings[$k] . "</td>";
echo "</tr>";
for($i=0; $i<$num; $i++)
{
$tdWithClass = "<td class='td" . ($i%2 ? "1" : "2") . "'>";
echo "<tr>";
echo $tdWithClass;
echo "<input type='text' name='".$i."_field' style='width:200px;'/>";
echo "</td>";
echo $tdWithClass;
echo "<select name='".$i."_type' id='i".$i."_type' onchange='toggleAutoincrement(".$i.");'>";
foreach ($sqlite_datatypes as $t) {
echo "<option value='".htmlencode($t)."'>".htmlencode($t)."</option>";
}
echo "</select>";
echo "</td>";
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_primarykey'/> ".$lang['yes']."</label>";
echo "</td>";
if($db->getType() != "SQLiteDatabase")
{
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_autoincrement' id='i".$i."_autoincrement'/> ".$lang['yes']."</label>";
echo "</td>";
}
echo $tdWithClass;
echo "<label><input type='checkbox' name='".$i."_notnull'/> ".$lang['yes']."</label>";
echo "</td>";
echo $tdWithClass;
echo "<select name='".$i."_defaultoption' id='i".$i."_defaultoption' onchange=\"if(this.value!='defined' && this.value!='expr') document.getElementById('i".$i."_defaultvalue').value='';\">";
echo "<option value='none'>".$lang['none']."</option><option value='defined'>".$lang['as_defined'].":</option><option>NULL</option><option>CURRENT_TIME</option><option>CURRENT_DATE</option><option>CURRENT_TIMESTAMP</option><option value='expr'>".$lang['expression'].":</option>";
echo "</select>";
echo "<input type='text' name='".$i."_defaultvalue' id='i".$i."_defaultvalue' style='width:100px;' onchange=\"if(document.getElementById('i".$i."_defaultoption').value!='expr') document.getElementById('i".$i."_defaultoption').value='defined';\"/>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='6'>";
echo "<input type='submit' value='".$lang['add_flds']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
break;
//- Confirm column action (=column_confirm)
case "column_confirm":
if(isset($_GET['check']))
$pks = $_GET['check'];
elseif(isset($_GET['pk']))
$pks = array($_GET['pk']);
else $pks = array();
if(sizeof($pks)==0) //nothing was selected so show an error
{
echo "<div class='confirm'>";
echo $lang['err'].": ".$lang['no_sel'];
echo "</div>";
echo "<br/><br/>";
echo $params->getLink(array('action'=>'column_view'), $lang['return']);
}
else
{
$str = $pks[0];
$pkVal = $pks[0];
for($i=1; $i<sizeof($pks); $i++)
{
$str .= ", ".$pks[$i];
$pkVal .= ":".$pks[$i];
}
echo $params->getForm(array('action'=>$_GET['action2'], 'confirm'=>'1', 'pk'=>$pkVal));
echo "<div class='confirm'>";
printf($lang['ques_'.$_GET['action2']], htmlencode($str), htmlencode($target_table));
echo "<br/><br/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</div>";
}
break;
//- Edit column (=column_edit)
case "column_edit":
echo "<h2>".sprintf($lang['edit_col'], htmlencode($_GET['pk']))." ".$lang['on_tbl']." '".htmlencode($target_table)."'</h2>";
echo $lang['sqlite_limit']."<br/><br/>";
if(!isset($_GET['pk']))
echo $lang['specify_col'];
else if (!$target_table)
echo $lang['specify_tbl'];
else
{
$tableInfo = $db->getTableInfo($target_table);
for($i=0; $i<sizeof($tableInfo); $i++)
{
if($tableInfo[$i][1]==$_GET['pk'])
{
$colVal = $tableInfo[$i][0];
$fieldVal = $tableInfo[$i][1];
$typeVal = $tableInfo[$i]['type'];
$notnullVal = $tableInfo[$i][3];
$defaultVal = $tableInfo[$i][4];
$primarykeyVal = $tableInfo[$i][5];
break;
}
}
if(!isset($fieldVal))
{
echo "<div class='confirm'>".$lang['err'].": ".sprintf($lang['col_inexistent'], htmlencode($_GET['pk']))."</div>";
}
else
{
$name = $target_table;
echo $params->getForm(array('action'=>'column_edit', 'confirm'=>'1'));
echo "<input type='hidden' name='oldvalue' value='".htmlencode($_GET['pk'])."'/>";
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
//$headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value");
$headings = array($lang["fld"], $lang["type"]);
for($k=0; $k<count($headings); $k++)
echo "<td class='tdheader'>".$headings[$k]."</td>";
echo "</tr>";
$i = 0;
$tdWithClass = "<td class='td" . ($i%2 ? "1" : "2") . "'>";
echo "<tr>";
echo $tdWithClass;
echo "<input type='text' name='".$i."_field' style='width:200px;' value='".htmlencode($fieldVal)."'/>";
echo "</td>";
echo $tdWithClass;
echo "<select name='".$i."_type' id='i".$i."_type' onchange='toggleAutoincrement(".$i.");'>";
if(!in_array($typeVal, $sqlite_datatypes))
echo "<option value='".htmlencode($typeVal)."' selected='selected'>".htmlencode($typeVal)."</option>";
foreach ($sqlite_datatypes as $t) {
if($t==$typeVal)
echo "<option value='".htmlencode($t)."' selected='selected'>".htmlencode($t)."</option>";
else
echo "<option value='".htmlencode($t)."'>".htmlencode($t)."</option>";
}
echo "</select>";
echo "</td>";
/*
echo $tdWithClass;
if($primarykeyVal)
echo "<input type='checkbox' name='".$i."_primarykey' checked='checked'/> Yes";
else
echo "<input type='checkbox' name='".$i."_primarykey'/> Yes";
echo "</td>";
echo $tdWithClass;
if(1==2)
echo "<input type='checkbox' name='".$i."_autoincrement' id='".$i."_autoincrement' checked='checked'/> Yes";
else
echo "<input type='checkbox' name='".$i."_autoincrement' id='".$i."_autoincrement'/> Yes";
echo "</td>";
echo $tdWithClass;
if($notnullVal)
echo "<input type='checkbox' name='".$i."_notnull' checked='checked'/> Yes";
else
echo "<input type='checkbox' name='".$i."_notnull'/> Yes";
echo "</td>";
echo $tdWithClass;
echo "<input type='text' name='".$i."_defaultvalue' value='".$defaultVal."' style='width:100px;'/>";
echo "</td>";
*/
echo "</tr>";
echo "<tr>";
echo "<td class='tdheader' style='text-align:right;' colspan='6'>";
echo "<input type='submit' value='".$lang['save_ch']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
}
break;
//- Delete index (=index_delete)
case "index_delete":
echo $params->getForm(array('action'=>'index_delete', 'pk'=>$_GET['pk'], 'confirm'=>'1'));
echo "<div class='confirm'>";
echo sprintf($lang['ques_index_delete'], htmlencode($_GET['pk']))."<br/><br/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</div>";
echo "</form>";
break;
//- Delete trigger (=trigger_delete)
case "trigger_delete":
echo $params->getForm(array('action'=>'trigger_delete', 'pk'=>$_GET['pk'], 'confirm'=>'1'));
echo "<div class='confirm'>";
echo sprintf($lang['ques_trigger_delete'], htmlencode($_GET['pk']))."<br/><br/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</div>";
echo "</form>";
break;
//- Create trigger (=trigger_create)
case "trigger_create":
echo "<h2>".$lang['create_trigger']." '".htmlencode($_GET['table'])."'</h2>";
if($_GET['table']=="")
echo $lang['specify_tbl'];
else
{
echo $params->getForm(array('action'=>'trigger_create', 'confirm'=>'1'));
echo $lang['trigger_name'].": <input type='text' name='trigger_name'/><br/><br/>";
echo "<fieldset><legend>".$lang['db_event']."</legend>";
echo $lang['before']."/".$lang['after'].": ";
echo "<select name='beforeafter'>";
echo "<option value=''></option>";
echo "<option value='BEFORE'>".$lang['before']."</option>";
echo "<option value='AFTER'>".$lang['after']."</option>";
echo "<option value='INSTEAD OF'>".$lang['instead']."</option>";
echo "</select>";
echo "<br/><br/>";
echo $lang['event'].": ";
echo "<select name='event'>";
echo "<option value='DELETE'>".$lang['del']."</option>";
echo "<option value='INSERT'>".$lang['insert']."</option>";
echo "<option value='UPDATE'>".$lang['update']."</option>";
echo "</select>";
echo "</fieldset><br/><br/>";
echo "<fieldset><legend>".$lang['trigger_act']."</legend>";
echo "<label><input type='checkbox' name='foreachrow'/> ".$lang['each_row']."</label><br/><br/>";
echo $lang['when_exp'].":<br/>";
echo "<textarea name='whenexpression' style='width:500px; height:100px;' rows='8' cols='50'></textarea>";
echo "<br/><br/>";
echo $lang['trigger_step'].":<br/>";
echo "<textarea name='triggersteps' style='width:500px; height:100px;' rows='8' cols='50'></textarea>";
echo "</fieldset><br/><br/>";
echo "<input type='submit' value='".$lang['create_trigger2']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</form>";
}
break;
//- Create index (=index_create)
case "index_create":
echo "<h2>".$lang['create_index']." '".htmlencode($_GET['table'])."'</h2>";
if($_GET['numcolumns']=="" || intval($_GET['numcolumns'])<=0)
echo $lang['specify_fields'];
else if($_GET['table']=="")
echo $lang['specify_tbl'];
else
{
echo $params->getForm(array('action'=>'index_create', 'confirm'=>'1'));
$num = intval($_GET['numcolumns']);
$tableInfo = $db->getTableInfo($_GET['table']);
echo "<fieldset><legend>".$lang['define_index']."</legend>";
echo "<label for='index_name'>".$lang['index_name'].":</label> <input type='text' name='name' id='index_name'/><br/>";
echo "<label for='index_duplicate'>".$lang['dup_val'].":</label>";
echo "<select name='duplicate' id='index_duplicate'>";
echo "<option value='yes'>".$lang['allow']."</option>";
echo "<option value='no'>".$lang['not_allow']."</option>";
echo "</select><br/>";
if(version_compare($db->getSQLiteVersion(),'3.8.0')>=0)
echo "<label for='index_where'>WHERE:</label> <input type='text' name='where' id='index_where'/> ".helpLink($lang['help10']);
echo "</fieldset>";
echo "<br/>";
echo "<fieldset><legend>".$lang['define_in_col']."</legend>";
for($i=0; $i<$num; $i++)
{
echo "<select name='".$i."_field'>";
echo "<option value=''>--".$lang['ignore']."--</option>";
for($j=0; $j<sizeof($tableInfo); $j++)
echo "<option value='".htmlencode($tableInfo[$j][1])."'>".htmlencode($tableInfo[$j][1])."</option>";
echo "</select> ";
echo "<select name='".$i."_order'>";
echo "<option value=''></option>";
echo "<option value=' ASC'>".$lang['asc']."</option>";
echo "<option value=' DESC'>".$lang['desc']."</option>";
echo "</select><br/>";
}
echo "</fieldset>";
echo "<br/><br/>";
echo "<input type='hidden' name='num' value='".$num."'/>";
echo "<input type='submit' value='".$lang['create_index1']."' class='btn'/> ";
echo $params->getLink(array('action'=>'column_view'), $lang['cancel']);
echo "</form>";
}
break;
}
echo "</div>";
}
//- HMTL: views for databases
if(!$target_table && !isset($_GET['confirm']) && (!isset($_GET['action']) || (isset($_GET['action']) && $_GET['action']!="table_create" && $_GET['action']!="table_confirm"))) //the absence of these fields means we are viewing the database homepage
{
//- Switch on $view (actually a series of if-else)
if($view=="structure")
{
//- Database structure, shows all the tables (=structure)
if($db->isWritable() && !$db->isDirWritable())
{
echo "<div class='confirm' style='margin:10px 0'>";
echo $lang['attention'].': '.$lang['directory_not_writable'];
echo "</div><br/>";
}
elseif(!$db->isWritable())
{
echo "<div class='confirm' style='margin:10px 0;'>";
echo $lang['attention'].': '.$lang['database_not_writable'];
echo "</div><br/>";
}
if ($auth->isPasswordDefault())
{
echo "<div class='confirm' style='margin:20px 0px;'>";
echo sprintf($lang['warn_passwd'],(is_readable('phpliteadmin.config.php')?'phpliteadmin.config.php':basename(__FILE__)))."<br />".$lang['warn0'];
echo "</div>";
}
if (!extension_loaded('mbstring'))
{
echo "<div class='confirm' style='margin:20px 0px;'>";
echo $lang['warn_mbstring'];
echo "</div>";
}
echo "<b>".$lang['db_name']."</b>: ".htmlencode($db->getName())."<br/>";
echo "<b>".$lang['db_path']."</b>: ".htmlencode($db->getPath())."<br/>";
echo "<b>".$lang['db_size']."</b>: ".number_format($db->getSize())." KiB<br/>";
echo "<b>".$lang['db_mod']."</b>: ".$db->getDate()."<br/>";
echo "<b>".$lang['sqlite_v']."</b>: ".$db->getSQLiteVersion()."<br/>";
echo "<b>".$lang['sqlite_ext']."</b> ".helpLink($lang['help1']).": ".$db->getType()."<br/>";
echo "<b>".$lang['php_v']."</b>: ".phpversion()."<br/>";
echo "<b>".PROJECT." ".$lang["ver"]."</b>: ".VERSION;
echo " <a href='".PROJECT_URL."' target='_blank' id='oldVersion' style='display: none;' class='warning'>".$lang['new_version']."</a><br/><br/>";
echo "<script type='text/javascript'>checkVersion('".VERSION."','".VERSION_CHECK_URL."');</script>";
if(isset($_GET['sort']) && ($_GET['sort']=='type' || $_GET['sort']=='name'))
$_SESSION[COOKIENAME.'sortTables'] = $_GET['sort'];
if(isset($_GET['order']) && ($_GET['order']=='ASC' || $_GET['order']=='DESC'))
$_SESSION[COOKIENAME.'orderTables'] = $_GET['order'];
if(!isset($_SESSION[COOKIENAME.'sortTables']))
$_SESSION[COOKIENAME.'sortTables'] = 'name';
if(!isset($_SESSION[COOKIENAME.'orderTables']))
$_SESSION[COOKIENAME.'orderTables'] = 'ASC';
$tables = $db->getTables(true, false, $_SESSION[COOKIENAME.'sortTables'], $_SESSION[COOKIENAME.'orderTables']);
if(sizeof($tables)==0)
echo $lang['no_tbl']."<br/><br/>";
else
{
echo $params->getForm(array('action'=>'table_confirm',), 'get', false, 'checkForm');
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
echo "<td class='tdheader' colspan='2'>";
if(isset($_SESSION[COOKIENAME.'sortTables']))
$orderTag = ($_SESSION[COOKIENAME.'sortTables']=="name" && $_SESSION[COOKIENAME.'orderTables']=="ASC") ? "DESC" : "ASC";
else
$orderTag = "ASC";
echo $params->getLink(array('sort'=>'name', 'order'=>$orderTag), $lang['name']);
if(isset($_SESSION[COOKIENAME.'sortTables']) && $_SESSION[COOKIENAME.'sortTables']=="name")
echo (($_SESSION[COOKIENAME.'orderTables']=="ASC") ? " <b>&uarr;</b>" : " <b>&darr;</b>");
echo "</td>";
echo "<td class='tdheader'>";
if(isset($_SESSION[COOKIENAME.'sortTables']))
$orderTag = ($_SESSION[COOKIENAME.'sortTables']=="type" && $_SESSION[COOKIENAME.'orderTables']=="ASC") ? "DESC" : "ASC";
else
$orderTag = "ASC";
echo $params->getLink(array('sort'=>'type', 'order'=>$orderTag), $lang['type']);
echo helpLink($lang['help3']);
if(isset($_SESSION[COOKIENAME.'sortTables']) && $_SESSION[COOKIENAME.'sortTables']=="type")
echo (($_SESSION[COOKIENAME.'orderTables']=="ASC") ? " <b>&uarr;</b>" : " <b>&darr;</b>");
echo "</td>";
echo "<td class='tdheader' colspan='10'>".$lang['act']."</td>";
echo "<td class='tdheader'>".$lang['rec']."</td>";
echo "</tr>";
$totalRecords = 0;
$skippedTables = false;
$tableId = 0;
foreach($tables as $tableName => $tableType)
{
$records = $db->numRows($tableName, (!isset($_GET['forceCount'])));
if($records == '?')
{
$skippedTables = true;
$records = $params->getLink(array('forceCount'=>'1'), '?');
}
else
$totalRecords += $records;
$tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
$tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
echo "<tr>";
echo $tdWithClass;
echo "<input type='checkbox' name='check[]' value='".htmlencode($tableName)."' id='check_".htmlencode($tableId)."'/>";
echo "</td>";
echo $tdWithClassLeft;
echo $params->getLink(array('table'=>$tableName, 'action'=>'row_view'), htmlencode($tableName));
echo "</td>";
echo $tdWithClassLeft;
echo ($tableType=="table"? $lang['tbl'] : $lang['view']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('table'=>$tableName, 'action'=>'row_view'), $lang['browse']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('table'=>$tableName, 'action'=>'column_view'), $lang['struct']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_sql'), $lang['sql']);
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_search'), $lang['srch']);
echo "</td>";
echo $tdWithClass;
if($tableType=="table" && $db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('table'=>$tableName, 'action'=>'row_create'), $lang['insert']);
else
echo $lang['insert'];
echo "</td>";
echo $tdWithClass;
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_export'), $lang['export']);
echo "</td>";
echo $tdWithClass;
if($tableType=="table" && $db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_import'), $lang['import']);
else
echo $lang['import'];
echo "</td>";
echo $tdWithClass;
if($db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_rename'), $lang['rename']);
else
echo $lang['rename'];
echo "</td>";
echo $tdWithClass;
if($tableType=="table" && $db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('table'=>$tableName, 'action'=>'table_confirm', 'action2'=>'table_empty'), $lang['empty'], 'empty');
else
echo $lang['empty'];
echo "</td>";
echo $tdWithClass;
if($db->isWritable() && $db->isDirWritable())
echo $params->getLink(array('table'=>$tableName,'action'=>'table_confirm', 'action2'=>'table_drop'), $lang['drop'], 'drop');
else
echo $lang['drop'];
echo "</td>";
echo $tdWithClass;
echo $records;
echo "</td>";
echo "</tr>";
$tableId++;
}
echo "<tr>";
echo "<td class='tdheader' colspan='13'>".sizeof($tables)." ".$lang['total']."</td>";
echo "<td class='tdheader' colspan='1' style='text-align:right;'>".$totalRecords.($skippedTables?" ".$params->getLink(array('forceCount'=>'1'),'+ ?'):"")."</td>";
echo "</tr>";
echo "</table>";
echo "<a onclick='checkAll()'>".$lang['chk_all']."</a> / <a onclick='uncheckAll()'>".$lang['unchk_all']."</a> <i>".$lang['with_sel'].":</i> ";
echo "<select name='action2'>";
if($db->isWritable() && $db->isDirWritable()) {
echo "<option value='table_drop'>".$lang['drop']."</option>";
echo "<option value='table_empty'>".$lang['empty']."</option>";
}
// echo "<option value='table_export'>".$lang['export']."</option>";
echo "</select> ";
echo "<input type='submit' value='".$lang['go']."' name='massGo' class='btn'/>";
echo "</form>";
echo "<br/>";
if($skippedTables)
echo "<div class='confirm' style='margin-bottom:20px;'>".sprintf($lang["counting_skipped"],"<a href='".$params->getURL(array('forceCount'=>'1'))."'>","</a>")."</div>";
}
if($db->isWritable() && $db->isDirWritable())
{
echo "<fieldset style='margin-top:2em'>";
echo "<legend><b>".$lang['create_tbl_db']." '".htmlencode($db->getName())."'</b></legend>";
echo $params->getForm(array('action'=>'table_create'), 'get');
echo $lang['name'].": <input type='text' name='tablename' style='width:200px;'/> ";
echo $lang['fld_num'].": <input type='text' name='tablefields' style='width:90px;'/> ";
echo "<input type='submit' name='createtable' value='".$lang['go']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
echo "<br/>";
echo "<fieldset>";
echo "<legend><b>".$lang['create_view']." '".htmlencode($db->getName())."'</b></legend>";
echo $params->getForm(array('action'=>'view_create', 'confirm'=>'1'));
echo $lang['name'].": <input type='text' name='viewname' style='width:200px;'/> ";
echo $lang['sel_state']." ".helpLink($lang['help4']).": <input type='text' name='select' style='width:400px;'/> ";
echo "<input type='submit' name='createtable' value='".$lang['go']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
}
}
else if($view=="sql")
{
//- Database SQL editor (=sql)
if(isset($_POST['query']) && $_POST['query']!="")
{
$delimiter = $_POST['delimiter'];
$queryStr = $_POST['queryval'];
//save the queries in history if necessary
if($maxSavedQueries!=0 && $maxSavedQueries!=false)
{
if(!isset($_SESSION[COOKIENAME.'query_history']))
$_SESSION[COOKIENAME.'query_history'] = array();
$_SESSION[COOKIENAME.'query_history'][md5(strtolower($queryStr))] = $queryStr;
if(sizeof($_SESSION[COOKIENAME.'query_history']) > $maxSavedQueries)
array_shift($_SESSION[COOKIENAME.'query_history']);
}
$query = explode_sql($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter
for($i=0; $i<sizeof($query); $i++) //iterate through the queries exploded by the delimiter
{
if(str_replace(" ", "", str_replace("\n", "", str_replace("\r", "", $query[$i])))!="") //make sure this query is not an empty string
{
$queryTimer = new MicroTimer();
$table_result = $db->query($query[$i]);
echo "<div class='confirm'>";
echo "<b>".htmlencode($query[$i])."</b>";
if($table_result === NULL || $table_result === false)
{
echo "<br /><b>".$lang['err'].": ".htmlencode($db->getError())."</b></div>";
}
echo "</div><br/>";
if($row = $db->fetch($table_result, 'num'))
{
for($j=0; $j<sizeof($row);$j++)
$headers[$j] = $db->getColumnName($table_result,$j);
echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
echo "<tr>";
for($j=0; $j<sizeof($headers); $j++)
{
echo "<td class='tdheader'>";
echo htmlencode($headers[$j]);
echo "</td>";
}
echo "</tr>";
$rowCount = 0;
for(; $rowCount==0 || $row = $db->fetch($table_result, 'num'); $rowCount++)
{
$tdWithClass = "<td class='td".($rowCount%2 ? "1" : "2")."'>";
echo "<tr>";
for($z=0; $z<sizeof($headers); $z++)
{
echo $tdWithClass;
if($row[$z]==="")
echo "&nbsp;";
elseif($row[$z]===NULL)
echo "<i class='null'>NULL</i>";
else
echo htmlencode(subString($row[$z]));
echo "</td>";
}
echo "</tr>";
}
$queryTimer->stop();
echo "</table><br/><br/>";
if($table_result !== NULL && $table_result !== false)
{
echo "<div class='confirm' style='margin-bottom: 2em'>";
if($rowCount>0 || $db->getAffectedRows()==0)
{
printf($lang['show_rows'], $rowCount);
}
if($db->getAffectedRows()>0 || $rowCount==0)
{
echo $db->getAffectedRows()." ".$lang['rows_aff']." ";
}
printf($lang['query_time'], $queryTimer);
echo "</div>";
}
}
}
}
}
else
{
$delimiter = ";";
$queryStr = "";
}
echo "<fieldset>";
echo "<legend><b>".sprintf($lang['run_sql'],htmlencode($db->getName()))."</b></legend>";
echo $params->getForm(array('view'=>'sql'));
if(isset($_SESSION[COOKIENAME.'query_history']) && sizeof($_SESSION[COOKIENAME.'query_history'])>0)
{
echo "<b>".$lang['recent_queries']."</b><ul>";
foreach($_SESSION[COOKIENAME.'query_history'] as $key => $value)
{
echo "<li><a onclick='sqleditorSetValue(this.textContent); return false;' href='#'>".htmlencode($value)."</a></li>";
}
echo "</ul><br/><br/>";
}
echo "<textarea style='width:100%; height:300px;' name='queryval' id='queryval' cols='50' rows='8'>".htmlencode($queryStr)."</textarea>";
echo "<script>sqleditor(document.getElementById('queryval'),".json_encode($db->getTableDefinitions()).", null);</script>";
echo $lang['delimit']." <input type='text' name='delimiter' value='".htmlencode($delimiter)."' style='width:50px;'/> ";
echo "<input type='submit' name='query' value='".$lang['go']."' class='btn'/>";
echo "</form>";
echo "</fieldset>";
}
else if($view=="vacuum")
{
//- Vacuum database confirmation (=vacuum)
if(isset($_POST['vacuum']))
{
$query = "VACUUM";
$db->query($query);
echo "<div class='confirm'>";
printf($lang['db_vac'], htmlencode($db->getName()));
echo "</div><br/>";
}
echo $params->getForm(array('view'=>'vacuum'));
printf($lang['vac_desc'],htmlencode($db->getName()));
echo "<br/><br/>";
echo "<input type='submit' value='".$lang['vac']."' name='vacuum' class='btn'/>";
echo "</form>";
}
else if($view=="export")
{
//- Export view (=export)
echo $params->getForm(array('view'=>'export'));
echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>".$lang['export']."</b></legend>";
echo "<select multiple='multiple' size='10' style='width:240px;' name='tables[]'>";
$tables = $db->getTables(true, false);
foreach($tables as $tableName => $tableType)
{
echo "<option value='".htmlencode($tableName)."' selected='selected'>".htmlencode($tableName)."</option>";
}
echo "</select>";
echo "<br/><br/>";
echo "<label><input type='radio' name='export_type' checked='checked' value='sql' onclick='toggleExports(\"sql\");'/> ".$lang['sql']."</label>";
echo "<br/><label><input type='radio' name='export_type' value='csv' onclick='toggleExports(\"csv\");'/> ".$lang['csv']."</label>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px;' id='exportoptions_sql'><legend><b>".$lang['options']."</b></legend>";
echo "<label><input type='checkbox' checked='checked' name='structure'/> ".$lang['export_struct']."</label> ".helpLink($lang['help5'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='data'/> ".$lang['export_data']."</label> ".helpLink($lang['help6'])."<br/>";
echo "<label><input type='checkbox' name='drop'/> ".$lang['add_drop']."</label> ".helpLink($lang['help7'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='transaction'/> ".$lang['add_transact']."</label> ".helpLink($lang['help8'])."<br/>";
echo "<label><input type='checkbox' checked='checked' name='comments'/> ".$lang['comments']."</label> ".helpLink($lang['help9'])."<br/>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px; display:none;' id='exportoptions_csv'><legend><b>".$lang['options']."</b></legend>";
echo "<div style='float:left;'>".$lang['fld_terminated']."</div>";
echo "<input type='text' value=';' name='export_csv_fieldsterminated' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_enclosed']."</div>";
echo "<input type='text' value='\"' name='export_csv_fieldsenclosed' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_escaped']."</div>";
echo "<input type='text' value='\' name='export_csv_fieldsescaped' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['rep_null']."</div>";
echo "<input type='text' value='NULL' name='export_csv_replacenull' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<label><input type='checkbox' name='export_csv_crlf'/> ".$lang['rem_crlf']."</label><br/>";
echo "<label><input type='checkbox' checked='checked' name='export_csv_fieldnames'/> ".$lang['put_fld']."</label>";
echo "</fieldset>";
echo "<div style='clear:both;'></div>";
echo "<br/><br/>";
echo "<fieldset><legend><b>".$lang['save_as']."</b></legend>";
$file = pathinfo($db->getPath());
$name = $file['filename'];
echo "<input type='text' name='filename' value='".htmlencode($name)."_".date("Y-m-d").".dump' style='width:400px;'/> <input type='submit' name='export' value='".$lang['export']."' class='btn'/>";
echo "</fieldset>";
echo "</form>";
echo "<div class='confirm' style='margin-top: 2em'>".sprintf($lang['backup_hint'],
$params->getLink(array('download'=>$currentDB['path'], 'token'=>$_SESSION[COOKIENAME.'token']), $lang["backup_hint_linktext"], '', $lang['backup'])
)."</div>";
}
else if($view=="import")
{
//- Import view (=import)
if(isset($_POST['import']))
{
echo "<div class='confirm'>";
if($importSuccess===true)
echo $lang['import_suc'];
else
echo $importSuccess;
echo "</div><br/>";
}
echo $params->getForm(array('view'=>'import'), 'post', true);
echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>".$lang['import']."</b></legend>";
echo "<label><input type='radio' name='import_type' checked='checked' value='sql' onclick='toggleImports(\"sql\");'/> ".$lang['sql']."</label>";
echo "<br/><label><input type='radio' name='import_type' value='csv' onclick='toggleImports(\"csv\");'/> ".$lang['csv']."</label>";
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px;' id='importoptions_sql'><legend><b>".$lang['options']."</b></legend>";
echo $lang['no_opt'];
echo "</fieldset>";
echo "<fieldset style='float:left; max-width:350px; display:none;' id='importoptions_csv'><legend><b>".$lang['options']."</b></legend>";
echo "<div style='float:left;'>".$lang['csv_tbl']."</div>";
echo "<select name='single_table' style='float:right;'>";
$tables = $db->getTables(true, false);
echo "<option value=''>(".$lang['create_tbl'].")</option>";
foreach($tables as $tableName => $tableType)
{
echo "<option value='".htmlencode($tableName)."'>".htmlencode($tableName)."</option>";
}
echo "</select>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_terminated']."</div>";
echo "<input type='text' value=';' name='import_csv_fieldsterminated' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_enclosed']."</div>";
echo "<input type='text' value='\"' name='import_csv_fieldsenclosed' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['fld_escaped']."</div>";
echo "<input type='text' value='\' name='import_csv_fieldsescaped' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<div style='float:left;'>".$lang['null_represent']."</div>";
echo "<input type='text' value='NULL' name='import_csv_replacenull' style='float:right;'/>";
echo "<div style='clear:both;'>";
echo "<label><input type='checkbox' checked='checked' name='import_csv_fieldnames'/> ".$lang['fld_names']."</label>";
echo "</fieldset>";
echo "<div style='clear:both;'></div>";
echo "<br/><br/>";
echo "<fieldset><legend><b>".$lang['import_f']."</b></legend>";
echo "<em>".$lang['max_file_size'].": ".number_format(fileUploadMaxSize()/1024/1024)." MiB</em> ".helpLink($lang['help11'])."<br />";
echo "<input type='file' value='".$lang['choose_f']."' name='file' style='background-color:transparent; border-style:none; margin:0; padding:0' onchange='checkFileSize(this)'/>";
echo "<input type='submit' value='".$lang['import']."' name='import' class='btn'/>";
echo "</fieldset>";
}
else if($view=="rename")
{
//- Rename database confirmation (=rename)
echo $params->getForm(array('view'=>'rename', 'database_rename'=>'1'));
echo "<input type='hidden' name='oldname' value='".htmlencode($db->getPath())."'/>";
echo $lang['db_rename']." '".htmlencode($db->getPath())."' ".$lang['to']." <input type='text' name='newname' style='width:200px;' value='".htmlencode($db->getPath())."'/> <input type='submit' value='".$lang['rename']."' name='rename' class='btn'/>";
echo "</form>";
}
else if($view=="delete")
{
//- Delete database confirmation (=delete)
echo $params->getForm(array('database_delete'=>'1'));
echo "<div class='confirm'>";
echo sprintf($lang['ques_database_delete'],htmlencode($db->getPath()))."<br/><br/>";
echo "<input name='database_delete' value='".htmlencode($db->getPath())."' type='hidden'/>";
echo "<input type='submit' value='".$lang['confirm']."' class='btn'/> ";
echo $params->getLink(array(), $lang['cancel']);
echo "</div>";
echo "</form>";
}
echo "</div>";
}
echo "</div>";
//- HTML: page footer
echo "<br/>";
echo "<span style='font-size:11px;'>".$lang['powered']." <a href='".PROJECT_URL."' target='_blank' style='font-size:11px;'>".PROJECT."</a> | ";
echo $lang['free_software']." <a href='".DONATE_URL."' target='_blank' style='font-size:11px;'>".$lang['please_donate']."</a> | ";
printf($lang['page_gen'], $pageTimer);
echo "</span>";
echo "</td></tr></table>";
$db->close(); //close the database
echo "</body>";
echo "</html>";
//- End of main code
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/weio/phpsqliteadmin.git
git@gitee.com:weio/phpsqliteadmin.git
weio
phpsqliteadmin
phpsqliteadmin
master

搜索帮助