示例#1
0
 function write()
 {
     if (bff::$isAjax) {
         $nUserID = $this->security->getUserID();
         $p = $this->input->postm(array('email' => TYPE_STR, 'phone' => TYPE_NOHTML, 'message' => TYPE_NOHTML, 'captcha' => TYPE_STR));
         if (!$nUserID) {
             if (empty($p['email']) || !Func::IsEmailAddress($p['email'])) {
                 $this->errors->set('wrong_email');
             }
         }
         $p['phone'] = func::cleanComment($p['phone']);
         if (empty($p['phone'])) {
             $this->errors->set('no_phone');
         }
         $p['message'] = func::cleanComment($p['message']);
         if (empty($p['message'])) {
             $this->errors->set('no_message');
         }
         if (!$nUserID) {
             $oProtection = new CCaptchaProtection();
             if (!$oProtection->valid(isset($_SESSION['c2']) ? $_SESSION['c2'] : '', $p['captcha'])) {
                 $this->errors->set('wrong_captcha');
             }
         }
         if ($this->errors->no()) {
             unset($_SESSION['c2']);
             $this->db->execute('INSERT INTO ' . TABLE_CONTACTS . ' (user_id, email, phone, message, created) 
                            VALUES (' . $nUserID . ', ' . $this->db->str2sql($p['email']) . ', 
                                    ' . $this->db->str2sql($p['phone']) . ', ' . $this->db->str2sql(nl2br($p['message'])) . ', 
                                    ' . $this->db->getNOW() . ')');
             $nRecordID = $this->db->insert_id(TABLE_CONTACTS, 'id');
             if ($nRecordID) {
                 config::saveCount('contacts_new', 1);
                 bff::sendMailTemplate(array('user' => !$nUserID ? 'Аноним' : $this->security->getUserEmail(), 'email' => !$nUserID ? $p['email'] : $this->security->getUserEmail(), 'phone' => $p['phone'], 'message' => nl2br($p['message'])), 'admin_contacts', config::get('mail_admin', BFF_EMAIL_SUPPORT));
             }
         }
         $this->ajaxResponse(Errors::SUCCESS);
     }
     config::set('title', 'Связь с редактором - ' . config::get('title', ''));
     return $this->tplFetch('write.tpl');
 }
示例#2
0
 function mod_add()
 {
     if (!$this->haveAccessTo('users-edit')) {
         return $this->showAccessDenied();
     }
     $this->input->postm(array('login' => TYPE_STR, 'avatar' => TYPE_STR, 'name' => TYPE_STR, 'email' => TYPE_STR, 'password' => TYPE_STR, 'password2' => TYPE_STR, 'balance' => TYPE_NUM, 'skype' => TYPE_STR, 'email2' => TYPE_STR, 'phone' => TYPE_STR, 'group_id' => TYPE_ARRAY_INT, 'cat' => TYPE_ARRAY_UINT), $aData);
     $aData['admin'] = 0;
     if (bff::$isPost) {
         do {
             //                if($aData['city_id']<=0) {
             //                    $this->errors->set('wrong:city'); break;
             //                }
             $aData['email_hash'] = func::getEmailHash($aData['email']);
             if (!$aData['login']) {
                 $this->errors->set('empty:login');
                 break;
             }
             if (!$aData['email']) {
                 $this->errors->set('empty:email');
                 break;
             } elseif (!Func::IsEmailAddress($aData['email'])) {
                 $this->errors->set('wrong:email');
                 break;
             }
             if ($this->isLoginExists($aData['login'])) {
                 $this->errors->set('login_exist');
                 break;
             }
             if ($this->isEmailExists($aData['email_hash'])) {
                 $this->errors->set('email_exist');
                 break;
             }
             if (!$aData['password']) {
                 $this->errors->set('empty:password');
                 break;
             } elseif ($aData['password'] != $aData['password2']) {
                 $this->errors->set('password_confirmation');
                 break;
             }
             if ($this->errors->no()) {
                 $aGroupID = $aData['group_id'];
                 //array
                 $aData['member'] = 0;
                 $aData['ip_reg'] = func::getRemoteAddress(true);
                 $aData['activated'] = 1;
                 $aData['cat'] = join(',', $aData['cat']);
                 unset($aData['password2'], $aData['group_id']);
                 $nRecordID = $this->userInsert($aData);
                 if ($nRecordID > 0) {
                     $avatar = new CAvatar(TABLE_USERS, USERS_AVATAR_PATH, 'avatar', 'user_id');
                     $avatar->update($nRecordID, false, true);
                     if (empty($aGroupID)) {
                         $aGroupID = array(USERS_GROUPS_MEMBER);
                     } else {
                         $this->assignUser2Groups($nRecordID, $aGroupID);
                     }
                     # обновляем, является ли юзер администратором
                     $bIsAdmin = 0;
                     if (!(count($aGroupID) == 1 && current($aGroupID) == self::GROUPID_MEMBER)) {
                         if (in_array(self::GROUPID_SUPERADMIN, $aGroupID) || in_array(self::GROUPID_MODERATOR, $aGroupID)) {
                             $bIsAdmin = 1;
                         } else {
                             $aUserGroups = $this->getGroups(null, $aGroupID);
                             foreach ($aUserGroups as $v) {
                                 if ($v['adminpanel'] == 1) {
                                     $bIsAdmin = 1;
                                     break;
                                 }
                             }
                         }
                         if ($bIsAdmin) {
                             $this->db->execute('UPDATE ' . TABLE_USERS . ' SET admin=' . $bIsAdmin . ' WHERE user_id=' . $nRecordID);
                         }
                     }
                 }
                 $this->adminRedirect(Errors::SUCCESSFULL, (!$aData['member'] ? 'admin_' : '') . 'listing');
             }
         } while (false);
         $this->input->postm(array('password2' => TYPE_STR, 'group_id' => TYPE_ARRAY_INT), $aData);
         func::array_2_htmlspecialchars($aData, null, true);
         $aActiveGroupsID = $aData['group_id'];
     } else {
         $aActiveGroupsID = array();
     }
     $aData = array_merge($aData, array('password2' => '', 'user_id' => ''));
     //assign groups
     $exists_options = '';
     $active_options = '';
     $aGroups = $this->getGroups(array(USERS_GROUPS_MEMBER, USERS_GROUPS_SUPERADMIN));
     for ($i = 0; $i < count($aGroups); $i++) {
         if (in_array($aGroups[$i]['group_id'], $aActiveGroupsID)) {
             $active_options .= '<option value="' . $aGroups[$i]['group_id'] . '" style="color:' . $aGroups[$i]['color'] . ';">' . $aGroups[$i]['title'] . '</option>';
         } else {
             $exists_options .= '<option value="' . $aGroups[$i]['group_id'] . '" style="color:' . $aGroups[$i]['color'] . ';">' . $aGroups[$i]['title'] . '</option>';
         }
     }
     $this->tplAssign('exists_options', $exists_options);
     $this->tplAssign('active_options', $active_options);
     //$aData['city_options'] = bff::i()->Sites_geoCityOptions($aData['city_id'], 'edit');
     $aData['edit'] = false;
     $this->tplAssign('aCategories', $this->getBBSCategories($aData['cat']));
     $this->tplAssignByRef('aData', $aData);
     return $this->tplFetch('admin.mod.form.tpl');
 }