Exemplo n.º 1
0
    echo json_encode($response);
    exit(0);
}
try {
    $parent = ProdsDir::fromURI($ruri, false);
    if (empty($parent->account->pass)) {
        $acct = $_SESSION['acct_manager']->findAcct($parent->account);
        if (empty($acct)) {
            $response = array('success' => false, 'log' => 'Authentication Required');
            echo json_encode($response);
            exit(0);
        }
        $parent->account = $acct;
    }
    if (empty($parent->account->zone)) {
        $parent->account->getUserInfo();
    }
    $parent->mkdir($name);
    $response = array('success' => true, 'log' => 'new collection created!');
    echo json_encode($response);
} catch (Exception $e) {
    $msg = '';
    $err_abbr = RODSException::rodsErrCodeToAbbr($e->getCode());
    if (null != $err_abbr) {
        $msg = 'Failed to create collection because server returned error: ' . $err_abbr;
    } else {
        $msg = 'Failed to create collection: ' . $e->getMessage();
    }
    $response = array('success' => false, 'errmsg' => $msg, 'errcode' => $e->getCode());
    echo json_encode($response);
}
 /**
  * Makes a general query to RODS server. Think it as an SQL. "select foo from sometab where bar = '3'". In this example, foo is specified by "$select", bar and "= '3'" are speficed by condition.
  * @param RODSGenQueSelFlds $select the fields (names) to be returned/interested. There can not be more than 50 input fields. For example:"COL_COLL_NAME" means collection-name.
  * @param RODSGenQueConds $condition  All fields are defined in RodsGenQueryNum.inc.php and RodsGenQueryKeyWd.inc.php
  * @param integer $start result start from which row.
  * @param integer $limit up to how many rows should the result contain. If -1 is passed, all available rows will be returned
  * @return RODSGenQueResults
  * Note: This function is very low level. It's not recommended for beginners.
  */
 public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $start = 0, $limit = -1)
 {
     if ($select->getCount() < 1 || $select->getCount() > 50) {
         throw new RODSException("Only 1-50 fields are supported", 'PERR_USER_INPUT_ERROR');
     }
     // contruct select packet (RP_InxIvalPair $selectInp), and condition packets
     $select_pk = $select->packetize();
     $cond_pk = $condition->packetize();
     $condkw_pk = $condition->packetizeKW();
     // determin max number of results per query
     if ($limit > 0 && $limit < 500) {
         $max_result_per_query = $limit;
     } else {
         $max_result_per_query = 500;
     }
     $num_fetched_rows = 0;
     $continueInx = 0;
     $results = new RODSGenQueResults();
     do {
         // construct RP_GenQueryInp packet
         $options = 1 | $GLOBALS['PRODS_GENQUE_NUMS']['RETURN_TOTAL_ROW_COUNT'];
         $genque_input_pk = new RP_GenQueryInp($max_result_per_query, $continueInx, $condkw_pk, $select_pk, $cond_pk, $options, $start);
         // contruce a new API request message, with type GEN_QUERY_AN
         $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']);
         fwrite($this->conn, $msg->pack());
         // send it
         // get value back
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') {
                 break;
             }
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
         $genque_result_pk = $msg_resv->getBody();
         $num_row_added = $results->addResults($genque_result_pk);
         $continueInx = $genque_result_pk->continueInx;
         $start = $start + $results->getNumRow();
     } while ($continueInx > 0 && ($results->getNumRow() < $limit || $limit < 0));
     // Make sure and close the query if there are any results left.
     if ($continueInx > 0) {
         $msg->getBody()->continueInx = $continueInx;
         $msg->getBody()->maxRows = -1;
         // tells the server to close the query
         fwrite($this->conn, $msg->pack());
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
     }
     return $results;
 }
Exemplo n.º 3
0
require_once "../config.inc.php";
session_start();
if (!isset($_SESSION['acct_manager'])) {
    $_SESSION['acct_manager'] = new RODSAcctManager();
}
$ruri = isset($_REQUEST['ruri']) ? $_REQUEST['ruri'] : '/';
$collection = ProdsDir::fromURI($ruri, false);
if (empty($collection->account->pass)) {
    $acct = $_SESSION['acct_manager']->findAcct($collection->account);
    if (empty($acct)) {
        $arr = array();
        $arr['success'] = false;
        $arr['errors'] = array();
        $arr['errmsg'] = "Please sign-on to access this collection/file";
        $arr['errcode'] = RODSException::rodsErrAbbrToCode("USER_AUTH_STRING_EMPTY");
        $str = json_encode($arr);
        echo "({$str})";
        exit(0);
    }
    $collection->account = $acct;
}
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 500;
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'name';
$dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : 'ASC';
if ($dir == 'ASC') {
    $dirbit = true;
} else {
    $dirbit = false;
}