function ppd_process_files(&$files) { if (empty($files) || !is_array($files)) { return array(); } foreach ($files as $key => $file) { $_real_path = ppd_check_path($file['filename']); if (empty($_real_path)) { unset($files[$key]); continue; } $files[$key]['size'] = ppd_convertfrom_bytes($file['size']); $files[$key]['fileicon'] = ppd_get_url_fileicon($file['fileicon']); } return $files; }
function ppd_clean($product_id) { global $available_fields, $smarty, $tables, $top_message; $product_id = (int) $product_id; if ($_SERVER['REQUEST_METHOD'] != 'POST') { ppd_redirect($product_id); } $files = cw_query('SELECT `file_id`, `filename` FROM ' . $tables['ppd_files'] . ' WHERE `product_id` = \'' . $product_id . '\''); if (empty($files) || !is_array($files)) { ppd_redirect($product_id); } $product_id_condition = 'product_id = \'' . $product_id . '\' AND '; foreach ($files as $key => $file) { $_real_path = ppd_check_path($file['filename']); if (empty($_real_path)) { $to_delete[] = $file['file_id']; } } if (!empty($to_delete) && is_array($to_delete)) { $files_ids_query = implode('\', \'', $to_delete); db_query('DELETE FROM ' . $tables['ppd_files'] . ' WHERE ' . $product_id_condition . 'file_id IN (\'' . $files_ids_query . '\')'); } $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_updated_succes'), 'type' => 'I'); ppd_redirect($product_id); }
$counter_query_param = ' AND dloads.allowed_number > dloads.counter'; } $file_info = cw_query_first('SELECT files.filename, files.title, files.size, types.type, dloads.download_id FROM ' . $tables['ppd_files'] . ' AS files LEFT JOIN ' . $tables['ppd_downloads'] . ' AS dloads ON files.file_id = dloads.file_id LEFT JOIN ' . $tables['ppd_types'] . ' AS types ON files.type_id = types.type_id WHERE files.file_id = \'' . $file_id . '\' AND dloads.product_id = \'' . $product_id . '\' AND files.active = 1 AND files.perms_owner = 5 AND files.perms_all = 0 AND dloads.customer_id = \'' . $customer_id . '\'' . $counter_query_param . $time_query_param); } if (empty($file_info) || !is_array($file_info)) { $file_info = cw_query_first('SELECT filename, title, size, type FROM ' . $tables['ppd_files'] . ' AS files LEFT JOIN ' . $tables['ppd_types'] . ' AS types ON files.type_id = types.type_id WHERE file_id = \'' . $file_id . '\' AND product_id = \'' . $product_id . '\' AND active = 1 AND perms_all = 5'); } if (empty($file_info) || !is_array($file_info)) { cw_header_location("index.php?target=product&product_id={$product_id}"); } if (empty($file_info['type'])) { $file_info['type'] = 'application/octet-stream'; //application/force-download } //$file = ppd_get_url_tofile($file_info['filename']); $file = ppd_check_path($file_info['filename']); if (empty($file)) { cw_header_location("index.php?target=product&product_id={$product_id}"); } else { if (isset($file_info['download_id'])) { db_query('UPDATE ' . $tables['ppd_downloads'] . ' SET counter = counter + 1 WHERE download_id = \'' . $file_info['download_id'] . '\''); } $_data = array(); $_data['file_id'] = $file_id; $_data['product_id'] = $product_id; $_data['period'] = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $_data['counter'] = cw_query_first_cell('SELECT counter FROM ' . $tables['ppd_stats'] . ' WHERE file_id = \'' . $file_id . '\' AND product_id = \'' . $product_id . '\' AND period = \'' . $_data['period'] . '\''); if (empty($_data['counter'])) { $_data['counter'] = 1; cw_array2insert($tables['ppd_stats'], $_data); } else {