Beispiel #1
0
 public static function forceSync()
 {
     $senderDAO = new SenderDAO();
     $strong = \Strong\Strong::getInstance();
     $user = $strong->getUser();
     $sendersQuery = array();
     $sendersQuery['user_id'] = $user['id'];
     $senders = $senderDAO->getList($sendersQuery);
     foreach ($senders['list'] as $sender) {
         $sender = $senderDAO->fetch($sender->getId());
         if (empty($sender)) {
             continue;
         }
         $flags = $sender->getFlags();
         $flags |= Sender::FLAG_UNSYNC;
         $sender->setFlags($flags);
         $senderDAO->save($sender);
     }
 }
Beispiel #2
0
 /**
  * Process message form
  */
 public static function postEditPage($id)
 {
     $app = \Slim\Slim::getInstance();
     $dao = new MessageDAO();
     $userDAO = new UserDAO();
     $strong = \Strong\Strong::getInstance();
     $user = $strong->getUser();
     $user = $userDAO->fetch($user['id']);
     $groupDAO = new GroupDAO();
     $groupsQuery = array();
     $senderDAO = new SenderDAO();
     $sendersQuery = array();
     $strong = \Strong\Strong::getInstance();
     $user2 = $strong->getUser();
     $groupsQuery['user_id'] = $user2['id'];
     $sendersQuery['user_id'] = $user2['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->view->set('KIND_TEXT_MSG', Message::KIND_TEXT_MSG);
     $app->view->set('KIND_PHOTO_MSG', Message::KIND_PHOTO_MSG);
     $app->view->set('KIND_AUDIO_MSG', Message::KIND_AUDIO_MSG);
     $app->view->set('KIND_VIDEO_MSG', Message::KIND_VIDEO_MSG);
     $item = $dao->fetch($id);
     if (empty($item)) {
         return $app->notFound();
     } else {
         if (!$userDAO->hasRole('ADMIN') && $item->getGroupId() > 0 && !in_array($item->getGroupId(), array_keys($groups['list']))) {
             return $app->status(403);
         }
         if (empty($_POST['data'])) {
             $_POST['data'] = $item->getData();
         }
     }
     $statuses = $dao->getStatuses($item);
     if (!empty($_POST['resend'])) {
         $dao->resend($item);
         $app->redirect(MAINURL . '/messages/edit/' . $item->getId());
         return;
     }
     $item->dataHuman = self::getHumanUrl($item);
     $mime = '*/*';
     if (Message::KIND_PHOTO_MSG == $item->getKind()) {
         $mime = 'image/*';
     }
     if (Message::KIND_AUDIO_MSG == $item->getKind()) {
         $mime = 'audio/*';
     }
     if (Message::KIND_VIDEO_MSG == $item->getKind()) {
         $mime = 'video/*';
     }
     $item->setUserId($user->getId());
     $dateParts = explode('-', $_POST['stime_date']);
     $timeParts = explode(':', $_POST['stime_time']);
     $stime = mktime($timeParts[0], $timeParts[1], $timeParts[2], $dateParts[1], $dateParts[2], $dateParts[0]);
     $item->setStime($stime);
     if ($item->getKind() == Message::KIND_TEXT_MSG) {
         $item->setData($_POST['data']);
     }
     $item->setGroupId($_POST['group_id']);
     $item->setSenderId($_POST['sender_id']);
     $personalized = array();
     $customField = $dao->getCustomFields($item);
     $numbers = $groupDAO->getNumbers($item->getGroupId());
     foreach ($customField as $num => $fields) {
         if (empty($numbers[$num])) {
             continue;
         }
         $personalized[$num] = $num;
     }
     $_POST['personalized'] = 'personalized $validator';
     $validator = new \Valitron\Validator($_POST);
     $validator->addRule('credits', function ($name, $value) use($user, $userDAO) {
         if ($userDAO->hasRole('ADMIN')) {
             return true;
         }
         return $user->getCredits() > 0;
     });
     $validator->addRule('time', function ($name, $value) {
         $value = explode(':', $value);
         if (count($value) != 3) {
             return false;
         }
         return true;
     });
     $validator->addRule('personalized', function ($name, $value) use($personalized, $numbers) {
         if (count($personalized) == 0) {
             return true;
         }
         return count($personalized) == count($numbers);
     });
     $validator->rule('personalized', 'personalized');
     $validator->label('Personalized');
     $validator->rule('required', 'group_id');
     $validator->label('Group');
     $validator->rule('required', 'sender_id');
     $validator->label('Sender');
     $validator->rule('date', 'stime_date');
     $validator->label('Date');
     $validator->rule('time', 'stime_time');
     $validator->label('Time');
     $validator->rule('required', 'data');
     $validator->label('Message');
     $validator->rule('credits', 'credits');
     $validator->label('Credits');
     if ($validator->validate()) {
         $item = $dao->save($item);
         if (!empty($_POST['send']) && empty($statuses)) {
             $dao->addStatus($item, Message::MESSAGE_STATUS_TO_SEND);
             if (!$userDAO->hasRole('ADMIN')) {
                 $numbers = $groupDAO->getNumbers($item->getGroupId());
                 $user->setCredits($user->getCredits() - count($numbers));
                 $userDAO->save($user);
             }
         }
         $app->redirect(MAINURL . '/messages/edit/' . $item->getId());
     } else {
         $app->view->set('menu', 'messages');
         $app->view->set('id', $id);
         $app->view->set('item', $item);
         $app->view->set('numbers', $numbers);
         $app->view->set('numbers_count', count($numbers));
         $app->view->set('personalized', $personalized);
         $app->view->set('personalized_count', count($personalized));
         $app->view->set('groups', $groups);
         $app->view->set('senders', $senders);
         $app->view->set('statuses', $statuses);
         $app->view->set('errors', $validator->errors());
         $app->view->set('mime', $mime);
         $app->render('messages/edit.twig.html');
     }
 }
Beispiel #3
0
    $retVal = '';
    for ($i = 0; $i < strlen($str); $i++) {
        $retVal .= sprintf("%02X ", ord($str[$i]));
    }
    return $retVal;
}
function logToCronFile($msg)
{
    echo date("Y-m-d H:i:s") . ' ' . time() . " " . $msg . "\n";
    file_put_contents(__DIR__ . '/logs/whatsapp.' . date('Ymd') . '.log', date("Y-m-d H:i:s") . " " . $msg . "\n", FILE_APPEND | LOCK_EX);
}
ob_start();
$senderDAO = new SenderDAO();
$groupDAO = new GroupDAO();
$messageDAO = new MessageDAO();
$senders = $senderDAO->getList();
foreach ($senders['list'] as $sender) {
    if ('' == $sender->getPassword()) {
        logToCronFile("No password for sender: " . $sender->getUsername());
        continue;
    }
    $sender = $senderDAO->fetch($sender->getId());
    if (($sender->getFlags() & \GitGis\Whatsapp\Model\Sender::FLAG_UNSYNC) > 0) {
        logToCronFile("Syncing " . $sender->getUsername());
        $groups = $groupDAO->getList(array('user_id' => $sender->getUserId()));
        $contacts = array();
        foreach ($groups['list'] as $groupId => $group) {
            $groupDAO->clearSynced($groupId);
            $groupNumbers = $groupDAO->getNumbers($groupId);
            foreach (array_keys($groupNumbers) as $number) {
                if ($number[0] != '+') {
Beispiel #4
0
 /**
  * Process edit sender form, validate, save to DB
  *
  * @param unknown $id
  * @return boolean
  */
 public static function postEditPage($id)
 {
     $app = \Slim\Slim::getInstance();
     $dao = new SenderDAO();
     $userDAO = new UserDAO();
     $item = $dao->fetch($id);
     if (empty($item)) {
         return $app->notFound();
     }
     $_POST['username'] = preg_replace('![^0-9]*!', '', $_POST['username']);
     $item->setNickname($_POST['nickname']);
     if (empty($id)) {
         $item->setUsername($_POST['username']);
     }
     if ($userDAO->hasRole('ADMIN')) {
         $item->setUserId($_POST['user_id']);
     } else {
         if (empty($id)) {
             $strong = \Strong\Strong::getInstance();
             $user = $strong->getUser();
             $item->setUserId($user['id']);
         }
     }
     $validator = new \Valitron\Validator($_POST);
     $validator->addRule('unique_username', function ($name, $value) use($id, $dao) {
         $list = $dao->getList(array('username' => $value));
         if (!empty($list['list'])) {
             foreach ($list['list'] as $item) {
                 if ($item->getId() != $id) {
                     return false;
                 }
             }
         }
         return true;
     }, 'is not unique');
     $validator->rule('unique_username', 'username');
     $validator->rule('required', 'nickname');
     $validator->rule('required', 'username');
     $validator->label('MSISDN');
     if ($validator->validate()) {
         $item = $dao->save($item);
         $app->flash('info', 'Sender ' . $item->getNickname() . ' has been created successfully');
         $app->redirect(MAINURL . '/senders/edit/' . $item->getId());
     } else {
         $app->view->set('menu', 'senders');
         $app->view->set('id', $id);
         $app->view->set('users', $userDAO->getList());
         $app->view->set('item', $item);
         $app->view->set('errors', $validator->errors());
         $app->render('senders/edit.twig.html');
     }
 }