protected function createUser($id)
 {
     $user = new waUser($id);
     if ($user['is_user']) {
         throw new waException('Already a user.');
     }
     if (waRequest::post('invite')) {
         $user['password'] = uniqid(time(), true);
     } else {
         $login = trim(waRequest::post('login'));
         if (strlen($login) <= 0) {
             $this->errors[] = _w('Login is required.');
         } else {
             if ($u = waUser::getByLogin($login)) {
                 $nameLink = '<a href="' . wa_url() . 'webasyst/contacts/#/contact/' . $u->getId() . '">' . $u->get('name') . '</a>';
                 $this->errors[] = str_replace('%NAME_LINK%', $nameLink, _w('This login is already set for user %NAME_LINK%'));
             }
         }
         $user['login'] = $login;
         if (waRequest::post('password') === waRequest::post('confirm_password')) {
             $user['password'] = waRequest::post('password');
         } else {
             $this->errors[] = _w('Passwords do not match.');
         }
     }
     if (!$this->errors) {
         $user['is_user'] = 1;
         $this->response = $user->save();
         $this->log('create_user_account', 1);
     }
 }
 protected function getParts($data, $format = null)
 {
     $result = array('pic' => '', 'marker' => '', 'parts' => array());
     $countryName = '';
     //        $countryPic = '';
     //        $searchLink = '';
     if (isset($data['data']['country']) && $data['data']['country']) {
         $model = new waCountryModel();
         $countryName = $model->name($data['data']['country']);
         // Do not show pic for unknown country
         if ($countryName) {
             $result['pic'] = '<img src="' . wa_url() . 'wa-content/img/country/' . strtolower($data['data']['country']) . '.gif" class="overhanging" />';
         }
     }
     if (isset($data['data']['street']) || isset($data['data']['city']) || isset($data['data']['region']) || isset($data['data']['country']) || $countryName) {
         $searchURL = '';
         foreach (array('street', 'city', 'region') as $id) {
             if (!isset($data['data'][$id])) {
                 continue;
             }
             $searchURL .= ($searchURL ? ' ' : '') . $data['data'][$id];
         }
         if ($countryName) {
             $searchURL .= ($searchURL ? ' ' : '') . $countryName;
         }
         $searchURL = htmlspecialchars($searchURL);
         $result['marker'] = '<a href="http://mapof.it/' . $searchURL . '" class="small"><i class="icon16 marker"></i><b><i>' . _w('show on map') . '</i></b></a>';
     }
     foreach (waContactFields::get('address')->getFields() as $field) {
         /**
          * @var waContactField $field
          */
         $id = $field->getId();
         if (isset($data['data'][$id]) && trim($data['data'][$id])) {
             if ($id === 'country') {
                 $result['parts'][$id] = $countryName;
             } else {
                 $result['parts'][$id] = $field->format($data['data'][$id], $format, $data['data']);
             }
             $result['parts'][$id] = htmlspecialchars($result['parts'][$id]);
         }
     }
     $result['marker'] = '';
     // marker is disabled, but may be needed in future
     return $result;
 }
 public static function getTop($contact)
 {
     $top = array();
     static $fields = null;
     if ($fields === null) {
         $fields = array(waContactFields::getAll('person', true), waContactFields::getAll('company', true));
     }
     $country_model = new waCountryModel();
     $iso3letters_map = $country_model->select('DISTINCT iso3letter')->fetchAll('iso3letter', true);
     foreach ($fields[intval($contact['is_company'])] as $f) {
         $info = $f->getInfo();
         if ($f->getParameter('top') && ($value = $contact->get($info['id'], 'top,html'))) {
             if ($info['type'] == 'Address') {
                 $data = $contact->get($info['id']);
                 $data_for_map = $contact->get($info['id'], 'forMap');
                 $value = (array) $value;
                 foreach ($value as $k => &$v) {
                     if (isset($data[$k]['data']['country']) && isset($iso3letters_map[$data[$k]['data']['country']])) {
                         $v = '<img src="' . wa_url() . 'wa-content/img/country/' . strtolower($data[$k]['data']['country']) . '.gif" /> ' . $v;
                     }
                     $map_url = '';
                     if (is_string($data_for_map[$k])) {
                         $map_url = $data_for_map[$k];
                     } else {
                         if (!empty($data_for_map[$k]['coords'])) {
                             $map_url = $data_for_map[$k]['coords'];
                         } else {
                             if (!empty($data_for_map[$k]['with_street'])) {
                                 $map_url = $data_for_map[$k]['with_street'];
                             }
                         }
                     }
                     $v .= ' <a target="_blank" href="//maps.google.com/maps?q=' . urlencode($map_url) . '&z=15" class="small underline map-link">' . _w('map') . '</a>';
                     $v = '<div data-subfield-index=' . $k . '>' . $v . '</div>';
                 }
                 unset($v);
             }
             $delimiter = $info['type'] == 'Composite' || $info['type'] == 'Address' ? "<br>" : ", ";
             $top[] = array('id' => $info['id'], 'name' => $f->getName(), 'value' => is_array($value) ? implode($delimiter, $value) : $value, 'icon' => $info['type'] == 'Email' || $info['type'] == 'Phone' ? strtolower($info['type']) : '', 'pic' => '');
         }
     }
     return $top;
 }
