Exemplo n.º 1
0
 /**
  * Обработчик действия: Комментирование товара.
  */
 function AddComment()
 {
     if (empty($_REQUEST['captcha']) || md5(strtolower($_REQUEST['captcha'])) != A_Session::get('captcha')) {
         $this->errors['captcha'] = true;
         return false;
     }
     A_Session::unregister('captcha');
     $data = array();
     $data['date'] = time();
     $data['idsec'] = SECTION_ID;
     $data['iduser'] = A::$AUTH->id;
     $data['iditem'] = $this->iditem;
     $data['name'] = strip_tags($_REQUEST['name']);
     $data['bbcode'] = $_REQUEST['message'];
     $data['message'] = parse_bbcode($data['bbcode']);
     $data['active'] = A::$OPTIONS['cactive'] ? 'N' : 'Y';
     if (empty($data['name']) || empty($data['message'])) {
         return false;
     }
     if ($id = A::$DB->Insert(DOMAIN . "_comments", $data)) {
         $count = A::$DB->getCount(DOMAIN . "_comments", "idsec=" . SECTION_ID . " AND iditem={$this->iditem}");
         A::$DB->execute("UPDATE " . SECTION . "_catalog SET comments={$count} WHERE id={$this->iditem}");
         $link = shoplite_createItemLink($this->iditem, SECTION);
         if (!empty(A::$OPTIONS['cemail'])) {
             if (!empty(A::$OPTIONS['commenttpl'])) {
                 $item = A::$DB->getRowById($this->iditem, SECTION . "_catalog");
                 $item['link'] = "http://" . HOSTNAME . $link;
                 $mail = new A_Mail(A::$OPTIONS['commenttpl'], "html");
                 $mail->Assign("item", $item);
                 $mail->Assign("comment", $data);
                 $mail->send(A::$OPTIONS['cemail']);
             }
         }
         if (A::$OPTIONS['cactive']) {
             A::goUrl($link . '?newcomment=1');
         } else {
             A::goUrl($link);
         }
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Обработчик действия: Отправка сообщения.
  */
 function sendMessage()
 {
     if (empty($_REQUEST['captcha']) || md5(strtolower($_REQUEST['captcha'])) != A_Session::get('captcha')) {
         $this->errors['captcha'] = true;
         return false;
     }
     A_Session::unregister('captcha');
     $mail = new A_Mail(A::$OPTIONS['template'], "html");
     if (!empty($_REQUEST['email'])) {
         $mail->setFrom($_REQUEST['email'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : '');
     }
     $mail->Assign("data", $_REQUEST);
     $fields = array();
     A::$DB->query("SELECT * FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' ORDER BY sort");
     while ($row = A::$DB->fetchRow()) {
         if ($row['type'] == "select" || $row['type'] == "mselect") {
             $row['options'] = loadList($row['property']);
             if ($row['type'] == "mselect") {
                 $row['value'] = array();
                 $values = isset($_REQUEST[$row['field']]) ? $_REQUEST[$row['field']] : array();
                 foreach ($values as $value) {
                     $row['value'][] = isset($row['options'][$value]) ? is_array($row['options'][$value]) ? $row['options'][$value]['name'] : $row['options'][$value] : "";
                 }
                 $row['value'] = implode(", ", $row['value']);
             } else {
                 $row['value'] = isset($_REQUEST[$row['field']]) ? (int) $_REQUEST[$row['field']] : 0;
                 $row['value'] = isset($row['options'][$row['value']]) ? $row['options'][$row['value']] : "";
                 if (is_array($row['value'])) {
                     $row['data'] = $row['value'];
                     $row['value'] = !empty($row['data']['name']) ? $row['data']['name'] : "";
                 }
             }
         } elseif ($row['type'] == "file") {
             if (isset($_FILES[$row['field']]['tmp_name']) && is_file($_FILES[$row['field']]['tmp_name'])) {
                 $mail->addAttachment($_FILES[$row['field']]['tmp_name'], $_FILES[$row['field']]['name'], $_FILES[$row['field']]['type']);
             }
         } else {
             $row['value'] = isset($_REQUEST[$row['field']]) ? strip_tags($_REQUEST[$row['field']]) : "";
         }
         if ($row['type'] == "float") {
             $row['value'] = round($row['value'], 2);
         }
         $row['name'] = $row['name_' . LANG];
         $fields[$row['field']] = $row;
     }
     A::$DB->free();
     $mail->Assign("fields", $fields);
     if (isset($fields['subject'])) {
         $mail->setSubject($fields['subject']['value']);
     }
     if (isset($_REQUEST['mailto']) && isset($fields['mailto']['options'][$_REQUEST['mailto']]['email'])) {
         $mail->send($fields['mailto']['options'][$_REQUEST['mailto']]['email']);
     } elseif (!empty(A::$OPTIONS['email'])) {
         $mail->send(A::$OPTIONS['email']);
     }
     $data = array('date' => time(), 'message' => $mail->getContent(), 'data' => serialize($fields));
     if (A::$AUTH->isLogin()) {
         $data['iduser'] = A::$AUTH->id;
     }
     if ($id = A::$DB->Insert(SECTION . "_arch", $data)) {
         A_Session::set(SECTION . "_id", $id);
         A::goUrl(getSectionLink(SECTION) . "message.html");
     } else {
         return false;
     }
 }