FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

[solved] html multiply list doesnt give all values

 


devroom
Hello,

html code
Code:
<select name="userlist" multiple size="10">
<option disabled="disabled">- Choose user -</option>
<option value="63">test 1</option>
<option value="64">test 2</option>
<option value="65">test 3</option>
</select>


This code checks if everything is given
Code:
//Get variables
   $userlist   = array( JRequest::getVar('userlist', NULL, 'POST') );
   $subject   = JRequest::getVar('subject', NULL, 'POST');
   $message   = JRequest::getVar('message', NULL, 'POST');

   //Is a message written?
   $validmsg   = JRequest::getVar('validmsg', NULL, 'POST');
   
   if($validmsg)
   {
      if (!$userlist || !$subject || !$message)
      {
         $mainframe->redirect( "index.php?option=com_pms&Itemid=$Itemid&func=new" , JText::_( 'MUST SELECT R WRITE S AND M' ) );
         exit;
      }
      else
      {
         pmsHelper::writemessage($userlist, $subject, $message);
         $mainframe->redirect( 'index.php?option=com_pms&Itemid='.$Itemid , JText::_( 'MESSAGE SENT' ) );
         exit;
      }
   }


This code inserts the message
Code:
function writemessage($userlist, $subject, $message)
   {#TODO the message is inserted twice or even more and the userlist is not working proparly
      global $mainframe, $Itemid;

      $db         =& JFactory::getDBO();
      $user      =& JFactory::getUser();
      $user_id   = $user->get('id');
      $nosend      = array();
      $i         = 0;

      //Get last variables
      $system      = JRequest::getVar('system', 0, 'POST');
      $disable   = JRequest::getVar('disable', 0, 'POST');
      $datetime   = date("Y-m-d H:i:s");

      //Make the message handable for php and mysql
      $message   = htmlspecialchars($message);
      $message   = nl2br($message);
      $message   = mysql_real_escape_string($message);

      foreach ($userlist as $receiver)
      {
         //receipent has space left for a message?
         $query      = "SELECT COUNT(*) FROM #__pms \n WHERE toid = '$receiver'";
         $db->setQuery($query);
         $total      = $db->loadResult();

         if ($total < pmsHelper::getConfig('maxmessages') || $system)
         {
            $query   = "INSERT INTO #__pms VALUES ( NULL, '$receiver', '$user_id', '$subject', '$message', '1', '1', '0', '$disable', '$system', '$datetime') ";
            $db->setQuery($query);
            if (!$db->query()) {
               JError::raiseError( 500, $db->stderror());
            }

            //mail 'new message' to user if allowed
            $query      = "SELECT mailonnew FROM #__pms_settings \n WHERE userid = '$user_id'";
            $db->setQuery($query);
            $usermailonnew   = $db->loadResult();

            if (($usermailonnew && pmsHelper::getConfig('mailonnew')) || ($system && pmsHelper::getConfig('mailonsystem')))
            {
               jimport( 'joomla.utilities.mail' );

               $query         = "SELECT email FROM #__users \n WHERE id = '$receiver'";
               $db->setQuery($query);

               $from         = $mainframe->getCfg( 'mailfrom' );
               $sender         = $user->get( 'username' );
               $email         = $db->loadResult();
               $mailsubject   = JText::_( 'NEW MESSAGE' ) . ': ' . $subject;#TODO get language from receiver
               $mailbody      = JText::_( 'NEW MESSAGE' ) . JText::_( 'FROM' ) . $user->get('username') . "\n" .
                             JText::_( 'VISIT SITE' ) . JURI::base() . 'index.php?option=com_pms&Itemid=' . $Itemid;

               // Clean the email data
               $subject      = JMailHelper::cleanSubject($mailsubject);
               $body         = JMailHelper::cleanBody($mailbody);
               $sender         = JMailHelper::cleanAddress($sender);

               // Send the email
               JUtility::sendMail($from, $sender, $email, $subject, $body);
            }
         }
         else
         {
            $nosent[$i] = $receiver;
            $i++;
         }
      }

      if ($nosend) {
         $mainframe->redirect( 'index.php?option=com_pms&Itemid=' . $Itemid , JText::_( 'FAILED INBOX FULL' ) . $nosent );
         exit;
      }
   }


The problem is that the message is only sent to the last user, but more are select. Somebody know the fix?

Grtz and thx in advance

ps. this is a component for joomla 1.5


Last edited by devroom on Fri Oct 27, 2006 8:32 pm; edited 1 time in total
shamil
Because u have to define name of select as array. Change it to
Code:
<select name="userlist[]" multiple size="10">
Then u can access its all selected elements in userlist array.
devroom
Yep worked. But found it already out myself. But thx Very Happy
Only the script select all function doesnt work anymore?
You know how to fix that too? Smile
shamil
devroom wrote:
Yep worked. But found it already out myself. But thx Very Happy
Only the script select all function doesnt work anymore?
You know how to fix that too? Smile
Which function do you mean? If it is built in function write your own function instead to select all.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.