Example #1
0
        break;
    case "move_process":
        moveDocumentProcess($cid);
        break;
    case "copy_form":
        copyDocumentForm($cid);
        break;
    case "copy_process":
        copyDocumentProcess($cid);
        break;
    case "remove":
        removeDocument($cid);
        break;
    case "apply":
    case "save":
        saveDocument();
        break;
    case "cancel":
        cancelDocument();
        break;
    case "download":
        $bid = JRequest::getInt('bid', 0);
        downloadDocument($bid);
        break;
    case "show":
    default:
        showDocuments($pend, $sort, 0);
}
function showDocuments($pend, $sort, $view_type)
{
    global $_DOCMAN;
     break;
 case "doc_view":
     require_once $_DOCMAN->getPath('includes_f', 'download');
     showDocumentView($gid);
     JRequest::setVar('tmpl', 'component');
     break;
     //maintain operations
 //maintain operations
 case "doc_edit":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     showDocumentEdit($gid, $script);
     break;
 case "doc_save":
 case "save":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     saveDocument(JRequest::getInt('gid'));
     // use jrequest, so we don't accidentally use the category id [#102]
     break;
 case "doc_cancel":
 case "cancel":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     cancelDocument($gid);
     break;
 case "doc_move":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     showDocumentMove($gid);
     break;
 case "doc_move_process":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     moveDocumentProcess($gid);
     break;
Example #3
0
     break;
 case "doc_view":
     require_once $_DOCMAN->getPath('includes_f', 'download');
     showDocumentView($gid);
     JRequest::setVar('tmpl', 'component');
     break;
     //maintain operations
 //maintain operations
 case "doc_edit":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     showDocumentEdit($gid, $script);
     break;
 case "doc_save":
 case "save":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     saveDocument($gid);
     break;
 case "doc_cancel":
 case "cancel":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     cancelDocument($gid);
     break;
 case "doc_move":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     showDocumentMove($gid);
     break;
 case "doc_move_process":
     require_once $_DOCMAN->getPath('includes_f', 'documents');
     moveDocumentProcess($gid);
     break;
 case "doc_checkin":
function render_beleg_pdf($contact_id, $address, $total, $items, $from_date, $to_date, $comment)
{
    global $civicrm_root;
    $docs = get_docs_table();
    $config = CRM_Core_Config::singleton(true, true);
    /* If receipts already exist for a date range overlapping the requested range, readjust the from date for the new receipt to follow the lastest date for which receipts were already generated. */
    $query = "SELECT GREATEST(MAX(DATE_ADD({$docs['field_to']}, INTERVAL 1 DAY)), '{$from_date}' ) AS from_date\n              FROM {$docs['table']}\n             WHERE entity_id = {$contact_id}\n               AND {$docs['field_from']} < '{$to_date}'    -- Ignore existing receipts for a date range beginning after the end of the requested range.\n           ";
    $from_ts = strtotime($from_date);
    $to_ts = strtotime($to_date);
    $res = CRM_Core_DAO::executeQuery($query);
    $res->fetch();
    if ($res->from_date) {
        $from_date = $res->from_date;
    }
    $from_ts = strtotime($from_date);
    $to_ts = strtotime($to_date);
    $template = CRM_Core_Smarty::singleton();
    list($html, $page_format) = get_template();
    // select and set up template type
    if (count($items) > 1) {
        // more than one payment -> "Sammelbescheinigung" with itemized list
        $item_table = array();
        foreach ($items as $item) {
            $item_table[] = array('date' => date("j.n.Y", strtotime($item["date"])), 'art' => $item["art"], 'amount' => number_format($item["amount"], 2, ',', '.'), 'amounttext' => num_to_text($item["amount"]));
        }
        $template->assign("items", $item_table);
    } else {
        // one payment only -> "Einzelbescheinigung"
        $template->assign("items", null);
        /* When generating multiple receipts in a batch (Jahresbescheinigungen), the smarty object is reused between the individual receipts (singleton) -- so need to reset this explicitly! */
        $template->assign("date", date("d.m.Y", strtotime($items[0]["date"])));
    }
    // fill further template fields
    if (date("m-d", $from_ts) == "01-01" && date("m-d", $to_ts) == "12-31") {
        $daterange = date("Y", $from_ts);
    } else {
        $daterange = date("j.n.", $from_ts) . " bis " . date("j.n.Y", $to_ts);
    }
    $template->assign("daterange", $daterange);
    $template->assign("donor", $address);
    $template->assign("total", number_format($total, 2, ',', '.'));
    $template->assign("totaltext", num_to_text($total));
    $template->assign("today", date("j.n.Y", time()));
    if (date("m-d", $from_ts) == "01-01" && date("m-d", $to_ts) == "12-31") {
        $rangespec = date("Y", $from_ts);
    } else {
        $rangespec = date("Y-m-d", $from_ts) . "_" . date("m-d", $to_ts);
    }
    $domain = CRM_Core_BAO_Domain::getDomain();
    $domain_tokens = array();
    foreach (array('name', 'address') as $token) {
        $domain_tokens[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain, true, true);
    }
    $domain_tokens['address'] = str_replace('> <', '>&nbsp;<', $domain_tokens['address']);
    /* Hack to work around (yet another) bug in dompdf... */
    $template->assign('organisation', $domain_tokens);
    $html = $template->fetch("string:{$html}");
    // set up file names
    $basename = CRM_Utils_File::makeFileName("Zuwendungen_" . $rangespec . "_" . $contact_id . ".pdf");
    $outfile = $config->customFileUploadDir;
    $outfile .= "/{$basename}";
    // render PDF receipt
    file_put_contents($outfile, CRM_Utils_PDF_Utils::html2pdf($html, null, true, $page_format));
    $file_id = saveDocument($contact_id, $basename, "application/pdf", "Spendenbescheinigung", date("Y-m-d h:i:s"), $from_date, $to_date, $comment);
    // return summary data and CiviCRM URL to generated file
    return array("contact_id" => $contact_id, "file_id" => $file_id, "from_date" => $from_date, "to_date" => $to_date, "total_amount" => $total, "filename" => "{$basename}", "url" => CRM_Utils_System::url("civicrm/file", "reset=1&id={$file_id}&eid={$contact_id}"));
}
Example #5
0
        }
    } else {
        $data = json_encode($doc);
    }
    $cb = getparam('callback');
    if ($cb) {
        echo $cb . '(' . $data . ')';
    } else {
        echo $data;
    }
}
F3::route('POST /@db/objects/@model', function () {
    $dbName = F3::get('PARAMS["db"]');
    $model = F3::get('PARAMS["model"]');
    $doc = json_decode(file_get_contents('php://input'));
    if (!isset($doc->_id)) {
        $doc->_id = $model;
    }
    $response = saveDocument($dbName, $doc, true);
    if (isset($response->rev)) {
        $doc->_rev = $response->rev;
    }
    wrapResponse($response, $doc);
});
F3::route('GET /@db/objects/@model', function () {
    $dbName = F3::get('PARAMS["db"]');
    $model = F3::get('PARAMS["model"]');
    $response = getDocument($dbName, $model);
    wrapResponse($response, $response);
});
F3::run();
 function run()
 {
     if (!file_exists("/usr/bin/pdftk")) {
         CRM_Core_Error::fatal("'pdftk' nicht installiert, Erstellung des Sammel-PDF nicht moeglich");
     }
     require_once 'backend.php';
     $year = CRM_Utils_Request::retrieve('year', 'Positive', $_ = null, true);
     CRM_Utils_System::setTitle("Jahresbescheinigungen {$year}");
     $from_date = "{$year}-01-01 00:00:00";
     if ($year == date("Y")) {
         $to_date = date("Y-m-d");
     } else {
         $to_date = "{$year}-12-31";
     }
     $to_date .= " 23:59:59";
     $params = array("from_date" => $from_date, "to_date" => $to_date, "comment" => "Jahresbescheinigung {$year}");
     // Creating a lot of documents can take quite long...
     set_time_limit(0);
     $result = generate_receipts($params);
     if (!empty($result)) {
         $this->assign("have_result", true);
         /*
          * Create a merged document containing all the individual receipts.
          *
          * The actual merging is done by invoking an external tool (pdftk)
          * with all the individual receipt documents as command line parameters.
          *
          * However, as most operating systems (except GNU Hurd) have a limited maximal command line length,
          * trying to merge all documents in one go would cause an overflow if we have a lot of receipts.
          * Thus, we have to merge them in smaller batches first, before combining these into the final result.
          *
          * We do this in an iterative process, with potentially multiple intermediate levels.
          * This is most probably overkill -- but better safe than sorry :-)
          */
         define('BATCH_SIZE', 1000);
         // With a typical command line length limit of 64 KiB, this should give us enough leeway...
         $tempDir = CRM_Utils_File::tempdir('donationreceipts-');
         $config = CRM_Core_Config::singleton();
         // In the first pass, we start with the individual receipt documents we just generated.
         $inFiles = array_map(function ($elem) {
             return $elem['filename'];
         }, $result);
         $inDir = $config->customFileUploadDir;
         for ($pass = 1, $isFinalPass = false; !$isFinalPass; ++$pass) {
             // Do at least one pass; and further ones as necessary.
             $batches = array_chunk($inFiles, BATCH_SIZE);
             $isFinalPass = !(count($batches) > 1);
             // If the current input files fit into a single batch, we will be done after this pass; otherwise, we need further passes.
             $outFiles = array();
             foreach ($batches as $batchID => $filesInBatch) {
                 // If this is the final pass, the current output will be the actual result file to save; otherwise, we generate temporary files for further merging.
                 $outDir = $isFinalPass ? $config->customFileUploadDir : $tempDir;
                 $baseName = $isFinalPass ? CRM_Utils_File::makeFileName("Jahresbescheinigungen-{$year}.pdf") : "{$pass}-{$batchID}.pdf";
                 $outFile = $outDir . $baseName;
                 $inputs = join(" ", $filesInBatch);
                 system("cd {$inDir} && pdftk {$inputs} cat output {$outFile}");
                 $outFiles[] = $baseName;
                 // If our inputs are temporary results from the previous pass, we can drop them now.
                 if ($inDir == $tempDir) {
                     foreach ($filesInBatch as $file) {
                         unlink($tempDir . $file);
                     }
                 }
             }
             // Outputs from this pass are inputs for next one.
             $inFiles = $outFiles;
             $inDir = $tempDir;
         }
         // for ($pass)
         rmdir($tempDir);
         if (file_exists($outFile)) {
             $session = CRM_Core_Session::singleton();
             $user = $session->get('userID');
             $file_id = saveDocument($user, $baseName, "application/pdf", "Jahresbescheinigungen", date("Y-m-d h:i:s"), $from_date, $to_date, "Sammeldatei Jahresbescheinigungen {$year}");
             $this->assign("url", CRM_Utils_System::url("civicrm/file", "reset=1&id={$file_id}&eid={$user}"));
         } else {
             CRM_Core_Error::fatal("Erstellen des Sammeldokuments fehlgeschlagen");
         }
     }
     /* !empty($result) */
     parent::run();
 }
Example #7
0
function updateViews($db, $app, $views)
{
    $obj = new stdClass();
    $obj->_id = "_design/" . urlencode($app);
    $obj->views = new stdClass();
    foreach ($views as $key => $value) {
        $viewName = urlencode($key);
        $obj->views->{$viewName} = new StdClass();
        if (is_array($value)) {
            $obj->views->{$viewName}->map = $value[map];
            $obj->views->{$viewName}->reduce = $value[reduce];
        } else {
            $obj->views->{$viewName}->map = $value;
        }
    }
    $a = saveDocument($db, $obj, true);
}