Loading

[0.6.0.] files and folders

Get help with problems, or report & discuss bugs in Collabtive

[0.6.0.] files and folders

Postby avychodil » 11.09.2009, 20:26

By default the folders are physically created in root directory independently on parent directory defined in the database. The problem is that you cannot download folder with sub-directories. If you want to have directory structure corresponded with database structure you have to change these two functions in class.datei.php. Furthermore you have to add column to the projectfolders table in the mysql database which will call datei (varchar 255, not allow nulls, without key and default value: "")

Code: Select all
    function addFolder($parent, $project, $folder, $desc, $visible = "")
    {
        $project = (int) $project;
        $folder = mysql_real_escape_string($folder);
        $desc = mysql_real_escape_string($desc);
//        $folder = str_replace("ä", "ae" , $folder);
//        $folder = str_replace("ö", "oe" , $folder);
//        $folder = str_replace("ü", "ue" , $folder);
//        $folder = str_replace("ß", "ss" , $folder);
        // remove whitespace
/*        $folder = preg_replace("/\W/", "", $folder); */
/*        $folder = preg_replace("/[^-_0-9a-zA-Z]/", "_", $folder); */
        // insert the folder into the db
//        $ins = mysql_query("INSERT INTO projectfolders (parent,project,name,description,visible) VALUES ($parent,$project,'$folder','$desc','$visstr')");
$path = mysql_fetch_array(mysql_query("SELECT datei FROM projectfolders WHERE ID = $parent"));
if (!empty($path))
{
$datei=$path["datei"] . "/$folder";
} else
{
$datei="$folder";
}
        $makefolder = CL_ROOT . "/files/" . CL_CONFIG . $datei;
        $ins = mysql_query("INSERT INTO projectfolders (`parent`,`project`,`name`,`description`,`visible`, `datei`) VALUES ($parent,$project,'$folder','$desc','$visible', '$datei')");
        if ($ins)
        {
            // create the folder
//            echo(CL_ROOT . "/files/" . CL_CONFIG . "/$project/" . $datei . "/");
            $makefolder = CL_ROOT . "/files/" . CL_CONFIG . "/$project/" . $datei . "/";
            if (!file_exists($makefolder))
            {
                if (mkdir($makefolder, 0777))
                {
                    // folder created return true
                    return true;
                }
            }
            else
            {
                // folder already existed, return false
                return false;
            }
        }
        else
        {
            // folder wasnt created , return false
            return false;
        }
    }
    /**
     * Delete a folder
     * Deletes the given folder with all files in it and all of its subfolders.
     *
     * @param int $id folder id
     * @param int $id project id
     * @return bool
     */
    function deleteFolder($id, $project)
    {
        $id = (int) $id;
        $folder = $this->getFolder($id);
        $files = $this->getProjectFiles($project, 10000, $id);
        // delete all the files in the folder from the database (and filesystem as well)
        foreach($files as $file)
        {
            $this->loeschen($file["ID"]);
        }
        if (!empty($folder["subfolders"]))
        {
            foreach($folder["subfolders"] as $sub)
            {
                $this->deleteFolder($sub["ID"], $sub["project"]);
            }
        }
       
        if ($folder["datei"] <> "") {
         $del = mysql_query("DELETE FROM projectfolders WHERE ID = $id");
        //remove directory
         $foldstr = CL_ROOT . "/files/" . CL_CONFIG . "/$project/" . $folder["datei"] . "/";
         delete_directory($foldstr);}
        else {
        return false;}
        return true;
    }


In managefile.php change function folderexport like this:

