public function test_output_for_attribute_empty_value()
 {
     $name = "output";
     $value = '';
     $actual = attributes::one($name, $value);
     $this->assertSame('output=""', $actual);
 }
 public static function tag($tagname, $attributes, $contents)
 {
     if (self::$zurb && isset($attributes['class'])) {
         $attributes['class'] = self::bootstrap_to_zurb($tagname, $attributes['class']);
     }
     if ($contents === null) {
         return "<{$tagname}" . attributes::all($attributes) . '>';
     } else {
         return "<{$tagname}" . attributes::all($attributes) . ">{$contents}</{$tagname}>";
     }
 }
示例#3
0
文件: faq.php 项目: yunsite/demila
require_once ROOT_PATH . '/apps/items/controllers/bookmark.php';
#是否免费文件
if ($item['free_file'] == 'true') {
    abr('freeFileMessage', langMessageReplace($langArray['free_file_info'], array('URL' => '/' . $languageURL . 'users/downloads/' . $item['id'])));
}
#加载其它作品
$otherItems = $itemsClass->getAll(0, 6, " `status` = 'active' AND `id` <> '" . intval($itemID) . "' AND `user_id` = '" . intval($item['user_id']) . "' ", "RAND()");
abr('otherItems', $otherItems);
if (!is_array($otherItems)) {
    abr('otherItemsCount', 0);
} else {
    abr('otherItemsCount', count($otherItems));
}
#加载属性
require_once ROOT_PATH . '/apps/attributes/models/attributes.class.php';
$attributesClass = new attributes();
$attributes = $attributesClass->getAll(0, 0, $itemsClass->attributesWhere);
abr('attributes', $attributes);
$attributeCategories = $attributesClass->getAllCategories(0, 0, $itemsClass->attributeCategoriesWhere);
abr('attributeCategories', $attributeCategories);
#加载分类
require_once ROOT_PATH . '/apps/categories/models/categories.class.php';
$categoriesClass = new categories();
$categories = $categoriesClass->getAll();
abr('categories', $categories);
#面包屑
abr('breadcrumb', '<a href="/' . $languageURL . '" title="">' . $langArray['home'] . '</a> \\ <a href="/' . $languageURL . 'items/' . $item['id'] . '" title="">' . $item['name'] . '</a> \\ <a href="/' . $languageURL . 'items/faq/' . $item['id'] . '" title="">' . $langArray['faqs'] . '</a>');
#FAQ
$faqs = $faqClass->CountAll($itemID);
abr('faqs', $faqs);
$user = $item['user'];
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     // process form
     $this->processForm();
     // if a pool is chosen, it is intanciated
     $is_one_pool = false;
     if (!(count(explode("a", $params->getParam('searchwhere'))) > 1)) {
         $pool = new pools();
         $pool->id = $params->getParam('searchwhere');
         $pool->find(true);
         $is_one_pool = true;
     }
     if (!$params->getParam('show_page')) {
         $params->addParam('show_page', 1, 'now');
     }
     // get Attributes
     $attr = new attributes();
     $attr->category_id = $params->getParam('cat');
     if ($attr->find()) {
         while ($attr->fetch()) {
             $this->attributes[] = clone $attr;
         }
     }
     // tabledata is fetched and ordered
     $tabledata = array();
     $res_fetcher = new resFetcher();
     $res_fetcher->_cat = $params->getParam('cat');
     $res_fetcher->_search_string = $params->getParam('searchstring');
     $get_add .= "&searchstring=" . $params->getParam('searchstring');
     $get_add .= "&searchwhere=" . $params->getParam('searchwhere');
     if ($is_one_pool) {
         $res_fetcher->_pools = array($pool->id);
     } else {
         $res_fetcher->_pools = explode("a", $params->getParam('searchwhere'));
     }
     // fetch users pools
     $my_pools_ids = $this->user->getPoolIDs();
     foreach ($my_pools_ids as $pool_id) {
         $userpool = new pools();
         $userpool->id = $pool_id;
         $userpool->find(true);
         $this->pools_get .= $pool_id . 'a';
         $this->pools[] = array($pool_id, $userpool->name);
     }
     if ($params->getParam('order')) {
         $res_fetcher->_order = $params->getParam('order');
     } else {
         $res_fetcher->_order = 'name';
     }
     $res_fetcher->search();
     $showres = $res_fetcher->getAsArray();
     // presets for attributes
     foreach ($this->attributes as $attr_obj) {
         if ($params->getParam('attribute' . $attr_obj->id)) {
             $this->attribute_presets[$attr_obj->id] = $params->getParam('attribute' . $attr_obj->id);
             $get_add .= "&attribute" . $attr_obj->id . "=" . $params->getParam('attribute' . $attr_obj->id);
         }
     }
     // contact and action-colums are build
     $count = 1;
     $page = $params->getParam('show_page');
     foreach ($showres as $show_res) {
         $fitsattr = true;
         foreach ($this->attributes as $attr_obj) {
             // string-type
             if ($params->getParam('attribute' . $attr_obj->id)) {
                 if ($attr_obj->type == "string") {
                     $resattr = new attributesString();
                     $resattr->attribute_id = $attr_obj->id;
                     $resattr->res_id = $show_res->id;
                     if (!$resattr->isLike($params->getParam('attribute' . $attr_obj->id))) {
                         $fitsattr = false;
                     }
                 }
                 if ($attr_obj->type == "select") {
                     $resattr = new attributesSelect();
                     $resattr->attribute_id = $attr_obj->id;
                     $resattr->res_id = $show_res->id;
                     if ($resattr->find()) {
                         $fitsattr = false;
                         while ($resattr->fetch()) {
                             $select_keys = new attributesSelectKeys();
                             $select_keys->key = $resattr->value;
                             $select_keys->find(true);
                             if (stripos($lang->getMsg('resdata_form_select_' . $select_keys->value), $params->getParam('attribute' . $attr_obj->id)) !== false) {
                                 $fitsattr = true;
                             }
                         }
                     } else {
                         $fitsattr = false;
                     }
                 }
             }
         }
         if ($fitsattr) {
             if ($count >= $page * 20 - 19 && $count <= $page * 20) {
                 $contact = "";
                 $action = "";
                 $show_res->fetchUser();
                 // if the pool is browsed or a search is shown, the *_public-variables are proofed, if another pool
                 // is browsed, all userdata ist shown. If only my pools are looked up by a search, all userdata is shown too.
                 // data in the conta	ct-column
                 // userdata is only shown, if he's in at least one of the pools
                 // the logged-in user is a member of
                 // show detalis if ressource id passed
                 $detail = $show_res->id == $params->getParam('res_id');
                 $email = $show_res->user->email;
                 $street = $show_res->user->street;
                 $house = $show_res->user->house;
                 $country = $show_res->user->country;
                 $plz = $show_res->user->plz;
                 $city = $show_res->user->city;
                 $phone = $show_res->user->phone;
                 $user_desc = $show_res->user->description;
                 // show detail: resource
                 if ($detail) {
                     // attributes for detail-article are fetched
                     $attributes = new attributes();
                     $attributes->category_id = $show_res->cat;
                     $attributes->find();
                     $res_attr_array = array();
                     while ($attributes->fetch()) {
                         // string-attributes
                         if ($attributes->type == "string") {
                             $res_attr = new attributesString();
                             $res_attr->res_id = $show_res->id;
                             $res_attr->attribute_id = $attributes->id;
                             if ($res_attr->find(true)) {
                                 $res_attr_array[] = array("value" => $res_attr->value, "name" => 'resdata_form_' . $attributes->name);
                             }
                         }
                         // select-attributes
                         if ($attributes->type == "select") {
                             $res_attr = new attributesSelect();
                             $res_attr->res_id = $show_res->id;
                             $res_attr->attribute_id = $attributes->id;
                             if ($res_attr->find()) {
                                 $value = "";
                                 while ($res_attr->fetch()) {
                                     $keys = new attributesSelectKeys();
                                     $keys->key = $res_attr->value;
                                     $keys->attribute_id = $res_attr->attribute_id;
                                     $keys->find(true);
                                     $value = $value . $lang->getMsg('resdata_form_select_' . $keys->value) . '&nbsp;';
                                 }
                                 $res_attr_array[] = array("value" => $value, "name" => 'resdata_form_' . $attributes->name);
                             }
                         }
                     }
                     if ($this->user->inMine($show_res->user->id)) {
                         if ($show_res->user->id == $this->user->id) {
                             $prove_public = 2;
                         } else {
                             $prove_public = false;
                         }
                     } else {
                         $prove_public = true;
                     }
                 } else {
                     $prove_public = false;
                 }
                 $is_waiting = new resWait();
                 $is_waiting->user_id = $this->user->id;
                 $is_waiting->res_id = $show_res->id;
                 if (strlen($show_res->name) > 60) {
                     $show_res->name = substr($show_res->name, 0, 60) . '...';
                 }
                 $act_row = array('res_id' => $show_res->id, 'name' => $show_res->name, 'description' => $show_res->description, 'type' => $show_res->type, 'resolvetype' => $this->resolveType($show_res->type), 'user_id' => $show_res->user->id, 'user_name' => $show_res->user->name, 'own_ressource' => $show_res->user->id == $this->user->id, 'available' => $show_res->isAvailable(), 'is_waiting' => $is_waiting->find(), 'prove_public' => $prove_public, 'detail' => $detail, 'user_email' => $email, 'user_street' => $street, 'user_house' => $house, 'user_country' => $country, 'user_plz' => $plz, 'user_city' => $city, 'user_phone' => $phone, 'user_user_desc' => $user_desc, 'user_email_public' => $show_res->user->email_public, 'user_phone_public' => $show_res->user->phone_public, 'user_plz_city_public' => $show_res->user->plz_city_public);
                 if ($detail) {
                     $act_row = array_merge($act_row, array('attributes' => $res_attr_array));
                     $this->resdata = $act_row;
                 }
                 $tabledata[] = $act_row;
             }
             ++$count;
         }
     }
     --$count;
     $count2 = 1;
     while ($count2 < $count / 20) {
         $this->res_count[] = $count2;
         ++$count2;
     }
     $this->res_count[] = $count2;
     $this->get_add_cat = $get_add;
     $get_add .= "&cat=" . $params->getParam('cat');
     // categories to refine search
     $showcats = $categories->getChildren($params->getParam('cat'));
     if (is_array($showcats)) {
         foreach ($showcats as $cat_id => $cat_name) {
             $show_res = new resFetcher();
             $show_res->_cat = $cat_id;
             $show_res->_search_string = $params->getParam('searchstring');
             if (!$is_one_pool) {
                 $show_res->_pools = explode("a", $params->getParam('searchwhere'));
             } else {
                 $show_res->_pools = array($pool->id);
             }
             $rescounter = $show_res->count();
             if ($rescounter > 0) {
                 $this->cats[] = array("id" => $cat_id, "name" => $cat_name, "count" => $rescounter);
             }
         }
         // order categories after rescount
         $c = 0;
         foreach ($this->cats as $cat) {
             if ($c == 0) {
                 $ocats = array($cat);
             } else {
                 $c2 = 0;
                 while ($c2 <= $c) {
                     if ($cat["count"] <= $ocats[$c2]["count"]) {
                         $before = array_slice($ocats, 0, $c2);
                         $after = array_slice($ocats, $c2);
                         if (is_array($before[0])) {
                             $ocats = array_merge($before, array($cat));
                             if (is_array($after[0])) {
                                 $ocats = array_merge($ocats, $after);
                             }
                         } else {
                             $ocats = array_merge(array($cat), $after);
                         }
                         $c2 = $c + 1;
                     } else {
                         if ($cat["count"] > $ocats[$c2]["count"] && ($cat["count"] <= $ocats[$c2 + 1]["count"] || !$ocats[$c2 + 1]["count"])) {
                             $before = array_slice($ocats, 0, $c2 + 1);
                             $after = array_slice($ocats, $c2 + 1);
                             if (is_array($after[0])) {
                                 $ocats = array_merge(array($cat), $after);
                                 if (is_array($before[0])) {
                                     $ocats = array_merge($before, $ocats);
                                 }
                             } else {
                                 $ocats = array_merge($before, array($cat));
                             }
                             $c2 = $c + 1;
                         }
                     }
                     ++$c2;
                 }
             }
             ++$c;
         }
         if (is_array($ocats)) {
             $this->cats = array_reverse($ocats);
         }
         // add subcategories to the most counting category
         $lowercats = $categories->getChildren($this->cats[0]["id"]);
         if (is_array($lowercats)) {
             foreach ($lowercats as $cat_id => $cat_name) {
                 $show_res = new resFetcher();
                 $show_res->_cat = $cat_id;
                 $show_res->_search_string = $params->getParam('searchstring');
                 if (!$is_one_pool) {
                     $show_res->_pools = explode("a", $params->getParam('searchwhere'));
                 } else {
                     $show_res->_pools = array($pool->id);
                 }
                 $rescounter = $show_res->count();
                 if ($rescounter > 0) {
                     $this->lowercats[] = array("id" => $cat_id, "name" => $cat_name, "count" => $rescounter);
                 }
             }
         }
     }
     $this->get_add = $get_add;
     // table itself
     $table = new tableResBrowser($tabledata, $get_add);
     // page-header
     $this->header = $lang->getMsg('resbrowser_header_search');
     // hierarchie-links
     $parent = $categories->getParent($params->getParam('cat'));
     if ($parent) {
         $hierarchie = array();
         $hierarchie[] = array('id' => $parent, 'name' => $categories->getName($parent));
         $parent = $categories->getParent($parent);
         if ($parent) {
             $hierarchie[] = array('id' => $parent, 'name' => $categories->getName($parent));
         }
         $this->hierarchie = array_reverse($hierarchie);
     } else {
         if ($params->getParam('cat') != 0) {
             $this->hierarchie = array(array('id' => 0, 'name' => $lang->getMsg('cat_all')));
         }
     }
     if ($this->resdata) {
         $this->hierarchie[] = array('id' => $params->getParam('cat'), 'name' => $categories->getName($params->getParam('cat')));
     }
     $this->table = $table;
     $this->pool = $pool;
 }
