From 5743d05478f234bc509bc77f9d67d67f9c56e4ee Mon Sep 17 00:00:00 2001 From: Andreas Moik Date: Thu, 28 Jul 2016 13:30:09 +0200 Subject: [PATCH 1/5] bugfixes --- content/dokumentenakt.pdf.php | 54 +++++++++++++++---------------- include/dokument_export.class.php | 4 ++- include/pdf.class.php | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/content/dokumentenakt.pdf.php b/content/dokumentenakt.pdf.php index 8755bf3b3..de6401bdf 100755 --- a/content/dokumentenakt.pdf.php +++ b/content/dokumentenakt.pdf.php @@ -68,21 +68,6 @@ foreach($prestudent_ids as $pid) if(!$prestudent->load($pid)) cleanUpAndDie($p->t('tools/studentWurdeNichtGefunden')."(".$pid.")", $tmpDir); - /* - * Deckblatt - */ - $filename = $tmpDir . "/".uniqid(); - $doc = new dokument_export('Bewerberakt'); - $doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),'bewerberakt'); - - if(!$doc->create('pdf')) - die($doc->errormsg); -// $doc->temp_filename = $filename; - $document = $doc->output(false); - $filename = $tmpDir.'/'.uniqid(); - file_put_contents($filename, $document); - $doc->close(); - $allDocs[] = $filename; /* @@ -100,25 +85,24 @@ foreach($prestudent_ids as $pid) AND prestudent_id='.$db->db_add_param($pid, FHC_INTEGER).'; '; + $preDocs = array(); $result = $db->db_query($query); while($row = $db->db_fetch_object($result)) { - - $filename = ""; - if($row->dms_id != null) + if($row->inhalt != null) + { + $filename = $tmpDir . "/".uniqid(); + $fileData = base64_decode($row->inhalt); + file_put_contents($filename, $fileData); + } + else if($row->dms_id != null) { $dms = new dms(); $dms->load($row->dms_id); $filename = DMS_PATH . $dms->filename; } - else if($row->inhalt != null) - { - $filename = $tmpDir . "/".uniqid(); - $fileData = base64_decode($row->inhalt); - file_put_contents($filename, $fileData); - } if($filename == "") @@ -146,16 +130,30 @@ foreach($prestudent_ids as $pid) { $fullFilename = $row->titel; } - else - cleanUpAndDie("falscher typ TODO", $tmpDir); // only filled, if the file is supported if($fullFilename != "") { - $allDocs[] = $fullFilename; + $preDocs[] = $fullFilename; } - } + + /* + * Deckblatt + */ + $filename = $tmpDir . "/".uniqid(); + $doc = new dokument_export($_GET["vorlage_kurzbz"]); + $doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),"bewerberakt"); + + if(!$doc->create('pdf')) + die($doc->errormsg); + + $document = $doc->output(false); + $filename = $tmpDir.'/'.uniqid(); + file_put_contents($filename, $document); + $doc->close(); + $allDocs[] = $filename; + $allDocs = array_merge($allDocs, $preDocs); } diff --git a/include/dokument_export.class.php b/include/dokument_export.class.php index c06f29abb..f78a8c86e 100644 --- a/include/dokument_export.class.php +++ b/include/dokument_export.class.php @@ -256,6 +256,7 @@ class dokument_export case 'pdf': $this->temp_filename='out.pdf'; exec("unoconv -e IsSkipEmptyPages=false --stdout -f pdf $tempname_zip > ".$this->temp_filename, $out, $ret); + if($ret!=0) { $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte informieren Sie den Administrator'; @@ -341,8 +342,9 @@ class dokument_export if($this->styles_xsl!='') unlink('styles.xml'); - unlink('out.zip'); unlink($this->temp_filename); + if(file_exists("out.zip")) + unlink('out.zip'); if(count($this->images)>0) { diff --git a/include/pdf.class.php b/include/pdf.class.php index 033c0f5a6..6d0cc7fc7 100644 --- a/include/pdf.class.php +++ b/include/pdf.class.php @@ -44,7 +44,7 @@ class Pdf } if(finfo_file($finfo, $f) != "application/pdf") { - $this->errormsg = "Wrong format: '$f'"; + $this->errormsg = "Wrong format(".finfo_file($finfo, $f)."): '$f'"; return false; } } From b820f409aa50e1bd90cc64a78b3c9e5b436c3cc4 Mon Sep 17 00:00:00 2001 From: Andreas Moik Date: Thu, 28 Jul 2016 16:55:09 +0200 Subject: [PATCH 2/5] bugfix --- content/dokumentenakt.pdf.php | 7 ++----- include/dokument_export.class.php | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/content/dokumentenakt.pdf.php b/content/dokumentenakt.pdf.php index de6401bdf..95c2ae585 100755 --- a/content/dokumentenakt.pdf.php +++ b/content/dokumentenakt.pdf.php @@ -69,7 +69,6 @@ foreach($prestudent_ids as $pid) cleanUpAndDie($p->t('tools/studentWurdeNichtGefunden')."(".$pid.")", $tmpDir); - /* * Get all Documents */ @@ -108,7 +107,6 @@ foreach($prestudent_ids as $pid) if($filename == "") continue; - /* * Determine the filetype * and convert, if nessecary @@ -148,15 +146,14 @@ foreach($prestudent_ids as $pid) if(!$doc->create('pdf')) die($doc->errormsg); - $document = $doc->output(false); $filename = $tmpDir.'/'.uniqid(); - file_put_contents($filename, $document); + file_put_contents($filename, $doc->output(false)); $doc->close(); $allDocs[] = $filename; $allDocs = array_merge($allDocs, $preDocs); + unset($doc); } - /* * generate the merged PDF */ diff --git a/include/dokument_export.class.php b/include/dokument_export.class.php index f78a8c86e..14aadac40 100644 --- a/include/dokument_export.class.php +++ b/include/dokument_export.class.php @@ -168,7 +168,7 @@ class dokument_export $contentbuffer = $proc->transformToXml($this->xml_data); - $this->temp_folder = '/tmp/fhcunoconv-'.uniqid(); + $this->temp_folder = sys_get_temp_dir().'/fhcunoconv-'.uniqid(); mkdir($this->temp_folder); chdir($this->temp_folder); file_put_contents('content.xml', $contentbuffer); @@ -201,7 +201,8 @@ class dokument_export if(!$vorlage_found) $zipfile = DOC_ROOT.'system/vorlage_zip/'.$this->vorlage_file; - $tempname_zip = 'out.zip'; + $tempname_zip = $this->temp_folder . '/out.zip'; + if(!copy($zipfile, $tempname_zip)) die('copy failed'); @@ -254,7 +255,7 @@ class dokument_export switch($this->outputformat) { case 'pdf': - $this->temp_filename='out.pdf'; + $this->temp_filename = $this->temp_folder . '/out.pdf'; exec("unoconv -e IsSkipEmptyPages=false --stdout -f pdf $tempname_zip > ".$this->temp_filename, $out, $ret); if($ret!=0) @@ -408,7 +409,6 @@ class dokument_export $command = 'unoconv --format %s --output %s %s'; $command = sprintf($command, $format, $outFile, $inFile); - exec($command, $out, $ret); if($ret!=0) { From 4b82843c76766a083e54a1f25c94770761faeaa8 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 29 Jul 2016 15:36:32 +0200 Subject: [PATCH 3/5] - Added parameter blockTags to controller Phrase If this parameter is set to "no", it will be removed the tags

