Ejemplo n.º 1
0
 /**
  * Get list of messages 
  */
 public static function getPage($page = 0)
 {
     $app = \Slim\Slim::getInstance();
     $dao = new MessageDAO();
     $userDAO = new UserDAO();
     $users = $userDAO->getList();
     $groupDAO = new GroupDAO();
     $groupsQuery = array();
     $senderDAO = new SenderDAO();
     $sendersQuery = array();
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $groupsQuery['user_id'] = $user['id'];
         $sendersQuery['user_id'] = $user['id'];
     }
     $groups = $groupDAO->getList($groupsQuery);
     if (0 == $groups['total']) {
         return $app->redirect(MAINURL . '/groups');
     }
     $senders = $senderDAO->getList($sendersQuery);
     if (0 == $senders['total']) {
         return $app->redirect(MAINURL . '/senders');
     }
     $app->expires(time());
     $query = $_GET;
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $query['user_id'] = $user['id'];
     }
     $pager = new Pager(MAINURL . '/messages/', 25);
     $pager->setPage($page);
     $query = $pager->getQueryArray($query);
     $list = $dao->getList($query);
     $pager->setCount(count($list['list']));
     if (isset($list['total'])) {
         $pager->setTotal($list['total']);
     }
     foreach ($list['list'] as $k => $v) {
         $list['list'][$k]->dataHuman = self::getHumanUrl($v);
     }
     $app->view->set('menu', 'messages');
     $app->view->set('result', $list);
     $app->view->set('pager', $pager);
     $app->view->set('groups', $groups);
     $app->view->set('senders', $senders);
     $app->view->set('users', $users);
     $app->render('messages/list.twig.html');
 }
Ejemplo n.º 2
0
 public static function getSentPage($page = 0)
 {
     $app = \Slim\Slim::getInstance();
     $limit = 50;
     if ($_GET['format'] == 'csv') {
         $page = 0;
         $limit = 10000;
     }
     $userDAO = new UserDAO();
     $messageDAO = new MessageDAO();
     $groupDAO = new GroupDAO();
     $groups = $groupDAO->getList();
     $groups = $groups['list'];
     $formUtils = new FormUtils();
     $startTime = $formUtils->toTimestamp($_GET['start_date'] . ' 00:00');
     $endTime = $formUtils->toTimestamp($_GET['end_date'] . ' 23:59');
     if ($endTime <= 0) {
         $endTime = time();
     }
     if ($startTime <= 0) {
         $startTime = $endTime - 7 * 24 * 3600;
     }
     $app->view->set('start_date', $startTime);
     $app->view->set('end_date', $endTime);
     $query = $_GET;
     $query['start_date'] = $startTime;
     $query['end_date'] = $endTime;
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $query['user_id'] = $user['id'];
     }
     $pager = new Pager(MAINURL . '/reports/sent/?' . http_build_query($_GET), $limit);
     $pager->setPage($page);
     $query = $pager->getQueryArray($query);
     $list = $messageDAO->getList($query);
     $pager->setCount(count($list['list']));
     if (isset($list['total'])) {
         $pager->setTotal($list['total']);
     }
     $reportTable = array();
     foreach ($list['list'] as $message) {
         $statuses = $messageDAO->getStatuses($message);
         foreach ($statuses as $status) {
             if (empty($status['target'])) {
                 continue;
             }
             $key = $status['message_id'];
             if (!empty($reportTable[$key])) {
                 $reportRow = $reportTable[$key];
             } else {
                 $reportRow = array();
                 $group = $groups[$message->getGroupId()];
                 $reportRow['group'] = $group->getNickname();
                 $reportRow['groupCnt'] = count($groupDAO->getNumbers($group->getId()));
                 $reportRow['ctime'] = $message->getCtime();
                 $reportRow['msg'] = $message->getData();
                 $reportRow['targets'] = array();
                 $reportRow['sent'] = array();
                 $reportRow['recv'] = array();
                 $reportRow['error'] = 0;
                 $reportRow['status'] = 0;
             }
             $reportRow['targets'] = $message->getTarget();
             switch ($status['status']) {
                 case Message::MESSAGE_STATUS_ERROR:
                     $reportRow['status'] = 'ERR';
                     break;
                 case Message::MESSAGE_STATUS_RECEIVED_BY_SERVER:
                 case Message::MESSAGE_STATUS_RECEIVED_BY_PHONE:
                     $reportRow['status'] = 'RECV';
                     $reportRow['recv'][$status['target']] = 1;
                     break;
                 case Message::MESSAGE_STATUS_SENT:
                     $reportRow['status'] = 'SENT';
                     $reportRow['sent'][$status['target']] = 1;
                     if ($reportRow['sent_time'] < $status['mtime']) {
                         $reportRow['sent_time'] = $status['mtime'];
                     }
                     break;
             }
             $reportTable[$key] = $reportRow;
         }
     }
     foreach ($reportTable as $k => $v) {
         $v['sentCnt'] = count($v['sent']);
         $v['recvCnt'] = count($v['recv']);
         $reportTable[$k] = $v;
     }
     $app->view->set('menu', 'reports');
     $app->view->set('reportTable', array_values($reportTable));
     $app->view->set('query', $query);
     $app->view->set('pager', $pager);
     if ($_GET['format'] == 'csv') {
         header("Content-type: text/csv");
         header("Content-disposition: attachment; filename=sent.csv");
         $app->render('reports/sent.twig.csv');
     } else {
         $app->render('reports/sent.twig.html');
     }
 }
Ejemplo n.º 3
0
            }
        }
        $contacts = array_keys($contacts);
        try {
            $whatsDAO = WhatsappDAO::instance($sender);
            $whatsDAO->syncContacts($sender, $contacts);
            $flags = $sender->getFlags();
            $flags &= ~\GitGis\Whatsapp\Model\Sender::FLAG_UNSYNC;
            $sender->setFlags($flags);
            $senderDAO->save($sender);
        } catch (\Exception $ex) {
            echo $ex;
        }
    }
}
$messagesList = $messageDAO->getList(array('toSend' => time()));
$messages = $messagesList['list'];
usort($messages, function ($a, $b) {
    return $a->getGroupId() - $b->getGroupId();
});
logToCronFile("Fetched messages to send: " . count($messages));
foreach ($messages as $message) {
    $messageDAO->clearRetry($message);
    $groupId = $message->getGroupId();
    $sender = $senderDAO->fetch($message->getSenderId());
    if (!$sender->getId()) {
        continue;
    }
    if ('' == $sender->getPassword()) {
        echo "Empty password for " . $sender->getUsername() . ' ' . $sender->getNickname() . "\n";
        $messageDAO->addStatus($message, Message::MESSAGE_STATUS_ERROR, 'Sender not registered - go sender and use confirm SMS function');