示例#5
0
文件: form.php 项目: yunsite/demila
if (!isset($_GET['category']) || !is_numeric($_GET['category']) || $_GET['category'] == '0') {
    $_GET['category'] = '';
}
$allCategories = $categoriesClass->getAllWithChilds(0, " `visible` = 'true' ");
if (!array_key_exists($_GET['category'], $allCategories)) {
    addErrorMessage($langArray['error_wrong_category'], '', 'error');
    abr('hideForm', 'true');
} else {
    if (!isset($_POST['category'])) {
        $_POST['category'] = 0;
    }
    $categoriesSelect = $categoriesClass->generateSelect($allCategories, $_POST['category'], $_GET['category']);
    abr('categoriesSelect', $categoriesSelect);
    #加载属性
    require_once ROOT_PATH . '/apps/attributes/models/attributes.class.php';
    $attributesClass = new attributes();
    $attributes = $attributesClass->getAllWithCategories(" `visible` = 'true' AND `categories` LIKE '%," . (int) $_GET['category'] . ",%' ");
    abr('attributes', $attributes);
    #保存作品
    if (isset($_POST['upload'])) {
        require_once ROOT_PATH . '/apps/items/models/items.class.php';
        $itemsClass = new items();
        $s = $itemsClass->add();
        if ($s === true) {
            refresh('/' . $languageURL . 'author_dashboard/', $langArray['complete_upload_item'], 'complete');
        } else {
            $message = '<ul>';
            foreach ($s as $e) {
                $message .= '<li>' . $e . '</li>';
            }
            $message .= '</ul>';
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     if ($params->getParam('res_id')) {
         $this->header = $lang->getMsg('resdata_header_change');
         $this->is_change = true;
     } else {
         $this->header = $lang->getMsg('resdata_header_new');
         $this->is_change = false;
     }
     $aItems = $categories->getThisAndBelow(1);
     $sJavaScriptArray = sprintf('new Array(%s)', implode(',', array_keys($aItems)));
     $this->sJavaScriptArray = $sJavaScriptArray;
     if ($_POST['resdata_isbn_submit'] && is_isbn($_POST['resdata_isbn'])) {
         foreach ($_POST as $key => $value) {
             if ($key != 'page' && $key != 'name' && $key != 'description' && $key != 'resdata_authors') {
                 $get .= $key . '=' . $value . '&';
             }
         }
         $this->switchPage('resdata&' . $get);
     }
     // Instantiate the HTML_QuickForm object
     $this->form = new formResData('ResDataForm', $params->getParam($res_id), $this->user);
     $this->new_res_link = false;
     // Try to validate a form
     if ($this->form->validate() && $this->form->exportValue('submit')) {
         $newres = new resources();
         if ($params->getParam('res_id')) {
             $newres->get($params->getParam('res_id'));
         }
         $newres->name = $this->form->exportValue('name');
         $newres->description = $this->form->exportValue('description');
         $newres->cat = $this->form->exportValue('resdata_cat');
         $newres->type = in_array($newres->cat, array_keys($aItems)) ? $this->form->exportValue('type') : 0;
         // insert/update in res-maintable
         if ($params->getParam('res_id')) {
             $newres->update();
         } else {
             $newres->since = time();
             $newres->user_id = $this->user->id;
             $newres->insert();
         }
         $newres->find(true);
         // insert/update in attributes-tables
         $attr_string = new attributesString();
         $attr_string->res_id = $newres->id;
         $attr_string->delete();
         $attr_select = new attributesSelect();
         $attr_select->res_id = $newres->id;
         $attr_select->delete();
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string = new attributesString();
                         $attr_string->res_id = $newres->id;
                         $attr_string->attribute_id = $attributes->id;
                         // insert
                         $value = $this->form->exportValue('resdata_' . $attributes->name);
                         if ($value != "") {
                             $attr_string->value = $value;
                             $attr_string->insert();
                         }
                     }
                     if ($attributes->type == "select") {
                         $values = $this->form->getElementValue('resdata_' . $attributes->name);
                         if (!is_array($values)) {
                             $values = array($values);
                         }
                         foreach ($values as $value) {
                             if ($value[0] != 0) {
                                 $attr_string = new attributesSelect();
                                 $attr_string->res_id = $newres->id;
                                 $attr_string->attribute_id = $attributes->id;
                                 // insert
                                 $attr_string->value = $value[0];
                                 $attr_string->insert();
                             }
                         }
                     }
                 }
             }
         }
         // add res to pools if given
         $respools = new poolsResources();
         $respools->res_id = $newres->id;
         $respools->delete();
         $res_pools = $this->form->exportValue('free_pools');
         if (is_array($res_pools)) {
             foreach ($res_pools as $pool_id => $bool) {
                 if ($bool) {
                     $newres->addPool($pool_id);
                 }
             }
         }
         if ($params->getParam('res_id')) {
             $params->addParam('msg', 'msg_data_change_success', 'page');
             $this->switchPage('resmanager&function=all');
         } else {
             $this->form->removeElement('resdata_isbn_submit');
             $this->form->freezeForm();
             $this->addMsg('msg_res_insert_success');
             $this->new_res_link = true;
         }
     }
     if ($_POST['resdata_isbn_submit']) {
         $this->form->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->form->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
 }
