Example #1
0
 /**
  * Read a directory
  *
  * @access public
  *
  * @param $pi path information
  * @param $retval file names in the directory
  */
 public static function getdir($pi, &$retval)
 {
     $filearray = array();
     Log::in("query - Getdir");
     /* Clear the return value */
     array_splice($retval, 0);
     switch ($pi[PI_LEVEL]) {
         case PL_ROOT:
             Log::output("query - Getdir - Getting psuedo entry list - root");
             $dirname = Pool::getDbName();
             $retval["."] = array('type' => FUSE_DT_DIR);
             $retval[".."] = array('type' => FUSE_DT_DIR);
             $retval["{$dirname}"] = array('type' => FUSE_DT_DIR);
             Log::out("query - Getdir");
             return 0;
         case PL_DB:
             Log::output("query - Getdir - Getting psuedo entry list - database");
             /* Get the db name */
             $dbname = Pool::getDbName();
             $retval["."] = array('type' => FUSE_DT_DIR);
             $retval[".."] = array('type' => FUSE_DT_DIR);
             /* Check for Evo or Revo database */
             foreach (Query::$_tableType as $tientry) {
                 $dirname = $tientry[TI_NAME];
                 if (Query::$_dbType == Query::dbIsRevo) {
                     if ($dirname == 'Modules') {
                         continue;
                     }
                 }
                 $retval["{$dirname}"] = array('type' => FUSE_DT_DIR);
             }
             Log::out("query - Getdir");
             return 0;
         case PL_TYPE:
             Log::output("query - Getdir - Getting category list");
             $retval["."] = array('type' => FUSE_DT_DIR);
             $retval[".."] = array('type' => FUSE_DT_DIR);
             $retval["Uncategorized"] = array('type' => FUSE_DT_DIR);
             /* If a resource group all of them under Uncategorized */
             if ($pi[PI_TYPE] == "Resources") {
                 Log::out("query - Getdir - Resources");
                 return 0;
             }
             /* Otherwise get the categories */
             Log::output("query - Getdir - Getting categories");
             $dbConn = Pool::get();
             $prefix = Pool::getTableprefix();
             $sql = "SELECT category FROM ";
             $sql .= "`{$prefix}" . "categories`";
             Log::output($sql);
             /* Check for failure */
             Log::output("query - Getdir - checking for failure");
             $result = mysql_query($sql, $dbConn);
             if ($result === false) {
                 Log::output(mysql_error($dbConn));
                 Pool::release($dbConn);
                 Log::out("query - Getdir - categories - EIO");
                 return -FUSE_EIO;
             }
             Log::output("query - Getdir - fetching rows");
             while ($row = mysql_fetch_row($result)) {
                 $dirname = $row[0];
                 $retval["{$dirname}"] = array('type' => FUSE_DT_DIR);
             }
             mysql_free_result($result);
             Pool::release($dbConn);
             Log::out("query - Getdir - categories");
             return 0;
         case PL_CATEGORY:
             Log::output("query - Getdir - Getting file list");
             $ret = Query::fillCategoryId($pi);
             if ($ret != 0) {
                 Log::out("query - Getdir fillcat failed");
                 return $ret;
             }
             $dbConn = Pool::get();
             $catid = $pi[PI_CATEGORYID];
             $name = $pi[PI_TI][TI_NAMEFIELD];
             $ext = $pi[PI_TI][TI_FILEEXT];
             $table = $pi[PI_TI][TI_TABLE];
             $prefix = Pool::getTableprefix();
             /* If a resource group all of them under Uncategorized */
             Log::output("query - Getdir - create sql");
             if ($pi[PI_TYPE] == "Resources") {
                 $sql = "SELECT id, {$name}  FROM ";
                 $sql .= "`{$prefix}" . "{$table}`";
             } else {
                 $sql = "SELECT id, {$name}  FROM ";
                 $sql .= "`{$prefix}" . "{$table}`";
                 $sql .= " WHERE category = '{$catid}'";
                 Log::output($sql);
             }
             /* Check for failure */
             Log::output("query - Getdir - checking for failure");
             $result = mysql_query($sql, $dbConn);
             if ($result === false) {
                 Log::output(mysql_error($dbConn));
                 Pool::release($dbConn);
                 Log::out("query - Getdir");
                 return -FUSE_EIO;
             }
             Log::output("query - Getdir - fetching rows");
             $retval["."] = array('type' => FUSE_DT_DIR);
             $retval[".."] = array('type' => FUSE_DT_DIR);
             while ($row = mysql_fetch_row($result)) {
                 $fileentry = array();
                 /* Get an entry from the DB and stack it */
                 $fileentry['id'] = $row[0];
                 $fileentry['name'] = $row[1];
                 $filestack[] = $fileentry;
             }
             /* Construct a list of id appended filenames */
             $filenames = Query::_constructFilename($filestack);
             /* Return them */
             foreach ($filenames as $filename) {
                 $fullfilename = $filename . $ext;
                 $retval["{$fullfilename}"] = array('type' => FUSE_DT_REG);
             }
             mysql_free_result($result);
             Pool::release($dbConn);
             Log::out("query - Getdir");
             return 0;
         default:
             Log::output("query - Getdir - Invalid PI_LEVEL");
             break;
     }
     /* Failed if we get here */
     Log::out("query - Getdir - failed");
     return -FUSE_EIO;
 }