/** * This forms lets admins pick files uploaded to the server for sorting on the site. */ public function classifyFileList() { $this->cabinet->title = dgettext('filecabinet', 'Classify files'); $classify_dir = $this->cabinet->getClassifyDir(); if (empty($classify_dir) || !is_dir($classify_dir)) { $this->cabinet->content = dgettext('filecabinet', 'Unable to locate the classify directory. Please check your File Cabinet settings, configuration file and directory permissions.'); return; } $allowed_file_types = $this->cabinet->getAllowedTypes(); $result = PHPWS_File::readDirectory($classify_dir, false, true); if (empty($result)) { $this->cabinet->content = dgettext('filecabinet', 'The incoming file directory is currently empty.'); return; } sort($result); if (PHPWS_Error::logIfError($result)) { $this->cabinet->content = dgettext('filecabinet', 'An error occurred when trying to read your incoming file directory.'); return; } $form = new PHPWS_Form('classify_file_list'); $form->addHidden('aop', 'classify_action'); $form->addHidden('module', 'filecabinet'); $image_folders = Cabinet::listFolders(IMAGE_FOLDER, true); if (!empty($image_folders)) { $form->addSelect('image_folders', $image_folders); $form->addSubmit('image_force', dgettext('filecabinet', 'Put all checked images here')); } $document_folders = Cabinet::listFolders(DOCUMENT_FOLDER, true); if (!empty($document_folders)) { $form->addSelect('document_folders', $document_folders); $form->addSubmit('document_force', dgettext('filecabinet', 'Put all checked documents here')); } $media_folders = Cabinet::listFolders(MULTIMEDIA_FOLDER, true); if (!empty($media_folders)) { $form->addSelect('media_folders', $media_folders); $form->addSubmit('media_force', dgettext('filecabinet', 'Put all checked media here')); } $options['classify'] = dgettext('filecabinet', '-- Pick option --'); $options['classify_file'] = dgettext('filecabinet', 'Classify checked'); $options['delete_incoming'] = dgettext('filecabinet', 'Delete checked'); $form->addSelect('process_checked', $options); $tpl = $form->getTemplate(); $js_vars['value'] = dgettext('filecabinet', 'Go'); $js_vars['select_id'] = 'classify_file_list_aop'; $js_vars['action_match'] = 'delete_incoming'; $js_vars['message'] = dgettext('filecabinet', 'Are you sure you wish to delete these files?'); $tpl['SUBMIT'] = javascript('select_confirm', $js_vars); $tpl['CHECK_ALL'] = javascript('check_all', array('checkbox_name' => 'file_list')); foreach ($result as $file) { $links = array(); $id = preg_replace('/\\W/', '-', $file); $rowtpl['FILE_NAME'] = sprintf('<label for="%s">%s</label>', $id, $file); $rowtpl['FILE_TYPE'] = PHPWS_File::getVbType($file); $vars['file'] = urlencode($file); if (!$this->cabinet->fileTypeAllowed($file)) { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'File type not allowed'); } elseif (!PHPWS_File::checkMimeType($classify_dir . $file)) { if (!is_readable($classify_dir . $file)) { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'File is unreadable'); } else { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'Unknown or mismatched mime type'); } } else { $rowtpl['CHECK'] = sprintf('<input type="checkbox" id="%s" name="file_list[]" value="%s" />', $id, $file); $rowtpl['ERROR'] = $rowtpl['MESSAGE'] = null; $vars['aop'] = 'classify_file'; $links[] = PHPWS_Text::secureLink(dgettext('filecabinet', 'Classify'), 'filecabinet', $vars); } $vars['aop'] = 'delete_incoming'; $cnf_js['QUESTION'] = dgettext('filecabinet', 'Are you sure you want to delete this file?'); $cnf_js['ADDRESS'] = PHPWS_Text::linkAddress('filecabinet', $vars, true); $cnf_js['LINK'] = dgettext('filecabinet', 'Delete'); $links[] = javascript('confirm', $cnf_js); $rowtpl['ACTION'] = implode(' | ', $links); $tpl['file-list'][] = $rowtpl; } $tpl['FILENAME_LABEL'] = dgettext('filecabinet', 'File name'); $tpl['FILETYPE_LABEL'] = dgettext('filecabinet', 'File type'); $tpl['ACTION_LABEL'] = dgettext('filecabinet', 'Action'); $this->cabinet->content = PHPWS_Template::process($tpl, 'filecabinet', 'Forms/classify_list.tpl'); }