Source for file admin.messages.php

Documentation is available at admin.messages.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Messages
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. require_once$mainframe->getPath'admin_html' ) );
  14. require_once$mainframe->getPath'class' ) );
  15.  
  16. $task trimmosGetParam$_REQUEST'task'null ) );
  17. $cid mosGetParam$_REQUEST'cid'array) );
  18. if (!is_array$cid )) {
  19.     $cid array );
  20. }
  21.  
  22. switch ($task{
  23.     case "view":
  24.         viewMessage$cid[0]$option );
  25.         break;
  26.  
  27.     case "new":
  28.         newMessage$optionNULLNULL );
  29.         break;
  30.  
  31.     case "reply":
  32.         newMessage(
  33.             $option,
  34.             mosGetParam$_REQUEST'userid'),
  35.             mosGetParam$_REQUEST'subject''' )
  36.         );
  37.         break;
  38.  
  39.     case "save":
  40.         saveMessage$option );
  41.         break;
  42.  
  43.     case "remove":
  44.         removeMessage$cid$option );
  45.         break;
  46.  
  47.     case "config":
  48.         editConfig$option );
  49.         break;
  50.  
  51.     case "saveconfig":
  52.         saveConfig$option );
  53.         break;
  54.  
  55.     default:
  56.         showMessages$option );
  57.         break;
  58. }
  59.  
  60. function editConfig$option {
  61.     global $database$my;
  62.  
  63.     $database->setQuery"SELECT cfg_name, cfg_value FROM #__messages_cfg WHERE user_id='$my->id');
  64.     $data $database->loadObjectList'cfg_name' );
  65.  
  66.     $vars array();
  67.     $vars['lock'mosHTML::yesnoSelectList"vars[lock]"'class="inputbox" size="1"'@$data['lock']->cfg_value );
  68.     $vars['mail_on_new'mosHTML::yesnoSelectList"vars[mail_on_new]"'class="inputbox" size="1"'@$data['mail_on_new']->cfg_value );
  69.  
  70.     HTML_messages::editConfig$vars$option );
  71.  
  72. }
  73.  
  74. function saveConfig$option {
  75.     global $database$my;
  76.  
  77.     $database->setQuery"DELETE FROM #__messages_cfg WHERE user_id='$my->id');
  78.     $database->query();
  79.  
  80.     $vars mosGetParam$_POST'vars'array() );
  81.     foreach ($vars as $k=>$v{
  82.         $v $database->getEscaped$v );
  83.         $database->setQuery"INSERT INTO #__messages_cfg (user_id,cfg_name,cfg_value)"
  84.             . "\nVALUES ('$my->id','$k','$v')"
  85.         );
  86.         $database->query();
  87.     }
  88.     mosRedirect"index2.php?option=$option);
  89. }
  90.  
  91. function newMessage$option$user$subject {
  92.     global $database$mainframe$my$acl;
  93.  
  94.     // get available backend user groups
  95.     $gid $acl->get_group_id'Public Backend''ARO' );
  96.     $gids $acl->get_group_children$gid'ARO''RECURSE' );
  97.     $gids implode','$gids );
  98.  
  99.     // get list of usernames
  100.     $recipients arraymosHTML::makeOption'0''- Select User -' ) );
  101.     $database->setQuery"SELECT id AS value, username AS text FROM #__users"
  102.     ."\n WHERE gid IN ($gids)"
  103.     . "\n ORDER BY name" );
  104.     $recipients array_merge$recipients$database->loadObjectList() );
  105.  
  106.     $recipientslist =
  107.         mosHTML::selectList(
  108.             $recipients,
  109.             'user_id_to',
  110.             'class="inputbox" size="1"',
  111.             'value',
  112.             'text',
  113.             $user
  114.         );
  115.     HTML_messages::newMessage($option$recipientslist$subject );
  116. }
  117.  
  118. function saveMessage$option {
  119.     global $database$mainframe$my$mosConfig_absolute_path;
  120.     global $mosConfig_mailfrom$mosConfig_fromname;
  121.  
  122.     require_once($mosConfig_absolute_path."/includes/mambofunc.php");
  123.  
  124.     $row new mosMessage$database );
  125.     if (!$row->bind$_POST )) {
  126.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  127.         exit();
  128.     }
  129.     
  130.     require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php');
  131.     $iFilter new InputFilternullnull1);
  132.     $row->subject trim$iFilter->process$row->subject ) );
  133.     $row->message trim$iFilter->process$row->message ) );
  134.     
  135.     if (!$row->send()) {
  136.         mosRedirect"index2.php?option=com_messages&mosmsg=" $row->getError() );
  137.     }
  138.  
  139.     $msg     $row->subject.' - '.$row->message;
  140.  
  141.     $sql "SELECT a.id, a.name, a.email"
  142.         . "\nFROM #__users AS a"
  143.         . "\nWHERE a.sendEmail = '1'"
  144.         . "\nAND a.id = '".$row->user_id_to."'"
  145.     ;
  146.     $database->setQuery$sql );
  147.     $rows $database->loadObjectList();
  148.  
  149.     if ($rows{
  150.         foreach($rows as $row){
  151.             $recipient $row->email;
  152.             $subject "New private message from ".$row->name;
  153.             mosMail($mosConfig_mailfrom$mosConfig_fromname$recipient$subject$msg);
  154.         }
  155.     }
  156.     mosRedirect"index2.php?option=com_messages" );
  157. }
  158.  
  159. function showMessages$option {
  160.     global $database$mainframe$my$mosConfig_list_limit;
  161.  
  162.     $limit $mainframe->getUserStateFromRequest"viewlistlimit"'limit'$mosConfig_list_limit );
  163.     $limitstart $mainframe->getUserStateFromRequest"view{$option}limitstart"'limitstart');
  164.     $search $mainframe->getUserStateFromRequest"search{$option}"'search''' );
  165.     $search $database->getEscapedtrimstrtolower$search ) ) );
  166.  
  167.     $wheres array();
  168.     $wheres[" a.user_id_to='$my->id'";
  169.  
  170.     if (isset($search&& $search!= ""{
  171.         $wheres["(u.username LIKE '%$search%' OR email LIKE '%$search%' OR u.name LIKE '%$search%')";
  172.     }
  173.  
  174.     $database->setQuery"SELECT COUNT(*)"
  175.         . "\nFROM #__messages AS a"
  176.         . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from"
  177.         . ($wheres " WHERE " implode" AND "$wheres "" )
  178.     );
  179.     $total $database->loadResult();
  180.  
  181.     require_once$GLOBALS['mosConfig_absolute_path''/administrator/includes/pageNavigation.php' );
  182.     $pageNav new mosPageNav$total$limitstart$limit  );
  183.  
  184.     $database->setQuery"SELECT a.*, u.name AS user_from"
  185.         . "\nFROM #__messages AS a"
  186.         . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from"
  187.         . ($wheres " WHERE " implode" AND "$wheres "" )
  188.         . "\nORDER BY date_time DESC"
  189.         . "\nLIMIT $pageNav->limitstart$pageNav->limit"
  190.     );
  191.  
  192.     $rows $database->loadObjectList();
  193.     if ($database->getErrorNum()) {
  194.         echo $database->stderr();
  195.         return false;
  196.     }
  197.  
  198.     HTML_messages::showMessages$rows$pageNav$search$option );
  199. }
  200.  
  201. function viewMessage$uid='0'$option {
  202.     global $database$my$acl;
  203.  
  204.     $row null;
  205.     $database->setQuery"SELECT a.*, u.name AS user_from"
  206.         . "\nFROM #__messages AS a"
  207.         . "\nINNER JOIN #__users AS u ON u.id = a.user_id_from"
  208.         . "\nWHERE a.message_id='$uid'"
  209.         . "\nORDER BY date_time DESC"
  210.     );
  211.     $database->loadObject$row );
  212.  
  213.     $database->setQuery"UPDATE #__messages SET state='1' WHERE message_id='$uid');
  214.     $database->query();
  215.  
  216.     HTML_messages::viewMessage$row$option );
  217. }
  218.  
  219. function removeMessage$cid$option {
  220.     global $database;
  221.  
  222.     if (!is_array$cid || count$cid 1{
  223.         echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n";
  224.         exit;
  225.     }
  226.     if (count$cid )) {
  227.         $cids implode','$cid );
  228.         $database->setQuery"DELETE FROM #__messages WHERE message_id IN ($cids));
  229.         if (!$database->query()) {
  230.             echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  231.         }
  232.     }
  233.  
  234.     $limit intvalmosGetParam$_REQUEST'limit'10 ) );
  235.     $limitstart    intvalmosGetParam$_REQUEST'limitstart') );
  236.     mosRedirect"index2.php?option=$option&limit=$limit&limitstart=$limitstart);
  237. }
  238.  
  239. ?>

Documentation generated on Mon, 05 May 2008 16:15:40 +0400 by phpDocumentor 1.4.0