Recover fhcdb_helper

This commit is contained in:
Paminger
2016-06-16 11:40:49 +02:00
parent 3df35d0ed5
commit 9ed42794a7
10 changed files with 541 additions and 685 deletions
@@ -1,62 +0,0 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Message extends FHC_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('messaging');
//$this->load->model('person/Person_model');
//$this->load->model('system/Message_model');
}
public function index()
{
//$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);
}
}
+450
View File
@@ -0,0 +1,450 @@
<?php
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2016 fhcomplete.org
* @license GPLv3
* @link https://fhcomplete.org
* @since Version 1.0.0
* @filesource
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
//require_once 'include/basis.class.php';
/**
* FHC-Auth Helpers
*
* @package FH-Complete
* @subpackage Helpers
* @category Helpers
* @author FHC-Team
* @link http://fhcomplete.org/user_guide/helpers/fhcauth_helper.html
*/
// ------------------------------------------------------------------------
//require_once('include/sprache.class.php');
class basis_db
{
protected $ci=null;
protected $db_result=null;
protected $errormsg=null;
public function __construct($ci)
{
$this->ci=$ci;
}
public function db_connect()
{
$conn_str='host='.DB_HOST.' port='.DB_PORT.' dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD;
//Connection Herstellen
if (DB_CONNECT_PERSISTENT)
{
if (!basis_db::$db_conn = pg_pconnect($conn_str))
die('Fehler beim Oeffnen der Datenbankverbindung');
}
else
{
if (!basis_db::$db_conn = pg_connect($conn_str))
die('Fehler beim Oeffnen der Datenbankverbindung');
}
}
public function db_query($sql)
{
if ($this->db_result=$this->ci->db->simple_query($sql))
return $this->db_result;
else
{
$this->errormsg.='Abfrage in Datenbank fehlgeschlagen! '.$this->db_last_error();
return false;
}
}
public function db_num_rows($result=null)
{
if (is_null($result))
return pg_num_rows($this->db_result);
else
return pg_num_rows($result);
}
public function db_fetch_object($result = null, $i=null)
{
if (is_null($result))
{
if (is_null($i))
return pg_fetch_object($this->db_result);
else
return pg_fetch_object($this->db_result, $i);
}
else
{
if (is_null($i))
return pg_fetch_object($result);
else
return pg_fetch_object($result, $i);
}
}
public function db_fetch_row($result = null, $i=null)
{
if (is_null($result))
{
if (is_null($i))
return pg_fetch_row($this->db_result);
else
return pg_fetch_row($this->db_result, $i);
}
else
{
if (is_null($i))
return pg_fetch_row($result);
else
return pg_fetch_row($result, $i);
}
}
public function db_fetch_assoc($result = null, $i=null)
{
if (is_null($result))
{
if (is_null($i))
return pg_fetch_assoc($this->db_result);
else
return pg_fetch_assoc($this->db_result, $i);
}
else
{
if (is_null($i))
return pg_fetch_row($result);
else
return pg_fetch_row($result, $i);
}
}
public function db_result($result = null, $i,$item)
{
if (is_null($result))
{
return pg_result($this->db_result, $i,$item);
}
else
{
return pg_result($result, $i,$item);
}
}
public function db_getResultJSON($result = null)
{
$rows=array();
if (is_null($result))
{
while ($r = pg_fetch_assoc($this->db_result))
$rows[] = $r;
//print json_encode($rows);
}
else
{
pg_result_seek($result, 0);
//var_dump($result);
while ($r = pg_fetch_assoc($result))
{
$rows[] = $r;
}
//print json_encode($rows);
}
return json_encode($rows);
}
public function db_last_error()
{
return pg_last_error();
}
public function db_affected_rows($result=null)
{
if (is_null($result))
return pg_affected_rows($this->db_result);
else
return pg_affected_rows($result);
}
public function db_result_seek($result=null, $offset)
{
if (is_null($result))
return pg_result_seek($this->db_result, $offset);
else
return pg_result_seek($result, $offset);
}
public function db_fetch_array($result=null)
{
if (is_null($result))
return pg_fetch_array($this->db_result);
else
return pg_fetch_array($result);
}
public function db_num_fields($result=null)
{
if (is_null($result))
return pg_num_fields($this->db_result);
else
return pg_num_fields($result);
}
/**
* Liefert den Feldnamen mit index i
*/
public function db_field_name($result=null, $i)
{
if (is_null($result))
return pg_field_name($this->db_result, $i);
else
return pg_field_name($result, $i);
}
/**
* Gibt den Speicher wieder Frei.
* (ist das sinnvoll wenn es per Value uebergeben wird??)
*/
public function db_free_result($result = null)
{
if (is_null($result))
{
return pg_free_result($this->db_result);
}
else
{
return pg_free_result($result);
}
}
/**
* Liefert die aktuelle Datenbankversion
*/
public function db_version()
{
return pg_version(basis_db::$db_conn);
}
/**
* Escaped Sonderzeichen in Variablen vor der Verwendung in SQL Statements
* um SQL Injections zu verhindern
*
*/
public function db_escape($var)
{
return pg_escape_string($var);
}
/**
* Null Value Handling und Hochkomma für Inserts / Updates
* Wenn die Uebergebe Variable leer ist, wird ein String mit null
* zurueckgeliefert, wenn nicht dann wird der string unter Hochkomma zurueckgeliefert
* es sei denn qoute=false dann wird nur der String zurueckgeliefert
*
* @param $var String-Value fuer SQL Request
* @return string
*/
public function db_null_value($var, $qoute=true)
{
if ($qoute)
return ($var!==''?$this->db_qoute($var):'null');
else
return ($var!==''?$var:'null');
}
/**
* Setzt einen String unter Hochkomma
* @param $var Value fuer Insert/Update
* @return value unter Hochkomma
*/
public function db_qoute($var)
{
return "'".$var."'";
}
/**
* Escaped einen Parameter fuer die Verwendung in Insert/Update SQL Befehlen
* Es werden abhaengig vom Typ Hochkomma oder Null hinzugefuegt
* @param $var Value der gesetzt werden soll
* @param $type Typ des Values (FHC_STRING | FHC_BOOLEAN | FHC_INTEGER | ...)
* @param $nullable boolean gibt an ob das Feld NULL sein darf. Wenn true wird
* NULL statt einem Leerstring zurueckgeliefert
* @return Escapter Value inklusive Hochkomma wenn noetig
*
* Verwendungsbeispiel:
* Update tbl_person set nachname=$this->db_add_param($var)
* Update tbl_person set aktiv=$this->db_add_param($var, FHC_BOOL, false)
* Update tbl_person set anzahlkinder=$this->db_add_param($var, FHC_INT)
*/
public function db_add_param($var, $type=FHC_STRING, $nullable=true)
{
if (($var==='' || is_null($var)) && $type!=FHC_BOOLEAN)
{
if ($nullable)
return 'null';
else
return "''";
}
switch($type)
{
case FHC_INTEGER:
$var = $this->db_escape($var);
if (!is_numeric($var) && $var!=='')
die('Invalid Integer Parameter detected:'.$var);
$var = $this->db_null_value($var, false);
break;
case FHC_LANG_ARRAY:
$sprache = new sprache();
$sprache->getAll(true);
$buf = $var;
$var = array();
$languages = $sprache->getAllIndexesSorted();
foreach($languages as $sk => $sp)
{
if (!$sp || !isset($buf[$sp]))
$var[$sk] = "";
else
$var[$sk] = $this->db_escape($buf[$sp]);
}
$var = str_replace('\\', '\\\\', $var);
$var = str_replace('"', '\\\"', $var);
$var = '\'{"' . join('","', $var) . '"}\'';
break;
case FHC_BOOLEAN:
if ($var===true)
$var='true';
elseif ($var===false)
$var='false';
elseif ($var=='' && $nullable)
$var = 'null';
else
die('Invalid Boolean Parameter detected');
break;
case FHC_STRING:
default:
$var = $this->db_escape($var);
$var = $this->db_null_value($var);
break;
}
return $var;
}
/**
* Erzeugt aus einem DB-Result-Boolean einen PHP Boolean
*/
public function db_parse_bool($var)
{
if ($var=='t')
return true;
elseif ($var=='f')
return false;
elseif ($var=='')
return '';
else
die('Invalid DB Boolean. Wrong DB-Engine?');
}
/**
* Bereitet ein Array von Elementen auf, damit es in der IN-Klausel eines
* Select Befehls verwendet werden kann.
*/
public function db_implode4SQL($array)
{
$string = '';
foreach($array as $row)
{
if ($string!='')
$string.=',';
$string.=$this->db_add_param($row);
}
return $string;
}
/**
* Erstellt aus einem DB Array ein PHP Array
* @param $var DB Result Array Spalte
* @return php array
*/
public function db_parse_array($var)
{
if ($var == '')
return;
preg_match_all('/(?<=^\{|,)(([^,"{]*)|\s*"((?:[^"\\\\]|\\\\(?:.|[0-9]+|x[0-9a-f]+))*)"\s*)(,|(?<!^\{)(?=\}$))/i', $var, $matches, PREG_SET_ORDER);
$values = array();
foreach ($matches as $match)
{
$values[] = $match[3] != '' ? stripcslashes($match[3]) : (strtolower($match[2]) == 'null' ? null : $match[2]);
}
return $values;
}
/**
* Erstellt aus einem DB Array ein PHP Array
* @param $var DB Result Array Spalte
* @return php array
*/
public function db_parse_lang_array($var)
{
if ($var == '')
return;
preg_match_all('/(?<=^\{|,)(([^,"{]*)|\s*"((?:[^"\\\\]|\\\\(?:.|[0-9]+|x[0-9a-f]+))*)"\s*)(,|(?<!^\{)(?=\}$))/i', $var, $matches, PREG_SET_ORDER);
$values = array();
$sprache = new sprache();
$sprache->loadIndexArray();
$sprache = new sprache();
$sprache->getAll(true);
$languages = $sprache->getAllIndexesSorted();
foreach ($matches as $mk => $match)
{
$values[$languages[$mk+1]] = $match[3] != '' ? stripcslashes($match[3]) : (strtolower($match[2]) == 'null' ? null : $match[2]);
}
return $values;
}
}
function indexSort($a, $b)
{
return strcmp($a->index, $b->index);
}
/**
* Bereitet ein Array von Elementen auf, damit es in der IN-Klausel eines
* Select Befehls verwendet werden kann.
*/
function dbImplode4SQL($array)
{
$string = '';
foreach($array as $row)
{
if ($string != '')
{
$string.=',';
}
$string.=$this->db_add_param($row);
}
return $string;
}
+17 -15
View File
@@ -1,17 +1,19 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php
if (! defined('BASEPATH'))
exit('No direct script access allowed');
// Account Creation
$lang['mahana_'.MSG_SUCCESS] = 'Success';
$lang['mahana_'.MSG_ERR_GENERAL] = 'Error';
$lang['mahana_'.MSG_ERR_INVALID_USER_ID] = 'No user id specified';
$lang['mahana_'.MSG_ERR_INVALID_MSG_ID] = 'No message id specified';
$lang['mahana_'.MSG_ERR_INVALID_THREAD_ID] = 'No message thread id specified';
$lang['mahana_'.MSG_ERR_INVALID_STATUS_ID] = 'No status specified';
$lang['mahana_'.MSG_ERR_INVALID_SENDER_ID] = 'Not a valid sender';
$lang['mahana_'.MSG_ERR_INVALID_RECIPIENTS] = 'No valid recipients';
$lang['mahana_'.MSG_MESSAGE_SENT] = 'Message sent';
$lang['mahana_'.MSG_STATUS_UPDATE] = 'Status updated';
$lang['mahana_'.MSG_PARTICIPANT_ADDED] = 'Participant added';
$lang['mahana_'.MSG_ERR_PARTICIPANT_EXISTS] = 'User is already participating in this thread';
$lang['mahana_'.MSG_ERR_PARTICIPANT_NONSYSTEM] = 'This user id is not in the system';
$lang['mahana_'.MSG_PARTICIPANT_REMOVED] = 'Participant removed from thread';
$lang['message_'.MSG_SUCCESS] = 'Success';
$lang['message_'.MSG_ERR_GENERAL] = 'Error';
$lang['message_'.MSG_ERR_INVALID_USER_ID] = 'No user id specified';
$lang['message_'.MSG_ERR_INVALID_MSG_ID] = 'No message id specified';
$lang['message_'.MSG_ERR_INVALID_THREAD_ID] = 'No message thread id specified';
$lang['message_'.MSG_ERR_INVALID_STATUS_ID] = 'No status specified';
$lang['message_'.MSG_ERR_INVALID_SENDER_ID] = 'Not a valid sender';
$lang['message_'.MSG_ERR_INVALID_RECIPIENTS] = 'No valid recipients';
$lang['message_'.MSG_MESSAGE_SENT] = 'Message sent';
$lang['message_'.MSG_STATUS_UPDATE] = 'Status updated';
$lang['message_'.MSG_PARTICIPANT_ADDED] = 'Participant added';
$lang['message_'.MSG_ERR_PARTICIPANT_EXISTS] = 'User is already participating in this thread';
$lang['message_'.MSG_ERR_PARTICIPANT_NONSYSTEM] = 'This user id is not in the system';
$lang['message_'.MSG_PARTICIPANT_REMOVED] = 'Participant removed from thread';
+17 -15
View File
@@ -1,17 +1,19 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php
if (! defined('BASEPATH'))
exit('No direct script access allowed');
// Account Creation
$lang['mahana_'.MSG_SUCCESS] = 'Success';
$lang['mahana_'.MSG_ERR_GENERAL] = 'Error';
$lang['mahana_'.MSG_ERR_INVALID_USER_ID] = 'No user id specified';
$lang['mahana_'.MSG_ERR_INVALID_MSG_ID] = 'No message id specified';
$lang['mahana_'.MSG_ERR_INVALID_THREAD_ID] = 'No message thread id specified';
$lang['mahana_'.MSG_ERR_INVALID_STATUS_ID] = 'No status specified';
$lang['mahana_'.MSG_ERR_INVALID_SENDER_ID] = 'Not a valid sender';
$lang['mahana_'.MSG_ERR_INVALID_RECIPIENTS] = 'No valid recipients';
$lang['mahana_'.MSG_MESSAGE_SENT] = 'Message sent';
$lang['mahana_'.MSG_STATUS_UPDATE] = 'Status updated';
$lang['mahana_'.MSG_PARTICIPANT_ADDED] = 'Participant added';
$lang['mahana_'.MSG_ERR_PARTICIPANT_EXISTS] = 'User is already participating in this thread';
$lang['mahana_'.MSG_ERR_PARTICIPANT_NONSYSTEM] = 'This user id is not in the system';
$lang['mahana_'.MSG_PARTICIPANT_REMOVED] = 'Participant removed from thread';
$lang['message_'.MSG_SUCCESS] = 'Success';
$lang['message_'.MSG_ERR_GENERAL] = 'Error';
$lang['message_'.MSG_ERR_INVALID_USER_ID] = 'No user id specified';
$lang['message_'.MSG_ERR_INVALID_MSG_ID] = 'No message id specified';
$lang['message_'.MSG_ERR_INVALID_THREAD_ID] = 'No message thread id specified';
$lang['message_'.MSG_ERR_INVALID_STATUS_ID] = 'No status specified';
$lang['message_'.MSG_ERR_INVALID_SENDER_ID] = 'Not a valid sender';
$lang['message_'.MSG_ERR_INVALID_RECIPIENTS] = 'No valid recipients';
$lang['message_'.MSG_MESSAGE_SENT] = 'Message sent';
$lang['message_'.MSG_STATUS_UPDATE] = 'Status updated';
$lang['message_'.MSG_PARTICIPANT_ADDED] = 'Participant added';
$lang['message_'.MSG_ERR_PARTICIPANT_EXISTS] = 'User is already participating in this thread';
$lang['message_'.MSG_ERR_PARTICIPANT_NONSYSTEM] = 'This user id is not in the system';
$lang['message_'.MSG_PARTICIPANT_REMOVED] = 'Participant removed from thread';
+2 -574
View File
@@ -11,582 +11,10 @@ class Message_model extends DB_Model
{
parent::__construct();
require_once APPPATH.'config/message.php';
$this->lang->load('message');
//$this->lang->load('message');
$this->dbTable = 'public.tbl_msg_message';
$this->pk = 'message_id';
}
/** -----------------------------------------------------------------
* getMessage() - will return a single message, including the status for specified user.
*
* @param integer $msg_id EQUIRED
* @param integer $person_id REQUIRED
* @return array
*/
/*function getMessage($msg_id)
{
// Validate
if (empty($msg_id))
return $this->_invalid_id(MSG_ERR_INVALID_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());
else
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.
*
* @param integer $thread_id REQUIRED
* @param integer $person_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, $person_id, $full_thread = FALSE, $order_by = 'ASC')
{
// Validate
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_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_participant p ' .
' JOIN ' . $this->db->dbprefix . 'tbl_msg_thread t ON (t.thread_id = p.thread_id) ' .
' JOIN ' . $this->db->dbprefix . 'tbl_msg_message m 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 p.person_id = ? ' .
' AND p.thread_id = ? ';
if ( ! $full_thread)
{
$sql .= ' AND m.cdate >= p.cdate';
}
$sql .= ' ORDER BY m.cdate ' . $order_by;
$result = $this->db->query($sql, array($person_id, $person_id, $thread_id));
if ($result)
return $this->_success($result->result_array());
else
return $this->_general_error();
}
/** -----------------------------------------------------------------
* get_all_threads() - will return all threads for user, including the status for specified user.
*
* @param integer $person_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($person_id, $full_thread = FALSE, $order_by = 'asc')
{
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_participant p ' .
' JOIN ' . $this->db->dbprefix . 'tbl_msg_thread t ON (t.thread_id = p.thread_id) ' .
' JOIN ' . $this->db->dbprefix . 'tbl_msg_message m 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 p.person_id = ? ' ;
if (!$full_thread)
{
$sql .= ' AND m.cdate >= p.cdate';
}
$sql .= ' ORDER BY t.thread_id ' . $order_by. ', m.cdate '. $order_by;
$result = $this->db->query($sql, array($person_id, $person_id));
if ($result)
return $this->_success($result->result_array());
else
return $this->_general_error();
}
/** -----------------------------------------------------------------
* Get all Threads Grouped
* get_all_threads_grouped() - will return all threads for user, including the status for specified user.
* - messages are grouped in threads.
*
* @param integer $person_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($person_id, $full_thread = FALSE, $order_by = 'ASC')
{
if (empty($person_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
$message = $this->get_all_threads($person_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();
}
/** -----------------------------------------------------------------
* Change Message Status
* update_message_status() - will change status on message for particular user
*
* @param integer $msg_id REQUIRED
* @param integer $person_id REQUIRED
* @param integer $status_id REQUIRED - should come from config/message.php list of constants
* @return array
*/
function update_message_status($msg_id, $person_id, $status_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);
}
if (empty($status_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID);
}
$this->db->where(array('message_id' => $msg_id, 'person_id' => $person_id ));
$this->db->update('tbl_msg_status', array('status' => $status_id ));
$rows = $this->db->affected_rows();
if ($rows == 1)
return $this->_success($rows, MSG_STATUS_UPDATE);
else
return $this->_general_error();
}
/** -----------------------------------------------------------------
* Add a Participant
* add_participant() - adds user to existing thread
*
* @param integer $thread_id REQUIRED
* @param integer $person_id REQUIRED
* @return array
*/
function addParticipant($thread_id, $person_id)
{
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if (empty($person_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if ( ! $this->valid_new_participant($thread_id, $person_id))
{
$this->_participant_error(MSG_ERR_PARTICIPANT_EXISTS);
}
if ( ! $this->application_user($person_id))
{
$this->_participant_error(MSG_ERR_PARTICIPANT_NONSYSTEM);
}
$this->db->trans_start();
$participants[] = array('thread_id' => $thread_id,'person_id' => $person_id);
$this->_insert_participants($participants);
// Get Messages by Thread
$messages = $this->_get_messages_by_thread_id($thread_id);
foreach ($messages as $message)
{
$statuses[] = array('message_id' => $message['message_id'], 'person_id' => $person_id, 'status' => MSG_STATUS_UNREAD);
}
$this->_insert_statuses($statuses);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return $this->_general_error();
}
return $this->_success(NULL, MSG_PARTICIPANT_ADDED);
}
/** ---------------------------------------------------------------
* Remove a Participant
* remove_participant() - removes user from existing thread
*
* @param integer $thread_id REQUIRED
* @param integer $person_id REQUIRED
* @return array
*/
function remove_participant($thread_id, $person_id)
{
// Validate
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if (empty($person_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
$this->db->trans_start();
$this->_delete_participant($thread_id, $person_id);
$this->_delete_statuses($thread_id, $person_id);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return $this->_success(NULL, MSG_PARTICIPANT_REMOVED);
}
return $this->_general_error();
}
/** ----------------------------------------------------------------
* Send a New Message
* 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 person_ids
* @param string $subject
* @param string $body
* @param integer $priority
* @return array
*/
function send_new_message($sender_id, $recipients, $subject, $body, $priority)
{
// Validate
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)
);
}
$this->db->trans_start();
$thread_id = $this->_insert_thread($subject);
$msg_id = $this->_insert_message($thread_id, $sender_id, $body, $priority);
// Create batch inserts
$participants[] = array('thread_id' => $thread_id,'person_id' => $sender_id);
$statuses[] = array('message_id' => $msg_id, 'person_id' => $sender_id,'status' => MSG_STATUS_READ);
if ( ! is_array($recipients) )
{
if ($sender_id != $recipients)
{
$participants[] = array('thread_id' => $thread_id,'person_id' => $recipients);
$statuses[] = array('message_id' => $msg_id, 'person_id' => $recipients, 'status' => MSG_STATUS_UNREAD);
}
}
else
{
foreach ($recipients as $recipient)
{
if ($sender_id != $recipient)
{
$participants[] = array('thread_id' => $thread_id,'person_id' => $recipient);
$statuses[] = array('message_id' => $msg_id, 'person_id' => $recipient, 'status' => MSG_STATUS_UNREAD);
}
}
}
$participants=array_unique($participants, SORT_REGULAR); // Clean if sender and recipient is the same
$this->_insert_participants($participants);
$this->_insert_statuses($statuses);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return $this->_general_error();
}
return $this->_success($thread_id, MSG_MESSAGE_SENT);
}
/** --------------------------------------------------------------
* Reply to Message
* 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($reply_msg_id, $sender_id, $body, $priority)
{
// Validate
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);
}
$this->db->trans_start();
// Get the thread id to keep messages together
if ( ! $thread_id = $this->_get_thread_id_from_message($reply_msg_id))
{
return FALSE;
}
// Add this message
$msg_id = $this->_insert_message($thread_id, $sender_id, $body, $priority);
if ($recipients = $this->_get_thread_participants($thread_id, $sender_id))
{
$statuses[] = array('message_id' => $msg_id, 'person_id' => $sender_id,'status' => MSG_STATUS_READ);
foreach ($recipients as $recipient)
{
$statuses[] = array('message_id' => $msg_id, 'person_id' => $recipient['person_id'], 'status' => MSG_STATUS_UNREAD);
}
$this->_insert_statuses($statuses);
}
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return $this->_general_error();
}
return $this->_success($msg_id, MSG_MESSAGE_SENT);
}
/** ----------------------------------------------------------------
* Get Participant List
* 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)
{
// Validate
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if ($results = $this->_get_thread_participants($thread_id, $sender_id))
return $this->_success($results);
else
return $this->_general_error();
}
/** ----------------------------------------------------------------
* Get Message Count
* get_msg_count() - returns integer with count of message for user, by status. defaults to new messages
*
* @param integer $person_id REQUIRED
* @param integer $status_id OPTIONAL - defaults to "Unread"
* @return array
*/
function get_msg_count($person_id, $status_id = MSG_STATUS_UNREAD)
{
if (empty($person_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
$result = $this->db->select('COUNT(*) AS msg_count')->where(array('person_id' => $person_id, 'status' => $status_id ))->get('tbl_msg_status');
$rows = $result->row()->msg_count;
if (is_numeric($rows))
return $this->_success($rows);
else
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* Valid New Participant - because of CodeIgniter's DB Class return style,
* it is safer to check for uniqueness first
*
* @param integer $thread_id
* @param integer $person_id
* @return boolean
*/
function valid_new_participant($thread_id, $person_id)
{
$sql = 'SELECT COUNT(*) AS count ' .
' FROM ' . $this->db->dbprefix . 'tbl_msg_participant p ' .
' WHERE p.thread_id = ? ' .
' AND p.person_id = ? ';
$query = $this->db->query($sql, array($thread_id, $person_id));
if ($query->row()->count)
{
return FALSE;
}
return TRUE;
}
/** ---------------------------------------------------------------
* Application User
*
* @param integer $person_id`
* @return boolean
*/
function application_user($person_id)
{
$sql = 'SELECT COUNT(*) AS count ' .
' FROM ' . $this->db->dbprefix . 'public.tbl_person' .
' WHERE ' . 'tbl_person.person_id' . ' = ?' ;
$query = $this->db->query($sql, array($person_id));
if ($query->row()->count)
{
return TRUE;
}
return FALSE;
}
// ------------------------------------------------------------------------
// Private Functions from here out!
// ------------------------------------------------------------------------
/**
* Insert Thread
*
* @param string $subject
* @return integer
*/
private function _insert_thread($subject)
{
$insert_id = $this->db->insert('tbl_msg_thread', array('subject' => $subject));
return $this->db->insert_id();
}
/**
* Insert Message
*
* @param integer $thread_id
* @param integer $sender_id
* @param string $body
* @param integer $priority
* @return integer
*/
private function _insert_message($thread_id, $sender_id, $body, $priority)
{
$insert['thread_id'] = $thread_id;
$insert['sender_id'] = $sender_id;
$insert['body'] = $body;
$insert['priority'] = $priority;
$insert_id = $this->db->insert('tbl_msg_message', $insert);
return $this->db->insert_id();
}
/**
* Insert Participants
*
* @param array $participants
* @return bool
*/
private function _insert_participants($participants)
{
return $this->db->insert_batch('tbl_msg_participant', $participants);
}
/**
* Insert Statuses
*
* @param array $statuses
* @return bool
*/
private function _insert_statuses($statuses)
{
return $this->db->insert_batch('tbl_msg_status', $statuses);
}
/**
* Get Thread ID from Message
*
* @param integer $msg_id
* @return integer
*/
private function _get_thread_id_from_message($msg_id)
{
$query = $this->db->select('thread_id')->get_where('tbl_msg_message', array('id' => $msg_id));
if ($query->num_rows())
{
return $query->row()->thread_id;
}
return 0;
}
/**
* Get Messages by Thread
*
* @param integer $thread_id
* @return array
*/
private function _get_messages_by_thread_id($thread_id)
{
$query = $this->db->get_where('tbl_msg_message', array('thread_id' => $thread_id));
return $query->result_array();
}
/**
* Get Thread Particpiants
*
* @param integer $thread_id
* @param integer $sender_id
* @return array
*/
private function _get_thread_participants($thread_id, $sender_id = 0)
{
$array['thread_id'] = $thread_id;
if ($sender_id) // If $sender_id 0, no one to exclude
{
$array['tbl_msg_participant.person_id != '] = $sender_id;
}
$this->db->select('tbl_msg_participant.person_id, '."CONCAT(vorname, ' ', nachname) as user_name", FALSE);
$this->db->join('public.tbl_person', 'tbl_msg_participant.person_id = ' . 'tbl_person.person_id');
$query = $this->db->get_where('tbl_msg_participant', $array);
return $query->result_array();
}
/**
* Delete Participant
*
* @param integer $thread_id
* @param integer $person_id
* @return boolean
*/
private function _delete_participant($thread_id, $person_id)
{
$this->db->delete('tbl_msg_participant', array('thread_id' => $thread_id, 'person_id' => $person_id));
if ($this->db->affected_rows() > 0)
{
return TRUE;
}
return FALSE;
}
/**
* Delete Statuses
*
* @param integer $thread_id
* @param integer $person_id
* @return boolean
*/
private function _delete_statuses($thread_id, $person_id)
{
$sql = 'DELETE s FROM tbl_msg_status s ' .
' JOIN ' . $this->db->dbprefix . 'tbl_msg_message m ON (m.message_id = s.message_id) ' .
' WHERE m.thread_id = ? ' .
' AND s.person_id = ? ';
$query = $this->db->query($sql, array($thread_id, $person_id));
return TRUE;
}
/** ---------------------------------------------------------------
* Error Particpant Exists
*
* @return array
*/
private function _participant_error($error = '')
{
return array(
'err' => 1,
'code' => 1,
'msg' => lang('mahana_' . $error)
);
}
}
/* end of file message_model.php */
/* end of file Message_model.php */
@@ -11,4 +11,15 @@ class Vorlage_model extends DB_Model
$this->dbTable = 'public.tbl_vorlage';
$this->pk = 'vorlage_kurzbz';
}
public function getMimeTypes()
{
$qry = 'SELECT DISTINCT mimetype FROM public.tbl_vorlage ORDER BY mimetype;';
if ($res = $this->db->query($qry))
return $this->_success($res);
else
return $this->_error($this->db->error());
}
}
-13
View File
@@ -1,13 +0,0 @@
<div class="row">
<div class="span4">
<h2>Nachricht <?php echo $message->message_id; ?></h2>
Absender: <?php echo $message->person_id; ?><br/>
Betreff: <?php echo $message->subject; ?><br/>
Text: <?php echo $message->body; ?><br/>
<?php
// This is an example to show that you can load stuff from inside the template file
echo $this->template->widget("organisationseinheit_widget", array('title' => 'Organisationseinheit', 'oe_kurzbz' => $message->oe_kurzbz));
?>
</div>
+40 -5
View File
@@ -1,11 +1,46 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined('BASEPATH'))
exit('No direct script access allowed');
isset($title) ? $title = 'VileSci - '.$title : $title = 'VileSci';
!isset($jquery) ? $jquery = false : $jquery = $jquery;
!isset($tablesort) ? $tablesort = false : $tablesort = $tablesort;
!isset($sortList) ? $sortList = '0,0' : $sortList = $sortList;
!isset($widgets) ? $widgets = 'zebra' : $widgets = $widgets;
!isset($headers) ? $headers = '' : $headers = $headers;
if ($tablesort)
$jquery = true;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>VileSci</title>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../skin/vilesci.css" type="text/css" />
<link rel="shortcut icon" href="../skin/images/Vilesci.ico" type="image/x-icon">
<link rel="shortcut icon" href="<?php echo base_url('skin/images/Vilesci.ico'); ?>" type="image/x-icon">
<link rel="stylesheet" href="<?php echo base_url('skin/vilesci.css'); ?>" type="text/css" />
<?php if($tablesort) : ?>
<link href="<?php echo base_url('skin/tablesort.css'); ?>" rel="stylesheet" type="text/css"/>
<?php endif ?>
<?php if($jquery) : ?>
<script src="<?php echo base_url('include/js/jquery1.9.min.js'); ?>" type="text/javascript"></script>
<?php endif ?>
<?php if($tablesort && !empty($tableid)) : ?>
<script language="Javascript" type="text/javascript">
$(document).ready(function()
{
$("#<?php echo $tableid; ?>").tablesorter(
{
sortList: [[<?php echo $sortList; ?>]],
widgets: ["<?php echo $widgets; ?>"],
headers: {<?php echo $headers; ?>}
});
});
</script>
<?php endif ?>
</head>
<body>
+2 -1
View File
@@ -50,7 +50,7 @@
"components/angular.js": "1.3.16",
"components/bootstrap": "3.3.5",
"michelf/php-markdown": "1.5.0",
"fzaninotto/faker": "1.*",
"tinymce/tinymce": "4.*",
"zetacomponents/workflow": "1.*",
"zetacomponents/document": "1.*",
"zetacomponents/workflow-database-tiein": "1.*",
@@ -59,6 +59,7 @@
},
"require-dev":
{
"fzaninotto/faker": "1.*",
"squizlabs/php_codesniffer": "2.*"
},
"config":
+2
View File
@@ -224,6 +224,8 @@ $menu=array
'name'=>'Admin', 'opener'=>'true', 'hide'=>'true', 'permissions'=>array('basis/cronjob'), 'image'=>'vilesci_admin.png',
'link'=>'left.php?categorie=Admin', 'target'=>'nav',
'Cronjobs'=>array('name'=>'Cronjobs', 'link'=>'stammdaten/cronjobverwaltung.php', 'target'=>'main','permissions'=>array('basis/cronjob')),
'Vorlagen'=>array('name'=>'Vorlagen', 'link'=>'../index.ci.php/system/Templates', 'target'=>'main','permissions'=>array('basis/cronjob')),
'Messages'=>array('name'=>'Nachrichten', 'link'=>'../index.ci.php/system/Messages', 'target'=>'main','permissions'=>array('basis/cronjob'))
),
'SD-Tools'=> array
(