Пример #4
0
</h1>
						<p>
						<?php 
if ($app) {
    ?>
							<?php 
    if ($env == 'backend') {
        ?>
<a href="<?php 
        echo $backend_url . $app['id'] . "/";
        ?>
"><?php 
    }
    ?>
							<img src="<?php 
    echo wa_url() . $app['img'];
    ?>
" /><br />
							<span class="small"><?php 
    echo $app['name'];
    ?>
</span>
							<?php 
    if ($env == 'backend') {
        ?>
</a><?php 
    }
    ?>
						<?php 
}
?>
 /**
  * Check field value to be unique, if field is set up as unique.
  *
  * @param $data
  * @param int $contactId
  * @return array|string|null Validation errors (array for multi fields, string for simple fields) or null if everything is ok.
  */
 public function validateUnique($data, $contactId = null)
 {
     if (!$this->getParameter('unique')) {
         return null;
     }
     if (!$this->isMulti()) {
         $data = array($data);
     }
     // array of plain string values
     $values = array();
     if (is_array($data)) {
         foreach ($data as $sort => $value) {
             $value = $this->format($value, 'value');
             if ($value || $value === 0) {
                 // do not check empty values to be unique
                 $values[$sort] = $value;
             }
         }
     } else {
         if ($data !== null) {
             return array(_ws('Data must be an array.'));
         }
     }
     // array of duplicates $sort => contact_id
     $dupl = array();
     // Check if there are duplicates among $values
     $flipped = array_flip($values);
     if (count($values) != count($flipped)) {
         // keys that disappeared after array_flip are duplicates, find them
         foreach (array_diff(array_keys($values), array_values($flipped)) as $key) {
             $dupl[$key] = $contactId;
             // there's another key that is not missing, but still is a duplicate since it's a copy of a missing key
             $dupl[$flipped[$values[$key]]] = $contactId;
         }
     }
     // Check if there are duplicates in database
     $rows = $this->getStorage()->findDuplicatesFor($this, array_keys($flipped), $contactId ? array($contactId) : array());
     foreach ($rows as $value => $cid) {
         if (isset($flipped[$value])) {
             $dupl[$flipped[$value]] = $cid;
         } else {
             // Must be a duplicate in case-insensitive search
             foreach ($flipped as $v => $i) {
                 if (mb_strtolower($v) == mb_strtolower($value)) {
                     $dupl[$i] = $cid;
                     break;
                 }
             }
             if (!$dupl) {
                 // Sanity check for debugging purposes
                 throw new waException("Unable to find duplicate value {$value} among flipped: " . print_r($flipped, true));
             }
         }
     }
     if (!$dupl) {
         return null;
     }
     // Create array of errors
     $errors = array();
     $errStrSelf = _ws('Duplicates are not allowed for this field.');
     $errStr = _ws('This field must be unique. The value entered is already set for %NAME_LINK%.');
     $errStrNoRights = _ws('This field must be unique. The value entered is already set for another contact.');
     $rights_model = null;
     $userId = null;
     foreach ($dupl as $sort => $cid) {
         if ($cid === $contactId) {
             $errors[$sort] = $errStrSelf;
             continue;
         }
         // Check if current user can view $cid profile.
         if (!$rights_model && class_exists('ContactsRightsModel')) {
             $rights_model = new ContactsRightsModel();
             $userId = waSystem::getInstance()->getUser()->getId();
         }
         if ($rights_model && $rights_model->getRight($userId, $cid)) {
             // at least read access
             $contact = new waContact($cid);
             $nameLink = '<a href="' . wa_url() . 'webasyst/contacts/#/contact/' . $cid . '">' . $contact->get('name') . '</a>';
             $errors[$sort] = str_replace('%NAME_LINK%', $nameLink, $errStr);
         } else {
             // no access
             $errors[$sort] = $errStrNoRights;
         }
     }
     return $errors;
 }
 protected function createLogin($id, $just_check = false)
 {
     $user = new waUser($id);
     $login = trim(waRequest::post('login'));
     if (strlen($login) <= 0) {
         $this->errors[] = _w('Login is required.');
     } else {
         if ($u = $this->loginExists($login, $id)) {
             $nameLink = '<a href="' . wa_url() . 'webasyst/contacts/#/contact/' . $u['id'] . '">' . $u['name'] . '</a>';
             $this->errors[] = str_replace('%NAME_LINK%', $nameLink, _w('This login is already set for user %NAME_LINK%'));
         }
     }
     if (!$this->errors) {
         if ($just_check) {
             return true;
         }
         $user['login'] = $login;
         $r = $user->save();
         if ($r === 0) {
             return array('login' => $login);
         } else {
             $this->errors = $r;
             return false;
         }
     } else {
         return false;
     }
 }