コード例 #1
0
ファイル: frontend.php プロジェクト: Acsac/CMS-RuDi
function catalog(){

    $inCore = cmsCore::getInstance();
    $inPage = cmsPage::getInstance();
    $inDB   = cmsDatabase::getInstance();
    $inUser = cmsUser::getInstance();

    global $_LANG;

    $model = new cms_model_catalog();

    define('IS_BILLING', $inCore->isComponentInstalled('billing'));
    if (IS_BILLING) { cmsCore::loadClass('billing'); }

    $pagetitle = $inCore->getComponentTitle();

	$inPage->addPathway($pagetitle, '/catalog');
	$inPage->setTitle($pagetitle);

	$inPage->setDescription($model->config['meta_desc'] ? $model->config['meta_desc'] : $pagetitle);
    $inPage->setKeywords($model->config['meta_keys'] ? $model->config['meta_keys'] : $pagetitle);

    $cfg = $inCore->loadComponentConfig('catalog');

    if (cmsCore::inRequest('cat_id')){
        $id = cmsCore::request('cat_id', 'int', 0);
    } else {
        $id = cmsCore::request('id', 'int', 0);
    }

    $do = $inCore->do;

    cmsCore::includeFile('components/catalog/includes/shopcore.php');

    //////////////////////////// RATING SUBMISSION ///////////////////////////////////////////////////////////////////
    if (cmsCore::inRequest('rating')){
        $points     = cmsCore::request('points', 'int', 0);
        $item_id    = cmsCore::request('item_id', 'int', 0);
        $ip         = $inUser->ip;
        if (!alreadyVoted($item_id)){
            $inDB->query("INSERT INTO cms_uc_ratings (item_id, points, ip) VALUES ($item_id, $points, '$ip')") ;
            $inDB->query("DELETE FROM cms_uc_ratings WHERE item_id = $item_id AND ip = '0.0.0.0'") ;
        }
    }

    //////////////////////////// SEARCH BY TAG ///////////////////////////////////////////////////////////////////////
    if ($do == 'tag') {

		$tag = $inCore->strClear(urldecode($inCore->request('tag', 'html', '')));

        $sql = "SELECT tag FROM cms_tags WHERE tag = '$tag' AND target='catalog' LIMIT 1";
        $result = $inDB->query($sql) ;
        if ($inDB->num_rows($result)==1){
            $item = $inDB->fetch_assoc($result);
            $query = $inCore->strClear($item['tag']);
            $findsql = "SELECT *
                        FROM cms_uc_items
                        WHERE category_id = '$id' AND published = 1 AND tags LIKE '%$query%'";
            $do = 'cat';
        } else { echo $_LANG['NO_MATCHING_FOUND']; }

    }
    //////////////////////////// ADVANCED SEARCH ////////////////////////////////////////////////////////////////////
    if ($do == 'search') {

        if (cmsCore::inRequest('gosearch')){

            $fdata = cmsCore::request('fdata', 'array', array());
            $query = cmsCore::strClear(implode('%', $fdata));
            $title = cmsCore::request('title', 'str', '');
            $tags  = cmsCore::request('tags', 'str', '');

            if ($query || $title || $tags){

                $findsql = "SELECT i.* , IFNULL(AVG(r.points),0) AS rating
                            FROM cms_uc_items i
                            LEFT JOIN cms_uc_ratings r ON r.item_id = i.id
                            WHERE i.published = 1 AND i.category_id = '$id' ";

                if($query){
                    $findsql .= " AND i.fieldsdata LIKE '%{$query}%' ";
                }
                if($title){
                    $findsql .= " AND i.title LIKE '%$title%' ";
                }
                if($tags){
                    $findsql .= "AND (i.tags LIKE '%".$tags."%')";
                }

                $findsql .=	" GROUP BY i.id";
                $advsearch = 1;
            }
            $do = 'cat';
        } else {
            //show search form
            $sql = "SELECT * FROM cms_uc_cats WHERE id = '$id'";
            $result = $inDB->query($sql) ;

            if ($inDB->num_rows($result)==1){
                $cat = $inDB->fetch_assoc($result);
                $fstruct = cmsCore::yamlToArray($cat['fieldsstruct']);

                //heading
                $inPage->addPathway($cat['title'], '/catalog/'.$cat['id']);
                $inPage->addPathway($_LANG['SEARCH'], '/catalog/'.$cat['id'].'/search.html');
                $inPage->setTitle($_LANG['SEARCH_IN_CAT']);

                $inPage->addHeadJS('components/catalog/js/search.js');

                $fstruct_ready = array();
                foreach($fstruct as $key=>$value) {
                    if (mb_strstr($value, '/~h~/')) { $ftype = 'html'; $value=str_replace('/~h~/', '', $value); }
                    elseif (mb_strstr($value, '/~l~/')) { $ftype = 'link'; $value=str_replace('/~l~/', '', $value); } else { $ftype='text'; }
                    if (mb_strstr($value, '/~m~/')) {
                        $value = str_replace('/~m~/', '', $value);
                    }
                    $fstruct_ready[stripslashes($key)] = stripslashes($value);
                }

                //searchform
                cmsPage::initTemplate('components', 'com_catalog_search')->
                        assign('id', $id)->
                        assign('cat', $cat)->
                        assign('fstruct', $fstruct_ready)->
                        display('com_catalog_search.tpl');

            } else { cmsCore::error404(); }
        }//search form

    }
    //////////////////////////// SEARCH BY FIRST LETTER OF TITLE ///////////////////////////////////////////////////////
    if ($do == 'findfirst') {

        $id = cmsCore::request('cat_id', 'int');

		$query = mb_substr(cmsCore::strClear(urldecode(cmsCore::request('text', 'html', ''))), 0, 1);

        $findsql = "SELECT i.* , IFNULL(AVG( r.points ),0) AS rating
                    FROM cms_uc_items i
                    LEFT JOIN cms_uc_ratings r ON r.item_id = i.id
                    WHERE i.published = 1 AND i.category_id = $id AND UPPER(LTRIM(i.title)) LIKE UPPER('$query%')
                    GROUP BY i.id";

        $do = 'cat';
        $advsearch = 0;

        $pagemode = 'findfirst';

    }

    //////////////////////////// SEARCH BY FIELD ////////////////////////////////////////////////////////////////////
    if ($do == 'find') {

        $id = cmsCore::request('cat_id', 'int');

        $query = cmsCore::strClear(urldecode(cmsCore::request('text', 'html', '')));

        $findsql = "SELECT i.* , IFNULL(AVG(r.points),0) AS rating
                    FROM cms_uc_items i
                    LEFT JOIN cms_uc_ratings r ON r.item_id = i.id
                    WHERE i.published = 1 AND i.category_id = $id AND i.fieldsdata LIKE '%$query%'
                    GROUP BY i.id";

        $do = 'cat';
        $advsearch = 0;

		$query = stripslashes($query);

        $pagemode = 'find';
    }

    //////////////////////////// LIST OF CATEGORIES ////////////////////////////////////////////////////////////////////
    if ($do == 'view'){ //List of all categories

        $cats_html = subCatsList();
        $inPage->addHead('<link rel="alternate" type="application/rss+xml" title="'.$_LANG['CATALOG'].'" href="'.HOST.'/rss/catalog/all/feed.rss">');
        cmsPage::initTemplate('components', 'com_catalog_index')->
                assign('cfg', $cfg)->
                assign('title', $pagetitle)->
                assign('cats_html', $cats_html)->
                display('com_catalog_index.tpl');

    }

    //////////////////////////// VIEW CATEGORY ///////////////////////////////////////////////////////////////////////
    if ($do == 'cat'){

        //get category data
        $sql = "SELECT * FROM cms_uc_cats WHERE id = $id";
        $catres = $inDB->query($sql);
        if (!$inDB->num_rows($catres)){ cmsCore::error404(); }

        $cat     = $inDB->fetch_assoc($catres);
        $fstruct = cmsCore::yamlToArray($cat['fieldsstruct']);

        $inPage->addHead('<link rel="alternate" type="application/rss+xml" title="'.$_LANG['CATALOG'].'" href="'.HOST.'/rss/catalog/'.$cat['id'].'/feed.rss">');

        //heading
        //PATHWAY ENTRY
        $path_list = $model->getCategoryPath($cat['NSLeft'], $cat['NSRight']);
        if ($path_list){
            foreach($path_list as $pcat){
                $inPage->addPathway($pcat['title'], '/catalog/'.$pcat['id']);
            }
        }
        $inPage->setTitle($cat['pagetitle'] ? $cat['pagetitle'] : $cat['title']);

        //subcategories
        $subcats = subCatsList($cat['id'], $cat['NSLeft'], $cat['NSRight']);

        //alphabetic list
        if ($cat['showabc']){ $alphabet = getAlphaList($cat['id']);	} else { $alphabet = ''; }

        //Tool links
        $shopcartlink = shopCartLink();

        //get items SQL
        if (!isset($findsql)){
            $sql = "SELECT i.* , IFNULL(AVG( r.points ), 0) AS rating, i.price as price
                    FROM cms_uc_items i
                    LEFT JOIN cms_uc_ratings r ON r.item_id = i.id
                    WHERE i.published = 1 AND i.category_id = $id
                    GROUP BY i.id";
        } else {
            $sql = $findsql;
            if (!$advsearch){ $inPage->addPathway(icms_ucfirst($query)); } else
            { $inPage->addPathway($_LANG['SEARCH_RESULT']); }
        }

        // сортировка
        if(cmsCore::inRequest('orderby')){
            $orderby = cmsCore::request('orderby', array('hits','rating','pubdate','title','price'), $cat['orderby']);
            cmsUser::sessionPut('uc_orderby', $orderby);
        } elseif(cmsUser::sessionGet('uc_orderby')){
            $orderby = cmsUser::sessionGet('uc_orderby');
        } else {
            $orderby = $cat['orderby'];
        }
        if(cmsCore::inRequest('orderto')){
            $orderto = cmsCore::request('orderto', array('asc','desc'), $cat['orderto']);
            cmsUser::sessionPut('uc_orderto', $orderto);
        } elseif(cmsUser::sessionGet('uc_orderto')){
            $orderto = cmsUser::sessionGet('uc_orderto');
        } else {
            $orderto = $cat['orderto'];
        }

        $sql .=  " ORDER BY ".$orderby." ".$orderto;

        //get total items count
        $result = $inDB->query($sql);
        $itemscount = $inDB->num_rows($result);

        //can user add items here?
        $is_cat_access = $model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id);
        $is_can_add = $is_cat_access || $inUser->is_admin;

        $tpl = cmsPage::initTemplate('components', 'com_catalog_view')->
                assign('id', $id)->
                assign('cat', $cat)->
                assign('subcats', $subcats)->
                assign('alphabet', $alphabet)->
                assign('shopcartlink', $shopcartlink)->
                assign('itemscount', $itemscount)->
                assign('is_can_add', $is_can_add)->
                assign('orderform', orderForm($orderby, $orderto, ($cat['view_type']=='shop')));

        //pagination
        if (!@$advsearch) { $perpage = $cat['perpage']; } else { $perpage='100'; }
        $page = $inCore->request('page', 'int', 1);

        //request items using pagination
        $sql .= " LIMIT ".(($page-1)*$perpage).", $perpage";
        $result = $inDB->query($sql) ;

        //search details, if needed
        $search_details = '';
        if (isset($findsql)){
            if ($advsearch){
                $search_details = '<div class="uc_queryform"><strong>'.$_LANG['SEARCH_RESULT'].' - </strong> '.$_LANG['FOUNDED'].': '.$itemscount.' | <a href="/catalog/'.$cat['id'].'">'.$_LANG['CANCEL_SEARCH'].'</a></div>';
            } else {
                $search_details = '<div class="uc_queryform"><strong>'.$_LANG['SEARCH_BY_TAG'].'</strong> "'.htmlspecialchars(icms_ucfirst(stripslashes($query))).'" ('.$_LANG['MATCHES'].': '.$itemscount.') <a href="/catalog/'.$cat['id'].'">'.$_LANG['CANCEL_SEARCH'].'</a></div>';
            }
        }

        $items = array();
        while($item = $inDB->fetch_assoc($result)){
            $item['ratingdata'] = ratingData($item['id']);
            $item['fdata'] = cmsCore::yamlToArray($item['fieldsdata']);
            $item['price'] = number_format(shopDiscountPrice($item['id'], $item['category_id'], $item['price']), 2, '.', ' ');
            $item['rating'] = cms_model_catalog::buildRating($item['ratingdata']['rating']);
            $item['is_new'] = isNew($item['id'], $cat['shownew'], $cat['newint']);
            $item['tagline'] = tagLine($item['tags'], $cat['id']);

            $item['can_edit'] = ($cat['can_edit'] && $is_cat_access && ($inUser->id == $item['user_id'])) || $inUser->is_admin;

            $item['fields'] = array();

            if (sizeof($fstruct)>0){
                $fields_show = 0;
                foreach($fstruct as $key=>$value){
                    if ($fields_show < $cat['fields_show']){

                        if ($item['fdata'][$key]){

                            if (mb_strstr($value, '/~h~/')){ $value = str_replace('/~h~/', '', $value); $is_html = true; } else { $is_html = false; }
                            if (mb_strstr($value, '/~m~/')){
                                $value = str_replace('/~m~/', '', $value);
                                $makelink = true;
                            } else {$makelink = false; }
                            if (!$is_html){
                                if (mb_strstr($value, '/~l~/')){
                                    if (@$item['fdata'][$key]!=''){
                                        $field = '<a class="uc_fieldlink" href="/load/url=-'.base64_encode($item['fdata'][$key]).'" target="_blank">'.str_replace('/~l~/', '', $value).'</a> ('.$inCore->fileDownloadCount($item['fdata'][$key]).')';
                                    }
                                } else {
                                    if ($makelink){
                                        $field = $model->getUCSearchLink($cat['id'], $item['fdata'][$key]);
                                    } else {
                                        $field = $item['fdata'][$key];
                                    }
                                }
                            } else {
                                $field = $item['fdata'][$key];
                            }

                            if (isset($query)) { if (mb_stristr($field, $query)) { $field .= '<span class="uc_findsame"> &larr; <i>'.$_LANG['MATCHE'].'</i></span>';} }
                            $fields_show++;

                            $item['fields'][stripslashes($value)] = stripslashes($field);

                        }

                    } else { break; }
                }
            }

            $items[] = $item;
        }

        if (!@$pagemode){
            $pagebar = cmsPage::getPagebar($itemscount, $page, $perpage, '/catalog/'.$id.'-%page%');
        } else {

            if ($pagemode=='findfirst'){
                $pagebar = cmsPage::getPagebar($itemscount, $page, $perpage, '/catalog/'.$id.'-%page%/find-first/'.urlencode(urlencode($query)));
            }

            if ($pagemode=='find'){
                $pagebar = cmsPage::getPagebar($itemscount, $page, $perpage, '/catalog/'.$id.'-%page%/find/'.urlencode(urlencode($query)));
            }

        }

        // SEO
        if($cat['NSLevel'] > 0){

            // meta description
            if($cat['meta_desc']){
                $meta_desc = $cat['meta_desc'];
            } elseif(mb_strlen(strip_tags($cat['description']))>=250){
                $meta_desc = crop($cat['description']);
            } else {
                $meta_desc = $cat['title'];
            }
            $inPage->setDescription($meta_desc);
            // meta keywords
            if($cat['meta_keys']){
                $meta_keys = $cat['meta_keys'];
            } elseif($items){
                foreach($items as $c){
                    $k[] = $c['title'];
                }
                $meta_keys = implode(', ', $k);
            } else {
                $meta_keys = $cat['title'];
            }
            $inPage->setKeywords($meta_keys);

        }

        $tpl->assign('cfg', $cfg)->
              assign('page', $page)->
              assign('search_details', $search_details)->
              assign('fstruct', $fstruct)->
              assign('items', $items)->
              assign('pagebar', $pagebar)->
              display('com_catalog_view.tpl');

        return true;

    }

    //////////////////////////// VIEW ITEM DETAILS ///////////////////////////////////////////////////////////////////////
    if ($do == 'item'){

        $id  = $inCore->request('id', 'int');
        $sql = "SELECT * FROM cms_uc_items WHERE id = '$id'";
        $itemres = $inDB->query($sql) ;

        if (!$inDB->num_rows($itemres)){ cmsCore::error404(); }

        $item = $inDB->fetch_assoc($itemres);

        if ((!$item['published'] || $item['on_moderate']) && !$inUser->is_admin){
            cmsCore::error404();
        }

        $fdata = cmsCore::yamlToArray($item['fieldsdata']);

        if ($item['meta_keys']) { $inPage->setKeywords($item['meta_keys']); }
        if ($item['meta_desc']) { $inPage->setDescription($item['meta_desc']); }

        $ratingdata = ratingData($id);

        $sql = "SELECT * FROM cms_uc_cats WHERE id = '{$item['category_id']}'";
        $catres = $inDB->query($sql) ;
        $cat = $inDB->fetch_assoc($catres);
        $fstruct = cmsCore::yamlToArray($cat['fieldsstruct']);

        $is_cat_access = $inUser->id ?
                            $model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id) : false;
        $item['can_edit'] = ($cat['can_edit'] && $is_cat_access && ($inUser->id == $item['user_id'])) || $inUser->is_admin;

        //PATHWAY ENTRY
        $path_list  = $model->getCategoryPath($cat['NSLeft'], $cat['NSRight']);

        if ($path_list){
            foreach($path_list as $pcat){
                $inPage->addPathway($pcat['title'], '/catalog/'.$pcat['id']);
            }
        }
        $inPage->addPathway($item['title'], '/catalog/item'.$item['id'].'.html');

        $inPage->setTitle($item['title']);


        if ($cat['view_type']=='shop'){

            $shopCartLink=shopCartLink();

        }

        //update hits
        $inDB->query("UPDATE cms_uc_items SET hits = hits + 1 WHERE id = '$id'") ;

        //print item details
        $fields = array();

        if (sizeof($fstruct)>0){
            foreach($fstruct as $key=>$value){
                if (@$fdata[$key]){
                    if (mb_strstr($value, '/~h~/')){
                        $value = str_replace('/~h~/', '', $value);
                        $htmlfield = true;
                    }
                    if (mb_strstr($value, '/~m~/')){
                        $value = str_replace('/~m~/', '', $value);
                        $makelink = true;
                    } else {$makelink = false; }
                    $field = (string)str_replace('<p>', '<p style="margin-top:0px; margin-bottom:5px">', $fdata[$key]);
                    if (mb_strstr($value, '/~l~/')){
                        $field = '<a class="uc_detaillink" href="/load/url=-'.base64_encode($field).'" target="_blank">'.str_replace('/~l~/', '', $value).'</a> ('.$inCore->fileDownloadCount($field).')';

                    } else {

                        if (isset($htmlfield)) {
                            if ($makelink) {
                                 $field = $model->getUCSearchLink($cat['id'], $field);
                            } else {
                                //PROCESS FILTERS, if neccessary
                                if ($cat['filters']){
                                    $filters = $inCore->getFilters();
                                    if ($filters){
                                        foreach($filters as $id=>$_data){
                                            require_once PATH.'/filters/'.$_data['link'].'/filter.php';
                                            $_data['link']($field);
                                        }
                                    }
                                }
                                $field =  stripslashes($field);
                            }
                        } else {
                            if ($makelink) {
                                 $field =  $model->getUCSearchLink($cat['id'], $field);
                            }
                        }

                    }
                    $fields[stripslashes($value)] = stripslashes($field);
                }
            }
        }
        if ($cat['view_type']=='shop'){
            $item['price'] = number_format(shopDiscountPrice($item['id'], $item['category_id'], $item['price']), 2, '.', ' ');
        }

        $user = $inDB->get_fields('cms_users', "id='{$item['user_id']}'", 'login, nickname');
        $getProfileLink = cmsUser::getProfileLink($user['login'], $user['nickname']);

        if ($cat['is_ratings']){
            $ratingForm = ratingForm($ratingdata, $item['id']);
        }

        cmsPage::initTemplate('components', 'com_catalog_item')->
                assign('shopCartLink', (isset($shopCartLink) ? $shopCartLink : ''))->
                assign('getProfileLink', $getProfileLink)->
                assign('tagline', tagLine($item['tags'], $cat['id']))->
                assign('item', $item)->
                assign('cat', $cat)->
                assign('fields', $fields)->
                assign('ratingForm', (isset($ratingForm) ? $ratingForm : ''))->
                display('com_catalog_item.tpl');

        if ($item['is_comments'] && $inCore->isComponentEnable('comments')) {
            cmsCore::includeComments();
            comments('catalog', $item['id'], array(), ($inUser->id == $item['user_id']));
        }

        return true;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////// S H O P /////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////// ADD TO CART /////////////////////////////////////////////////////////////////////////////
    if ($do == 'addcart'){
        shopAddToCart($id, 1);
		$inCore->redirect('/catalog/viewcart.html');
    }
    ///////////////////////// VIEW CART /////////////////////////////////////////////////////////////////////////////
    if ($do == 'viewcart'){
        shopCart();
    }
    ///////////////////////// DELETE FROM CART /////////////////////////////////////////////////////////////////////////////
    if ($do == 'cartremove'){
        shopRemoveFromCart($id);
		$inCore->redirectBack();
    }
    ///////////////////////// CLEAR CART /////////////////////////////////////////////////////////////////////////////
    if ($do == 'clearcart'){
        shopClearCart();
        $inCore->redirectBack();
    }
    ///////////////////////// CLEAR CART /////////////////////////////////////////////////////////////////////////////
    if ($do == 'savecart'){
        $itemcounts =  $inCore->request('kolvo', 'array_int');
        if (is_array($itemcounts)){
            shopUpdateCart($itemcounts);
        }
        $inCore->redirectBack();
    }
    ///////////////////////// ORDER //////////////////////////////////////////////////////////////////////////////////
    if ($do == 'order'){
        shopOrder($cfg);
    }
    ///////////////////////// ORDER //////////////////////////////////////////////////////////////////////////////////
    if ($do == 'finish'){
        shopFinishOrder($cfg);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    if ($do == 'add_item' || $do == 'edit_item'){

        $cat_id  = cmsCore::request('cat_id', 'int');
        $item_id = cmsCore::request('item_id', 'int', 0);

        if ($do == 'add_item'){

            $cat = $inDB->get_fields('cms_uc_cats', "id='$cat_id'", '*');
            if (!$cat){ cmsCore::error404(); }

            $inPage->setTitle($_LANG['ADD_ITEM']);

            if (!($model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id) || $inUser->is_admin)){
                cmsCore::error404();
            }

            $item  = array();
            $fdata = array();

            if ($cat['cost']=='') { $cat['cost'] = false; }
            if (IS_BILLING){
                cmsBilling::checkBalance('catalog', 'add_catalog_item', false, $cat['cost']);
            }

            $item['is_comments'] = 1;

        }

        if ($do == 'edit_item'){

            $inPage->setTitle($_LANG['EDIT_ITEM']);

            $item = $inDB->get_fields('cms_uc_items', "id='$item_id'", '*');
            if (!$item) { cmsCore::error404(); }

            $cat = $inDB->get_fields('cms_uc_cats', "id='{$item['category_id']}'", '*');
            if (!$cat){ cmsCore::error404(); }

            $is_cat_access  = $model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id);
            $is_can_edit    = ($cat['can_edit'] && $is_cat_access && ($inUser->id == $item['user_id'])) || $inUser->is_admin;
            if (!$is_can_edit) { cmsCore::error404(); }

            $fdata = cmsCore::yamlToArray($item['fieldsdata']);

        }

        $path_list  = $model->getCategoryPath($cat['NSLeft'], $cat['NSRight']);
        if ($path_list){
            foreach($path_list as $pcat){
                $inPage->addPathway($pcat['title'], '/catalog/'.$pcat['id']);
            }
        }
        if($do == 'add_item'){
            $inPage->addPathway($_LANG['ADD_ITEM']);
        } else {
            $inPage->addPathway($_LANG['EDIT_ITEM']);
        }

		$cats = $inCore->getListItems('cms_uc_cats', $cat['id'], 'id', 'ASC', 'parent_id > 0 AND published = 1');

        $fields = array();

        $fstruct = cmsCore::yamlToArray($cat['fieldsstruct']);

        foreach($fstruct as $f_id=>$value){

            if (mb_strstr($value, '/~h~/')) { $ftype = 'html'; $value=str_replace('/~h~/', '', $value); }
            elseif (mb_strstr($value, '/~l~/')) { $ftype = 'link'; $value=str_replace('/~l~/', '', $value); } else { $ftype='text'; }

            if (mb_strstr($value, '/~m~/')) { $makelink = true; $value=str_replace('/~m~/', '', $value); }
            else { $makelink = false; }

            $next['ftype']    = stripslashes($ftype);
            $next['title']    = stripslashes($value);
            $next['makelink'] = stripslashes($makelink);

            if (!empty($fdata[$f_id])){
                $next['value']  = stripslashes($fdata[$f_id]);
            } else {
                $next['value']  = '';
            }

            $fields[$f_id] = $next;

        }

        cmsPage::initTemplate('components', 'com_catalog_add')->
                assign('do', $do)->
                assign('item', $item)->
                assign('fields', $fields)->
                assign('cat', $cat)->
                assign('cats', $cats)->
                assign('cfg', $cfg)->
                assign('is_admin', $inUser->is_admin)->
                assign('cat_id', $cat['id'])->
                display('com_catalog_add.tpl');

        return;

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    if ($do == 'submit_item'){

        $opt     = cmsCore::request('opt', 'str', 'add');
        $new_cat_id = cmsCore::request('new_cat_id', 'int', 0);
        $cat_id = $new_cat_id ? $new_cat_id : cmsCore::request('cat_id', 'int', 0);

        $item_id = cmsCore::request('item_id', 'int', 0);

        $cat = $inDB->get_fields('cms_uc_cats', "id='$cat_id'", '*');
        if(!$cat){ cmsCore::error404(); }

        if ($opt == 'add'){

            if(!$inUser->is_admin &&
                    !$model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id)){
                cmsCore::error404();
            }

        } else {

            $item = $inDB->get_fields('cms_uc_items', "id='{$item_id}'", '*');
            if(!$item){ cmsCore::error404(); }

            if(!$inUser->is_admin &&
                    !($cat['can_edit'] && ($inUser->id == $item['user_id']) &&
                        $model->checkCategoryAccess($cat['id'], $cat['is_public'], $inUser->group_id))){
                cmsCore::error404();
            }

        }

        $item['title'] = cmsCore::request('title', 'str');
        if (!$item['title']) { cmsCore::addSessionMessage($_LANG['NEED_TITLE'], 'error'); cmsCore::redirectBack(); }

        $item['category_id']    = $cat_id;
        $item['published']      = ($cfg['premod'] && !$inUser->is_admin ? 0 : 1);
        $item['on_moderate']    = ($cfg['premod'] && !$inUser->is_admin ? 1 : 0);

        $item['fdata']          = cmsCore::request('fdata', 'array', array());;
        foreach($item['fdata'] as $key=>$value) {
			$item['fdata'][$key] = cmsCore::badTagClear($value);
		}
        $item['fieldsdata']     = $inDB->escape_string(cmsCore::arrayToYaml($item['fdata']));

        $item['is_comments']    = $inUser->is_admin ? cmsCore::request('is_comments', 'int', 0) : $cfg['is_comments'];
        $item['tags']           = cmsCore::request('tags', 'str', '');
        $item['canmany']        = 1;
        $item['imageurl']       = ($opt == 'add' ? '' : $item['imageurl']);
        $item['price']          = 0;
        $item['canmany']        = 1;

        if($inUser->is_admin){
            $meta_desc = cmsCore::request('meta_desc', 'str', '');
            $meta_keys = cmsCore::request('meta_keys', 'str', '');
            $item['meta_desc']  = $meta_desc ? $meta_desc : $item['title'];
            $item['meta_keys']  = $meta_keys ? $meta_keys : $item['tags'];
        } else {
            $item['meta_desc']  = @$item['meta_desc'] ? $item['meta_desc'] : $item['title'];
            $item['meta_keys']  = @$item['meta_keys'] ? $item['meta_keys'] : $item['tags'];
        }

		if (cmsCore::inRequest('price')) {
			$price          = cmsCore::request('price', 'str', '');
			$price          = str_replace(',', '.', $price);
            $item['price']  = round($price, 2);
            $item['canmany']= cmsCore::request('canmany', 'int', 0);
		}

        if (cmsCore::request('delete_img', 'int', 0)){

            @unlink(PATH."/images/catalog/".$item['imageurl']);
            @unlink(PATH."/images/catalog/small/".$item['imageurl']);
            @unlink(PATH."/images/catalog/medium/".$item['imageurl']);

            $item['imageurl'] = '';

        }
        $file = $model->uploadPhoto($item['imageurl']);
        if($file){
            $item['imageurl'] = $file['filename'];
        }

        if ($opt=='add'){

            $item['pubdate'] = date('Y-m-d H:i');
            $item['user_id'] = $inUser->id;

            $item['id'] = $model->addItem($item);

            if (IS_BILLING){
                if ($cat['cost']=='') { $cat['cost'] = false; }
                cmsBilling::process('catalog', 'add_catalog_item', $cat['cost']);
            }

            if (!$cfg['premod'] || $inUser->is_admin) {

                cmsCore::callEvent('ADD_CATALOG_DONE', $item);

                //регистрируем событие
                cmsActions::log('add_catalog', array(
                    'object' => $item['title'],
                    'object_url' => '/catalog/item'.$item['id'].'.html',
                    'object_id' => $item['id'],
                    'target' => $cat['title'],
                    'target_url' => '/catalog/'.$cat['id'],
                    'target_id' => $cat['id'],
                    'description' => ''
                ));
            }
		}
        if ($opt=='edit'){
			$model->updateItem($item['id'], $item);
			cmsActions::updateLog('add_catalog', array('object' => $item['title']), $item['id']);
		}

        if ($inUser->id != 1 && $cfg['premod'] && $cfg['premod_msg']){

            $link = '<a href="/catalog/item'.$item['id'].'.html">'.$item['title'].'</a>';
            $user = '******'.cmsUser::getProfileURL($inUser->login).'">'.$inUser->nickname.'</a>';

            if ($opt=='add')  { $message = $_LANG['MSG_ITEM_SUBMIT']; }
            if ($opt=='edit') { $message = $_LANG['MSG_ITEM_EDITED']; }
            $message = str_replace('%user%', $user, $message);
            $message = str_replace('%link%', $link, $message);

            cmsUser::sendMessage(USER_UPDATER, 1, $message);

            cmsCore::addSessionMessage($_LANG['ITEM_PREMOD_NOTICE'], 'info');

            cmsCore::redirect('/catalog/'.$item['category_id']);

        }

        cmsCore::redirect('/catalog/item'.$item['id'].'.html');

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    if ($do == 'accept_item'){

        $item_id = cmsCore::request('item_id', 'int');

        $item = $inDB->get_fields('cms_uc_items', "id='{$item_id}'", 'title, user_id, category_id');
        if (!$item || !$inUser->is_admin){ cmsCore::error404(); }

        $inDB->query("UPDATE cms_uc_items SET published=1, on_moderate=0 WHERE id='{$item_id}'");

		$cat = $inDB->get_fields('cms_uc_cats', 'id='.$item['category_id'], 'id, title');

        cmsCore::callEvent('ADD_CATALOG_DONE', $item);

		//регистрируем событие
		cmsActions::log('add_catalog', array(
				'object' => $item['title'],
				'user_id' => $item['user_id'],
				'object_url' => '/catalog/item'.$item_id.'.html',
				'object_id' => $item_id,
				'target' => $cat['title'],
				'target_url' => '/catalog/'.$cat['id'],
				'target_id' => $cat['id'],
				'description' => ''
		));

        $item_link  = '<a href="/catalog/item'.$item_id.'.html">'.$item['title'].'</a>';

        $message = str_replace('%link%', $item_link, $_LANG['MSG_ITEM_ACCEPTED']);

        cmsUser::sendMessage(USER_UPDATER, $item['user_id'], $message);

        cmsCore::redirectBack();

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    if ($do == 'delete_item'){

        $item_id = cmsCore::request('item_id', 'int');

        $item = $inDB->get_fields('cms_uc_items', "id='{$item_id}'", '*');
        if(!$item){ cmsCore::error404(); }

        if (!($item['user_id']==$inUser->id || $inUser->is_admin)){ cmsCore::error404(); }

        $model->deleteItem($item_id);

        $message = str_replace('%item%', $item['title'], $_LANG['MSG_ITEM_REJECTED']);
        cmsUser::sendMessage(USER_UPDATER, $item['user_id'], $message);

        cmsCore::redirect('/catalog/'.$item['category_id']);

    }

}
コード例 #2
0
ファイル: index.php プロジェクト: aportale/touchandlearn
function writeContent()
{
    global $page;
    global $lang;
    switch ($page) {
        case 'screenshots':
            ?>
				<h2><?php 
            echo text('Screenshots', 'Bildschirmfotos');
            ?>
</h2>
				<div id="screenshotthumbs">
					<?php 
            echo screenShot("menu1", text("Menu page 1", "Men&uuml; Seite 1"));
            ?>
					<?php 
            echo screenShot("menu2", text("Menu page 2", "Men&uuml; Seite 2"));
            ?>
					<?php 
            echo screenShot("counting", text("Counting", "Z&auml;hlen"));
            ?>
					<?php 
            echo screenShot("addition", text("Addition", "Addition"));
            ?>
					<?php 
            echo screenShot("subtraction", text("Subtraction", "Subtraktion"));
            ?>
					<?php 
            echo screenShot("reading", text("Reading words", "W&ouml;rter lesen"));
            ?>
					<?php 
            echo screenShot("spelling", text("Spelling", "Buchstabieren"));
            ?>
					<?php 
            echo screenShot("readingclock1", text("Reading clock", "Uhr lesen"));
            ?>
					<?php 
            echo screenShot("readingclock2", text("Reading clocks", "Uhren lesen"));
            ?>
					<?php 
            echo screenShot("readingnotes", text("Reading notes", "Noten lesen"));
            ?>
					<?php 
            echo screenShot("readingintervals", text("Intervals", "Intervalle"));
            ?>
					<?php 
            echo screenShot("playingnotes", text("Playing notes", "Noten spielen"));
            ?>
				</div>
<?php 
            break;
        case 'status':
            ?>
				<h2><?php 
            echo text('Status', 'Status');
            ?>
</h2>
					<?php 
            echo text('<p>The progam Touch\'n\'learn was developed in 1998 in Turbo Delphi 1.0 for Windows 3.1.</p>' . '<p>In 2007, I released it on SourceForge and adjusted the source code to be compilabe with Turbo Delphi 2006 Express. I intended to afterwards port Touch\'n\'learn to the opensource and crossplatform <a href="http://www.lazarus.freepascal.org/">Free Pascal Lazarus</a>. Then I realized that unlike Delphi, Lazarus has no tools for loading and rendering vector graphics.</p>' . '<p>A basic concept of Touch\'n\'learn is, however, the fullscreen resolution independent UI, which relies on vector graphics. That lead to my conclusion that the program rather needs to be reimplemented with a modern framework like <a href="http://trolltech.com/products/qt">Trolltechs Qt</a>. The paint system of Qt supports <a href="http://doc.trolltech.com/4.3/paintsystem.html">SVG and antialiasing</a>.</p>' . '<p>The code reflects my coding style of 9 years, ago. German-english namings, weak design and wrong ambitions. So Touch\'n\'learn would definitely benefit from a complete reimplementation.</p>' . '<p>If there is enough interest for the project, I will love to create something new, better, bigger. Just contact me via the SourceForge page.</p>', '<p>Das Programm Touch\'n\'learn wurde 1998 mit Turbo Delphi für Windows 3.1 entwickelt.</p>' . '<p>2007 veröffentlichte ich es auf SourceForge und passte den Quelltext an, um ihn unter Turbo Delphi 2006 Express kompilierbar zu machen. Ich hatte vor, Touch\'n\'learn anschließend auf das quelloffene und plattformunabhängige <a href="http://www.lazarus.freepascal.org/">Free Pascal Lazarus</a> zu portieren. Dann stellte ich fest, dass Lazarus -anders als Delphi- keine Werkzeuge zum Laden und Zeichnen von Vektorgrafik hat.</p>' . '<p>Ein grundlegendes Konzept von Touch\'n\'learn ist allerdings eine bildschirmfüllende, auflösungsunabhängige Benutzeroberfläche. Dieses Konzept erfordert Vektorgrafik. Dies führte zu meiner Schlussfolgerung, dass eher eine Neuimplementierung mit einem modernen Werkzeug wie <a href="http://trolltech.com/products/qt">Trolltechs Qt</a> nötig sei. Das Grafiksystem von Qt unterstützt <a href="http://doc.trolltech.com/4.3/paintsystem.html">SVG und Bildkantenglättung</a>.</p>' . '<p>Der Quelltext spiegelt meinen Programmierstil von vor 9 Jahren wider. Deutsch-englische Namensgebungs, schwaches Design und falsche Ambitionen. Daher würde Touch\'n\'learn definitiv von einer kompletten Neuimplementierung profitieren.</p>' . '<p>Sollte es genug Interesse an dem Projekt würde ich sehr gerne etwas neues, besseres und größeres kreieren. Kontaktieren Sie mich einfach auf der SourceForge-seite.</p>');
            break;
        case 'license':
            ?>
				<h2><?php 
            echo text('License', 'Lizenz');
            ?>
</h2>
				<p>
					Touch'n'learn - <?php 
            echo tagLine();
            ?>
<br />
					Copyright (C) 1998, 2007 by Alessandro Portale<br />
					<a class="external" href="http://touchandlearn.sourceforge.net/<?php 
            echo text('', '?lang=german');
            ?>
">http://touchandlearn.sourceforge.net/</a>
				</p>
				<?php 
            echo text('', '<p><em>Der folgende Lizenztext ist in seiner englischen Originalfassung aufgef&uuml;hrt, da die <a class="external" href="http://www.gnu.de/gpl-ger.html">deutsche &Uuml;bersetzung</a> nicht offiziell oder im rechtlichen Sinne anerkannt ist.</em></p>');
            ?>
				<p>Touch'n'learn is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.</p>
				<p>Touch'n'learn is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <a class="external" href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</a> for more details.</p>
<?php 
            break;
        default:
            ?>
				<h2><?php 
            echo text('About', '&Uuml;ber');
            ?>
</h2>
				<?php 
            echo text('<p>An educative software for physically challenged children which is completely usable with a touch screen. The elements of the user interface are big and clear.</p>' . '<p>It was created during a practical semestre. Since a few years, the <a href="http://www.luckenberger-schule.de/">Luckenberger elementary school</a> in <a href="http://www.stadt-brb.de/stadt-brandenburg/">Brandenburg an der Havel</a> integrates physically challenged children into the lessons. This software was concepted together with Heiko Nachtigall, the vice president of the school.</p>' . '<p>When a physically challenged child has problems using pen and paper or other pedagogical material, it may happen that th child stays behind other children with its learning pensum. Using the hands when is are very essential for learning at the age of 6 or 7. A learning program which is really easy to use with a touch screen and has big and uncomplicated user interface elements could maybe compensate those motorical problems a little bit.</p>', '<p>Ein Lernprogramm für körperlich behinderte Grundschulkinder, das für die Benutzung mit einem Touchscreen geeignet ist. Die Bedienelemente sind groß und deutlich.</p>' . '<p>Das Programm enstand im Zuge eines Praktikumssemesters. Die <a href="http://www.luckenberger-schule.de/">Luckenberger Grundschule</a> in <a href="http://www.stadt-brb.de/stadt-brandenburg/">Brandenburg an der Havel</a> integriert seit einigen Jahren körperlich behinderte und lernbehinderte Kinder in den Schulalltag. Zusammen mit Herrn Heiko Nachtigall, dem stellvertretenden Schulleiter der Schule, wurde es konzipiert.</p>' . '<p>Ein körperlich behindertes Kind kann, wenn es Schwierigkeiten im Umgang mit Stift und Papier oder pädagogischem Spielzeug hat, in den frühen Grundschuljahren evtl. mit dem Lernpensum zurück bleiben. Das Be-"greifen" spielt beim Lernen eine wichtige Rolle. Ein leicht per Touchscreen bedienbares Lernprogramm mit großen Bedienelementen kann diese motorischen Schwierigkeiten eventuell teilweise kompensieren.</p>');
    }
}
コード例 #3
0
ファイル: relation.php プロジェクト: Haikuch/osm-deep-history
echo date("d-M-Y H:i", filemtime("users_agreed.txt"));
?>
)</small></td>
    </tr>
