+ 0) {
+ // Generate the table using the class.
+ $table_attributes = array(
+ 'id' => 'files_tbl',
+ 'class' => 'footable table',
+ );
+ $table = new \ProjectSend\Classes\TableGenerate($table_attributes);
+
+ /**
+ * Set the conditions to true or false once here to
+ * avoid repetition
+ * They will be used to generate or no certain columns
+ */
+ $conditions = array(
+ 'select_all' => true,
+ 'is_not_client' => (CURRENT_USER_LEVEL != '0') ? true : false,
+ 'can_set_public' => (CURRENT_USER_LEVEL != '0' || current_user_can_upload_public()) ? true : false,
+ 'total_downloads' => (CURRENT_USER_LEVEL != '0' && !isset($search_on)) ? true : false,
+ 'is_search_on' => (isset($search_on)) ? true : false,
+ );
+
+ $thead_columns = array(
+ array(
'select_all' => true,
- 'is_not_client' => (CURRENT_USER_LEVEL != '0') ? true : false,
- 'can_set_public' => (CURRENT_USER_LEVEL != '0' || current_user_can_upload_public()) ? true : false,
- 'total_downloads' => (CURRENT_USER_LEVEL != '0' && !isset($search_on)) ? true : false,
- 'is_search_on' => (isset($search_on)) ? true : false,
- );
+ 'attributes' => array(
+ 'class' => array('td_checkbox'),
+ ),
+ 'condition' => $conditions['select_all'],
+ ),
+ array(
+ 'content' => __('Preview', 'cftp_admin'),
+ 'hide' => 'phone,tablet',
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'timestamp',
+ 'sort_default' => true,
+ 'content' => __('Added on', 'cftp_admin'),
+ 'hide' => 'phone',
+ ),
+ array(
+ 'content' => __('Type', 'cftp_admin'),
+ 'hide' => 'phone,tablet',
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'filename',
+ 'content' => __('Title', 'cftp_admin'),
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'description',
+ 'content' => __('Description', 'cftp_admin'),
+ ),
+ array(
+ 'content' => __('Size', 'cftp_admin'),
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'uploader',
+ 'content' => __('Uploader', 'cftp_admin'),
+ 'hide' => 'phone,tablet',
+ 'condition' => $conditions['is_not_client'],
+ ),
+ array(
+ 'content' => __('Assigned', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => ($conditions['is_not_client'] && !$conditions['is_search_on']),
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'public_allow',
+ 'content' => __('Public permissions', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => $conditions['can_set_public'],
+ ),
+ array(
+ 'content' => __('Expiry', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => $conditions['is_not_client'],
+ ),
+ array(
+ 'content' => __('Status', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => $conditions['is_search_on'],
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'download_count',
+ 'content' => __('Download count', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => $conditions['is_search_on'],
+ ),
+ array(
+ 'sortable' => true,
+ 'sort_url' => 'download_count',
+ 'content' => __('Total downloads', 'cftp_admin'),
+ 'hide' => 'phone',
+ 'condition' => $conditions['total_downloads'],
+ ),
+ array(
+ 'content' => __('Actions', 'cftp_admin'),
+ 'hide' => 'phone',
+ ),
+ );
+
+ $table->thead($thead_columns);
+
+ $sql->setFetchMode(PDO::FETCH_ASSOC);
+ while ($row = $sql->fetch()) {
+ $table->addRow();
+ $file = new \ProjectSend\Classes\Files();
+ $file->get($row['id']);
+
+ // Visibility is only available when filtering by client or group.
+ $assignations = get_file_assignations($file->id);
+
+ $count_assignations = 0;
+ if (!empty($assignations['clients'])) {
+ $count_assignations += count($assignations['clients']);
+ }
+ if (!empty($assignations['groups'])) {
+ $count_assignations += count($assignations['groups']);
+ }
+
+ switch ($results_type) {
+ case 'client':
+ $hidden = $assignations['clients'][$this_id]['hidden'];
+ break;
+ case 'group':
+ $hidden = $assignations['groups'][$this_id]['hidden'];
+ break;
+ }
+
+ // Preview
+ $preview_cell = '';
+ if ($file->embeddable) {
+ $preview_cell = '
' . __('Preview', 'cftp_admin') . ' ';
+ }
+ if (file_is_image($file->full_path)) {
+ $thumbnail = make_thumbnail($file->full_path, null, 50, 50);
+ if (!empty($thumbnail['thumbnail']['url'])) {
+ $preview_cell = '
+
+ ';
+ }
+ }
+
+ // Is file assigned?
+ $assigned_class = ($count_assignations == 0) ? 'danger' : 'success';
+ $assigned_status = ($count_assignations == 0) ? __('No', 'cftp_admin') : __('Yes', 'cftp_admin');
+
+ // Visibility
+ if ($file->isPublic()) {
+ $visibility_link = '
' . __('Download', 'cftp_admin') . ' ';
+ } else {
+ if (get_option('enable_landing_for_all_files') == '1') {
+ $visibility_link = '
' . __('View information', 'cftp_admin') . ' ';
+ } else {
+ $visibility_link = '
' . __('None', 'cftp_admin') . ' ';
+ }
+ }
+
+ // Expiration
+ if ($file->expires == '0') {
+ $expires_button = 'success';
+ $expires_label = __('Does not expire', 'cftp_admin');
+ } else {
+ $expires_date = date(get_option('timeformat'), strtotime($file->expiry_date));
+
+ if ($file->expired == true) {
+ $expires_button = 'danger';
+ $expires_label = __('Expired on', 'cftp_admin') . ' ' . $expires_date;
+ } else {
+ $expires_button = 'info';
+ $expires_label = __('Expires on', 'cftp_admin') . ' ' . $expires_date;
+ }
+ }
+
+ // Visibility
+ $status_class = '';
+ $status_label = '';
+ if (isset($search_on)) {
+ $status_class = ($hidden == 1) ? 'danger' : 'success';
+ $status_label = ($hidden == 1) ? __('Hidden', 'cftp_admin') : __('Visible', 'cftp_admin');
+ }
+
+ // Download count when filtering by group or client
+ if (isset($search_on)) {
+ $download_count_content = $row['download_count'] . ' ' . __('times', 'cftp_admin');
+
+ switch ($results_type) {
+ case 'client':
+ break;
+ case 'group':
+ case 'category':
+ $download_count_class = ($row['download_count'] > 0) ? 'downloaders btn-primary' : 'btn-pslight disabled';
+ $download_count_content = '
' . $download_count_content . ' ';
+ break;
+ }
+ }
+
+ // Download count and link on the unfiltered files table no specific client or group selected)
+ if (!isset($search_on)) {
+ if (CURRENT_USER_LEVEL != '0') {
+ if ($row["download_count"] > 0) {
+ $btn_class = 'downloaders btn-primary';
+ } else {
+ $btn_class = 'btn-pslight disabled';
+ }
+
+ $downloads_table_link = '
' . $row["download_count"] . ' ' . __('downloads', 'cftp_admin') . ' ';
+ }
+ }
- $thead_columns = array(
+ //* Add the cells to the row
+ $tbody_cells = array(
array(
- 'select_all' => true,
- 'attributes' => array(
- 'class' => array('td_checkbox'),
- ),
+ 'checkbox' => true,
+ 'value' => $file->id,
'condition' => $conditions['select_all'],
),
array(
- 'content' => __('Preview', 'cftp_admin'),
- 'hide' => 'phone,tablet',
+ 'content' => $preview_cell,
),
array(
- 'sortable' => true,
- 'sort_url' => 'timestamp',
- 'sort_default' => true,
- 'content' => __('Added on', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => format_date($file->uploaded_date),
),
array(
- 'content' => __('Type', 'cftp_admin'),
- 'hide' => 'phone,tablet',
+ 'content' => $file->extension,
),
array(
- 'sortable' => true,
- 'sort_url' => 'filename',
- 'content' => __('Title', 'cftp_admin'),
+ 'attributes' => array(
+ 'class' => array('file_name'),
+ ),
+ 'content' => '
' . $file->title . ' ',
),
array(
- 'sortable' => true,
- 'sort_url' => 'description',
- 'content' => __('Description', 'cftp_admin'),
+ 'content' => $file->description,
),
array(
- 'content' => __('Size', 'cftp_admin'),
+ 'content' => $file->size_formatted,
),
array(
- 'sortable' => true,
- 'sort_url' => 'uploader',
- 'content' => __('Uploader', 'cftp_admin'),
- 'hide' => 'phone,tablet',
+ 'content' => $file->uploaded_by,
'condition' => $conditions['is_not_client'],
),
array(
- 'content' => __('Assigned', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => '
' . $assigned_status . ' ',
'condition' => ($conditions['is_not_client'] && !$conditions['is_search_on']),
),
array(
- 'sortable' => true,
- 'sort_url' => 'public_allow',
- 'content' => __('Public permissions', 'cftp_admin'),
- 'hide' => 'phone',
+ 'attributes' => array(
+ 'class' => array('col_visibility'),
+ ),
+ 'content' => $visibility_link,
'condition' => $conditions['can_set_public'],
),
array(
- 'content' => __('Expiry', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => '
' . $expires_label . ' ',
'condition' => $conditions['is_not_client'],
),
array(
- 'content' => __('Status', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => '
' . $status_label . ' ',
'condition' => $conditions['is_search_on'],
),
array(
- 'sortable' => true,
- 'sort_url' => 'download_count',
- 'content' => __('Download count', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => (!empty($download_count_content)) ? $download_count_content : false,
'condition' => $conditions['is_search_on'],
),
array(
- 'sortable' => true,
- 'sort_url' => 'download_count',
- 'content' => __('Total downloads', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => (!empty($downloads_table_link)) ? $downloads_table_link : false,
'condition' => $conditions['total_downloads'],
),
array(
- 'content' => __('Actions', 'cftp_admin'),
- 'hide' => 'phone',
+ 'content' => '
' . __('Edit', 'cftp_admin') . ' ',
),
);
- $table->thead($thead_columns);
-
- $sql->setFetchMode(PDO::FETCH_ASSOC);
- while ($row = $sql->fetch()) {
- $table->addRow();
- $file = new \ProjectSend\Classes\Files();
- $file->get($row['id']);
-
- // Visibility is only available when filtering by client or group.
- $assignations = get_file_assignations($file->id);
-
- $count_assignations = 0;
- if (!empty($assignations['clients'])) {
- $count_assignations += count($assignations['clients']);
- }
- if (!empty($assignations['groups'])) {
- $count_assignations += count($assignations['groups']);
- }
-
- switch ($results_type) {
- case 'client':
- $hidden = $assignations['clients'][$this_id]['hidden'];
- break;
- case 'group':
- $hidden = $assignations['groups'][$this_id]['hidden'];
- break;
- }
-
- // Preview
- $preview_cell = '';
- if ($file->embeddable) {
- $preview_cell = '
' . __('Preview', 'cftp_admin') . ' ';
- }
- if (file_is_image($file->full_path)) {
- $thumbnail = make_thumbnail($file->full_path, null, 50, 50);
- if (!empty($thumbnail['thumbnail']['url'])) {
- $preview_cell = '
-
- ';
- }
- }
-
- // Is file assigned?
- $assigned_class = ($count_assignations == 0) ? 'danger' : 'success';
- $assigned_status = ($count_assignations == 0) ? __('No', 'cftp_admin') : __('Yes', 'cftp_admin');
-
- // Visibility
- if ($file->isPublic()) {
- $visibility_link = '
' . __('Download', 'cftp_admin') . ' ';
- } else {
- if (get_option('enable_landing_for_all_files') == '1') {
- $visibility_link = '
' . __('View information', 'cftp_admin') . ' ';
- } else {
- $visibility_link = '
' . __('None', 'cftp_admin') . ' ';
- }
- }
-
- // Expiration
- if ($file->expires == '0') {
- $expires_button = 'success';
- $expires_label = __('Does not expire', 'cftp_admin');
- } else {
- $expires_date = date(get_option('timeformat'), strtotime($file->expiry_date));
-
- if ($file->expired == true) {
- $expires_button = 'danger';
- $expires_label = __('Expired on', 'cftp_admin') . ' ' . $expires_date;
- } else {
- $expires_button = 'info';
- $expires_label = __('Expires on', 'cftp_admin') . ' ' . $expires_date;
- }
- }
-
- // Visibility
- $status_class = '';
- $status_label = '';
- if (isset($search_on)) {
- $status_class = ($hidden == 1) ? 'danger' : 'success';
- $status_label = ($hidden == 1) ? __('Hidden', 'cftp_admin') : __('Visible', 'cftp_admin');
- }
-
- // Download count when filtering by group or client
- if (isset($search_on)) {
- $download_count_content = $row['download_count'] . ' ' . __('times', 'cftp_admin');
-
- switch ($results_type) {
- case 'client':
- break;
- case 'group':
- case 'category':
- $download_count_class = ($row['download_count'] > 0) ? 'downloaders btn-primary' : 'btn-pslight disabled';
- $download_count_content = '
' . $download_count_content . ' ';
- break;
- }
- }
-
- // Download count and link on the unfiltered files table no specific client or group selected)
- if (!isset($search_on)) {
- if (CURRENT_USER_LEVEL != '0') {
- if ($row["download_count"] > 0) {
- $btn_class = 'downloaders btn-primary';
- } else {
- $btn_class = 'btn-pslight disabled';
- }
-
- $downloads_table_link = '
' . $row["download_count"] . ' ' . __('downloads', 'cftp_admin') . ' ';
- }
- }
-
- //* Add the cells to the row
- $tbody_cells = array(
- array(
- 'checkbox' => true,
- 'value' => $file->id,
- 'condition' => $conditions['select_all'],
- ),
- array(
- 'content' => $preview_cell,
- ),
- array(
- 'content' => format_date($file->uploaded_date),
- ),
- array(
- 'content' => $file->extension,
- ),
- array(
- 'attributes' => array(
- 'class' => array('file_name'),
- ),
- 'content' => '
' . $file->title . ' ',
- ),
- array(
- 'content' => $file->description,
- ),
- array(
- 'content' => $file->size_formatted,
- ),
- array(
- 'content' => $file->uploaded_by,
- 'condition' => $conditions['is_not_client'],
- ),
- array(
- 'content' => '
' . $assigned_status . ' ',
- 'condition' => ($conditions['is_not_client'] && !$conditions['is_search_on']),
- ),
- array(
- 'attributes' => array(
- 'class' => array('col_visibility'),
- ),
- 'content' => $visibility_link,
- 'condition' => $conditions['can_set_public'],
- ),
- array(
- 'content' => '
' . $expires_label . ' ',
- 'condition' => $conditions['is_not_client'],
- ),
- array(
- 'content' => '
' . $status_label . ' ',
- 'condition' => $conditions['is_search_on'],
- ),
- array(
- 'content' => (!empty($download_count_content)) ? $download_count_content : false,
- 'condition' => $conditions['is_search_on'],
- ),
- array(
- 'content' => (!empty($downloads_table_link)) ? $downloads_table_link : false,
- 'condition' => $conditions['total_downloads'],
- ),
- array(
- 'content' => '
' . __('Edit', 'cftp_admin') . ' ',
- ),
- );
-
- foreach ($tbody_cells as $cell) {
- $table->addCell($cell);
- }
-
- $table->end_row();
+ foreach ($tbody_cells as $cell) {
+ $table->addCell($cell);
}
- echo $table->render();
+ $table->end_row();
}
- ?>
-