public function execute() { $system = wa(); $datetime = $system->getDateTime(); if (!($this->id = (int) waRequest::get('id'))) { throw new waException('No id specified.'); } $user = $this->getUser()->getRights('contacts', 'backend'); $admin = $user >= 2; $ownProfile = $this->id == wa()->getUser()->getId(); $cr = new contactsRightsModel(); if (!$cr->getRight(null, $this->id)) { if ($user && $ownProfile) { $this->view->assign('readonly', true); } else { throw new waRightsException('Access denied.'); } } $this->getContactInfo(); $this->getUserInfo(); // free or premium app? $this->view->assign('versionFull', $this->getConfig()->getInfo('edition') === 'full'); // collect data from other applications to show in tabs (for premium app only) if ($this->getConfig()->getInfo('edition') === 'full') { $links = array(); foreach (wa()->event('profile.tab', $this->id) as $app_id => $one_or_more_links) { if (!isset($one_or_more_links['html'])) { $i = ''; foreach ($one_or_more_links as $link) { $key = isset($link['id']) ? $link['id'] : $app_id . $i; $links[$key] = $link; $i++; } } else { $key = isset($one_or_more_links['id']) ? $one_or_more_links['id'] : $app_id; $links[$key] = $one_or_more_links; } } $this->view->assign('links', $links); } // tab to open by default $this->view->assign('tab', waRequest::get('tab')); $this->view->assign('admin', $admin); $this->view->assign('superadmin', $admin && $this->getUser()->getRights('webasyst', 'backend')); $this->view->assign('current_user_id', wa()->getUser()->getId()); $this->view->assign('limitedCategories', $admin || $this->getRights('category.all') ? 0 : 1); // Update history if (($name = $this->contact->get('name')) || $name === '0') { $name = trim($this->contact->get('title') . ' ' . $name); $history = new contactsHistoryModel(); $history->save('/contact/' . $this->id, $name); } // Update history in user's browser $historyModel = new contactsHistoryModel(); $this->view->assign('history', $historyModel->get()); $this->view->assign('wa_view', $this->view); }
public function execute() { $system = wa(); $datetime = $system->getDateTime(); $user = $this->getUser()->getRights('contacts', 'backend'); $admin = $user >= 2; $cr = new contactsRightsModel(); if (!empty($this->params['limited_own_profile'])) { $this->id = wa()->getUser()->getId(); $this->view->assign('limited_own_profile', true); $this->view->assign('save_url', '?module=profile&action=save'); $this->view->assign('password_save_url', '?module=profile&action=password'); $this->view->assign('save_geocoords_url', '?module=profile&action=saveGeocoords'); $this->view->assign('photo_upload_url', '?module=profile&action=tmpimage'); $this->view->assign('photo_editor_url', '?module=profile&action=photo'); $this->view->assign('photo_editor_uploaded_url', '?module=profile&action=photo&uploaded=1'); } else { $this->id = (int) waRequest::get('id'); if (empty($this->id)) { throw new waException('No id specified.'); } $r = $cr->getRight(null, $this->id); //var_dump($r );exit; if (!$r) { throw new waRightsException(_w('Access denied')); } else { $this->view->assign('readonly', $r === 'read'); } } $exists = $this->getContactInfo(); if ($exists) { $this->getUserInfo(); $this->view->assign('last_view_context', $this->getLastViewContext()); // collect data from other applications to show in tabs if (empty($this->params['limited_own_profile'])) { $links = array(); foreach (wa()->event('profile.tab', $this->id) as $app_id => $one_or_more_links) { if (!isset($one_or_more_links['html'])) { $i = ''; foreach ($one_or_more_links as $link) { $key = isset($link['id']) ? $link['id'] : $app_id . $i; $links[$key] = $link; $i++; } } else { $key = isset($one_or_more_links['id']) ? $one_or_more_links['id'] : $app_id; $links[$key] = $one_or_more_links; } } $this->view->assign('links', $links); } // tab to open by default $this->view->assign('tab', waRequest::get('tab')); $this->view->assign('admin', $admin); $this->view->assign('superadmin', $admin && $this->getUser()->getRights('webasyst', 'backend')); $this->view->assign('current_user_id', wa()->getUser()->getId()); $this->view->assign('can_edit', $cr->getRight(null, $this->id)); // Update history if (empty($this->params['limited_own_profile'])) { $name = $this->contact->get('name'); if ($name || $name === '0') { $history = new contactsHistoryModel(); $history->save('/contact/' . $this->id, $name); } // Update history in user's browser $historyModel = new contactsHistoryModel(); $this->view->assign('history', $historyModel->get()); } $this->view->assign('wa_view', $this->view); $this->view->assign('access_disable_msg', contactsHelper::getAccessDisableMsg($this->contact)); $this->view->assign('my_url', wa()->getRootUrl(true) . 'my/'); $this->view->assign('backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl(false) . '/'); $this->view->assign('static_url', wa()->getAppStaticUrl('contacts')); } $this->view->assign('exists', $exists); if ($this->getRequest()->request('standalone')) { /** * Include plugins js and css * @event backend_assets * @return array[string]string $return[%plugin_id%] */ $this->view->assign('backend_assets', wa()->event('backend_assets')); } $auth = wa()->getAuthConfig(); $this->view->assign('personal_portal_available', !empty($auth['app'])); /* * @event backend_contact_info * @return array[string]array $return[%plugin_id%] array of html output * @return array[string][string]string $return[%plugin_id%]['after_header'] html output * @return array[string][string]string $return[%plugin_id%]['header'] html output * @return array[string][string]string $return[%plugin_id%]['before_header'] html output * @return array[string][string]string $return[%plugin_id%]['before_top'] html output * @return array[string][string]string $return[%plugin_id%]['top'] html output * @return array[string][string]string $return[%plugin_id%]['after_top'] html output * @return array[string][string]string $return[%plugin_id%]['photo'] html output */ $backend_contact_info_params = array('contact_id' => $this->id); $this->view->assign('backend_contact_info', wa()->event('backend_contact_info', $backend_contact_info_params)); }
public function execute() { $this->id = (int) waRequest::post('id'); // Check access if (!$this->id) { if (!$this->getRights('create')) { throw new waRightsException('Access denied.'); } } else { $cr = new contactsRightsModel(); if ($cr->getRight(null, $this->id) != 'write') { throw new waRightsException('Access denied.'); } } $this->type = waRequest::post('type'); $this->contact = new waContact($this->id); if ($this->type == 'company') { $this->contact['is_company'] = 1; } $data = json_decode(waRequest::post('data'), true); if (!$this->id && !isset($data['create_method'])) { $data['create_method'] = 'add'; } $oldLocale = $this->getUser()->getLocale(); // get old data for logging if ($this->id) { $old_data = array(); foreach ($data as $field_id => $field_value) { $old_data[$field_id] = $this->contact->get($field_id); } } $response = array(); if (!($errors = $this->contact->save($data, true))) { if ($this->id) { $new_data = array(); foreach ($data as $field_id => $field_value) { if (!isset($errors[$field_id])) { $response[$field_id] = $this->contact->get($field_id, 'js'); $new_data[$field_id] = $this->contact->get($field_id); } } if (empty($errors)) { $this->logContactEdit($old_data, $new_data); } $response['name'] = $this->contact->get('name', 'js'); $response['top'] = contactsHelper::getTop($this->contact); $response['id'] = $this->contact->getId(); } else { $response = array('id' => $this->contact->getId()); $response['address'] = $this->contact->get('address', 'js'); $this->logAction('contact_add', null, $this->contact->getId()); } // Update recently added menu item $name = waContactNameField::formatName($this->contact); if ($name || $name === '0') { $history = new contactsHistoryModel(); $history->save('/contact/' . $this->contact->getId(), $name, $this->id ? null : 'add'); $history = $history->get(); // to update history in user's browser } } // Reload page with new language if user just changed it in own profile if ($this->contact->getId() == $this->getUser()->getId() && $oldLocale != $this->contact->getLocale()) { $response['reload'] = true; } $this->response = array('errors' => $errors, 'data' => $response); if (isset($history)) { $this->response['history'] = $history; } }
/** * Verifies current user's access rights to contact with specified id. * * @param int|null $contact_id Contact id. If not specified, access rights to all contacts are verified. * @return bool */ public static function getContactRights($contact_id = null) { $rights = false; if (wa()->appExists('contacts')) { if ($contact_id) { wa('contacts'); $contact_rights = new contactsRightsModel(); if ($contact_rights->getRight(null, $contact_id)) { $rights = true; } } else { $rights = wa()->getUser()->getRights('contacts'); $rights = $rights && !empty($rights['backend']); } } return $rights; }
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; }
public function execute() { $this->id = (int) waRequest::post('id'); // Check access if (!$this->id) { if (!$this->getRights('create')) { throw new waRightsException('Access denied.'); } } else { $cr = new contactsRightsModel(); if ($cr->getRight(null, $this->id) != 'write') { throw new waRightsException('Access denied.'); } } $this->type = waRequest::post('type'); $this->contact = new waContact($this->id); if ($this->type == 'company') { $this->contact['is_company'] = 1; } $data = json_decode(waRequest::post('data'), true); if (!$this->id && !isset($data['create_method'])) { $data['create_method'] = 'add'; } $oldLocale = $this->getUser()->getLocale(); $response = array(); if (!($errors = $this->contact->save($data, true))) { if ($this->id) { foreach ($data as $field_id => $field_value) { if (!isset($errors[$field_id])) { $response[$field_id] = $this->contact->get($field_id, 'js'); } } $response['name'] = $this->contact->get('name', 'js'); $fields = array('email', 'phone', 'im'); $top = array(); foreach ($fields as $f) { if ($v = $this->contact->get($f, 'top,html')) { $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v); } } $response['top'] = $top; } else { $response = array('id' => $this->contact->getId()); $this->log('contact_add', 1); } // Update recently added menu item if (($name = $this->contact->get('name')) || $name === '0') { $name = trim($this->contact->get('title') . ' ' . $name); $history = new contactsHistoryModel(); $history->save('/contact/' . $this->contact->getId(), $name, $this->id ? null : 'add'); $history = $history->get(); // to update history in user's browser } } // Reload page with new language if user just changed it in own profile if ($this->contact->getId() == $this->getUser()->getId() && $oldLocale != $this->contact->getLocale()) { $response['reload'] = TRUE; } $this->response = array('errors' => $errors, 'data' => $response); if (isset($history)) { $this->response['history'] = $history; } }
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>'; } 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 (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']][] = $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 inline-link" title="close"><b><i>' . _ws('Close') . '</i></b></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'); $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="#" id="wa-moreapps"></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; }