Displaying Private And Public Files

Use GitHub to post bug reports and error descriptions for phpwcms. Describe your problem detailed!
Locked
Shrike71
Posts: 14
Joined: Fri 28. Nov 2003, 16:26

Displaying Private And Public Files

Post by Shrike71 »

Hi All,

I'm not sure if this has been treated before, but here's my 2 cents worth and a fix to the problem, too. If this has been fixed in the upcoming version 2 then disregard it.

When using/appending images in article creation, the image browser would only show files and folders marked as PUBLIC; which meant that if i wanted to use a file which i though that i would "partition" as private i would have to place it in a folder marked "public" and mark the image itself as "public". From a content grouping point of view i found this to be a bit pointless, so i had a look at image_browser.php and noticed that there had been an incomplete attempt to do this before. Below, i've listed the changes you need to make to get this effect.

Now, when you click on the image browser, it will display ALL folders and images marked as PUBLIC, and your OWN folders and images marked as PRIVATE


The main changes involve the reconstruction of the SQL statements fetching the folders and images:


First, we fix the image query as this is easiest. Find the query in image browser that looks like this (it's around line 171):

//Tabelle
echo "<table bgColor=\"#FFFFFF\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
$file_sql = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE f_pid=".$_SESSION["imgdir"]." AND ";
switch($js_aktion) {
case 2: $file_sql .= "(f_ext='aif' OR f_ext='aiff' OR f_ext='mov' OR f_ext='movie' OR f_ext='mp3' OR f_ext='mpeg' OR f_ext='mpeg4' OR ";
$file_sql .= "f_ext='mpeg2' OR f_ext='wav' OR f_ext='swf' OR f_ext='ram' OR f_ext='ra' OR f_ext='wma' OR f_ext='wmv' OR ";
$file_sql .= "f_ext='avi' OR f_ext='au' OR f_ext='midi' OR f_ext='moov' OR f_ext='rm' OR f_ext='rpm' OR f_ext='mid' OR f_ext='midi') ";
break;

default: $file_sql .= "f_thumb_preview<>'' "; //JS_AKTION: 0, 1 or 3
}
//$file_sql .= "AND f_uid=".$_SESSION["wcs_user_id"];
$file_sql .= " AND f_public=1 AND f_aktiv=1";
$file_sql .= " AND f_kid=1 AND f_trash=0 ORDER BY f_name;";

notice that commented //$file_sql .= "AND f_uid=".$_SESSION["wcs_user_id"]; ?

You need to uncomment it and change that, AND the line after it to :

$file_sql .= " AND ((f_uid=".$_SESSION["wcs_user_id"]." AND f_aktiv=1) ";
$file_sql .= " OR (f_public=1 AND f_aktiv=1))";


Doing the same thing for folders is a little more complex:

First, uncomment the older folder_list function with the $userID at the end and comment out the newer one after it (around line 240).


From this:

//function folder_list($pid, $dbcon, $vor, $zieldatei, $userID) {
function folder_list($pid, $dbcon, $vor, $zieldatei) {


To this:

function folder_list($pid, $dbcon, $vor, $zieldatei, $userID) {
//function folder_list($pid, $dbcon, $vor, $zieldatei) {


Then, in the function change the second line of the query (around line 248)

From:

"f_pid=".intval($pid)." AND f_public=1 AND f_aktiv=1 AND ".

To:

"f_pid=".intval($pid)." AND ((f_public=1 AND f_aktiv=1) OR (f_uid=".intval($userID)." AND f_aktiv=1)) AND ".

The function is recursive, and the $userID is required, so at about line 287, make sure the function call looks like this:

if(!$folder_status && $count_wert) {
folder_list($row["f_id"], $dbcon, $vor+18, $zieldatei, $userID);
}


Finally, we need to make the initial call to folder_list(), supplying the userID of the currently logged in user, so at about line 159, change

From:

if(!$folder_status && $count_wert) {
//folder_list(0, $db, 18, "browser_image.php?opt=".$js_aktion."&", $_SESSION["wcs_user_id"], $cutID);
folder_list(0, $db, 18, "browser_image.php?opt=".$js_aktion."&");

}

To:

if(!$folder_status && $count_wert) {
folder_list(0, $db, 18, "browser_image.php?opt=".$js_aktion."&", $_SESSION["wcs_user_id"], $_SESSION["wcs_user_id"]);
//folder_list(0, $db, 18, "browser_image.php?opt=".$js_aktion."&");

}


Hope this is useful!

Regards,

Shrike71
Locked