2 require_once(
'dbHandler.php');
3 require_once(
'ppyrd.base.php');
32 $this->
output(
"working on: " . $this->pdf);
35 $newFilenameStructure=$this->db->getConfigValue(
'newFilenameStructure');
39 $unwanted = array(
')',
']');
40 $separators =
"/ - | \(| \[| \-\- /";
41 $templateName = str_replace($unwanted,
'', $newFilenameStructure);
44 $templateParts = array_flip(preg_split($separators, $templateName));
47 $tmpName = str_replace($unwanted,
'', $this->pdf);
48 $filenameParts = preg_split($separators, $tmpName);
53 $parts = explode(
" - ", $this->pdf);
56 $this->date = $filenameParts[$templateParts[
'ddatum']];
57 $this->year = date(
'Y',strtotime($this->date));
58 $this->month = date(
'm',strtotime($this->date));
59 $this->day = date(
'd',strtotime($this->date));
62 $this->company = $filenameParts[$templateParts[
'ffirma']];
63 $this->recipient = $filenameParts[$templateParts[
'wwer']];
64 $this->subject = $filenameParts[$templateParts[
'bbetreff']];
65 $this->amount = $filenameParts[$templateParts[
'bbetrag']];
70 preg_match_all(
'/\[(\d|\w)*\]/',$this->pdf,$tags);
71 $this->tags = implode($tags[0]);
74 $this->
output(
"date: " . $this->date);
75 $this->
output(
"year: " . $this->year);
76 $this->
output(
"month: " . $this->month);
77 $this->
output(
"day: " . $this->day);
79 $this->
output(
"company: " . $this->company);
80 $this->
output(
"recipient: " . $this->recipient);
81 $this->
output(
"subject: " . $this->subject);
82 $this->
output(
"amount: " . $this->amount);
83 $this->
output(
"tags: " . $this->tags);
92 $rules = $this->db->getActiveArchiveRules();
93 while ($row = $rules->fetchArray()) {
96 $match = fnmatch($row[
'company'], $this->company)
97 && fnmatch($row[
'subject'], $this->subject)
98 && fnmatch($row[
'recipient'], $this->recipient)
99 && fnmatch($row[
'tags'], $this->tags);
104 $toFolder = $row[
'toFolder'];
107 $toFolder = str_replace(
'[year]', $this->year, $toFolder);
108 $toFolder = str_replace(
'[month]', $this->month, $toFolder);
109 $toFolder = str_replace(
'[day]', $this->day, $toFolder);
110 $toFolder = str_replace(
'[recipient]', $this->recipient, $toFolder);
113 $toFolder = rtrim($toFolder,
'/') .
'/';
116 exec(
"mkdir -p '$toFolder'");
119 exec(
'mv --backup=numbered "' . $this->pdf .
'" "' . $toFolder . $this->pdf .
'"');
121 $this->db->writeLog($this->pdf, $this->pdf,
"",
"Moved file to: " . $toFolder);
151 $ppyrd->output(
"starting paperyard");
158 $ppyrd->checkCliVsWebserver();
162 $ppyrd->output(
"checking for confirmed files ...");
165 const ATTRIBUTE_PATTERN =
'/^(.*?) - (.*?) - (.*?) \((.*?)\) \(EUR(.*?)\) \[(?<tags>.*?)\] -- (.*?)(?:.pdf)$/';
177 $basename = basename($document);
179 $tags = explode(
',', $attributes[
'tags']);
180 if (in_array(
'ok', $tags)) {
181 rename($document,
'/data/sort/' . $basename);
196 foreach (
$pdfs as $pdf){
handling database connection and queries
run()
runs the main process
Sorts thru PDF documents and puts them into corresponding folders etc.
__construct($pdf, $db)
constructor
output($string, $debug=0)
outputs string
splitUpFilename()
function gets from file name the information what the date, company and subject is.