and

from the beginning and from the end of the returned phrases --- application/controllers/api/v1/system/Phrase.php | 3 ++- application/libraries/PhrasesLib.php | 16 ++++++++++++++-- composer.json | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/application/controllers/api/v1/system/Phrase.php b/application/controllers/api/v1/system/Phrase.php index 7821d42f4..31decf540 100644 --- a/application/controllers/api/v1/system/Phrase.php +++ b/application/controllers/api/v1/system/Phrase.php @@ -54,10 +54,11 @@ class Phrase extends APIv1_Controller $phrase = $this->get('phrase'); $orgeinheit_kurzbz = $this->get('orgeinheit_kurzbz'); $orgform_kurzbz = $this->get('orgform_kurzbz'); + $blockTags = $this->get('blockTags'); if (isset($app) && isset($sprache)) { - $result = $this->phraseslib->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz); + $result = $this->phraseslib->getPhrases($app, $sprache, $phrase, $orgeinheit_kurzbz, $orgform_kurzbz, $blockTags); $this->response($result, REST_Controller::HTTP_OK); } diff --git a/application/libraries/PhrasesLib.php b/application/libraries/PhrasesLib.php index 5a1ca48f8..d4fa939e6 100644 --- a/application/libraries/PhrasesLib.php +++ b/application/libraries/PhrasesLib.php @@ -111,7 +111,7 @@ class PhrasesLib * * @return struct */ - function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null) + function getPhrases($app, $sprache, $phrase = null, $orgeinheit_kurzbz = null, $orgform_kurzbz = null, $blockTags = null) { if (isset($app) && isset($sprache)) { @@ -123,7 +123,19 @@ class PhrasesLib for ($i = 0; $i < count($result->retval); $i++) { - $result->retval[$i]->text = $parser->textileThis($result->retval[$i]->text); + // If no

tags required + if ($blockTags == "no") + { + // Removes tags

and

from the beginning and from the end of the string + $tmpText = $parser->textileThis($result->retval[$i]->text); + $tmpText = substr($tmpText, 3, strlen($tmpText)); + $tmpText = substr($tmpText, 0, strlen($tmpText) - 4); + $result->retval[$i]->text = $tmpText; + } + else + { + $result->retval[$i]->text = $parser->textileThis($result->retval[$i]->text); + } } } } diff --git a/composer.json b/composer.json index 3b1f37eb5..d8469d498 100755 --- a/composer.json +++ b/composer.json @@ -86,7 +86,7 @@ "json-forms": "1.4.0", "wikimedia/composer-merge-plugin": "^1.3", "fzaninotto/faker": "1.*", - "netcarver/textile": "3.5.*" + "netcarver/textile": "^3.5" }, "require-dev": { From 1c01faba5f0b29437a6d6f5d0a853d0417688373 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 29 Jul 2016 16:33:21 +0200 Subject: [PATCH 4/5] This controller allows to call any methods of any class present in libraries and in models. First raw version, code to be refined. Functionality to be extended to others HTTP methods. PS: PCRM stands for "Please Christian Rename Me", because I've no name to give to it :D --- .../controllers/api/v1/system/PCRM.php | 262 ++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 application/controllers/api/v1/system/PCRM.php diff --git a/application/controllers/api/v1/system/PCRM.php b/application/controllers/api/v1/system/PCRM.php new file mode 100644 index 000000000..4d527adb1 --- /dev/null +++ b/application/controllers/api/v1/system/PCRM.php @@ -0,0 +1,262 @@ +_getParameters($this->get()); + $validation = $this->_validateCall($parameters); + + // If the validation was passed + if($validation->error == EXIT_SUCCESS) + { + $loaded = null; + // Check if the resource is already loaded, it works only with libraries and drivers + if (($loaded = $this->load->is_loaded($parameters->resourceName)) === false) + { + // If the given resource is a model + if(strpos($parameters->resourceName, "_model") !== false) + { + try + { + // Try to load it + $loaded = $this->load->model($parameters->resourcePath . $parameters->resourceName); + } + catch(Exception $e) + { + // Errors while loading the model + $loaded = null; + $result = $this->_error($e->getMessage()); + } + } + // If the given resource is a library + else if(strpos($parameters->resourceName, "Lib") !== false) + { + // The method "library" of the class CI_Loader provided by CI has some limitations, + // so to be able to check errors was used this workaround + try + { + // Gets all the configured resources paths + $packagePaths = $this->load->get_package_paths(); + // Looking for a file in every paths with the same name of the resource + $found = null; + for ($i = 0; $i < count($packagePaths) && is_null($found); $i++) + { + if (file_exists($packagePaths[$i] . "libraries/" . $parameters->resourcePath . $parameters->resourceName . ".php")) + { + $found = $packagePaths[$i] . "libraries/" . $parameters->resourcePath . $parameters->resourceName . ".php"; + } + } + + // If the file was found + if (!is_null($found)) + { + // Load the file + $loaded = $this->load->file($found); + // If the resource is not present inside the file + if (!class_exists($parameters->resourceName)) + { + $loaded = null; + // Same phrase error as load->model() + $result = $this->_error($found . " exists, but doesn't declare class " . $parameters->resourceName); + } + } + else + { + $loaded = null; + // Same phrase error as load->model() + $result = $this->_error("Unable to load the requested class: " . $parameters->resourceName); + } + } + catch(Exception $e) + { + $result = $this->_error($e->getMessage()); + } + } + // Wrong selection! + else + { + $result = $this->_error("Neither a lib nor model: " . $parameters->resourcePath . $parameters->resourceName); + } + } + + // If the resource was found and loaded + if(!is_null($loaded)) + { + try + { + // Get informations about the function + $reflectionMethod = new ReflectionMethod($parameters->resourceName, $parameters->function); + // If the number of given parameters is equal to the number of parameters required by the function + if ($reflectionMethod->getNumberOfRequiredParameters() == count($parameters->parameters)) + { + // If the function is static + if ($reflectionMethod->isStatic() === true) + { + $classMethod = $parameters->resourceName . "::" . $parameters->function; + } + // If the function is not static + else + { + $classMethod = array(new $parameters->resourceName(), $parameters->function); + } + + // If the function of that resource is callable + if(is_callable($classMethod)) + { + // Call resource->function() + $resultCall = @call_user_func_array($classMethod, $parameters->parameters); + // If errors occurred while running it + if($resultCall === false) + { + $result = $this->_error("Error running " . $parameters->resourceName . "->" . $parameters->function . "()"); + } + // Returns the result of resource->function() + else + { + $result = $resultCall; + } + } + else + { + $result = $this->_error($parameters->resourceName . "->" . $parameters->function . "() is not callable!"); + } + } + else + { + $result = $this->_error("Wrong parameters number"); + } + } + catch(Exception $e) + { + $result = $this->_error($e->getMessage()); + } + } + } + else + { + $result = $validation; + } + + // Print the result + $this->response($result, REST_Controller::HTTP_OK); + } + + /** + * @return void + */ + public function postCall() + { + $validation = $this->_validatePostMessage($this->post()); + + if(is_object($validation) && $validation->error == EXIT_SUCCESS) + { + $result = $this->messagelib->sendMessage( + $this->post()['person_id'], $this->post()['subject'], $this->post()['body'], PRIORITY_NORMAL, $this->post()['relationmessage_id'], $this->post()['oe_kurzbz'] + ); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response($validation, REST_Controller::HTTP_OK); + } + } + + /** + * Gets the parameters from the call + */ + private function _getParameters($parametersArray) + { + $parameters = new stdClass(); + $parameters->parameters = array(); + $count = 0; + + foreach($parametersArray as $parameterName => $parameterValue) + { + // The name of the resource, path included + if($parameterName == "resource") + { + // Separates the resource path from the resource name + $splittedResource = preg_split("/\//", $parameterValue); + $parameters->resourceName = $splittedResource[count($splittedResource) - 1]; + $parameters->resourcePath = str_replace($parameters->resourceName, "", $parameterValue); + } + // The name of the function + else if($parameterName == "function") + { + $parameters->function = $parameterValue; + } + // It is assumed that all other parameters are parameters to be passed to the function + // They will be passed to the function in the same order in which they are passed to + // this controller + else + { + $parameters->parameters[$count++] = $parameterValue; + } + } + + return $parameters; + } + + /** + * Validate the given parameters + */ + private function _validateCall($parameters) + { + if (!is_object($parameters)) + { + return $this->_error("Parameter is not an object"); + } + if (!isset($parameters->resourcePath)) + { + return $this->_error("Resource path is not specified"); + } + if (!isset($parameters->resourceName)) + { + return $this->_error("Resource name is not specified"); + } + if (!isset($parameters->function)) + { + return $this->_error("Function is not specified"); + } + if (!is_array($parameters->parameters)) + { + return $this->_error("Parameters are not specified"); + } + if (in_array($parameters->resourceName, PCRM::$RESOURCES_BLACK_LIST)) + { + return $this->_error("You are trying to access to unauthorized resources"); + } + + return $this->_success("Input data are valid"); + } +} \ No newline at end of file From 8074fa53837f8f5e0ea503f0e1750ff3ff8c1e76 Mon Sep 17 00:00:00 2001 From: Andreas Moik Date: Mon, 1 Aug 2016 11:37:25 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Bewerberakt=20vorlage=20ge=C3=A4ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/xsl/Bewerberakt.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/xsl/Bewerberakt.xsl b/system/xsl/Bewerberakt.xsl index d8e5e30ec..989f90900 100644 --- a/system/xsl/Bewerberakt.xsl +++ b/system/xsl/Bewerberakt.xsl @@ -7,7 +7,7 @@ xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn -Bewerberakt +Bewerberakt