diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index daf66411a..cb307908c 100644 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -155,8 +155,10 @@ $config['fhc_acl'] = array 'public.tbl_lehrverband' => 'basis/lehrverband', 'public.tbl_log' => 'basis/log', 'public.tbl_mitarbeiter' => 'basis/mitarbeiter', - 'public.tbl_msg_message' => 'basis/msg_message', - 'public.tbl_msg_thread' => 'basis/msg_thread', + 'public.tbl_msg_message' => 'basis/message', + 'public.tbl_msg_recipient' => 'basis/message', + 'public.tbl_msg_status' => 'basis/message', + 'public.tbl_msg_attachment' => 'basis/message', 'public.tbl_notiz' => 'basis/notiz', 'public.tbl_notizzuordnung' => 'basis/notizzuordnung', 'public.tbl_organisationseinheit' => 'basis/organisationseinheit', @@ -228,7 +230,5 @@ $config['fhc_acl'] = array 'wawi.tbl_rechnungstyp' => 'basis/rechnungstyp', 'wawi.tbl_zahlungstyp' => 'basis/zahlungstyp', - 'public.tbl_sprache' => 'admin', - 'public.tbl_msg_thread' => 'admin', - 'public.tbl_msg_message' => 'admin' -); \ No newline at end of file + 'public.tbl_sprache' => 'admin' +); diff --git a/application/config/migration.php b/application/config/migration.php index 33ddfa277..095644a91 100755 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -55,7 +55,8 @@ $config['migration_type'] = 'sequential'; | will migrate up. This must be set. | */ -$config['migration_table'] = 'system.ci_migrations'; +//$config['migration_table'] = 'system.ci_migrations'; // A missing feature or a bug cannot use another schema than public. Bug: tableExists only looks in the public schema. +$config['migration_table'] = 'ci_migrations'; /* |-------------------------------------------------------------------------- diff --git a/application/config/template.php b/application/config/template.php index 5dbf44178..d47a13d4f 100644 --- a/application/config/template.php +++ b/application/config/template.php @@ -10,6 +10,6 @@ | 'cache_ttl' = the time all partials should be cache in seconds, 0 means no global caching */ -$config['parser'] = FALSE; -$config['template'] = 'template'; -$config['cache_ttl'] = 0; \ No newline at end of file +$config['parser'] = TRUE; +$config['template'] = 'templates/vilesci'; +$config['cache_ttl'] = 0; diff --git a/application/controllers/DBTools.php b/application/controllers/DBTools.php index ea0b61e6f..dc3925269 100644 --- a/application/controllers/DBTools.php +++ b/application/controllers/DBTools.php @@ -91,16 +91,16 @@ class DBTools extends FHC_Controller */ public function migrate($version = 'latest') { - if ($this->cli && $this->migration->current() === false) - { - show_error($this->migration->error_string()); - } - elseif ($version != 'latest' && $version != 'current') + echo 'DB-Migration'; + if ($version != 'latest' && $version != 'current') { $this->__failed('Migration version must be either latest or current'); } - - if (!$this->migration->$version()) + elseif ($this->cli && !$this->migration->$version()) + { + show_error($this->migration->error_string()); + } + elseif (!$this->migration->$version()) { $this->__failed(); } @@ -181,6 +181,8 @@ class DBTools extends FHC_Controller $method = 'seed'; $pending = array(); + + foreach ($seeds as $number => $file) { include_once($file); @@ -203,13 +205,24 @@ class DBTools extends FHC_Controller $pending[$number] = array($class, $method); } + // Now just run the necessary seeds foreach ($pending as $number => $seed) { - log_message('debug', 'Seeding '.$method); - - $seed[0] = new $seed[0]; - call_user_func($seed); + if (is_null($name)) + { + log_message('debug', 'Seeding '.$method); + + $seed[0] = new $seed[0]; + call_user_func($seed); + } + elseif ($seed[0] == 'Seed_'.$name) + { + log_message('debug', 'Seeding '.$method); + + $seed[0] = new $seed[0]; + call_user_func($seed); + } } } diff --git a/application/controllers/api/v1/person/Adresse.php b/application/controllers/api/v1/person/Adresse.php index 0cc3b90ed..5da78c292 100644 --- a/application/controllers/api/v1/person/Adresse.php +++ b/application/controllers/api/v1/person/Adresse.php @@ -24,7 +24,7 @@ class Adresse extends APIv1_Controller { parent::__construct(); // Load model PersonModel - $this->load->model('person/adresse_model', 'AdresseModel'); + $this->load->model('person/Adresse_model', 'AdresseModel'); // Load set the uid of the model to let to check the permissions $this->AdresseModel->setUID($this->_getUID()); } @@ -67,4 +67,4 @@ class Adresse extends APIv1_Controller $this->response(); } } -} \ No newline at end of file +} diff --git a/application/controllers/organisation/Studiengang2.php b/application/controllers/organisation/Studiengang2.php new file mode 100644 index 000000000..600a1d17b --- /dev/null +++ b/application/controllers/organisation/Studiengang2.php @@ -0,0 +1,167 @@ +load->model('organisation/studiengang_model'); + $this->load->library('form_validation'); + } + + public function index() + { + $keyword = ''; + $this->load->library('pagination'); + + $config['base_url'] = base_url() . 'studiengang/index/'; + $config['total_rows'] = $this->studiengang_model->total_rows(); + $config['per_page'] = 10; + $config['uri_segment'] = 3; + $config['suffix'] = '.html'; + $config['first_url'] = base_url() . 'studiengang.html'; + $this->pagination->initialize($config); + + $start = $this->uri->segment(3, 0); + $studiengang = $this->studiengang_model->index_limit($config['per_page'], $start); + + $data = array( + 'studiengang_data' => $studiengang, + 'keyword' => $keyword, + 'pagination' => $this->pagination->create_links(), + 'total_rows' => $config['total_rows'], + 'start' => $start, + ); + + $this->load->view('tbl_studiengang_list', $data); + } + + public function search() + { + $keyword = $this->uri->segment(3, $this->input->post('keyword', TRUE)); + $this->load->library('pagination'); + + if ($this->uri->segment(2)=='search') { + $config['base_url'] = base_url() . 'studiengang/search/' . $keyword; + } else { + $config['base_url'] = base_url() . 'studiengang/index/'; + } + + $config['total_rows'] = $this->studiengang_model->search_total_rows($keyword); + $config['per_page'] = 10; + $config['uri_segment'] = 4; + $config['suffix'] = '.html'; + $config['first_url'] = base_url() . 'studiengang/search/'.$keyword.'.html'; + $this->pagination->initialize($config); + + $start = $this->uri->segment(4, 0); + $studiengang = $this->studiengang_model->search_index_limit($config['per_page'], $start, $keyword); + + $data = array( + 'studiengang_data' => $studiengang, + 'keyword' => $keyword, + 'pagination' => $this->pagination->create_links(), + 'total_rows' => $config['total_rows'], + 'start' => $start, + ); + $this->load->view('tbl_studiengang_list', $data); + } + + public function read($id) + { + $row = $this->studiengang_model->get_by_id($id); + if ($row) { + $data = array( + ); + $this->load->view('tbl_studiengang_read', $data); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function create() + { + $data = array( + 'button' => 'Create', + 'action' => site_url('studiengang/create_action'), + ); + $this->load->view('tbl_studiengang_form', $data); + } + + public function create_action() + { + $this->_rules(); + + if ($this->form_validation->run() == FALSE) { + $this->create(); + } else { + $data = array( + ); + + $this->studiengang_model->insert($data); + $this->session->set_flashdata('message', 'Create Record Success'); + redirect(site_url('studiengang')); + } + } + + public function update($id) + { + $row = $this->studiengang_model->get_by_id($id); + + if ($row) { + $data = array( + 'button' => 'Update', + 'action' => site_url('studiengang/update_action'), + ); + $this->load->view('tbl_studiengang_form', $data); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function update_action() + { + $this->_rules(); + + if ($this->form_validation->run() == FALSE) { + $this->update($this->input->post('', TRUE)); + } else { + $data = array( + ); + + $this->studiengang_model->update($this->input->post('', TRUE), $data); + $this->session->set_flashdata('message', 'Update Record Success'); + redirect(site_url('studiengang')); + } + } + + public function delete($id) + { + $row = $this->studiengang_model->get_by_id($id); + + if ($row) { + $this->studiengang_model->delete($id); + $this->session->set_flashdata('message', 'Delete Record Success'); + redirect(site_url('studiengang')); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function _rules() + { + + $this->form_validation->set_rules('', '', 'trim'); + $this->form_validation->set_error_delimiters('', ''); + } + +}; + +/* End of file Studiengang.php */ +/* Location: ./application/controllers/Studiengang.php */ diff --git a/application/controllers/system/Message.php b/application/controllers/system/Message.php index 8ed3331b6..52986e6da 100755 --- a/application/controllers/system/Message.php +++ b/application/controllers/system/Message.php @@ -1,22 +1,62 @@ load->library('Messaging'); - $this->load->model('message/Message_model'); - $this->load->model('person/Person_model'); + $this->load->library('messaging'); + //$this->load->model('person/Person_model'); + //$this->load->model('system/Message_model'); } public function index() { - $person=$this->Person_model->getPersonFromBenutzerUID('pam'); - $msg_id=1; - $msg = $this->Message_model->getMessage($msg_id, $person[0]->person_id); - //$this->load->view('welcome_message'); - //$msg = $this->Message_model->send_new_message(1, $msg_id, 'test', 'This is a test!', 1); + //$messages = $this->Message_model->getMessages(); + $msg = $this->Message_model->load(1); + if ($msg->error) + show_error($msg->retval); + + $data = array + ( + 'message' => $msg->retval[0] + ); + $v = $this->load->view('test.php', $data); + } + + public function view($msg_id) + { + $msg = $this->messaging->getMessage($msg_id); + //var_dump($msg); + if ($msg->error) + show_error($msg->retval); + if (count($msg->retval) != 1) + show_error('Nachricht nicht vorhanden! ID: '.$msg_id); + + $data = array + ( + 'message' => $msg->retval[0] + ); + var_dump($data['message']); + $v = $this->load->view('system/message', $data); + } + + public function neu() + { + //$messages = $this->Message_model->getMessages(); + $msg = $this->Message_model->load($id); + if ($msg->error) + show_error($msg->retval); + if (count($msg->retval) != 1) + show_error('Nachricht nicht vorhanden! ID: '.$id); + + $data = array + ( + 'message' => $msg->retval[0] + ); + var_dump($data); + $v = $this->load->view('system/message', $data); } } diff --git a/application/core/APIv1_Controller.php b/application/core/APIv1_Controller.php index cc3d3fef8..50b5e1f52 100644 --- a/application/core/APIv1_Controller.php +++ b/application/core/APIv1_Controller.php @@ -6,10 +6,9 @@ class APIv1_Controller extends REST_Controller { function __construct() { - parent::__construct(); - //$this->load->library('session'); // -> autoload - //$this->load->library('database'); -> autoload - + parent::__construct(); + //$this->load->library('session'); // -> autoload + //$this->load->library('database'); -> autoload } /** diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index e0c318961..f0e224914 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -8,12 +8,12 @@ class DB_Model extends FHC_Model // True if this table has a primary key that uses a sequence protected $acl; // Name of the PrimaryKey for DB-Update, Load, ... - function __construct($dbTable = null, $pk = null) + function __construct($dbTable = null, $pk = null, $hasSequence = true) { parent::__construct(); $this->dbTable = $dbTable; $this->pk = $pk; - $this->hasSequence = true; + $this->hasSequence = $hasSequence; $this->load->database(); $this->acl = $this->config->item('fhc_acl'); } @@ -427,4 +427,4 @@ class DB_Model extends FHC_Model 'msg' => lang('fhc_' . $error) ); } -} \ No newline at end of file +} diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index 7c45a2fc3..ad29804c6 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -3,9 +3,20 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class FHC_Controller extends CI_Controller { + public $uid; + function __construct() { parent::__construct(); + $this->load->library('template'); + $this->load->library('session'); //$this->load->helper('language'); + + // look if User is logged in and set uid + if (isset($_SERVER['PHP_AUTH_USER'])) + $this->uid = $_SERVER['PHP_AUTH_USER']; + if (isset($_SESSION['uid'])) + $this->uid = $_SESSION['uid']; + $this->session->set_userdata('uid', 'pam'); } -} \ No newline at end of file +} diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index 2539c7203..14b50a109 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -14,15 +14,11 @@ class FHC_Model extends CI_Model $uid = null; // Get UID from CI session - if(isset($this->session->uid)) - { + if(isset($_SESSION['uid'])) $uid = $this->session->uid; - } // Get UID from the environment (HTTP authentication via authentication.class.php) - else if(isset($_SERVER['PHP_AUTH_USER'])) - { + elseif(isset($_SERVER['PHP_AUTH_USER'])) $uid = $_SERVER['PHP_AUTH_USER']; - } // After getting UID for the first time, it saves it in CI session if (isset($uid) && !isset($this->session->uid)) diff --git a/application/libraries/FHC_Seed.php b/application/libraries/FHC_Seed.php deleted file mode 100644 index 065a19259..000000000 --- a/application/libraries/FHC_Seed.php +++ /dev/null @@ -1,170 +0,0 @@ - $val) - { - $this->{'_'.$key} = $val; - } - - log_message('info', 'Seed Class Initialized'); - - // If not set, set it - $this->_seed_path !== '' OR $this->_seed_path = APPPATH.'seeds/'; - - // Add trailing slash if not set - $this->_seed_path = rtrim($this->_seed_path, '/').'/'; - - // Load seed language - $this->lang->load('seed'); - } - - - /** - * Seeds DB with Testdata - * - * @param string $name - * @return bool - */ - function seed($name = null) - { - $seeds = $this->find_seeds(); - - if (empty($seeds)) - { - $this->_error_string = $this->lang->line('seed_none_found'); - return FALSE; - } - - $method = 'seed'; - $pending = array(); - foreach ($seeds as $number => $file) - { - include_once($file); - $class = 'Seed_'.ucfirst(strtolower($this->_get_seed_name(basename($file, '.php')))); - - // Validate the seed file structure - if ( ! class_exists($class, FALSE)) - { - $this->_error_string = sprintf($this->lang->line('seed_class_doesnt_exist'), $class); - return FALSE; - } - // method_exists() returns true for non-public methods, - // while is_callable() can't be used without instantiating. - // Only get_class_methods() satisfies both conditions. - elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class)))) - { - $this->_error_string = sprintf($this->lang->line('seed_missing_'.$method.'_method'), $class); - return FALSE; - } - - $pending[$number] = array($class, $method); - } - // Now just run the necessary seeds - foreach ($pending as $number => $seed) - { - log_message('debug', 'Seeding '.$method); - - $seed[0] = new $seed[0]; - call_user_func($seed); - } - } - - /** - * Retrieves list of available seed files - * - * @return array list of seed file paths sorted by version - */ - public function find_seeds() - { - $seeds = array(); - - // Load all *_*.php files in the seeds path - foreach (glob($this->_seed_path.'*_*.php') as $file) - { - $name = basename($file, '.php'); - - // Filter out non-seed files - if (preg_match($this->_seed_regex, $name)) - { - $number = $this->_get_seed_number($name); - - // There cannot be duplicate seed numbers - if (isset($seeds[$number])) - { - $this->_error_string = sprintf($this->lang->line('seed_multiple_version'), $number); - show_error($this->_error_string); - } - - $seeds[$number] = $file; - } - } - - ksort($seeds); - return $seeds; - } - - /** - * Extracts the seed number from a filename - * - * @param string $seed - * @return string Numeric portion of a seed filename - */ - protected function _get_seed_number($seed) - { - return sscanf($seed, '%[0-9]+', $number) - ? $number : '0'; - } -} diff --git a/application/libraries/image_moo.php b/application/libraries/Image_moo.php similarity index 100% rename from application/libraries/image_moo.php rename to application/libraries/Image_moo.php diff --git a/application/libraries/Messaging.php b/application/libraries/Messaging.php deleted file mode 100644 index 677ef2ff0..000000000 --- a/application/libraries/Messaging.php +++ /dev/null @@ -1,448 +0,0 @@ -ci =& get_instance(); - $this->ci->load->model('message/message_model'); - $this->ci->load->helper('language'); - $this->ci->lang->load('message'); - } - - // ------------------------------------------------------------------------ - - /** - * get_message() - will return a single message, including the status for specified user. - * - * @param integer $msg_id EQUIRED - * @param integer $user_id REQUIRED - * @return array - */ - function get_message($msg_id, $user_id) - { - if (empty($msg_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - } - - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if ($message = $this->ci->message_model->get_message($msg_id, $user_id)) - { - return $this->_success($message); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * get_full_thread() - will return a entire thread, including the status for specified user. - * - * @param integer $thread_id REQUIRED - * @param integer $user_id REQUIRED - * @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant - * @param string $order_by OPTIONAL - * @return array - */ - function get_full_thread($thread_id, $user_id, $full_thread = FALSE, $order_by = 'ASC') - { - if (empty($thread_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID); - } - - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if ($message = $this->ci->message_model->get_full_thread($thread_id, $user_id, $full_thread, $order_by)) - { - return $this->_success($message); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * get_all_threads() - will return all threads for user, including the status for specified user. - * - * @param integer $user_id REQUIRED - * @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant - * @param string $order_by OPTIONAL - * @return array - */ - function get_all_threads($user_id, $full_thread = FALSE, $order_by = 'ASC') - { - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - $message = $this->ci->message_model->get_all_threads($user_id, $full_thread, $order_by); - if (is_array($message)) - { - return $this->_success($message); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * get_all_threads_grouped() - will return all threads for user, including the status for specified user. - * - messages are grouped in threads. - * - * @param integer $user_id REQUIRED - * @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant - * @param string $order_by OPTIONAL - * @return array - */ - function get_all_threads_grouped($user_id, $full_thread = FALSE, $order_by = 'ASC') - { - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - $message = $this->ci->message_model->get_all_threads($user_id, $full_thread, $order_by); - if (is_array($message)) - { - $threads = array(); - - foreach ($message as $msg) - { - if ( ! isset($threads[$msg['thread_id']])) - { - $threads[$msg['thread_id']]['thread_id'] = $msg['thread_id']; - $threads[$msg['thread_id']]['messages'] = array($msg); - } - else - { - $threads[$msg['thread_id']]['messages'][] = $msg; - } - } - - return $this->_success($threads); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * update_message_status() - will change status on message for particular user - * - * @param integer $msg_id REQUIRED - * @param integer $user_id REQUIRED - * @param integer $status_id REQUIRED - should come from config/message.php list of constants - * @return array - */ - function update_message_status($msg_id, $user_id, $status_id ) - { - if (empty($msg_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - } - - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if (empty($status_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID); - } - - if ($this->ci->message_model->update_message_status($msg_id, $user_id, $status_id)) - { - return $this->_success(NULL, MSG_STATUS_UPDATE); - } - - // General Error Occurred - return $this->_general_error(); - - } - - // ------------------------------------------------------------------------ - - /** - * add_participant() - adds user to existing thread - * - * @param integer $thread_id REQUIRED - * @param integer $user_id REQUIRED - * @return array - */ - function add_participant($thread_id, $user_id) - { - if (empty($thread_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID); - } - - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if ( ! $this->ci->message_model->valid_new_participant($thread_id, $user_id)) - { - $this->_participant_error(MSG_ERR_PARTICIPANT_EXISTS); - } - - if ( ! $this->ci->message_model->application_user($user_id)) - { - $this->_participant_error(MSG_ERR_PARTICIPANT_NONSYSTEM); - } - - if ($this->ci->message_model->add_participant($thread_id, $user_id )) - { - return $this->_success(NULL, MSG_PARTICIPANT_ADDED); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * remove_participant() - removes user from existing thread - * - * @param integer $thread_id REQUIRED - * @param integer $user_id REQUIRED - * @return array - */ - function remove_participant($thread_id, $user_id) - { - if (empty($thread_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID); - } - - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if ($this->ci->message_model->remove_participant($thread_id, $user_id)) - { - return $this->_success(NULL, MSG_PARTICIPANT_REMOVED); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * send_new_message() - sends new internal message. This function will create a new thread - * - * @param integer $sender_id REQUIRED - * @param mixed $recipients REQUIRED - a single integer or an array of integers, representing user_ids - * @param string $subject - * @param string $body - * @param integer $priority - * @return array - */ - function send_new_message($sender_id, $recipients, $subject = '', $body = '', $priority = PRIORITY_NORMAL) - { - if (empty($sender_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_SENDER_ID); - } - - if (empty($recipients)) - { - return array( - 'err' => 1, - 'code' => MSG_ERR_INVALID_RECIPIENTS, - 'msg' => lang('mahana_'.MSG_ERR_INVALID_RECIPIENTS) - ); - } - - if ($thread_id = $this->ci->message_model->send_new_message($sender_id, $recipients, $subject, $body, $priority)) - { - return $this->_success($thread_id, MSG_MESSAGE_SENT); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * reply_to_message() - replies to internal message. This function will NOT create a new thread or participant list - * - * @param integer $msg_id REQUIRED - * @param integer $sender_id REQUIRED - * @param string $subject - * @param string $body - * @param integer $priority - * @return array - */ - function reply_to_message($msg_id, $sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL) - { - if (empty($sender_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_SENDER_ID); - } - - if (empty($msg_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - } - - if ($new_msg_id = $this->ci->message_model->reply_to_message($msg_id, $sender_id, $body, $priority)) - { - return $this->_success($new_msg_id, MSG_MESSAGE_SENT); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * get_participant_list() - returns list of participants on given thread. If sender_id set, sender_id will be left off list - * - * @param integer $thread_id REQUIRED - * @param integer $sender_id REQUIRED - * @return array - */ - function get_participant_list($thread_id, $sender_id = 0) - { - if (empty($thread_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID); - } - - if ($participants = $this->ci->message_model-> get_participant_list($thread_id, $sender_id)) - { - return $this->_success($participants); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - - /** - * get_msg_count() - returns integer with count of message for user, by status. defaults to new messages - * - * @param integer $user_id REQUIRED - * @param integer $status_id OPTIONAL - defaults to "Unread" - * @return array - */ - function get_msg_count($user_id, $status_id = MSG_STATUS_UNREAD) - { - if (empty($user_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - - if (is_numeric($message = $this->ci->message_model->get_msg_count($user_id, $status_id))) - { - return $this->_success($message); - } - - // General Error Occurred - return $this->_general_error(); - } - - // ------------------------------------------------------------------------ - // Private Functions from here out! - // ------------------------------------------------------------------------ - - /** - * Success - * - * @param mixed $retval - * @return array - */ - private function _success($retval = '', $message = MSG_SUCCESS) - { - return array( - 'err' => 0, - 'code' => MSG_SUCCESS, - 'msg' => lang('mahana_' . $message), - 'retval' => $retval - ); - } - - // ------------------------------------------------------------------------ - - /** - * Invalid ID - * - * @param integer config.php error code numbers - * @return array - */ - private function _invalid_id($error = '') - { - return array( - 'err' => 1, - 'code' => $error, - 'msg' => lang('mahana_'.$error) - ); - } - - // ------------------------------------------------------------------------ - - /** - * Error Particpant Exists - * - * @return array - */ - private function _participant_error($error = '') - { - return array( - 'err' => 1, - 'code' => 1, - 'msg' => lang('mahana_' . $error) - ); - } - - - // ------------------------------------------------------------------------ - - /** - * General Error - * - * @return array - */ - private function _general_error() - { - return array( - 'err' => 1, - 'code' => MSG_ERR_GENERAL, - 'msg' => lang('mahana_'.MSG_ERR_GENERAL) - ); - } -} diff --git a/application/migrations/008_message.php b/application/migrations/008_message.php index 0621272dc..5cc00c48f 100644 --- a/application/migrations/008_message.php +++ b/application/migrations/008_message.php @@ -8,14 +8,25 @@ class Migration_Message extends CI_Migration { { if (! $this->db->table_exists('public.tbl_msg_message')) { + $this->db->insert('system.tbl_berechtigung', array( + 'berechtigung_kurzbz' => 'basis/message', + 'beschreibung' => 'Nachrichtensystem von FH-Complete')); + $this->db->insert('system.tbl_rolleberechtigung', array( + 'berechtigung_kurzbz' => 'basis/message', + 'rolle_kurzbz' => 'admin', + 'art' => 'suid')); + $query= " CREATE TABLE public.tbl_msg_message ( message_id serial, - thread_id bigint NOT NULL, + person_id bigint NOT NULL, + subject varchar(256) NOT NULL, body text NOT NULL, priority smallint NOT NULL DEFAULT 0, - person_id bigint NOT NULL, - cdate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + relationmessage_id bigint, + oe_kurzbz varchar(32), + insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + insertvon varchar(32), PRIMARY KEY (message_id) ); COMMENT ON COLUMN public.tbl_msg_message.person_id IS 'Sender'; @@ -27,37 +38,45 @@ class Migration_Message extends CI_Migration { GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_message_message_id_seq TO admin; GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_message_message_id_seq TO vilesci; - CREATE TABLE public.tbl_msg_participant ( + CREATE TABLE public.tbl_msg_recipient ( person_id bigint NOT NULL, - thread_id bigint NOT NULL, - cdate timestamp NOT NULL DEFAULT now(), - PRIMARY KEY (person_id,thread_id) + message_id bigint NOT NULL, + insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + insertvon varchar(32), + PRIMARY KEY (person_id,message_id) ); - GRANT SELECT ON TABLE public.tbl_msg_participant TO web; - GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_participant TO admin; - GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_participant TO vilesci; + GRANT SELECT ON TABLE public.tbl_msg_recipient TO web; + GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_recipient TO admin; + GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_recipient TO vilesci; CREATE TABLE public.tbl_msg_status ( message_id bigint NOT NULL, person_id bigint NOT NULL, status smallint NOT NULL, + statusinfo text, + insertamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + insertvon varchar(32), + updateamum timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + updatevon varchar(32), PRIMARY KEY (message_id,person_id) ); GRANT SELECT ON TABLE public.tbl_msg_status TO web; GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_status TO admin; GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_status TO vilesci; - CREATE TABLE public.tbl_msg_thread ( - thread_id serial, - subject text, - PRIMARY KEY (thread_id) + CREATE TABLE public.tbl_msg_attachment ( + attachment_id serial, + message_id bigint NOT NULL, + name text, + filename text, + PRIMARY KEY (message_id) ); - GRANT SELECT ON TABLE public.tbl_msg_thread TO web; - GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_thread TO admin; - GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_thread TO vilesci; - GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_thread_thread_id_seq TO web; - GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_thread_thread_id_seq TO admin; - GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_thread_thread_id_seq TO vilesci; + GRANT SELECT ON TABLE public.tbl_msg_attachment TO web; + GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_attachment TO admin; + GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tbl_msg_attachment TO vilesci; + GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_attachment_attachment_id_seq TO web; + GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_attachment_attachment_id_seq TO admin; + GRANT SELECT, UPDATE ON SEQUENCE public.tbl_msg_attachment_attachment_id_seq TO vilesci; "; if (!$this->db->simple_query($query)) { @@ -68,10 +87,21 @@ class Migration_Message extends CI_Migration { public function down() { - $this->dbforge->drop_table('public.tbl_msg_message'); - $this->dbforge->drop_table('public.tbl_msg_participant'); - $this->dbforge->drop_table('public.tbl_msg_status'); - $this->dbforge->drop_table('public.tbl_msg_thread'); + try + { + $this->db->delete('system.tbl_rolleberechtigung', array('berechtigung_kurzbz' => 'basis/message')); + $this->db->delete('system.tbl_berechtigung', array('berechtigung_kurzbz' => 'basis/message')); + $this->dbforge->drop_table('public.tbl_msg_recipient'); + $this->dbforge->drop_table('public.tbl_msg_status'); + $this->dbforge->drop_table('public.tbl_msg_attachment'); + $this->dbforge->drop_table('public.tbl_msg_message'); + echo "Table public.tbl_msg_message, public.tbl_msg_status, public.tbl_msg_attachment and public.tbl_msg_recipient dropped!"; + } + catch(Exception $e) + { + echo 'Exception abgefangen: ', $e->getMessage(), "\n"; + echo $this->db->error(); + } } } diff --git a/application/models/organisation/Organisationseinheit_model.php b/application/models/organisation/Organisationseinheit_model.php index e64654872..840594af0 100644 --- a/application/models/organisation/Organisationseinheit_model.php +++ b/application/models/organisation/Organisationseinheit_model.php @@ -10,4 +10,31 @@ class Organisationseinheit_model extends DB_Model $this->dbTable = 'public.tbl_organisationseinheit'; $this->pk = 'oe_kurzbz'; } -} \ No newline at end of file + + public function getRecursiveList() + { + $qry = "WITH RECURSIVE tree (oe_kurzbz, bezeichnung,path) AS + ( + SELECT + oe_kurzbz, + bezeichnung||' ('||organisationseinheittyp_kurzbz||')' AS bezeichnung, + oe_kurzbz||'|' AS path + FROM tbl_organisationseinheit + WHERE oe_parent_kurzbz IS NULL AND aktiv + UNION ALL + SELECT + oe.oe_kurzbz, + oe.bezeichnung||' ('||oe.organisationseinheittyp_kurzbz||')' AS bezeichnung, + tree.path ||oe.oe_kurzbz||'|' AS path + FROM tree + JOIN tbl_organisationseinheit oe ON (tree.oe_kurzbz=oe.oe_parent_kurzbz) + ) + SELECT oe_kurzbz AS value, substring(regexp_replace(path, '[A-z]+\|', '-','g')||bezeichnung,2) AS name, path FROM tree ORDER BY path;"; + + + if ($res = $this->db->query($qry)) + return $this->_success($res); + else + return $this->_error($this->db->error()); + } +} diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index d2f503eea..a0a1c54f8 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -23,29 +23,19 @@ class Message_model extends DB_Model * @param integer $person_id REQUIRED * @return array */ - function getMessage($msg_id, $person_id) + /*function getMessage($msg_id) { // Validate if (empty($msg_id)) - { return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); - } - if (empty($person_id)) - { - return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); - } - $sql = 'SELECT m.*, s.status, t.subject, ' . "CONCAT(vorname, ' ', nachname) as user_name" . - ' FROM ' . $this->db->dbprefix . 'tbl_msg_message m ' . - ' JOIN ' . $this->db->dbprefix . 'tbl_msg_thread t ON (m.thread_id = t.thread_id) ' . - ' JOIN ' . $this->db->dbprefix . 'public.tbl_person' . ' ON (' . 'tbl_person.person_id' . ' = m.sender_id) '. - ' JOIN ' . $this->db->dbprefix . 'tbl_msg_status s ON (s.message_id = m.message_id AND s.person_id = ? ) ' . - ' WHERE m.message_id = ? ' ; - $result = $this->db->query($sql, array($person_id, $msg_id)); + + $sql = 'SELECT * FROM tbl_msg_message JOIN tbl_person USING (person_id) WHERE message_id=?' ; + $result = $this->db->query($sql, array($msg_id)); if ($result) - return $this->_success($result->result_array()); + return $this->_success($result->result()); else - return $this->_general_error(); - } + return $this->_error($this->db->error(), FHC_DB_ERROR); + }*/ /** ----------------------------------------------------------------- * Get a Full Thread * get_full_thread() - will return a entire thread, including the status for specified user. diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php new file mode 100644 index 000000000..b1acf5b61 --- /dev/null +++ b/application/models/system/Recipient_model.php @@ -0,0 +1,15 @@ +dbTable = 'public.tbl_msg_recipient'; + $this->pk = array('person_id', 'message_id'); + $this->hasSequence = false; + } +} diff --git a/application/models/system/Thread_model.php b/application/models/system/Thread_model.php deleted file mode 100644 index f5f1ee3ca..000000000 --- a/application/models/system/Thread_model.php +++ /dev/null @@ -1,14 +0,0 @@ -dbTable = 'public.tbl_msg_thread'; - $this->pk = 'thread_id'; - } -} diff --git a/application/seeds/002_prestudent.php b/application/seeds/002_prestudent.php new file mode 100644 index 000000000..5b8e99cc0 --- /dev/null +++ b/application/seeds/002_prestudent.php @@ -0,0 +1,47 @@ +fhc =& get_instance(); + $this->fhc->load->model('crm/Prestudent_model'); + + for ($i = 0; $i < $limit; $i++) + { + echo "."; + $data = array( + 'person_id' => $i+3, // start with person_id 3 + 'aufmerksamdurch_kurzbz' => 'k.A.', + 'studiengang_kz' => $this->fhc->faker->firstName, + 'nachname' => $this->fhc->faker->lastName, + //'address' => $this->faker->streetAddress, + 'gebort' => $this->fhc->faker->city, + //'state' => $this->faker->state, + //'country' => $this->faker->country, + //'postcode' => $this->faker->postcode, + //'email' => $this->faker->email, + //'email_verified' => mt_rand(0, 1) ? '0' : '1', + //'phone' => $this->faker->phoneNumber, + 'gebdatum' => $this->fhc->faker->dateTimeThisCentury->format('Y-m-d H:i:s'), + //'registration_date' => $this->faker->dateTimeThisYear->format('Y-m-d H:i:s'), + //'ip_address' => mt_rand(0, 1) ? $this->faker->ipv4 : $this->faker->ipv6, + ); + + $this->fhc->Prestudent_model->insert($data); + } + + echo PHP_EOL; + + } + + public function truncate() + { + //$this->db->query('EMPTY TABLE public.person;'); + } +} + diff --git a/application/seeds/003_message.php b/application/seeds/003_message.php new file mode 100644 index 000000000..f5ed383a7 --- /dev/null +++ b/application/seeds/003_message.php @@ -0,0 +1,50 @@ +fhc =& get_instance(); + $this->fhc->load->model('system/Recipient_model'); + $this->fhc->Recipient_model->setUid('admin'); + $this->fhc->load->model('system/Message_model'); + + for ($i = 0; $i < $limit; $i++) + { + echo "."; + + $data = array + ( + 'subject' => $this->fhc->faker->sentence(4, true), + 'body' => $this->fhc->faker->text(400), + 'person_id' => $i%5+1 + ); + $message = $this->fhc->Message_model->insert($data); + + $data = array + ( + 'message_id' => $message->retval, + 'person_id' => $i%5+2, + 'insertvon' => 'seed' + ); + $recipient = $this->fhc->Recipient_model->insert($data); + if ($recipient->error) + show_error($recipient->retval); + //for ($j=1; $j<10; $j++) + // $this->fhc->Message_model->addRecipient($thread->retval, $i+$j+5); + } + + echo PHP_EOL; + + } + + public function truncate() + { + //$this->db->query('EMPTY TABLE public.person;'); + } +} + diff --git a/application/views/system/message.php b/application/views/system/message.php new file mode 100644 index 000000000..ab67ecceb --- /dev/null +++ b/application/views/system/message.php @@ -0,0 +1,13 @@ +
+
+

