コード例 #1
0
 /** Using $this->id get waContact and save it in $this->contact;
  * Load vars into $this->view specific to waContact. */
 protected function getContactInfo()
 {
     $system = wa();
     if ($this->id == $system->getUser()->getId()) {
         $this->contact = $system->getUser();
         $this->view->assign('own_profile', TRUE);
     } else {
         $this->contact = new waContact($this->id);
     }
     //
     // Load vars into view
     //
     $this->view->assign('contact', $this->contact);
     // who created this contact and when
     $this->view->assign('contact_create_time', waDateTime::format('datetime', $this->contact['create_datetime'], $system->getUser()->getTimezone()));
     if ($this->contact['create_contact_id']) {
         try {
             $author = new waContact($this->contact['create_contact_id']);
             if ($author['name']) {
                 $this->view->assign('author', $author);
             }
         } catch (Exception $e) {
             // Contact not found. Ignore silently.
         }
     }
     // Info above tabs
     $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);
         }
     }
     $this->view->assign('top', $top);
     // Main contact editor data
     $fieldValues = $this->contact->load('js', TRUE);
     $contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', TRUE);
     $this->view->assign('contactFields', $contactFields);
     $this->view->assign('fieldValues', $fieldValues);
     // Contact categories
     $cm = new waContactCategoriesModel();
     $this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id)));
 }
コード例 #2
0
 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));
 }