Beispiel #1
0
 public function getName($id = false)
 {
     $rez = 'no name';
     if ($id === false) {
         $id = $this->id;
     }
     if (!empty($id) && is_numeric($id)) {
         $facetConfig = $this->getFacetFieldConfig($this->getClassDepth() - 1);
         switch (@$facetConfig['type']) {
             case 'users':
                 $rez = User::getDisplayName($id);
                 break;
             case 'varchar':
                 $rez = $id;
                 break;
             default:
                 $rez = Objects::getName($id);
         }
     } else {
         switch ($id) {
             case 'root':
                 $rez = parent::getName('root');
                 break;
         }
     }
     return $rez;
 }
function sendUserMails($u)
{
    $uid = $u['id'];
    if (empty($u['email'])) {
        return;
    }
    $sendType = User::canSendNotifications($uid);
    if ($sendType == false) {
        return;
    }
    $coreName = Config::get('core_name');
    // $coreUrl = Config::get('core_url');
    $languages = Config::get('languages');
    $lang = $languages[$u['language_id'] - 1];
    if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) {
        //group mails into digest and separate ones (where user is mentioned)
        $mails = array('digest' => array(), 'separate' => array());
        foreach ($u['mails'] as $notificationId => $notification) {
            //[$core #$nodeId] $action_type $template_name: $object_title
            $templateId = Objects::getTemplateId($notification['object_id']);
            $templateName = Objects::getName($templateId);
            $subject = '[' . $coreName . ' #' . $notification['object_id'] . '] ' . Notifications::getActionDeclination($notification['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($notification['data']['name']) . '"';
            $sender = Notifications::getSender($notification['from_user_id']);
            //divide notification into separate number of actions it consist of
            $actions = getNotificationActions($notification);
            for ($i = 0; $i < sizeof($actions); $i++) {
                $a = $actions[$i];
                $message = Notifications::getMailBodyForAction($a, $u);
                $isMentioned = !empty($a['data']['mentioned']) && in_array($uid, $a['data']['mentioned']);
                $mails[$isMentioned ? 'separate' : 'digest'][] = array('subject' => $subject, 'body' => $message, 'sender' => $sender, 'nId' => $notificationId);
            }
        }
        //merge digest emails group into one email and put it into separate group
        if (sizeof($mails['digest']) == 1) {
            $mails['separate'][] = $mails['digest'][0];
        } elseif (!empty($mails['digest'])) {
            $mail = array();
            $ids = array();
            $sender = '';
            foreach ($mails['digest'] as $m) {
                $mail[] = $m['body'];
                $sender = $m['sender'];
                $ids[] = $m['nId'];
            }
            $mails['separate'][] = array('subject' => '[' . $coreName . '] Notifications digest', 'body' => implode('<hr />', $mail), 'sender' => $sender, 'nId' => $ids);
        }
        foreach ($mails['separate'] as $mail) {
            echo $u['email'] . ': ' . $mail['subject'] . "\n";
            if (!mail($u['email'], $mail['subject'], $mail['body'], "Content-type: text/html; charset=utf-8\r\nFrom: " . $mail['sender'] . "\r\n")) {
                System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $mail['nId'] . ') mail to "' . $u['email'] . '"', $mail['body']);
            } else {
                DM\Notifications::markAsSeen($mail['nId'], $uid);
            }
        }
        if (!empty($mails['digest'])) {
            User::setUserConfigParam('lastNotifyTime', Util\dateISOToMysql('now'), $uid);
        }
    }
}
Beispiel #3
0
 public function getName($id = false)
 {
     if ($id == false) {
         $id = $this->id;
     }
     $rez = Objects::getName($id);
     return $rez;
 }
Beispiel #4
0
 /**
  * get data model pid that is different from tree one
  * @param  int $pid
  * @return int
  */
 protected function getDMPid($pid)
 {
     $rez = null;
     $name = Objects::getName($pid);
     $id = DM\Config::toId($name, 'param');
     if (is_numeric($id)) {
         $rez = $id;
     }
     return $rez;
 }
Beispiel #5
0
 public function getName($id = false)
 {
     if ($id === false) {
         $id = $this->id;
     }
     $rez = $id;
     switch ($id) {
         case 'recycleBin':
             return L\get('RecycleBin');
         default:
             if (!empty($id) && is_numeric($id)) {
                 $rez = \CB\Objects::getName($id);
             }
             break;
     }
     return $rez;
 }
 public function getName($id = false)
 {
     if ($id == false) {
         $id = $this->id;
     }
     switch ($id) {
         case 1:
             return L\get('Manager');
         case 2:
             return L\get('Lead');
         case 3:
             return L\get('Support');
         case 4:
             return L\get('AllMyCases');
     }
     return Objects::getName($id);
 }
