public function dashboardAction() { $widget_model = new waWidgetModel(); $locale = wa()->getUser()->getLocale(); // Create dashboard widgets on first login if (!wa()->getUser()->getSettings('webasyst', 'dashboard')) { $apps = wa()->getApps(true); $widgets = array(); foreach ($apps as $app_id => $app) { if ($app_id == 'webasyst' || $this->getUser()->getRights($app_id, 'backend')) { foreach (wa($app_id)->getConfig()->getWidgets() as $w_id => $w) { if (!empty($w['locale']) && $w['locale'] != $locale) { continue; } $widgets[] = $w; } } } $block = 0; $contact_id = wa()->getUser()->getId(); foreach ($widgets as $w) { $max_size = $w['sizes'][0]; foreach ($w['sizes'] as $s) { if ($s[0] + $s[1] > $max_size[0] + $max_size[1]) { $max_size = $s; } } $row = array('app_id' => $w['app_id'], 'widget' => $w['widget'], 'name' => $w['name'], 'block' => $block++, 'sort' => 0, 'size' => $max_size[0] . 'x' . $max_size[1], 'contact_id' => $contact_id, 'create_datetime' => date('Y-m-d H:i:s')); $widget_model->insert($row); } wa()->getUser()->setSettings('webasyst', 'dashboard', 1); } // fetch widgets $rows = $widget_model->getByContact($this->getUserId()); $widgets = array(); foreach ($rows as $row) { if ($row['app_id'] == 'webasyst' || $this->getUser()->getRights($row['app_id'], 'backend')) { $app_widgets = wa($row['app_id'])->getConfig()->getWidgets(); if (isset($app_widgets[$row['widget']])) { $row['size'] = explode('x', $row['size']); $row = $row + $app_widgets[$row['widget']]; foreach ($row['sizes'] as $s) { if ($s == array(1, 1)) { $row['has_sizes']['small'] = true; } elseif ($s == array(2, 1)) { $row['has_sizes']['medium'] = true; } elseif ($s == array(2, 2)) { $row['has_sizes']['big'] = true; } } $widgets[$row['block']][] = $row; } } } $this->view->assign('widgets', $widgets); // announcement $user = wa()->getUser(); $announcement_model = new waAnnouncementModel(); $apps = $user->getApps(); $data = $announcement_model->getByApps($user->getId(), array_keys($apps), $user['create_datetime']); $announcements = array(); $announcements_apps = array(); foreach ($data as $row) { // show no more than 1 message per application if (!empty($announcements_apps[$row['app_id']])) { continue; } $announcements_apps[$row['app_id']] = true; $announcements[] = $row; } $this->view->assign('notifications', $announcements); // activity stream $activity_action = new webasystDashboardActivityAction(); $this->view->assign('apps', wa()->getUser()->getApps()); $user_filters = wa()->getUser()->getSettings('webasyst', 'dashboard_activity'); if ($user_filters) { $user_filters = explode(',', $user_filters); } else { $user_filters = array(); } $this->view->assign('user_filters', $user_filters); $this->view->assign('activity', $activity_action->getLogs(array(), $count)); if ($count == 50) { $this->view->assign('activity_load_more', true); } // Whether to show tutorial $this->view->assign('show_tutorial', !wa()->getUser()->getSettings('webasyst', 'widget_tutorial_closed')); }
function wa_header() { $system = waSystem::getInstance(); if ($system->getEnv() == 'frontend') { return ''; } $root_url = $system->getRootUrl(); $backend_url = $system->getConfig()->getBackendUrl(true); $user = $system->getUser(); $apps = $user->getApps(); $current_app = $system->getApp(); $app_settings_model = new waAppSettingsModel(); $apps_html = ''; $applist_class = ''; $counts = wa()->getStorage()->read('apps-count'); if (is_array($counts)) { $applist_class .= ' counts-cached'; } foreach ($apps as $app_id => $app) { if (isset($app['img'])) { $img = '<img ' . (!empty($app['icon'][96]) ? 'data-src2="' . $root_url . $app['icon'][96] . '"' : '') . ' src="' . $root_url . $app['img'] . '" alt="">'; } else { $img = ''; } $count = ''; $app_url = $backend_url . $app_id . '/'; if ($counts && isset($counts[$app_id])) { if (is_array($counts[$app_id])) { $app_url = $counts[$app_id]['url']; $n = $counts[$app_id]['count']; } else { $n = $counts[$app_id]; } if ($n) { $count = '<span class="indicator">' . $n . '</span>'; } } $apps_html .= '<li id="wa-app-' . $app_id . '"' . ($app_id == $current_app ? ' class="selected"' : '') . '><a href="' . $app_url . '">' . $img . ' ' . $app['name'] . $count . '</a></li>'; } $announcement_model = new waAnnouncementModel(); $announcements = array(); if ($current_app != 'webasyst') { $data = $announcement_model->getByApps($user->getId(), array_keys($apps), $user['create_datetime']); foreach ($data as $row) { // show no more than 1 message per application if (isset($announcements[$row['app_id']]) && count($announcements[$row['app_id']]) >= 1) { continue; } $announcements[$row['app_id']][] = $row['text'] . ' <span class="hint">' . waDateTime::format('humandatetime', $row['datetime']) . '</span>'; } } $announcements_html = ''; foreach ($announcements as $app_id => $texts) { $announcements_html .= '<a href="#" rel="' . $app_id . '" class="wa-announcement-close" title="close">×</a><p>'; $announcements_html .= implode('<br />', $texts); $announcements_html .= '</p>'; } if ($announcements_html) { $announcements_html = '<div id="wa-announcement">' . $announcements_html . '</div>'; } $logout = _ws('logout'); $userpic = '<img width="32" height="32" src="' . $user->getPhoto(32) . '" alt="">'; $username = htmlspecialchars(waContactNameField::formatName($user), ENT_QUOTES, 'utf-8'); // If the user has access to contacts app then show a link to his profile if (wa()->appExists('contacts')) { require_once wa()->getConfig()->getAppsPath('contacts', 'lib/models/contactsRights.model.php'); try { $cr = new contactsRightsModel(); } catch (waDbException $e) { wa('contacts'); $cr = new contactsRightsModel(); } if ($user->getRights('contacts', 'backend') && $cr->getRight(null, $user['id'])) { $userpic = '<a href="' . $backend_url . 'contacts/#/contact/' . $user['id'] . '">' . $userpic . '</a>'; $username = '******' . $backend_url . 'contacts/#/contact/' . $user['id'] . '" id="wa-my-username">' . $username . '</a>'; } else { $userpic = '<a href="' . $backend_url . '?module=profile">' . $userpic . '</a>'; $username = '******' . $backend_url . '?module=profile" id="wa-my-username">' . $username . '</a>'; } } $more = _ws('more'); if ($applist_class) { $applist_class = ' class="' . trim($applist_class) . '"'; } $company_name = htmlspecialchars($app_settings_model->get('webasyst', 'name', 'Webasyst'), ENT_QUOTES, 'utf-8'); $company_url = $app_settings_model->get('webasyst', 'url', $system->getRootUrl(true)); $version = wa()->getVersion(); $strings = array('customize' => _ws('Customize dashboard'), 'done' => _ws('Done editing'), 'date' => _ws(waDateTime::date('l')) . ', ' . trim(str_replace(date('Y'), '', waDateTime::format('humandate')), ' ,/')); $html = <<<HTML <script type="text/javascript">var backend_url = "{$backend_url}";</script> {$announcements_html} <div id="wa-header"> <div id="wa-account"> HTML; if (wa()->getApp() == 'webasyst') { $html .= <<<HTML <h3>{$company_name} <a href="{$company_url}" class="wa-frontend-link" target="_blank"><i class="icon16 new-window"></i></a></h3> <a class="inline-link" id="show-dashboard-editable-mode" href="{$backend_url}"><b><i>{$strings['customize']}</i></b></a> <input id="close-dashboard-editable-mode" type="button" value="{$strings['done']}" style="display: none;"> HTML; } else { $html .= <<<HTML <a href="{$backend_url}" class="wa-dashboard-link"><h3>{$company_name}</h3> <span class="gray">{$strings['date']}</span></a> HTML; } $html .= <<<HTML </div> <div id="wa-usercorner"> <div class="profile image32px"> <div class="image"> {$userpic} </div> <div class="details"> {$username} <p class="status"></p> <a class="hint" href="{$backend_url}?action=logout">{$logout}</a> </div> </div> </div> <div id="wa-applist" {$applist_class}> <ul> {$apps_html} <li> <a href="#" id="wa-moreapps"></a> </li> </ul> HTML; if (wa()->getApp() == 'webasyst') { $html .= '<div class="d-dashboard-header-content"> <div class="d-dashboards-list-wrapper" id="d-dashboards-list-wrapper"></div> <div class="d-dashboard-link-wrapper" id="d-dashboard-link-wrapper"><i class="icon10 lock-bw"></i> ' . _w('Only you can see this dashboard.') . '</div> </div>'; } $html .= <<<HTML </div> </div> <script id="wa-header-js" type="text/javascript" src="{$root_url}wa-content/js/jquery-wa/wa.header.js?v{$version}"></script> HTML; return $html; }
function wa_header() { $system = waSystem::getInstance(); if ($system->getEnv() == 'frontend') { return ''; } $root_url = $system->getRootUrl(); $backend_url = $system->getConfig()->getBackendUrl(true); $user = $system->getUser(); $apps = $user->getApps(); $current_app = $system->getApp(); $app_settings_model = new waAppSettingsModel(); $apps_html = ''; $applist_class = ''; $counts = wa()->getStorage()->read('apps-count'); if (is_array($counts)) { $applist_class .= ' counts-cached'; } foreach ($apps as $app_id => $app) { if (isset($app['img'])) { $img = '<img src="' . $root_url . $app['img'] . '" alt="">'; } else { $img = ''; } $count = ''; $app_url = $backend_url . $app_id . '/'; if ($counts && isset($counts[$app_id])) { if (is_array($counts[$app_id])) { $app_url = $counts[$app_id]['url']; $n = $counts[$app_id]['count']; } else { $n = $counts[$app_id]; } if ($n) { $count = '<span class="indicator">' . $n . '</span>'; } } $apps_html .= '<li id="wa-app-' . $app_id . '"' . ($app_id == $current_app ? ' class="selected"' : '') . '><a href="' . $app_url . '">' . $img . ' ' . $app['name'] . $count . '</a></li>'; } if ($system->getRequest()->isMobile(false)) { $top_url = '<a href="' . $backend_url . '?mobile=1">mobile version</a>'; } else { $url = $app_settings_model->get('webasyst', 'url', $system->getRootUrl(true)); $url_info = @parse_url($url); if ($url_info) { $url_name = ''; if (empty($url_info['scheme'])) { $url = 'http://' . $url; } if (!empty($url_info['scheme']) && $url_info['scheme'] != 'http') { $url_name = $url_info['scheme'] . '://'; } if (isset($url_info['host'])) { $url_name .= $url_info['host']; } if (isset($url_info['path'])) { if ($url_info['path'] == '/' && !isset($url_info['query'])) { } else { $url_name .= $url_info['path']; } } if (isset($url_info['query'])) { $url_name .= '?' . $url_info['query']; } } else { $url = $url_name = $system->getRootUrl(true); } $top_url = '<a target="_blank" href="' . $url . '">' . $url_name . '</a>'; } $announcement_model = new waAnnouncementModel(); $data = $announcement_model->getByApps($user->getId(), array_keys($apps), $user['create_datetime']); $announcements = array(); foreach ($data as $row) { // show no more than 1 message per application if (isset($announcements[$row['app_id']]) && count($announcements[$row['app_id']]) >= 1) { continue; } $announcements[$row['app_id']][] = waDateTime::format('datetime', $row['datetime']) . ': ' . $row['text']; } $announcements_html = ''; foreach ($announcements as $app_id => $texts) { $announcements_html .= '<a href="#" rel="' . $app_id . '" class="wa-announcement-close" title="close">' . _ws('[close]') . '</a><p>'; $announcements_html .= implode('<br />', $texts); $announcements_html .= '</p>'; } if ($announcements_html) { $announcements_html = '<div id="wa-announcement">' . $announcements_html . '</div>'; } $logout = _ws('logout'); $userpic = '<img width="32" height="32" src="' . $user->getPhoto(32) . '" alt="">'; $username = htmlspecialchars($user['name'], ENT_QUOTES, 'utf-8'); // If the user has access to contacts app then show a link to his profile if (wa()->getUser()->getRights('contacts', 'backend')) { $userpic = '<a href="' . $backend_url . 'contacts/#/contact/' . $user['id'] . '">' . $userpic . '</a>'; $username = '******' . $backend_url . 'contacts/#/contact/' . $user['id'] . '" id="wa-my-username">' . $username . '</a>'; } $more = _ws('more'); if ($applist_class) { $applist_class = ' class="' . trim($applist_class) . '"'; } $company_name = htmlspecialchars($app_settings_model->get('webasyst', 'name', 'Webasyst'), ENT_QUOTES, 'utf-8'); $version = wa()->getVersion(); $html = <<<HTML <script type="text/javascript">var backend_url = "{$backend_url}";</script> {$announcements_html} <div id="wa-header"> <div id="wa-account"> <h3>{$company_name}</h3> {$top_url} </div> <div id="wa-usercorner"> <div class="profile image32px"> <div class="image"> {$userpic} </div> <div class="details"> {$username} <p class="status"></p> <a class="hint" href="{$backend_url}?action=logout">{$logout}</a> </div> </div> </div> <div id="wa-applist" {$applist_class}> <ul> {$apps_html} <li> <a href="#" class="inline-link" id="wa-moreapps"><i class="icon10 darr" id="wa-moreapps-arrow"></i><b><i>{$more}</i></b></a> </li> </ul> </div> </div> <script id="wa-header-js" type="text/javascript" src="{$root_url}wa-content/js/jquery-wa/wa.header.js?v{$version}"></script> HTML; return $html; }
public static function getUpdates($vendor = null) { static $items = null; $config = wa('installer')->getConfig(); if ($items === null) { self::$counter = array('total' => 0, 'applicable' => 0, 'payware' => 0); $app_settings_model = new waAppSettingsModel(); $errors = (array) json_decode($app_settings_model->get('installer', 'errors', '[]')); $items = self::getInstaller()->getUpdates($vendor); $changed = false; foreach ($items as $id => $item) { if (isset($item['version'])) { ++self::$counter['total']; if (!empty($item['applicable'])) { ++self::$counter['applicable']; } } if (!empty($item['error'])) { if (!$errors) { $model = new waAnnouncementModel(); $data = array('app_id' => 'installer', 'text' => $item['error'], 'datetime' => date('Y-m-d H:i:s', time() - 86400)); if (!$model->select('COUNT(1) `cnt`')->where('app_id=s:app_id AND datetime > s:datetime', $data)->fetchField('cnt')) { $data['datetime'] = date('Y-m-d H:i:s'); $model->insert($data); } } $errors[$id] = true; $changed = true; } elseif (!empty($errors[$id])) { unset($errors[$id]); $changed = true; } foreach (array('themes', 'plugins') as $extras) { if (isset($item[$extras])) { self::$counter['total'] += count($item[$extras]); foreach ($item[$extras] as $extras_item) { if (!empty($extras_item['applicable'])) { ++self::$counter['applicable']; } } } } } if ($changed) { $app_settings_model->ping(); $app_settings_model->set('installer', 'errors', json_encode($errors)); } if ($errors) { $count = '!'; } elseif (self::$counter['total']) { $count = self::$counter['total']; } else { $count = null; } $config->setCount($count); } return $items; }