Mediaburst_SMS - Version 1.1.4

Version Notes

Initial Public Release

Download this release

Release Info

Developer Mediaburst
Extension Mediaburst_SMS
Version 1.1.4
Comparing to
See all releases


Version 1.1.4

app/code/community/Mediaburst/Sms/Block/AbstractMessageGrid.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Abstract Message Grid
28
+ */
29
+ abstract class Mediaburst_Sms_Block_AbstractMessageGrid extends Mage_Adminhtml_Block_Widget_Grid
30
+ {
31
+
32
+ protected $_resourceClass = null;
33
+
34
+ public function setCollectionResourceModel($model)
35
+ {
36
+ $this->_collectionResourceModel = $model;
37
+ }
38
+
39
+ /**
40
+ * Retrieve collection class
41
+ *
42
+ * @return string
43
+ */
44
+ protected function getCollectionResourceModel()
45
+ {
46
+ return $this->_collectionResourceModel;
47
+ }
48
+
49
+ protected function _prepareCollection()
50
+ {
51
+ $collection = Mage::getResourceModel($this->getCollectionResourceModel());
52
+ $this->_filterCollection($collection);
53
+ $this->setCollection($collection);
54
+ return parent::_prepareCollection();
55
+ }
56
+
57
+ protected function _filterCollection(Varien_Data_Collection_Db $collection)
58
+ {
59
+ return $this;
60
+ }
61
+
62
+ protected function _prepareColumns()
63
+ {
64
+ $this->addColumn('id', array(
65
+ 'header' => $this->__('Message #'),
66
+ 'width' => '80px',
67
+ 'type' => 'number',
68
+ 'index' => 'id',
69
+ ));
70
+
71
+ $this->addColumn('store_id', array(
72
+ 'header' => $this->__('Store'),
73
+ 'index' => 'store_id',
74
+ 'type' => 'store',
75
+ 'store_view' => true,
76
+ 'display_deleted' => true,
77
+ ));
78
+
79
+ $this->addColumn('created_at', array(
80
+ 'header' => $this->__('Created'),
81
+ 'index' => 'created_at',
82
+ 'type' => 'datetime',
83
+ ));
84
+
85
+ $this->addColumn('updated_at', array(
86
+ 'header' => $this->__('Updated'),
87
+ 'index' => 'updated_at',
88
+ 'type' => 'datetime',
89
+ ));
90
+
91
+ $this->addColumn('to', array(
92
+ 'header' => $this->__('To'),
93
+ 'index' => 'to',
94
+ ));
95
+
96
+ $this->addColumn('from', array(
97
+ 'header' => $this->__('From'),
98
+ 'index' => 'from',
99
+ ));
100
+
101
+ $this->addColumn('content', array(
102
+ 'header' => $this->__('Content'),
103
+ 'index' => 'content',
104
+ 'filter' => false,
105
+ ));
106
+
107
+ return parent::_prepareColumns();
108
+ }
109
+
110
+ }
app/code/community/Mediaburst/Sms/Block/CreditReportGrid.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Credit Report Grid
28
+ */
29
+ class Mediaburst_Sms_Block_CreditReportGrid extends Mage_Adminhtml_Block_Widget_Grid
30
+ {
31
+
32
+ protected function _prepareLayout()
33
+ {
34
+ parent::_prepareLayout();
35
+
36
+ $this->unsetChild('reset_filter_button');
37
+ $this->unsetChild('search_button');
38
+
39
+ return $this;
40
+ }
41
+
42
+ protected function _prepareCollection()
43
+ {
44
+ $collection = new Varien_Data_Collection();
45
+
46
+ $helper = Mage::helper('Mediaburst_Sms/Data');
47
+
48
+ $runs = array();
49
+
50
+ $stores = Mage::app()->getStores();
51
+ foreach ($stores as $store) {
52
+ if ($helper->isActive($store)) {
53
+ $username = $helper->getUsername($store);
54
+ $password = $helper->getPassword($store);
55
+ $url = $helper->getCheckUrl($store);
56
+ $hash = md5($username . ':' . $password . ':' . $url);
57
+
58
+ if (!isset($runs[$hash])) {
59
+ $runs[$hash] = array(
60
+ 'username' => $username,
61
+ 'url' => $url,
62
+ 'stores' => array()
63
+ );
64
+ }
65
+
66
+ $runs[$hash]['stores'][] = $store->getId();
67
+ }
68
+ }
69
+
70
+ $api = Mage::getModel('Mediaburst_Sms/Api', $helper);
71
+ /* @var $api Mediaburst_Sms_Model_Api */
72
+
73
+ $results = array();
74
+
75
+ foreach ($runs as $hash => $run) {
76
+ $helper->setDefaultStore(reset($run['stores']));
77
+ $credits = $api->checkCredits();
78
+
79
+ $item = new Varien_Object();
80
+ $item->setUsername($run['username']);
81
+ $item->setUrl($run['url']);
82
+ $item->setCredits($credits);
83
+
84
+ $collection->addItem($item);
85
+ }
86
+
87
+ $this->setCollection($collection);
88
+ return parent::_prepareCollection();
89
+ }
90
+
91
+ protected function _prepareColumns()
92
+ {
93
+ $this->addColumn('username', array(
94
+ 'header' => $this->__('Username'),
95
+ 'index' => 'username',
96
+ 'filter' => false,
97
+ ));
98
+
99
+ $this->addColumn('url', array(
100
+ 'header' => $this->__('Service URL'),
101
+ 'index' => 'url',
102
+ 'filter' => false,
103
+ ));
104
+
105
+ $this->addColumn('credits', array(
106
+ 'header' => $this->__('Credits'),
107
+ 'index' => 'credits',
108
+ 'filter' => false,
109
+ ));
110
+
111
+ return parent::_prepareColumns();
112
+ }
113
+
114
+ public function registerBuyButton()
115
+ {
116
+ $container = $this->getParentBlock();
117
+ if ($container instanceof Mage_Adminhtml_Block_Widget_Grid_Container) {
118
+ $helper = Mage::helper('Mediaburst_Sms/Data');
119
+ $container->addButton('buy', array(
120
+ 'label' => $this->__('Buy'),
121
+ 'onclick' => 'setLocation(\'' . $helper->getBuyUrl(0) . '\')',
122
+ 'class' => 'add',
123
+ ));
124
+ }
125
+ }
126
+
127
+ }
app/code/community/Mediaburst/Sms/Block/FailedGrid.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Failed Message Grid
28
+ */
29
+ class Mediaburst_Sms_Block_FailedGrid extends Mediaburst_Sms_Block_AbstractMessageGrid
30
+ {
31
+
32
+ protected function _filterCollection(Varien_Data_Collection_Db $collection)
33
+ {
34
+ $collection->addFieldToFilter('status', Mediaburst_Sms_Model_Message::STATUS_FAILED);
35
+ return $this;
36
+ }
37
+
38
+ protected function _prepareColumns()
39
+ {
40
+ $this->addColumnAfter('error', array(
41
+ 'header' => $this->__('Error'),
42
+ 'index' => 'error_description',
43
+ 'filter' => false,
44
+ ), 'content');
45
+
46
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/mediaburst_sms/retry')) {
47
+ $this->addColumnAfter('action', array(
48
+ 'header' => $this->__('Action'),
49
+ 'width' => '50px',
50
+ 'type' => 'action',
51
+ 'getter' => 'getId',
52
+ 'actions' => array(
53
+ array(
54
+ 'caption' => $this->__('Retry'),
55
+ 'url' => array('base' => '*/*/retry'),
56
+ 'field' => 'id'
57
+ )
58
+ ),
59
+ 'filter' => false,
60
+ 'sortable' => false,
61
+ 'is_system' => true,
62
+ ), 'error');
63
+ }
64
+
65
+ return parent::_prepareColumns();
66
+ }
67
+
68
+ }
app/code/community/Mediaburst/Sms/Block/GridContainer.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Grid Container
28
+ */
29
+ class Mediaburst_Sms_Block_GridContainer extends Mage_Adminhtml_Block_Widget_Grid_Container
30
+ {
31
+ protected function _prepareLayout()
32
+ {
33
+ Mage_Adminhtml_Block_Widget_Container::_prepareLayout();
34
+ }
35
+
36
+ public function setHeaderText($headerText)
37
+ {
38
+ $this->_headerText = $headerText;
39
+ }
40
+ }
app/code/community/Mediaburst/Sms/Block/PendingGrid.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Pending Message Grid
28
+ */
29
+ class Mediaburst_Sms_Block_PendingGrid extends Mediaburst_Sms_Block_AbstractMessageGrid
30
+ {
31
+
32
+ protected function _filterCollection(Varien_Data_Collection_Db $collection)
33
+ {
34
+ $collection->addFieldToFilter('status', Mediaburst_Sms_Model_Message::STATUS_PENDING);
35
+ return $this;
36
+ }
37
+
38
+ protected function _prepareColumns()
39
+ {
40
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/mediaburst_sms/send')) {
41
+ $this->addColumnAfter('action', array(
42
+ 'header' => $this->__('Action'),
43
+ 'width' => '50px',
44
+ 'type' => 'action',
45
+ 'getter' => 'getId',
46
+ 'actions' => array(
47
+ array(
48
+ 'caption' => $this->__('Send'),
49
+ 'url' => array('base' => '*/*/send'),
50
+ 'field' => 'id'
51
+ )
52
+ ),
53
+ 'filter' => false,
54
+ 'sortable' => false,
55
+ 'is_system' => true,
56
+ ), 'content');
57
+ }
58
+
59
+ return parent::_prepareColumns();
60
+ }
61
+
62
+ }
app/code/community/Mediaburst/Sms/Block/SentGrid.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Sent Message Grid
28
+ */
29
+ class Mediaburst_Sms_Block_SentGrid extends Mediaburst_Sms_Block_AbstractMessageGrid
30
+ {
31
+
32
+ protected function _filterCollection(Varien_Data_Collection_Db $collection)
33
+ {
34
+ $collection->addFieldToFilter('status', Mediaburst_Sms_Model_Message::STATUS_SENT);
35
+ return $this;
36
+ }
37
+
38
+ protected function _prepareColumns()
39
+ {
40
+ $this->addColumnAfter('message_id', array(
41
+ 'header' => $this->__('MessageID'),
42
+ 'index' => 'message_id',
43
+ 'filter' => false,
44
+ ), 'content');
45
+
46
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/mediaburst_sms/requeue')) {
47
+ $this->addColumnAfter('action', array(
48
+ 'header' => $this->__('Action'),
49
+ 'width' => '50px',
50
+ 'type' => 'action',
51
+ 'getter' => 'getId',
52
+ 'actions' => array(
53
+ array(
54
+ 'caption' => $this->__('Requeue'),
55
+ 'url' => array('base' => '*/*/requeue'),
56
+ 'field' => 'id'
57
+ )
58
+ ),
59
+ 'filter' => false,
60
+ 'sortable' => false,
61
+ 'is_system' => true,
62
+ ), 'message_id');
63
+ }
64
+
65
+ return parent::_prepareColumns();
66
+ }
67
+
68
+ }
app/code/community/Mediaburst/Sms/Exception.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
22
+ */
23
+
24
+ /**
25
+ * Base Exception
26
+ */
27
+ class Mediaburst_Sms_Exception extends Mage_Core_Exception
28
+ {
29
+
30
+ }
app/code/community/Mediaburst/Sms/Helper/Data.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MediaBurst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package MediaBurst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Helper
28
+ */
29
+ class MediaBurst_Sms_Helper_Data extends Mage_Core_Helper_Abstract implements MediaBurst_Sms_Model_ApiConfig
30
+ {
31
+ const XML_CONFIG_BASE_PATH = 'mediaburst_sms/';
32
+
33
+ protected $_defaultStore = null;
34
+
35
+ public function setDefaultStore($store)
36
+ {
37
+ $this->_defaultStore = $store;
38
+ }
39
+
40
+ public function isActive($store = null)
41
+ {
42
+ if ($store === null) {
43
+ $store = $this->_defaultStore;
44
+ }
45
+
46
+ return Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'general/active', $store);
47
+ }
48
+
49
+ public function getCheckUrl($store = null)
50
+ {
51
+ if ($store === null) {
52
+ $store = $this->_defaultStore;
53
+ }
54
+
55
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/check_url', $store);
56
+ }
57
+
58
+ public function getBuyUrl($store = null)
59
+ {
60
+ if ($store === null) {
61
+ $store = $this->_defaultStore;
62
+ }
63
+
64
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/buy_url', $store);
65
+ }
66
+
67
+ public function getSendUrl($store = null)
68
+ {
69
+ if ($store === null) {
70
+ $store = $this->_defaultStore;
71
+ }
72
+
73
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/send_url', $store);
74
+ }
75
+
76
+ public function getUsername($store = null)
77
+ {
78
+ if ($store === null) {
79
+ $store = $this->_defaultStore;
80
+ }
81
+
82
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/username', $store);
83
+ }
84
+
85
+ public function getPassword($store = null)
86
+ {
87
+ if ($store === null) {
88
+ $store = $this->_defaultStore;
89
+ }
90
+
91
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/password', $store);
92
+ }
93
+
94
+ public function isDebug($store = null)
95
+ {
96
+ if ($store === null) {
97
+ $store = $this->_defaultStore;
98
+ }
99
+
100
+ return Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'general/debug', $store);
101
+ }
102
+
103
+ public function log($message, $level = Zend_Log::DEBUG, $store = null)
104
+ {
105
+ if ($store === null) {
106
+ $store = $this->_defaultStore;
107
+ }
108
+
109
+ if ($message instanceof Exception) {
110
+ $message = "\n" . $message->__toString();
111
+ $level = Zend_Log::ERR;
112
+ $file = Mage::getStoreConfig('dev/log/exception_file', $store);
113
+ } else {
114
+ if (is_array($message) || is_object($message)) {
115
+ $message = print_r($message, true);
116
+ }
117
+ $file = Mage::getStoreConfig('dev/log/file', $store);
118
+ }
119
+
120
+ if ($level < Zend_Log::DEBUG || $this->isDebug($store)) {
121
+ $force = ($level <= Zend_Log::ERR);
122
+ Mage::log($message, $level, $file, $force);
123
+ }
124
+ }
125
+
126
+ public function isOrderCreatedActive($store = null)
127
+ {
128
+ if ($store === null) {
129
+ $store = $this->_defaultStore;
130
+ }
131
+
132
+ return $this->isActive($store) && Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'order_created/active', $store);
133
+ }
134
+
135
+ public function getOrderCreatedTo($store = null)
136
+ {
137
+ if ($store === null) {
138
+ $store = $this->_defaultStore;
139
+ }
140
+
141
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_created/to', $store);
142
+ }
143
+
144
+ public function getOrderCreatedFrom($store = null)
145
+ {
146
+ if ($store === null) {
147
+ $store = $this->_defaultStore;
148
+ }
149
+
150
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_created/from', $store);
151
+ }
152
+
153
+ public function getOrderCreatedContent($store = null)
154
+ {
155
+ if ($store === null) {
156
+ $store = $this->_defaultStore;
157
+ }
158
+
159
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_created/content', $store);
160
+ }
161
+
162
+ public function isOrderHeldActive($store = null)
163
+ {
164
+ if ($store === null) {
165
+ $store = $this->_defaultStore;
166
+ }
167
+
168
+ return $this->isActive($store) && Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'order_held/active', $store);
169
+ }
170
+
171
+ public function getOrderHeldFrom($store = null)
172
+ {
173
+ if ($store === null) {
174
+ $store = $this->_defaultStore;
175
+ }
176
+
177
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_held/from', $store);
178
+ }
179
+
180
+ public function getOrderHeldContent($store = null)
181
+ {
182
+ if ($store === null) {
183
+ $store = $this->_defaultStore;
184
+ }
185
+
186
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_held/content', $store);
187
+ }
188
+
189
+ public function isOrderUnheldActive($store = null)
190
+ {
191
+ if ($store === null) {
192
+ $store = $this->_defaultStore;
193
+ }
194
+
195
+ return $this->isActive($store) && Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'order_unheld/active', $store);
196
+ }
197
+
198
+ public function getOrderUnheldFrom($store = null)
199
+ {
200
+ if ($store === null) {
201
+ $store = $this->_defaultStore;
202
+ }
203
+
204
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_unheld/from', $store);
205
+ }
206
+
207
+ public function getOrderUnheldContent($store = null)
208
+ {
209
+ if ($store === null) {
210
+ $store = $this->_defaultStore;
211
+ }
212
+
213
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_unheld/content', $store);
214
+ }
215
+
216
+ public function isOrderShippedActive($store = null)
217
+ {
218
+ if ($store === null) {
219
+ $store = $this->_defaultStore;
220
+ }
221
+
222
+ return $this->isActive($store) && Mage::getStoreConfigFlag(self::XML_CONFIG_BASE_PATH . 'order_shipped/active', $store);
223
+ }
224
+
225
+ public function getOrderShippedFrom($store = null)
226
+ {
227
+ if ($store === null) {
228
+ $store = $this->_defaultStore;
229
+ }
230
+
231
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_shipped/from', $store);
232
+ }
233
+
234
+ public function getOrderShippedContent($store = null)
235
+ {
236
+ if ($store === null) {
237
+ $store = $this->_defaultStore;
238
+ }
239
+
240
+ return Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'order_shipped/content', $store);
241
+ }
242
+
243
+ public function generateOrderCreatedContent(Mage_Sales_Model_Order $order)
244
+ {
245
+ $filter = Mage::getModel('core/email_template_filter');
246
+ $filter->setPlainTemplateMode(true);
247
+ $filter->setStoreId($order->getStoreId());
248
+ $filter->setVariables(array('order' => $order));
249
+ return $filter->filter($this->getOrderCreatedContent($order->getStoreId()));
250
+ }
251
+
252
+ public function generateOrderShippedContent(Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment)
253
+ {
254
+ $filter = Mage::getModel('core/email_template_filter');
255
+ $filter->setPlainTemplateMode(true);
256
+ $filter->setStoreId($order->getStoreId());
257
+ $filter->setVariables(array('order' => $order, 'shipment' => $shipment));
258
+ return $filter->filter($this->getOrderShippedContent($order->getStoreId()));
259
+ }
260
+
261
+ public function generateOrderHeldContent(Mage_Sales_Model_Order $order)
262
+ {
263
+ $filter = Mage::getModel('core/email_template_filter');
264
+ $filter->setPlainTemplateMode(true);
265
+ $filter->setStoreId($order->getStoreId());
266
+ $filter->setVariables(array('order' => $order));
267
+ return $filter->filter($this->getOrderHeldContent($order->getStoreId()));
268
+ }
269
+
270
+ public function generateOrderUnheldContent(Mage_Sales_Model_Order $order)
271
+ {
272
+ $filter = Mage::getModel('core/email_template_filter');
273
+ $filter->setPlainTemplateMode(true);
274
+ $filter->setStoreId($order->getStoreId());
275
+ $filter->setVariables(array('order' => $order));
276
+ return $filter->filter($this->getOrderUnheldContent($order->getStoreId()));
277
+ }
278
+
279
+ /**
280
+ * Convert a result array into a series of session messages
281
+ *
282
+ * @param Mage_Core_Model_Session_Abstract $session
283
+ * @return MediaBurst_Sms_Helper_Data
284
+ */
285
+ public function reportResults(Mage_Core_Model_Session_Abstract $session, array $result)
286
+ {
287
+ foreach ($result['sent'] as $message) {
288
+ $session->addSuccess($this->__('Sent message %s to %s', $message->getId(), $message->getTo()));
289
+ }
290
+ foreach ($result['failed'] as $message) {
291
+ $session->addError($this->__('Failed sending message %s to %s (%s: %s)', $message->getId(), $message->getTo(), $message->getErrorNumber(), $message->getErrorDescription()));
292
+ }
293
+ foreach ($result['errors'] as $error) {
294
+ $session->addError(implode(' / ', $error));
295
+ }
296
+
297
+ return $this;
298
+ }
299
+
300
+ public function getTelephone(Mage_Sales_Model_Order $order)
301
+ {
302
+ $billingAddress = $order->getBillingAddress();
303
+
304
+ $number = $billingAddress->getTelephone();
305
+ $number = preg_replace('#[^\+\d]#', '', trim($number));
306
+
307
+ if (substr($number, 0, 1) === '+') {
308
+ $number = substr($number, 1);
309
+ } elseif (substr($number, 0, 2) === '00') {
310
+ $number = substr($number, 2);
311
+ } else {
312
+ // Handle special case where mobile numbers are prefixed with a 0
313
+ if (substr($number, 0, 1) === '0') {
314
+ $number = substr($number, 1);
315
+ }
316
+
317
+ // Find the telephone dialing code for the billing country
318
+ $expectedPrefix = Zend_Locale_Data::getContent(Mage::app()->getLocale()->getLocale(), 'phonetoterritory', $billingAddress->getCountry());
319
+
320
+ // If we couldn't find the dialing code by billing country, chose the store level default
321
+ if (empty($expectedPrefix)) {
322
+ $expectedPrefix = Mage::getStoreConfig(self::XML_CONFIG_BASE_PATH . 'general/failsafe_prefix', $store);
323
+ }
324
+
325
+ // Try to prepend the dialing prefix if it's not part of the number already (Not bullet-proof)
326
+ if (!empty($expectedPrefix)) {
327
+ $prefix = substr($number, 0, strlen($expectedPrefix));
328
+ if ($prefix !== $expectedPrefix) {
329
+ $number = $expectedPrefix . $number;
330
+ }
331
+ }
332
+ }
333
+
334
+ // Final trim of number, Just-In-Case™
335
+ $number = preg_replace('#[^\d]#', '', trim($number));
336
+
337
+ return $number;
338
+ }
339
+
340
+ /**
341
+ *
342
+ * @param Mage_Sales_Model_Order $order
343
+ * @param string $comment
344
+ * @return MediaBurst_Sms_Helper_Data
345
+ */
346
+ public function addOrderComment(Mage_Sales_Model_Order $order, $comment)
347
+ {
348
+ Mage::getModel('sales/order_status_history')
349
+ ->setOrder($order)
350
+ ->setStatus($order->getStatus())
351
+ ->setComment($comment)
352
+ ->setIsCustomerNotified(true)
353
+ ->save();
354
+
355
+ return $this;
356
+ }
357
+
358
+ }
app/code/community/Mediaburst/Sms/Model/Api.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * API implementation class
28
+ */
29
+ class Mediaburst_Sms_Model_Api extends Zend_Service_Abstract
30
+ {
31
+ const SMS_PER_REQUEST_LIMIT = 500;
32
+
33
+ /**
34
+ * Reference to a config object that can provide the details needed for the API
35
+ *
36
+ * @var Mediaburst_Sms_Model_ApiConfig
37
+ */
38
+ protected $_config;
39
+
40
+ /**
41
+ * Basic constructor
42
+ *
43
+ * @param Mediaburst_Sms_Model_ApiConfig $config
44
+ */
45
+ public function __construct(Mediaburst_Sms_Model_ApiConfig $config)
46
+ {
47
+ $this->_config = $config;
48
+ }
49
+
50
+ /**
51
+ * Send a single SMS message
52
+ *
53
+ * @param string $from The name or number of the sender
54
+ * @param string $to The mobile number of the receipient
55
+ * @param string $content Message to send. Limited to 160 GMS characters
56
+ * @param array $extra Addition parameters
57
+ */
58
+ public function sendMessage(Mediaburst_Sms_Model_Message $message)
59
+ {
60
+ return $this->sendMessages(array($message));
61
+ }
62
+
63
+ /**
64
+ * Send multiple messages at once
65
+ *
66
+ * @param array $messages Array containing multiple messages
67
+ */
68
+ public function sendMessages(array $messages)
69
+ {
70
+ if (count($messages) === 0) {
71
+ return;
72
+ }
73
+
74
+ if (count($messages) > self::SMS_PER_REQUEST_LIMIT) {
75
+ throw new Mediaburst_Sms_Exception('Too many messages. Limit is ' . self::SMS_PER_REQUEST_LIMIT . ' per request');
76
+ }
77
+
78
+ $result = array('pending' => array(), 'sent' => array(), 'failed' => array(), 'errors' => array());
79
+
80
+ $indexedMessages = array();
81
+
82
+ $xml = new DOMDocument('1.0', 'UTF-8');
83
+ $root = $xml->appendChild($xml->createElement('Message'));
84
+ $root->appendChild($xml->createElement('Username', $this->_config->getUsername()));
85
+ $root->appendChild($xml->createElement('Password', $this->_config->getPassword()));
86
+ foreach ($messages as $message) {
87
+ if (!$message instanceof Mediaburst_Sms_Model_Message) {
88
+ $this->_config->log('Message object not expected type', Zend_Log::WARN);
89
+ continue;
90
+ }
91
+
92
+ $result['pending'][$message->getId()] = $message;
93
+
94
+ $sms = $root->appendChild($xml->createElement('SMS'));
95
+
96
+ $from = trim($message->getFrom());
97
+ if (!empty($from)) {
98
+ $sms->appendChild($xml->createElement('From', $message->getFrom()));
99
+ }
100
+
101
+ $sms->appendChild($xml->createElement('To', $this->_formatMobileNumber($message->getTo())));
102
+ $sms->appendChild($xml->createElement('ClientID', $message->getId()));
103
+ $sms->appendChild($xml->createElement('Content', $message->getContent()));
104
+ // TODO: Map additional parameters
105
+ }
106
+
107
+ $requestBody = $xml->saveXML();
108
+ $this->_config->log($requestBody, Zend_Log::DEBUG);
109
+
110
+ $client = $this->getHttpClient();
111
+ $client->resetParameters(true);
112
+ $client->setUri($this->_config->getSendUrl());
113
+ $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'text/xml');
114
+ $client->setRawData($requestBody);
115
+
116
+ unset($requestBody);
117
+
118
+ $response = $client->request(Zend_Http_Client::POST);
119
+
120
+ if (!$response->isSuccessful()) {
121
+ throw new Mediaburst_Sms_Exception("Problem communicating with host", $response->getStatus());
122
+ }
123
+
124
+ $responseBody = $response->getBody();
125
+ $this->_config->log($responseBody, Zend_Log::DEBUG);
126
+
127
+ $xml = new DOMDocument('1.0', 'UTF-8');
128
+ $xml->loadXML($responseBody);
129
+
130
+ unset($responseBody);
131
+
132
+ $xpath = new DOMXPath($xml);
133
+
134
+ $responseNodes = $xpath->query('//SMS_Resp');
135
+ foreach ($responseNodes as $responseNode) {
136
+ $clientId = $xpath->evaluate('string(./ClientID)', $responseNode);
137
+ if (!isset($result['pending'][$clientId])) {
138
+ $result['errors'][] = "Unexpected ClientID:" . $clientId;
139
+ continue;
140
+ }
141
+
142
+ $message = $result['pending'][$clientId];
143
+ unset($result['pending'][$clientId]);
144
+
145
+ $to = $xpath->evaluate('string(./To)', $responseNode);
146
+ $messageId = $xpath->evaluate('string(./MessageID)', $responseNode);
147
+ $errorNumber = $xpath->evaluate('string(./ErrNo)', $responseNode);
148
+ $errorDescription = $xpath->evaluate('string(./ErrDesc)', $responseNode);
149
+
150
+ if (!empty($errorNumber)) {
151
+ try {
152
+ $message->getMessageId(null);
153
+ $message->setErrorNumber($errorNumber);
154
+ $message->setErrorDescription($errorDescription);
155
+ $message->setStatus(Mediaburst_Sms_Model_Message::STATUS_FAILED);
156
+ $message->save();
157
+ $result['failed'][$clientId] = $message;
158
+ } catch (Exception $e) {
159
+ $result['errors'][] = array($e->getMessage(), $to, $errorNumber, $errorDescription);
160
+ }
161
+ } elseif (!empty($messageId)) {
162
+ try {
163
+ $message->setMessageId($messageId);
164
+ $message->setErrorNumber(null);
165
+ $message->setErrorDescription(null);
166
+ $message->setStatus(Mediaburst_Sms_Model_Message::STATUS_SENT);
167
+ $message->save();
168
+ $result['sent'][$clientId] = $message;
169
+ } catch (Exception $e) {
170
+ $result['errors'][] = array($e->getMessage(), $to, $messageId);
171
+ }
172
+ } else {
173
+ $result['errors'][] = array($e->getMessage(), $to);
174
+ }
175
+ }
176
+
177
+ $messageNodes = $xpath->query('//Message_Resp[ErrNo]');
178
+ foreach ($messageNodes as $messageNode) {
179
+ $errorNumber = $xpath->evaluate('string(./ErrNo)', $messageNode);
180
+ $errorDescription = $xpath->evaluate('string(./ErrDesc)', $messageNode);
181
+ $result['errors'][] = array($errorNumber, $errorDescription);
182
+ }
183
+
184
+ return $result;
185
+ }
186
+
187
+ /**
188
+ * Return the current number of remaining credits
189
+ *
190
+ * @return int
191
+ */
192
+ public function checkCredits()
193
+ {
194
+ $credits = false;
195
+
196
+ $client = $this->getHttpClient();
197
+ $client->resetParameters(true);
198
+ $client->setUri($this->_config->getCheckUrl());
199
+ $client->setParameterPost('username', $this->_config->getUsername());
200
+ $client->setParameterPost('password', $this->_config->getPassword());
201
+
202
+ $response = $client->request(Zend_Http_Client::POST);
203
+
204
+ if ($response->isSuccessful()) {
205
+ $body = $response->getBody();
206
+ $this->_config->log($body, Zend_Log::DEBUG);
207
+ $body = explode(":", $body, 2);
208
+ if (count($body) === 2) {
209
+ $credits = intval($body[1]);
210
+ }
211
+ }
212
+
213
+ return $credits;
214
+ }
215
+
216
+ protected function _formatMobileNumber($number)
217
+ {
218
+ return preg_replace('#[^\d]#', '', trim($number));
219
+ }
220
+
221
+ }
app/code/community/Mediaburst/Sms/Model/ApiConfig.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Config Interface
28
+ */
29
+ interface Mediaburst_Sms_Model_ApiConfig
30
+ {
31
+
32
+ /**
33
+ * Return the URL to the send message serviceÏ
34
+ */
35
+ public function getSendUrl();
36
+
37
+ /**
38
+ * Return the URL to the credit check service
39
+ *
40
+ * @return string
41
+ */
42
+ public function getCheckUrl();
43
+
44
+ /**
45
+ * Return the API username
46
+ *
47
+ * @return string
48
+ */
49
+ public function getUsername();
50
+
51
+ /**
52
+ * Return the API password
53
+ *
54
+ * @return string
55
+ */
56
+ public function getPassword();
57
+
58
+ /**
59
+ * Check is debugging is enabled
60
+ *
61
+ * @return bool
62
+ */
63
+ public function isDebug();
64
+
65
+ /**
66
+ * Log a message
67
+ *
68
+ * @param mixed $message
69
+ * @param int $level
70
+ * @param mixed $store
71
+ */
72
+ public function log($message, $level, $store);
73
+ }
app/code/community/Mediaburst/Sms/Model/Message.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ *
28
+ */
29
+ class Mediaburst_Sms_Model_Message extends Mage_Core_Model_Abstract
30
+ {
31
+ const STATUS_PENDING = 0;
32
+ const STATUS_SENT = 1;
33
+ const STATUS_FAILED = 2;
34
+ const DATETIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
35
+
36
+ protected function _construct()
37
+ {
38
+ $this->_init('Mediaburst_Sms/Message');
39
+ }
40
+
41
+ /**
42
+ * Processing object before save data
43
+ *
44
+ * @return Mage_Core_Model_Abstract
45
+ */
46
+ protected function _beforeSave()
47
+ {
48
+ parent::_beforeSave();
49
+
50
+ $this->setCreatedAt($this->_toDbDate($this->getCreatedAt()));
51
+ $this->setUpdatedAt($this->_toDbDate());
52
+
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * Processing object after save data
58
+ *
59
+ * @return Mage_Core_Model_Abstract
60
+ */
61
+ protected function _afterSave()
62
+ {
63
+ parent::_afterSave();
64
+
65
+ $this->setCreatedAt($this->_fromDbDate($this->getCreatedAt()));
66
+ $this->setUpdatedAt($this->_fromDbDate($this->getUpdatedAt()));
67
+
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * Processing object after load data
73
+ *
74
+ * @return Mage_Core_Model_Abstract
75
+ */
76
+ protected function _afterLoad()
77
+ {
78
+ parent::_afterLoad();
79
+
80
+ $this->setCreatedAt($this->_fromDbDate($this->getCreatedAt()));
81
+ $this->setUpdatedAt($this->_fromDbDate($this->getUpdatedAt()));
82
+
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * Convert a date string or object into a MySQL formatted date-time string
88
+ *
89
+ * @param Zend_Date|string|null $date
90
+ * @return string
91
+ */
92
+ protected function _toDbDate($date = null)
93
+ {
94
+ if (!$date instanceof Zend_Date) {
95
+ if (empty($date)) {
96
+ $date = new Zend_Date();
97
+ } else {
98
+ $date = new Zend_Date(strtotime($date), Zend_Date::TIMESTAMP);
99
+ }
100
+ }
101
+
102
+ return $date->toString(self::DATETIME_FORMAT);
103
+ }
104
+
105
+ /**
106
+ * Convert a MySQL Formatted DateTime string into a Zend_Date object
107
+ *
108
+ * @param string $date
109
+ * @return Zend_Date
110
+ */
111
+ protected function _fromDbDate($date)
112
+ {
113
+ if (!$date instanceof Zend_Date) {
114
+ $date = strtotime($date);
115
+
116
+ if ($date === false) {
117
+ $date = new Zend_Date();
118
+ } else {
119
+ $date = new Zend_Date($date, Zend_Date::TIMESTAMP);
120
+ }
121
+ }
122
+
123
+ return $date;
124
+ }
125
+
126
+ }
app/code/community/Mediaburst/Sms/Model/Mysql4/Message.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ *
28
+ */
29
+ class Mediaburst_Sms_Model_Mysql4_Message extends Mage_Core_Model_Mysql4_Abstract
30
+ {
31
+
32
+ protected function _construct()
33
+ {
34
+ $this->_init('Mediaburst_Sms/Message', 'id');
35
+ }
36
+
37
+ }
app/code/community/Mediaburst/Sms/Model/Mysql4/Message/Collection.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ *
28
+ */
29
+ class Mediaburst_Sms_Model_Mysql4_Message_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
30
+ {
31
+
32
+ protected function _construct()
33
+ {
34
+ $this->_init('Mediaburst_Sms/Message');
35
+ }
36
+
37
+ }
app/code/community/Mediaburst/Sms/Model/Observer.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ * Event Observer
28
+ */
29
+ class Mediaburst_Sms_Model_Observer
30
+ {
31
+
32
+ public function createOrderCreatedMessage(Varien_Event_Observer $observer)
33
+ {
34
+ $order = $observer->getOrder();
35
+ if ($order instanceof Mage_Sales_Model_Order) {
36
+ /* @var $order Mage_Sales_Model_Order */
37
+ if (!$this->getHelper()->isOrderCreatedActive($order->getStoreId())) {
38
+ return;
39
+ }
40
+ try {
41
+ $message = Mage::getModel('Mediaburst_Sms/Message');
42
+ $message->setStoreId($order->getStoreId());
43
+ $message->setTo($this->getHelper()->getOrderCreatedTo());
44
+ $message->setFrom($this->getHelper()->getOrderCreatedFrom());
45
+ $message->setContent($this->getHelper()->generateOrderCreatedContent($order));
46
+ $message->save();
47
+ } catch (Exception $e) {
48
+ $this->getHelper()->log('Error creating Order Created SMS Message Record for Order ' . $order->getIncrementId(), Zend_Log::ERR);
49
+ }
50
+ }
51
+ }
52
+
53
+ public function createOrderShippedMessage(Varien_Event_Observer $observer)
54
+ {
55
+ $shipment = $observer->getShipment();
56
+ if ($shipment instanceof Mage_Sales_Model_Order_Shipment) {
57
+ /* @var $shipment Mage_Sales_Model_Order_Shipment */
58
+ $order = $shipment->getOrder();
59
+ if (!$this->getHelper()->isOrderShippedActive($order->getStoreId())) {
60
+ return;
61
+ }
62
+ try {
63
+ $message = Mage::getModel('Mediaburst_Sms/Message');
64
+ $message->setStoreId($order->getStoreId());
65
+ $message->setTo($this->getHelper()->getTelephone($order));
66
+ $message->setFrom($this->getHelper()->getOrderShippedFrom());
67
+ $message->setContent($this->getHelper()->generateOrderShippedContent($order, $shipment));
68
+ $message->save();
69
+ $this->getHelper()->addOrderComment($order, 'SMS message generated (' . $message->getId() . ')');
70
+ } catch (Exception $e) {
71
+ $this->getHelper()->log('Error creating Order Shipped SMS Message Record for Order ' . $order->getIncrementId(), Zend_Log::ERR);
72
+ }
73
+ }
74
+ }
75
+
76
+ public function createOrderHeldMessage(Varien_Event_Observer $observer)
77
+ {
78
+ $order = $observer->getOrder();
79
+ if ($order instanceof Mage_Sales_Model_Order) {
80
+ /* @var $order Mage_Sales_Model_Order */
81
+ if (!$this->getHelper()->isOrderHeldActive($order->getStoreId())) {
82
+ return;
83
+ }
84
+ if ($order->getState() !== $order->getOrigData('state') && $order->getState() === Mage_Sales_Model_Order::STATE_HOLDED) {
85
+ try {
86
+ $message = Mage::getModel('Mediaburst_Sms/Message');
87
+ $message->setStoreId($order->getStoreId());
88
+ $message->setTo($this->getHelper()->getTelephone($order));
89
+ $message->setFrom($this->getHelper()->getOrderHeldFrom());
90
+ $message->setContent($this->getHelper()->generateOrderHeldContent($order));
91
+ $message->save();
92
+ $this->getHelper()->addOrderComment($order, 'SMS message generated (' . $message->getId() . ')');
93
+ } catch (Exception $e) {
94
+ $this->getHelper()->log('Error creating Order Held SMS Message Record for Order ' . $order->getIncrementId(), Zend_Log::ERR);
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ public function createOrderUnheldMessage(Varien_Event_Observer $observer)
101
+ {
102
+ $order = $observer->getOrder();
103
+ if ($order instanceof Mage_Sales_Model_Order) {
104
+ /* @var $order Mage_Sales_Model_Order */
105
+ if (!$this->getHelper()->isOrderUnheldActive($order->getStoreId())) {
106
+ return;
107
+ }
108
+ if ($order->getState() !== $order->getOrigData('state') && $order->getOrigData('state') === Mage_Sales_Model_Order::STATE_HOLDED) {
109
+ try {
110
+ $message = Mage::getModel('Mediaburst_Sms/Message');
111
+ $message->setStoreId($order->getStoreId());
112
+ $message->setTo($this->getHelper()->getTelephone($order));
113
+ $message->setFrom($this->getHelper()->getOrderUnheldFrom());
114
+ $message->setContent($this->getHelper()->generateOrderUnheldContent($order));
115
+ $message->save();
116
+ $this->getHelper()->addOrderComment($order, 'SMS message generated (' . $message->getId() . ')');
117
+ } catch (Exception $e) {
118
+ $this->getHelper()->log('Error creating Order Held SMS Message Record for Order ' . $order->getIncrementId(), Zend_Log::ERR);
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Cron Job
126
+ */
127
+ public function sendPendingMessages($session = null)
128
+ {
129
+ $runs = array();
130
+
131
+ $stores = Mage::app()->getStores();
132
+ foreach ($stores as $store) {
133
+ if ($this->getHelper()->isActive($store)) {
134
+ $username = $this->getHelper()->getUsername($store);
135
+ $password = $this->getHelper()->getPassword($store);
136
+ $url = $this->getHelper()->getSendUrl($store);
137
+ $hash = md5($username . ':' . $password . ':' . $url);
138
+
139
+ if (!isset($runs[$hash])) {
140
+ $runs[$hash] = array(
141
+ 'username' => $username,
142
+ 'password' => $password,
143
+ 'url' => $url,
144
+ 'stores' => array()
145
+ );
146
+ }
147
+
148
+ $runs[$hash]['stores'][] = $store->getId();
149
+ }
150
+ }
151
+
152
+ $api = Mage::getModel('Mediaburst_Sms/Api', $this->getHelper());
153
+ /* @var $api Mediaburst_Sms_Model_Api */
154
+
155
+ foreach ($runs as $run) {
156
+ $collection = Mage::getModel('Mediaburst_Sms/Message')->getCollection()
157
+ ->addFieldToSelect('*')
158
+ ->addFieldToFilter('status', Mediaburst_Sms_Model_Message::STATUS_PENDING)
159
+ ->addFieldToFilter('store_id', $run['stores'])
160
+ ->setPageSize(Mediaburst_Sms_Model_Api::SMS_PER_REQUEST_LIMIT);
161
+
162
+ Mage::dispatchEvent('mediaburst_sms_send_pending_before', array('collection' => $collection));
163
+
164
+ $this->getHelper()->setDefaultStore(reset($run['stores']));
165
+
166
+ $results = $api->sendMessages($collection->getItems());
167
+
168
+ if ($session instanceof Mage_Core_Model_Session_Abstract) {
169
+ $this->getHelper()->reportResults($session, $results);
170
+ }
171
+ }
172
+
173
+ $this->getHelper()->setDefaultStore(null);
174
+ }
175
+
176
+ /**
177
+ *
178
+ * @return Mediaburst_Sms_Helper_Data
179
+ */
180
+ public function getHelper()
181
+ {
182
+ return Mage::helper('Mediaburst_Sms/Data');
183
+ }
184
+
185
+ }
app/code/community/Mediaburst/Sms/controllers/Mediaburst/SmsController.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+
26
+ /**
27
+ *
28
+ */
29
+ class Mediaburst_Sms_Mediaburst_SmsController extends Mage_Adminhtml_Controller_Action
30
+ {
31
+
32
+ public function indexAction()
33
+ {
34
+ $this->_redirect('*/*/pending');
35
+ }
36
+
37
+ public function checkAction()
38
+ {
39
+ $this->loadLayout();
40
+ $this->_setActiveMenu('sales/mediaburst_sms/check');
41
+ $this->_addBreadcrumb($this->__('Sales'), $this->__('Sales'));
42
+ $this->renderLayout();
43
+ }
44
+
45
+ public function pendingAction()
46
+ {
47
+ $this->loadLayout();
48
+ $this->_setActiveMenu('sales/mediaburst_sms/pending');
49
+ $this->_addBreadcrumb($this->__('Sales'), $this->__('Sales'));
50
+ $this->renderLayout();
51
+ }
52
+
53
+ public function sentAction()
54
+ {
55
+ $this->loadLayout();
56
+ $this->_setActiveMenu('sales/mediaburst_sms/sent');
57
+ $this->_addBreadcrumb($this->__('Sales'), $this->__('Sales'));
58
+ $this->renderLayout();
59
+ }
60
+
61
+ public function failedAction()
62
+ {
63
+ $this->loadLayout();
64
+ $this->_setActiveMenu('sales/mediaburst_sms/failed');
65
+ $this->_addBreadcrumb($this->__('Sales'), $this->__('Sales'));
66
+ $this->renderLayout();
67
+ }
68
+
69
+ public function sendAction()
70
+ {
71
+ $id = (int) $this->getRequest()->getParam('id');
72
+ $message = Mage::getModel('Mediaburst_Sms/Message')->load($id);
73
+ if ($message->getId() > 0 && $message->getId() == $id) {
74
+ if ($message->getStatus() == Mediaburst_Sms_Model_Message::STATUS_PENDING) {
75
+ $helper = Mage::helper('Mediaburst_Sms/Data');
76
+ $helper->setDefaultStore($message->getStoreId());
77
+ $api = Mage::getModel('Mediaburst_Sms/Api', $helper);
78
+ $result = $api->sendMessage($message);
79
+ $helper->setDefaultStore(null);
80
+ $helper->reportResults($this->_getSession(), $result);
81
+ } else {
82
+ $this->_getSession()->addError($this->__('Invalid Message Status'));
83
+ }
84
+ } else {
85
+ $this->_getSession()->addError($this->__('Invalid Message ID'));
86
+ }
87
+
88
+ $this->_redirect('*/*/pending');
89
+ }
90
+
91
+ public function requeueAction()
92
+ {
93
+ $id = (int) $this->getRequest()->getParam('id');
94
+ $message = Mage::getModel('Mediaburst_Sms/Message')->load($id);
95
+ if ($message->getId() > 0 && $message->getId() == $id) {
96
+ if ($message->getStatus() == Mediaburst_Sms_Model_Message::STATUS_SENT) {
97
+ try {
98
+ $message->setStatus(Mediaburst_Sms_Model_Message::STATUS_PENDING);
99
+ $message->getMessageId(null);
100
+ $message->setErrorNumber(null);
101
+ $message->setErrorDescription(null);
102
+ $message->save();
103
+ $this->_getSession()->addSuccess($this->__('Requeued message %s to %s', $message->getId(), $message->getTo()));
104
+ } catch (Exception $e) {
105
+ $this->_getSession()->addException($e);
106
+ }
107
+ } else {
108
+ $this->_getSession()->addError($this->__('Invalid Message Status'));
109
+ }
110
+ } else {
111
+ $this->_getSession()->addError($this->__('Invalid Message ID'));
112
+ }
113
+
114
+ $this->_redirect('*/*/sent');
115
+ }
116
+
117
+ public function retryAction()
118
+ {
119
+ $id = (int) $this->getRequest()->getParam('id');
120
+ $message = Mage::getModel('Mediaburst_Sms/Message')->load($id);
121
+ if ($message->getId() > 0 && $message->getId() == $id) {
122
+ if ($message->getStatus() == Mediaburst_Sms_Model_Message::STATUS_FAILED) {
123
+ try {
124
+ $message->setStatus(Mediaburst_Sms_Model_Message::STATUS_PENDING);
125
+ $message->getMessageId(null);
126
+ $message->setErrorNumber(null);
127
+ $message->setErrorDescription(null);
128
+ $message->save();
129
+ $this->_getSession()->addSuccess($this->__('Retrying message %s to %s', $message->getId(), $message->getTo()));
130
+ } catch (Exception $e) {
131
+ $this->_getSession()->addException($e);
132
+ }
133
+ } else {
134
+ $this->_getSession()->addError($this->__('Invalid Message Status'));
135
+ }
136
+ } else {
137
+ $this->_getSession()->addError($this->__('Invalid Message ID'));
138
+ }
139
+
140
+ $this->_redirect('*/*/failed');
141
+ }
142
+
143
+ public function forceCronAction()
144
+ {
145
+ Mage::getSingleton('Mediaburst_Sms/Observer')->sendPendingMessages($this->_getSession());
146
+ $this->_redirect('*/*');
147
+ }
148
+
149
+ protected function _isAllowed()
150
+ {
151
+ $allowed = false;
152
+
153
+ $action = $this->getRequest()->getActionName();
154
+ switch ($action) {
155
+ case 'pending':
156
+ case 'send':
157
+ case 'sent':
158
+ case 'requeue':
159
+ case 'failed':
160
+ case 'retry':
161
+ case 'check':
162
+ $allowed = $this->_permissionCheck($action);
163
+ break;
164
+ case 'index':
165
+ case 'forceCron':
166
+ $allowed = true;
167
+ break;
168
+ }
169
+
170
+ return $allowed;
171
+ }
172
+
173
+ protected function _permissionCheck($permission)
174
+ {
175
+ return Mage::getSingleton('admin/session')->isAllowed('sales/mediaburst_sms/' . $permission);
176
+ }
177
+
178
+ }
app/code/community/Mediaburst/Sms/etc/adminhtml.xml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <menu>
4
+ <sales>
5
+ <children>
6
+ <mediaburst_sms translate="title" module="Mediaburst_Sms">
7
+ <title>SMS Messages</title>
8
+ <sort_order>100</sort_order>
9
+ <children>
10
+ <pending translate="title">
11
+ <title>Pending</title>
12
+ <action>adminhtml/mediaBurst_sms/pending</action>
13
+ <sort_order>100</sort_order>
14
+ </pending>
15
+ <sent translate="title">
16
+ <title>Sent</title>
17
+ <action>adminhtml/mediaBurst_sms/sent</action>
18
+ <sort_order>200</sort_order>
19
+ </sent>
20
+ <failed translate="title">
21
+ <title>Failed</title>
22
+ <action>adminhtml/mediaBurst_sms/failed</action>
23
+ <sort_order>300</sort_order>
24
+ </failed>
25
+ <check translate="title">
26
+ <title>View/Buy Credits</title>
27
+ <action>adminhtml/mediaBurst_sms/check</action>
28
+ <sort_order>400</sort_order>
29
+ </check>
30
+ </children>
31
+ </mediaburst_sms>
32
+ </children>
33
+ </sales>
34
+ </menu>
35
+ <acl>
36
+ <resources>
37
+ <admin>
38
+ <children>
39
+ <sales>
40
+ <children>
41
+ <mediaburst_sms translate="title">
42
+ <title>SMS Messages</title>
43
+ <sort_order>100</sort_order>
44
+ <children>
45
+ <pending translate="title">
46
+ <title>View Pending</title>
47
+ <sort_order>110</sort_order>
48
+ </pending>
49
+ <sent translate="title">
50
+ <title>View Sent</title>
51
+ <sort_order>120</sort_order>
52
+ </sent>
53
+ <failed translate="title">
54
+ <title>View Failed</title>
55
+ <sort_order>130</sort_order>
56
+ </failed>
57
+ <check translate="title">
58
+ <title>View/Buy Credits</title>
59
+ <sort_order>140</sort_order>
60
+ </check>
61
+ <send translate="title">
62
+ <title>Manual Send</title>
63
+ <sort_order>210</sort_order>
64
+ </send>
65
+ <requeue translate="title">
66
+ <title>Manual Requeue</title>
67
+ <sort_order>220</sort_order>
68
+ </requeue>
69
+ <retry translate="title">
70
+ <title>Manual Retry</title>
71
+ <sort_order>230</sort_order>
72
+ </retry>
73
+ </children>
74
+ </mediaburst_sms>
75
+ </children>
76
+ </sales>
77
+ <system>
78
+ <children>
79
+ <config>
80
+ <children>
81
+ <mediaburst_sms translate="title">
82
+ <title>Mediaburst SMS</title>
83
+ </mediaburst_sms>
84
+ </children>
85
+ </config>
86
+ </children>
87
+ </system>
88
+ </children>
89
+ </admin>
90
+ </resources>
91
+ </acl>
92
+ </config>
app/code/community/Mediaburst/Sms/etc/config.xml ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Mediaburst_Sms>
5
+ <version>1.1.4</version>
6
+ </Mediaburst_Sms>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <Mediaburst_Sms>
11
+ <class>Mediaburst_Sms_Model</class>
12
+ <resourceModel>Mediaburst_Sms_Mysql4</resourceModel>
13
+ </Mediaburst_Sms>
14
+ <Mediaburst_Sms_Mysql4>
15
+ <class>Mediaburst_Sms_Model_Mysql4</class>
16
+ <entities>
17
+ <Message>
18
+ <table>mediaburst_message</table>
19
+ </Message>
20
+ </entities>
21
+ </Mediaburst_Sms_Mysql4>
22
+ </models>
23
+ <resources>
24
+ <Mediaburst_Sms>
25
+ <setup>
26
+ <module>Mediaburst_Sms</module>
27
+ </setup>
28
+ </Mediaburst_Sms>
29
+ </resources>
30
+ <blocks>
31
+ <Mediaburst_Sms>
32
+ <class>Mediaburst_Sms_Block</class>
33
+ </Mediaburst_Sms>
34
+ </blocks>
35
+ <helpers>
36
+ <Mediaburst_Sms>
37
+ <class>Mediaburst_Sms_Helper</class>
38
+ </Mediaburst_Sms>
39
+ </helpers>
40
+ <events>
41
+ <sales_order_save_after>
42
+ <observers>
43
+ <Mediaburst_Sms_Held>
44
+ <class>Mediaburst_Sms/Observer</class>
45
+ <method>createOrderHeldMessage</method>
46
+ </Mediaburst_Sms_Held>
47
+ <Mediaburst_Sms_Unheld>
48
+ <class>Mediaburst_Sms/Observer</class>
49
+ <method>createOrderUnheldMessage</method>
50
+ </Mediaburst_Sms_Unheld>
51
+ </observers>
52
+ </sales_order_save_after>
53
+ <sales_order_shipment_save_after>
54
+ <observers>
55
+ <Mediaburst_Sms_Shipped>
56
+ <class>Mediaburst_Sms/Observer</class>
57
+ <method>createOrderShippedMessage</method>
58
+ </Mediaburst_Sms_Shipped>
59
+ </observers>
60
+ </sales_order_shipment_save_after>
61
+ <checkout_type_onepage_save_order_after>
62
+ <observers>
63
+ <Mediaburst_Sms_Created>
64
+ <class>Mediaburst_Sms/Observer</class>
65
+ <method>createOrderCreatedMessage</method>
66
+ </Mediaburst_Sms_Created>
67
+ </observers>
68
+ </checkout_type_onepage_save_order_after>
69
+ </events>
70
+ </global>
71
+ <adminhtml>
72
+ <layout>
73
+ <updates>
74
+ <Mediaburst_Sms>
75
+ <file>mediaburst/sms.xml</file>
76
+ </Mediaburst_Sms>
77
+ </updates>
78
+ </layout>
79
+ </adminhtml>
80
+ <admin>
81
+ <routers>
82
+ <adminhtml>
83
+ <args>
84
+ <modules>
85
+ <Mediaburst_Sms before="Mage_Adminhtml">Mediaburst_Sms</Mediaburst_Sms>
86
+ </modules>
87
+ </args>
88
+ </adminhtml>
89
+ </routers>
90
+ </admin>
91
+ <default>
92
+ <mediaburst_sms>
93
+ <general>
94
+ <active>0</active>
95
+ <username></username>
96
+ <password></password>
97
+ <send_url>http://sms.message-platform.com/xml/send.aspx</send_url>
98
+ <check_url>http://sms.message-platform.com/http/credit.aspx</check_url>
99
+ <buy_url>https://smsapi3.mediaburst.co.uk/Login.aspx?ReturnUrl=https://smsapi3.mediaburst.co.uk/shop/</buy_url>
100
+ <schedule>*/10 * * * *</schedule>
101
+ <debug>0</debug>
102
+ </general>
103
+ <order_created>
104
+ <active></active>
105
+ <from></from>
106
+ <to></to>
107
+ <content>Order {{var order.increment_id}} placed for {{var order.base_grand_total}}</content>
108
+ </order_created>
109
+ <order_held>
110
+ <active>0</active>
111
+ <from></from>
112
+ <content>{{var order.getCustomerName()}}, your order {{var order.increment_id}} has been placed on hold.</content>
113
+ </order_held>
114
+ <order_unheld>
115
+ <active>0</active>
116
+ <from></from>
117
+ <content>{{var order.getCustomerName()}}, your order {{var order.increment_id}} has been released from hold.</content>
118
+ </order_unheld>
119
+ <order_shipped>
120
+ <active>0</active>
121
+ <from></from>
122
+ <content>{{var order.getCustomerName()}}, your order {{var order.increment_id}} has shipped. Shipment {{var shipment.increment_id}}</content>
123
+ </order_shipped>
124
+ </mediaburst_sms>
125
+ </default>
126
+ <crontab>
127
+ <jobs>
128
+ <Mediaburst_Sms_Send>
129
+ <schedule>
130
+ <config_path>mediaburst_sms/general/schedule</config_path>
131
+ <cron_expr>*/10 * * * *</cron_expr>
132
+ </schedule>
133
+ <run>
134
+ <model>Mediaburst_Sms/Observer::sendPendingMessages</model>
135
+ </run>
136
+ </Mediaburst_Sms_Send>
137
+ </jobs>
138
+ </crontab>
139
+ </config>
app/code/community/Mediaburst/Sms/etc/system.xml ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <mediaburst_sms translate="label">
5
+ <label>SMS Notifications</label>
6
+ <tab>sales</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>305</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <general translate="label">
14
+ <label>General</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>10</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <fields>
20
+ <active translate="label">
21
+ <label>Enabled</label>
22
+ <frontend_type>select</frontend_type>
23
+ <source_model>adminhtml/system_config_source_yesno</source_model>
24
+ <sort_order>10</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ </active>
28
+ <username translate="label">
29
+ <label>Username</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>20</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ </username>
35
+ <password translate="label">
36
+ <label>Password</label>
37
+ <frontend_type>password</frontend_type>
38
+ <sort_order>30</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ </password>
42
+ <send_url translate="label">
43
+ <label>Send Message URL</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>40</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ </send_url>
48
+ <check_url translate="label">
49
+ <label>Check Credits URL</label>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>50</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ </check_url>
54
+ <buy_url translate="label">
55
+ <label>Buy Credits URL</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>60</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ </buy_url>
60
+ <failsafe_prefix translate="label">
61
+ <label>Failsafe Country Prefix</label>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>70</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ </failsafe_prefix>
67
+ <schedule translate="label">
68
+ <label>Sending Cron Schedule</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>100</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ </schedule>
73
+ <debug translate="label">
74
+ <label>Debug</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <sort_order>1000</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>1</show_in_website>
80
+ </debug>
81
+ </fields>
82
+ </general>
83
+ <order_created translate="label">
84
+ <label>Order Created</label>
85
+ <frontend_type>text</frontend_type>
86
+ <sort_order>20</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ <fields>
91
+ <active translate="label">
92
+ <label>Enabled</label>
93
+ <frontend_type>select</frontend_type>
94
+ <source_model>adminhtml/system_config_source_yesno</source_model>
95
+ <sort_order>10</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ </active>
100
+ <to translate="label comment">
101
+ <label>Recipient Mobile Number</label>
102
+ <frontend_type>text</frontend_type>
103
+ <sort_order>20</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ <comment>Must be a telephone number that can receive SMS messages</comment>
108
+ </to>
109
+ <from translate="label comment">
110
+ <label>Name or Number of Message Sender</label>
111
+ <frontend_type>text</frontend_type>
112
+ <sort_order>30</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ </from>
117
+ <content translate="label comment">
118
+ <label>Message Template</label>
119
+ <frontend_type>textarea</frontend_type>
120
+ <sort_order>40</sort_order>
121
+ <show_in_default>1</show_in_default>
122
+ <show_in_website>1</show_in_website>
123
+ <show_in_store>1</show_in_store>
124
+ <comment>Template for 160 character SMS message.</comment>
125
+ </content>
126
+ </fields>
127
+ </order_created>
128
+ <order_held translate="label">
129
+ <label>Order Held</label>
130
+ <frontend_type>text</frontend_type>
131
+ <sort_order>30</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ <fields>
136
+ <active translate="label">
137
+ <label>Enabled</label>
138
+ <frontend_type>select</frontend_type>
139
+ <source_model>adminhtml/system_config_source_yesno</source_model>
140
+ <sort_order>10</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <show_in_store>1</show_in_store>
144
+ </active>
145
+ <from translate="label comment">
146
+ <label>Name or Number of Message Sender</label>
147
+ <frontend_type>text</frontend_type>
148
+ <sort_order>30</sort_order>
149
+ <show_in_default>1</show_in_default>
150
+ <show_in_website>1</show_in_website>
151
+ <show_in_store>1</show_in_store>
152
+ </from>
153
+ <content translate="label comment">
154
+ <label>Message Template</label>
155
+ <frontend_type>textarea</frontend_type>
156
+ <sort_order>40</sort_order>
157
+ <show_in_default>1</show_in_default>
158
+ <show_in_website>1</show_in_website>
159
+ <show_in_store>1</show_in_store>
160
+ <comment>Template for 160 character SMS message.</comment>
161
+ </content>
162
+ </fields>
163
+ </order_held>
164
+ <order_unheld translate="label">
165
+ <label>Order Unheld</label>
166
+ <frontend_type>text</frontend_type>
167
+ <sort_order>30</sort_order>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ <fields>
172
+ <active translate="label">
173
+ <label>Enabled</label>
174
+ <frontend_type>select</frontend_type>
175
+ <source_model>adminhtml/system_config_source_yesno</source_model>
176
+ <sort_order>10</sort_order>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>1</show_in_store>
180
+ </active>
181
+ <from translate="label comment">
182
+ <label>Name or Number of Message Sender</label>
183
+ <frontend_type>text</frontend_type>
184
+ <sort_order>30</sort_order>
185
+ <show_in_default>1</show_in_default>
186
+ <show_in_website>1</show_in_website>
187
+ <show_in_store>1</show_in_store>
188
+ </from>
189
+ <content translate="label comment">
190
+ <label>Message Template</label>
191
+ <frontend_type>textarea</frontend_type>
192
+ <sort_order>40</sort_order>
193
+ <show_in_default>1</show_in_default>
194
+ <show_in_website>1</show_in_website>
195
+ <show_in_store>1</show_in_store>
196
+ <comment>Template for 160 character SMS message.</comment>
197
+ </content>
198
+ </fields>
199
+ </order_unheld>
200
+ <order_shipped translate="label">
201
+ <label>Order Shipped</label>
202
+ <frontend_type>text</frontend_type>
203
+ <sort_order>40</sort_order>
204
+ <show_in_default>1</show_in_default>
205
+ <show_in_website>1</show_in_website>
206
+ <show_in_store>1</show_in_store>
207
+ <fields>
208
+ <active translate="label">
209
+ <label>Enabled</label>
210
+ <frontend_type>select</frontend_type>
211
+ <source_model>adminhtml/system_config_source_yesno</source_model>
212
+ <sort_order>10</sort_order>
213
+ <show_in_default>1</show_in_default>
214
+ <show_in_website>1</show_in_website>
215
+ <show_in_store>1</show_in_store>
216
+ </active>
217
+ <from translate="label comment">
218
+ <label>Name or Number of Message Sender</label>
219
+ <frontend_type>text</frontend_type>
220
+ <sort_order>30</sort_order>
221
+ <show_in_default>1</show_in_default>
222
+ <show_in_website>1</show_in_website>
223
+ <show_in_store>1</show_in_store>
224
+ </from>
225
+ <content translate="label comment">
226
+ <label>Message Template</label>
227
+ <frontend_type>textarea</frontend_type>
228
+ <sort_order>40</sort_order>
229
+ <show_in_default>1</show_in_default>
230
+ <show_in_website>1</show_in_website>
231
+ <show_in_store>1</show_in_store>
232
+ <comment>Template for 160 character SMS message.</comment>
233
+ </content>
234
+ </fields>
235
+ </order_shipped>
236
+ </groups>
237
+ </mediaburst_sms>
238
+ </sections>
239
+ </config>
app/code/community/Mediaburst/Sms/sql/MediaBurst_Sms/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+ /* @var $this Mage_Core_Model_Resource_Setup */
26
+
27
+ $this->startSetup();
28
+
29
+ $this->run("
30
+ -- DROP TABLE IF EXISTS {$this->getTable('Mediaburst_Sms/Message')};
31
+ CREATE TABLE {$this->getTable('Mediaburst_Sms/Message')} (
32
+ `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
33
+ `store_id` SMALLINT(5) UNSIGNED NOT NULL,
34
+ `to` VARCHAR(40) NOT NULL,
35
+ `from` VARCHAR(40),
36
+ `content` VARCHAR(180),
37
+ `status` TINYINT(1) NOT NULL DEFAULT 0,
38
+ `message_id` VARCHAR(255),
39
+ `error_number` INT(10) UNSIGNED,
40
+ `error_description` VARCHAR(255),
41
+ PRIMARY KEY (`id`)
42
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Mediaburst SMS Messages';
43
+ ");
44
+
45
+ $this->run("
46
+ ALTER TABLE `{$this->getTable('Mediaburst_Sms/Message')}`
47
+ ADD KEY `FK_MESSAGE_STORE` (`store_id`),
48
+ ADD CONSTRAINT `FK_MESSAGE_STORE` FOREIGN KEY (`store_id`) REFERENCES `{$this->getTable('core/store')}` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE;
49
+ ");
50
+
51
+ $this->endSetup();
app/code/community/Mediaburst/Sms/sql/MediaBurst_Sms/mysql4-upgrade-1.0.0-1.1.2.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediaburst SMS Magento Integration
4
+ *
5
+ * Copyright © 2011 by Mediaburst Limited
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
12
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ * FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
14
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
17
+ * OF THIS SOFTWARE.
18
+ *
19
+ * @category Mage
20
+ * @package Mediaburst_Sms
21
+ * @license http://opensource.org/licenses/isc-license.txt
22
+ * @copyright Copyright © 2011 by Mediaburst Limited
23
+ * @author Lee Saferite <lee.saferite@lokeycoding.com>
24
+ */
25
+ /* @var $this Mage_Core_Model_Resource_Setup */
26
+
27
+ $this->startSetup();
28
+
29
+ $this->run("
30
+ ALTER TABLE `{$this->getTable('Mediaburst_Sms/Message')}`
31
+ ADD COLUMN `created_at` DATETIME NULL,
32
+ ADD COLUMN `updated_at` DATETIME NULL;
33
+ ");
34
+
35
+ $this->endSetup();
app/design/adminhtml/default/default/layout/mediaburst/sms.xml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_mediaburst_sms_pending>
4
+ <reference name="content">
5
+ <block type="MediaBurst_Sms/GridContainer" name="mediaburst_sms.gridcontainer">
6
+ <action method="setHeaderText">
7
+ <param>Pending SMS Messages</param>
8
+ </action>
9
+ <action method="removeButton">
10
+ <param>add</param>
11
+ </action>
12
+ <block type="MediaBurst_Sms/PendingGrid" name="mediaburst_sms.grid" as="grid">
13
+ <action method="setCollectionResourceModel">
14
+ <param>MediaBurst_Sms/Message_Collection</param>
15
+ </action>
16
+ <action method="setDefaultDir">
17
+ <param>DESC</param>
18
+ </action>
19
+ </block>
20
+ </block>
21
+ </reference>
22
+ </adminhtml_mediaburst_sms_pending>
23
+ <adminhtml_mediaburst_sms_sent>
24
+ <reference name="content">
25
+ <block type="MediaBurst_Sms/GridContainer" name="mediaburst_sms.gridcontainer">
26
+ <action method="setHeaderText">
27
+ <param>Sent SMS Messages</param>
28
+ </action>
29
+ <action method="removeButton">
30
+ <param>add</param>
31
+ </action>
32
+ <block type="MediaBurst_Sms/SentGrid" name="mediaburst_sms.grid" as="grid">
33
+ <action method="setCollectionResourceModel">
34
+ <param>MediaBurst_Sms/Message_Collection</param>
35
+ </action>
36
+ <action method="setDefaultDir">
37
+ <param>DESC</param>
38
+ </action>
39
+ </block>
40
+ </block>
41
+ </reference>
42
+ </adminhtml_mediaburst_sms_sent>
43
+ <adminhtml_mediaburst_sms_failed>
44
+ <reference name="content">
45
+ <block type="MediaBurst_Sms/GridContainer" name="mediaburst_sms.gridcontainer">
46
+ <action method="setHeaderText">
47
+ <param>Failed SMS Messages</param>
48
+ </action>
49
+ <action method="removeButton">
50
+ <param>add</param>
51
+ </action>
52
+ <block type="MediaBurst_Sms/FailedGrid" name="mediaburst_sms.grid" as="grid">
53
+ <action method="setCollectionResourceModel">
54
+ <param>MediaBurst_Sms/Message_Collection</param>
55
+ </action>
56
+ <action method="setDefaultDir">
57
+ <param>DESC</param>
58
+ </action>
59
+ </block>
60
+ </block>
61
+ </reference>
62
+ </adminhtml_mediaburst_sms_failed>
63
+ <adminhtml_mediaburst_sms_check>
64
+ <reference name="content">
65
+ <block type="MediaBurst_Sms/GridContainer" name="mediaburst_sms.gridcontainer">
66
+ <action method="setHeaderText">
67
+ <param>Remaining Credits</param>
68
+ </action>
69
+ <action method="removeButton">
70
+ <param>add</param>
71
+ </action>
72
+ <block type="MediaBurst_Sms/CreditReportGrid" name="mediaburst_sms.grid" as="grid">
73
+ <action method="registerBuyButton" />
74
+ </block>
75
+ </block>
76
+ </reference>
77
+ </adminhtml_mediaburst_sms_check>
78
+ </layout>
app/etc/modules/Mediaburst_Sms.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Mediaburst_Sms>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Core />
9
+ <Mage_Adminhtml />
10
+ <Mage_Sales />
11
+ <Mage_Checkout />
12
+ </depends>
13
+ </Mediaburst_Sms>
14
+ </modules>
15
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Mediaburst_SMS</name>
4
+ <version>1.1.4</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/isc-license.txt">ISC License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Mediaburst SMS Notifications</summary>
10
+ <description>Mediaburst SMS Notifications</description>
11
+ <notes>Initial Public Release</notes>
12
+ <authors><author><name>Mediaburst Ltd</name><user>mediaburst</user><email>hello@mediaburst.co.uk</email></author><author><name>Lee Saferite</name><user>LeeSaferite</user><email>lee.saferite@lokeycoding.com</email></author></authors>
13
+ <date>2011-08-01</date>
14
+ <time>18:31:52</time>
15
+ <contents><target name="magecommunity"><dir name="Mediaburst"><dir name="Sms"><dir name="Block"><file name="AbstractMessageGrid.php" hash="2be4146a28ead5a5c6e9a7d22c4ec015"/><file name="CreditReportGrid.php" hash="0afd90c0058dcc7a317bd952861f5993"/><file name="FailedGrid.php" hash="ea4d192711053b969feef90fba5eb431"/><file name="GridContainer.php" hash="e9db6ad67f86c00f27cf4fada82ab548"/><file name="PendingGrid.php" hash="b12cb8626ae81ea5ff336f2187c22f80"/><file name="SentGrid.php" hash="0687068d6c3d95257e4bfc2ca78d5d1b"/></dir><file name="Exception.php" hash="a61b41609348442384c156505bbf04bd"/><dir name="Helper"><file name="Data.php" hash="3d97f0c2e23326d833318a1cd913c1f7"/></dir><dir name="Model"><file name="Api.php" hash="06f6ff1e487ce176902d74d20af54938"/><file name="ApiConfig.php" hash="63b3b1bb77bbf075279e3780f8716297"/><file name="Message.php" hash="5ef6ec217d24897163bbeb3a6f394c45"/><dir name="Mysql4"><dir name="Message"><file name="Collection.php" hash="122e6ad32fb74d6a7eb199209db5ca7f"/></dir><file name="Message.php" hash="b0c5dca8d71575554597500342a7eaee"/></dir><file name="Observer.php" hash="43a878c0a91be91cc8ee5334d824e89c"/></dir><dir name="controllers"><dir name="Mediaburst"><file name="SmsController.php" hash="324f5bec58e6cd13d280d841ded5f145"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="483ad7009db99b20c0d5b2f178008fb4"/><file name="config.xml" hash="75cea2e164d0b60c4132ac2667e6d75f"/><file name="system.xml" hash="19f92b14ef57d3b2b6178074a30e97de"/></dir><dir name="sql"><dir name="MediaBurst_Sms"><file name="mysql4-install-1.0.0.php" hash="4d2862d3ab72dd8db342f126f27502b3"/><file name="mysql4-upgrade-1.0.0-1.1.2.php" hash="f82c128da5ea76c7f7a058d54cdb29b5"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mediaburst_Sms.xml" hash="841b7a08d28215c3e5a1d5368b6383e5"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="mediaburst"><file name="sms.xml" hash="7f846681b3a55bfde623db8cfb422bfa"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>