public function execute() { // Layout caching is forbidden header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: " . date("r")); $this->executeAction('sidebar', new contactsBackendSidebarAction()); $fields = array(); // normally this is done with waContactFields::getInfo() but we don't need most of the info // so we loop through fields manually. foreach (waContactFields::getAll('enabled') as $field_id => $f) { /** * @var $f waContactField */ $fields[$field_id] = array(); $fields[$field_id]['id'] = $field_id; $fields[$field_id]['name'] = $f->getName(); $fields[$field_id]['fields'] = $f instanceof waContactCompositeField; if ($ext = $f->getParameter('ext')) { $fields[$field_id]['ext'] = $ext; foreach ($fields[$field_id]['ext'] as &$v) { $v = _ws($v); } } } // Plugin assets if ($this->getConfig()->getInfo('edition') === 'full') { wa()->event('assets'); } $this->view->assign('admin', wa()->getUser()->getRights('contacts', 'backend') > 1); $this->view->assign('global_admin', wa()->getUser()->getRights('webasyst', 'backend') > 0); $this->view->assign('fields', $fields); $this->view->assign('versionFull', $this->getConfig()->getInfo('edition') === 'full'); }
public function format($data) { if (is_array($data)) { $data['data'] = $data['value']; $data['value'] = htmlspecialchars($data['value']); } else { $data = array('data' => $data, 'value' => htmlspecialchars($data)); } if (!$data['data']) { $data['value'] = ''; return $data; } $icon = ''; if (isset($data['ext']) && $data['ext'] && ($f = waContactFields::get('im'))) { $exts = $f->getParameter('ext'); if (isset($exts[$data['ext']])) { $icon = '<i class="icon16 ' . $data['ext'] . '"></i>'; } } if (!$icon) { $icon = '<i class="icon16 im"></i>'; } $data['value'] = $icon . $data['value']; return $data; }
public function format($data) { $value = htmlspecialchars(trim($data['value'])); if (!preg_match("/^(http|https):/", $value)) { $f = waContactFields::get('socialnetwork'); if ($f) { $domain = $f->getParameter('domain'); if (!empty($domain[$data['ext']])) { $d = $domain[$data['ext']]; if (strpos($value, $d) === false) { $value = '<a href="' . 'http://' . $d . '/' . ltrim($value, "/ ") . '" target="_blank">' . $value . '</a>'; } } } } else { $value = "<a href='{$value}' target='_blank'>{$value}</a>"; } $icon = ''; $ext = ''; if (isset($data['ext']) && $data['ext'] && ($f = waContactFields::get('socialnetwork'))) { $exts = $f->getParameter('ext'); if (isset($exts[$data['ext']])) { $ext = ' <em class="hint">' . $exts[$data['ext']] . '</em>'; $icon = '<i class="icon16 ' . $data['ext'] . '"></i>'; } else { $ext = ' <em class="hint">' . htmlspecialchars($data['ext']) . '</em>'; } } return $icon . $value . $ext; }
public function execute() { $field = waRequest::get('field', null, waRequest::TYPE_STRING_TRIM); if (!$field) { throw new waException(_w("Unknown field")); } // List of field values $cfvm = new waContactFieldValuesModel(); $fields = $cfvm->getInfo($field); // Possible parent fields this conditional field may depend on $parent_fields = array(); foreach (waContactFields::getAll('person') as $f) { /** @var waContactField $f */ if (!$f instanceof waContactCompositeField && !$f->isMulti()) { $parent_fields[$f->getId()] = $f->getName(); } } $field_ids = explode(':', $field); $f = waContactFields::get($field_ids[0]); if (!empty($field_ids[1]) && $f && $f instanceof waContactCompositeField) { $subfields = $f->getFields(); foreach ($subfields as $sfid => $sf) { $pid = $f->getId() . ':' . $sfid; if ($pid !== $field) { $parent_fields[$pid] = $f->getName() . ' — ' . $sf->getName(); } } } // Selected parent field $parent_selected = null; if ($fields) { $parent_selected = reset($fields); $parent_selected = $parent_selected['field']; } // Human readable name of current field if (!empty($field_ids[1]) && !empty($subfields[$field_ids[1]])) { $title = $subfields[$field_ids[1]]->getName(); } else { if ($f) { $title = $f->getName(); } else { // Loose guess on whether this field has just been created $new_field = false; if (substr($field, 0, 2) == '__') { $new_field = true; } else { if (!empty($field_ids[1]) && substr($field_ids[1], 0, 2) == '__') { $new_field = true; } } if ($new_field) { $title = _w('Conditional field'); } else { $title = _w(ucfirst($field)); } } } $this->view->assign(array('field' => $field, 'title' => $title, 'fields' => $fields, 'parent_fields' => $parent_fields, 'parent_selected' => $parent_selected)); }
public function execute() { $domain = siteHelper::getDomain(); $config = wa()->getConfig()->getAuth(); if (!isset($config[$domain])) { $config[$domain] = array(); } if (waRequest::post('auth_captcha') !== null) { if (waRequest::post('auth_captcha')) { $config[$domain]['signup_captcha'] = true; } elseif (isset($config[$domain]['signup_captcha'])) { unset($config[$domain]['signup_captcha']); } } if (waRequest::post('auth_rememberme')) { $config[$domain]['rememberme'] = true; } elseif (isset($config[$domain]['rememberme'])) { unset($config[$domain]['rememberme']); } // save auth adapters if (waRequest::post('auth_adapters') && waRequest::post('adapter_ids')) { $config[$domain]['adapters'] = array(); $adapters = waRequest::post('adapters', array()); foreach (waRequest::post('adapter_ids') as $adapter_id) { $config[$domain]['adapters'][$adapter_id] = $adapters[$adapter_id]; } } else { if (isset($config[$domain]['adapters'])) { unset($config[$domain]['adapters']); } } // signup $fields = waRequest::post('fields'); $params = waRequest::post('params'); $must_have_fields = array('email', 'password'); $default_fields = array_merge(array('firstname', 'lastname', ''), $must_have_fields); $config[$domain]['params'] = $params; if (!$config[$domain]) { $config[$domain]['fields'] = $default_fields; } else { $config[$domain]['fields'] = array(); } foreach ($fields as $field_id => $field) { $config[$domain]['fields'][$field_id] = $field; } foreach ($must_have_fields as $field) { if (!in_array($field, array_keys($fields))) { $tmp = waContactFields::get($field); $config[$domain]['fields'][$field] = array('required' => true, 'caption' => $tmp->getName()); } else { $config[$domain]['fields'][$field]['required'] = true; } } // save to file if (!$this->getConfig()->setAuth($config)) { $this->errors = sprintf(_w('File could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-config/'); } }
public function execute() { if (!$this->getRights('create')) { throw new waRightsException('Access denied.'); } $type = waRequest::get('company') ? 'company' : 'person'; $fields = waContactFields::getInfo($type, TRUE); $this->view->assign('contactFields', $fields); $this->view->assign('contactType', $type); $this->view->assign('header', _w('New ' . ($this->getConfig()->getInfo('edition') === 'full' ? $type : 'contact'))); $this->view->assign('limitedCategories', $this->getRights('category.all') ? 0 : 1); }
public function execute() { if (!$this->getRights('create')) { throw new waRightsException('Access denied.'); } $type = waRequest::get('company') ? 'company' : 'person'; $fields = array(); foreach (waContactFields::getAll($type, true) as $field_id => $field) { $fields[$field_id] = $field->getInfo(); $fields[$field_id]['top'] = $field->getParameter('top'); } $this->view->assign('contactFields', $fields); $this->view->assign('contactType', $type); }
public function format($data) { $data['value'] = htmlspecialchars(trim($data['value'])); $value = self::formatLink($data); $icon = ''; $ext = ''; if (isset($data['ext']) && $data['ext'] && ($f = waContactFields::get('socialnetwork'))) { $exts = $f->getParameter('ext'); if (isset($exts[$data['ext']])) { $ext = ' <em class="hint">' . $exts[$data['ext']] . '</em>'; $icon = '<i class="icon16 ' . $data['ext'] . '"></i>'; } else { $ext = ' <em class="hint">' . htmlspecialchars($data['ext']) . '</em>'; } } return $icon . $value . $ext; }
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 function format($data) { if (is_array($data)) { $result = htmlspecialchars($data['value']); $result = '<a class="inline" href="mailto:' . $result . '">' . $result . '</a>'; if (isset($data['ext']) && $data['ext']) { $ext = $data['ext']; $f = waContactFields::get('email'); $exts = $f->getParameter('ext'); if (isset($exts[$ext])) { $ext = _ws($exts[$ext]); } $result .= ' <em class="hint">' . htmlspecialchars($ext) . '</em>'; } return $result; } return htmlspecialchars($data); }
public function execute() { $this->contact = wa()->getUser(); $data = json_decode(waRequest::post('data'), true); if (!$data || !is_array($data)) { $this->response = array('errors' => array(), 'data' => array()); return; } // Make sure only allowed fields are saved $allowed = array(); foreach (waContactFields::getAll('person') as $f) { if ($f->getParameter('allow_self_edit')) { $allowed[$f->getId()] = true; } } $data = array_intersect_key($data, $allowed); $oldLocale = $this->getUser()->getLocale(); // Validate and save contact if no errors found $errors = $this->contact->save($data, true); if ($errors) { $response = array(); } else { // New data formatted for JS $response['name'] = $this->contact->get('name', 'js'); foreach ($data as $field_id => $field_value) { if (!isset($errors[$field_id])) { $response[$field_id] = $this->contact->get($field_id, 'js'); } } // Top fields $response['top'] = array(); foreach (array('email', 'phone', 'im') as $f) { if ($v = $this->contact->get($f, 'top,html')) { $response['top'][] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v); } } } // Reload page with new language if user just changed it in own profile if ($oldLocale != $this->contact->getLocale()) { $response['reload'] = TRUE; } $this->response = array('errors' => $errors, 'data' => $response); }
public function format($data) { $value = htmlspecialchars($data['value']); $icon = ''; $ext = ''; if (isset($data['ext']) && $data['ext'] && ($f = waContactFields::get('im'))) { $exts = $f->getParameter('ext'); if (isset($exts[$data['ext']])) { $ext = ' <em class="hint">' . $exts[$data['ext']] . '</em>'; $icon = '<i class="icon16 ' . $data['ext'] . '"></i>'; } else { $ext = ' <em class="hint">' . htmlspecialchars($data['ext']) . '</em>'; } } if (!$icon) { $icon = '<i class="icon16 im"></i>'; } return $icon . $value . $ext; }
public function execute() { $domain = siteHelper::getDomain(); $fields = array(); $default_fields = array('firstname' => true, 'lastname' => true, 'middlename' => true, 'email' => true, 'phone' => true, 'password' => true); $auth_config = wa()->getAuthConfig($domain); if (!empty($auth_config['app']) && $auth_config['app'] == 'shop') { $settings = wa('shop')->getConfig()->getCheckoutSettings(); if (!isset($settings['contactinfo'])) { $settings = wa('shop')->getConfig()->getCheckoutSettings(true); } if (!empty($settings['contactinfo']['fields'])) { $default_fields = array(); foreach ($settings['contactinfo']['fields'] as $field_id => $f) { $default_fields[$field_id] = true; } } } $domain_config_path = wa('site')->getConfig()->getConfigPath('domains/' . $domain . '.php'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } if (!isset($domain_config['personal_fields'])) { $domain_config['personal_fields'] = $default_fields; } if (!empty($auth_config['app']) && isset($domain_config['personal'][$auth_config['app']]) && !$domain_config['personal'][$auth_config['app']]) { $this->view->assign('profile_disabled', true); $this->view->assign('auth_app', wa()->getAppInfo($auth_config['app'])); } $contacts_fields = array('photo' => new waContactHiddenField('photo', _ws('Photo'))) + waContactFields::getAll('person', true) + array('password' => new waContactPasswordField('password', _ws('Password'))); foreach ($contacts_fields as $fiels_name => $field) { $name = $field->getName(); if ($name && $fiels_name !== 'name') { $fields[] = array('id' => $fiels_name, 'name' => $name, 'checked' => isset($domain_config['personal_fields'][$fiels_name]) && $domain_config['personal_fields'][$fiels_name] === true ? true : false); } } $this->view->assign('domain', $domain); $this->view->assign('fields', $fields); }
public function execute() { if (!$this->getRequest()->request('json', 0)) { $action = new contactsContactsInfoAction(); echo $action->display(); return; } $m = new waContactModel(); $contact_id = $this->getRequest()->request('id', 0, 'int'); $contact = new waContact($contact_id); $values = $contact->load('js', true); if (isset($values['company_contact_id'])) { if (!$m->getById($values['company_contact_id'])) { $values['company_contact_id'] = 0; $contact->save(array('company_contact_id' => 0)); } } $values['photo_url_96'] = $contact->getPhoto(96); $values['photo_url_20'] = $contact->getPhoto(20); $fields = waContactFields::getInfo($contact['is_company'] ? 'company' : 'person', true); echo json_encode(array('fields' => $fields, 'values' => $values, 'top' => $contact->getTopFields())); }
public function execute() { // Layout caching is forbidden header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: " . date("r")); $this->executeAction('sidebar', new contactsBackendSidebarAction()); $fields = array(); // normally this is done with waContactFields::getInfo() but we don't need most of the info // so we loop through fields manually. foreach (waContactFields::getAll('enabled') as $field_id => $f) { /** * @var $f waContactField */ $fields[$field_id] = array(); $fields[$field_id]['id'] = $field_id; $fields[$field_id]['name'] = $f->getName(); $fields[$field_id]['fields'] = $f instanceof waContactCompositeField; if ($ext = $f->getParameter('ext')) { $fields[$field_id]['ext'] = $ext; foreach ($fields[$field_id]['ext'] as &$v) { $v = _ws($v); } } } /** * Include plugins js and css * @event backend_assets * @return array[string]string $return[%plugin_id%] */ $this->view->assign('backend_assets', wa()->event('backend_assets')); /** * Include plugins js templates * @event backend_tempaltes * @return array[string]string $return[%plugin_id%] */ $this->view->assign('backend_templates', wa()->event('backend_templates')); $this->view->assign(array('admin' => wa()->getUser()->getRights('contacts', 'backend') > 1, 'global_admin' => wa()->getUser()->getRights('webasyst', 'backend') > 0, 'fields' => $fields, 'groups' => $this->getGroups(), 'paginator_type' => wa('contacts')->getConfig('contacts')->getOption('paginator_type'), 'lang' => substr(wa()->getLocale(), 0, 2))); }
public static function getFieldsDescription($field_ids, $skip = false) { $fields = array(); $all_fields = waContactFields::getAll('enabled'); if ($skip) { foreach ($field_ids as $field_id) { if (isset($all_fields[$field_id])) { unset($all_fields[$field_id]); } } $field_ids = array_keys($all_fields); } foreach ($field_ids as $field_id) { $f = $all_fields[$field_id]; if (!$f) { continue; } /** * @var $f waContactField */ $fields[$field_id] = array(); $fields[$field_id]['id'] = $field_id; $fields[$field_id]['name'] = $f->getName(); $fields[$field_id]['type'] = $f->getType(); if ($fields[$field_id]['type'] === 'Select') { $fields[$field_id]['options'] = $f->getOptions(); } $fields[$field_id]['fields'] = $f instanceof waContactCompositeField; if ($ext = $f->getParameter('ext')) { $fields[$field_id]['ext'] = $ext; foreach ($fields[$field_id]['ext'] as &$v) { $v = _ws($v); } } $fields[$field_id]['icon'] = $fields[$field_id]['type'] == 'Email' || $fields[$field_id]['type'] == 'Phone' ? strtolower($fields[$field_id]['type']) : ''; } return $fields; }
protected function searchPrepare($query, $auto_title = true) { if ($auto_title || !isset($this->alias_index['data'])) { $this->alias_index['data'] = 0; } //$query = urldecode($query); // sometime this urldecode broke query, better make urldecode (if needed) outside the searchPrepare // `&` can be escaped in search request. Need to split by not escaped ones only. $escapedBS = 'ESCAPED_BACKSLASH'; while (FALSE !== strpos($query, $escapedBS)) { $escapedBS .= rand(0, 9); } $escapedAmp = 'ESCAPED_AMPERSAND'; while (FALSE !== strpos($query, $escapedAmp)) { $escapedAmp .= rand(0, 9); } $query = str_replace('\\&', $escapedAmp, str_replace('\\\\', $escapedBS, $query)); $query = explode('&', $query); $model = $this->getModel(); $title = array(); foreach ($query as $part) { if (!($part = trim($part))) { continue; } $part = str_replace(array($escapedBS, $escapedAmp), array('\\', '&'), $part); $parts = preg_split("/(\\\$=|\\^=|\\*=|==|!=|>=|<=|=|>|<|@=)/uis", $part, 2, PREG_SPLIT_DELIM_CAPTURE); if ($parts) { if ($parts[0] === 'name' && $parts[1] === '*=') { $t_a = preg_split("/\\s+/", $parts[2]); $cond = array(); foreach ($t_a as $t) { $t = trim($t); if ($t) { $t = $model->escape($t, 'like'); $cond[] = "c.name LIKE '%{$t}%'"; } } $this->addWhere(implode(" AND ", $cond)); $title[] = _ws('Name') . $parts[1] . $parts[2]; } else { if ($parts[0] == 'email') { if (!isset($this->joins['email'])) { $this->joins['email'] = array('table' => 'wa_contact_emails', 'alias' => 'e'); } $title[] = waContactFields::get($parts[0])->getName() . $parts[1] . $parts[2]; $this->where[] = 'e.email' . $this->getExpression($parts[1], $parts[2]); } else { if ($model->fieldExists($parts[0])) { if ($f = waContactFields::get($parts[0])) { $title[] = $f->getName() . $parts[1] . $parts[2]; } else { $title[] = $parts[0] . $parts[1] . $parts[2]; } $this->where[] = 'c.' . $parts[0] . $this->getExpression($parts[1], $parts[2]); } else { if ($parts[0] == 'category') { if (!isset($this->joins['categories'])) { $this->joins['categories'] = array('table' => 'wa_contact_categories', 'alias' => 'cc'); } $title[] = _ws('Category') . $parts[1] . $parts[2]; $this->where[] = 'cc.category_id' . $this->getExpression($parts[1], $parts[2]); } else { $field_parts = explode('.', $parts[0]); $f = $field_parts[0]; if ($fo = waContactFields::get($f)) { $title[] = $fo->getName() . $parts[1] . $parts[2]; } $ext = isset($field_parts[1]) ? $field_parts[1] : null; $on = ":table.contact_id = c.id AND :table.field = '" . $model->escape($f) . "'"; $this->where_fields[] = $f; $op = $parts[1]; $term = $parts[2]; if ($f === 'address:country') { $al1 = $this->addJoin('wa_contact_data', $on); $whr = "{$al1}.value " . $this->getExpression($op, $term); if ($ext !== null) { $whr .= " AND {$al1}.ext = '" . $model->escape($ext) . "'"; $whr = "({$whr})"; } // search by l18n name of countries if ($op === '*=') { if (wa()->getLocale() === 'en_US') { $al2 = $this->addLeftJoin('wa_country', ":table.iso3letter = {$al1}.value"); $whr .= " OR {$al2}.name " . $this->getExpression($parts[1], $parts[2]); } else { if (wa()->getLocale() !== 'en_US') { $iso3letters = array(); $country_model = new waCountryModel(); $countries = $country_model->all(); $term = mb_strtolower($term); foreach ($countries as &$cntr) { if (mb_strpos(mb_strtolower($cntr['name']), $term) === 0) { $iso3letters[] = $cntr['iso3letter']; } } unset($cntr); if ($iso3letters) { $al2 = $this->addLeftJoin('wa_country', ":table.iso3letter = {$al1}.value"); $whr .= " OR {$al2}.iso3letter IN ('" . implode("','", $iso3letters) . "')"; } } } } $this->addWhere($whr); } else { if ($f === 'address:region') { if (strpos($term, ":") !== false) { // country_code : region_code - search by country code AND region code AND only in wa_region $term = explode(":", $term); $country_iso3 = $model->escape($term[0]); $code = $model->escape($term[1]); $al1 = $this->addJoin('wa_contact_data', $on); $whr = array(); if ($ext !== null) { $whr[] = "{$al1}.ext = '" . $model->escape($ext) . "'"; } $al2 = $this->addJoin('wa_contact_data', ":table.contact_id = c.id AND :table.field = 'address:country'"); $al3 = $this->addJoin('wa_region', ":table.code = {$al1}.value AND :table.country_iso3 = {$al2}.value"); $whr[] = "{$al3}.country_iso3 = '{$country_iso3}'"; $whr[] = "{$al3}.code = '{$code}'"; $whr = implode(" AND ", $whr); } else { $al1 = $this->addJoin('wa_contact_data', $on); $whr = "{$al1}.value" . $this->getExpression($op, $term); if ($ext !== null) { $whr .= " AND {$al1}.ext = '" . $model->escape($ext) . "'"; $whr = "({$whr})"; } if ($op === "*=") { // if search by like, search by wa_region.name but taking into account country $al2 = $this->addJoin('wa_contact_data', ":table.contact_id = c.id AND :table.field = 'address:country'"); $al3 = $this->addLeftJoin('wa_region', ":table.code = {$al1}.value AND :table.country_iso3 = {$al2}.value"); $whr .= " OR {$al3}.name " . $this->getExpression($op, $term); } } $this->addWhere($whr); } else { $on .= ' AND :table.value ' . $this->getExpression($op, $term); if ($ext !== null) { $on .= " AND :table.ext = '" . $model->escape($ext) . "'"; } $this->addJoin('wa_contact_data', $on); } } } } } } } } if ($title) { $title = implode(', ', $title); // Strip slashes from search title. $bs = '\\\\'; $title = preg_replace("~{$bs}(_|%|&|{$bs})~", '\\1', $title); } if ($auto_title && $title) { $this->addTitle($title, ' '); } }
private function getContactfieldControl($name, $params = array()) { $params['options'] = array(); $params['options'][] = array('title' => '—', 'value' => ''); $fields = waContactFields::getAll(); foreach ($fields as $field) { if ($field instanceof waContactCompositeField) { $subfields = $field->getFields(); foreach ($subfields as $subfield) { $params['options'][] = array('group' => $field->getName(), 'title' => $subfield->getName(), 'value' => $field->getId() . '.' . $subfield->getId()); } } else { $params['options'][] = array('title' => $field->getName(), 'value' => $field->getId()); } } return $this->getSelectControl($name, $params); }
/** * @param bool $name * @return waContactStorage|string */ public function getStorage($name = null) { if ($name) { return $this->options['storage']; } if (!$this->options['storage']) { return null; } return waContactFields::getStorage($this->options['storage']); }
public function getHtmlOne($params = array(), $attrs = '') { // // HTML: list of radio buttons // $value = isset($params['value']) ? $params['value'] : ''; $html = ''; $radios_name = $this->getHTMLName($params); foreach ($this->getOptions() as $k => $v) { $html .= '<label><input type="radio"' . ($k == $value ? ' checked="checked"' : '') . ' name="' . $radios_name . '" value="' . htmlspecialchars($k) . '"> ' . htmlspecialchars($v) . '</label>'; } // // JS: hide form fields depending on radio selection // $hide_data = array(); $hide_by_default = array(); $field_names = array(); $p = $params; $all_fields = waContactFields::getAll('enabled'); foreach (ifempty($this->options['hide'], array()) as $option_id => $field_ids) { $hide_data[$option_id] = array_fill_keys($field_ids, 1); $hide_by_default += $hide_data[$option_id]; foreach ($field_ids as $fid) { if (empty($all_fields[$fid]) || $all_fields[$fid]->isRequired()) { // Never hide required fields unset($hide_by_default[$fid], $hide_data[$option_id][$fid]); continue; } if (empty($field_names[$fid])) { $p['id'] = $fid; $field_names[$fid] = $this->getHTMLName($p); } } } $uniqid = uniqid('s'); $hide_data['hide_by_default'] = $hide_by_default; $field_names = json_encode($field_names); $hide_data = json_encode($hide_data); $js = <<<EOF <span id="{$uniqid}"></span> <script>if (\$) { \$(function() { "use strict"; var hide_data = {$hide_data}; var radios_parent = \$('#{$uniqid}').parent(); var field_names = {$field_names}; if (!radios_parent || !radios_parent.length) { return; } var initially_selected = radios_parent.find(':radio[name="{$radios_name}"]:checked'); var previous_selection = 'hide_by_default'; radios_parent.on('change', ':radio[name="{$radios_name}"]', function() { var option_id = \$(this).val(); // Show previously hidden if (hide_data[previous_selection]) { for (var field_id in hide_data[previous_selection]) { if (!hide_data[previous_selection].hasOwnProperty(field_id)) { continue; } if (hide_data[option_id] && hide_data[option_id][field_id]) { continue; } if (!field_names[field_id]) { continue; } \$('[name^="'+field_names[field_id]+'"]:first').closest('.wa-field,.field').show(); } } // Hide using new selection if (hide_data[option_id]) { for (var field_id in hide_data[option_id]) { if (!hide_data[option_id].hasOwnProperty(field_id)) { continue; } if (hide_data[previous_selection] && hide_data[previous_selection][field_id]) { continue; } if (!field_names[field_id]) { continue; } var field_to_hide = \$('[name^="'+field_names[field_id]+'"]:first').closest('.wa-field,.field'); if (!field_to_hide.is('.required,.wa-required')) { field_to_hide.hide(); } } } previous_selection = option_id; }); if (initially_selected && initially_selected.length) { initially_selected.change(); } else { var hide_by_default = hide_data.hide_by_default; for (var field_id in hide_by_default) { if (!hide_by_default.hasOwnProperty(field_id)) { continue; } if (!field_names[field_id]) { continue; } var field_to_hide = \$('[name^="'+field_names[field_id]+'"]:first').closest('.wa-field,.field'); if (!field_to_hide.is('.required,.wa-required')) { field_to_hide.hide(); } } } }); };</script> EOF; return $html . $js; }
/** 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); $this->view->assign('own_profile', false); } $exists = $this->contact->exists(); if ($exists) { $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. } } $this->view->assign('top', $this->contact->getTopFields()); // Main contact editor data $fieldValues = $this->contact->load('js', true); $m = new waContactModel(); if (isset($fieldValues['company_contact_id'])) { if (!$m->getById($fieldValues['company_contact_id'])) { $fieldValues['company_contact_id'] = 0; $this->contact->save(array('company_contact_id' => 0)); } } $contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', true); // Only show fields that are allowed in own profile if (!empty($this->params['limited_own_profile'])) { $allowed = array(); foreach (waContactFields::getAll('person') as $f) { if ($f->getParameter('allow_self_edit')) { $allowed[$f->getId()] = true; } } $fieldValues = array_intersect_key($fieldValues, $allowed); $contactFields = array_intersect_key($contactFields, $allowed); } contactsHelper::normalzieContactFieldValues($fieldValues, $contactFields); $this->view->assign('contactFields', $contactFields); $this->view->assign('contactFieldsOrder', array_keys($contactFields)); $this->view->assign('fieldValues', $fieldValues); // Contact categories $cm = new waContactCategoriesModel(); $this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id))); } else { $this->view->assign('contact', array('id' => $this->id)); } return $exists; }
<?php // // When this installation has a custom person_fields_order config, // make sure default set of fields is allowed in personal profile to edit. // if (!file_exists($this->getConfigPath('person_fields_order.php', true, 'contacts'))) { return; } $person_fields_default_file = $this->getRootPath() . '/wa-system/contact/data/person_fields_default.php'; if (!is_readable($person_fields_default_file)) { return; } $person_fields_default = (include $person_fields_default_file); if (!$person_fields_default || !is_array($person_fields_default)) { return; } foreach ($person_fields_default as $f_id => $opts) { if (!empty($opts['allow_self_edit'])) { $f = waContactFields::get($f_id, 'person'); if ($f) { $f->setParameter('allow_self_edit', true); waContactFields::enableField($f, 'person'); } } }
/** * Load self::$personFields, self::$companyFields, self::$fieldStatus if not loaded yet * @throws waException * @return */ protected static function ensureStaticVars() { if (self::$personFields !== null) { return; } // Temporary storage for field objects; id => waContactField $fields = array(); // Load system fields self::$fieldStatus = array(); foreach (include wa()->getConfig()->getPath('system', 'contact/data/fields') as $f) { /** * @var waContactField $f */ if (!$f instanceof waContactField) { throw new waException("Invalid contact field " . print_r($f, TRUE)); } $id = $f->getId(); self::$fieldStatus[$id] = true; $fields[$id] = $f; } // Load custom fields $file = wa()->getConfig()->getConfigPath('custom_fields.php', true, 'contacts'); if (is_readable($file)) { $cfg = (include $file); if (empty($cfg) || !is_array($cfg)) { $cfg = array(); } foreach ($cfg as $f) { /** * @var waContactField $f */ if (!$f instanceof waContactField) { throw new waException("Invalid contact field " . print_r($f, TRUE)); } $id = $f->getId(); self::$fieldStatus[$id] = false; $fields[$id] = $f; } } // Person field order $file = wa()->getConfig()->getConfigPath('person_fields_order.php', true, 'contacts'); if (!is_readable($file)) { $file = wa()->getConfig()->getPath('system', 'contact/data/person_fields_default'); } $contactOrder = (include $file); // Company field order $file = wa()->getConfig()->getConfigPath('company_fields_order.php', true, 'contacts'); if (!is_readable($file)) { $file = wa()->getConfig()->getPath('system', 'contact/data/company_fields_default'); } $companyOrder = (include $file); // Load fields into self::$companyFields in correct order, and the rest into self::$companyDisabled self::$companyFields = array(); foreach ($companyOrder as $id => $param) { if (!isset($fields[$id])) { throw new waException('Unknown field ' . $id . ' in company field order.'); } self::$companyFields[$id] = clone $fields[$id]; self::$companyFields[$id]->setParameters($param); } self::$companyDisabled = array_diff_key($fields, self::$companyFields); // same for self::$personFields and self::$personDisabled self::$personFields = array(); foreach ($contactOrder as $id => $param) { if (!isset($fields[$id])) { throw new waException('Unknown field ' . $id . ' in person field order.'); } if (isset(self::$companyDisabled[$id])) { self::$personFields[$id] = clone $fields[$id]; } else { // don't have to clone since this object is used nowhere else self::$personFields[$id] = $fields[$id]; unset($fields[$id]); // being paranoid } self::$personFields[$id]->setParameters($param); } self::$personDisabled = array_diff_key($fields, self::$personFields); }
/** * Merge given contacts into master contact, save, send merge event, then delete slaves. * * !!! Probably should move it into something like contactsHelper * * @param array $merge_ids list of contact ids * @param int $master_id contact id to merge others into * @return array */ public static function merge($merge_ids, $master_id) { $merge_ids[] = $master_id; // List of contacts to merge $collection = new contactsCollection('id/' . implode(',', $merge_ids)); $contacts_data = $collection->getContacts('*'); // Master contact data if (!$master_id || !isset($contacts_data[$master_id])) { throw new waException('No contact to merge into.'); } $master_data = $contacts_data[$master_id]; unset($contacts_data[$master_id]); $master = new waContact($master_id); $result = array('total_requested' => count($contacts_data) + 1, 'total_merged' => 0, 'error' => '', 'users' => 0); if ($master_data['photo']) { $filename = wa()->getDataPath(waContact::getPhotoDir($master_data['id']) . "{$master_data['photo']}.original.jpg", true, 'contacts'); if (!file_exists($filename)) { $master_data['photo'] = null; } } $data_fields = waContactFields::getAll('enabled'); $check_duplicates = array(); // field_id => true $update_photo = null; // if need to update photo here it is file paths // merge loop foreach ($contacts_data as $id => $info) { if ($info['is_user'] > 0) { $result['users']++; unset($contacts_data[$id]); continue; } foreach ($data_fields as $f => $field) { if (!empty($info[$f])) { if ($field->isMulti()) { $master->add($f, $info[$f]); $check_duplicates[$f] = true; } else { // Field does not allow multiple values. // Set value if no value yet. if (empty($master_data[$f])) { $master[$f] = $master_data[$f] = $info[$f]; } } } } // photo if (!$master_data['photo'] && $info['photo'] && !$update_photo) { $filename_original = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.original.jpg", true, 'contacts'); if (file_exists($filename_original)) { $update_photo = array('original' => $filename_original); $filename_crop = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.jpg", true, 'contacts'); if (file_exists($filename_crop)) { $update_photo['crop'] = $filename_crop; } } } // birthday parts if (!empty($data_fields['birthday'])) { foreach (array('birth_day', 'birth_month', 'birth_year') as $f) { if (empty($master_data[$f]) && !empty($info[$f])) { $master[$f] = $master_data[$f] = $info[$f]; } } } } // Remove duplicates foreach (array_keys($check_duplicates) as $f) { $values = $master[$f]; if (!is_array($values) || count($values) <= 1) { continue; } $unique_values = array(); // md5 => true foreach ($values as $k => $v) { if (is_array($v)) { if (isset($v['value']) && is_string($v['value'])) { $v = $v['value']; } else { unset($v['ext'], $v['status']); ksort($v); $v = serialize($v); } } $hash = md5(mb_strtolower($v)); if (!empty($unique_values[$hash])) { unset($values[$k]); continue; } $unique_values[$hash] = true; } $master[$f] = array_values($values); } // Save master contact $errors = $master->save(array(), 42); // 42 == do not validate anything at all if ($errors) { $errormsg = array(); foreach ($errors as $field => $err) { if (!is_array($err)) { $err = array($err); } foreach ($err as $str) { $errormsg[] = $field . ': ' . $str; } } $result['error'] = implode("\n<br>", $errormsg); return $result; } // Merge categories $category_ids = array(); $ccm = new waContactCategoriesModel(); foreach ($ccm->getContactsCategories($merge_ids) as $cid => $cats) { $category_ids += array_flip($cats); } $category_ids = array_keys($category_ids); $ccm->add($master_id, $category_ids); // update photo if ($update_photo) { $rand = mt_rand(); $path = wa()->getDataPath(waContact::getPhotoDir($master['id']), true, 'contacts', false); // delete old image if (file_exists($path)) { waFiles::delete($path); } waFiles::create($path); $filename = $path . "/" . $rand . ".original.jpg"; waFiles::create($filename); waImage::factory($update_photo['original'])->save($filename, 90); if (!empty($update_photo['crop'])) { $filename = $path . "/" . $rand . ".jpg"; waFiles::create($filename); waImage::factory($update_photo['crop'])->save($filename, 90); } else { waFiles::copy($filename, $path . "/" . $rand . ".jpg"); } $master->save(array('photo' => $rand)); } $result['total_merged'] = count($contacts_data) + 1; $contact_ids = array_keys($contacts_data); // wa_log $log_model = new waLogModel(); $log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id)); // wa_login_log $login_log_model = new waLoginLogModel(); $login_log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id)); // Merge event $params = array('contacts' => $contact_ids, 'id' => $master_data['id']); wa()->event(array('contacts', 'merge'), $params); // Delete all merged contacts $contact_model = new waContactModel(); $contact_model->delete($contact_ids, false); // false == do not trigger event $history_model = new contactsHistoryModel(); foreach ($contact_ids as $contact_id) { $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id)); } return $result; }
public function setOptions($config) { if (!waRequest::post()) { return $config; } $options = waRequest::post('options'); if (!is_array($options)) { return $config; } $fields_unsorted = waContactFields::getAll(); $config['fields'] = array(); $cfvm = new waContactFieldValuesModel(); foreach ($options as $fld_id => $opts) { if ($fld_id == '%FID%') { continue; } $fld_id_no_ext = explode('.', $fld_id, 2); $field_ext = empty($fld_id_no_ext[1]) ? '' : '.' . $fld_id_no_ext[1]; $fld_id_no_ext = $fld_id_no_ext[0]; $field = ifset($fields_unsorted[$fld_id_no_ext]); // Special treatment for subfields of shipping and billing address: // copy actual settings from address field. if ($field_ext && $fld_id_no_ext == 'address') { $existing_subfields = $field->getFields(); // Sanity check if (!is_array($opts) || empty($options['address']) || !is_array($options['address']) || empty($options['address']['fields']) || !is_array($options['address']['fields'])) { continue; } // Copy settings if subfield is turned on, or required, or is hidden $fields = array(); foreach ($options['address']['fields'] as $sf_id => $sf_opts) { if (!empty($sf_opts['required']) || !empty($sf_opts['_disabled']) && !empty($sf_opts['_default_value_enabled']) && empty($sf_opts['_deleted']) || !empty($opts['fields'][$sf_id])) { if (!$field_ext || isset($existing_subfields[$sf_id])) { $fields[$sf_id] = $sf_opts; } } } $opts['fields'] = $fields; } if ($field) { if (!empty($opts['_deleted'])) { waContactFields::deleteField($field); unset($fields_unsorted[$fld_id_no_ext]); continue; } $new_field = false; } else { $field = self::createFromOpts($opts, $fields_unsorted); if (!$field || $field instanceof waContactCompositeField) { continue; } // For conditional fields, update ID in database: replace temporary id with new one if ($field instanceof waContactConditionalField) { $cfvm->changeField($fld_id_no_ext, $field->getId()); } $fld_id = $field->getId() . $field_ext; $new_field = true; } list($local_opts, $sys_opts) = self::tidyOpts($field, $fld_id, $opts); if ($local_opts === null || $sys_opts === null) { continue; } // Write to system config. if (!$field_ext) { $field->setParameters($sys_opts); $fields_unsorted[$fld_id_no_ext] = $field; if ($new_field) { waContactFields::createField($field); waContactFields::enableField($field, 'person'); $fields_unsorted[$field->getId()] = $field; } else { if ($sys_opts) { waContactFields::updateField($field); waContactFields::enableField($field, 'person'); } } } $config['fields'][$fld_id] = $local_opts; } // Delete garbage from wa_contact_field_values $cfvm->exec("DELETE FROM wa_contact_field_values WHERE field RLIKE '__[0-9]+\$'"); return $config; }
public function execute() { // $this->getConfig()->getCheckoutSettings()['contactinfo'] $config = $this->params; if (empty($config)) { //$config_steps = $this->getConfig()->getCheckoutSettings(); //$config = $config_steps['contactinfo']; // debug helper $config = array(); } $fields_unsorted = waContactFields::getAll(); // Allow to disable name field in form, despite that it is normally required. $fields_unsorted['name'] = clone $fields_unsorted['name']; $fields_unsorted['name']->setParameter('required', false); $fields_unsorted['address.billing'] = clone $fields_unsorted['address']; $fields_unsorted['address.billing']->setParameter('localized_names', _w('Billing address')); $fields_unsorted['address.shipping'] = clone $fields_unsorted['address']; $fields_unsorted['address.shipping']->setParameter('localized_names', _w('Shipping address')); // Load config parameters into cloned fields $fields = array(); $config_fields = ifempty($config['fields'], array()); foreach ($config_fields as $fld_id => $opts) { // Skip hidden fields (they are shown as 'disabled') if (!empty($opts['hidden'])) { continue; } // This allows to specify e.g. 'address.shipping' as field id in config. $real_fld_id = explode('.', $fld_id, 2); $real_fld_id = $real_fld_id[0]; if (empty($fields_unsorted[$real_fld_id]) || !$fields_unsorted[$real_fld_id] instanceof waContactField || !is_array($opts)) { continue; } $fields[$fld_id] = clone $fields_unsorted[$real_fld_id]; foreach ($opts as $k => $v) { if ($fields[$fld_id] instanceof waContactCompositeField && $k == 'fields') { if (is_array($v)) { $cloned_subfields = $v; $unknown_subfields = array(); foreach ($cloned_subfields as $sf_id => $sf) { $unknown_subfields[$sf_id] = true; } foreach ($fields[$fld_id]->getFields() as $sf) { $sf = clone $sf; $o = ifset($v[$sf->getId()]); if (isset($unknown_subfields[$sf->getId()])) { unset($unknown_subfields[$sf->getId()]); } if ($o && is_array($o) && empty($o['hidden'])) { $sf->setParameters($o); $cloned_subfields[$sf->getId()] = $sf; } else { if (isset($cloned_subfields[$sf->getId()])) { unset($cloned_subfields[$sf->getId()]); } $sf->setParameter('_disabled', true); $cloned_subfields[] = $sf; } } foreach ($unknown_subfields as $sf_id => $flag) { unset($cloned_subfields[$sf_id]); } $fields[$fld_id]->setParameter('fields', $cloned_subfields); } } else { $fields[$fld_id]->setParameter($k, $v); } } } // Add to $fields everything that were not specified in config. foreach ($fields_unsorted as $fld_id => $f) { if (empty($fields[$fld_id])) { $fields[$fld_id] = clone $f; $fields[$fld_id]->setParameter('_disabled', true); } } // Address fields are shown separately $address = $fields['address']; $billing_address = $fields['address.billing']; $shipping_address = $fields['address.shipping']; unset($fields['address.billing'], $fields['address.shipping'], $fields['address']); $shipbill_address = array(); $shipbill_address['ship'] = array('short_id' => 'ship', 'id' => 'address.shipping', 'name' => _w('Shipping address prompt'), 'f' => $shipping_address, 'subfields' => array(), 'show_custom_settings' => false); $shipbill_address['bill'] = array('short_id' => 'bill', 'id' => 'address.billing', 'name' => _w('Billing address prompt'), 'f' => $billing_address, 'subfields' => array(), 'show_custom_settings' => false); $address_subfields = $address->getFields(); foreach ($address_subfields as $sf) { $sfa = array('id' => $sf->getId(), 'name' => $sf->getName(), 'enabled' => false, 'f' => $sf); $shipbill_address['ship']['subfields'][$sf->getId()] = $sfa; $shipbill_address['bill']['subfields'][$sf->getId()] = $sfa; } foreach ($shipping_address->getFields() as $sf) { if ($sf->getParameter('_disabled')) { $shipbill_address['ship']['show_custom_settings'] = true; } else { $shipbill_address['ship']['subfields'][$sf->getId()]['enabled'] = true; } } foreach ($billing_address->getFields() as $sf) { if ($sf->getParameter('_disabled')) { if (!empty($address_subfields[$sf->getId()]) && !$address_subfields[$sf->getId()]->getParameter('_disabled')) { $shipbill_address['bill']['show_custom_settings'] = true; } } else { $shipbill_address['bill']['subfields'][$sf->getId()]['enabled'] = true; } } $this->view->assign('fields', $fields); $this->view->assign('address', $address); $this->view->assign('shipbill_address', $shipbill_address); }
public function signupFields($errors = array()) { $config = wa()->getAuthConfig(); $config_fields = isset($config['fields']) ? $config['fields'] : array('firstname', 'lastname', '', 'email' => array('required' => true), 'password' => array('required' => true)); $format_fields = array(); foreach ($config_fields as $k => $v) { if (is_numeric($k)) { if ($v) { $format_fields[$v] = array(); } else { $format_fields[] = ''; } } else { $format_fields[$k] = $v; } } $fields = array(); foreach ($format_fields as $field_id => $field) { if (!is_numeric($field_id)) { if (strpos($field_id, '.')) { $field_id_parts = explode('.', $field_id); $id = $field_id_parts[0]; $field['ext'] = $field_id_parts[1]; } else { $id = $field_id; } $f = waContactFields::get($id); if ($f) { $fields[$field_id] = array($f, $field); } elseif ($field_id == 'login') { $fields[$field_id] = array(new waContactStringField($field_id, _ws('Login')), $field); } elseif ($field_id == 'password') { $fields[$field_id] = array(new waContactPasswordField($field_id, _ws('Password')), $field); $field_id .= '_confirm'; $fields[$field_id] = array(new waContactPasswordField($field_id, _ws('Confirm password')), $field); } } else { $fields[] = ''; } } return $fields; }
/** * @param array $data * @param array $errors * @return bool|waContact */ public function signup($data, &$errors = array()) { // check exists contacts $auth = wa()->getAuth(); $field_id = $auth->getOption('login'); if ($field_id == 'login') { $field_name = _ws('Login'); } else { $field = waContactFields::get($field_id); if ($field) { $field_name = $field->getName(); } else { $field_name = ucfirst($field_id); } } $is_error = false; // check passwords if ($data['password'] !== $data['password_confirm']) { $errors['password'] = array(); $errors['password_confirm'] = array(_ws('Passwords do not match')); $is_error = true; } elseif (!$data['password']) { $errors['password'] = array(); $errors['password_confirm'][] = _ws('Password can not be empty.'); $is_error = true; } if (!$data[$field_id]) { $errors[$field_id] = array(sprintf(_ws("%s is required"), $field_name)); $is_error = true; } if (!$is_error) { $contact = $auth->getByLogin($data[$field_id]); if ($contact) { $errors[$field_id] = array(sprintf(_ws('User with the same %s is already registered'), $field_name)); $is_error = true; } } $auth_config = wa()->getAuthConfig(); // set unknown or unconfirmed status for email if (isset($data['email']) && $data['email']) { if (!empty($auth_config['params']['confirm_email'])) { $email_status = 'unconfirmed'; } else { $email_status = 'unknown'; } $data['email'] = array('value' => $data['email'], 'status' => $email_status); } // check captcha if (isset($auth_config['signup_captcha']) && $auth_config['signup_captcha']) { if (!wa()->getCaptcha()->isValid()) { $errors['captcha'] = _ws('Invalid captcha'); $is_error = true; } } if (is_array($auth_config['fields'])) { foreach ($auth_config['fields'] as $fld_id => $fld) { if (array_key_exists('required', $fld) && !$data[$fld_id] && $fld_id !== 'password') { $field = waContactFields::get($fld_id); if (!empty($fld['caption'])) { $field_name = $fld['caption']; } else { if ($field) { $field_name = $field->getName(); } else { $field_name = ucfirst($fld_id); } } $errors[$fld_id] = array(sprintf(_ws("%s is required"), $field_name)); $is_error = true; } } } if ($is_error) { return false; } if (isset($data['birthday']) && is_array($data['birthday']['value'])) { foreach ($data['birthday']['value'] as $bd_id => $bd_val) { if (strlen($bd_val) === 0) { $data['birthday']['value'][$bd_id] = null; } } } // remove password_confirm field unset($data['password_confirm']); // set advanced data $data['create_method'] = 'signup'; $data['create_ip'] = waRequest::getIp(); $data['create_user_agent'] = waRequest::getUserAgent(); // try save contact $contact = new waContact(); if (!($errors = $contact->save($data, true))) { if (!empty($data['email'])) { $this->send($contact); } /** * @event signup * @param waContact $contact */ wa()->event('signup', $contact); // after sign up callback $this->afterSignup($contact); // try auth new contact try { if (empty($data['email']) || empty($auth_config['params']['confirm_email'])) { if (wa()->getAuth()->auth($contact)) { $this->logAction('signup', wa()->getEnv()); } } } catch (waException $e) { $errors = array('auth' => $e->getMessage()); } return $contact; } if (isset($errors['name'])) { $errors['firstname'] = array(); $errors['middlename'] = array(); $errors['lastname'] = $errors['name']; } return false; }
/** * @return waContactForm */ protected function getForm() { // Read all contact fields and find all enabled for "my profile" $fields = array('photo' => new waContactHiddenField('photo', _ws('Photo'))) + waContactFields::getAll('person') + array('password' => new waContactPasswordField('password', _ws('Password'))) + array('password_confirm' => new waContactPasswordField('password_confirm', _ws('Confirm password'))); $domain = wa()->getRouting()->getDomain(); $domain_config_path = wa()->getConfig()->getConfigPath('domains/' . $domain . '.php', true, 'site'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } $enabled = array(); foreach ($fields as $fld_id => $f) { if (!empty($domain_config['personal_fields'][$fld_id])) { $enabled[$fld_id] = $f; if ($fld_id === 'password') { $enabled[$fld_id . '_confirm'] = $fields[$fld_id . '_confirm']; } } } // If nothing found, fall back to the default field list if (!$enabled) { foreach (array('firstname', 'middlename', 'lastname', 'email', 'phone', 'password') as $fld_id) { if (!empty($fields[$fld_id])) { $enabled[$fld_id] = $fields[$fld_id]; } } } return waContactForm::loadConfig($enabled, array('namespace' => 'profile')); }
public function format($data) { $parts = $this->getParts($data); $i = 0; $data['value'] = array(); $fields = waContactFields::get('address')->getFields(); foreach ($parts['parts'] as $part_id => $part) { $v = ''; // add country flag before the first line if ($i === 0 && $parts['pic'] && (!isset($this->options['image']) || $this->options['image'])) { $v = $parts['pic'] . ' '; } $v .= $part; // add marker after the first line of address if ($i == 0 && $parts['marker']) { $v .= $parts['marker']; } $data['value'][] = $v; $i++; } $data['value'] = implode("<br>\n", $data['value']); return $data; }