示例#7
0
$page_title = 'Редактирование атрибута';
$id = intval(get_request_variable('id', 0));
$attr_id = intval(get_request_variable('attr_id', 0));
$value = get_request_variable('value', '');
$save = get_request_variable('save', 0);
$_REQUEST['callback'] = get_request_variable('callback', '');
$attr = new attrs_values();
$attr->id_io_object = $id;
$attr->id_io_attribute = $attr_id;
if ($id > 0 && $attr_id > 0) {
    if (!$attr->Load()) {
        $attr->id_io_category = 0;
    }
}
$attr_desc = new attributes();
$attr_desc->id = $attr_id;
if ($attr_id > 0 && $id > 0) {
    if (!$attr_desc->Load()) {
        $attr_desc->id = 0;
    }
}
$type_attribute = $attr_desc->id_a_type;
$list_values = array();
if ($type_attribute == 2) {
    $table_name = $attr_desc->table_name;
    $column_name = $attr_desc->column_name;
    $query = 'SELECT * FROM ' . $table_name . ' ORDER BY 1;';
    $db->query($query);
    $list_values = $db->value;
}
示例#8
0
文件: delete.php 项目: yunsite/demila
<?php

// +----------------------------------------------------------------------
// | Demila [ Beautiful Digital Content Trading System ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://demila.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Email author@demila.org
// +----------------------------------------------------------------------
define('USING_LANGUAGE', false);
require_once '../../../config.php';
require_once $config['root_path'] . '/core/functions.php';
include_once $config['system_core'] . "/initEngine.php";
admin_login();
if (isset($_POST['delete']) && isset($_POST['id']) && isset($_SESSION['user']['access']['attributes'])) {
    require_once ROOT_PATH . "/apps/attributes/models/categories.class.php";
    $cms = new categories();
    $cms->delete(intval($_POST['id']));
    die(json_encode(array_merge($_POST, array('status' => 'true'))));
} elseif (isset($_POST['deleteAttr']) && isset($_POST['id']) && isset($_SESSION['user']['access']['attributes'])) {
    require_once ROOT_PATH . "/apps/attributes/models/attributes.class.php";
    $cms = new attributes();
    $cms->delete(intval($_POST['id']));
    die(json_encode(array_merge($_POST, array('status' => 'true'))));
}
echo json_encode(array_merge($_POST, array('status' => 'unknown error')));
die;
示例#9
0
文件: attr.php 项目: yunsite/demila
// +----------------------------------------------------------------------
// | Demila [ Beautiful Digital Content Trading System ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://demila.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Email author@demila.org
// +----------------------------------------------------------------------
_setView(__FILE__);
_setTitle($langArray['attributes']);
if (!isset($_GET['id']) && !is_numeric($_GET['id'])) {
    refresh("/" . $languageURL . adminURL . "/?m=" . $_GET['m'] . "&c=list");
}
$cms = new attributes();
if (isset($_GET['up']) || isset($_GET['down'])) {
    $cms->tableName = 'attributes';
    $cms->idColumn = 'id';
    $cms->orderWhere = " AND `category_id` = '" . intval($_GET['id']) . "' ";
    if (isset($_GET['up']) && is_numeric($_GET['up'])) {
        $cms->moveUp($_GET['up']);
    } elseif (isset($_GET['down']) && is_numeric($_GET['down'])) {
        $cms->moveDown($_GET['down']);
    }
}
$data = $cms->getAll(START, LIMIT, " `category_id` = '" . intval($_GET['id']) . "' ");
abr('data', $data);
$p = paging("?m=" . $_GET['m'] . "&c=attr&id=" . $_GET['id'] . "&p=", "", PAGE, LIMIT, $cms->foundRows);
abr('paging', $p);
$categoriesClass = new categories();
示例#10
0
// +----------------------------------------------------------------------
// | Demila [ Beautiful Digital Content Trading System ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://demila.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Email author@demila.org
// +----------------------------------------------------------------------
_setView(__FILE__);
_setTitle($langArray['add'] . ' ' . $langArray['attribute']);
if (!isset($_GET['id']) && !is_numeric($_GET['id'])) {
    refresh("/" . $languageURL . adminURL . "/?m=" . $_GET['m'] . "&c=list");
}
$cms = new attributes();
if (isset($_POST['add'])) {
    $_POST['category_id'] = $_GET['id'];
    $status = $cms->add();
    if ($status !== true) {
        abr('error', $status);
    } else {
        refresh("?m=" . $_GET['m'] . "&c=attr&id=" . $_GET['id'], $langArray['add_complete']);
    }
} else {
    $_POST['visible'] = 'true';
}
$categoriesClass = new categories();
$pdata = $categoriesClass->get($_GET['id']);
abr('pdata', $pdata);
require_once ROOT_PATH . '/apps/lists/leftlist_admin.php';
function eo_get_new_product($product_id, $product_qty = 1, $product_options = array(), $use_specials = true)
{
    global $db;
    $product_id = (int) $product_id;
    $product_qty = (double) $product_qty;
    $retval = array('id' => $product_id, 'qty' => $product_qty);
    $query = $db->Execute('SELECT `p`.`products_id`, `p`.`master_categories_id`, `p`.`products_status`, ' . '`pd`.`products_name`, `p`.`products_model`, `p`.`products_image`, `p`.`products_price`, ' . '`p`.`products_weight`, `p`.`products_tax_class_id`, `p`.`manufacturers_id`, ' . '`p`.`products_quantity_order_min`, `p`.`products_quantity_order_units`, ' . '`p`.`products_quantity_order_max`, `p`.`product_is_free`, `p`.`products_virtual`, ' . '`p`.`products_discount_type`, `p`.`products_discount_type_from`, ' . '`p`.`products_priced_by_attribute`, `p`.`product_is_always_free_shipping` ' . 'FROM `' . TABLE_PRODUCTS . '` AS `p`, `' . TABLE_PRODUCTS_DESCRIPTION . '` AS `pd` ' . 'WHERE `p`.`products_id`=\'' . (int) $product_id . '\' ' . 'AND `pd`.`products_id`=`p`.`products_id` ' . 'AND `pd`.`language_id`=\'' . (int) $_SESSION['languages_id'] . '\'');
    if (!$query->EOF) {
        // Handle common fields
        $retval = array_merge($retval, array('name' => $query->fields['products_name'], 'model' => $query->fields['products_model'], 'price' => $query->fields['products_price'], 'products_discount_type' => $query->fields['products_discount_type'], 'products_discount_type_from' => $query->fields['products_discount_type_from'], 'products_priced_by_attribute' => $query->fields['products_priced_by_attribute'], 'product_is_free' => $query->fields['product_is_free'], 'products_virtual' => $query->fields['products_virtual'], 'product_is_always_free_shipping' => $query->fields['product_is_always_free_shipping'], 'tax' => number_format(zen_get_tax_rate_value($query->fields['products_tax_class_id']), 4), 'tax_description' => zen_get_tax_description($query->fields['products_tax_class_id'])));
        // Handle pricing
        $special_price = zen_get_products_special_price($product_id);
        if ($use_specials && $special_price && $retval['products_priced_by_attribute'] == 0) {
            $retval['price'] = $special_price;
        } else {
            $special_price = 0;
        }
        if (zen_get_products_price_is_free($product_id)) {
            // no charge
            $retval['price'] = 0;
        }
        // adjust price for discounts when priced by attribute
        if ($retval['products_priced_by_attribute'] == '1' && zen_has_product_attributes($product_id, 'false')) {
            // reset for priced by attributes
            if ($special_price) {
                $retval['price'] = $special_price;
            } else {
                $retval['price'] = $query->fields['products_price'];
                // START MARKUP
                if (isset($GLOBALS['priceMarkup'])) {
                    $retval['price'] = $GLOBALS['priceMarkup']->calculatePrice($product_id, $query->fields['manufacturers_id'], $query->fields['master_categories_id'], $retval['price']);
                }
                // END MARKUP
            }
        } else {
            // discount qty pricing
            if ($retval['products_discount_type'] != '0') {
                $retval['price'] = zen_get_products_discount_price_qty($product_id, $retval['qty']);
            }
            // START MARKUP
            if (isset($GLOBALS['priceMarkup'])) {
                $retval['price'] = $GLOBALS['priceMarkup']->calculatePrice($product_id, $query->fields['manufacturers_id'], $query->fields['master_categories_id'], $retval['price']);
            }
            // END MARKUP
        }
        unset($special_price);
        $retval['onetime_charges'] = 0;
        $retval['final_price'] = $retval['price'];
    }
    // Handle attributes
    if (is_array($product_options) && count($product_options > 0)) {
        $retval['attributes'] = array();
        include_once DIR_WS_CLASSES . 'attributes.php';
        $attributes = new attributes();
        foreach ($product_options as $option_id => $details) {
            $attr = array();
            switch ($details['type']) {
                case PRODUCTS_OPTIONS_TYPE_TEXT:
                case PRODUCTS_OPTIONS_TYPE_FILE:
                    $attr['option_id'] = $option_id;
                    $attr['value'] = $details['value'];
                    if ($attr['value'] == '') {
                        continue 2;
                    }
                    // There should only be one text per name.....
                    $get_attr_id = $attributes->get_attributes_by_option($product_id, $option_id);
                    if (count($get_attr_id) == 1) {
                        $details['value'] = $get_attr_id[0]['products_attributes_id'];
                    }
                    unset($get_attr_id);
                    break;
                case PRODUCTS_OPTIONS_TYPE_CHECKBOX:
                    if (!array_key_exists('value', $details)) {
                        continue 2;
                    }
                    $tmp_id = array_shift($details['value']);
                    foreach ($details['value'] as $attribute_id) {
                        // We only get here if more than one checkbox per
                        // option was selected.
                        $tmp = $attributes->get_attribute_by_id($attribute_id, 'order');
                        $retval['attributes'][] = $tmp;
                        // Handle pricing
                        $prices = eo_get_product_attribute_prices($attribute_id, $tmp['value'], $product_qty);
                        unset($tmp);
                        if (!$query->EOF) {
                            $retval['onetime_charges'] += $prices['onetime_charges'];
                            $retval['final_price'] += $prices['price'];
                        }
                    }
                    $details['value'] = $tmp_id;
                    $attr = $attributes->get_attribute_by_id($details['value'], 'order');
                    unset($attribute_id);
                    unset($attribute_value);
                    unset($tmp_id);
                    break;
                default:
                    $attr = $attributes->get_attribute_by_id($details['value'], 'order');
            }
            $retval['attributes'][] = $attr;
            if (!$query->EOF) {
                // Handle pricing
                $prices = eo_get_product_attribute_prices($details['value'], $attr['value'], $product_qty);
                $retval['onetime_charges'] += $prices['onetime_charges'];
                $retval['final_price'] += $prices['price'];
            }
        }
        unset($query, $attr, $prices, $option_id, $details);
    }
    return $retval;
}
 function formResData($name, $res_id = 0, $user)
 {
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $cats = services::getService('cats');
     $this->form($name);
     if ($params->getParam('res_id')) {
         $this->addElement('hidden', 'res_id', $params->getParam('res_id'));
         // Categories
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change(this.value, document.ResDataForm.res_id.value)'));
     } else {
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change_new(this.value)'));
     }
     $this->addElement('text', 'name', $lang->getMsg('resdata_form_name'), array('size' => 40, 'maxlength' => 255));
     $this->addElement('textarea', 'description', $lang->getMsg('resdata_form_description'), array('rows' => 7, 'cols' => 40));
     // fetch additional attributes e.g. form-fields for chosen category
     if ($params->getParam('cat')) {
         $cat = $params->getParam('cat');
         $this->addElement('hidden', 'cat', $cat);
         $attributes = new attributes();
         $attributes->category_id = $cat;
         if ($attributes->find()) {
             while ($attributes->fetch()) {
                 if ($attributes->type == "string") {
                     if ($attributes->name == "isbn") {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                         $this->addElement('submit', 'resdata_' . $attributes->name . '_submit', $lang->getMsg('resdata_form_' . $attributes->name . '_submit'), "asd");
                     } else {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                     }
                 }
                 if ($attributes->type == "select") {
                     $keys = new attributesSelectKeys();
                     $keys->attribute_id = $attributes->id;
                     $keys->find();
                     $options = array();
                     $options[0] = "----";
                     while ($keys->fetch()) {
                         $options[$keys->key] = $lang->getMsg('resdata_form_select_' . $keys->value);
                     }
                     sort($options);
                     $select_elements = array();
                     for ($i = 1; $attributes->amount >= $i; ++$i) {
                         $select_elements[] =& HTML_QuickForm::createElement('select', $i, null, $options);
                     }
                     $this->addGroup($select_elements, 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), ' ');
                 }
             }
         }
     }
     $this->addElement('select', 'type', $lang->getMsg('resdata_form_type'), array("2" => $lang->getMsg('resdata_form_type_borrow'), "1" => $lang->getMsg('resdata_form_type_give')));
     $free_pool = new poolsUser();
     $free_pool->user_id = $user->id;
     $free_pool->wait = 0;
     $free_pool->find();
     $free_pools = array();
     while ($free_pool->fetch()) {
         $free_pool->fetchPool();
         $free_pools[] =& HTML_QuickForm::createElement('checkbox', $free_pool->pool->id, null, ' ' . $free_pool->pool->name, $free_pool->pool->id);
     }
     $this->addGroup($free_pools, 'free_pools', $lang->getMsg('resdata_form_pools'), '<br>');
     $this->addElement('submit', 'submit', $lang->getMsg('resdata_form_submit'));
     // rules
     if (!$_POST['resdata_isbn_submit']) {
         $this->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
     // presets
     if ($params->getParam('resdata_isbn_submit') && is_isbn($params->getParam('resdata_isbn'))) {
         $lastletter = 0;
         $isbnfound = 0;
         $firstletter = substr($params->getParam('resdata_isbn'), 0, 1);
         if ($firstletter == 0 || $firstletter == 1) {
             $urlendings = array('com', 'co.uk', 'de', 'jp', 'fr', 'ca');
         } else {
             if ($firstletter == 2) {
                 $urlendings = array('fr', 'de', 'com', 'co.uk', 'jp', 'ca');
             } else {
                 if ($firstletter == 3) {
                     $urlendings = array('de', 'com', 'co.uk', 'jp', 'fr', 'ca');
                 } else {
                     if ($firstletter == 4) {
                         $urlendings = array('jp', 'de', 'com', 'co.uk', 'fr', 'ca');
                     } else {
                         $urlendings = array('com', 'co.uk', 'de', 'fr', 'ca', 'jp');
                     }
                 }
             }
         }
         $lastletters = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'x');
         foreach ($urlendings as $urlending) {
             foreach ($lastletters as $lastletter) {
                 if ($isbnfound == 0) {
                     $url = "http://ecs.amazonaws." . $urlending . "/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=1WFW5KS6EFZ0M8690ZR2&Operation=ItemLookup&ItemId=" . substr($params->getParam('resdata_isbn'), 0, 9) . $lastletter . "&ResponseGroup=Medium&type=lite&f=xml";
                     $xml = file_get_contents($url);
                     if (!strpos($xml, 'is not a valid value for ItemId')) {
                         $isbnfound = true;
                     }
                 }
             }
         }
         $first = strpos($xml, '<Item>') + 6;
         $sec = strpos($xml, '</Item>');
         $newxml = substr($xml, $first, $sec - $first);
         $newxml = unhtmlentities($newxml);
         // title
         $first = strpos($newxml, '<Title>') + 7;
         $sec = strpos($newxml, '</Title>');
         $title = substr($newxml, $first, $sec - $first);
         // binding
         $first = strpos($newxml, '<Binding>') + 9;
         $sec = strpos($newxml, '</Binding>');
         $binding = substr($newxml, $first, $sec - $first);
         // publisher
         $first = strpos($newxml, '<Label>') + 7;
         $sec = strpos($newxml, '</Label>');
         $publisher = substr($newxml, $first, $sec - $first);
         // publication date
         $first = strpos($newxml, '<PublicationDate>') + 17;
         $sec = strpos($newxml, '</PublicationDate>');
         $publicationdate = substr($newxml, $first, $sec - $first);
         // number of pages
         $first = strpos($newxml, '<NumberOfPages>') + 15;
         $sec = strpos($newxml, '</NumberOfPages>');
         $numberofpages = substr($newxml, $first, $sec - $first);
         // author(s)
         $authors = array();
         while (strstr($newxml, '<Author>')) {
             $first = strpos($newxml, '<Author>') + 8;
             $sec = strpos($newxml, '</Author>');
             $authors[] = substr($newxml, $first, $sec - $first);
             $newxml = substr($newxml, $sec + 9);
         }
         foreach ($authors as $key => $author) {
             if ($key != 0) {
                 $authors_field .= "; ";
             }
             $authors_field .= $this->changeAuthor($author);
         }
         // description
         $first = strpos($newxml, '<EditorialReviews><EditorialReview><Source>Aus der Amazon.de-Redaktion</Source><Content>') + 88;
         $sec = strpos($newxml, '</Content></EditorialReview></EditorialReviews>');
         $description = substr($newxml, $first, $sec - $first);
         $description = substr($description, 0, strrpos($description, '--'));
         // name
         if ($authors_field) {
             $name = $authors_field . ": " . $title;
         } else {
             $name = $title;
         }
         $this->setDefaults(array('resdata_title' => $title, 'name' => $name, 'description' => $description, 'resdata_authors' => $authors_field, 'resdata_binding' => $binding, 'resdata_number_of_pages' => $numberofpages, 'resdata_publication_date' => $publicationdate, 'resdata_publisher' => $publisher, 'resdata_isbn' => $params->getParam('resdata_isbn')));
     }
     if ($params->getParam('res_id')) {
         $free_pool = new poolsResources();
         $free_pool->res_id = $params->getParam('res_id');
         $free_pool->find();
         $free_pools_presets = array();
         while ($free_pool->fetch()) {
             $free_pools_presets[$free_pool->pool_id] = 1;
         }
         $changeform_res = new resources();
         $changeform_res->get($params->getParam('res_id'));
         $this->setDefaults(array('name' => $changeform_res->name, 'type' => $changeform_res->type, 'description' => $changeform_res->description, 'resdata_cat' => $changeform_res->cat, 'free_pools' => $free_pools_presets, 'public' => $changeform_res->is_public));
         // presets for additional fields
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $this->setDefaults(array('resdata_cat' => $cat));
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string_presets = new attributesString();
                         $attr_string_presets->res_id = $params->getParam('res_id');
                         $attr_string_presets->attribute_id = $attributes->id;
                         $attr_string_presets->find(true);
                         $this->setDefaults(array('resdata_' . $attributes->name => $attr_string_presets->value));
                     }
                     if ($attributes->type == "select") {
                         $attr_select_presets = new attributesSelect();
                         $attr_select_presets->res_id = $params->getParam('res_id');
                         $attr_select_presets->attribute_id = $attributes->id;
                         $attr_select_presets->find();
                         $i = 1;
                         while ($attr_select_presets->fetch()) {
                             $this->setDefaults(array("resdata_" . $attributes->name . "[" . $i . "]" => $attr_select_presets->value));
                             ++$i;
                         }
                     }
                 }
             }
         }
     } else {
         if (isset($pool)) {
             $free_pools_presets[$pool->id] = 1;
             $this->setDefaults(array('type' => 2, 'public' => 0, 'free_pools' => $free_pools_presets));
         }
     }
     if ($params->getParam('cat')) {
         $this->setDefaults(array('resdata_cat' => $params->getParam('cat')));
     }
 }
