/** * Displays User full name * * Format of full name is language specific and defined by $R['users_full_name'] * resource string. * * @param array|int $user User Data or User ID * @return string */ function cot_user_full_name($user) { if (empty($user)) { return ''; } if (is_int($user) && $user > 0 || ctype_digit($user)) { require_once cot_incfile('users', 'module'); $user = cot_user_data($user); } if (empty($user)) { return ''; } $user_fname = $user['user_firstname'] ? $user['user_firstname'] : $user['user_first_name']; $user_mname = $user['user_middlename'] ? $user['user_middlename'] : $user['user_middle_name']; $user_lname = $user['user_lastname'] ? $user['user_lastname'] : $user['user_last_name']; $full_name = trim(cot_rc('users_full_name', array('firstname' => $user_fname, 'middlename' => $user_mname, 'lastname' => $user_lname, 'name' => $user['user_name']))); return $full_name ? $full_name : $user['user_name']; }
public function indexAction() { global $structure; $uid = cot_import('uid', 'G', 'INT'); if (empty($uid)) { $uid = cot::$usr['id']; } // Незарегов, если они не смотрят объявления другого пользователя перенаправляем if (!$uid) { cot_redirect(cot_url('advboard', '', '', true)); } // Проверить существование пользователя $user = cot_user_data($uid); if (!$user) { cot_die_message(404, TRUE); } $maxrowsperpage = cot::$cfg['advboard']['cat___default']['maxrowsperpage']; if ($maxrowsperpage < 1) { $maxrowsperpage = 1; } list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage); //page number for pages list $condition = array(array('user', $uid)); if (!cot::$usr['isadmin'] && $uid != cot::$usr['id']) { $condition[] = array('state', advboard_model_Advert::PUBLISHED); $condition[] = array('begin', cot::$sys['now'], '<='); $condition[] = array('SQL', "expire = 0 OR expire > " . cot::$sys['now']); } $order = array(array('state', 'ASC'), array('sort', 'DESC')); cot::$out['canonical_uri'] = cot_url('advboard', array('m' => 'user', 'uid' => $uid)); $urlParams = array('m' => 'user'); if ($uid != cot::$usr['id']) { $urlParams['uid'] = $uid; } $title = ''; $crumbs = array(); if ($uid != cot::$usr['id']) { cot::$out['subtitle'] = $title = cot::$L['advboard_user_ads'] . ': ' . cot_user_full_name($user); $crumbs[] = array(cot_url("users"), cot::$L['Users']); $crumbs[] = array(cot_url("users", "m=details&id=" . $user["user_id"] . "&u=" . $user["user_name"]), cot_user_full_name($user)); $crumbs[] = cot::$L['advboard_user_ads']; // $advUrlParams['uid'] = $user['user_id']; $urlParams['uid'] = $user['user_id']; } else { cot::$out['subtitle'] = $title = cot::$L['advboard_my_ads']; $crumbs[] = array(cot_url('users', array('m' => 'details')), cot::$L['advboard_my_page']); $crumbs[] = cot::$L['advboard_my_ads']; } /* === Hook === */ foreach (cot_getextplugins('advboard.user.list.query') as $pl) { include $pl; } /* ===== */ $totallines = advboard_model_Advert::count($condition); $advertisement = advboard_model_Advert::find($condition, $maxrowsperpage, $d, $order); $addNewUrl = ''; if ((cot::$usr['auth_write'] || cot::$usr['isadmin']) && !empty($structure['advboard'])) { // Ищем категорию куда пользователь может подать оьбъявление foreach ($structure['advboard'] as $catCode => $catRow) { $auth_write = cot_auth('advboard', $catCode, 'W'); if ($auth_write) { $addNewUrl = cot_url('advboard', array('a' => 'edit', 'c' => $catCode)); break; } } } $pagenav = cot_pagenav('advboard', $urlParams, $d, $totallines, $maxrowsperpage); if (empty($pagenav['current'])) { $pagenav['current'] = 1; } $breadcrumbs = ''; if (!empty($crumbs)) { $breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true); } $template = array('advboard', 'list', 'user'); $pageUrlParams = $urlParams; if ($durl > 1) { $pageUrlParams['d'] = $durl; } $view = new View(); $view->breadcrumbs = $breadcrumbs; $view->page_title = htmlspecialchars($title); $view->advertisement = $advertisement; $view->allowComments = true; $view->totalitems = $totallines; $view->pagenav = $pagenav; $view->addNewUrl = $addNewUrl; $view->urlParams = $urlParams; $view->pageUrlParams = $pageUrlParams; /* === Hook === */ foreach (cot_getextplugins('advboard.user.list.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
public function editAction() { global $structure, $cot_extrafields, $db_structure; $id = cot_import('id', 'G', 'INT'); // id Объявления $c = cot_import('c', 'G', 'TXT'); $act = cot_import('act', 'G', 'ALP'); if (empty($act)) { $act = cot_import('act', 'P', 'ALP'); } /* === Hook === */ foreach (cot_getextplugins('advboard.edit.first') as $pl) { include $pl; } /* ===== */ // Права на любую категорию доски объявлений list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin']) = cot_auth('advboard', 'any'); cot_block(cot::$usr['auth_write']); if (!$c || !isset($structure['advboard'][$c])) { cot_die_message(404, TRUE); } $category = $structure['advboard'][$c]; $category['config'] = cot::$cfg['advboard']['cat_' . $c]; $category['code'] = $c; // Extra fields for structure foreach ($cot_extrafields[$db_structure] as $exfld) { $uname = $exfld['field_name']; $val = $structure['advboard'][$c][$exfld['field_name']]; $category[$uname . '_title'] = isset(cot::$L['structure_' . $exfld['field_name'] . '_title']) ? cot::$L['structure_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $category[$uname] = cot_build_extrafields_data('structure', $exfld, $val); $category[$uname . '_value'] = $val; } $published = 0; if (!$id) { $advert = new advboard_model_Advert(); $advert->category = $c; $advert->user = cot::$usr['id']; } else { $advert = advboard_model_Advert::getById($id); if (!$advert) { cot_die_message(404, TRUE); } if (!cot::$usr['isadmin']) { if ($advert->user != cot::$usr['id']) { cot_die_message(404, TRUE); } } if ($c != $advert->category && isset($structure['advboard'][$advert->category])) { $tmp = array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id); if (!empty($act)) { $tmp['act'] = $act; } cot_redirect(cot_url('advboard', array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id), '', true)); } if ($act == 'clone') { $id = null; $advert = clone $advert; // Установить статус и пользователя нового объекта $advert->user = cot::$usr['id']; $advert->state = advboard_model_Advert::DRAFT; } $published = $advert->state < 2 ? 1 : 0; } //Проверим права на категорию: list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin'], cot::$usr['auth_upload']) = cot_auth('advboard', $c, 'RWA1'); if ($structure['advboard'][$c]['locked'] && !cot::$usr['isadmin']) { cot_die_message(602, TRUE); } elseif ($advert->id == 0) { // Если у пользователя нет прав на подачу объявления, то ищем категорию куда он может подать оьбъявление if (!cot::$usr['auth_write']) { foreach ($structure['advboard'] as $catCode => $catRow) { $auth_write = cot_auth('advboard', $catCode, 'W'); if ($auth_write) { cot_redirect(cot_url('advboard', array('c' => $catCode, 'a' => 'edit'), '', true)); } } } cot_block(cot::$usr['auth_write']); } // Владелец объявления $user = array(); if ($advert->user > 0) { $user = cot_user_data($advert->user); } $periodItems = adv_periodItems($c); // Сохранение if ($act == 'save') { unset($_POST['id'], $_POST['user']); cot_shield_protect(); /* === Hook === */ foreach (cot_getextplugins('advboard.save.first') as $pl) { include $pl; } /* ===== */ // импортировать даты $begin = (int) cot_import_date('begin'); $expire = (int) cot_import_date('expire'); if ($begin == 0) { $begin = !empty($advert->begin) ? $advert->begin : cot::$sys['now']; } // Пересчитать период публикации объявления if ($expire == 0 && cot::$cfg['advboard']['cat_' . $c]['maxPeriod'] > 0) { $period = cot_import('period', 'P', 'INT'); $maxPeriod = max($periodItems); if (empty($period)) { $period = $maxPeriod; } if (!cot::$usr['isadmin'] && $period > $maxPeriod) { $period = $maxPeriod; } if ($period > 0) { $expire = $begin + $period * 86400; } } if ($category['config']['title_require']) { $advert->setValidator('title', 'required'); } // Валидатор 'allowemptytext' if (!$category['config']['allowemptytext']) { $advert->setValidator('text', 'required'); } if ($category['config']['phone_require']) { // проверить надичие заполненного поля в профиле пользователя - владельца if (empty($user['user_phone'])) { $advert->setValidator('phone', 'required'); } } if ($category['config']['city_require']) { // Проверить наличие заполненного города (id или названия) в профиле владельца if (empty($user['user_city_name']) && empty($user['user_city'])) { if (cot_plugin_active('regioncity')) { $advert->setValidator('city', function ($value) { $value = (int) $value; if ($value == 0) { return cot::$L['field_required'] . ': ' . advboard_model_Advert::fieldLabel('city'); } return true; }); } else { $advert->setValidator('city_name', 'required'); } } } if (cot::$usr['id'] == 0) { $advert->setValidator('person', 'required'); // Email $email = cot_import('email', 'P', 'TXT'); if (cot::$cfg['advboard']['guestEmailRequire']) { if ($email == '') { cot_error(cot::$L['advboard_err_noemail'], 'email'); } } if ($email != '') { $tmp = advert_checkEmail($email); if ($tmp !== true) { cot_error($tmp, 'email'); } } // Капча if (cot::$cfg['advboard']['guestUseCaptcha']) { $verify = cot_import('verify', 'P', 'TXT'); if (!cot_captcha_validate($verify)) { cot_error(cot::$L['captcha_verification_failed'], 'verify'); } } } $advert->setData($_POST); $advert->begin = $begin; $advert->expire = $expire; if (!cot::$usr['isadmin']) { if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky']) { $advert->sticky = 0; } if (cot::$usr['id'] == 0) { $advert->sticky = 0; } // гости не дают срочных объявлений } $advert->category = $c; if (empty($advert->user) || !cot::$usr['isadmin']) { $advert->user = cot::$usr['id']; } $published = cot_import('published', 'P', 'BOL'); if (!$published) { $advert->state = advboard_model_Advert::DRAFT; } elseif (cot::$usr['isadmin'] || cot_auth('advboard', $c, '2')) { $advert->state = advboard_model_Advert::PUBLISHED; } else { $advert->state = advboard_model_Advert::AWAITING_MODERATION; } /* === Hook === */ foreach (cot_getextplugins('advboard.save.validate') as $pl) { include $pl; } /* ===== */ // There is some errors if (!$advert->validate() || cot_error_found()) { $urlParams = array('c' => $c, 'a' => 'edit'); if ($advert->id > 0) { $urlParams['id'] = $advert->id; } cot_redirect(cot_url('advboard', $urlParams, '', true)); } if (empty($advert->sort)) { $advert->sort = cot::$sys['now']; } $isNew = $advert->id == 0; // Сохранение if ($advert->save()) { // Для незарега запомним id страницы для чтого, чтобы он мог ее отредактировать в пределах сесии if ($isNew) { if (cot::$usr['id'] == 0) { if (empty($_SESSION['advboard'])) { $_SESSION['advboard'] = array(); } if (!in_array($id, $_SESSION['advboard'])) { $_SESSION['advboard'][] = $advert->id; } } if ($advert->state == advboard_model_Advert::PUBLISHED) { cot_message(cot::$L['advboard_created']); } } else { if ($advert->state == advboard_model_Advert::PUBLISHED) { cot_message(cot::$L['advboard_updated']); } } if ($advert->state == advboard_model_Advert::AWAITING_MODERATION) { cot_message(cot::$L['advboard_awaiting_moderation']); } elseif ($advert->state == advboard_model_Advert::DRAFT) { cot_message(cot::$L['Saved']); } $redirectUrl = $advert->getUrl(true); /* === Hook === */ foreach (cot_getextplugins('advboard.save.done') as $pl) { include $pl; } /* ===== */ // Редирект на станицу объявления cot_redirect($redirectUrl); } } $crumbs = cot_structure_buildpath('advboard', $c); if (cot::$cfg['advboard']['firstCrumb']) { array_unshift($crumbs, array(cot_url('advboard'), cot::$L['advboard_ads'])); } if (!$id) { $crumbs[] = $title = cot::$L['advboard_add_new']; cot::$out['subtitle'] = $title; } else { $crumbs[] = array($advert->url, $advert->title); $crumbs[] = cot::$L['Edit']; $title = cot::$L['advboard_advert'] . ' #' . $advert->id; if (!empty($advert->title)) { $title = $advert->title; } $title .= ': ' . cot::$L['Edit']; if (!empty(cot::$out['subtitle'])) { $title .= ' - ' . cot::$out['subtitle']; } cot::$out['subtitle'] = $title; } // Elemets placeholders $placeHolder_Person = ''; $placeHolder_Phone = ''; $placeHolder_Email = ''; $placeHolder_City = ''; //if($advboard->user == cot::$usr['id'] && cot::$usr['id'] > 0) { if (!empty($user)) { // Контакное лицо $placeHolder_Person = cot_user_full_name($user); // Телефон if (!empty($user['user_phone'])) { $placeHolder_Phone = $user['user_phone']; } // email if (!$user['user_hideemail']) { $placeHolder_Email = $user['user_email']; } // город if (!empty($user['user_city_name'])) { $placeHolder_City = $user['user_city_name']; } } // 'input_textarea_editor', 'input_textarea_medieditor', 'input_textarea_minieditor', '' $editor = 'input_textarea_editor'; /* === Hook === */ foreach (cot_getextplugins('advboard.edit.main') as $pl) { include $pl; } /* ===== */ $minYear = date('Y'); $maxYear = $minYear + 30; $price = $advert->rawValue('price'); if ($price <= 0) { $price = ''; } $formElements = array('hidden' => array('element' => cot_inputbox('hidden', 'act', 'save')), 'category' => array('element' => cot_selectbox_structure('advboard', $advert->category, 'category'), 'label' => advboard_model_Advert::fieldLabel('category')), 'price' => array('element' => cot_inputbox('text', 'price', $price), 'label' => advboard_model_Advert::fieldLabel('price'), 'hint' => cot::$L['advboard_price_hint']), 'title' => array('element' => cot_inputbox('text', 'title', $advert->rawValue('title')), 'required' => true, 'label' => advboard_model_Advert::fieldLabel('title')), 'description' => array('element' => cot_inputbox('text', 'description', $advert->rawValue('description')), 'label' => advboard_model_Advert::fieldLabel('description')), 'text' => array('element' => cot_textarea('text', $advert->rawValue('text'), 5, 120, '', $editor), 'label' => advboard_model_Advert::fieldLabel('text')), 'person' => array('element' => cot_inputbox('text', 'person', $advert->rawValue('person'), array('class' => 'form-control', 'placeholder' => $placeHolder_Person)), 'label' => advboard_model_Advert::fieldLabel('person'), 'required' => cot::$usr['id'] == 0), 'email' => array('element' => cot_inputbox('text', 'email', $advert->rawValue('email'), array('class' => 'form-control', 'placeholder' => $placeHolder_Email)), 'label' => advboard_model_Advert::fieldLabel('email')), 'city' => array('element' => cot_inputbox('text', 'city_name', $advert->rawValue('city_name'), array('class' => 'form-control', 'placeholder' => $placeHolder_City)), 'label' => advboard_model_Advert::fieldLabel('city_name'), 'required' => $category['config']['city_require']), 'phone' => array('element' => cot_inputbox('text', 'phone', $advert->rawValue('phone'), array('class' => 'form-control', 'placeholder' => $placeHolder_Phone)), 'label' => advboard_model_Advert::fieldLabel('phone'), 'required' => $category['config']['phone_require']), 'sticky' => array('element' => cot_checkbox($advert->sticky, 'sticky', advboard_model_Advert::fieldLabel('sticky')), 'label' => advboard_model_Advert::fieldLabel('sticky')), 'published' => array('element' => cot_checkbox($published, 'published', cot::$L['advboard_published'] . '?'), 'label' => cot::$L['advboard_published'] . '?'), 'begin' => array('element' => cot_selectbox_date($advert->begin, 'long', 'begin', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('begin')), 'expire' => array('element' => cot_selectbox_date($advert->expire, 'long', 'expire', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('expire')), 'sort' => array('element' => cot_selectbox_date($advert->sort, 'long', 'sort', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('sort')), 'period' => array('element' => cot_selectbox('', 'period', $periodItems, array(), false), 'label' => cot::$L['advboard_period'])); if (!empty($cot_extrafields[cot::$db->advboard])) { // Extra fields for ads foreach ($cot_extrafields[cot::$db->advboard] as $exfld) { $fName = $exfld['field_name']; $formElements[$fName] = array('element' => cot_build_extrafields($fName, $exfld, $advert->rawValue($fName))); if ($exfld['field_type'] !== 'checkbox') { $formElements[$fName]['label'] = isset(cot::$L['advboard_' . $exfld['field_name'] . '_title']) ? cot::$L['advboard_' . $exfld['field_name'] . '_title'] : advboard_model_Advert::fieldLabel($fName); } } } if (cot_plugin_active('regioncity')) { $formElements['city']['element'] = rec_select2_city('city', $advert->rawValue('city'), true, array('class' => 'form-control', 'placeholder' => $placeHolder_City)); } if ($category['config']['city_require']) { $formElements['city']['required'] = true; } if ($category['config']['phone_require']) { $formElements['phone']['required'] = true; } // Hints if (!empty($user)) { // Контакное лицо $formElements['person']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . cot_user_full_name($user); // Телефон if (!empty($user['user_phone'])) { $formElements['phone']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_phone']; } // email if (!$user['user_hideemail']) { $formElements['email']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_email']; } // город if (!empty($user['user_city_name'])) { $formElements['city']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_city_name']; } } if (!cot::$usr['isadmin']) { unset($formElements['begin']); unset($formElements['expire']); unset($formElements['sort']); if (cot::$usr['id'] == 0) { if (cot::$cfg['advboard']['guestEmailRequire']) { $formElements['email']['required'] = true; } // Гости не дают срочных объявлений unset($formElements['sticky']); // Капча if (cot::$cfg['advboard']['guestUseCaptcha']) { $formElements['verify'] = array('element' => cot_inputbox('text', 'verify'), 'img' => cot_captcha_generate(), 'label' => cot::$L['advboard_captcha'], 'required' => true); } } if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky'] && isset($formElements['sticky'])) { unset($formElements['sticky']); } } else { // Администратор напрямую указывает дату окончания публикации unset($formElements['period']); } $actionParams = array('a' => 'edit', 'c' => $advert->category); if ($advert->id > 0) { $actionParams['id'] = $advert->id; } $view = new View(); $view->breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true); $view->page_title = $title; $view->category = $category; $view->advert = $advert; $view->user = $user; $view->formElements = $formElements; $view->formAction = cot_url('advboard', $actionParams); /* === Hook === */ foreach (cot_getextplugins('advboard.edit.view') as $pl) { include $pl; } /* ===== */ return $view->render(array('advboard', 'edit', $structure['advboard'][$c]['tpl'])); }
/** * Обработка Ajax запроса на подписку на рассылку или отписку */ public function ajxSubscribeToggleAction() { global $db_users; $ret = array('error' => '', 'message' => ''); $id = cot_import('id', 'P', 'INT'); $email = cot_import('email', 'P', 'TXT'); $uid = cot_import('uid', 'P', 'INT'); if (!$uid || !cot::$usr['isadmin']) { $uid = cot::$usr['id']; } // Только для авторизованных пользователей if (!$uid) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } // Управлять чужими подписками может только администратор if ($uid != cot::$usr['id'] && !cot::$usr['isadmin']) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } $user = cot_user_data($uid); if (!$user || empty($user['user_email'])) { $ret['error'] = cot::$L['subscribe_err_user_not_found']; echo json_encode($ret); exit; } if (!$id) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } $subscribe = subscribe_model_Subscribe::getById($id); if (!$subscribe) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } $cond = array(array('SQL', "subscribe={$id} AND (user={$uid} OR email=" . cot::$db->quote(cot::$usr['profile']['user_email']) . ')')); $subscriber = subscribe_model_Subscriber::fetchOne($cond); if (!$subscriber) { $subscriber = new subscribe_model_Subscriber(); $subscriber->subscribe = $id; } $subscriber->email = $user['user_email']; $subscriber->user = $uid; $subscriber->name = cot_user_full_name($user); if (!$subscriber->email_valid) { $subscriber->email_valid = 1; $subscriber->email_valid_date = cot_date('Y-m-d H:i:s', cot::$sys['now']); } if (!$subscriber->active) { // Включить // Проверка на то что рассылка включена if (!$subscribe->active) { $ret['error'] = cot::$L['subscribe_err_disabled']; echo json_encode($ret); exit; } // Если эта функция будет доступна незарегам... if ($subscriber->email_valid) { $subscriber->active = 1; if ($user['user_id'] == cot::$usr['id']) { cot_message(sprintf(cot::$L['subscribe_msg_you_subscribed'], $subscribe->title)); } else { cot_message(cot::$L['Saved']); } } } else { $subscriber->active = 0; if ($user['user_id'] == cot::$usr['id']) { cot_message(sprintf(cot::$L['subscribe_msg_you_unsubscribed'], $subscribe->title)); } else { cot_message(cot::$L['Saved']); } } $subscriber->save(); echo json_encode($ret); exit; }
public function ajxEditAction() { global $db_users; $ret = array('error' => ''); $id = cot_import('subrid', 'P', 'INT'); unset($_POST['id'], $_POST['subrid']); if ($id > 0) { $subscriber = subscribe_model_Subscriber::getById($id); if (!$subscriber) { $ret['error'] = cot::$L['subscribe_err_subscriber_not_found']; echo json_encode($ret); exit; } } else { $subscriber = new subscribe_model_Subscriber(); } if (!empty($_POST['email'])) { $_POST['email'] = mb_strtolower($_POST['email']); } $subscriber->setData($_POST); $error = array(); $subscr = null; $tmp = $subscriber->rawValue('subscribe'); if (empty($tmp)) { $error[] = cot::$L['field_required'] . ': ' . cot::$L['subscribe_subscribe']; } else { $subscr = subscribe_model_Subscribe::getById($subscriber->rawValue('subscribe')); if (!$subscr) { $error[] = cot::$L['subscribe_err_not_found']; } } $user = null; if (!empty($subscriber->user)) { $user = cot_user_data($subscriber->user); // Если получили данные пользователя, то e-mail всегда берем из профиля if (isset($user['user_email'])) { $subscriber->email = mb_strtolower($user['user_email']); } } if (empty($subscriber->email)) { $error[] = cot::$L['field_required'] . ': ' . cot::$L['Email']; } else { $tmp = subscribe_checkEmail($subscriber->email); if ($tmp !== true) { $error[] = $tmp; } if ($subscriber->rawValue('subscribe') > 0) { if (!empty($subscr)) { $cond = array(array('email', $subscriber->email), array('subscribe', $subscr->id)); if ($subscriber->id > 0) { $cond[] = array('id', $subscriber->id, '<>'); } $cnt = subscribe_model_Subscriber::count($cond); if ($cnt > 0) { $error[] = sprintf(cot::$L['subscribe_err_user_subscribed'], $subscriber->email, htmlspecialchars($subscr->title)); } } } } if (!empty($error)) { $ret['error'] = implode('<br />', $error); echo json_encode($ret); exit; } if (empty($subscriber->name) && (!empty($subscriber->email) || !empty($user))) { if (!empty($user)) { $subscriber->name = cot_user_full_name($user); } else { $sql = cot::$db->query("SELECT * FROM {$db_users} WHERE user_email = ? LIMIT 1", $subscriber->email); $user = $sql->fetch(); if (!empty($user)) { $subscriber->name = cot_user_full_name($user); if (empty($subscriber->user)) { $subscriber->user = $user['user_id']; } } } } // Админ при сохранении подтверждает e-mail if (!$subscriber->email_valid && (empty($subscriber->id) || $subscriber->active)) { $subscriber->email_valid = 1; $subscriber->email_valid_date = date('Y-m-d H:i:s', cot::$sys['now']); } // Сохранение $subscriber->save(); cot_message(cot::$L['Saved']); echo json_encode($ret); exit; }
/** * Пользователь - Владелец объявления * @return array */ public function getOwner() { if (is_null($this->_owner)) { if ($this->_data['user'] > 0) { $this->_owner = cot_user_data($this->_data['created_by']); if (empty($this->_owner)) { $this->_owner = array('user_id' => null, 'user_maingrp' => 1, 'user_name' => cot::$L['Deleted'], 'full_name' => cot::$L['Deleted'], 'user_avatar' => ''); } else { $this->_owner['full_name'] = cot_user_full_name($this->_owner); $this->_owner['url'] = cot_url('users', 'm=details&id=' . $this->_owner['user_id'] . '&u=' . htmlspecialchars($this->_owner['user_name'])); } } else { $this->_owner = array('user_id' => 0, 'user_maingrp' => 1, 'user_name' => cot::$L['Guest'], 'full_name' => cot::$L['Guest'], 'user_avatar' => ''); } } return $this->_owner; }