<?php 
echo licenseLine($relations);
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($relations) + 1;
?>
'>Tags</td>
    </tr>
    <?php 
foreach (array_keys($tag_keys) as $key) {
    print tagLine($relations, $key, $key);
}
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($relations) + 1;
?>
'>Members</td>
    </tr>
    <?php 
foreach (array_keys($relation_refs) as $key) {
    list($type, $ref) = split(',', $key);
    print memberLine($relations, $type, $ref);
}
?>
  </table>
コード例 #4
0
ファイル: node.php プロジェクト: Haikuch/osm-deep-history
    <?php 
echo wayLine($nodes, 'lon', true, "Lon");
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($nodes) + 1;
?>
'>License Status <small>(Last updated: <?php 
echo date("d-M-Y H:i", filemtime("users_agreed.txt"));
?>
)</small></td>
    </tr>
<?php 
echo licenseLine($nodes);
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($nodes) + 1;
?>
'>Tags</td>
    </tr>
    <?php 
foreach (array_keys($tag_keys) as $key) {
    print tagLine($nodes, $key, $key);
}
?>
  </table>
  <div class="reset_collapse"><!-- --></div>
  </div>
</body>
コード例 #5
0
ファイル: way.php プロジェクト: Haikuch/osm-deep-history
echo date("d-M-Y H:i", filemtime("users_agreed.txt"));
?>
)</small></td>
    </tr>
    <?php 
echo licenseLine($ways);
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($ways) + 1;
?>
'>Tags</td>
    </tr>
    <?php 
foreach (array_keys($tag_keys) as $key) {
    print tagLine($ways, $key, $key);
}
?>
    <tr>
      <td style='background:#aaa;' colspan='<?php 
echo count($ways) + 1;
?>
'>Nodes</td>
    </tr>
    <?php 
foreach (array_keys($way_refs) as $ref) {
    print refLine($ways, $ref);
}
?>
  </table>
  <div class="reset_collapse"><!-- --></div>