Features ¶
- Enable/disable user-to-user messaging, Ie. disable to make simple customer support messaging between admin/users only.
- Enable/Disable Inbox/Sent/Trash
- Works with Yii-User / Rights modules
- Custom themes / multiple layouts
- Enable/disable trashcan/recycling
- Enable/disable dragndrop trash
- Enable/disable users can see when recipient reads their message.
- Html Purify Admin/User input separately
- Create site news plugin using publicly accessible mailbox
To Do ¶
I will try to get these features working within a few days...
- CC Your newsletter etc to local mailbox using templates
Notes ¶
I am currently developing this module as part of another project. As the project progresses I will continue to update this extension. So please be warned that right now this module is still being developed and unknown bugs/issues may exists. Once all the features have been implemented I will do more extensive bug/browser compatibility checks and hopefully have a stable release candidate for v1.0. So if you decide to use this module in your project it's recommended that you follow this extension for updates until I get a stable version released (ie. v1.0).
Requirements ¶
Yii 1.1 or above
Browser Requirements ¶
This module uses Javascript for some of it's features, however, you do not need Javascript enabled to use this module. All features in this module using Javascript should degrade gracefully.
The only known compatibility issues so far are in the HTML/CSS.
- FF 3+
- IE 5.5+
- Chrome 1+
- Safari 4+
- Minefield 3+
- Flock 2+
- Seamonkey 2+
- Konqueror 3+
- Epiphany 2+
- Iceape 2+
- Iceweasal 3.5+
I have also tested this module on Netscape 10 and Opera 9 but could not find older versions to test. I will get all browsers to display properly before releasing v1.0.
Usage ¶
Unzip to modules directory.
Install data/structure.sql
If you want to alter the table names edit the following lines in MailboxModule.php
const TBL_CONV = '{{mailbox_conversation}}';
const TBL_MSG = '{{mailbox_message}}';
Add Module ¶
Add the module inside your main config file.
return array(
...
'modules'=array(
...
'mailbox'=>
array(
'userClass' => 'User',
'userIdColumn' => 'id',
'usernameColumn' => 'username',
....more options here....
),
...
);
Module Options
Full list of module config options.
- NOTE: The following options do not have an affect if you are using an authManager such as Rights. In this case the authManager will control the access.
- sendMsgs
- sentbox
- trashbox
- userClass - the name of the user model class.
- userIdColumn - the name of the id column in the user table.
- usernameColumn - the name of the username column in the user table.
- superuserColumn - the name of the column in your User model that defines whether user is an admin or not.
- deletedUser - text to display if user not found.
- pageSize - number of conversations to display per page.
- authManager - if you want to use an authManager (such as the Rights module) to control the access rules then set to true, if your using the Rights module specifically set to 'rights' in order to include the Rights filter.
- readOnly - enable a read-only mailbox for regular users. Admins will still have fully functional mailbox.
- userToUser - whether to allow user's to message other users. False would means users can only contact admins.
- sendMsgs - whether or not to allow users to send messages.
- sentbox - whether or not to enable/disable sent folder for viewing sent messages.
- trashbox - whether or not to enable/disable trash folder for recycling deleted messages. If trashbox is enabled then you must run the cron() method at least once daily, ideally after midnight or each morning.
- recyclePeriod - number of days to keep deleted items in trash folder before being permanently deleted by the cron() method.
- dragDelete - enable/disable drag-n-drop deleting.
- confirmDelete - wether to ask the user for confirmation before deleting messages. Note that if trashbox is turned off, values of 1 and 2 have the same effect (since messages are always deleted permanently).
- 0 - Never ask for user confirmation.
- 1 - Ask for user confirmation, but only when deleting permanently.
- 2 - Ask for user confirmation when moving messages to trash, and when deleting permanently (ie. deleting from trash).
- recipientRead - whether to allow users, when viewing the sent folder, to see if recipient has read the sent message.
- cssFile - set to custom css file location relative to base URL or set to false to skip css includes.
- menuPosition - set to either 'left' or 'top' to position the mailbox menu. If readOnly set to true this is ignored for user and only applied for admins (since there is no menu in readOnly mode).
- cssFileColumn - custom left menu css.
- juiThemes - apply jQuery UI widget styles. Can be one of the following:
- 'none' Don't add any jQuery UI themes.
- 'basic' Add themes to buttons and some elements but keep the background/font color of the parent element. Ie. <body> or #content
- 'widget' Full jQuery UI styling.
- juiButtons - enable/disable the JUI themes for buttons. Eg. if you want to use Twitter Bootstrap buttons instead.
- juiIcons - whether to add icons to menu buttons (only if juiButtons is enabled)
- defaultSubject - default subject to use when no subject is provided.
- allowableCharsSubject - list of allowable characters to check Subject field against using case-insensitive regular expression. Square brackets '[]', dashes, single quotes, and slashes need to be escaped in order to be used literally.
- adminHtml - HTML Purify options array used to purify HTML input from admins. See http://htmlpurifier.org/live/configdoc/plain.html for list of options. Set to an empty string to strip all HTML tags from message input.
- html - HTML Purify options array used to purify HTML input from non-admins. See http://htmlpurifier.org/live/configdoc/plain.html for list of options. Set to an empty string to strip all HTML tags from message input.
- allowLookupById - whether to allow users to be able to enter user Id's instead of username when sending messages.
- allowUsernameSearch - whether to allow users to be able to search list of usernames to contact when sending messages.
- editToField - whether to allow users to be able to edit the To field when sending messages.
- userSupportList - whether to create a drop down menu for the To field ( from array created by getUserSupportList() method). This attribute is always true for admins unless the getUserSupportList() method returns false.
- linkUser - whether to create a link for the From field to user's profile etc (link created by getUrl() method). This attribute is always true for admins unless the getUrl() method returns false.
- checksums - whether to use checksums when storing messages. Checksums can be used not only for validating data but also to help implement certain spam protection. Eg. if a user copy and paste a message and sends it to multiple users you can easily find these messages by searching for other messages with the same checksum.
- alternateRows - whether to alternate the row colors when viewing message list (ie. inbox etc).
- newsUserId - the Id of the user account used for the site news.
Define Wrapper Functions ¶
Edit the following functions in the file /module/mailbox/MailboxModule.php >*Note if you are using the User module from Yii extensions (Yii-User) then you do not need to configure the following functions. Unless if you'd like to customize the From label or modify how the auto complete is handled.
getUserId($username='')
getUserName($userid='')
getFromLabel($userid)
getUrl($userid)
isAdmin($userid='')
0.2.1
- Fixed CSS/display issues
- Browser compatibility testing (display only)
0.2
- Reorganized module - Changed all config variables to be regular class properties (ie. not static vars) so that they can now be set in the config array.
- Added JUI widget styling
- Added basic site news feature (still in development)
- Added qTip 2 for tooltips and growls (may also be used for other features in the future ie. calendar etc.)
- Added more options to module config
- Added user support list - dropdown/combobox that lets user select from a predefined list of user's to contact.
- Fixed one major bug/issue - In previous version all messages would be deleted when conversation was destroyed.
0.1
- Initial public release
If you are using v0.1 please change line 473 in models/Mailbox.php from this...
```php $msg_count=Message::model()->conversation($this->conversation_id)->deleteAll(); ```to this..
```php $msg_count=Message::model()->deleteAll('conversation_id=:cid',array(':cid'=>$this->conversation_id)); ``` ##Resources [View Demo](http://www.cgihub.com/mailbox "Project Demo")
What the hell...
There are no resources to download and the aim of the link is not correct...
No source?
No source?
well, gonna following first...
I've created something similar but not with that much of feature so
looking forward to seeing the source.
Demo + Sources
Hey guys,
Sorry I didn't realize this would get such a quick response. The demo link is working now. I forgot to update the DNS, but had it set locally so it worked for me.
I am working on the sources .zip right now. Should have them up in a hour or so. I have to round out a working version first (remove features not yet complete). My initial release won't have the templates feature or admin section. I am still working on finishing those parts along with a few more features. Hopefully it will all be done by next week.
Uploaded Zips...
I uploaded the sources... but I found an issue after I uploaded, so I've re-uploaded, however one person seems to have downloaded it already. So if your that one person who doesn't see the mailbox menu when logged-in as admin please re-download. I also corrected the wrapper functions so that they work with the Yii-User extension out-of-box.
Thread oriented with multiple recivers
Hello derekisbusy,
I was about to develope a module like yours for my eCommerce platform, so it's nice to see an already developed extensions from you. However I was considerating a nice featured to allow messaging like Facebook does, you know, it's the "modern message system" with 2 main features:
-You can use admin to all (or maybe grouped) users "push" notifications (like facebook does with notifications, mentions, likes, etc)
-And you can send messages to multiples users like you can in Facebook when you send a message to multiple receivers.
This kind of messaging used to be called thread oriented, because it's like if you subscribe to a thread or multiple threads shared by users and admin. Its faster and very escalable, and maybe its a good time for you to adapt your extension to that style.
Im leting you here 2 links with a nice discussion about that:
http://stackoverflow.com/questions/6420264/creating-a-threaded-private-messaging-system-like-facebook-and-gmail
http://stackoverflow.com/questions/6541302/thread-messaging-system-database-schema-design
I'd like if you could tell me if you would consider to adapt your extension to this style.
thanks,
alex
Thanks for your amazing extensions.
Thanks so much for your great extension.
I am waiting for your next generation... So i can totally replace my old message module and change to yours.
That is just so good. I love it.
Waiting for your ext!
I will keep updating.
Again, thanks so much man.
I just tried it . So good!
I just tried your extension.
So good!
I like your chat format (just like iPhone's sms)
looking forward to your new features!!!
1.CC Your newsletter etc to local mailbox using templates
2.setup a read-only config to make a quick site news plugin.
That would make your extension the best message module in yii.
Nice work!!
Thanks
released v0.2
Just uploaded a new version. Will update the documentation to reflect the changes here shortly.
@jzhong5 Thanks for the feedback :)
@aleksdj Yes, I was thinking about that too. I will definitely make a threaded messaging system in the future. However for now I am just going to try to get this non-threaded version working solid. I still have a few more features I would like to add to this module first before moving on to a threaded version. And I will probably create the threaded version as a different extension, since it could be used to create more than just a mailbox (eg. threaded comments, walls, or even a simple forum).
New features
Is there any chance you can make a function called getUnreadedCount or something like that?
So people can read how many unreaded messages they have in the index page. like this
Login|Profile|Mailbox(2)....
get new msgs count
@jzhong5 You can use the following method...
MailboxModule::getNewMsgs();
This is equivalent to the getCountUnread() you proposed. So in your main.php layout (or other layout file) add something like..
Mailbox (<?php echo MailboxModule::getNewMsgs(); ?>)
I will upload a new release tomorrow and add this to the documentation.
Thanks
that works. it's great!
Thanks
Nice Work.
Thanks
send message to others via url-command?
Thanks for this amazing ext.
Hi, is there a way to send message to others via link?
Like I click on a link:
www.123.com/mailbox?receiver=demo
So after I clicked on this link, the receiver will be automatically completed by 'demo'....?
Then we can click on a link and send message to that user......
Thank you!
$.yiimailbox is undefined
Hello..
thanks for your great extensions.
when i use this on my site, on index page its display this error in my console.
why...?
sorry for my english.
TypeError: $.yiimailbox is undefined http://localhost/assets/38eb2e7a/js/menu.js Line 4
Crontabs are buggy
It always gives me undefined column in crontabs..I guess you have some typos or something like that?
I tried to fixed but failed..
medical issues
I know I had high hopes for getting this project finished a long time ago
but I was struck with some...
severe medical issues that may lead to my death.
BTW anybody want to take this project over if I do die?
I am also dealing with legal issues against some cowards that tried to murder me with poison.
I'm not fully operational at the moment. Give a few days, and I'll get back to it.
Sorry for letting you guys down.
@zainiafzan I'll add the proper fix in the next version. But a hot fix that should work is to simply add the following to your main layout somewhere near the top...
<script type="text/javascript"> <!--- $.yiimailbox={}; //--> </script>
Get well soon
Hello Derek,
tq for your answer & Get well soon.
God bless you.
@derek
What just happened???
God bless you.
Best wishes,
jimmy
Error in Chrome while deleting an element
Hi I am facing a problem in chrome. While i am going to delete any item after selecting and deleting its not deleting. not even read and unread.
In console its giving error
"Uncaught TypeError: Cannot call method 'attr' of null mailbox.js:303
$.yiimailbox.submitAjax mailbox.js:303
$.yiimailbox.updateMailbox.$.draggable.containment mailbox.js:61
jQuery.event.dispatch jquery.js:3332
jQuery.event.add.elemData.handle.eventHandle"
While the same code is running in firefox and Ie.
don't know why.. Please help me. I am stuck.
Is this project still alive...? Is there a way to hide the dropdown menu?
Is this project still alive...?...Is there a way to hide the dropdown menu so the user can not see all the user list ?
hide the dropdown menu from to field
Hii jiaming,
you change in modules/mailbox/views/message/compose.php on line no 28,
from here you have to just remove 'id'=>'message-to' and you are done.
Use of php cron script
I really like this mailbox demo. But i can't implement that in my application. I completed the steps till "Define Wrapper Functions". Where i put this code "MailboxModule::cron();" in my application?
i dont knowthe path of php cron script...
reply:Use of php cron script
hii Rvr101,
Is this mailbox working in your application or not?
If not working proper then please tell what is the error?
Because for basic use of mailbox, Cron job configuration not required at first stage as per my knowledge,i used this mailbox.
its working best for me.
PHP error-
This is my error in this case-
"Only variables should be assigned by reference"
C:\xampp\htdocs\yii\demos\mailbox\protected\modules\mailbox\controllers\MessageController.php(37)
public function actionInbox($ajax=null)
35 {
36 $this->module->registerConfig($this->getAction()->getId());
37 $cs =& $this->module->getClientScript();
38 $cs->registerScriptFile($this->module->getAssetsUrl().'/js/mailbox.js',CClientScript::POS_END);
39 //$js = '$("#mailbox-list").yiiMailboxList('.$this->module->getOptions().');console.log(1)';
40
41 //$cs->registerScript('mailbox-js',$js,CClientScript::POS_READY);
42
43
44 if(isset($_POST['convs']))
45 {
46 $this->buttonAction('inbox');
47 }
48 $dataProvider = new CActiveDataProvider( Mailbox::model()->inbox($this->module->getUserId()) );
49 if(isset($ajax))
reply:php Error
I think this error is raised becuae it cant get user id.. so r you using user module?
if not then in config/mail.php
'mailbox'=> array( 'userClass' => 'User', // 'userIdColumn' => 'id', 'userIdColumn' => 'user_id', 'usernameColumn' => 'user_organization_email_id', //'usernameColumn' => 'username', 'superuserColumn'=>'user_type', // 'pageSize' => 50, 'newsUserId' => 'admin@rudrasoftech.com', ),
userIdColumn and usernameColumn of your user table and also add,
'tablePrefix' => 'tbl_',
in db configuration array
and in mailbox module change MailboxModule.php like this,
public function getUserId($username='') { if($username) { $r = call_user_func(array($this->userClass, 'model')) ->findByAttributes(array($this->usernameColumn=>$username)); if(!is_null($r)) return $r->{$this->userIdColumn}; } else { if(!$this->_userid) $this->_userid = Yii::app()->user->id; return $this->_userid; } }
PHP error-
I used the user module for this. But error not changed. Still have the same problem. Is there any method for using this extension without using user module?
@ Maclein Got the solution for chrome problem
@ Maclein Got the solution for chrome problem..
just replace the mailbox.js with source js of the online demo
http://www.cgihub.com/mailbox/
forum post
http://www.yiiframework.com/forum/index.php/topic/37562-yii-mailbox-extension-google-chrome-problem/page__gopid__181208
what kind of error ?
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{mailbox_message}}
WHERE recipient_id='10' ORDER BY created DESC
) AS m ' at line 4. The SQL statement executed was: SELECT SQL_CACHE COUNT(c.conversation_id) AS num_messages
FROM mailbox_conversation AS c
INNER JOIN (
SELECT message_id,conversation_id FROM {{mailbox_message}}
WHERE recipient_id=:userid ORDER BY created DESC
) AS m ON(m.conversation_id=c.conversation_id)
WHERE (c.initiator_id=:userid OR c.interlocutor_id=:userid)
AND (c.bm_read & IF(c.initiator_id=:userid, :bminit, :bminter)) = 0
AND (c.bm_deleted & IF(c.initiator_id=:userid, :bminit, :bminter)) = 0
GROUP BY c.conversation_id
Error
Im getting this error : "Only variables should be assigned by reference"
I have configured my main.php like this:
'mailbox'=>array( 'userClass' => 'User', 'userIdColumn' => 'id', 'usernameColumn' => 'full_name', 'superuserColumn'=>'user_type', // 'pageSize' => 50, 'newsUserId' => 'basem@mail.com', ),
any suggestions pls?
Re: Error
Reply tomyself, found that I have to make the code for any occurance of this
$cs = $this->module->getClientScript();
To this:
$script = $this->module->getClientScript(); $cs =& $script;
but I got myself into another problem now... 'delete', 'read', 'unread' functions are not working or actually not sending a request, I have defined the module in the main.php as follows:
'mailbox'=>array( 'userClass' => 'User', 'userIdColumn' => 'id', 'usernameColumn' => 'full_name', 'superuserColumn'=>'id',
kindly advise
basem
how can admin send message to all users?
As the title said, how can admin send message to all the users? Is there a simple way to do this or i need to add some code in actionNew to send message to
every user manually? thanks in advance.
Without Yii-user
How this extension can use without using the yii-user extension? Which changes and tables are needed without yii-user extension?
Just to get it "working"
Please note the userClass changes are because I'm using yii-user module.
in config/main.php
change
'mailbox'=> array( 'userClass' => 'User', ....other settings ),
to
'mailbox'=> array( 'userClass' => 'users', ....other settings ),
modules/mailbox/MailboxModule.php
change
public $userClass = 'User';
to
public $userClass = 'users';
modules/mailbox/controllers/MessageController.php
find and replace all (lines 37, 105, and 267)
$cs =& $this->module->getClientScript();
with
$script = $this->module->getClientScript(); $cs =& $script;
modules/mailbox/views/message/_list.php
Line 3 change
$userid =& $this->module->getUserId();
to
$userid = $this->module->getUserId();
There are a lot of bugs still with how I did this. i.e. when you delete a message it doesn't really delete it, it will still show in the trash folder. However, it is sending the messages between the users.
Maybe it's not the best way but it's a start for someone with more time. I just did this in about 3 minutes so I will over the next few days mess with it some more and hopefully get it fully working like in the demo and post how i did it here.
However, if someone does it first please post how you got it to work.
Also, Rvr101 I assume if you use the same names in your db you will not have to make changes or just edit the main.php and the mailboxmodule.php accordingly to use your table name and structure. Read the instructions above it lays it out somewhat
Edit the following functions in the file /module/mailbox/MailboxModule.php
*Note if you are using the User module from Yii extensions (Yii-User) then you do not need to configure the following functions. Unless if you'd like to customize the From label or modify how the auto complete is handled.
getUserId($username='') getUserName($userid='') getFromLabel($userid) getUrl($userid) isAdmin($userid='')
solve error ""Only variables should be assigned by reference""
"Only variables should be assigned by reference"
just search in the module for =& and replace it with =
means remove & sign .
The solutions of comment #c10766
I found the problem of this comment:
http://www.yiiframework.com/extension/mailbox#c10766
the error is the MySQL query writhed on Line 221 in Models->Maibox.php
The correct SQL is this:
$query = "SELECT SQL_CACHE COUNT(c.conversation_id) AS num_messages FROM ".MailboxModule::TBL_CONV." AS c INNER JOIN ( SELECT message_id,conversation_id FROM ".MailboxModule::TBL_MSG." WHERE recipient_id=:userid ORDER BY created DESC ) AS m ON(m.conversation_id=c.conversation_id) WHERE (c.initiator_id=:userid OR c.interlocutor_id=:userid) AND (c.bm_read & IF(c.initiator_id=:userid, :bminit, :bminter)) = 0 AND (c.bm_deleted & IF(c.initiator_id=:userid, :bminit, :bminter)) = 0 GROUP BY c.conversation_id ";
The name of this table {{mailbox_message}} remain hard-coded in the sql sintax.
autocomplete
I don't get it, what I need to do to get auto complete working
Send to multiple user
Is it possible to send message to multiple user/group using this extension. I found this code in MessageController.php (from openschool community edition). How do i create the view for this controller
public function actionNewgroup() { $this->module->registerConfig($this->getAction()->getId()); $cs = $this->module->getClientScript(); $cs->registerScriptFile($this->module->getAssetsUrl().'/js/compose.js'); $cs->registerScriptFile($this->module->getAssetsUrl().'/js/jquery.combobox.contacts.js'); $js = '$(".mailbox-compose").yiiMailboxCompose('.$this->module->getOptions().");"; $cs->registerScript('mailbox-js',$js,CClientScript::POS_READY); if(!$this->module->authManager && (!$this->module->sendMsgs || ($this->module->readOnly && !$this->module->isAdmin()) )) $this->redirect(array('message/inbox')); if(isset($_POST['Mailbox']['to']) and $_POST['Mailbox']['to']!=NULL) { $users = AuthAssignment::model()->findAllByAttributes(array('itemname'=>$_POST['Mailbox']['to'])); if($users!=NULL) { foreach($users as $user) { $t = time(); $conv = new Mailbox(); $conv->subject = ($_POST['Mailbox']['subject'])? $_POST['Mailbox']['subject'] : $this->module->defaultSubject; $conv->to = $user->userid; $conv->initiator_id = $this->module->getUserId(); $conv->interlocutor_id = $user->userid; if($conv->interlocutor_id && $conv->initiator_id == $conv->interlocutor_id) { $conv->addError('to', "Can't send message to self!"); } if(!$this->module->isAdmin() && $conv->interlocutor_id == $this->module->newsUserId){ $conv->addError('to', "User not found?"); } // check user-to-user perms if(!$conv->hasErrors() && !$this->module->userToUser && !$this->module->isAdmin()) { if(!$this->module->isAdmin($conv->to)) $conv->addError('to', "Invalid user!"); } $conv->modified = $t; $conv->bm_read = Mailbox::INITIATOR_FLAG; if($this->module->isAdmin()) $msg = new Message('admin'); else $msg = new Message('user'); $msg->text = $_POST['Message']['text']; $validate = $conv->validate(array('text'),false); // html purify $msg->created = $t; $msg->sender_id = $conv->initiator_id; $msg->recipient_id = $conv->interlocutor_id; if($this->module->checksums) { $msg->crc64 = Message::crc64($msg->text); // 64bit INT } else $msg->crc64 = 0; // Validate $validate = $conv->validate(null,false); // don't clear errors $validate = $msg->validate() && $validate; if($validate) { $conv->save(); $msg->conversation_id = $conv->conversation_id; $msg->save(); } Yii::app()->user->setFlash('success', "Message has been sent!"); } $this->redirect(array('message/inbox')); } else { Yii::app()->user->setFlash('error', "Error sending message!"); Yii::app()->user->setFlash('success', "Check Sent Mail"); } } else{ $conv = new Mailbox(); if(isset($_GET['id'])) $conv->to = $this->module->getUserName($_GET['id']); elseif(isset($_GET['to'])) $conv->to = $_GET['to']; else $conv->to = ''; $msg = new Message(); } $this->render('composegroup',array('conv'=>$conv,'msg'=>$msg)); }
@ghimau
Hi ghimau,
I developed that feature .
its a simple dropdown with user roles.
iam using yii user + rights .
Redirect is not working in server
$this->redirect(array('message/inbox'));
this Redirect is not working in server . Redirect is working in all other modules in the same application. Any solutions?
Solved redirect blank page issue
Got the solution from yii forum
You can remove the UTF-8 BOM from the output using the ob_start function. This way you can leave the UTF-8 BOM in your source files so your editor understands it is really UTF-8.
In the /protected/config/main.php you have to add before returning the config array:
ob_start('My_OB'); function My_OB($str, $flags) { //remove UTF-8 BOM $str = preg_replace("/\xef\xbb\xbf/","",$str); return $str; } return array( ... yii config array ...);
P.S. You don't have to call ob_end_flush(), php will do this automatically at the end of the script.
giving error: "Only variables should be assigned by reference"
I am facing this error. How to solve this.
@mwt
There are lots of ' & ' symbols in the code. Remove it all.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.