Example #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();
     }
 }
Example #2
0
    public function upd()
    {
        // Проверяем наличие шаблонов
        $templs = templates::getByDestination(0, true);
        if (empty($templs)) {
            ui::MessageBox(lang::get('STRUCTURE_TEMPL_NOT_FOUND'), lang::get('STRUCTURE_TEMPL_NOT_FOUND2'));
            system::redirect('/structure/settings#tabs-page_tpl');
        }
        // Указываем для какого объекта строить форму
        if (system::action() == "upd") {
            // Изменение страницы
            if (system::url(2) == 0) {
                system::redirect('/structure/settings');
            }
            $obj = ormPages::get(system::url(2));
            if ($obj instanceof ormPage) {
                $parent_id = $obj->getParentId();
                ui::setHeader($obj->name);
                ui::setNaviBar(lang::get('TEXT_EDIT') . $obj->getClass()->getPadej(1));
            }
            $class_list = '';
            $right = 'page_proc_upd';
        } else {
            if (system::action() == "add") {
                // Добавление страницы
                $class_name = system::issetUrl(3) ? system::url(3) : ormPages::getPopularClass(system::url(2));
                if (!($class = ormClasses::get($class_name))) {
                    system::redirect('/structure/tree');
                }
                if (in_array($class->id(), reg::getList(ormPages::getPrefix() . '/no_edit'))) {
                    system::redirect('/structure/tree');
                }
                if (system::issetUrl(2) && system::url(2) != 0) {
                    $parent = ormPages::get(system::url(2));
                    ui::setNaviBar($parent->name, '/structure/list/' . $parent->id);
                }
                ui::setHeader(lang::get('TEXT_ADD') . $class->getPadej(1));
                // Если это добавление нового объекта
                $obj = new ormPage();
                $obj->setParent(system::url(2));
                $obj->setClass($class_name);
                $obj->view_in_menu = 1;
                $obj->view_submenu = 1;
                $obj->active = 1;
                $obj->in_search = 1;
                $obj->in_index = 1;
                $obj->publ_date = date('d.m.Y H:i:s');
                // Наследуем параметры от родителя
                // Шаблоны
                $parent_id = $obj->issetParents() ? $obj->getParentId() : 0;
                $templ = templates::getPopularForSection($parent_id);
                $def_templ_1 = $obj->getClass()->getDefTemplate(0);
                $def_templ_2 = $obj->getClass()->getDefTemplate(1);
                $obj->template_id = $def_templ_1 != 0 ? $def_templ_1 : $templ[0];
                $obj->template2_id = $def_templ_2 != 0 ? $def_templ_2 : $templ[1];
                $parent_id = system::url(2);
                // Количество элементов на странице
                $this->getPopularValue($obj, 'number_of_items', 10);
                // Способ сортировки
                $this->getPopularValue($obj, 'order_by', '');
                // Формируем список классов для быстрого изменения класса объекта
                $types = ormClasses::get('section')->getAllInheritors();
                $no_edit = reg::getList(ormPages::getPrefix() . '/no_edit');
                $elem_list = $cat_list = '';
                while (list($id, $name) = each($types)) {
                    if (!in_array($id, $no_edit)) {
                        $bc = ormClasses::get($id);
                        $pach = '/css_mpanel/tree/images/';
                        $ico = 'classes/' . $bc->getSName() . '.png';
                        if (!file_exists(ROOT_DIR . $pach . $ico)) {
                            $ico = 'file1.gif';
                        }
                        if ($bc->isInheritor('category') || $bc->getSName() == 'section') {
                            $cat_list .= '
				    	<li><img src="' . $pach . $ico . '">
				    	<a href="' . system::au() . '/structure/page_add/' . $parent_id . '/' . $bc->getSName() . '">' . $bc->getName() . '</a></li>';
                        } else {
                            $elem_list .= '
				    	<li ><img src="' . $pach . $ico . '">
				    	<a href="' . system::au() . '/structure/page_add/' . $parent_id . '/' . $bc->getSName() . '">' . $bc->getName() . '</a></li>';
                        }
                    }
                }
                $class_list = '<ul>' . $cat_list . '</ul><ul>' . $elem_list . '</ul>';
                $right = 'page_proc_add';
            }
        }
        page::assign('right', $right);
        // Если произошли ошибки, перенаправляем на главную страницу модуля
        if (!$obj instanceof ormPage || $obj->issetErrors()) {
            system::redirect('/structure/tree');
        }
        // Устанавливаем кнопки для формы
        if (isset($_SESSION['STRUCTURE_LIST_FLAG']) && $_SESSION['STRUCTURE_LIST_FLAG']) {
            ui::setCancelButton('/structure/list/' . $parent_id);
        } else {
            ui::setCancelButton('/structure/tree');
        }
        if ($obj->isEditable()) {
            ui::newButton(lang::get('BTN_SAVE'), "javascript:sendForm('save');");
            ui::newButton(lang::get('BTN_APPLY'), "javascript:sendForm('apply');");
        }
        // Создаем форму и выводим ее на страницу
        $form = new ormEditForm($obj, $right);
        $form->setORMList($class_list);
        $form->addPadding('param', 9, 1);
        // Выбор шаблона оформления страниц
        $form->addField('param', 10, '', lang::get('STRUCTURE_TEMPLATE'), $this->getTemplateBox('template_id', $templs, $obj->template_id));
        // Выбор шаблона оформления объектов
        $form->addField('param', 11, '', lang::get('STRUCTURE_TEMPLATE2'), $this->getTemplateBox('template2_id', templates::getByDestination(1, true), $obj->template2_id, 1));
        // Выводим ID и URL страницы
        $this->getPageInfo($obj, $form);
        $form->newTabs(lang::get('STRUCTURE_TABS_RIGHT'), rights::getListForObject($obj, system::action()));
        //$form->newTabs(lang::get('STRUCTURE_TABS_RESTORE'), '&nbsp;');
        return $form->getHTML();
    }