Exemplo n.º 1
0
 public function send_messageAction()
 {
     if ($form_obj = ormObjects::get(system::POST('form_id'))) {
         $issetErrors = false;
         $answer = array();
         // Проверка капчи
         if ($form_obj->captcha && !system::validCapcha('random_image')) {
             $issetErrors = true;
             $answer = array('field' => 'random_image', 'msg' => lang::get('FEEDBACK_ERROR1'));
         }
         // Если указанно куда, добавляем объект в БД
         if (($form_obj->any_sections || $form_obj->section) && !$issetErrors) {
             // Определяем раздел, в который будем добавлять отзыв
             if ($form_obj->any_sections) {
                 $section = system::POST('section_id', isInt);
             } else {
                 $section = $form_obj->section;
                 $section = !empty($section) ? $section[0] : 0;
             }
             // Создаем объект обратной связи
             $obj = new ormPage();
             $obj->setParent($section);
             $obj->setClass($form_obj->form_class);
             $obj->tabuList('pseudo_url', 'h1', 'keywords', 'title', 'description', 'answer', 'active', 'is_home_page', 'view_in_menu', 'view_submenu', 'in_search', 'in_index', 'in_new_window', 'other_link', 'img_act', 'img_no_act', 'img_h1');
             $obj->loadFromPost();
             $obj->active = 0;
             $obj->view_in_menu = 1;
             $obj->view_submenu = 1;
             $obj->in_search = 1;
             $obj->in_index = 1;
             $obj->is_home_page = 0;
             if ($obj->name != '') {
                 $obj->h1 = $obj->name;
                 $obj->title = $obj->name;
             }
             $obj->pseudo_url = rand(1000, 9999);
             $obj->template_id = ($sect = ormPages::get($form_obj->section)) ? $sect->template_id : 1;
             $obj->form_id = $form_obj->id;
             $obj->setRightForAll(2);
             $obj_id = $obj->save();
             if ($obj_id) {
                 $obj->pseudo_url = $obj_id;
                 $obj->save();
                 $obj = new ormPage($obj_id);
             } else {
                 $issetErrors = true;
                 $f = $obj->getErrorFields();
                 $answer = array('field' => $f['focus'], 'msg' => $obj->getErrorListText(' '));
             }
         }
         if (!$issetErrors) {
             // Отправка нужных писем
             page::assign('site_name', domains::curDomain()->getSiteName());
             page::assign('site_url', domains::curDomain()->getName());
             page::assign('base_email', domains::curDomain()->getEmail());
             while (list($key, $val) = each($_POST)) {
                 page::assign($key, system::checkVar($val, isText));
             }
             if (isset($obj)) {
                 $fields = $obj->getClass()->loadFields();
                 foreach ($fields as $field) {
                     if (in_array($field['f_type'], array(70, 75, 80, 85))) {
                         $fsname = $field['f_sname'];
                         $fvalue = $obj->{$fsname};
                         if ($fvalue != '') {
                             page::assign($fsname, $fvalue);
                         }
                     }
                 }
             }
             // Если указан список адресатов, отправляем письма
             if ($form_obj->mailing_list != '') {
                 $mail = new phpmailer();
                 $mail->From = $this->parse($form_obj->admin_sender_address);
                 $mail->FromName = $this->parse($form_obj->admin_sender_name);
                 /*
                                   if (!empty($this->files))
                 for($i = 0; $i < count($this->files); $i++)
                    $mail->AddAttachment($this->files[$i][0], $this->files[$i][1]);
                 */
                 $mail->AddAddress($form_obj->mailing_list);
                 $mail->WordWrap = 50;
                 $mail->IsHTML(true);
                 $mail->Subject = $this->parse($form_obj->admin_subject);
                 $mail->Body = $this->parse($form_obj->admin_template);
                 $mail->Send();
             }
             // Если нужно, отправляем уведомление пользователю
             if ($form_obj->send_notice && !$issetErrors) {
                 $mail = new phpmailer();
                 $mail->From = $this->parse($form_obj->notice_sender_address);
                 $mail->FromName = $this->parse($form_obj->notice_sender_name);
                 $mail->AddAddress(system::POST('email'));
                 $mail->WordWrap = 50;
                 $mail->IsHTML(true);
                 $mail->Subject = $this->parse($form_obj->notice_subject);
                 $mail->Body = $this->parse($form_obj->notice_template);
                 $mail->Send();
             }
             // Показываем результат
             if (system::isAjax()) {
                 if ($form_obj->msg != '') {
                     $text = $form_obj->msg;
                 } else {
                     $text = lang::get('FEEDBACK_MSG_1');
                 }
                 system::json(array('field' => 0, 'msg' => strip_tags($text)));
             } else {
                 system::redirect('/feedback/ok/' . $form_obj->id);
             }
         } else {
             // Произошли ошибки
             if (system::isAjax()) {
                 system::json($answer);
             } else {
                 system::savePostToSession();
                 system::saveErrorToSession('feedback', $answer);
                 if (empty($_POST['back_url'])) {
                     $_POST['back_url'] = '/structure/map';
                 }
                 system::redirect($_POST['back_url'], true);
             }
         }
         system::stop();
     } else {
         system::stop();
     }
 }
Exemplo n.º 2
0
 public function copy($with_child = true, $copyTo = 0)
 {
     if (!empty($this->id)) {
         $copy = new ormPage();
         $copy->setClass($this->getClass()->id());
         // Перенос данных полей
         $fields = $this->getClass()->loadFields();
         while (list($fname, $field) = each($fields)) {
             if (!empty($field['f_type']) && $field['f_type'] != 97 && $field['f_relation'] < 2 && $fname != 'pseudo_url' && $fname != 'tags') {
                 $copy->__set($fname, $this->__get($fname));
             }
         }
         if (empty($copyTo)) {
             $copy->__set('name', $this->__get('name') . lang::get('copy'));
             $copy->__set('h1', $this->__get('h1') . lang::get('copy'));
             $copy->__set('title', $this->__get('title') . lang::get('copy'));
             $copy->__set('pseudo_url', $this->__get('pseudo_url') . rand(1000, 9999));
         } else {
             $copy->__set('pseudo_url', $this->__get('pseudo_url'));
         }
         $copy->__set('template_id', $this->__get('template_id'));
         $copy->__set('template2_id', $this->__get('template2_id'));
         $copy->__set('tags', $this->__get('_tags'));
         // Устанавливаем родителя
         if (empty($copyTo)) {
             $parents = $this->getParents();
             while (list($id, $parent) = each($parents)) {
                 // $parent['position']
                 $copy->setNewParent($id);
             }
         } else {
             $copy->setNewParent($copyTo);
         }
         // Права доступа
         $rights = db::q('SELECT r_state, r_group_id FROM <<rights>> WHERE r_obj_id = "' . $this->id . '";', records);
         if (count($rights) === 1 && empty($rights[0]['r_group_id'])) {
             $copy->setRightForAll($rights[0]['r_state']);
         } else {
             while (list($key, $right) = each($rights)) {
                 $copy->setRight($right['r_group_id'], $right['r_state']);
             }
         }
         $copy->save();
         if (!$copy->issetErrors() && $with_child) {
             while ($child = $this->getChild()) {
                 $child->copy(true, $copy->id);
             }
             return true;
         } else {
             if ($copy->issetErrors()) {
                 //echo $copy->getErrorListText();
                 return false;
             }
         }
     }
 }