Commit 6a15d87683ac22f763a1f57cc66d3fa5126b2a6b

Authored by Tiago Zimmermann
1 parent 3a1848e5
Exists in master

Notification

install/database/schema.sql
@@ -749,6 +749,7 @@ CREATE TABLE IF NOT EXISTS `core_notifications` ( @@ -749,6 +749,7 @@ CREATE TABLE IF NOT EXISTS `core_notifications` (
749 `id` int(11) NOT NULL AUTO_INCREMENT, 749 `id` int(11) NOT NULL AUTO_INCREMENT,
750 `id_itc` int(11), 750 `id_itc` int(11),
751 `title` varchar(255) NOT NULL, 751 `title` varchar(255) NOT NULL,
  752 + `from` varchar(128) DEFAULT "OPENS",
752 `message` text NOT NULL, 753 `message` text NOT NULL,
753 `creation_date` datetime NOT NULL, 754 `creation_date` datetime NOT NULL,
754 `read` boolean DEFAULT false, 755 `read` boolean DEFAULT false,
install/database/system_data.sql
@@ -88,4 +88,4 @@ INSERT INTO `regras_negocio` VALUES ('',0,'Internas - Ramal para Ramal','G:all', @@ -88,4 +88,4 @@ INSERT INTO `regras_negocio` VALUES ('',0,'Internas - Ramal para Ramal','G:all',
88 INSERT INTO `regras_negocio_actions` VALUES (1,0,'PBX_Rule_Action_CCustos'),(1,1,'PBX_Rule_Action_DiscarRamal'); 88 INSERT INTO `regras_negocio_actions` VALUES (1,0,'PBX_Rule_Action_CCustos'),(1,1,'PBX_Rule_Action_DiscarRamal');
89 INSERT INTO `regras_negocio_actions_config` VALUES (1,0,'ccustos','9'),(1,1,'allow_voicemail','false'),(1,1,'dial_flags','twk'),(1,1,'dial_timeout','60'),(1,1,'diff_ring','false'),(1,1,'dont_overflow','false'),(1,1,'resolv_agent','false'); 89 INSERT INTO `regras_negocio_actions_config` VALUES (1,0,'ccustos','9'),(1,1,'allow_voicemail','false'),(1,1,'dial_flags','twk'),(1,1,'dial_timeout','60'),(1,1,'diff_ring','false'),(1,1,'dont_overflow','false'),(1,1,'resolv_agent','false');
90 90
91 -INSERT INTO `core_config` (`config_module`, `config_name`, `config_value`) VALUES ('CORE', 'HOST_NOTIFICATION', 'http://api.opens.com.br:3003/notifications/last_id/'); 91 +INSERT INTO `core_config` (`config_module`, `config_name`, `config_value`) VALUES ('CORE', 'HOST_NOTIFICATION', 'http://api.opens.com.br:3003/notifications');
lib/Snep/Notifications.php
@@ -174,14 +174,17 @@ class Snep_Notifications { @@ -174,14 +174,17 @@ class Snep_Notifications {
174 * @param <string> $title 174 * @param <string> $title
175 * @param <string> $notification 175 * @param <string> $notification
176 */ 176 */
177 - public function addNotification($title,$message,$id_itc) { 177 + public function addNotification($title,$message,$id_itc,$costumer) {
178 178
179 $db = Zend_Registry::get('db'); 179 $db = Zend_Registry::get('db');
180 180
  181 + ($costumer == 68) ? $from = "OPENS" : $from = "INTEGRADOR";
  182 +
181 $insert_data = array('title' => $title, 183 $insert_data = array('title' => $title,
182 'message' => $message, 184 'message' => $message,
183 'id_itc' => $id_itc, 185 'id_itc' => $id_itc,
184 - 'creation_date' => date('Y-m-d H:i:s')); 186 + 'creation_date' => date('Y-m-d H:i:s'),
  187 + 'from' => $from);
185 188
186 $db->insert('core_notifications', $insert_data); 189 $db->insert('core_notifications', $insert_data);
187 190
@@ -238,5 +241,19 @@ class Snep_Notifications { @@ -238,5 +241,19 @@ class Snep_Notifications {
238 } 241 }
239 } 242 }
240 243
  244 + /**
  245 + * Method to update a lastNotification
  246 + * @param <int> $id
  247 + */
  248 + public function updateLastNotification($id) {
  249 +
  250 + $db = Zend_Registry::get('db');
  251 +
  252 + $update_data = array('config_value' => $id);
  253 +
  254 + $db->update("core_config", $update_data, "config_name = 'LAST_ID_NOTIFICATION'");
  255 +
  256 + }
  257 +
241 } 258 }
242 ?> 259 ?>
modules/default/controllers/IndexController.php
@@ -199,7 +199,7 @@ class IndexController extends Zend_Controller_Action { @@ -199,7 +199,7 @@ class IndexController extends Zend_Controller_Action {
199 199
200 $title = $this->view->translate('Welcome to Intercomunexão.'); 200 $title = $this->view->translate('Welcome to Intercomunexão.');
201 $message = $this->view->translate('By registering your SNEP, you connect to the portal of Intercomunexão. Portal where you will have access to exclusive solutions, high-quality support and a constantly evolving technology. <br>Access: itc.opens.com.br'); 201 $message = $this->view->translate('By registering your SNEP, you connect to the portal of Intercomunexão. Portal where you will have access to exclusive solutions, high-quality support and a constantly evolving technology. <br>Access: itc.opens.com.br');
202 - Snep_Notifications::addNotification($title,$message); 202 + Snep_Notifications::addNotification($title,$message,1,"OPENS");
203 203
204 // go to snep 204 // go to snep
205 $_SESSION['registered'] = true; 205 $_SESSION['registered'] = true;
@@ -277,19 +277,22 @@ class IndexController extends Zend_Controller_Action { @@ -277,19 +277,22 @@ class IndexController extends Zend_Controller_Action {
277 $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array( 277 $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array(
278 $this->view->translate("Dashboard"))); 278 $this->view->translate("Dashboard")));
279 279
  280 + $configs = Snep_Config::getConfiguration('CORE','HOST_NOTIFICATION');
  281 +
280 // get last_id_notification if exists 282 // get last_id_notification if exists
281 $idLastNotification = Snep_Config::getConfiguration("CORE", "LAST_ID_NOTIFICATION"); 283 $idLastNotification = Snep_Config::getConfiguration("CORE", "LAST_ID_NOTIFICATION");
282 if($idLastNotification){ 284 if($idLastNotification){
283 - $idLastNotification = $idLastNotification["config_value"]; 285 +
  286 + $idLastNotification = $idLastNotification["config_value"];
  287 + $url = $configs["config_value"]."/last_id/".$idLastNotification."/UUID/".$_SESSION["uuid"];
  288 +
284 }else{ 289 }else{
285 - $idLastNotification = Snep_Notifications::getDateLastNotification();  
286 - }  
287 290
288 - $configs = Snep_Config::getConfiguration('CORE','HOST_NOTIFICATION'); 291 + $dateNotification = date("Y-m-d");
  292 + $url = $configs["config_value"]."/date/".$dateNotification."/UUID/".$_SESSION["uuid"];
  293 + }
289 294
290 // get notification in itc 295 // get notification in itc
291 - $url = $configs["config_value"].$idLastNotification."/UUID/".$_SESSION["uuid"];  
292 -  
293 $http = curl_init($url); 296 $http = curl_init($url);
294 297
295 curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false); 298 curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
@@ -304,8 +307,23 @@ class IndexController extends Zend_Controller_Action { @@ -304,8 +307,23 @@ class IndexController extends Zend_Controller_Action {
304 307
305 $notifications = json_decode($http_response); 308 $notifications = json_decode($http_response);
306 foreach($notifications as $item => $notification){ 309 foreach($notifications as $item => $notification){
307 - Snep_Notifications::addNotification(utf8_decode($notification->title),utf8_decode($notification->message),$notification->id); 310 + $lastId = $notification->id;
  311 +
  312 + Snep_Notifications::addNotification(utf8_decode($notification->title),utf8_decode($notification->message),$notification->id,$notification->id_costumer);
308 } 313 }
  314 +
  315 + if(isset($lastId)){
  316 +
  317 + // get last_id_notification if exists
  318 + $idLastNotification = Snep_Config::getConfiguration("CORE", "LAST_ID_NOTIFICATION");
  319 + if($idLastNotification){
  320 + Snep_Notifications::updateLastNotification($lastId);
  321 + }else{
  322 + Snep_Notifications::addLastNotification($lastId);
  323 + }
  324 +
  325 + }
  326 +
309 break; 327 break;
310 case 500: 328 case 500:
311 329
@@ -314,7 +332,7 @@ class IndexController extends Zend_Controller_Action { @@ -314,7 +332,7 @@ class IndexController extends Zend_Controller_Action {
314 332
315 $title = $this->view->translate('Warning'); 333 $title = $this->view->translate('Warning');
316 $message = $this->view->translate('Internal Server Error. <br> To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.'); 334 $message = $this->view->translate('Internal Server Error. <br> To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.');
317 - Snep_Notifications::addNotification($title,$message); 335 + Snep_Notifications::addNotification($title,$message,1,"OPENS");
318 } 336 }
319 337
320 break; 338 break;
@@ -325,7 +343,7 @@ class IndexController extends Zend_Controller_Action { @@ -325,7 +343,7 @@ class IndexController extends Zend_Controller_Action {
325 343
326 $title = $this->view->translate('Warning'); 344 $title = $this->view->translate('Warning');
327 $message = $this->view->translate('Error notifications.<br> To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.'); 345 $message = $this->view->translate('Error notifications.<br> To receive notifications about new features, modules and related news Snep you must be connected to an internet network. Check your connection and try again.');
328 - Snep_Notifications::addNotification($title,$message); 346 + Snep_Notifications::addNotification($title,$message,1,"OPENS");
329 } 347 }
330 348
331 break; 349 break;
@@ -336,7 +354,7 @@ class IndexController extends Zend_Controller_Action { @@ -336,7 +354,7 @@ class IndexController extends Zend_Controller_Action {
336 354
337 $title = $this->view->translate('Warning'); 355 $title = $this->view->translate('Warning');
338 $message = $this->view->translate("Error: Code ") . $httpcode . $this->view->translate(". Please contact the administrator for receiver notifications."); 356 $message = $this->view->translate("Error: Code ") . $httpcode . $this->view->translate(". Please contact the administrator for receiver notifications.");
339 - Snep_Notifications::addNotification($title,$message); 357 + Snep_Notifications::addNotification($title,$message,"OPENS");
340 } 358 }
341 break; 359 break;
342 } 360 }
modules/default/controllers/NotificationsController.php
@@ -135,10 +135,6 @@ class NotificationsController extends Zend_Controller_Action { @@ -135,10 +135,6 @@ class NotificationsController extends Zend_Controller_Action {
135 135
136 $idLastNotification = Snep_Notifications::getDateLastNotification(); 136 $idLastNotification = Snep_Notifications::getDateLastNotification();
137 137
138 - // update last notification in config_core  
139 - Snep_Notifications::removeLastNotification();  
140 - Snep_Notifications::addLastNotification($idLastNotification);  
141 -  
142 // remove notification 138 // remove notification
143 Snep_Notifications::removeNotification($id); 139 Snep_Notifications::removeNotification($id);
144 140
modules/default/views/layouts/layout.phtml
@@ -67,26 +67,20 @@ @@ -67,26 +67,20 @@
67 <li class="dropdown"> 67 <li class="dropdown">
68 68
69 <?php $noView = Snep_Notifications::getNoView(); 69 <?php $noView = Snep_Notifications::getNoView();
  70 +
70 if($noView){?> 71 if($noView){?>
71 72
72 - <a class="dropdown-toggle new-notification" data-toggle="dropdown" href="#"><?php echo count($noView)?> 73 + <a class="dropdown-toggle new-notification" href="<?php echo $this->baseUrl()."/index.php/notifications?id=all";?>"><?php echo count($noView)?>
73 74
74 <?php }else{?> 75 <?php }else{?>
75 76
76 - <a class="dropdown-toggle" data-toggle="dropdown" href="#"> 77 + <a class="dropdown-toggle" href="<?php echo $this->baseUrl()."/index.php/notifications?id=all" ?>" >
77 78
78 <?php } ?> 79 <?php } ?>
79 80
80 - <i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i> 81 + <i class="fa fa-envelope fa-fw"></i>
81 </a> 82 </a>
82 - <ul class="dropdown-menu dropdown-messages">  
83 -  
84 - <?php  
85 - echo Snep_Notifications::getNotifications($this->baseUrl());  
86 - ?>  
87 -  
88 -  
89 - </ul> 83 +
90 84
91 </li> 85 </li>
92 86
modules/default/views/scripts/notifications/index.phtml
@@ -33,6 +33,7 @@ $this-&gt;headLink()-&gt;appendStylesheet( $this-&gt;baseUrl() . &quot;/css/index.css&quot;); @@ -33,6 +33,7 @@ $this-&gt;headLink()-&gt;appendStylesheet( $this-&gt;baseUrl() . &quot;/css/index.css&quot;);
33 <thead> 33 <thead>
34 <tr> 34 <tr>
35 35
  36 + <th><?php echo $this->translate('Remetente');?></th>
36 <th><?php echo $this->translate('Notification');?></th> 37 <th><?php echo $this->translate('Notification');?></th>
37 <th data-sort-ignore="true"><?php echo $this->translate('Date');?></th> 38 <th data-sort-ignore="true"><?php echo $this->translate('Date');?></th>
38 <th colspan="2" class="text-center" data-sort-ignore="true"><?php echo $this->translate('Actions');?></th> 39 <th colspan="2" class="text-center" data-sort-ignore="true"><?php echo $this->translate('Actions');?></th>
@@ -46,12 +47,14 @@ $this-&gt;headLink()-&gt;appendStylesheet( $this-&gt;baseUrl() . &quot;/css/index.css&quot;); @@ -46,12 +47,14 @@ $this-&gt;headLink()-&gt;appendStylesheet( $this-&gt;baseUrl() . &quot;/css/index.css&quot;);
46 47
47 <tr> 48 <tr>
48 <?php if($notification['read'] == '1'){?> 49 <?php if($notification['read'] == '1'){?>
49 - 50 +
  51 + <td> <?php echo $notification['from'] ?> </td>
50 <td> <?php echo $notification['title'] ." - ". substr($notification['message'], 0,60)."..." ?> </td> 52 <td> <?php echo $notification['title'] ." - ". substr($notification['message'], 0,60)."..." ?> </td>
51 <td> <?php echo date("d/m/Y G:i:s", strtotime($notification['creation_date'])) ?> </td> 53 <td> <?php echo date("d/m/Y G:i:s", strtotime($notification['creation_date'])) ?> </td>
52 54
53 <?php }else{?> 55 <?php }else{?>
54 56
  57 + <td class="bold"> <?php echo $notification['from'] ?> </td>
55 <td class="bold"> <?php echo $notification['title'] ." - ". substr($notification['message'], 0,60)."..." ?> </td> 58 <td class="bold"> <?php echo $notification['title'] ." - ". substr($notification['message'], 0,60)."..." ?> </td>
56 <td class="bold"> <?php echo date("d/m/Y G:i:s", strtotime($notification['creation_date'])) ?> </td> 59 <td class="bold"> <?php echo date("d/m/Y G:i:s", strtotime($notification['creation_date'])) ?> </td>
57 60