예제 #1
0
// Create links
if ($result && !empty($preview_attachments)) {
    global $DB;
    load_class('links/model/_linkcomment.class.php', 'LinkComment');
    $order = 1;
    $FileCache =& get_FileCache();
    $attachments = explode(',', $preview_attachments);
    $final_attachments = explode(',', $checked_attachments);
    $LinkOwner = new LinkComment($Comment);
    $attachment_dir = NULL;
    // No need transaction here, because if one file can't be attached, the rest should be still attached
    foreach ($attachments as $file_ID) {
        // create links between comment and attached files
        if (in_array($file_ID, $final_attachments)) {
            // attachment checkbox was checked, create the link
            $LinkOwner->add_link($file_ID, 'aftermore', $order, false);
            $order++;
        } else {
            // attachment checkbox was not checked, remove unused uploaded file
            $unused_File = $FileCache->get_by_ID($file_ID, false);
            if ($unused_File) {
                if (empty($checked_attachments) && empty($attachment_dir)) {
                    // None of the previously attached file was checked to be attached
                    $attachment_dir = dirname($unused_File->get_full_path()) . '/';
                }
                $unused_File->unlink();
            }
        }
    }
    if (empty($checked_attachments) && !empty($attachment_dir)) {
        // None of the previously attached files were finally attached