messages.php 811 B

12345678910111213141516171819
  1. <?php
  2. require_once(realpath(dirname(__FILE__)).'/config.php');
  3. require_once(PATH_PHP.'database.php');
  4. function messages($id,$type){
  5. switch($type){
  6. case 'project':
  7. if($res = query("SELECT m.id, u.name, m.message, UNIX_TIMESTAMP(m.timestamp) as timestamp FROM `messages` m JOIN `users` u ON u.id = m.from_id WHERE m.p_id='%d'",Array($id))){
  8. return $res->fetch_all(MYSQLI_ASSOC);
  9. }
  10. break;
  11. case 'user':
  12. if($res = query("SELECT m.id, uf.name as \"from\", ut.name as \"to\", m.message, UNIX_TIMESTAMP(m.timestamp) as timestamp FROM `messages` m JOIN `users` uf ON uf.id = m.from_id JOIN `users` ut ON ut.id = m.to_id WHERE (m.from_id='%d' AND m.to_id IS NOT NULL) OR m.to_id='%d'",Array($id,$id))){
  13. return $res->fetch_all(MYSQLI_ASSOC);
  14. }
  15. break;
  16. }
  17. return Array();
  18. }
  19. ?>