Beispiel #7
0
 public function getData($id = false)
 {
     $rez = array('success' => true, 'data' => array());
     parent::getData($id);
     $obj = $this->getObjectClass();
     if (!is_object($obj)) {
         return $rez;
     }
     $data = $obj->getData();
     $rez['data'] = array_intersect_key($data, array('id' => 1, 'name' => 1, 'template_id' => 1, 'cid' => 1, 'cdate' => 1, 'uid' => 1, 'udate' => 1, 'dstatus' => 1, 'did' => 1, 'ddate' => 1, 'size' => 1));
     $d =& $rez['data'];
     $pids = Util\toNumericArray($data['pids']);
     array_pop($pids);
     $d['pids'] = $d['path'] = implode('/', $pids);
     $arr = array(&$d);
     Search::setPaths($arr);
     $d['template_name'] = Objects::getName($d['template_id']);
     $sd = $obj->getSysData();
     $userId = User::getId();
     $d['subscription'] = 'ignore';
     if (!empty($sd['fu']) && in_array($userId, $sd['fu'])) {
         $d['subscription'] = 'watch';
         //follow
     }
     if (!empty($sd['wu']) && in_array($userId, $sd['wu'])) {
         $d['subscription'] = 'watch';
     }
     $d['cid_text'] = User::getDisplayName($d['cid']);
     $d['cdate_ago_text'] = Util\formatAgoTime($d['cdate']);
     $d['cdate'] = Util\dateMysqlToISO($d['cdate']);
     $d['udate'] = Util\dateMysqlToISO($d['udate']);
     $d['uid_text'] = User::getDisplayName($d['uid']);
     $d['udate_ago_text'] = Util\formatAgoTime($d['udate']);
     if (!empty($d['dstatus'])) {
         $d['did_text'] = User::getDisplayName($d['did']);
         $d['ddate_text'] = Util\formatAgoTime($d['ddate']);
     }
     return $rez;
 }
Beispiel #8
0
 public function getName($id = false)
 {
     $rez = 'no name';
     if ($id === false) {
         $id = $this->id;
     }
     if (!empty($id) && is_numeric($id)) {
         $facetConfig = $this->getFacetFieldConfig($this->getClassDepth() - 1);
         switch (@$facetConfig['type']) {
             case 'users':
                 $rez = User::getDisplayName($id);
                 break;
             default:
                 $rez = Objects::getName($id);
         }
     } else {
         switch ($id) {
             case 'root':
                 $cfg =& $this->config;
                 $l = Config::get('user_language');
                 if (empty($cfg['title_' . $l])) {
                     $l = Config::get('language');
                     if (empty($cfg['title_' . $l])) {
                         if (!empty($cfg['title'])) {
                             $rez = $cfg['title'];
                         }
                     } else {
                         $rez = $cfg['title_' . $l];
                     }
                 } else {
                     $rez = $cfg['title_' . $l];
                 }
                 break;
         }
     }
     return $rez;
 }
Beispiel #9
0
 /**
  * save current file version into versions table
  * and delete versions exceeding mfvc
  * @param  int  $id   file id
  * @param  int  $mfvc max file version count
  * @return void
  */
 protected function saveCurrentVersion($id, $mfvc = false)
 {
     if ($mfvc === false) {
         $mfvc = $this->getMFVC(Objects::getName($id));
     }
     if (empty($mfvc)) {
         return false;
     }
     $data = DM\Files::read($id);
     $data['file_id'] = $data['id'];
     unset($data['id']);
     DM\FilesVersions::create($data);
     //detect versions exceeding mfvc and delete them
     if ($dIds = DM\FilesVersions::getOldestIds($id, $mfvc)) {
         DM\FilesVersions::delete($dIds);
     }
     return true;
 }