Nachricht message_id; ?>

+ +Absender: person_id; ?>
+Betreff: subject; ?>
+Text: body; ?>
+template->widget("organisationseinheit_widget", array('title' => 'Organisationseinheit', 'oe_kurzbz' => $message->oe_kurzbz)); +?> + +
diff --git a/application/views/templates/vilesci.php b/application/views/templates/vilesci.php new file mode 100644 index 000000000..0d55734c7 --- /dev/null +++ b/application/views/templates/vilesci.php @@ -0,0 +1,42 @@ + + + + <?php echo $this->template->title->default("Default title"); ?> + + + + template->meta; ?> + template->stylesheet; ?> + + + +template->widget("navigation", array('title' => 'Project name')); +?> + +
+ + template->content; + ?> + +
+ +
+

+ template->footer->prepend("© Special Company 2012 - "); + ?> +

+
+ +
+ + +template->javascript; ?> + + + \ No newline at end of file diff --git a/application/views/widgets/navigation.php b/application/views/widgets/navigation.php new file mode 100644 index 000000000..6baca95f5 --- /dev/null +++ b/application/views/widgets/navigation.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/application/views/widgets/organisationseinheit.php b/application/views/widgets/organisationseinheit.php new file mode 100644 index 000000000..52b0f19b1 --- /dev/null +++ b/application/views/widgets/organisationseinheit.php @@ -0,0 +1,8 @@ + + diff --git a/application/widgets/navigation.php b/application/widgets/navigation.php new file mode 100644 index 000000000..67e1af8b2 --- /dev/null +++ b/application/widgets/navigation.php @@ -0,0 +1,17 @@ +view('widgets/navigation', $data); + } + +} \ No newline at end of file diff --git a/application/widgets/organisationseinheit_widget.php b/application/widgets/organisationseinheit_widget.php new file mode 100644 index 000000000..6a9789dd1 --- /dev/null +++ b/application/widgets/organisationseinheit_widget.php @@ -0,0 +1,26 @@ +load->model('organisation/Organisationseinheit_model'); + $res = $this->Organisationseinheit_model->getRecursiveList(); + var_dump($res); + foreach ($res->retval->result() as $obj) + { + $item = array('name' => $obj->name, 'value' => $obj->value); + if (isset($data['oe_kurzbz']) && $obj->value == $data['oe_kurzbz']) + $item['selected'] = true; + else + $item['selected'] = false; + $data['items'][] = $item; + } + + $this->view('widgets/organisationseinheit', $data); + } + +}