Code: Select all
elseif ($action == "folderexport")
{
    $thefolder = $myfile->getFolder($thisfile);
    $topfad = CL_ROOT . "/files/" . CL_CONFIG .  "/temp/" . $thefolder["name"] . ".zip";
    $zip = new PclZip($topfad);
    if (file_exists($topfad))
    {
        if (unlink($topfad))
        {
            $create = $zip->create(CL_ROOT . "/files/" . CL_CONFIG . "/$id/$thefolder[datei]/", PCLZIP_OPT_REMOVE_PATH, CL_ROOT . "/files/" . CL_CONFIG . "/$id");
        }
    }
    else
    {
        $create = $zip->create(CL_ROOT . "/files/" . CL_CONFIG . "/$id/$thefolder[datei]/", PCLZIP_OPT_REMOVE_PATH, CL_ROOT . "/files/" . CL_CONFIG . "/$id");
    }
    if ($create != 0)
    {
        $loc = $url . "/files/" . CL_CONFIG . "/temp/" . $thefolder["name"] . ".zip";
        header("Location: $loc");
    }


in upload replace in line 55 name - datei
add folder name temp in standard directory for temporary files that are uploaded - don't forget to set up rights for it

in addfileform.tpl change line 31:

Code: Select all
 <option value = "{$allfolders[fold].ID}">/{$allfolders[fold].datei}</option>

in addfolder.tpl change line 9

Code: Select all
 <option value = "{$allfolders[fold].ID}">/{$allfolders[fold].datei}</option>


The folders have to correspond with the messages witch use files from file-system and even save files into the file-system. So is necessary change some files that operates with messages to be able attach files:


Change managemessage.php

add to the declaration (24)

Code: Select all
$upfolder = getArrayVal($_POST, "upfolder"); 


in action add change these lines (78):

Code: Select all
        if ($thefiles > 0)
        {
            // if upload files are set, upload and attach
            $msg->attachFile($thefiles, $themsg, $id, $upfolder);
        } elseif ($thefiles == 0 and $numfiles > 0)
        {
            // else just attach existing file
            $msg->attachFile(0, $themsg, $id, $upfolder);
        }


add these lines (299) into showproject action:
Code: Select all
    $myfile = new datei();
    $allfolders = $myfile->getAllProjectFolders($id);
    $template->assign("allfolders", $allfolders);


in file addmessageform.tpl add these lines (65) for choose path where the files will be

Code: Select all
<div class = "row">

<label for = "upfolder">{#folder#}:</label>
<select name = "upfolder" id = "upfolder">
<option value = "">{#rootdir#}</option>
{section name=fold loop=$allfolders}
<option value = "{$allfolders[fold].ID}">/{$allfolders[fold].datei}</option>
{/section}
</select>
</div>


There is a problem with attachment show in message. You have to change action showmessage in managemessage.php like:

Code: Select all
$ordner = $message["files"];


in the same section add these lines to correctly show data in attach and assing files:

Code: Select all
    $myfile = new datei();
    $allfolders = $myfile->getAllProjectFolders($id);
    $template->assign("allfolders", $allfolders);
    $thefiles = $myfile->getAllProjectFiles($id);
    $template->assign("files", $thefiles);


in header change declaration of $thefiles

Code: Select all
$thefiles = getArrayVal($_POST, "thefiles");



And finally change some code to be able work with assigned files in message

change line 34 in addmessageform.tpl

Code: Select all
<option value = "{$files[file].ID}">{$files[file].path}/{$files[file].name}</option>


in class.datei.php change sql query in function getfile() line 428

   
Code: Select all
     $sel = mysql_query("SELECT *, (SELECT datei FROM projectfolders WHERE files.folder = projectfolders.id) AS path  FROM files WHERE ID=$id");


in managemessage.php replace all instances of getprojectfiles -> getAllProjectFiles

change actions reply and replyform in managemessage.php

Code: Select all
} elseif ($action == "replyform")
{
    // check if the user is allowed to add messages
    if (!$userpermissions["messages"]["add"])
    {
        $errtxt = $langfile["nopermission"];
        $noperm = $langfile["accessdenied"];
        $template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
        $template->display("error.tpl");
        die();
    }
    $title = $langfile['reply'];
    $template->assign("title", $title);
   
    $myfile = new datei();
    $allfolders = $myfile->getAllProjectFolders($id);
    $template->assign("allfolders", $allfolders);
   
    $thefiles = $myfile->getAllProjectFiles($id);
    $message = $msg->getMessage($mid);
    $template->assign("message", $message);
    $template->assign("files", $thefiles);
    $template->display("replyform.tpl");
} elseif ($action == "reply")
{
    // check if the user is allowed to edit messages
    if (!$userpermissions["messages"]["add"])
    {
        $errtxt = $langfile["nopermission"];
        $noperm = $langfile["accessdenied"];
        $template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
        $template->display("error.tpl");
        die();
    }

    $tagobj = new tags();
    $tags = $tagobj->formatInputTags($tags);
    $themsg = $msg->add($id, $title, $message, $tags, $userid, $username, $mid_post);
    if ($themsg)
    {
        if ($thefiles > 0)
        {
            $msg->attachFile($thefiles, $themsg, $id, $upfolder);
        } elseif ($thefiles == 0 and $numfiles > 0)
        {
            $msg->attachFile(0, $themsg, $id, $upfolder);
        }
        $loc = $url . "managemessage.php?action=showmessage&mid=$mid_post&id=$id&mode=replied";
        header("Location: $loc");
    }



add to replyform.tpl to the add section line 80

Code: Select all
<div class = "row">
<label for = "upfolder">{#folder#}:</label>
<select name = "upfolder" id = "upfolder">
<option value = "">{#rootdir#}</option>
{section name=fold loop=$allfolders}
<option value = "{$allfolders[fold].ID}">/{$allfolders[fold].datei}</option>
{/section}
</select>
</div>


in the same file change attach section

Code: Select all
{*Attach*}
<div id = "files-attach" class="blinded" style = "display:none;clear:both;">

    <div class="row">
<label for = "thefiles">{#attachfile#}</label>
<select name = "thefiles" id = "thefiles">
<option value = "0">{#chooseone#}</option>
{section name = file loop=$files}
<option value = "{$files[file].ID}">{$files[file].path}/{$files[file].name}</option>
{/section}
{section name = file loop=$myprojects[project].files}
<option value = "{$myprojects[project].files[file].ID}">{$myprojects[project].files[file].name}</option>
{/section}
</select>
</div>

</div>
avychodil
 
Posts: 13
Joined: 07.07.2009, 22:47

Return to Problems and Bugs

Who is online

Users browsing this forum: No registered users

cron