diff --git a/application/controllers/api/v1/crm/Prestudent.php b/application/controllers/api/v1/crm/Prestudent.php index e067a3894..e3498e9cd 100644 --- a/application/controllers/api/v1/crm/Prestudent.php +++ b/application/controllers/api/v1/crm/Prestudent.php @@ -63,27 +63,6 @@ class Prestudent extends APIv1_Controller $this->response(); } } - - /** - * @return void - */ - public function getLastStatus() - { - $prestudent_id = $this->get('prestudent_id'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); - $status_kurzbz = $this->get('status_kurzbz'); - - if (isset($prestudent_id)) - { - $result = $this->PrestudentModel->getLastStatus($prestudent_id, $studiensemester_kurzbz, $status_kurzbz); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } /** * @return void diff --git a/application/controllers/api/v1/crm/Prestudentstatus.php b/application/controllers/api/v1/crm/Prestudentstatus.php index 8c415f942..7d5bc84f9 100644 --- a/application/controllers/api/v1/crm/Prestudentstatus.php +++ b/application/controllers/api/v1/crm/Prestudentstatus.php @@ -24,8 +24,6 @@ class Prestudentstatus extends APIv1_Controller parent::__construct(); // Load model PrestudentstatusModel $this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel'); - - } /** @@ -49,6 +47,27 @@ class Prestudentstatus extends APIv1_Controller $this->response(); } } + + /** + * @return void + */ + public function getLastStatus() + { + $prestudent_id = $this->get("prestudent_id"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); + $status_kurzbz = $this->get("status_kurzbz"); + + if (isset($prestudent_id)) + { + $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id, $studiensemester_kurzbz, $status_kurzbz); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } /** * @return void @@ -89,4 +108,4 @@ class Prestudentstatus extends APIv1_Controller { return true; } -} +} \ No newline at end of file diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 253d4abc1..14dea1439 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -1,10 +1,9 @@ ci->load->library("parser"); // Loads LogLib - $this->ci->load->library('LogLib'); + $this->ci->load->library("LogLib"); // Loads VorlageLib - $this->ci->load->library('VorlageLib'); + $this->ci->load->library("VorlageLib"); // Initializing email library with the loaded configurations $this->ci->email->initialize($this->ci->config->config["mail"]); // Loading models - $this->ci->load->model('system/Message_model', 'MessageModel'); - $this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel'); - $this->ci->load->model('system/Recipient_model', 'RecipientModel'); - $this->ci->load->model('system/Attachment_model', 'AttachmentModel'); + $this->ci->load->model("system/Message_model", "MessageModel"); + $this->ci->load->model("system/MsgStatus_model", "MsgStatusModel"); + $this->ci->load->model("system/Recipient_model", "RecipientModel"); + $this->ci->load->model("system/Attachment_model", "AttachmentModel"); // Loads fhc helper - $this->ci->load->helper('fhc'); + $this->ci->load->helper("fhc"); //$this->ci->load->helper('language'); - $this->ci->lang->load('message'); + $this->ci->lang->load("message"); } // ------------------------------------------------------------------------ @@ -52,19 +51,22 @@ class MessageLib * @param integer $msg_id REQUIRED * @return array */ - function getMessage($msg_id) + public function getMessage($msg_id) { if (!is_numeric($msg_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - $this->ci->MessageModel->addJoin('public.tbl_person', 'person_id'); - $msg = $this->ci->MessageModel->loadWhere(array('message_id' => $msg_id)); - //$msg = $this->ci->MessageModel->getMessage($msg_id); - $stat = $this->ci->MsgStatusModel->loadWhere(array('message_id' => $msg_id)); + $this->ci->MessageModel->addJoin("public.tbl_person", "person_id"); + $msg = $this->ci->MessageModel->loadWhere(array("message_id" => $msg_id)); + + // Sorts the statuses by the insert date, so the first in the array is the most updated + $this->ci->MsgStatusModel->addOrder("insertamum", "DESC"); + $stat = $this->ci->MsgStatusModel->loadWhere(array("message_id" => $msg_id)); $msg->retval[0]->stat = $stat->retval; - $recp = $this->ci->RecipientModel->loadWhere(array('message_id' => $msg_id)); + + $recp = $this->ci->RecipientModel->loadWhere(array("message_id" => $msg_id)); $msg->retval[0]->recp = $recp->retval; - $attm = $this->ci->AttachmentModel->loadWhere(array('message_id' => $msg_id)); + $attm = $this->ci->AttachmentModel->loadWhere(array("message_id" => $msg_id)); $msg->retval[0]->attm = $attm->retval; return $msg; @@ -76,7 +78,7 @@ class MessageLib * @param string $uid REQUIRED * @return array */ - function getMessagesByUID($uid, $all = false) + public function getMessagesByUID($uid, $all = false) { if (empty($uid)) return $this->_error(MSG_ERR_INVALID_MSG_ID); @@ -92,7 +94,7 @@ class MessageLib * @param bigint $person_id REQUIRED * @return array */ - function getMessagesByPerson($person_id, $all = false) + public function getMessagesByPerson($person_id, $all = false) { if (empty($person_id)) return $this->_error(MSG_ERR_INVALID_MSG_ID); @@ -110,7 +112,7 @@ class MessageLib * @param integer $msg_id REQUIRED * @return array */ - function getSubMessages($msg_id) + public function getSubMessages($msg_id) { if (!is_numeric($msg_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); @@ -124,7 +126,7 @@ class MessageLib * @param token string * @return array */ - function getMessagesByToken($token) + public function getMessagesByToken($token) { if (empty($token)) return $this->_error(MSG_ERR_INVALID_MSG_ID); @@ -132,31 +134,33 @@ class MessageLib $result = $this->ci->MessageModel->getMessagesByToken($token); if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { - if ($result->retval[0]->status == MSG_STATUS_UNREAD) + // Searches for a status that is different from unread + $found = -1; + for ($i = 0; $i < count($result->retval); $i++) + { + if ($result->retval[$i]->status > MSG_STATUS_UNREAD) + { + $found = $i; + break; + } + } + + // If not found then insert the read status + if ($found == -1) { $statusKey = array( - 'message_id' => $result->retval[0]->message_id, - 'person_id' => $result->retval[0]->receiver_id, - 'status' => MSG_STATUS_UNREAD + "message_id" => $result->retval[0]->message_id, + "person_id" => $result->retval[0]->receiver_id, + "status" => MSG_STATUS_READ ); - $resTmp = $this->ci->MsgStatusModel->update($statusKey, array('status' => MSG_STATUS_READ)); - if (!is_object($resTmp) || (is_object($resTmp) && $resTmp->error != EXIT_SUCCESS)) - { - $result = $resTmp; - } - else - { - $result->retval[0]->status = MSG_STATUS_READ; - } + + $result = $this->ci->MsgStatusModel->insert($statusKey); } } return $result; } - // ------------------------------------------------------------------------ - - // ------------------------------------------------------------------------ /** @@ -167,7 +171,7 @@ class MessageLib * @param integer $status_id REQUIRED - should come from config/message.php list of constants * @return array */ - function updateMessageStatus($message_id, $person_id, $status) + public function updateMessageStatus($message_id, $person_id, $status) { if (empty($message_id)) { @@ -185,10 +189,23 @@ class MessageLib return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID); } - $result = $this->ci->MsgStatusModel->update( - array('message_id' => $message_id, 'person_id' => $person_id), - array('status' => $status) - ); + // Searches if the status is already present + $result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status)); + if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) + { + // status already present + } + else + { + // Insert the new status + $statusKey = array( + "message_id" => $message_id, + "person_id" => $person_id, + "status" => $status + ); + + $result = $this->ci->MsgStatusModel->insert($statusKey); + } return $result; } @@ -202,7 +219,7 @@ class MessageLib * @param integer $user_id REQUIRED * @return array */ - function addRecipient($person_id) + public function addRecipient($person_id) { if (!is_numeric($person_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); @@ -212,8 +229,6 @@ class MessageLib return true; } - - // ------------------------------------------------------------------------ /** @@ -226,7 +241,7 @@ class MessageLib * @param integer $priority * @return array */ - function sendMessage($sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null) + public function sendMessage($sender_id, $subject = "", $body = "", $priority = PRIORITY_NORMAL, $relationmessage_id = null, $oe_kurzbz = null) { if (!is_numeric($sender_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); @@ -235,12 +250,12 @@ class MessageLib $this->ci->db->trans_start(false); //save Message $data = array( - 'person_id' => $sender_id, - 'subject' => $subject, - 'body' => $body, - 'priority' => $priority, - 'relationmessage_id' => $relationmessage_id, - 'oe_kurzbz' => $oe_kurzbz + "person_id" => $sender_id, + "subject" => $subject, + "body" => $body, + "priority" => $priority, + "relationmessage_id" => $relationmessage_id, + "oe_kurzbz" => $oe_kurzbz ); $result = $this->ci->MessageModel->insert($data); @@ -251,9 +266,9 @@ class MessageLib */ $msg_id = $result->retval; $statusData = array( - 'message_id' => $msg_id, - 'person_id' => $sender_id, - 'status' => MSG_STATUS_UNREAD + "message_id" => $msg_id, + "person_id" => $sender_id, + "status" => MSG_STATUS_UNREAD ); $result = $this->ci->MsgStatusModel->insert($statusData); } @@ -282,13 +297,13 @@ class MessageLib * @param integer $priority * @return array */ - function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null) + public function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null) { if (!is_numeric($sender_id) || !is_numeric($receiver_id)) return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); // Load reveiver data to get its relative language - $this->ci->load->model('person/Person_model', 'PersonModel'); + $this->ci->load->model("person/Person_model", "PersonModel"); $result = $this->ci->PersonModel->load($receiver_id); if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0) { @@ -314,12 +329,12 @@ class MessageLib $this->ci->db->trans_start(false); // Save Message $msgData = array( - 'person_id' => $sender_id, - 'subject' => $result->retval[0]->subject, - 'body' => $parsedText, - 'priority' => PRIORITY_NORMAL, - 'relationmessage_id' => $relationmessage_id, - 'oe_kurzbz' => $oe_kurzbz + "person_id" => $sender_id, + "subject" => $result->retval[0]->subject, + "body" => $parsedText, + "priority" => PRIORITY_NORMAL, + "relationmessage_id" => $relationmessage_id, + "oe_kurzbz" => $oe_kurzbz ); $result = $this->ci->MessageModel->insert($msgData); if (is_object($result) && $result->error == EXIT_SUCCESS) @@ -327,18 +342,18 @@ class MessageLib // Link the message with the receiver $msg_id = $result->retval; $recipientData = array( - 'person_id' => $receiver_id, - 'message_id' => $msg_id, - 'token' => generateToken() + "person_id" => $receiver_id, + "message_id" => $msg_id, + "token" => generateToken() ); $result = $this->ci->RecipientModel->insert($recipientData); if (is_object($result) && $result->error == EXIT_SUCCESS) { // Save message status $statusData = array( - 'message_id' => $msg_id, - 'person_id' => $receiver_id, - 'status' => MSG_STATUS_UNREAD + "message_id" => $msg_id, + "person_id" => $receiver_id, + "status" => MSG_STATUS_UNREAD ); $result = $this->ci->MsgStatusModel->insert($statusData); } @@ -362,21 +377,21 @@ class MessageLib // Better message error if (!is_array($result->retval) || (is_array($result->retval) && count($result->retval) == 0)) { - $result = $this->_error('Vorlage not found', EXIT_ERROR); + $result = $this->_error("Vorlage not found", EXIT_ERROR); } else if (is_array($result->retval) && count($result->retval) > 0) { if (is_null($result->retval[0]->oe_kurzbz)) { - $result = $this->_error('Vorlage not found', EXIT_ERROR); + $result = $this->_error("Vorlage not found", EXIT_ERROR); } else if (empty($result->retval[0]->text)) { - $result = $this->_error('Vorlage has an empty text', EXIT_ERROR); + $result = $this->_error("Vorlage has an empty text", EXIT_ERROR); } else if (empty($result->retval[0]->subject)) { - $result = $this->_error('Vorlage has an empty subject', EXIT_ERROR); + $result = $this->_error("Vorlage has an empty subject", EXIT_ERROR); } } } @@ -389,123 +404,6 @@ class MessageLib return $result; } - - - // ------------------------------------------------------------------------ - // Private Functions from here out! - // ------------------------------------------------------------------------ - - /** --------------------------------------------------------------- - * Success - * - * @param mixed $retval - * @return array - */ - protected function _success($retval, $message = MSG_SUCCESS) - { - $return = new stdClass(); - $return->error = EXIT_SUCCESS; - $return->Code = $message; - $return->msg = lang('message_' . $message); - $return->retval = $retval; - return $return; - } - - /** --------------------------------------------------------------- - * General Error - * - * @return array - */ - protected function _error($retval = '', $message = MSG_ERROR) - { - $return = new stdClass(); - $return->error = EXIT_ERROR; - $return->Code = $message; - $return->msg = lang('message_' . $message); - $return->retval = $retval; - return $return; - } - /** - * Invalid ID - * - * @param integer config.php error code numbers - * @return array - */ - private function _invalid_id($error = '') - { - return array( - 'err' => 1, - 'code' => $error, - 'msg' => lang('message_'.$error) - ); - } - - /** - * Gets an item from the email configuration array - */ - private function getEmailCfgItem($itemName) - { - return $this->ci->config->item($itemName, EMAIL_CONFIG_INDEX); - } - - /** - * Sends a single email - */ - private function sendOne($from, $to, $subject, $message, $alias = "", $cc = null, $bcc = null) - { - $this->ci->email->from($from, $alias); - $this->ci->email->to($to); - if (!is_null($cc)) $this->ci->email->cc($cc); - if (!is_null($bcc)) $this->ci->email->bcc($bcc); - $this->ci->email->subject($subject); - $this->ci->email->message($message); - - // Avoid printing on standard output ugly error messages - return @$this->ci->email->send(); - } - - /** - * Update the table tbl_message_recipient - */ - private function _updateMessageRecipient($message_id, $receiver_id, $parameters) - { - $updated = false; - - // Changes the status of the message from unread to read - $resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters); - // Checks if errors were occurred - if (is_object($resultUpdate) && $resultUpdate->error == EXIT_SUCCESS && is_array($resultUpdate->retval)) - { - $updated = true; - } - - return $updated; - } - - /** - * Changes the status of the message from unsent to sent - */ - private function setMessageSent($message_id, $receiver_id) - { - $parameters = array("sent" => "NOW()", "sentinfo" => null); - - return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); - } - - /** - * Sets the sentInfo with the error - */ - private function setMessageError($message_id, $receiver_id, $sentInfo, $prevSentInfo = null) - { - if (!is_null($prevSentInfo) && $prevSentInfo != "") - { - $sentInfo = $prevSentInfo . SENT_INFO_NEWLINE . $sentInfo; - } - - $parameters = array("sent" => null, "sentinfo" => $sentInfo); - - return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); - } /** * Gets all the messages from DB and sends them via email @@ -631,4 +529,120 @@ class MessageLib return $sent; } + + // ------------------------------------------------------------------------ + // Private Functions from here out! + // ------------------------------------------------------------------------ + + /** --------------------------------------------------------------- + * Success + * + * @param mixed $retval + * @return array + */ + protected function _success($retval, $message = MSG_SUCCESS) + { + $return = new stdClass(); + $return->error = EXIT_SUCCESS; + $return->Code = $message; + $return->msg = lang("message_" . $message); + $return->retval = $retval; + return $return; + } + + /** --------------------------------------------------------------- + * General Error + * + * @return array + */ + protected function _error($retval = "", $message = MSG_ERROR) + { + $return = new stdClass(); + $return->error = EXIT_ERROR; + $return->Code = $message; + $return->msg = lang("message_" . $message); + $return->retval = $retval; + return $return; + } + /** + * Invalid ID + * + * @param integer config.php error code numbers + * @return array + */ + private function _invalid_id($error = "") + { + return array( + "err" => 1, + "code" => $error, + "msg" => lang("message_".$error) + ); + } + + /** + * Gets an item from the email configuration array + */ + private function getEmailCfgItem($itemName) + { + return $this->ci->config->item($itemName, EMAIL_CONFIG_INDEX); + } + + /** + * Sends a single email + */ + private function sendOne($from, $to, $subject, $message, $alias = "", $cc = null, $bcc = null) + { + $this->ci->email->from($from, $alias); + $this->ci->email->to($to); + if (!is_null($cc)) $this->ci->email->cc($cc); + if (!is_null($bcc)) $this->ci->email->bcc($bcc); + $this->ci->email->subject($subject); + $this->ci->email->message($message); + + // Avoid printing on standard output ugly error messages + return @$this->ci->email->send(); + } + + /** + * Update the table tbl_message_recipient + */ + private function _updateMessageRecipient($message_id, $receiver_id, $parameters) + { + $updated = false; + + // Changes the status of the message from unread to read + $resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters); + // Checks if errors were occurred + if (is_object($resultUpdate) && $resultUpdate->error == EXIT_SUCCESS && is_array($resultUpdate->retval)) + { + $updated = true; + } + + return $updated; + } + + /** + * Changes the status of the message from unsent to sent + */ + private function setMessageSent($message_id, $receiver_id) + { + $parameters = array("sent" => "NOW()", "sentinfo" => null); + + return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); + } + + /** + * Sets the sentInfo with the error + */ + private function setMessageError($message_id, $receiver_id, $sentInfo, $prevSentInfo = null) + { + if (!is_null($prevSentInfo) && $prevSentInfo != "") + { + $sentInfo = $prevSentInfo . SENT_INFO_NEWLINE . $sentInfo; + } + + $parameters = array("sent" => null, "sentinfo" => $sentInfo); + + return $this->_updateMessageRecipient($message_id, $receiver_id, $parameters); + } } \ No newline at end of file diff --git a/application/libraries/MigrationLib.php b/application/libraries/MigrationLib.php index 0a9d1dfef..ac80ff351 100644 --- a/application/libraries/MigrationLib.php +++ b/application/libraries/MigrationLib.php @@ -8,11 +8,16 @@ if (! defined("BASEPATH")) exit("No direct script access allowed"); class MigrationLib extends CI_Migration { // Prefixes and separator for messages - private $MSG_PREFIX = "[-]"; - private $INFO_PREFIX = "[I]"; - private $ERROR_PREFIX = "[E]"; - private $SEPARATOR = "------------------------------"; + const MSG_PREFIX = "[-]"; + const INFO_PREFIX = "[I]"; + const ERROR_PREFIX = "[E]"; + const SEPARATOR = "------------------------------"; + // Console colors codes + const ERROR_COLOR = 31; + const INFO_COLOR = 33; + // HTML colors names + private $HTML_COLORS = array(31 => "red", 33 => "orange"); // Used to set if the migration process is called via command line or via browser private $cli; @@ -58,12 +63,42 @@ class MigrationLib extends CI_Migration } } + /** + * Returns the string needed to color the output + */ + private function getColored($color) + { + $colored = "%s"; + + if (!is_null($color)) + { + if ($this->cli === true) + { + $colored = "\033[" . $color . "m%s\033[37m"; + } + else + { + $colored = "HTML_COLORS[$color] . "\">%s"; + } + } + + return $colored; + } + + /** + * Print a message, even colored if specified + */ + private function _print($prefix, $text, $color = null) + { + printf($this->getColored($color), sprintf("%s %s" . $this->getEOL(), $prefix, $text)); + } + /** * Prints a formatted message */ private function printMessage($message) { - printf("%s %s" . $this->getEOL(), $this->MSG_PREFIX, $message); + $this->_print(MigrationLib::MSG_PREFIX, $message); } /** @@ -71,7 +106,7 @@ class MigrationLib extends CI_Migration */ private function printInfo($info) { - printf("%s %s" . $this->getEOL(), $this->INFO_PREFIX, $info); + $this->_print(MigrationLib::INFO_PREFIX, $info, MigrationLib::INFO_COLOR); } /** @@ -79,7 +114,7 @@ class MigrationLib extends CI_Migration */ private function printError($error) { - printf("%s %s" . $this->getEOL(), $this->ERROR_PREFIX, $error); + $this->_print(MigrationLib::ERROR_PREFIX, $error, MigrationLib::ERROR_COLOR); } /** @@ -102,7 +137,9 @@ class MigrationLib extends CI_Migration */ protected function startUP() { - $this->printInfo(sprintf("%s Start method up of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + $this->printInfo(sprintf("%s Start method up of class %s %s", + MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR) + ); } /** @@ -110,7 +147,9 @@ class MigrationLib extends CI_Migration */ protected function endUP() { - $this->printInfo(sprintf("%s End method up of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + $this->printInfo(sprintf("%s End method up of class %s %s", + MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR) + ); } /** @@ -118,7 +157,9 @@ class MigrationLib extends CI_Migration */ protected function startDown() { - $this->printInfo(sprintf("%s Start method down of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + $this->printInfo(sprintf("%s Start method down of class %s %s", + MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR) + ); } /** @@ -126,7 +167,9 @@ class MigrationLib extends CI_Migration */ protected function endDown() { - $this->printInfo(sprintf("%s End method down of class %s %s", $this->SEPARATOR, get_called_class(), $this->SEPARATOR)); + $this->printInfo(sprintf("%s End method down of class %s %s", + MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR) + ); } /** @@ -477,7 +520,6 @@ class MigrationLib extends CI_Migration } } - /** * Executes the given query */ diff --git a/application/migrations/013_akte.php b/application/migrations/013_akte.php new file mode 100644 index 000000000..21ad85f6a --- /dev/null +++ b/application/migrations/013_akte.php @@ -0,0 +1,38 @@ +startUP(); + + // Add nachgereicht_am to public.tbl_akte + $columns = array( + "nachgereicht_am" => array( + "type" => "date", + "null" => true + ) + ); + $this->addColumn("public", "tbl_akte", $columns); + + $this->endUP(); + } + + public function down() + { + $this->startDown(); + + $this->dropColumn("public", "tbl_akte", "nachgereicht_am"); + + $this->endDown(); + } +} \ No newline at end of file diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index c5896da64..9353444cd 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -11,50 +11,4 @@ class Prestudent_model extends DB_Model $this->dbTable = 'public.tbl_prestudent'; $this->pk = 'prestudent_id'; } - - /** - * @return void - */ - public function getLastStatus($prestudent_id, $studiensemester_kurzbz = '', $status_kurzbz = '') - { - // Checks if the operation is permitted by the API caller - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('lehre.tbl_studienplan'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('lehre.tbl_studienplan'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_status'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_status'), FHC_MODEL_ERROR); - - $query = "SELECT tbl_prestudentstatus.*, - bezeichnung AS studienplan_bezeichnung, - tbl_status.bezeichnung_mehrsprachig - FROM public.tbl_prestudentstatus LEFT JOIN lehre.tbl_studienplan USING (studienplan_id) - JOIN public.tbl_status USING (status_kurzbz) - WHERE tbl_status.status_kurzbz = tbl_prestudentstatus.status_kurzbz - AND prestudent_id = ?"; - - $parametersArray = array($prestudent_id); - - if ($studiensemester_kurzbz != '') - { - array_push($parametersArray, $studiensemester_kurzbz); - $query .= ' AND studiensemester_kurzbz = ?'; - } - if ($status_kurzbz != '') - { - array_push($parametersArray, $status_kurzbz); - $query .= ' AND status_kurzbz = ?'; - } - - $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC LIMIT 1'; - - $result = $this->db->query($query, $parametersArray); - - if (is_object($result)) - return $this->_success($result->result()); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); - } } \ No newline at end of file diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 8f6b57a41..6d960a07b 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -12,4 +12,50 @@ class Prestudentstatus_model extends DB_Model $this->pk = array('ausbildungssemester', 'studiensemester_kurzbz', 'status_kurzbz', 'prestudent_id'); $this->hasSequence = false; } + + /** + * @return void + */ + public function getLastStatus($prestudent_id, $studiensemester_kurzbz = '', $status_kurzbz = '') + { + // Checks if the operation is permitted by the API caller + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), FHC_MODEL_ERROR); + + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('lehre.tbl_studienplan'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('lehre.tbl_studienplan'), FHC_MODEL_ERROR); + + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_status'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_status'), FHC_MODEL_ERROR); + + $query = "SELECT tbl_prestudentstatus.*, + bezeichnung AS studienplan_bezeichnung, + tbl_status.bezeichnung_mehrsprachig + FROM public.tbl_prestudentstatus LEFT JOIN lehre.tbl_studienplan USING (studienplan_id) + JOIN public.tbl_status USING (status_kurzbz) + WHERE tbl_status.status_kurzbz = tbl_prestudentstatus.status_kurzbz + AND prestudent_id = ?"; + + $parametersArray = array($prestudent_id); + + if ($studiensemester_kurzbz != '') + { + array_push($parametersArray, $studiensemester_kurzbz); + $query .= ' AND studiensemester_kurzbz = ?'; + } + if ($status_kurzbz != '') + { + array_push($parametersArray, $status_kurzbz); + $query .= ' AND status_kurzbz = ?'; + } + + $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC LIMIT 1'; + + $result = $this->db->query($query, $parametersArray); + + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } } \ No newline at end of file diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 602a01694..a114e58b2 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -1,6 +1,6 @@ dbTable = 'public.tbl_msg_message'; - $this->pk = 'message_id'; + $this->dbTable = "public.tbl_msg_message"; + $this->pk = "message_id"; } public function getMessagesByUID($uid, $all) @@ -21,50 +21,46 @@ class Message_model extends DB_Model // if same user if ($uid === getAuthUID()) { - if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> basis/message', FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message", FHC_MODEL_ERROR); } // if different user, for reading messages from other users else { - if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> basis/message:all', FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message:all", FHC_MODEL_ERROR); } // get Data - $sql = 'SELECT uid, - person_id, - message_id, - subject, - body, - priority, - relationmessage_id, - oe_kurzbz, + $sql = "SELECT b.uid, + m.person_id, + m.message_id, + m.subject, + m.body, + m.priority, + m.relationmessage_id, + m.oe_kurzbz, m.insertamum, - anrede, - titelpost, - titelpre, - nachname, - vorname, - vornamen, - status, - statusinfo, + p.anrede, + p.titelpost, + p.titelpre, + p.nachname, + p.vorname, + p.vornamen, + s.status, + s.statusinfo, s.insertamum AS statusamum - FROM public.tbl_msg_message m JOIN public.tbl_person USING (person_id) - JOIN public.tbl_benutzer USING (person_id) - LEFT OUTER JOIN ( - SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum - FROM public.tbl_msg_status INNER JOIN ( - SELECT message_id, person_id, max(insertamum) AS insertamum - FROM public.tbl_msg_status - GROUP BY message_id, person_id - ) status USING (message_id, person_id) - WHERE tbl_msg_status.insertamum=status.insertamum - ) s USING (message_id, person_id) - WHERE uid = ?'; + FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) + JOIN public.tbl_person p ON (r.person_id = p.person_id) + JOIN public.tbl_benutzer b ON (r.person_id = b.person_id) + JOIN ( + SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) + WHERE b.uid = ?"; if (! $all) - $sql .= ' AND (status < 3 OR status IS NULL)'; + $sql .= " AND (status < 3 OR status IS NULL)"; + $result = $this->db->query($sql, array($uid)); if (is_object($result)) return $this->_success($result->result()); @@ -75,16 +71,16 @@ class Message_model extends DB_Model public function getMessagesByPerson($person_id, $all) { // Check wrights - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_recipient'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_recipient'), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_message'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_message'), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_person'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_person'), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_status'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_status'), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_person"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_person"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); - $sql = 'SELECT r.message_id, + $sql = "SELECT r.message_id, m.person_id, m.subject, m.body, @@ -93,11 +89,13 @@ class Message_model extends DB_Model m.oe_kurzbz, s.status, s.statusinfo, - s.updateamum + s.insertamum AS statusamum FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) JOIN public.tbl_person p ON (p.person_id = m.person_id) - JOIN public.tbl_msg_status s USING (message_id) - WHERE r.person_id = ?'; + JOIN ( + SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 + ) s ON (m.message_id = s.message_id AND r.person_id = s.person_id) + WHERE r.person_id = ?"; $result = $this->db->query($sql, array($person_id)); if (is_object($result)) @@ -109,14 +107,14 @@ class Message_model extends DB_Model public function getMessagesByToken($token) { // Check wrights - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_recipient'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_recipient'), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_message'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_message'), FHC_MODEL_ERROR); - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_msg_status'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_msg_status'), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR); + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s")) + return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR); - $sql = 'SELECT r.message_id, + $sql = "SELECT r.message_id, r.person_id as receiver_id, m.person_id as sender_id, m.subject, @@ -126,11 +124,14 @@ class Message_model extends DB_Model m.oe_kurzbz, s.status, s.statusinfo, - s.updateamum + s.insertamum as statusamum FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) - JOIN public.tbl_msg_status s USING (message_id) + JOIN ( + SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1 + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) WHERE r.token = ? - AND status < ?'; + AND status < ? + ORDER BY s.insertamum DESC"; $result = $this->db->query($sql, array($token, MSG_STATUS_DELETED)); if (is_object($result)) diff --git a/application/models/system/MsgStatus_model.php b/application/models/system/MsgStatus_model.php index 81aaba06b..b6a6da286 100644 --- a/application/models/system/MsgStatus_model.php +++ b/application/models/system/MsgStatus_model.php @@ -11,7 +11,7 @@ class MsgStatus_model extends DB_Model { parent::__construct(); $this->dbTable = "public.tbl_msg_status"; - $this->pk = array("message_id", "person_id"); + $this->pk = array("message_id", "person_id", "status"); $this->hasSequence = false; } } \ No newline at end of file diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 47d6e5d57..6e6352c93 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -24,7 +24,7 @@ class Recipient_model extends DB_Model */ public function getMessages($kontaktType, $sent, $limit = null) { - // Check wrights + // Check rights if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s")) return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR); if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s")) @@ -67,8 +67,6 @@ class Recipient_model extends DB_Model array_push($parametersArray, $limit); } - - // Get data of the messages to sent $result = $this->db->query($query, $parametersArray); if (is_object($result)) diff --git a/content/dokumentenakt.pdf.php b/content/dokumentenakt.pdf.php new file mode 100755 index 000000000..8755bf3b3 --- /dev/null +++ b/content/dokumentenakt.pdf.php @@ -0,0 +1,220 @@ +. + */ + + +require_once(dirname(__FILE__).'/../config/vilesci.config.inc.php'); +require_once(dirname(__FILE__).'/../include/pdf.class.php'); +require_once(dirname(__FILE__).'/../include/dokument_export.class.php'); +require_once(dirname(__FILE__).'/../include/phrasen.class.php'); +require_once(dirname(__FILE__).'/../include/prestudent.class.php'); +require_once(dirname(__FILE__).'/../include/dms.class.php'); + +$sprache = getSprache(); +$p=new phrasen($sprache); + +$db = new basis_db(); + +$user = get_uid(); + +if(!isset($_GET["prestudent_ids"]) || !isset($_GET["vorlage_kurzbz"])) + die($p->t('anwesenheitsliste/fehlerhafteParameteruebergabe')); + +$prestudent_ids = explode(";", $_GET["prestudent_ids"]); + +if(count($prestudent_ids) < 1) + die($p->t('anwesenheitsliste/fehlerhafteParameteruebergabe')); + + + +/* + * Temporaeren Ordner fuer die erstellung der Dokumente generieren + */ +$tmpDir = sys_get_temp_dir() . "/dokumentenakt_" . uniqid(); + +if (!file_exists($tmpDir)) + mkdir($tmpDir, 0777, true); + +/* + * converter classes + */ +$pdf = new pdf(); +$docExp = new dokument_export(); + + +/* + * Create Documents + */ +$allDocs = array(); +foreach($prestudent_ids as $pid) +{ + $prestudent = new prestudent(); + 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; + + + /* + * Get all Documents + */ + $query= ' + SELECT + titel, dms_id, inhalt + FROM + public.tbl_dokumentstudiengang + JOIN public.tbl_prestudent USING(studiengang_kz) + JOIN public.tbl_akte USING(person_id,dokument_kurzbz) + WHERE + onlinebewerbung + AND prestudent_id='.$db->db_add_param($pid, FHC_INTEGER).'; + '; + + $result = $db->db_query($query); + while($row = $db->db_fetch_object($result)) + { + + + $filename = ""; + 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 == "") + continue; + + + /* + * Determine the filetype + * and convert, if nessecary + */ + $explodedTitle = explode(".", $row->titel); + $type = $explodedTitle[count($explodedTitle)-1]; + if($type == "jpg" || $type = "jpeg") + { + $fullFilename = $tmpDir . "/".uniqid() . ".pdf"; + if(!$pdf->jpegToPdf($filename, $fullFilename)) + cleanUpAndDie($pdf->errormsg, $tmpDir); + } + else if($type == "odt" || $type == "doc" || $type == "docx") + { + $fullFilename = $tmpDir . "/".uniqid() . ".pdf"; + $docExp->convert($filename, $fullFilename, "pdf"); + } + else if($type == "pdf") + { + $fullFilename = $row->titel; + } + else + cleanUpAndDie("falscher typ TODO", $tmpDir); + + // only filled, if the file is supported + if($fullFilename != "") + { + $allDocs[] = $fullFilename; + } + + } +} + + +/* + * generate the merged PDF + */ +$finishedPdf = $tmpDir . "/Dokumentenakt.pdf"; +if(!$pdf->merge($allDocs, $finishedPdf)) + cleanUpAndDie($pdf->errormsg, $tmpDir); +$fsize = filesize($finishedPdf); + +if(!$handle = fopen($finishedPdf,'r')) + die('load failed'); + +header('Content-type: application/pdf'); +header('Content-Disposition: attachment; filename="'.$finishedPdf); +header('Content-Length: '.$fsize); + +while (!feof($handle)) +{ + echo fread($handle, 8192); +} +fclose($handle); + + + + +/* + * Cleanup + */ +removeFolder($tmpDir); + + + + + +/* + * Functions + */ +function cleanUpAndDie($msg, $tmpDir) +{ + removeFolder($tmpDir); + die($msg); +} + +function removeFolder($dir) +{ + + if($dir == "/") + return false; + if (is_dir($dir) === true) + { + $files = array_diff(scandir($dir), array('.', '..')); + foreach ($files as $file) + { + unlink($dir . "/" . $file); + } + return rmdir($dir); + } + return false; +} +?> diff --git a/content/fas.xul.php b/content/fas.xul.php index 7d7e189ff..492ca34d9 100644 --- a/content/fas.xul.php +++ b/content/fas.xul.php @@ -120,6 +120,7 @@ foreach($addon_obj->result as $addon) + @@ -475,6 +476,12 @@ foreach($addon_obj->result as $addon) + 0) + window.open('content/dokumentenakt.pdf.php?prestudent_ids='+paramList+'&output='+output+'&vorlage_kurzbz=Bewerberakt','Bewerberakt', 'height=200,width=350,left=0,top=0,hotkeys=0,resizable=yes,status=no,scrollbars=yes,toolbar=no,location=no,menubar=no,dependent=yes'); + else + alert('Bitte markieren Sie zuerst eine oder mehrere Personen'); +} + // **** // * Excel Export der Studentendaten // **** diff --git a/include/dokument_export.class.php b/include/dokument_export.class.php index f60f94c3e..c06f29abb 100644 --- a/include/dokument_export.class.php +++ b/include/dokument_export.class.php @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * Authors: Andreas Oesterreicher and + * Andreas Moik . */ require_once(dirname(__FILE__).'/vorlage.class.php'); require_once(dirname(__FILE__).'/addon.class.php'); @@ -37,8 +38,11 @@ class dokument_export /** * Konstruktor */ - public function __construct($vorlage, $oe_kurzbz=0, $version=null) + public function __construct($vorlage = null, $oe_kurzbz=0, $version=null) { + if(!isset($vorlage)) + return; + //Vorlage aus der Datenbank holen $this->vorlage = new vorlage(); if(!$this->vorlage->getAktuelleVorlage($oe_kurzbz, $vorlage, $version)) @@ -321,7 +325,7 @@ class dokument_export } else { - $data = fread($handle, filesize($file)); + $data = fread($handle, $fsize); fclose($handle); return $data; } @@ -389,5 +393,28 @@ class dokument_export } return $_xml_data->asXML(); } + + /** + * Konvertiert ein Dokument in ein anderes Format + * @param string $inFile Origin File Path + * @param string $outFile Output file + * @param string $format Format to export To + * @return boolean + */ + public function convert($inFile, $outFile, $format = "pdf") + { + $command = 'unoconv --format %s --output %s %s'; + $command = sprintf($command, $format, $outFile, $inFile); + + + exec($command, $out, $ret); + if($ret!=0) + { + $this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte informieren Sie den Administrator'; + return false; + } + + return true; + } } ?> diff --git a/include/pdf.class.php b/include/pdf.class.php new file mode 100644 index 000000000..033c0f5a6 --- /dev/null +++ b/include/pdf.class.php @@ -0,0 +1,107 @@ +. + */ + +class Pdf +{ + public $errormsg = ""; + + /** + * Fügt beliebig viele PDF Dateien zu einer zusammen + * @param array $files Array mit Dateien + * @param string $outFile Zieldatei + * @return boolean + */ + public function merge($files, $outFile) + { + $cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outFile "; + $finfo = finfo_open(FILEINFO_MIME_TYPE); + + // add all pdf files to the command + foreach($files as $f) + { + $cmd .= $f." "; + if(!file_exists($f)) + { + $this->errormsg = "File not found: '$f'"; + return false; + } + if(finfo_file($finfo, $f) != "application/pdf") + { + $this->errormsg = "Wrong format: '$f'"; + return false; + } + } + + finfo_close($finfo); + + exec($cmd, $out, $ret); + if($ret!=0) + { + $this->errormsg = 'PDF-zusammenfuegung ist derzeit nicht möglich. Bitte informieren Sie den Administrator'; + return false; + } + return true; + } + + + /** + * Konvertiert eine jpeg Datei zu einer PDF + * @param string $image jpeg Datei + * @param string $outFile Zieldatei + * @return boolean + */ + public function jpegToPdf($image, $outFile) + { + if(!file_exists($image)) + { + $this->errormsg = "File not found: '$image'"; + return false; + } + + $s = getimagesize($image); + + /* + * längere Seite ermitteln + * Hochformat wenn die Seiten gleich lang sind. + */ + if($s[0] > $s[1]) + { + $height = 595; + $width = 842; + } + else + { + $height = 842; + $width = 595; + } + + // -r300 = 300 ppi + $cmd = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -r100 -o '.$outFile.' viewjpeg.ps -c "('.$image.') << /PageSize [' . $width . ' ' . $height .'] /.HWMargins [18 18 18 13.5] /countspaces { [ exch { dup 32 ne { pop } if } forall ] length } bind def >> setpagedevice viewJPEG"'; + + exec($cmd, $out, $ret); + if($ret!=0) + { + $this->errormsg = 'jpegToPdf ist derzeit nicht möglich. Bitte informieren Sie den Administrator'; + return false; + } + return true; + } +} + diff --git a/locale/de-AT/fas.dtd b/locale/de-AT/fas.dtd index 58783c98f..61d7aa51d 100644 --- a/locale/de-AT/fas.dtd +++ b/locale/de-AT/fas.dtd @@ -191,6 +191,10 @@ + + + + diff --git a/system/dbupdate_3.2.php b/system/dbupdate_3.2.php index d309f81af..2ab852b18 100755 --- a/system/dbupdate_3.2.php +++ b/system/dbupdate_3.2.php @@ -1297,6 +1297,39 @@ if(!@$db->db_query("SELECT bezeichnung_mehrsprachig FROM public.tbl_status LIMIT } + + +/************************************ 07.16 Vorlage für bewerberakt ************************************/ +if($result = $db->db_query("SELECT * FROM public.tbl_vorlage WHERE vorlage_kurzbz='Bewerberakt'")) +{ + if($db->db_num_rows($result)==0) + { + $qry_oe = "SELECT oe_kurzbz FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz is null"; + if($result = $db->db_query($qry_oe)) + { + $qry = "INSERT INTO public.tbl_vorlage(vorlage_kurzbz, bezeichnung, anmerkung,mimetype) + VALUES('Bewerberakt','Bewerberakt Deckblatt', 'wird als Deckblatt fuer den Bewerberakt verwendet', 'application/vnd.oasis.opendocument.text');"; + + $text = file_get_contents('xsl/Bewerberakt.xsl'); + + while($row = $db->db_fetch_object($result)) + { + $qry.="INSERT INTO public.tbl_vorlagestudiengang(vorlage_kurzbz, studiengang_kz, version, text, + oe_kurzbz, style, berechtigung, anmerkung_vorlagestudiengang, aktiv) VALUES( + 'Bewerberakt',0,0,".$db->db_add_param($text).",".$db->db_add_param($row->oe_kurzbz).",null,null,'',true);"; + } + } + + if(!$db->db_query($qry)) + echo 'Bewerberakt Dokumentenvorlage: '.$db->db_last_error().'
'; + else + echo 'Bewerberakt Dokumentenvorlage hinzugefuegt
'; + } +} + + + + // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; diff --git a/system/vorlage_zip/Bewerberakt.odt b/system/vorlage_zip/Bewerberakt.odt new file mode 100644 index 000000000..88226e050 Binary files /dev/null and b/system/vorlage_zip/Bewerberakt.odt differ diff --git a/system/xsl/Bewerberakt.xsl b/system/xsl/Bewerberakt.xsl new file mode 100644 index 000000000..d8e5e30ec --- /dev/null +++ b/system/xsl/Bewerberakt.xsl @@ -0,0 +1,14 @@ + + + + + + + +Bewerberakt + + + + diff --git a/tests/codeception/tests/api/v1/MessageCept.php b/tests/codeception/tests/api/v1/MessageCept.php index 6a4146a29..64b129687 100644 --- a/tests/codeception/tests/api/v1/MessageCept.php +++ b/tests/codeception/tests/api/v1/MessageCept.php @@ -8,4 +8,14 @@ $I->haveHttpHeader("FHC-API-KEY", "testapikey@fhcomplete.org"); $I->sendGET("v1/system/message/MessagesByPersonID", array("person_id" => "1")); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); +$I->seeResponseContainsJson(["error" => 0]); + +$I->sendGET("v1/system/message/MessagesByUID", array("uid" => "mckenzie")); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); +$I->seeResponseContainsJson(["error" => 0]); + +$I->sendGET("v1/system/message/MessagesByToken", array("token" => "token")); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); $I->seeResponseContainsJson(["error" => 0]); \ No newline at end of file diff --git a/tests/codeception/tests/api/v1/PrestudentstatusCept.php b/tests/codeception/tests/api/v1/PrestudentstatusCept.php index c74f30aea..2c31f76e6 100644 --- a/tests/codeception/tests/api/v1/PrestudentstatusCept.php +++ b/tests/codeception/tests/api/v1/PrestudentstatusCept.php @@ -8,4 +8,9 @@ $I->haveHttpHeader("FHC-API-KEY", "testapikey@fhcomplete.org"); $I->sendGET("v1/crm/Prestudentstatus/Prestudentstatus", array("ausbildungssemester" => "0", "studiensemester_kurzbz" => "0", "status_kurzbz" => "0", "prestudent_id" => "0")); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); +$I->seeResponseContainsJson(["error" => 0]); + +$I->sendGET("v1/crm/Prestudentstatus/LastStatus", array("prestudent_id" => 3)); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); $I->seeResponseContainsJson(["error" => 0]); \ No newline at end of file