Beispiel #10
0
 /**
  * save current file version into versions table
  * and delete versions exceeding mfvc
  * @param  int  $id   file id
  * @param  int  $mfvc max file version count
  * @return void
  */
 protected function saveCurrentVersion($id, $mfvc = false)
 {
     if ($mfvc === false) {
         $mfvc = $this->getMFVC(Objects::getName($id));
     }
     if (empty($mfvc)) {
         return false;
     }
     $res = DB\dbQuery('INSERT INTO files_versions (
             file_id
             ,content_id
             ,`date`
             ,name
             ,cid
             ,uid
             ,cdate
             ,udate)
             SELECT id
                 ,content_id
                 ,`date`
                 ,name
                 ,cid
                 ,uid
                 ,cdate
                 ,udate
             FROM files
             WHERE id = $1', $id) or die(DB\dbQueryError());
     //detect versions exceeding mfvc and delete them
     $deleteVersionIds = array();
     $res = DB\dbQuery('SELECT id
         FROM files_versions
         WHERE file_id = $1
         ORDER BY id DESC
         LIMIT ' . $mfvc . ', 10', $id) or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $deleteVersionIds[] = $r['id'];
     }
     $res->close();
     if (!empty($deleteVersionIds)) {
         DB\dbQuery('DELETE
             FROM files_versions
             WHERE id in (' . implode(',', $deleteVersionIds) . ')') or die(DB\dbQueryError());
     }
     return true;
 }
Beispiel #11
0
 /**
  * process a message:
  *     - replace urls with links
  *     - replace object references with links
  * @param varchar $message
  */
 public static function processAndFormatMessage($message, $replacements = 'user,object,url')
 {
     if (empty($message)) {
         return $message;
     }
     $replacements = Util\toTrimmedArray($replacements);
     // replace urls with links
     if (in_array('url', $replacements)) {
         $message = \Kwi\UrlLinker::getInstance()->linkUrlsAndEscapeHtml($message);
     }
     //replace object references with links
     if (in_array('object', $replacements) && preg_match_all('/(.?)#(\\d+)(.?)/', $message, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             // check if not a html code
             if ($match[1] == '&' && $match[3] == ';') {
                 continue;
             }
             $templateId = Objects::getTemplateId($match[2]);
             $name = Objects::getName($match[2]);
             $name = strlen($name) > 30 ? mb_substr($name, 0, 30) . '&hellip;' : $name;
             $message = str_replace($match[0], $match[1] . '<a class="click obj-ref" itemid="' . $match[2] . '" templateid= "' . $templateId . '" title="' . $name . '"' . '>#' . $match[2] . '</a>' . $match[3], $message);
         }
     }
     //replace users with their names
     if (in_array('user', $replacements) && preg_match_all('/@([\\w\\.\\-]+[\\w])/', $message, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $userId = DM\User::getIdByName($match[1]);
             if (is_numeric($userId)) {
                 $userName = $match[1];
                 $message = str_replace($match[0], '<span class="cDB user-ref" title="' . User::getDisplayName($userId) . '">@' . $userName . '</span>', $message);
             }
         }
     }
     return $message;
 }
Beispiel #12
0
 public function toggleFavorite($p)
 {
     $favoriteFolderId = $this->getFavoriteFolderId();
     $p['pid'] = $favoriteFolderId;
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE pid = $1
             AND `type` = 2
             AND target_id = $2', array($favoriteFolderId, $p['id'])) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         DB\dbQuery('DELETE FROM tree WHERE id = $1', $r['id']) or die(DB\dbQueryError());
         $res->close();
         $p['favorite'] = 0;
     } else {
         $res->close();
         /* get objects name */
         $name = 'Link';
         $name = Objects::getName($p['id']);
         /* end of get objects name */
         DB\dbQuery('INSERT INTO tree
                 (pid
                 ,user_id
                 ,`type`
                 ,name
                 ,target_id)
             VALUES($1
                 ,$2
                 ,2
                 ,$3
                 ,$4)', array($favoriteFolderId, $_SESSION['user']['id'], $name, $p['id'])) or die(DB\dbQueryError());
         $p['favorite'] = 1;
     }
     return array('success' => true, 'data' => $p);
 }
    if (!isset($users[$uid])) {
        $users[$uid] = User::getPreferences($uid);
    }
    $users[$uid]['mails'][$r['id']] = $r;
}
//iterate mails for each user and send them
foreach ($users as $u) {
    if (empty($u['email'])) {
        continue;
    }
    $lang = $languages[$u['language_id'] - 1];
    if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) {
        foreach ($u['mails'] as $notificationId => $action) {
            //[$core #$nodeId] $action_type $template_name: $object_title
            $templateId = Objects::getTemplateId($action['object_id']);
            $templateName = Objects::getName($templateId);
            $subject = '[' . $coreName . ' #' . $action['object_id'] . '] ' . Notifications::getActionDeclination($action['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($action['data']['name']) . '"';
            //skip sending notifications from devel server to other emails than Admin
            if (!$sendNotificationMails && $u['email'] !== $adminEmail) {
                echo 'Devel skip: ' . $u['email'] . ': ' . $subject . "\n";
            } else {
                echo $u['email'] . ': ' . $subject . "\n";
                $message = Notifications::getMailBodyForAction($action, $u);
                $sender = Notifications::getSender($action['from_user_id']);
                // file_put_contents(TEMP_DIR . $action['id'].'.html', "$sender<br />\n<h1>$subject<h1>" . $message);
                //  COMMENTED FOR TEST
                if (!mail($u['email'], $subject, $message, "Content-type: text/html; charset=utf-8\r\nFrom: " . $sender . "\r\n")) {
                    $markNotificationAsSent = false;
                    System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $notificationId . ') mail to "' . $u['email'] . '"', $message);
                } else {
                    DB\dbQuery('UPDATE notifications