function list_files()
 {
     ajx_current("empty");
     /* get query parameters */
     $start = (int) array_var($_GET, 'start');
     $limit = (int) array_var($_GET, 'limit');
     if (!$start) {
         $start = 0;
     }
     if (!$limit) {
         $limit = config_option('files_per_page');
     }
     $order = array_var($_GET, 'sort');
     $orderdir = array_var($_GET, 'dir');
     $page = (int) ($start / $limit) + 1;
     $hide_private = !logged_user()->isMemberOfOwnerCompany();
     $tag = array_var($_GET, 'tag');
     $type = array_var($_GET, 'type');
     $user = array_var($_GET, 'user');
     /* if there's an action to execute, do so */
     if (array_var($_GET, 'action') == 'delete') {
         $ids = explode(',', array_var($_GET, 'objects'));
         $succ = 0;
         $err = 0;
         foreach ($ids as $id) {
             $file = ProjectFiles::findById($id);
             if (isset($file) && $file->canDelete(logged_user())) {
                 try {
                     DB::beginWork();
                     $file->trash();
                     ApplicationLogs::createLog($file, $file->getWorkspaces(), ApplicationLogs::ACTION_TRASH);
                     DB::commit();
                     $succ++;
                 } catch (Exception $e) {
                     DB::rollback();
                     $err++;
                 }
             } else {
                 $err++;
             }
         }
         if ($succ > 0) {
             flash_success(lang("success delete files", $succ));
         } else {
             flash_error(lang("error delete files", $err));
         }
     } else {
         if (array_var($_GET, 'action') == 'tag') {
             $ids = explode(',', array_var($_GET, 'objects'));
             $tagTag = array_var($_GET, 'tagTag');
             $tagged = 0;
             $not_tagged = 0;
             foreach ($ids as $id) {
                 $file = ProjectFiles::findById($id);
                 if (isset($file) && $file->canEdit(logged_user())) {
                     $arr_tags = $file->getTags();
                     if (!array_search($tagTag, $arr_tags)) {
                         $arr_tags[] = $tagTag;
                         $file->setTagsFromCSV(implode(',', $arr_tags));
                         $tagged++;
                     }
                 } else {
                     $not_tagged++;
                 }
             }
             if ($tagged > 0) {
                 flash_success(lang("success tag objects", $tagged));
             } else {
                 flash_error(lang("error tag objects", $not_tagged));
             }
         } else {
             if (array_var($_GET, 'action') == 'untag') {
                 $ids = explode(',', array_var($_GET, 'objects'));
                 $tagTag = array_var($_GET, 'tagTag');
                 $untagged = 0;
                 $not_untagged = 0;
                 foreach ($ids as $id) {
                     $file = ProjectFiles::findById($id);
                     if (isset($file) && $file->canEdit(logged_user())) {
                         if ($tagTag != '') {
                             $file->deleteTag($tagTag);
                         } else {
                             $file->clearTags();
                         }
                         $untagged++;
                     } else {
                         flash_error(lang('no access permissions'));
                         $not_untagged++;
                     }
                 }
                 if ($untagged > 0) {
                     flash_success(lang("success untag objects", $untagged));
                 } else {
                     flash_error(lang("error untag objects", $not_untagged));
                 }
             } else {
                 if (array_var($_GET, 'action') == 'markasread') {
                     $ids = explode(',', array_var($_GET, 'objects'));
                     $succ = 0;
                     $err = 0;
                     foreach ($ids as $id) {
                         $file = ProjectFiles::findById($id);
                         try {
                             $file->setIsRead(logged_user()->getId(), true);
                             $succ++;
                         } catch (Exception $e) {
                             $err++;
                         }
                         // try
                     }
                     //for
                     if ($succ <= 0) {
                         flash_error(lang("error markasread files", $err));
                     }
                 } else {
                     if (array_var($_GET, 'action') == 'markasunread') {
                         $ids = explode(',', array_var($_GET, 'objects'));
                         $succ = 0;
                         $err = 0;
                         foreach ($ids as $id) {
                             $file = ProjectFiles::findById($id);
                             try {
                                 $file->setIsRead(logged_user()->getId(), false);
                                 $succ++;
                             } catch (Exception $e) {
                                 $err++;
                             }
                             // try
                         }
                         //for
                         if ($succ <= 0) {
                             flash_error(lang("error markasunread files", $err));
                         }
                     } else {
                         if (array_var($_GET, 'action') == 'zip_add') {
                             $this->zip_add();
                         } else {
                             if (array_var($_GET, 'action') == 'move') {
                                 $wsid = array_var($_GET, "moveTo");
                                 $destination = Projects::findById($wsid);
                                 if (!$destination instanceof Project) {
                                     $resultMessage = lang('project dnx');
                                     $resultCode = 1;
                                 } else {
                                     if (!can_add(logged_user(), $destination, 'ProjectFiles')) {
                                         $resultMessage = lang('no access permissions');
                                         $resultCode = 1;
                                     } else {
                                         $count = 0;
                                         $ids = explode(',', array_var($_GET, 'ids', ''));
                                         for ($i = 0; $i < count($ids); $i++) {
                                             $id = $ids[$i];
                                             $file = ProjectFiles::findById($id);
                                             if ($file instanceof ProjectFile && $file->canEdit(logged_user())) {
                                                 if (!array_var($_GET, "mantainWs")) {
                                                     $removed = "";
                                                     $ws = $file->getWorkspaces(null);
                                                     foreach ($ws as $w) {
                                                         if (can_add(logged_user(), $w, 'ProjectFiles')) {
                                                             $file->removeFromWorkspace($w);
                                                             $removed .= $w->getId() . ",";
                                                         }
                                                     }
                                                     $removed = substr($removed, 0, -1);
                                                     $log_action = ApplicationLogs::ACTION_MOVE;
                                                     $log_data = ($removed == "" ? "" : "from:{$removed};") . "to:{$wsid}";
                                                 } else {
                                                     $log_action = ApplicationLogs::ACTION_COPY;
                                                     $log_data = "to:{$wsid}";
                                                 }
                                                 $file->addToWorkspace($destination);
                                                 ApplicationLogs::createLog($file, $file->getWorkspaces(), $log_action, false, null, true, $log_data);
                                                 $count++;
                                             }
                                         }
                                         // for
                                         $resultMessage = lang("success move objects", $count);
                                         $resultCode = 0;
                                     }
                                 }
                             } else {
                                 if (array_var($_GET, 'action') == 'archive') {
                                     $ids = explode(',', array_var($_GET, 'ids'));
                                     $succ = 0;
                                     $err = 0;
                                     foreach ($ids as $id) {
                                         $file = ProjectFiles::findById($id);
                                         if (isset($file) && $file->canEdit(logged_user())) {
                                             try {
                                                 DB::beginWork();
                                                 $file->archive();
                                                 ApplicationLogs::createLog($file, $file->getWorkspaces(), ApplicationLogs::ACTION_ARCHIVE);
                                                 DB::commit();
                                                 $succ++;
                                             } catch (Exception $e) {
                                                 DB::rollback();
                                                 //Logger::log($e->getMessage());
                                                 $err++;
                                             }
                                         } else {
                                             $err++;
                                         }
                                     }
                                     if ($succ > 0) {
                                         flash_success(lang("success archive objects", $succ));
                                     } else {
                                         flash_error(lang("error archive objects", $err));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     Hook::fire('classify_action', null, $ret);
     $project = active_project();
     /* perform query */
     $result = ProjectFiles::getProjectFiles($project, null, $hide_private, $order, $orderdir, $page, $limit, false, $tag, $type, $user);
     ProjectFiles::populateData($result[0]);
     $objects = null;
     $pagination = null;
     if (is_array($result)) {
         list($objects, $pagination) = $result;
         if ($pagination->getTotalItems() < ($page - 1) * $limit) {
             // if we are past the last page show the first page
             $start = 0;
             $page = 1;
             $result = ProjectFiles::getProjectFiles($project, null, $hide_private, $order, $orderdir, $page, $limit, false, $tag, $type, $user);
             if (is_array($result)) {
                 list($objects, $pagination) = $result;
             }
         }
     }
     /* prepare response object */
     $listing = array("totalCount" => $pagination ? $pagination->getTotalItems() : 0, "start" => $start, "files" => array());
     if ($objects) {
         $index = 0;
         foreach ($objects as $o) {
             $coName = "";
             $coId = $o->getCheckedOutById();
             if ($coId != 0) {
                 if ($coId == logged_user()->getId()) {
                     $coName = "self";
                 } else {
                     $coUser = Users::findById($coId);
                     if ($coUser instanceof User) {
                         $coName = $coUser->getUsername();
                     } else {
                         $coName = "";
                     }
                 }
             }
             if ($o->isMP3()) {
                 $songname = $o->getProperty("songname");
                 $artist = $o->getProperty("songartist");
                 $album = $o->getProperty("songalbum");
                 $track = $o->getProperty("songtrack");
                 $year = $o->getProperty("songyear");
                 $duration = $o->getProperty("songduration");
                 $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId()));
             } else {
                 $songInfo = array();
             }
             $values = array("id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "name" => $o->getFilename(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "tags" => project_object_tags($o), "createdBy" => $o->getCreatedByDisplayName(), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn()) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => $o->getUpdatedByDisplayName(), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn()) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => $o->getFileSize(), "wsIds" => $o->getUserWorkspacesIdsCSV(logged_user(), ProjectUsers::instance()->getTableName(true) . ".`can_read_files` = 1"), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "isRead" => $o->getIsRead(logged_user()->getId()));
             if ($o->isMP3()) {
                 $values['isMP3'] = true;
             }
             Hook::fire('add_classification_value', $o, $values);
             $listing["files"][] = $values;
         }
     }
     ajx_extra_data($listing);
     tpl_assign("listing", $listing);
 }