Пример #1
0
function getCatsSelectlist($cat_id = 0, &$cat_tree, $max_level = 0)
{
    $database =& JFactory::getDBO();
    static $level = 0;
    $sql = "SELECT *, '" . $level . "' AS level FROM #__mt_cats WHERE cat_published=1 && cat_approved=1 && cat_parent= " . $database->quote($cat_id) . " ORDER BY cat_name ASC";
    $database->setQuery($sql);
    $cat_ids = $database->loadObjectList();
    if (count($cat_ids) > 0) {
        $level++;
        if ($max_level == 0 || $level <= $max_level) {
            foreach ($cat_ids as $cid) {
                $cat_tree[] = array("level" => $cid->level, "cat_id" => $cid->cat_id, "cat_name" => $cid->cat_name, "cat_allow_submission" => $cid->cat_allow_submission);
                if ($cid->cat_cats > 0) {
                    $children_ids = getCatsSelectlist($cid->cat_id, $cat_tree, $max_level);
                    $cat_ids = array_merge($cat_ids, $children_ids);
                }
            }
        }
        $level--;
    }
    return $cat_ids;
}
Пример #2
0
function editlisting($link_id, $option)
{
    global $savantConf, $Itemid, $mtconf;
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    $document =& JFactory::getDocument();
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'mfields.class.php';
    # Get cat_id if user is adding new listing.
    $cat_id = JRequest::getInt('cat_id', 0);
    // This var retrieve the link_id for adding listing
    $link_id_passfromurl = JRequest::getInt('link_id', 0);
    if ($link_id_passfromurl > 0 && $cat_id == 0) {
        $database->setQuery("SELECT cat_id FROM (#__mt_links AS l, #__mt_cl AS cl) WHERE l.link_id ='" . $link_id_passfromurl . "' AND cl.link_id = l.link_id");
        $cat_id = $database->loadResult();
    }
    $link = new mtLinks($database);
    # Do not allow Guest to edit listing
    if ($link_id > 0 && $my->id <= 0) {
        $link->load(0);
    } else {
        $link->load($link_id);
    }
    # Load all published CORE & custom fields
    $sql = "SELECT cf.*, " . ($link_id ? $link_id : 0) . " AS link_id, cfv.value AS value, cfv.attachment, cfv.counter, ft.ft_class FROM #__mt_customfields AS cf " . "\nLEFT JOIN #__mt_cfvalues AS cfv ON cf.cf_id=cfv.cf_id AND cfv.link_id = " . $link_id . "\nLEFT JOIN #__mt_fieldtypes AS ft ON ft.field_type=cf.field_type" . "\nWHERE cf.hidden ='0' AND cf.published='1' ORDER BY ordering ASC";
    $database->setQuery($sql);
    $fields = new mFields();
    $fields->setCoresValue($link->link_name, $link->link_desc, $link->address, $link->city, $link->state, $link->country, $link->postcode, $link->telephone, $link->fax, $link->email, $link->website, $link->price, $link->link_hits, $link->link_votes, $link->link_rating, $link->link_featured, $link->link_created, $link->link_modified, $link->link_visited, $link->publish_up, $link->publish_down, $link->metakey, $link->metadesc, $link->user_id, '');
    $fields->loadFields($database->loadObjectList());
    # Load images
    $database->setQuery("SELECT img_id, filename FROM #__mt_images WHERE link_id = '" . $link_id . "' ORDER BY ordering ASC");
    $images = $database->loadObjectList();
    # Get current category's template
    $database->setQuery("SELECT cat_name, cat_parent, cat_template, metakey, metadesc FROM #__mt_cats WHERE cat_id='" . $cat_id . "' AND cat_published='1' LIMIT 1");
    $cat = $database->loadObject();
    if ($link->link_id == 0) {
        if ($cat) {
            $document->setTitle(sprintf(JText::_('Add listing2'), $cat->cat_name));
        } else {
            $document->setTitle(JText::_('Add listing'));
        }
    } else {
        $document->setTitle(sprintf(JText::_('Edit listing2'), $link->link_name));
    }
    if (isset($cat->cat_template) && $cat->cat_template != '') {
        loadCustomTemplate(null, $savantConf, $cat->cat_template);
    }
    # Get other categories
    $database->setQuery("SELECT cl.cat_id FROM #__mt_cl AS cl WHERE cl.link_id = '{$link_id}' AND cl.main = '0'");
    $other_cats = $database->loadResultArray();
    # Pathway
    $pathWay = new mtPathWay($cat_id);
    $pw_cats = $pathWay->getPathWayWithCurrentCat($cat_id);
    $pathWayToCurrentCat = '';
    $mtCats = new mtCats($database);
    $pathWayToCurrentCat = ' <a href="' . JRoute::_("index.php?option=com_mtree&task=listcats&Itemid=" . $Itemid) . '">' . JText::_('Root') . "</a>";
    foreach ($pw_cats as $pw_cat) {
        $pathWayToCurrentCat .= JText::_('Arrow') . ' <a href="' . JRoute::_("index.php?option=com_mtree&task=listcats&cat_id=" . $pw_cat . "&Itemid=" . $Itemid) . '">' . $mtCats->getName($pw_cat) . "</a>";
    }
    # Savant Template
    $savant = new Savant2($savantConf);
    assignCommonVar($savant);
    $savant->assign('pathway', $pathWay);
    $savant->assign('pathWayToCurrentCat', $pathWayToCurrentCat);
    $savant->assign('cat_id', $link_id == 0 ? $cat_id : $link->cat_id);
    $savant->assign('other_cats', $other_cats);
    $savant->assignRef('link', $link);
    $savant->assignRef('fields', $fields);
    $savant->assignRef('images', $images);
    if ($mtconf->get('image_maxsize') > 1048576) {
        $savant->assign('image_size_limit', round($mtconf->get('image_maxsize') / 1048576, 1) . 'MB');
    } else {
        $savant->assign('image_size_limit', round($mtconf->get('image_maxsize') / 1024) . 'KB');
    }
    # Check permission
    if ($mtconf->get('user_addlisting') == 1 && $my->id < 1 || $link_id > 0 && $my->id == 0) {
        $savant->assign('error_msg', JText::_('Please login before addlisting'));
        $savant->display('page_error.tpl.php');
    } elseif ($link_id > 0 && $my->id != $link->user_id || $mtconf->get('user_allowmodify') == 0 && $link_id > 0 || $mtconf->get('user_addlisting') == -1 && $link_id == 0 || $mtconf->get('user_addlisting') == 1 && $my->id == 0) {
        echo _NOT_EXIST;
    } else {
        // OK, you can edit
        $database->setQuery("SELECT CONCAT('cust_',cf_id) as varname, caption As value, field_type, prefix_text_mod, suffix_text_mod FROM #__mt_customfields WHERE hidden <> '1' AND published = '1'");
        $custom_fields = $database->loadObjectList('varname');
        $savant->assign('custom_fields', $custom_fields);
        # Load custom fields' value from #__mt_cfvalues to $link
        $database->setQuery("SELECT CONCAT('cust_',cf_id) as varname, value FROM #__mt_cfvalues WHERE link_id = '" . $link_id . "'");
        $cfvalues = $database->loadObjectList('varname');
        foreach ($custom_fields as $cfkey => $value) {
            if (isset($cfvalues[$cfkey])) {
                $savant->custom_data[$cfkey] = $cfvalues[$cfkey]->value;
            } else {
                $savant->custom_data[$cfkey] = '';
            }
        }
        // Get category's tree
        if ($mtconf->get('allow_changing_cats_in_addlisting')) {
            getCatsSelectlist($cat_id, $cat_tree, 1);
            if ($cat_id > 0) {
                $cat_options[] = JHTML::_('select.option', $cat->cat_parent, JText::_('Arrow back'));
            }
            if ($mtconf->get('allow_listings_submission_in_root')) {
                $cat_options[] = JHTML::_('select.option', '0', JText::_('Root'));
            }
            if (count($cat_tree) > 0) {
                foreach ($cat_tree as $ct) {
                    if ($ct["cat_allow_submission"] == 1) {
                        $cat_options[] = JHTML::_('select.option', $ct["cat_id"], str_repeat("&nbsp;", $ct["level"] * 3) . ($ct["level"] > 0 ? " -" : '') . $ct["cat_name"]);
                    } else {
                        $cat_options[] = JHTML::_('select.option', $ct["cat_id"] * -1, str_repeat("&nbsp;", $ct["level"] * 3) . ($ct["level"] > 0 ? " -" : '') . "(" . $ct["cat_name"] . ")");
                    }
                }
            }
            $catlist = JHTML::_('select.genericlist', $cat_options, 'new_cat_id', 'size=8 class="inputbox"', 'value', 'text', '', 'browsecat');
            $savant->assignRef('catlist', $catlist);
        }
        // Give warning is there is already a pending approval for modification.
        if ($link_id > 0) {
            $database->setQuery("SELECT link_id FROM #__mt_links WHERE link_approved = '" . -1 * $link_id . "'");
            if ($database->loadResult() > 0) {
                $savant->assign('warn_duplicate', 1);
            } else {
                $savant->assign('warn_duplicate', 0);
            }
        }
        $savant->assign('pathWay', $pathWay);
        $savant->display('page_addListing.tpl.php');
    }
}
Пример #3
0
function getCatsSelectlist( $cat_id=0, &$cat_tree, $max_level=0 ) {
	$database	=& JFactory::getDBO();

	static $level = 0;

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// OSE Added - OSE and Open Source Excellence is the registered trade mark of the Open Source Excellence PTE LTD.
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	if (file_exists(JPATH_SITE.DS.'components'.DS.'com_osemsc'.DS.'init.php') && file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_ose_cpu'.DS.'define.php') && !file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_osemsc'.DS.'installer.dummy.ini'))
	{
		require_once(JPATH_SITE.DS.'components'.DS.'com_osemsc'.DS.'init.php');
		$content_ids = oseRegistry::call('content')->getRestrictedContent('mtree','category');

		$where = (COUNT($content_ids) > 0)?' AND cat_id NOT IN ('.implode(',',$content_ids).')':null;
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// OSE Added - OSE and Open Source Excellence is the registered trade mark of the Open Source Excellence PTE LTD.
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	$sql = "SELECT *, '".$level."' AS level FROM #__mt_cats WHERE cat_published=1 && cat_approved=1 && cat_parent= " . $database->quote($cat_id) . $where." ORDER BY cat_name ASC";
	$database->setQuery( $sql );

	$cat_ids = $database->loadObjectList();
	
	if ( count($cat_ids) > 0 ) {

		$level++;
		
		if( $max_level == 0 || $level <= $max_level) {
			foreach( $cat_ids AS $cid ) {
				
				$cat_tree[] = array("level" => $cid->level, "cat_id" => $cid->cat_id, "cat_name" => $cid->cat_name, "cat_allow_submission" => $cid->cat_allow_submission ) ;

				if ( $cid->cat_cats > 0 ) {
					$children_ids = getCatsSelectlist( $cid->cat_id, $cat_tree, $max_level );
					$cat_ids = array_merge( $cat_ids, $children_ids );
				}
			}
		}
		$level--;
	}

	return $cat_ids;

}