function file_list($message = '') { global $txpcfg, $extensions, $file_base_path, $file_statuses, $file_list_pageby; pagetop(gTxt('file'), $message); extract($txpcfg); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if (!is_dir($file_base_path) or !is_writeable($file_base_path)) { echo graf(gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), ' id="warning"'); } else { $existing_files = get_filenames(); if (count($existing_files) > 0) { echo form(eInput('file') . sInput('file_create') . graf(gTxt('existing_file') . sp . selectInput('filename', $existing_files, '', 1) . sp . fInput('submit', '', gTxt('Create'), 'smallerbox')), 'text-align: center;'); } echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; switch ($sort) { case 'id': $sort_sql = 'id ' . $dir; break; case 'description': $sort_sql = 'description ' . $dir . ', filename desc'; break; case 'category': $sort_sql = 'category ' . $dir . ', filename desc'; break; case 'downloads': $sort_sql = 'downloads ' . $dir . ', filename desc'; break; default: $sort = 'filename'; $sort_sql = 'filename ' . $dir; break; } $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit) { $crit_escaped = doSlash($crit); $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "filename like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $total = safe_count('txp_file', "{$criteria}"); if ($total < 1) { if ($criteria != 1) { echo n . file_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"'); } else { echo n . graf(gTxt('no_files_recorded'), ' class="indicator"'); } return; } $limit = max($file_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo file_search_form($crit, $search_method); $rs = safe_rows_start('*', 'txp_file', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { echo '<form name="longform" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list') . tr(column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, 'id' == $sort ? $dir : '') . hCell() . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, 'filename' == $sort ? $dir : '') . column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method, 'description' == $sort ? $dir : '') . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, 'category' == $sort ? $dir : '') . hCell(gTxt('tags')) . hCell(gTxt('status')) . hCell(gTxt('condition')) . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, 'downloads' == $sort ? $dir : '') . hCell()); while ($a = nextRow($rs)) { extract($a); $edit_url = '?event=file' . a . 'step=file_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit; $file_exists = file_exists(build_file_path($file_base_path, $filename)); $download_link = $file_exists ? '<li>' . make_download_link($id, '', $filename) . '</li>' : ''; $category = $category ? '<span title="' . htmlspecialchars(fetch_category_title($category, 'file')) . '">' . $category . '</span>' : ''; $tag_url = '?event=tag' . a . 'tag_name=file_download_link' . a . 'id=' . $id . a . 'description=' . urlencode($description) . a . 'filename=' . urlencode($filename); $condition = '<span class="'; $condition .= $file_exists ? 'ok' : 'not-ok'; $condition .= '">'; $condition .= $file_exists ? gTxt('file_status_ok') : gTxt('file_status_missing'); $condition .= '</span>'; echo tr(n . td($id) . td('<ul>' . '<li>' . href(gTxt('edit'), $edit_url) . '</li>' . $download_link . '</ul>', 65) . td(href(htmlspecialchars($filename), $edit_url), 125) . td(htmlspecialchars($description), 150) . td($category, 90) . td(n . '<ul>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href, 400, 250); return false;">Textile</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href, 400, 250); return false;">Textpattern</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=xhtml" onclick="popWin(this.href, 400, 250); return false;">XHTML</a></li>' . n . '</ul>', 75) . td($file_statuses[$status], 45) . td($condition, 45) . td($downloads == '0' ? gTxt('none') : $downloads, 25) . td(fInput('checkbox', 'selected[]', $id), 10)); } echo tr(tda(select_buttons() . file_multiedit_form($page, $sort, $dir, $crit, $search_method), ' colspan="10" style="text-align: right; border: none;"')) . endTable() . '</form>' . nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method) . pageby_form('file', $file_list_pageby); } }
function file_list($message = '') { global $file_base_path, $file_statuses, $file_list_pageby, $txp_user, $event; pagetop(gTxt('tab_file'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('file_sort_column', 'filename'); } if ($dir === '') { $dir = get_pref('file_sort_dir', 'asc'); } if ($dir === 'desc') { $dir = 'desc'; } else { $dir = 'asc'; } echo hed(gTxt('tab_file'), 1, array('class' => 'txp-heading')) . n . tag_start('div', array('id' => $event . '_control', 'class' => 'txp-control-panel')); if (!is_dir($file_base_path) || !is_writeable($file_base_path)) { echo graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), array('class' => 'alert-block warning')); } elseif (has_privs('file.edit.own')) { $existing_files = get_filenames(); if ($existing_files) { echo form(eInput('file') . sInput('file_create') . graf(tag(gTxt('existing_file'), 'label', array('for' => 'file-existing')) . sp . selectInput('filename', $existing_files, '', 1, '', 'file-existing') . sp . fInput('submit', '', gTxt('Create')), array('class' => 'existing-file')), '', '', 'post', '', '', 'assign_file'); } echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); } switch ($sort) { case 'id': $sort_sql = 'txp_file.id ' . $dir; break; case 'description': $sort_sql = 'txp_file.description ' . $dir . ', txp_file.filename desc'; break; case 'category': $sort_sql = 'txp_category.title ' . $dir . ', txp_file.filename desc'; break; case 'title': $sort_sql = 'txp_file.title ' . $dir . ', txp_file.filename desc'; break; case 'downloads': $sort_sql = 'txp_file.downloads ' . $dir . ', txp_file.filename desc'; break; case 'author': $sort_sql = 'txp_users.RealName ' . $dir . ', txp_file.id asc'; break; default: $sort = 'filename'; $sort_sql = 'txp_file.filename ' . $dir; break; } set_pref('file_sort_column', $sort, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE); set_pref('file_sort_dir', $dir, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE); if ($dir == 'desc') { $switch_dir = 'asc'; } else { $switch_dir = 'desc'; } $criteria = 1; if ($search_method && $crit !== '') { $verbatim = preg_match('/^"(.*)"$/', $crit, $m); $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit); $critsql = $verbatim ? array('id' => "txp_file.id in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "txp_file.filename = '{$crit_escaped}'", 'title' => "txp_file.title = '{$crit_escaped}'", 'description' => "txp_file.description = '{$crit_escaped}'", 'category' => "txp_file.category = '{$crit_escaped}' or txp_category.title = '{$crit_escaped}'", 'author' => "txp_file.author = '{$crit_escaped}' or txp_users.RealName = '{$crit_escaped}'") : array('id' => "txp_file.id in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "txp_file.filename like '%{$crit_escaped}%'", 'title' => "txp_file.title like '%{$crit_escaped}%'", 'description' => "txp_file.description like '%{$crit_escaped}%'", 'category' => "txp_file.category like '%{$crit_escaped}%' or txp_category.title like '%{$crit_escaped}%'", 'author' => "txp_file.author like '%{$crit_escaped}%' or txp_users.RealName like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $criteria .= callback_event('admin_criteria', 'file_list', 0, $criteria); $sql_from = safe_pfx_j('txp_file') . "\n left join " . safe_pfx_j('txp_category') . " on txp_category.name = txp_file.category and txp_category.type = 'file'\n left join " . safe_pfx_j('txp_users') . " on txp_users.name = txp_file.author"; if ($criteria === 1) { $total = safe_count('txp_file', $criteria); } else { $total = getThing('select count(*) from ' . $sql_from . ' where ' . $criteria); } if ($total < 1) { if ($criteria != 1) { echo file_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>'; } else { echo graf(gTxt('no_files_recorded'), ' class="indicator"') . '</div>'; } return; } $limit = max($file_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo file_search_form($crit, $search_method) . '</div>'; $rs = safe_query("select\n txp_file.id,\n txp_file.filename,\n txp_file.title,\n txp_file.category,\n txp_file.description,\n txp_file.downloads,\n txp_file.status,\n txp_file.author,\n txp_users.RealName as realname,\n txp_category.Title as category_title\n from {$sql_from} where {$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs && numRows($rs)) { $show_authors = !has_single_author('txp_file'); echo n . tag_start('div', array('id' => $event . '_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'files_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') . column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'txp-list-col-id') . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, ('filename' == $sort ? "{$dir} " : '') . 'txp-list-col-filename') . column_head('title', 'title', 'file', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'txp-list-col-title') . column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'txp-list-col-description files_detail') . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'txp-list-col-category category') . hCell(gTxt('tags'), '', ' scope="col" class="txp-list-col-tag-build files_detail"') . hCell(gTxt('status'), '', ' scope="col" class="txp-list-col-status"') . hCell(gTxt('condition'), '', ' scope="col" class="txp-list-col-condition"') . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, ('downloads' == $sort ? "{$dir} " : '') . 'txp-list-col-downloads') . ($show_authors ? column_head('author', 'author', 'file', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author name') : '')) . n . tag_end('thead') . n . tag_start('tbody'); $validator = new Validator(); while ($a = nextRow($rs)) { extract($a); $filename = sanitizeForFile($filename); $edit_url = array('event' => 'file', 'step' => 'file_edit', 'id' => $id, 'sort' => $sort, 'dir' => $dir, 'page' => $page, 'search_method' => $search_method, 'crit' => $crit); $tag_url = array('event' => 'tag', 'tag_name' => 'file_download_link', 'id' => $id, 'description' => $description, 'filename' => $filename); $file_exists = file_exists(build_file_path($file_base_path, $filename)); $can_edit = has_privs('file.edit') || $author === $txp_user && has_privs('file.edit.own'); $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'file')))); if ($validator->validate()) { $vc = ''; } else { $vc = ' error'; } if ($file_exists) { $downloads = make_download_link($id, $downloads, $filename); $condition = span(gTxt('file_status_ok'), array('class' => 'success')); } else { $condition = span(gTxt('file_status_missing'), array('class' => 'error')); } if ($category) { $category = span(txpspecialchars($category_title), array('title' => $category)); } if ($can_edit) { $name = href(txpspecialchars($filename), $edit_url, array('title' => gTxt('edit'))); } else { $name = txpspecialchars($filename); } if ($can_edit) { $id_column = href($id, $edit_url, array('title' => gTxt('edit'))); $multi_edit = fInput('checkbox', 'selected[]', $id); } else { $id_column = $id; $multi_edit = ''; } if ($file_exists) { $id_column .= sp . span('[', array('aria-hidden' => 'true')) . make_download_link($id, gTxt('download'), $filename) . span(']', array('aria-hidden' => 'true')); } if (isset($file_statuses[$status])) { $status = $file_statuses[$status]; } else { $status = span(gTxt('none'), array('class' => 'error')); } echo tr(td($multi_edit, '', 'txp-list-col-multi-edit') . hCell($id_column, '', array('scope' => 'row', 'class' => 'txp-list-col-id')) . td($name, '', 'txp-list-col-filename') . td(txpspecialchars($title), '', 'txp-list-col-title') . td(txpspecialchars($description), '', 'txp-list-col-description files_detail') . td($category, '', 'txp-list-col-category category' . $vc) . td(href('Textile', $tag_url + array('type' => 'textile'), ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('|', array('role' => 'separator')) . sp . href('Textpattern', $tag_url + array('type' => 'textpattern'), ' target="_blank" onclick="popWin(this.href); return false;"') . sp . span('|', array('role' => 'separator')) . sp . href('HTML', $tag_url + array('type' => 'html'), ' target="_blank" onclick="popWin(this.href); return false;"'), '', 'txp-list-col-tag-build files_detail') . td($status, '', 'txp-list-col-status') . td($condition, '', 'txp-list-col-condition') . td($downloads, '', 'txp-list-col-downloads') . ($show_authors ? td(span(txpspecialchars($realname), array('title' => $author)), '', 'txp-list-col-author name') : '')); } echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . file_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . graf(toggle_box('files_detail'), array('class' => 'detail-toggle')) . n . tag_start('div', array('id' => $event . '_navigation', 'class' => 'txp-navigation')) . pageby_form('file', $file_list_pageby) . nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div') . n . tag_end('div'); } }
if (!$source) { login_page(); exit; } switch ($action) { case 'edit_store_action': edit_store_action(); break; case 'edit_store_form': edit_store_form(); break; case 'file_search_action': file_search_action(); break; case 'file_search_form': file_search_form(); break; case 'logout': logout(); break; case 'obs_search_action': obs_search_action(); break; case 'store': show_store(); break; case 'stores': show_stores(); break; case 'tasks': show_tasks();
function file_list($message = '') { global $file_base_path, $file_statuses, $file_list_pageby, $txp_user, $event; pagetop(gTxt('file'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('file_sort_column', 'filename'); } if ($dir === '') { $dir = get_pref('file_sort_dir', 'asc'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; echo '<div id="' . $event . '_control" class="txp-control-panel">'; if (!is_dir($file_base_path) or !is_writeable($file_base_path)) { echo graf(gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), ' id="warning"'); } elseif (has_privs('file.edit.own')) { $existing_files = get_filenames(); if (count($existing_files) > 0) { echo form(eInput('file') . sInput('file_create') . graf('<label for="file-existing">' . gTxt('existing_file') . '</label>' . sp . selectInput('filename', $existing_files, '', 1, '', 'file-existing') . sp . fInput('submit', '', gTxt('Create'), 'smallerbox'), ' class="existing-file"'), 'text-align: center;', '', 'post', '', '', 'assign_file'); } echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); } switch ($sort) { case 'id': $sort_sql = 'id ' . $dir; break; case 'description': $sort_sql = 'description ' . $dir . ', filename desc'; break; case 'category': $sort_sql = 'category ' . $dir . ', filename desc'; break; case 'title': $sort_sql = 'title ' . $dir . ', filename desc'; break; case 'downloads': $sort_sql = 'downloads ' . $dir . ', filename desc'; break; case 'author': $sort_sql = 'author ' . $dir . ', id asc'; break; default: $sort = 'filename'; $sort_sql = 'filename ' . $dir; break; } set_pref('file_sort_column', $sort, 'file', 2, '', 0, PREF_PRIVATE); set_pref('file_sort_dir', $dir, 'file', 2, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit) { $crit_escaped = doSlash(str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit)); $critsql = array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "filename like '%{$crit_escaped}%'", 'title' => "title like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $total = safe_count('txp_file', "{$criteria}"); if ($total < 1) { if ($criteria != 1) { echo n . file_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>'; } else { echo n . graf(gTxt('no_files_recorded'), ' class="indicator"') . '</div>'; } return; } $limit = max($file_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo file_search_form($crit, $search_method) . '</div>'; $rs = safe_rows_start('*', 'txp_file', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { $show_authors = !has_single_author('txp_file'); echo n . '<div id="' . $event . '_container" class="txp-container txp-list">'; echo '<form name="longform" id="files_form" method="post" action="index.php" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list', '', 'list') . n . '<thead>' . tr(column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . hCell('', '', ' class="actions"') . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, ('filename' == $sort ? "{$dir} " : '') . 'name') . column_head('title', 'title', 'file', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'title') . column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'description') . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . hCell(gTxt('tags'), '', ' class="tag-build"') . hCell(gTxt('status'), '', ' class="status"') . hCell(gTxt('condition'), '', ' class="condition"') . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, ('downloads' == $sort ? "{$dir} " : '') . 'downloads') . ($show_authors ? column_head('author', 'author', 'file', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '') . hCell('', '', ' class="multi-edit"')) . n . '</thead>'; $tfoot = n . '<tfoot>' . tr(tda(select_buttons() . file_multiedit_form($page, $sort, $dir, $crit, $search_method), ' class="multi-edit" colspan="' . ($show_authors ? '12' : '11') . '" style="text-align: right; border: none;"')) . n . '</tfoot>'; echo $tfoot; echo '<tbody>'; $ctr = 1; while ($a = nextRow($rs)) { extract($a); $filename = sanitizeForFile($filename); $edit_url = '?event=file' . a . 'step=file_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit; $file_exists = file_exists(build_file_path($file_base_path, $filename)); $download_link = $file_exists ? '<li class="action-view">' . make_download_link($id, '', $filename) . '</li>' : ''; $category = $category ? '<span title="' . htmlspecialchars(fetch_category_title($category, 'file')) . '">' . $category . '</span>' : ''; $tag_url = '?event=tag' . a . 'tag_name=file_download_link' . a . 'id=' . $id . a . 'description=' . urlencode($description) . a . 'filename=' . urlencode($filename); $condition = '<span class="'; $condition .= $file_exists ? 'ok' : 'not-ok'; $condition .= '">'; $condition .= $file_exists ? gTxt('file_status_ok') : gTxt('file_status_missing'); $condition .= '</span>'; $can_edit = has_privs('file.edit') || $author == $txp_user && has_privs('file.edit.own'); echo tr(n . td($id, '', 'id') . td('<ul>' . ($can_edit ? '<li class="action-edit">' . href(gTxt('edit'), $edit_url) . '</li>' : '') . $download_link . '</ul>', 65, 'actions') . td($can_edit ? href(htmlspecialchars($filename), $edit_url) : htmlspecialchars($filename), 125, 'name') . td(htmlspecialchars($title), 90, 'title') . td(htmlspecialchars($description), 150, 'description') . td($category, 90, 'category') . td(n . '<ul>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href, 400, 250); return false;">Textile</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href, 400, 250); return false;">Textpattern</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=xhtml" onclick="popWin(this.href, 400, 250); return false;">XHTML</a></li>' . n . '</ul>', 75, 'tag-build') . td(in_array($status, array_keys($file_statuses)) ? $file_statuses[$status] : '<span class="not-ok">' . gTxt('none') . '</span>', 45, 'status') . td($condition, 45, 'condition') . td($downloads == '0' ? gTxt('none') : $downloads, 25, 'downloads') . ($show_authors ? td('<span title="' . htmlspecialchars(get_author_name($author)) . '">' . htmlspecialchars($author) . '</span>', '', 'author') : '') . td($can_edit ? fInput('checkbox', 'selected[]', $id) : ' ', 10, 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"'); $ctr++; } echo '</tbody>' . n . endTable() . n . '</form>' . n . '<div id="' . $event . '_navigation" class="txp-navigation">' . nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . pageby_form('file', $file_list_pageby) . n . '</div>' . n . '</div>'; } }
function file_list($message = '') { global $file_base_path, $file_statuses, $file_list_pageby, $txp_user, $event; pagetop(gTxt('tab_file'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('file_sort_column', 'filename'); } if ($dir === '') { $dir = get_pref('file_sort_dir', 'asc'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; echo '<h1 class="txp-heading">' . gTxt('tab_file') . '</h1>'; echo '<div id="' . $event . '_control" class="txp-control-panel">'; if (!is_dir($file_base_path) or !is_writeable($file_base_path)) { echo graf(gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), ' class="alert-block warning"'); } elseif (has_privs('file.edit.own')) { $existing_files = get_filenames(); if (count($existing_files) > 0) { echo form(eInput('file') . sInput('file_create') . graf('<label for="file-existing">' . gTxt('existing_file') . '</label>' . sp . selectInput('filename', $existing_files, '', 1, '', 'file-existing') . sp . fInput('submit', '', gTxt('Create')), ' class="existing-file"'), '', '', 'post', '', '', 'assign_file'); } echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); } switch ($sort) { case 'id': $sort_sql = 'id ' . $dir; break; case 'description': $sort_sql = 'description ' . $dir . ', filename desc'; break; case 'category': $sort_sql = 'category ' . $dir . ', filename desc'; break; case 'title': $sort_sql = 'title ' . $dir . ', filename desc'; break; case 'downloads': $sort_sql = 'downloads ' . $dir . ', filename desc'; break; case 'author': $sort_sql = 'author ' . $dir . ', id asc'; break; default: $sort = 'filename'; $sort_sql = 'filename ' . $dir; break; } set_pref('file_sort_column', $sort, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE); set_pref('file_sort_dir', $dir, 'file', PREF_HIDDEN, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit != '') { $verbatim = preg_match('/^"(.*)"$/', $crit, $m); $crit_escaped = doSlash($verbatim ? $m[1] : str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit)); $critsql = $verbatim ? array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "filename = '{$crit_escaped}'", 'title' => "title = '{$crit_escaped}'", 'description' => "description = '{$crit_escaped}'", 'category' => "category = '{$crit_escaped}'", 'author' => "author = '{$crit_escaped}'") : array('id' => "ID in ('" . join("','", do_list($crit_escaped)) . "')", 'filename' => "filename like '%{$crit_escaped}%'", 'title' => "title like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'", 'author' => "author like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $criteria .= callback_event('admin_criteria', 'file_list', 0, $criteria); $total = safe_count('txp_file', "{$criteria}"); if ($total < 1) { if ($criteria != 1) { echo n . file_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>'; } else { echo n . graf(gTxt('no_files_recorded'), ' class="indicator"') . '</div>'; } return; } $limit = max($file_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo file_search_form($crit, $search_method) . '</div>'; $rs = safe_rows_start('*', 'txp_file', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { $show_authors = !has_single_author('txp_file'); echo n . '<div id="' . $event . '_container" class="txp-container">'; echo '<form name="longform" id="files_form" class="multi_edit_form" method="post" action="index.php">' . n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, ('id' == $sort ? "{$dir} " : '') . 'id') . n . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, ('filename' == $sort ? "{$dir} " : '') . 'name') . n . column_head('title', 'title', 'file', true, $switch_dir, $crit, $search_method, ('title' == $sort ? "{$dir} " : '') . 'title') . n . column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method, ('description' == $sort ? "{$dir} " : '') . 'files_detail description') . n . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, ('category' == $sort ? "{$dir} " : '') . 'category') . n . hCell(gTxt('tags'), '', ' class="files_detail tag-build"') . n . hCell(gTxt('status'), '', ' class="status"') . n . hCell(gTxt('condition'), '', ' class="condition"') . n . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, ('downloads' == $sort ? "{$dir} " : '') . 'downloads') . ($show_authors ? n . column_head('author', 'author', 'file', true, $switch_dir, $crit, $search_method, ('author' == $sort ? "{$dir} " : '') . 'author') : '')) . n . '</thead>'; echo '<tbody>'; $validator = new Validator(); while ($a = nextRow($rs)) { extract($a); $filename = sanitizeForFile($filename); $edit_url = '?event=file' . a . 'step=file_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit; $file_exists = file_exists(build_file_path($file_base_path, $filename)); $download_link = $file_exists ? make_download_link($id, $downloads, $filename) : $downloads; $validator->setConstraints(array(new CategoryConstraint($category, array('type' => 'file')))); $vc = $validator->validate() ? '' : ' error'; $category = $category ? '<span title="' . txpspecialchars(fetch_category_title($category, 'file')) . '">' . $category . '</span>' : ''; $tag_url = '?event=tag' . a . 'tag_name=file_download_link' . a . 'id=' . $id . a . 'description=' . urlencode($description) . a . 'filename=' . urlencode($filename); $condition = '<span class="'; $condition .= $file_exists ? 'success' : 'error'; $condition .= '">'; $condition .= $file_exists ? gTxt('file_status_ok') : gTxt('file_status_missing'); $condition .= '</span>'; $can_edit = has_privs('file.edit') || $author == $txp_user && has_privs('file.edit.own'); echo tr(n . td($can_edit ? fInput('checkbox', 'selected[]', $id) : ' ', '', 'multi-edit') . n . td(($can_edit ? href($id, $edit_url, ' title="' . gTxt('edit') . '"') : $id) . ($file_exists ? sp . '<span class="files_detail">[' . make_download_link($id, gTxt('download'), $filename) . ']</span>' : ''), '', 'id') . td($can_edit ? href(txpspecialchars($filename), $edit_url, ' title="' . gTxt('edit') . '"') : txpspecialchars($filename), '', 'name') . td(txpspecialchars($title), '', 'title') . td(txpspecialchars($description), '', 'files_detail description') . td($category, '', 'category' . $vc) . td(n . '<a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href, 400, 250); return false;">Textile</a>' . sp . '|' . sp . '<a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href, 400, 250); return false;">Textpattern</a>' . sp . '|' . sp . '<a target="_blank" href="' . $tag_url . a . 'type=html" onclick="popWin(this.href, 400, 250); return false;">HTML</a>', '', 'files_detail tag-build') . td(in_array($status, array_keys($file_statuses)) ? $file_statuses[$status] : '<span class="error">' . gTxt('none') . '</span>', '', 'status') . td($condition, '', 'condition') . td($download_link, '', 'downloads') . ($show_authors ? td('<span title="' . txpspecialchars(get_author_name($author)) . '">' . txpspecialchars($author) . '</span>', '', 'author') : '')); } echo '</tbody>', n, endTable(), n, '</div>', n, file_multiedit_form($page, $sort, $dir, $crit, $search_method), n, tInput(), n, '</form>', n, graf(toggle_box('files_detail'), ' class="detail-toggle"'), n, '<div id="' . $event . '_navigation" class="txp-navigation">', n, nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit), n, pageby_form('file', $file_list_pageby), n, '</div>', n, '</div>'; } }
function file_list($message = '') { global $txpcfg, $extensions, $file_base_path; pagetop(gTxt('file'), $message); extract($txpcfg); extract(get_prefs()); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if (!is_dir($file_base_path) or !is_writeable($file_base_path)) { echo graf(gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)), ' id="warning"'); } else { $existing_files = get_filenames(); if (count($existing_files) > 0) { echo form(eInput('file') . sInput('file_create') . graf(gTxt('existing_file') . sp . selectInput('filename', $existing_files, '', 1) . sp . fInput('submit', '', gTxt('Create'), 'smallerbox')), 'text-align: center;'); } echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; switch ($sort) { case 'id': $sort_sql = 'id ' . $dir; break; case 'filename': $sort_sql = 'filename ' . $dir; break; case 'description': $sort_sql = 'description ' . $dir . ', filename desc'; break; case 'category': $sort_sql = 'category ' . $dir . ', filename desc'; break; case 'downloads': $sort_sql = 'downloads ' . $dir . ', filename desc'; break; default: $dir = 'desc'; $sort_sql = 'filename ' . $dir; break; } $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit) { $crit_escaped = doSlash($crit); $critsql = array('id' => "id = '{$crit_escaped}'", 'filename' => "filename like '%{$crit_escaped}%'", 'description' => "description like '%{$crit_escaped}%'", 'category' => "category like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $total = safe_count('txp_file', "{$criteria}"); if ($total < 1) { if ($criteria != 1) { echo n . file_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' style="text-align: center;"'); } else { echo n . graf(gTxt('no_files_recorded'), ' style="text-align: center;"'); } return; } $limit = max(@$file_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo file_search_form($crit, $search_method); $rs = safe_rows_start('*', 'txp_file', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { echo startTable('list') . tr(column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method) . td() . column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method) . column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method) . column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method) . hCell(gTxt('tags')) . hCell(gTxt('status')) . column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method) . hCell()); while ($a = nextRow($rs)) { extract($a); $edit_url = '?event=file' . a . 'step=file_edit' . a . 'id=' . $id . a . 'sort=' . $sort . a . 'dir=' . $dir . a . 'page=' . $page . a . 'search_method=' . $search_method . a . 'crit=' . $crit; $file_exists = file_exists(build_file_path($file_base_path, $filename)); $download_link = $file_exists ? '<li>' . make_download_link($id) . '</li>' : ''; $category = $category ? '<span title="' . fetch_category_title($category, 'file') . '">' . $category . '</span>' : ''; $tag_url = '?event=tag' . a . 'tag_name=file_download_link' . a . 'id=' . $id . a . 'description=' . urlencode($description) . a . 'filename=' . urlencode($filename); $status = '<span class="'; $status .= $file_exists ? 'ok' : 'not-ok'; $status .= '">'; $status .= $file_exists ? gTxt('file_status_ok') : gTxt('file_status_missing'); $status .= '</span>'; // does the downloads column exist? if (!isset($downloads)) { // nope, add it safe_alter('txp_file', "ADD downloads INT DEFAULT '0' NOT NULL"); $downloads = 0; } elseif (empty($downloads)) { $downloads = '0'; } echo tr(n . td($id) . td('<ul>' . '<li>' . href(gTxt('edit'), $edit_url) . '</li>' . $download_link . '</ul>', 65) . td(href($filename, $edit_url), 125) . td($description, 150) . td($category, 90) . td(n . '<ul>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textile" onclick="popWin(this.href, 400, 250); return false;">Textile</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=textpattern" onclick="popWin(this.href, 400, 250); return false;">Textpattern</a></li>' . n . t . '<li><a target="_blank" href="' . $tag_url . a . 'type=xhtml" onclick="popWin(this.href, 400, 250); return false;">XHTML</a></li>' . n . '</ul>', 75) . td($status, 45) . td($downloads == '0' ? gTxt('none') : $downloads, 25) . td(dLink('file', 'file_delete', 'id', $id), 10)); } echo endTable() . nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method) . pageby_form('file', $file_list_pageby); } }