function can($task, $view, $created_by = null, $vendorId = null) { static $user_id = null; static $isAdmin = null; static $vendor = null; if ($vendor === null) { JLoader::register('Permissions', JPATH_VM_ADMINISTRATOR . '/helpers/permissions.php'); $vendor = Permissions::getInstance()->isSuperVendor(); if ($user_id = JFactory::getUser()->get('id')) { $isAdmin = Permissions::getInstance()->check("admin,storeadmin"); JLoader::register('ShopFunctions', JPATH_VM_ADMINISTRATOR . '/helpers/shopfunctions.php'); } } if (!$vendor) { return ''; } if ($vendor > 1) { if (!ShopFunctions::can($task, $view)) { return false; } // only link to own entries or same vendor id if ($vendorId) { if ($vendorId != $vendor) { return false; } } elseif ($created_by != $user_id) { return false; } } return true; }
function addStandardEditViewCommands($id = 0, $save2new = true) { // if (JRequest::getCmd('tmpl') =='component' ) { // if (!class_exists('JToolBarHelper')) require(JPATH_ADMINISTRATOR.DS.'includes'.DS.'toolbarhelper.php'); // } else { // JRequest::setVar('hidemainmenu', true); $view = $this->getName(); JToolBarHelper::divider(); if (ShopFunctions::can('add', $view)) { if ($id) { JToolBarHelper::save2copy('save2copy', 'JTOOLBAR_SAVE_AS_COPY'); } if ($save2new) { JToolbarHelper::save2new('save2new', 'JTOOLBAR_SAVE_AND_NEW'); } } JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); // todo add filter by view if ($id) { JToolBarHelper::custom('preview', 'eye', null, 'COM_VIRTUEMART_PREVIEW', false); } // } // javascript for cookies setting in case of press "APPLY" $document = JFactory::getDocument(); if ($view == 'product') { $view = 'productdetails'; } $j = "\n\t\t\tJoomla.submitbutton=function(a){\n\t\t\t\tvar options = { path: '/', expires: 2},\n\t\t\t\t\tlink = '';\n\t\t\t\tif (a == 'preview') {\n\t\t\t\t\tlink='" . juri::root() . "index.php?option=com_virtuemart&view=" . $view . "&" . $this->_cidName . "=" . $id . "';\n\t\t\t\t\twindow.location = link;\n\t\t\t\t\t// console.log(link);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (a == 'apply') {\n\t\t\t\t\tjQuery('#searchMedia-div ul').remove();\n\t\t\t\t\tvar idx = jQuery('#adminForm ul li.active').index();\n\t\t\t\t\tjQuery.cookie('vmapply', idx, options);\n\t\t\t\t} else {\n\t\t\t\t\tjQuery.cookie('vmapply', '0', options);\n\t\t\t\t}\n\t\t\t\tjQuery( '#media-dialog' ).remove();\n\t\t\t\tJoomla.submitform(a);\n\t\t\t};\n\t\t"; $document->addScriptDeclaration($j); // LANGUAGE setting $editView = JRequest::getWord('view', ''); $params = JComponentHelper::getParams('com_languages'); //$config =JFactory::getConfig();$config->get('language'); $selectedLangue = $params->get('site', 'en-GB'); $lang = JFactory::getLanguage(); if ($this->frontEdit) { $selectedLangue = $lang->getTag(); } $lang = strtolower(strtr($selectedLangue, '-', '_')); // only add if ID and view not null if ($id && count(vmconfig::get('active_languages')) > 1) { if ($view == 'user') { $view = 'vendor'; } //$params = JComponentHelper::getParams('com_languages'); jimport('joomla.language.helper'); $this->lang = JRequest::getVar('vmlang', $lang); $languages = JLanguageHelper::createLanguageList($selectedLangue, constant('JPATH_SITE'), true); $activeVmLangs = vmconfig::get('active_languages'); foreach ($languages as $k => &$joomlaLang) { if (!in_array($joomlaLang['value'], $activeVmLangs)) { unset($languages[$k]); } } $this->langList = JHTML::_('select.genericlist', $languages, 'vmlang', 'class="inputbox"', 'value', 'text', $selectedLangue, 'vmlang'); $token = JSession::getFormToken(); $j = ' jQuery(function($) { var oldflag = ""; $("select#vmlang").chosen().change(function() { langCode = $(this).val(); flagClass = "flag-"+langCode.substr(0,2) ; $.getJSON( "index.php?option=com_virtuemart&view=translate&task=paste&format=json&lg="+langCode+"&id=' . $id . '&editView=' . $editView . '&' . $token . '=1' . $this->tmpl . '" , function(data) { var items = []; if (data.fields !== "error" ) { if (data.structure == "empty") alert(data.msg); $.each(data.fields , function(key, val) { cible = jQuery("#"+key); if (oldflag !== "") cible.parent().removeClass(oldflag) if (cible.parent().addClass(flagClass).children().hasClass("mce_editable") && data.structure !== "empty" ) { if (tinyMCE.execInstanceCommand) tinyMCE.execInstanceCommand(key,"mceSetContent",false,val); else tinymce.editors[key].setContent(val); } else if (data.structure !== "empty") cible.val(val); }); oldflag = flagClass ; } else alert(data.msg); } ) }); })'; $document->addScriptDeclaration($j); } else { // $params = JComponentHelper::getParams('com_languages'); // $lang = $params->get('site', 'en-GB'); $jlang = JFactory::getLanguage(); $langs = $jlang->getKnownLanguages(); $defautName = $langs[$selectedLangue]['name']; $flagImg = JURI::root(true) . '/administrator/components/com_virtuemart/assets/images/flag/' . substr($lang, 0, 2) . '.png'; $this->langList = '<input name ="vmlang" type="hidden" value="' . $selectedLangue . '" ><img style="vertical-align: middle;" alt="' . $defautName . '" src="' . $flagImg . '"> <b> ' . $defautName . '</b>'; $this->lang = $lang; } //I absolutly do not understand for that should be for, note by Max /* if ($object) { if(Vmconfig::get('multix','none')!=='none'){ $this->loadHelper('permissions'); if(!Permissions::getInstance()->check('admin')) { if (!$object->virtuemart_vendor_id) { if(!class_exists('VirtueMartModelVendor')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'vendor.php'); $object->virtuemart_vendor_id = VirtueMartModelVendor::getLoggedVendor(); } $vendorList = '<input type="hidden" name="virtuemart_vendor_id" value="'.$object->virtuemart_vendor_id.'" />'; } else $vendorList= ShopFunctions::renderVendorList($object->virtuemart_vendor_id,false); } else { $vendorList = '<input type="hidden" name="virtuemart_vendor_id" value="1" />'; } $this->assignRef('vendorList', $vendorList); }*/ }
echo $mainIcons[$topname]; ?> "></i><span class="desktop"><?php echo jtext::_($topname); ?> </span><span class="caret"></span></a> <ul class="dropdown-menu"> <?php foreach ($menus as $link => $name) { if ($task === 'add') { $viewArray = explode('&', $link); $view = $viewArray[0]; } else { $view = $link; } if (!ShopFunctions::can($task, $view)) { continue; } $hasLink = true; ?> <li> <a href="<?php echo jRoute::_('index.php?option=com_virtuemart&tmpl=component&view=' . $link); ?> " class="menu-cpanel"><?php echo jText::_($name); ?> </a> </li> <?php }
</th> <th width="40px" class="hidden-phone"><?php echo $this->sort('published'); ?> </th> <th class="hidden-phone"><?php echo $this->sort('p.virtuemart_product_id', 'COM_VIRTUEMART_ID'); ?> </th> </tr> </thead> <tbody> <?php if ($total = count($this->productlist)) { $i = 0; $canPublish = ShopFunctions::can('publish'); foreach ($this->productlist as $key => $product) { $checked = JHTML::_('grid.id', $i, $product->virtuemart_product_id); $canDo = $this->canChange($product->created_by); $published = $this->toggle($product->published, $i, 'published', $canDo && $canPublish); // featured bootstrap style , canDo is the permission $is_featured = vmHtml::featured($product->product_special, $i, $canDo); ?> <tr sortable-group-id="<?php echo $this->virtuemart_category_id; ?> "> <?php if ($this->virtuemart_category_id) { ?> <td class="order nowrap center hidden-phone">
/** * Collect all data to show on the template * * @author RolandD, Max Milbers */ function display($tpl = null) { //TODO get plugins running // $dispatcher = JDispatcher::getInstance(); // $limitstart = JRequest::getVar('limitstart', 0, '', 'int'); $this->show_prices = VmConfig::get('show_prices', 1); if ($this->show_prices == 1) { JLoader::register('calculationHelper', JPATH_VM_ADMINISTRATOR . '/helpers/calculationh.php'); } $document = JFactory::getDocument(); // add javascript for price and cart, need even for quantity buttons, so we need it almost anywhere vmJsApi::jPrice(); $app = JFactory::getApplication(); $pathway = $app->getPathway(); $task = JRequest::getCmd('task'); JLoader::register('VmImage', JPATH_VM_ADMINISTRATOR . '/helpers/image.php'); // Load the product //$product = $this->get('product'); //Why it is sensefull to use this construction? Imho it makes it just harder $this->product_model = VmModel::getModel('product'); $virtuemart_product_idArray = JRequest::getVar('virtuemart_product_id', 0); if (is_array($virtuemart_product_idArray) and count($virtuemart_product_idArray) > 0) { $virtuemart_product_id = (int) $virtuemart_product_idArray[0]; } else { $virtuemart_product_id = (int) $virtuemart_product_idArray; } $quantityArray = JRequest::getVar('quantity', array()); //is sanitized then JArrayHelper::toInteger($quantityArray); $quantity = 1; if (!empty($quantityArray[0])) { $quantity = $quantityArray[0]; } $onlyPublished = true; // set unpublished product when it's editable by its owner for preview if ($canEdit = ShopFunctions::can('edit', 'product')) { $onlyPublished = false; } $product = $this->product_model->getProduct($virtuemart_product_id, TRUE, TRUE, $onlyPublished, $quantity); if ($product && $canEdit) { JLoader::register('Permissions', JPATH_VM_ADMINISTRATOR . '/helpers/permissions.php'); $vendor = Permissions::getInstance()->isSuperVendor(); if ($vendor > 1 && $product->virtuemart_vendor_id !== $vendor) { $product = null; } elseif (!$product->published) { $app->enqueueMessage(JText::_('COM_VIRTUEMART_ORDER_PRINT_PRODUCT_STATUS') . ' : ' . JText::_('COM_VIRTUEMART_UNPUBLISHED'), 'warning'); } } $last_category_id = shopFunctionsF::getLastVisitedCategoryId(); if (empty($product->slug)) { //Todo this should be redesigned to fit better for SEO $app->enqueueMessage(JText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND')); $categoryLink = ''; if (!$last_category_id) { $last_category_id = JRequest::getInt('virtuemart_category_id', false); } if ($last_category_id) { $categoryLink = '&virtuemart_category_id=' . $last_category_id; } if (VmConfig::get('handle_404', 1)) { $app->redirect(JRoute::_('index.php?option=com_virtuemart&view=category' . $categoryLink . '&error=404', FALSE)); } else { JError::raise(E_ERROR, '404', 'Not found'); } return; } if (!empty($product->customfields)) { foreach ($product->customfields as $k => $custom) { if (!empty($custom->layout_pos)) { $product->customfieldsSorted[$custom->layout_pos][] = $custom; unset($product->customfields[$k]); } } $product->customfieldsSorted['normal'] = $product->customfields; unset($product->customfields); } $product->event = new stdClass(); $product->event->afterDisplayTitle = ''; $product->event->beforeDisplayContent = ''; $product->event->afterDisplayContent = ''; if (VmConfig::get('enable_content_plugin', 0)) { // add content plugin // $dispatcher =& JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $product->text = $product->product_desc; // jimport( 'joomla.html.parameter' ); // $params = new JParameter(''); $params = new JRegistry(); $product->event = new stdClass(); $results = $dispatcher->trigger('onContentPrepare', array('com_virtuemart.productdetails', &$product, &$params, 0)); // More events for 3rd party content plugins // This do not disturb actual plugins, because we don't modify $product->text $res = $dispatcher->trigger('onContentAfterTitle', array('com_virtuemart.productdetails', &$product, &$params, 0)); $product->event->afterDisplayTitle = trim(implode("\n", $res)); $res = $dispatcher->trigger('onContentBeforeDisplay', array('com_virtuemart.productdetails', &$product, &$params, 0)); $product->event->beforeDisplayContent = trim(implode("\n", $res)); $res = $dispatcher->trigger('onContentAfterDisplay', array('com_virtuemart.productdetails', &$product, &$params, 0)); $product->event->afterDisplayContent = trim(implode("\n", $res)); $product->product_desc = $product->text; } $this->product_model->addImages($product); if (isset($product->min_order_level) && (int) $product->min_order_level > 0) { $this->min_order_level = $product->min_order_level; } else { $this->min_order_level = 1; } if (isset($product->step_order_level) && (int) $product->step_order_level > 0) { $this->step_order_level = $product->step_order_level; } else { $this->step_order_level = 1; } // Load the neighbours if (VmConfig::get('product_navigation', 1)) { $product->neighbours = $this->product_model->getNeighborProducts($product); } // Product vendor multiX if ($multix = Vmconfig::get('multix', 'none') === 'admin') { $vendor_model = VmModel::getModel('vendor'); $this->vendor = $vendor_model->getVendor($product->virtuemart_vendor_id); } else { $this->vendor = null; } // echo 'multi'.$multix; // Load the category $category_model = VmModel::getModel('category'); shopFunctionsF::setLastVisitedCategoryId($product->virtuemart_category_id); $catTitle = array(); if ($category_model) { $category = $category_model->getCategory($product->virtuemart_category_id); $category_model->addImages($category, 1); $this->assignRef('category', $category); //Seems we dont need this anylonger, destroyed the breadcrumb if ($category->parents) { foreach ($category->parents as $c) { if (is_object($c) and isset($c->category_name)) { $pathway->addItem(strip_tags($c->category_name), JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $c->virtuemart_category_id, FALSE)); $catTitle[] = $c->category_name; } else { vmdebug('Error, parent category has no name, breadcrumb maybe broken, category', $c); } } } $vendorId = JRequest::getInt('virtuemart_vendor_id', null); $category->children = $category_model->getChildCategoryList($vendorId, $product->virtuemart_category_id); $category_model->addImages($category->children, 1); } if (!empty($tpl)) { $format = $tpl; } else { $format = JRequest::getWord('format', 'html'); } if ($format == 'html') { // Set Canonic link $document->addHeadLink($product->canonical, 'canonical', 'rel', ''); } $uri = JURI::getInstance(); //$pathway->addItem(JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), $uri->toString(array('path', 'query', 'fragment'))); $pathway->addItem(strip_tags($product->product_name)); // Set the titles // $document->setTitle should be after the additem pathway if ($product->customtitle) { $document->setTitle(strip_tags($product->customtitle)); } else { $document->setTitle(($catTitle ? implode(" / ", $catTitle) . ' / ' : '') . $product->product_name); } $ratingModel = VmModel::getModel('ratings'); $this->allowReview = $ratingModel->allowReview($product->virtuemart_product_id); $this->showReview = $ratingModel->showReview($product->virtuemart_product_id); if ($this->showReview) { $this->review = $ratingModel->getReviewByProduct($product->virtuemart_product_id); $this->rating_reviews = $ratingModel->getReviews($product->virtuemart_product_id); } $this->showRating = $ratingModel->showRating($product->virtuemart_product_id); if ($this->showRating) { $this->vote = $ratingModel->getVoteByProduct($product->virtuemart_product_id); $this->rating = $ratingModel->getRatingByProduct($product->virtuemart_product_id); } $this->allowRating = $ratingModel->allowRating($product->virtuemart_product_id); // todo: atm same form for "call for price" and "ask a question". Title of the form should be different $this->askquestion_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component', FALSE); // Load the user details $this->user = JFactory::getUser(); // More reviews link $uri = JURI::getInstance(); $uri->setVar('showall', 1); $uristring = $uri->toString(); $this->more_reviews = $uristring; if ($product->metadesc) { $document->setDescription($product->metadesc); } if ($product->metakey) { $document->setMetaData('keywords', $product->metakey); } if ($product->metarobot) { $document->setMetaData('robots', $product->metarobot); } if ($app->getCfg('MetaTitle') == '1') { $document->setMetaData('title', $product->product_name); //Maybe better product_name } if ($app->getCfg('MetaAuthor') == '1') { $document->setMetaData('author', $product->metaauthor); } $this->showBasePrice = Permissions::getInstance()->check('admin'); //todo add config settings $productDisplayShipments = array(); $productDisplayPayments = array(); JLoader::register('vmPSPlugin', JPATH_VM_PLUGINS . 'vmpsplugin.php'); JPluginHelper::importPlugin('vmshipment'); JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmOnProductDisplayShipment', array($product, &$productDisplayShipments)); $returnValues = $dispatcher->trigger('plgVmOnProductDisplayPayment', array($product, &$productDisplayPayments)); $this->productDisplayPayments = $productDisplayPayments; $this->productDisplayShipments = $productDisplayShipments; if (empty($category->category_template)) { $category->category_template = VmConfig::get('categorytemplate'); } $this->product = $product; shopFunctionsF::setVmTemplate($this, $category->category_template, $product->product_template, $category->category_product_layout, $product->layout); shopFunctionsF::addProductToRecent($virtuemart_product_id); $this->currency = CurrencyDisplay::getInstance(); if (JRequest::getCmd('layout', 'default') == 'notify') { $this->setLayout('notify'); } //Added by Seyi Awofadeju to catch notify layout parent::display($tpl); }
/** * Generic save task * * @author Max Milbers * @param post $data sometimes we just want to override the data to process */ function save($data = 0) { JSession::checkToken() or jexit('Invalid Token save'); if ($data === 0) { $data = JRequest::get('post'); } $task = JRequest::getCmd('task'); // remove shared when not superVendor if ($this->_vendor > 1) { if (isset($data['shared'])) { $data['shared'] = 0; } if (!ShopFunctions::can('publish')) { $data['published'] = 0; } // check vendor max uploaded images if (!($max_uploads = ShopFunctions::can('max_uploads'))) { JRequest::setVar('uploads', null, 'files'); jexit('save file error'); } // better filter in mediaManager // else $medias = JRequest::getVar('uploads', array(), 'files'); } // save2copy is same as save, only unset the primary ID if ($task == 'save2copy') { unset($data[$this->_cidName]); $data['published'] = 0; } $model = VmModel::getModel($this->_cname); $id = $model->store($data); $errors = $model->getErrors(); if (empty($errors)) { $msg = JText::sprintf('COM_VIRTUEMART_STRING_SAVED', $this->mainLangKey); $type = 'message'; } else { $type = 'error'; } foreach ($errors as $error) { $msg = $error . '<br />'; } $redir = $this->redirectPath; if ($task == 'apply' || $task == 'save2copy') { $redir .= '&task=edit&' . $this->_cidName . '=' . $id; } else { if ($task == 'save2new') { $redir .= '&task=add'; } } if ($task == 'apply') { $app = JFactory::getApplication(); $lastTab = $app->input->get('lastTab', '', 'cmd'); $app->setUserState("com_virtuemart.lasttab", $lastTab); } //else $this->display(); $this->setRedirect($redir, $msg, $type); }
/** * Build an array containing all the menu items. * * @param int $moduleId Id of the module to filter on */ static function _getAdminMenu($moduleId = 0) { $db = JFactory::getDBO(); $menuArr = array(); $filter = array(); $admin = JFactory::getUser()->authorise('core.admin'); $manage = JFactory::getUser()->authorise('core.manage'); $filter[] = "jmmod.published='1'"; $filter[] = "item.published='1'"; $filter[] = "jmmod.is_admin='1'"; // simple vendor menu to display $isVendor = Permissions::getInstance()->isSuperVendor() > 1; if ($isVendor) { $or = array(); $vendorViews = array("product", "category", "manufacturer", "media", "custom", "orders", "shoppers", "coupons", "report"); foreach ($vendorViews as $view) { if (ShopFunctions::can('edit', $view)) { $or[] = "item.view='" . $view . "'"; } } $or[] = "item.view='virtuemart'"; $or[] = "item.view='about'"; $filter[] = '(' . implode(' OR ', $or) . ')'; } elseif (!$admin) { // manager $filter[] = "item.view!='config'"; $filter[] = "item.view!='updatesmigration'"; } // var_dump($admin,$filter); // if (!$manage) { // $filter [] = "item.view!='config'"; // } if (!empty($moduleId)) { $filter[] = 'vmmod.module_id=' . (int) $moduleId; } $query = 'SELECT `jmmod`.`module_id`, `module_name`, `module_perms`, `id`, `name`, `link`, `depends`, `icon_class`, `view`, `task` FROM `#__virtuemart_modules` AS jmmod LEFT JOIN `#__virtuemart_adminmenuentries` AS item ON `jmmod`.`module_id`=`item`.`module_id` WHERE ' . implode(' AND ', $filter) . ' ORDER BY `jmmod`.`ordering`, `item`.`ordering` '; $db->setQuery($query); $result = $db->loadAssocList(); // echo '<pre>'.print_r($query,1).'</pre>'; for ($i = 0, $n = count($result); $i < $n; $i++) { $row = $result[$i]; if ($linkComponent = strpos($row['link'], '?')) { $linkToSplit = explode('=', $row['link']); if ($linkToSplit[0] == 'index.php?option') { $component = $linkToSplit[1]; VmConfig::loadJLang($component . '.sys'); } } $menuArr[$row['module_id']]['title'] = 'COM_VIRTUEMART_' . strtoupper($row['module_name']) . '_MOD'; $menuArr[$row['module_id']]['items'][] = $row; } return $menuArr; }
echo $this->DisplayFilterPublish(); ?> <div class="btn-group pull-right"><?php echo $this->pagination->getLimitBox(); ?> </div> <div class="btn-group pull-left"><?php echo $this->lists['search_role']; ?> </div> </div> <div class="clearfix"> </div> <div id="results"> <?php // split to use ajax search echo $this->loadTemplate('results'); ?> </div> <?php if (ShopFunctions::can('removeAll')) { ?> <div class="btn-wrapper" id="toolbar-removeAll"> <button onclick="Joomla.submitbutton('removeUnused')" class="btn btn-small"> <span class="icon-delete"></span> remove all unused media and delete the files</button> <?php } ?> </div> </form> <?php AdminUIHelper::endAdminArea(true);
?> </strong></span> <a href="<?php echo JROUTE::_('index.php?option=com_virtuemart&view=orders' . $this->tmpl); ?> "> <?php echo JText::_('JALL'); ?> </a> </div> </div> </div> <?php } if (ShopFunctions::can('edit', 'orders')) { ?> <div class="well well-small"> <div class="module-title nav-header"><?php echo JText::_('COM_VIRTUEMART_STATISTIC_NEW_CUSTOMERS'); ?> </div> <div class="row-striped"> <?php for ($i = 0, $n = count($this->recentCustomers); $i < $n; $i++) { $row = $this->recentCustomers[$i]; $link = JROUTE::_('index.php?option=com_virtuemart&view=user&virtuemart_user_id=' . $row->virtuemart_user_id . $this->tmpl); ?> <div class="row-fluid"> <a href="<?php echo $link;