/** * @param waContact $user * @return string */ public static function getAccessDisableMsg($user) { $access_disable = ''; if ($user['is_user'] == '-1') { $log_model = new waLogModel(); $log_item = $log_model->select('*')->where("subject_contact_id = i:id AND action = 'access_disable'", array('id' => $user['id']))->order('datetime DESC')->limit(1)->fetch(); if ($log_item) { $contact = new waContact($log_item['contact_id']); $name = htmlspecialchars(waContactNameField::formatName($contact)); $access_disable = _w("Access disabled by") . " <a href='#/contact/{$log_item['contact_id']}/'>{$name}</a>, " . wa_date("humandatetime", $log_item['datetime']); } } return $access_disable; }
/** * Возвращает имя/имена указанного контакта/контактов * * @param int|array $id - число или массив * @return string|array - если $id был массивов, возвращает ассоциативный массив с ключем - id, значением - имя контакта */ public function getName($id) { $sql = "SELECT * FROM " . $this->table . " WHERE id "; if (is_array($id)) { $id = array_unique($id); $sql .= " IN ('" . implode("','", $this->escape($id, 'int')) . "')"; $rows = $this->query($sql)->fetchAll(); $result = array(); foreach ($rows as $row) { $result[$row['id']] = waContactNameField::formatName($row); } return $result; } else { $sql .= " = i:id"; $row = $this->query($sql, array('id' => $id))->fetch(); if ($row) { return waContactNameField::formatName($row); } return ''; } }
/** * Extend items by adding contact info into $rows[i]['user'] * Uses: * - $rows[i]['contact_id'] * - $rows[i]['name'] or $rows[i]['contact_name'] when contact is not found or its name is empty * - $rows[i]['auth_provider'] for default userpic URL * * @param array $rows * @param array $fields * @param bool $get_link pass true to get $rows[i]['user']['posts_link'] */ public static function extendUser(&$rows, $fields = array(), $get_link = false) { $default_fields = array('id', 'name', 'firstname', 'middlename', 'lastname'); $fields = array_unique(array_merge($fields, $default_fields)); // All contact ids $ids = array(); foreach ($rows as $row) { if ($row['contact_id']) { $ids[] = intval($row['contact_id']); } } $ids = array_unique($ids); // Fetch contacts using collection $collection = new waContactsCollection($ids); $contacts = $collection->getContacts(implode(',', $fields), 0, count($ids)); // Prepare data row to use as a placeholder when contact is not found $contact = new waContact(0); $contacts[0] = array('name' => ''); $photo_fields = array(); foreach ($fields as $field) { if (preg_match('@^photo_url_(\\d+)$@', $field, $matches)) { $photo_fields[] = $field; $contacts[0][$field] = $contact->getPhoto($matches[1], $matches[1]); } else { $contacts[0][$field] = $contact->get($field); } } // Format contact names foreach ($contacts as &$c) { $c['name'] = waContactNameField::formatName($c); } unset($c); // Add data as 'user' key to each row in $rows $app_static_url = wa()->getAppStaticUrl(); foreach ($rows as &$row) { $row['user'] = array(); $id = $row['contact_id'] = max(0, intval($row['contact_id'])); if (!isset($contacts[$id])) { $id = 0; } if (isset($contacts[$id])) { if (isset($row['url']) && $get_link && !isset($contacts[$id]['posts_link'])) { $contacts[$id]['posts_link'] = blogPost::getUrl($row, 'author'); } $row['user'] = $contacts[$id]; } if (!$id || !isset($contacts[$id])) { if (isset($row['name'])) { $row['user']['name'] = $row['name']; } elseif (isset($row['contact_name'])) { $row['user']['name'] = $row['contact_name']; } if (isset($row['auth_provider'])) { if ($row['auth_provider'] && $row['auth_provider'] != blogCommentModel::AUTH_GUEST) { $row['user']['photo_url'] = "{$app_static_url}img/{$row['auth_provider']}.png"; foreach ($photo_fields as $field) { $row['user'][$field] =& $row['user']['photo_url']; } } } } unset($row); } }
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; } }
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('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('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'])) { if (($name = waContactNameField::formatName($this->contact)) || $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'])); }
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 getLogs($filters = array(), &$count = null) { $log_model = new waLogModel(); $apps = wa()->getUser()->getApps(); if (!isset($filters['app_id']) || !is_array($filters['app_id'])) { $user_filter = wa()->getUser()->getSettings('webasyst', 'dashboard_activity'); if ($user_filter) { $filters['app_id'] = explode(',', $user_filter); } } if (!$this->getUser()->isAdmin()) { if (!empty($filters['app_id'])) { $filters['app_id'] = array_keys(array_intersect_key(array_flip($filters['app_id']), $apps)); } else { $filters['app_id'] = array_keys($apps); } } $rows = $log_model->getLogs($filters); $count = count($rows); $apps = wa()->getApps(true); $apps_rows = array(); $prev = array(); foreach ($rows as $row_id => &$row) { if ($prev) { $flag = true; foreach (array('app_id', 'action', 'contact_id', 'subject_contact_id', 'params') as $k) { if ($prev[$k] != $row[$k]) { $flag = false; break; } } if ($flag) { unset($rows[$row_id]); continue; } } $contact_name = waContactNameField::formatName($row); if ($contact_name) { $row['contact_name'] = $contact_name; } if ($row['is_user']) { $row['contact_photo_url'] = waContact::getPhotoUrl($row['contact_id'], $row['contact_photo'], 32, 32); } $row['datetime_group'] = $this->getDatetimeGroup($row['datetime']); if (!empty($apps[$row['app_id']])) { $row['app'] = $apps[$row['app_id']]; $logs = wa($row['app_id'])->getConfig()->getLogActions(true); $row['action_name'] = ifset($logs[$row['action']]['name'], $row['action']); if (strpos($row['action'], 'del')) { $row['type'] = 4; } elseif (strpos($row['action'], 'add')) { $row['type'] = 3; } else { $row['type'] = 1; } $apps_rows[$row['app_id']][$row_id] = $row; } else { $row['app'] = array('name' => $row['app_id']); $row['action_name'] = $row['action']; $row['type'] = 1; } $prev = $row; unset($row); } foreach ($apps_rows as $app_id => $app_rows) { $app_rows = wa($app_id)->getConfig()->explainLogs($app_rows); foreach ($app_rows as $row_id => $row) { if ($row) { $rows[$row_id] = $row; } else { unset($rows[$row_id]); } } } return $rows; }
public function execute() { // only allowed to admin if ($this->getRights('backend') <= 1) { throw new waRightsException(_w('Access denied')); } $ids = waRequest::request('ids', array(), 'array_int'); $collection = new contactsCollection('id/' . implode(',', $ids)); $collection->orderBy('~data', 'DESC'); $contacts = $collection->getContacts('*,photo_url_96', 0, 500); foreach ($contacts as &$c) { $c['name'] = waContactNameField::formatName($c); } unset($c); // Field names $fields = array(); // field id => field name foreach (waContactFields::getAll('enabled') as $field_id => $field) { $fields[$field_id] = $field->getName(); // Format data for template if needed foreach ($contacts as &$c) { if (empty($c[$field_id])) { continue; } if (!is_array($c[$field_id]) || $this->is_assoc($c[$field_id])) { $c[$field_id] = $field->format($c[$field_id], 'html'); } else { foreach ($c[$field_id] as &$v) { $v = $field->format($v, 'html'); } unset($v); $c[$field_id] = implode(', ', $c[$field_id]); } } unset($c); } // skip some fields in the list $fields = array_diff_key($fields, array('title' => true, 'name' => true, 'photo' => true, 'firstname' => true, 'middlename' => true, 'lastname' => true, 'locale' => true, 'timezone' => true)); // Initialize 'master_only' key foreach ($contacts as &$c) { $c['master_only'] = ''; } unset($c); // Event to allow other applications to add their data if needed $params = array_keys($contacts); $links = wa()->event('links', $params); $apps = wa()->getApps(); foreach ($links as $app_id => $app_links) { foreach ($app_links as $contact_id => $contact_links) { foreach ($contact_links as $l) { // Show information about links $field_name = $apps[$app_id]['name'] . '/' . $l['role']; $fields[$field_name] = $field_name; $contacts[$contact_id][$field_name] = _w("%d link", "%d links", $l['links_number']); // Show warning if this contact cannot be merged into other contacts. if (!empty($l['forbid_merge_reason'])) { if (!empty($contacts[$contact_id]['master_only'])) { $contacts[$contact_id]['master_only'] .= '<br>'; } else { $contacts[$contact_id]['master_only'] = ''; } $contacts[$contact_id]['master_only'] .= $l['forbid_merge_reason']; } } } } // List of contacts that can be safely merged into other contacts $slave_ids = array(); foreach ($contacts as &$c) { if ($c['is_user'] > 0) { $c['master_only'] = ($c['master_only'] ? $c['master_only'] . '<br>' : '') . _w('Users can not be merged into other contacts.'); } else { if (empty($c['master_only'])) { $slave_ids[] = $c['id']; } } $author = array('name' => ''); if ($c['create_contact_id']) { $author_contact = new waContact($c['create_contact_id']); if ($author_contact->exists()) { $author = $author_contact; } } $c['author'] = $author; } unset($c); $this->view->assign('slave_ids', $slave_ids); $this->view->assign('contacts', $contacts); $this->view->assign('fields', $fields); }
public function execute() { $this->prepare(); if ($query = trim(waRequest::post('query'), '/')) { if (strpos($query, '/') === false) { $h = $hash = 'search/' . $query; } else { $h = $hash = $query; if (substr($hash, 0, 14) == 'import/results') { $h = str_replace('import/results', 'import', $hash); } } } else { $h = $hash = ''; } $h_parts = explode('/', $h, 2); $collection = new contactsCollection($h); $this->response['fields'] = array(); $fields = '*,photo_url_32,photo_url_96'; if ($h_parts[0] === 'users' || $h_parts[0] === 'group') { if (!wa()->getUser()->isAdmin()) { throw new waRightsException(_w('Access denied')); } $fields .= ',_access'; $this->response['fields']['_access'] = array('id' => '_access', 'name' => _w('Access'), 'type' => 'Access', 'vertical' => true); } $collection->orderBy($this->sort, $this->order); $this->response['count'] = $collection->count(); $view = waRequest::post('view'); if ($view == 'list') { // Preload info to cache to avoid excess DB access $cm = new waCountryModel(); $cm->preload(); } $this->response['contacts'] = array_values($collection->getContacts($fields, $this->offset, $this->limit)); $this->workupContacts($this->response['contacts']); $this->response['total_count'] = $collection->count(); foreach ($this->response['contacts'] as $i => &$c) { $c['offset'] = $this->offset + $i; } unset($c); if ($view == 'list') { // Need to format field values correctly for this view. foreach ($this->response['contacts'] as &$cdata) { $c = new waContact($cdata['id']); $c->setCache($cdata); $data = $c->load('list,js') + $cdata; contactsHelper::normalzieContactFieldValues($data, waContactFields::getInfo($c['is_company'] ? 'company' : 'person', true)); if (isset($data['photo'])) { $data['photo'] = $c->getPhoto(); } $c->removeCache(array_keys($cdata)); $cdata = $data; } $this->response['fields'] = array_merge($this->response['fields'], contactsHelper::getFieldsDescription(array('title', 'name', 'photo', 'firstname', 'middlename', 'lastname', 'locale', 'timezone', 'jobtitle', 'company', 'sex', 'company_contact_id'), true)); unset($cdata); } else { foreach ($this->response['contacts'] as &$cdata) { $cdata['name'] = waContactNameField::formatName($cdata); if ($cdata['name'] == $cdata['id']) { $cdata['name'] = false; } } unset($cdata); } // for companies set name to company name // for contacts with empty name, set it to <no name> foreach ($this->response['contacts'] as &$c) { if (isset($c['name']) && trim($c['name'])) { continue; } if (isset($c['company']) && trim($c['company'])) { $c['name'] = $c['company']; unset($c['company']); continue; } $c['name'] = '<' . _w('no name') . '>'; } unset($c); $title = $collection->getTitle(); $hm = new contactsHistoryModel(); if ($hash) { $type = explode('/', $hash); $hash = substr($hash, 0, 1) == '/' ? $hash : '/contacts/' . $hash; $type = $type[0]; // if search query looks like a quick search then remove field name from header if ($type == 'search' && preg_match('~^/contacts/search/(name\\*=[^/]*|email\\*=[^/]*@[^/]*)/?$~i', $hash)) { $title = preg_replace("~^[^=]+=~", '', $title); } // save history if ($type == 'search') { $hm->save($hash, $title, $type, $this->response['count']); $this->logAction('search'); } // Information about system category in categories view if (substr($hash, 0, 19) === '/contacts/category/') { $category_id = (int) substr($hash, 19); $cm = new waContactCategoryModel(); $category = $cm->getById($category_id); if ($category && $category['system_id']) { $this->response['system_category'] = $category['system_id']; } } } // Update history in user's browser $this->response['history'] = $hm->get(); $this->response['title'] = $title; }
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; }
/** * Returns array of orders included in collection. * * @param string $fields List of order properties, comma-separated, to be included in returned array: * '*' — values from shop_order table * '*,params,items,contact' (different combinations are acceptable) — values from tables shop_order, shop_order_items, shop_order_params, wa_contact * @param int $offset Initial position in returned order array, 0 means first order in collection * @param int|bool $limit Maximum order limit. * If a Boolean value is specified, then $escape = $limit and $limit = null * If no value is specified, then $limit = 0. * If no value is specified and $offset is non-zero, then $limit = $offset and $offset = 50 * @param bool $escape Whether order parameters and contact names must be escaped using htmlspecialchars() function, defaults to true * * @return array Array of collection orders' sub-arrays */ public function getOrders($fields = "*", $offset = 0, $limit = null, $escape = true) { if (is_bool($limit)) { $escape = $limit; $limit = null; } if ($limit === null) { if ($offset) { $limit = $offset; $offset = 0; } else { $limit = 50; } } $sql = $this->getSQL(); $sql = "SELECT " . $this->getFields($fields) . " " . $sql; $sql .= " LIMIT " . ($offset ? $offset . ',' : '') . (int) $limit; $data = $this->getModel()->query($sql)->fetchAll('id'); if (!$data) { return array(); } $ids = array_keys($data); // add other fields foreach ($this->other_fields as $field) { switch ($field) { case 'items': case 'params': $rows = $this->getModel($field)->getByField('order_id', $ids, true); foreach ($rows as $row) { if ($field == 'params') { $data[$row['order_id']][$field][$row['name']] = $row['value']; } else { if ($escape) { $row['name'] = htmlspecialchars($row['name']); } $data[$row['order_id']][$field][] = $row; } } break; case 'contact': $contact_ids = array(); foreach ($data as $o) { $contact_ids[] = $o['contact_id']; } $contact_model = new waContactModel(); $contacts = $contact_model->getById(array_unique($contact_ids)); foreach ($data as &$o) { if (isset($contacts[$o['contact_id']])) { $c = $contacts[$o['contact_id']]; $o['contact'] = array('id' => $c['id'], 'name' => waContactNameField::formatName($c), 'photo' => $c['photo']); if ($escape) { $o['contact']['name'] = htmlspecialchars($o['contact']['name']); } } } unset($o); break; } } unset($t); return $data; }