count('publications'); $filter = false; // sort $order = null; $sortby = "DESC"; if ($VARS['order'][0]['dir'] == 'asc') { $sortby = "ASC"; } switch ($VARS['order'][0]['column']) { case 2: $order = ["pubname" => $sortby]; break; case 3: $order = ["pubdate" => $sortby]; break; case 5: $order = ["style" => $sortby]; break; case 6: $order = ["columns" => $sortby]; break; case 7: $order = ["sizename" => $sortby]; break; case 8: $order = ["permname" => $sortby]; break; } // search if (!is_empty($VARS['search']['value'])) { $filter = true; $wherenolimit = []; $wherenolimit["AND"]["OR"] = [ "pubname[~]" => $VARS['search']['value'], "pubdate[~]" => $VARS['search']['value'], "style[~]" => $VARS['search']['value'], "sizename[~]" => $VARS['search']['value'], "permname[~]" => $VARS['search']['value'] ]; $where = $wherenolimit; $where["LIMIT"] = [$VARS['start'], $VARS['length']]; } else { $where = ["LIMIT" => [$VARS['start'], $VARS['length']]]; } if (!is_null($order)) { $where["ORDER"] = $order; } $where["OR #perms"] = [ "uid" => $_SESSION['uid'], "permname #logg" => "LOGGEDIN", "permname #link" => "LINK" ]; //var_dump($where); $pubs = $database->select('publications', [ '[>]pub_permissions' => ['permid' => 'permid'], '[>]page_sizes' => ['page_size' => 'sizeid'] ], [ 'pubid', 'pubname', 'uid', 'pubdate', 'style', 'columns', 'permname', 'pwd', 'publications.permid', "page_size", "sizename", "landscape" ], $where); $out['status'] = "OK"; if ($filter) { $recordsFiltered = $database->count('publications', [ '[>]pub_permissions' => ['permid' => 'permid'] ], 'pubid', $wherenolimit); } else { $recordsFiltered = $out['recordsTotal']; } $out['recordsFiltered'] = $recordsFiltered; $usercache = []; for ($i = 0; $i < count($pubs); $i++) { if ($pubs[$i]["uid"] == $_SESSION['uid']) { $pubs[$i]["editbtn"] = ' ' . lang("edit", false) . ''; $pubs[$i]["editbtn"] .= ' ' . lang("format", false) . ''; } else { $pubs[$i]["editbtn"] = ' ' . lang("view", false) . ''; } $pubs[$i]["clonebtn"] = ' ' . lang("clone", false) . ''; $pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"])); if (is_null($pubs[$i]['uid'])) { $pubs[$i]["username"] = ""; } else { if (!isset($usercache[$pubs[$i]['uid']])) { $usercache[$pubs[$i]['uid']] = getUserByID($pubs[$i]['uid']); } $pubs[$i]["username"] = $usercache[$pubs[$i]['uid']]['name']; } $pubs[$i]["pagesize"] = lang2("page size and orientation", [ "size" => $pubs[$i]["sizename"], "orientation" => ( $pubs[$i]["landscape"] == 0 ? lang("portrait", false) : lang("landscape", false) ) ], false); if (!is_empty($pubs[$i]["pwd"])) { $pubs[$i]["permname"] = "password"; } $pubs[$i]["visibility"] = lang("visibility " . strtolower($pubs[$i]["permname"]), false); } $out['pubs'] = $pubs; echo json_encode($out);