Esempio n. 1
0
 /**
  * Обработчик действия: Комментирование альбома.
  */
 function AddComment()
 {
     if (!getAccess("comment")) {
         return false;
     }
     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->idalb;
     $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->idalb}");
         A::$DB->execute("UPDATE " . SECTION . "_albums SET comments={$count} WHERE id={$this->idalb}");
         $link = gallery_createItemLink($this->idalb, SECTION);
         if (!empty(A::$OPTIONS['cemail'])) {
             if (!empty(A::$OPTIONS['commenttpl'])) {
                 $item = A::$DB->getRowById($this->idalb, SECTION . "_albums");
                 $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;
     }
 }
Esempio n. 2
0
 /**
  * Формирование данных доступных в шаблоне страницы категории.
  */
 function CategoryPage()
 {
     $this->supportCached();
     $this->addCacheParam_Get('page');
     if (A::$OPTIONS['usetags']) {
         $this->category['tags'] = A_SearchEngine::getInstance()->convertTags($this->category['tags']);
     }
     $this->category = A::$OBSERVER->Modifier('fcategory_prepareValues', SECTION, $this->category);
     $this->Assign("category", $this->category);
     if (isset($_GET['filterdel']) && isset($_GET['namedel'])) {
         $fdel = $_GET['filterdel'];
         $ndel = $_GET['namedel'];
         $ar = A_Session::get(SECTION . "_filters");
         foreach ($ar[$fdel] as $key => $value) {
             if ($value == $ndel) {
                 unset($ar[$fdel][$key]);
             }
         }
         A_Session::set(SECTION . '_filters', $ar);
     }
     if ($_GET['filters'] == "no") {
         A_Session::unregister(SECTION . "_filters");
     }
     $idcat = $this->category['id'];
     // new
     $child_cat = A::$DB->getAll("SELECT id FROM " . SECTION . "_categories WHERE idker='{$idcat}'");
     $add_query = '';
     if ($child_cat) {
         foreach ($child_cat as $child_id) {
             $child_ = $child_id['id'];
             $add_query = $add_query . " OR idcat='{$child_}'";
         }
     }
     // END new
     $test = A::$DB->getAll("SELECT id FROM " . SECTION . "_catalog WHERE idcat='{$idcat}'" . $add_query);
     if ($test) {
         foreach ($this->category['fields'] as $key => $value) {
             if ($value['field'] != 'cat') {
                 $q = array();
                 if (strlen($value['value']) == 4) {
                     $k = $value['field'];
                     $all = A::$DB->getAll("SELECT " . $k . " FROM " . SECTION . "_catalog WHERE idcat='{$idcat}'" . $add_query . " group by " . $k);
                     foreach ($all as $v) {
                         if ($v[$k] != "") {
                             $q['value'][] = $v[$k];
                         }
                     }
                     $q['name'] = $value['name'];
                     $q['id'] = $k;
                     $qq[] = $q;
                 }
             }
         }
     }
     $this->Assign("filters", $qq);
     if (isset($_GET['fvalue']) && isset($_GET['fname'])) {
         $ar = A_Session::get(SECTION . "_filters");
         $fieldname = $_GET['fname'];
         $ar[$fieldname][] = $_GET['fvalue'];
         $ar[$fieldname] = array_unique($ar[$fieldname]);
         A_Session::set(SECTION . '_filters', $ar);
     }
     if (A_Session::get(SECTION . "_filters")) {
         $myfilter = '';
         $ar = A_Session::get(SECTION . "_filters");
         foreach ($ar as $key => $value) {
             if (is_array($value)) {
                 $f = false;
                 foreach ($value as $k => $v) {
                     if ($f != true) {
                         $myfilter .= " AND " . $key . " = '" . $v . "'";
                         $f = true;
                         $filterOn[] = $v;
                     } else {
                         $myfilter .= " OR " . $key . " = '" . $v . "'";
                         $filterOn[] = $v;
                     }
                 }
             } else {
                 $myfilter .= " AND " . $key . " = '" . $value . "'";
             }
         }
     }
     $this->Assign("filterOn", $filterOn);
     $categories = array();
     A::$DB->query("SELECT * FROM " . SECTION . "_categories WHERE idker={$this->idcat} AND active='Y' ORDER BY sort");
     while ($row = A::$DB->fetchRow()) {
         $row['link'] = shoplite_createCategoryLink($row['id'], SECTION);
         $row['subcategories'] = array();
         A::$DB->query("SELECT * FROM " . SECTION . "_categories WHERE idker={$row['id']} AND active='Y' ORDER BY sort");
         while ($subrow = A::$DB->fetchRow()) {
             $subrow['link'] = shoplite_createCategoryLink($subrow['id'], SECTION);
             $row['subcategories'][] = $subrow;
         }
         A::$DB->free();
         $categories[] = $row;
     }
     A::$DB->free();
     $this->Assign("categories", $categories);
     if (!empty($_REQUEST['sort'])) {
         A_Session::set(SECTION . '_csort', $_REQUEST['sort']);
     }
     if (!empty($_REQUEST['rows'])) {
         A_Session::set(SECTION . '_crows', $_REQUEST['rows']);
     }
     $sort = escape_order_string(A_Session::get(SECTION . '_csort', !empty(A::$OPTIONS['mysort']) ? A::$OPTIONS['mysort'] : A::$OPTIONS['sort']));
     $rows = (int) A_Session::get(SECTION . '_crows', A::$OPTIONS['crows']);
     $this->Assign("rows", $rows);
     $this->Assign("sort", $sort);
     if (A::$OPTIONS['childview']) {
         $childcats = $this->childCategories($this->idcat);
         $where = "(idcat IN(" . implode(",", $childcats) . ") OR idcat1 IN(" . implode(",", $childcats) . ") OR idcat2 IN(" . implode(",", $childcats) . ")) AND active='Y'";
     } else {
         $where = "(idcat={$this->idcat} OR idcat1={$this->idcat} OR idcat2={$this->idcat}) AND active='Y'";
     }
     $fields = array('name' => 'string', 'content' => 'string', 'tags' => 'string', 'art' => 'string', 'date' => 'int', 'price' => 'int', 'favorite' => 'bool', 'new' => 'bool');
     $where = $this->frontfilter($where, $fields);
     $items = array();
     $pager = new A_Pager($rows);
     $pager->query("SELECT *,svote/cvote AS vote FROM " . SECTION . "_catalog WHERE {$where} " . $myfilter . " ORDER BY {$sort}");
     if ($pager->allcount < 1) {
         A_Session::unregister(SECTION . "_filters");
         $pager->query("SELECT *,svote/cvote AS vote FROM " . SECTION . "_catalog WHERE {$where} ORDER BY {$sort}");
     }
     while ($row = $pager->fetchRow()) {
         $row['link'] = shoplite_createItemLink($row['id'], SECTION);
         $row['tobasketlink'] = getSectionLink(SECTION) . "?action=addbasket&id=" . $row['id'];
         $row['tocomparelink'] = getSectionLink(SECTION) . "?action=addcompare&id=" . $row['id'];
         $row['category'] = getTreePath(SECTION . "_categories", $row['idcat']);
         $row['vote'] = round($row['vote'], 2);
         $row['available'] = $row['iscount'] > 0;
         if (A::$OPTIONS['useimages']) {
             $row['images'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_images WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $row['id']));
             $row['idimg'] = isset($row['images'][0]['id']) ? $row['images'][0]['id'] : 0;
         }
         if (A::$OPTIONS['usefiles']) {
             $row['files'] = A::$DB->getAll("SELECT * FROM " . DOMAIN . "_files WHERE idsec=? AND iditem=? ORDER BY sort", array(SECTION_ID, $row['id']));
             foreach ($row['files'] as $i => $data) {
                 $row['files'][$i]['link'] = (LANG == DEFAULTLANG ? "" : "/" . LANG) . "/getfile/" . $data['id'] . "/" . $data['name'];
                 $row['files'][$i]['size'] = sizestring($data['size']);
             }
             $row['idfile'] = isset($row['files'][0]['id']) ? $row['files'][0]['id'] : 0;
         }
         if (A::$OPTIONS['modprices']) {
             $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array();
             $row['mprices'] = array();
             foreach ($mprices as $i => $mp) {
                 $row['mprices'][] = array('id' => $i, 'name' => $mp['name'], 'price' => $mp['price']);
             }
         }
         if (A::$OPTIONS['usetags']) {
             $row['tags'] = A_SearchEngine::getInstance()->convertTags($row['tags']);
         }
         prepareValues(SECTION, $row);
         $row = A::$OBSERVER->Modifier('shoplite_prepareValues', SECTION, $row);
         $items[] = $row;
     }
     $this->Assign("items", $items);
     $this->Assign("items_pager", $pager);
     $this->AddNavigation(SECTION_NAME, getSectionLink(SECTION));
     $this->AddNavCategories($this->category['idker']);
     $this->AddNavigation($this->category['name']);
     $this->title = $this->category['name'] . (!empty($this->title) ? " - " . $this->title : "");
     $this->description = $this->category['description'];
 }
Esempio n. 3
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;
     }
 }