Project: |
+ if ($PROJECT==='ALL') $tmp="button"; else $tmp="ubutton"; ?>
foreach($USERPROJECTS as $pid => $pname) { ?>
if (SU($pname)===SU($PROJECT)) $tmp="button"; else $tmp="ubutton"; ?>
diff --git a/src/init.php b/src/init.php
index dba2bce..19cbcc8 100644
--- a/src/init.php
+++ b/src/init.php
@@ -6,10 +6,10 @@
include_once('access.php');
include_once('tools.php');
- function callback($buffer) { // cleanup html output (disable with $NOCLEAN=true)
- return PR("/^\s+/m","",$buffer);
- }
- if (!$NOCLEAN) ob_start("callback");
+// function callback($buffer) { // cleanup html output (disable with $NOCLEAN=true)
+// return PR("/^\s+/m","",$buffer);
+// }
+// if (!$NOCLEAN) ob_start("callback");
global $DB; // connect to database
$DB=@mysqli_connect($MYHOST,$MYUSER,$MYPW,$MYDB);
@@ -49,8 +49,9 @@
}
global $USER,$ROLE,$ROLENAMES,$USERPROJECTS,$PROJECTS,$PROJECTNAMES,$ACCESSQL,$TCHR,$VERSION;
- global $TITLE,$DEBUG,$STDEF,$STYPES,$LMSG,$PROJECTPRIV,$ALLFIELDS,$DEFSEARCHFIELD,$IDPAT;
-
+ global $TITLE,$DEBUG,$STDEF,$STYPES,$LMSG,$PROJECTPRIV,$ALLFIELDS,$DEFSEARCHFIELD,$IDPAT,$DEVTYPE;
+ global $LABELPRINTER;
+
$USER='';$USERTYPE='';$ROLE='';$ACCESSQL='';$ROLENAMES=array();$USERPROJECTS=array();
$res = mysqli_query($DB,"SELECT * FROM projects");
@@ -64,5 +65,4 @@
phplog('','info');
-?>
-
+?>
\ No newline at end of file
diff --git a/src/login.php b/src/login.php
index c695dc3..6c460d5 100644
--- a/src/login.php
+++ b/src/login.php
@@ -16,7 +16,6 @@
session_unset();session_destroy();
?>
-
if (!PM("/^\s*$/",$LMSG)) { ?>
@@ -32,5 +31,4 @@
-
include_once('footer.php'); ?>
diff --git a/src/preview.php b/src/preview.php
index 663dfa6..3691333 100644
--- a/src/preview.php
+++ b/src/preview.php
@@ -63,7 +63,7 @@
readfile($prevfilepath); ?>
} else if (PM("/^image\//",$prevmime)) { ?>
-
+
} else if (PM("/^application\/pdf$/",$prevmime)) { ?>
header("Location: /send/".idencode($catid,$row['docid']));exit; ?>
} else { ?>
diff --git a/src/rest.php b/src/rest.php
index 000c78f..9f89dad 100644
--- a/src/rest.php
+++ b/src/rest.php
@@ -2,7 +2,7 @@
$NOLOGIN=1;
require('./init.php');
-
+// sleep(1);
function jfailed($err='') {
header('Content-Type: application/json');
if (strlen($err)>0) echo json_encode(array('success' => 0, 'error' => $err))."\n";
@@ -28,8 +28,6 @@ if ($cmd==='login') {
jfailed('login failed');
}
-mydo($DB,"DELETE FROM tokens WHERE unix_timestamp(now())-unix_timestamp(ts)>86400");
-
$J = json_decode(file_get_contents('php://input'), true); // load user info from token
if ($J==null) jfailed("invalid json");
@@ -41,7 +39,7 @@ if ($numrows==1) {
$row = mysqli_fetch_assoc($res);
if ($_SERVER['REMOTE_ADDR']===$row['ip']) {
- mydo($DB,"UPDATE tokens SET ts=now() WHERE token='".$J['token']."'");
+ mydo($DB,"UPDATE tokens SET ts=now() WHERE token='".$J['token']."'",1);
$name=$row['name'];
$type=$row['type'];
@@ -52,6 +50,14 @@ if (!setaccess($name,$type)) jfailed("login failed");
////////////////////////////////////////////////////////////////////////////////////////////////// rest commands
+if ($cmd==='renew') { ////////////////////////////////////////////////////////////////////////////// renew token
+ $I=array();
+ $J=json_decode(file_get_contents('php://input'), true);
+ $newtoken=id62(16);
+ mydo($DB,"UPDATE tokens SET ts=now(),token='".$newtoken."' WHERE token='".$J['token']."'",1);
+ jsuccess(array('success' => 1, 'token' => $newtoken));
+}
+
if ($cmds[0]==='download') { ///////////////////////////////////////////////////////////////////// download file
$catid=catidfromid($cmds[1]); if ($catid==-1) jfailed("id not found");
@@ -114,6 +120,7 @@ if ($cmds[0]==='directupload' || $cmds[0]==='urlupload') { //////////////// uplo
$J=json_decode(file_get_contents('php://input'), true);
$fn=$J['filename'];
+ $comment=$J['comment'];
$fid=id62(12);
if ($cmds[0]==='directupload') {
@@ -131,7 +138,8 @@ if ($cmds[0]==='directupload' || $cmds[0]==='urlupload') { //////////////// uplo
$mysqlts=date('Y-m-d H:i:s');
$sql="INSERT INTO docs SET docid=0,catid=$catid,ts='$mysqlts',rm=0,md5='$md5',filename='".
- mysqli_escape_string($DB,$fn) ."',mime='".mysqli_escape_string($DB,$mime)."',size=$size";
+ mysqli_escape_string($DB,$fn) ."',comment='".mysqli_escape_string($DB,$comment).
+ "',mime='".mysqli_escape_string($DB,$mime)."',size=$size";
$res= mydo($DB,$sql);
$docid=mysqli_insert_id($DB);
@@ -158,7 +166,7 @@ if ($cmd==='list') { ///////////////////////////////////////////////////////////
if ($numrows>0) {
while($row = mysqli_fetch_assoc($res)) {
- array_push($I,$row['catid']);
+ array_push($I,$row['id']);
}
jsuccess(array('success' => 1, 'ids' => $I));
@@ -196,6 +204,186 @@ if ($cmd==='projects') { ///////////////////////////////////////////////////////
jsuccess(array('success' => 1, 'projects' => $I));
}
+if ($cmds[0]==='metadump') { /////////////////////////////////////////////////////////// bulk get entry data
+
+ $CTI=array();
+ $sql="SELECT id,catid FROM cat";
+ $res=mydo($DB,$sql,1);
+ while($r = mysqli_fetch_assoc($res)) {
+ $CTI[$r['catid']]=$r['id'];
+ }
+
+ $JJ = array('success' => 1);
+
+ $sql="SELECT * FROM cat WHERE rm=0 AND $ACCESSQL";
+ $res=mydo($DB,$sql,1);
+
+ $numrows =mysqli_num_rows($res);
+
+ if ($numrows>0) {
+ $I=array();
+ while($row = mysqli_fetch_assoc($res)) {
+
+ $comment =$row['comment'];if (PM("/^\s*$/",$row['comment'])) $comment="";
+
+ $J=array('catid'=> $row['catid'],
+ 'id' => $row['id'],
+ 'comment' => $comment,
+ 'tent'=>$row['tent'],
+ 'tcha'=>$row['tcha'],
+ 'project'=>$project,
+ 'user'=>$row['user'],
+ 'type'=>$row['type']);
+
+ for ($i=0;$i<$FMAX;$i++) {
+ $key=$FMAP[$row['type']][$i][0];
+ if (!PM("/^\s*$/",$row["f$i"])) $J[$key]=$row["f$i"];
+ }
+
+ $J["jasondata"]= json_decode($row['jsondata']);
+
+ array_push($I,$J);
+
+ }
+ $JJ["cat"]=$I;
+ }
+
+ $sql="SELECT * FROM cat,links,".
+ "(select access as laccess,project as lproject,catid as lcatid,user as luser from cat) AS L ".
+ "WHERE cat.rm=0 AND cat.catid=links.catid AND links.link=lcatid AND $LACCESSQL AND $ACCESSQL";
+ $res=mydo($DB,$sql,1);
+ $numrows =mysqli_num_rows($res);
+
+ if ($numrows>0) {
+ $I=array();
+ while($row = mysqli_fetch_assoc($res)) {
+ $J=array('lid' => $row['lid'],
+ 'ts' => $row['ts'],
+ 'catid' => $CTI[$row['catid']],
+ 'link' => $CTI[$row['link']]);
+ array_push($I,$J);
+ }
+ $JJ["links"]=$I;
+ }
+
+ $sql="select * from gen where rm=0";
+ $res=mydo($DB,$sql,1);
+ $numrows =mysqli_num_rows($res);
+
+ if ($numrows>0) {
+ $I=array();
+ while($row = mysqli_fetch_assoc($res)) {
+ $J=array('ts' => $row['ts'],
+ 'catid' => $CTI[$row['catid']],
+ 'parent' => $CTI[$row['parent']],
+ 'gen' => $row['gen']);
+
+ array_push($I,$J);
+ }
+ $JJ["gen"]=$I;
+ }
+
+ jsuccess($JJ);
+
+}
+
+if ($cmds[0]==='bulk') { /////////////////////////////////////////////////////////////////// bulk get entry data
+
+ $xids=explode(',',$cmds[1]);
+ $JJ=array();
+
+ $CTI=array();
+ $sql="SELECT id,catid FROM cat";
+ $res=mydo($DB,$sql,1);
+ while($r = mysqli_fetch_assoc($res)) {
+ $CTI[$r['id']]=$r['catid'];
+ }
+
+ foreach ($xids as $xid) {
+ if (!array_key_exists($xid, $CTI)) jfailed("id not found");
+
+ $catid=$CTI[$xid];
+
+ $gen=array();
+ $sql="SELECT * FROM gen WHERE catid=$catid AND rm=0 ORDER BY gen";
+ $res=mydo($DB,$sql,1);
+ while($r = mysqli_fetch_assoc($res)) {
+ array_push($gen,$CTI[$r['parent']]);
+ }
+
+ $par=array();
+ $sql="SELECT * FROM gen WHERE parent=$catid AND rm=0 ORDER BY gen";
+ $res=mydo($DB,$sql,1);
+ while($r = mysqli_fetch_assoc($res)) {
+ array_push($par,$CTI[$r['catid']]);
+ }
+
+ $sql="SELECT * FROM cat WHERE catid=$catid AND $ACCESSQL";
+ $res=mydo($DB,$sql,1);
+
+ $numrows =mysqli_num_rows($res);
+ if ($numrows==1) {
+ $row = mysqli_fetch_assoc($res);
+
+ $project=$PROJECTS[$row['project']];
+
+ $J = array('success' => 1,
+ 'id'=>$row['id'],
+ 'tent'=>$row['tent'],
+ 'tcha'=>$row['tcha'],
+ 'project'=>$project,
+ 'user'=>$row['user'],
+ 'type'=>$row['type']);
+
+ if (count($gen)>0) $J['ancestry'] = $gen;
+ if (count($par)>0) $J['descendants'] = $par;
+
+ for ($i=0;$i<$FMAX;$i++) {
+ $key=$FMAP[$row['type']][$i][0];
+ if (!PM("/^\s*$/",$row["f$i"])) $J[$key]=$row["f$i"];
+ }
+
+ $J["jasondata"]= json_decode($row['jsondata']);
+
+ $I=array();
+
+ $sql="SELECT * FROM docs WHERE catid=$catid AND rm=0";
+ $res=mydo($DB,$sql,1);
+ $fnumrows =mysqli_num_rows($res);
+ if ($fnumrows>0) {
+ while($row = mysqli_fetch_assoc($res)) {
+
+ $comment =$row['comment'];if (PM("/^\s*$/",$row['comment'])) $comment="";
+
+ array_push($I,array('id' => $row['docid'],
+ 'filename' => $row['filename'],
+ 'comment' => $comment,
+ 'size' => $row['size'],
+ 'mimetype' => $row['mime']));
+ }
+ $J["files"]=$I;
+ }
+
+ $I=array();
+ $sql="select * from cat,links where links.catid=$catid and cat.catid=links.link and $ACCESSQL";
+
+ $res=mydo($DB,$sql,1);
+ $fnumrows =mysqli_num_rows($res);
+ if ($fnumrows>0) {
+ while($lrow = mysqli_fetch_assoc($res)) {
+ array_push($I,array('lid' => $lrow['lid'],
+ 'link' => $lrow['id']));
+ }
+ $J["links"]=$I;
+ }
+ array_push($JJ,$J);
+ }
+ }
+
+ jsuccess($JJ);
+
+}
+
if ($cmds[0]==='get' || $cmds[0]==='getraw') { ////////////////////////////////////////////////// get entry data
$catid=catidfromid($cmds[1]); if ($catid==-1) jfailed("id not found");
@@ -244,7 +432,7 @@ if ($cmds[0]==='get' || $cmds[0]==='getraw') { /////////////////////////////////
$J["jasondata"]= json_decode($row['jsondata']);
$I=array();
- $sql="SELECT * FROM docs WHERE catid=$catid AND rm=0";
+ $sql="SELECT * FROM docs WHERE catid=$catid AND rm=0 ORDER BY ts DESC";
$res=mydo($DB,$sql,1);
$fnumrows =mysqli_num_rows($res);
if ($fnumrows>0) {
@@ -254,6 +442,7 @@ if ($cmds[0]==='get' || $cmds[0]==='getraw') { /////////////////////////////////
array_push($I,array('id' => $row['docid'],
'filename' => $row['filename'],
+ 'timestamp' => $row['ts'],
'comment' => $comment,
'size' => $row['size'],
'mimetype' => $row['mime']));
@@ -416,6 +605,29 @@ if ($cmds[0]==='edit') { ///////////////////////////////////////////////////////
jfailed();
}
+if ($cmds[0]==='fix') { ////////////////////////////////////////////////////////////////////////////// fix entry
+ $J=json_decode(file_get_contents('php://input'), true);
+
+ $catid=catidfromid($cmds[1]);if ($catid==-1) jfailed("id not found");
+
+ if (chkeditaccess($catid)) {
+
+ $sql="SELECT * FROM cat WHERE catid=$catid AND $ACCESSQL";
+ $res=mydo($DB,$sql,1);
+
+ $numrows =mysqli_num_rows($res);
+ if ($numrows==1) {
+ mydo($DB,"UPDATE cat SET fixed=1 WHERE catid=$catid");
+ alog($cmds[1],0,'fixed');
+ jsuccess(array('success' => 1, 'id' => $cmds[1]));
+ }
+ } else {
+ jfailed('no access');
+ }
+
+ jfailed();
+}
+
if ($cmds[0]==='delete') { //////////////////////////////////////////////////////////////////////// delete entry
$J=json_decode(file_get_contents('php://input'), true);
@@ -546,16 +758,22 @@ if ($cmds[0]==='search') { /////////////////////////////////////////////////////
$sql="SELECT * FROM cat WHERE (";
foreach ($S as $s) {
- foreach ($s['fields'] as $f) {
+
+ $fa=array();
+ if (array_key_exists('fields',$s)) $fa=$s['fields'];
+ else $fa=range(0,31);
+
+ foreach ($fa as $f) {
$sql.="(";
foreach ($s['keys'] as $k) {
-
+
$sql.="f$f LIKE '%$k%' OR ";
}
$sql=PR("/\s*OR\s*$/",") OR ",$sql);
}
$sql=PR("/\s*OR\s*$/","",$sql);
$sql.=" AND ";
+
}
$sql=PR("/\s*AND\s*$/","",$sql);
$sql.=") AND $ACCESSQL";
@@ -597,7 +815,7 @@ if ($cmds[0]==='jsonadd') { ////////////////////////////////////////////////////
jfailed();
}
-if ($cmds[0]==='jsonget') { ////////////////////////////////////////////////////////////////////// add json data
+if ($cmds[0]==='jsonget') { ////////////////////////////////////////////////////////////////////// get json data
$J=json_decode(file_get_contents('php://input'), true);
$catid=catidfromid($cmds[1]);if ($catid==-1) jfailed("id not found");
@@ -651,4 +869,4 @@ if ($cmds[0]==='jsonsearch') { /////////////////////////////////////////////////
jsuccess(array('success' => 1, 'result' => $I));
}
-?>
+?>
\ No newline at end of file
diff --git a/src/search.php b/src/search.php
index 7611872..6ecbac6 100644
--- a/src/search.php
+++ b/src/search.php
@@ -13,6 +13,7 @@
unset($_SESSION['s_json2']);
$_SESSION['s_op']='AND';
unset($_SESSION['s_usr']);
+ unset($_SESSION['s_ft']);
unset($_SESSION['s_all']);
unset($_SESSION['s_id']);
unset($_SESSION['s_fn']);
@@ -34,7 +35,7 @@
$_POST["s_field$fn"] =$S['s_field'][$fn];
$_POST["s_fieldop$fn"] =$S['s_fieldop'][$fn];
}
- foreach (array('type','project','s_op','s_json1','s_json2','s_usr','s_all','s_id','s_fn') as $val) {
+ foreach (array('type','project','s_op','s_json1','s_json2','s_usr','s_ft','s_all','s_id','s_fn') as $val) {
$_POST[$val]=$S[$val];
}
$TYPE=$S['type'];
@@ -49,7 +50,7 @@
if (!PM("/^\s*$/",getpar('project'))) $_SESSION['currentproject']=getpar('project');
$PROJECT=$_SESSION['currentproject'];
- foreach (array('s_op','s_json1','s_json2','s_usr','s_all','s_id','s_fn') as $val) {
+ foreach (array('s_op','s_json1','s_json2','s_usr','s_ft','s_all','s_id','s_fn') as $val) {
if (isset($_POST[$val])) $_SESSION[$val]=getpar($val);
$S[$val]=$_SESSION[$val];
}
@@ -82,6 +83,15 @@
}
$MS=PR("/,\s*$/","",$MS);
+ unset($_SESSION["ftres"]);
+ if (!PM("/^\s*$/",$S['s_ft'])) {
+ $res=mydo($DB,"SELECT catid,docid FROM ft WHERE ft LIKE '%".$S['s_ft']."%'",1);
+ while($row = mysqli_fetch_assoc($res)) {
+ phplog($row['docid']);
+ $_SESSION['ftres'][$row['docid']]=$row['catid'];
+ }
+ }
+
foreach($TYPES as $type) {
foreach($FMAP[$type] as $n => $f) {
$ALLFIELDS[$f[0]]=1;
@@ -192,7 +202,11 @@
$searchsql.=" AND (catid=".catidfromid($M[1].$M[2]).")";
}
}
-
+
+ if (!PM("/^\s*$/",$S['s_ft'])) {
+ $searchsql.=" AND (cat.catid in (select ft.catid from ft where ft like '%".$S['s_ft']."%'))";
+ }
+
$FX='';
for ($n=1;$n<$FSM;$n++) {
if ($S['s_fieldop'][$n]==='AND') $FX.="1";
@@ -268,7 +282,7 @@
|
-