예제 #1
0
function CreateDocument($filepath, $ifattach, $id, $module, &$docid)
{
    $adb = PearDatabase::getInstance();
    $current_user = vglobal('current_user');
    $size = filesize($filepath);
    //echo $size;
    require_once 'modules/Documents/Documents.php';
    $obiekt = new Documents();
    ###
    $storage_path = decideFilePath();
    $pelnasciezka = $storage_path . $filepath;
    //echo $pelnasciezka;
    $wynik = $adb->query("select value from vtiger_osspdf_config where name='{$module}' and conf_id = 'GENERALCONFIGURATION'", true);
    $wartosc = $adb->query_result($wynik, 0, "value");
    if ($wartosc == 'default') {
        $assign = $current_user->id;
    } else {
        $assign = $wartosc;
    }
    ### Tworzenie nowego Dokumentu
    $obiekt->column_fields['notes_title'] = getTranslatedString($module, $module) . ' ' . $_REQUEST['file_name'] . ' ' . date("Y-m-d H:i:s");
    $obiekt->column_fields['filename'] = $filepath;
    $obiekt->column_fields['notecontent'] = 'OSSPdf';
    $obiekt->column_fields['folderid'] = '1';
    $obiekt->column_fields['filetype'] = "application/pdf";
    $obiekt->column_fields['filesize'] = $size;
    $obiekt->column_fields['filelocationtype'] = 'I';
    $obiekt->column_fields['filestatus'] = '1';
    $obiekt->column_fields['assigned_user_id'] = $assign;
    ### Zapis Dokumentu
    $obiekt->saveentity("Documents");
    $docid = $obiekt->id;
    $newid = $adb->getUniqueId('vtiger_crmentity');
    ### Dodanie relacji między załacznikiem a dokumentem
    $sql = "INSERT INTO vtiger_seattachmentsrel (`crmid`,`attachmentsid`) VALUES ('{$docid}','{$newid}')";
    //echo $sql;
    $wykonaj = $adb->query($sql, true);
    $date_var = date("Y-m-d H:i:s");
    ### Dodanie wpisu o załączniku
    $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)";
    $params1 = array($newid, $current_user->id, $current_user->id, "Documents Attachment", NULL, $adb->formatDate($date_var, true), $adb->formatDate($date_var, true));
    $adb->pquery($sql1, $params1, true);
    ### Dodanie informacji o załączniku do tabeli attachments
    $sql = "INSERT INTO vtiger_attachments (`attachmentsid`,`name`,`type`,`path`) VALUES ('{$newid}','{$filepath}','application/pdf','{$storage_path}')";
    //echo $sql;
    $wykonaj = $adb->pquery($sql, array(), true);
    ### Przeniesienie pliku do właściwego podkatalogu
    return $docid;
}