示例#13
0
文件: edit.php 项目: yunsite/demila
}
//路径
$item["thumbnail"] = DATA_SERVER . '/uploads/items/' . $itemID . '/' . $item["thumbnail"];
$item["theme_preview"] = DATA_SERVER . '/uploads/items/' . $itemID . '/' . $item["theme_preview"];
$item["main_file"] = DATA_SERVER . '/uploads/items/' . $itemID . '/' . $item["main_file"];
//获取所有预览图
$item['preview'] = $itemsClass->get_theme_preview($itemID);
abr('item', $item);
#加载分类
require_once ROOT_PATH . '/apps/categories/models/categories.class.php';
$categoriesClass = new categories();
$categories = $categoriesClass->getAll();
abr('categories', $categories);
#加载属性
require_once ROOT_PATH . '/apps/attributes/models/attributes.class.php';
$attributesClass = new attributes();
$first_category = 0;
foreach ($item['categories'] as $cat) {
    if (is_array($cat)) {
        foreach ($cat as $c) {
            if ($c) {
                $first_category = $c;
                break;
            }
        }
    } else {
        if ($cat) {
            $first_category = $cat;
            break;
        }
    }
示例#14
0
// | Demila [ Beautiful Digital Content Trading System ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://demila.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Email author@demila.org
// +----------------------------------------------------------------------
_setView(ROOT_PATH . "apps/" . $_GET['m'] . "/admin/addAttr.php");
_setTitle($langArray['edit'] . ' ' . $langArray['attribute']);
if (!isset($_GET['id']) && !is_numeric($_GET['id'])) {
    refresh("/" . $languageURL . adminURL . "/?m=" . $_GET['m'] . "&c=list", 'INVALID ID', 'error');
}
if (!isset($_GET['fid']) || !is_numeric($_GET['fid'])) {
    refresh('?m=' . $_GET['m'] . '&c=files&id=' . $_GET['id'], 'INVALID ID', 'error');
}
$cms = new attributes();
if (isset($_POST['edit'])) {
    $status = $cms->edit($_GET['fid']);
    if ($status !== true) {
        abr('error', $status);
    } else {
        refresh("?m=" . $_GET['m'] . "&c=attr&id=" . $_GET['id'], $langArray['edit_complete']);
    }
} else {
    $_POST = $cms->get($_GET['fid']);
}
$categoriesClass = new categories();
$pdata = $categoriesClass->get($_GET['id']);
abr('pdata', $pdata);
require_once ROOT_PATH . '/apps/lists/leftlist_admin.php';
     //add new attributes
     foreach ($new_attributes as $group => $attributes) {
         $tmp_string .= "&group_" . $group . "_new_attributes=" . $attributes;
     }
     $_SESSION["error"]["form"]["attributes_customer"] = "failed";
     header("Location: ../index.php?page=customers/attributes.php&id_customer=" . $obj_customer->id . "&new_groups=" . $data["new_groups"] . $tmp_string);
     exit(0);
 }
 /*
  * 	Add/ delete attributes and groups from database
  */
 $sql_obj = new sql_query();
 $sql_obj->trans_begin();
 // update records
 foreach ($data["attributes"] as $attribute) {
     $obj_attribute = new attributes();
     $obj_attribute->load_data();
     $obj_attribute->id = $attribute["id"];
     //if attribute is to be deleted, call delete action
     if (isset($attribute["mode"]) && $attribute["mode"] == "delete") {
         $obj_attribute->action_delete();
     } elseif (empty($attribute["mode"])) {
         $obj_attribute->id_owner = $obj_customer->id;
         $obj_attribute->type = "customer";
         $obj_attribute->id_group = $attribute["id_group"];
         $obj_attribute->data["key"] = $attribute["key"];
         $obj_attribute->data["value"] = $attribute["value"];
         //if id doesn't exist, create new
         if (!$obj_attribute->verify_id()) {
             $obj_attribute->action_create();
         } elseif ($obj_attribute->data["value"] != $attribute["value"] || $obj_attribute->data["key"] != $attribute["key"] || isset($attribute["id_group"]) && $obj_attribute->data["id_group"] != $attribute["id_group"]) {
示例#16
0
 public function delete($id)
 {
     global $mysql;
     require_once ROOT_PATH . '/apps/attributes/models/attributes.class.php';
     $attributesClass = new attributes();
     $attributes = $attributesClass->getAll(0, 0, " `category_id` = '" . intval($id) . "' ");
     if (is_array($attributes)) {
         foreach ($attributes as $a) {
             $attributesClass->delete($a['id']);
         }
     }
     $mysql->query("\n\t\t\tDELETE FROM `attributes_categories`\n\t\t\tWHERE `id` = '" . intval($id) . "'\n\t\t", __FUNCTION__);
     return true;
 }