Source of file CountryPrice_DistributorManagementTool.php
Size: 36,856 Bytes - Last Modified: 2021-12-23T10:40:38+00:00
/var/www/docs.ssmods.com/process/src/code/control/cms/CountryPrice_DistributorManagementTool.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899 | <?php /** * Controller that allows checking of all information. * @author Nicolaas @ sunnysideup .co .nz * * */ class CountryPrice_DistributorManagementTool extends Controller { private static $allowed_actions = array( "setcountryprice" => 'distributors', "setobjectfield" => 'distributors' ); /** * Holds the current distributor, if any * * @Var Distributor | Null */ private $distributor = null; /** * List of Countries that the current member is allowed to see. * like so: * ID => Code * 1 => NZ * * @Var Array */ private $countryArray = array(); public function DistributorLabel() { return _t('Distributor.SINGULAR_NAME', 'Distributor'); } /** * determine level of access */ public function init() { parent::init(); $member = Member::currentUser(); $canViewAndEdit = false; $countries = null; if ($member) { if (Permission::check('ADMIN')) { $countries = CountryPrice_EcommerceCountry::get_real_countries_list() ->exclude(array("DistributorID" => 0)); $canViewAndEdit = true; } else { $distributor = $member->Distributor(); if ($distributor->exists()) { $this->distributor = $distributor; $countries = $distributor->Countries(); $canViewAndEdit = true; } $primaryCountry = $distributor->PrimaryCountry(); if ($primaryCountry && $primaryCountry->exists()) { $distributorPrimaryCountryCode = $primaryCountry->Code; $currentCountry = $countryObject = CountryPrice_EcommerceCountry::get_real_country(); $currentCountryCode = ''; if ($currentCountry) { $currentCountryCode = $currentCountry->Code; } if ($currentCountryCode !== $distributorPrimaryCountryCode) { return $this->redirect(CountryPrices_ChangeCountryController::new_country_link($distributorPrimaryCountryCode)); } } else { die("ERROR: No primary country has been set for this ". _t('Distributor.SINGULAR_NAME', 'Distributor') ."."); } } if ($countries && $countries->count()) { $this->countryArray = $countries->map("ID", "Code")->toArray(); } } if (!$canViewAndEdit) { Security::permissionFailure($this, 'Please log in first or log in as a '. _t('Distributor.SINGULAR_NAME', 'Distributor'). '.'); } } public function index($request) { return $this->renderWith('CountryPrice_DistributorManagementTool'); } /******************** * actions ********************/ /** * * * NOT CURRENTLY IN USE!!! */ public function setcountryprice() { return "NOT IN USE"; // 1) Check that all parameters have been specified $fields = $this->getCountryPriceIndexes(); $fields['Price'] = 'Price'; foreach ($fields as $field) { if (! isset($_REQUEST[$field])) { return "$field value missing"; } } // 2 Check the parameters values $objectClass = $_REQUEST['ObjectClass']; $valid = false; if (class_exists($objectClass)) { $object = singleton($objectClass); if (is_a($object, 'DataObject') && $object->hasExtension('CountryPrice_BuyableExtension')) { $valid = true; } } if (! $valid) { return 'ObjectClass value incorrect'; } $objectID = intval($_REQUEST['ObjectID']); $object = $objectClass::get()->byID($objectID); if (! $object) { return 'ObjectID value incorrect'; } $country = strtoupper($_REQUEST['Country']); $countryObject = CountryPrice_EcommerceCountry::get_real_country(Convert::raw2sql($country)); $countryCode = ''; if ($countryObject) { $countryCode = $countryObject->Code; } $valid = false; $currencyPerCountry = CountryPrice_EcommerceCurrency::get_currency_per_country(); if (isset($currencyPerCountry[$countryCode])) { $valid = true; if ($this->distributor) { $countries = $this->distributor->Countries()->map('Code', 'Code')->toArray(); if (! in_array($countryCode, $countries)) { $valid = false; } } } if (! $valid) { return 'Country value incorrect'; } $currency = strtoupper($_REQUEST['Currency']); if (strlen($currency) != 3) { return 'Currency value incorrect'; } $price = $_REQUEST['Price']; if (! is_numeric($price)) { return 'Price value incorrect'; } DB::query(" INSERT INTO \"CountryPrice\" (\"Created\",\"LastEdited\",\"Price\",\"Country\",\"Currency\",\"ObjectClass\",\"ObjectID\") VALUES (NOW(),NOW(),$price,'$countryCode','$currency','$objectClass',$objectID) ON DUPLICATE KEY UPDATE \"LastEdited\" = VALUES(\"LastEdited\"), \"Price\" = VALUES(\"Price\")"); return true; } /** * * * update field */ public function setobjectfield() { if (isset($_REQUEST["F"]) && $_REQUEST["F"]== "TESTONLY") { return "THIS IS FOR TESTING ONLY"; } // 1) Check that all parameters have been specified foreach (array('T', 'I', 'F', 'V') as $field) { if (! isset($_REQUEST[$field])) { return "$field value missing"; } } // 2 Check the parameters values $result = 1; // Updated $objectClass = $_REQUEST['T']; if (! class_exists($objectClass)) { return 'ObjectClass value incorrect'; } $objectID = $_REQUEST['I']; if ($objectClass == 'CountryPrice' && is_array($objectID)) { $object = new $objectClass($objectID); $objectID = $object->write(); $result = $objectID; // Added } elseif (intval($objectID)) { $objectID = intval($objectID); $object = $objectClass::get()->byID($objectID); if (! $object) { return 'ObjectID (ID: $objectID, Class Name: $objectClass) value incorrect'; } } else { return 'ObjectID value missing...'; } //check if object can be edited! if (!$this->canEditThisObject($objectClass, $objectID)) { return 'You can not edit this object'; } $fieldName = Convert::raw2sql($_REQUEST['F']); $value = $_REQUEST['V']; if ($fieldName == 'Price' && (! is_numeric($value) || $value < 0)) { return 'Price value incorrect'; } if ($value == '0') { $object->delete(); $result = 'deleted'; } else { $object->$fieldName = $value; $object->write(); } //create log $log = new CountryPrice_DistributorManagementTool_Log(); $member = Member::currentUser(); $log->UserEmail = $member->Email; $log->ObjectClass = $objectClass; $log->ObjectID = $objectID; $log->FieldName = $fieldName; $log->NewValue = $value; if ($this->distributor) { $log->DistributorID = $this->distributor->ID; } $log->write(); return $result; } /** * Title for page * @return String */ public function DistributorTitle() { return Permission::check('ADMIN') ? 'Shop Administrator' : $this->distributor->Name; } /** * @return string */ public function DistributorFilterList() { $html = ""; if (!$this->distributor) { $distributors = Distributor::get(); foreach ($distributors as $distributor) { $countries = $distributor->Countries(); if ($countries && $countries->count()) { $html .= " <li> <a href=\"#Distributor".$distributor->ID."\" data-name=\"Distributor".$distributor->ID."\" data-countries=\"".implode(",", $countries->map("ID", "ID")->toArray())."\">". $distributor->Name. "</a> </li> "; } } } return $html; } /** * returns list of Distributor Fields * @return String */ public function Distributors() { $html = ""; $where = ""; if ($this->distributor) { $where = "ID = {$this->distributor->ID}"; } $distributors = Distributor::get() ->where($where); if ($distributors && $distributors->count()) { foreach ($distributors as $distributor) { $data = array('T' => 'Distributor', 'I' => $distributor->ID); $html .= $this->createTreeNode( $distributor->Name, "", array($distributor) ); $html .= $this->createEditNode( "Name", "", $distributor->Name, $data + array("F" => "Name") ); $distributorFields = array( 'Email', 'Address1', 'Address2', 'Address3', 'Address4', 'Address5', 'Phone', 'DisplayEmail', 'WebAddress', 'DeliveryCostNote', 'ShippingEstimation', 'ReturnInformation' ); foreach ($distributorFields as $distributorField) { $html .= $this->createEditNode( $distributorField, "", $distributor->$distributorField, $data + array("F" => $distributorField) ); } if (Permission::check("ADMIN")) { $html .= $this->createEditNode( "Default " . _t('Distributor.SINGULAR_NAME', 'Distributor'), $distributor->IsDefault ? "YES" : "NO" ); } //countries $countryList = array(); $countries = $distributor->Countries(); foreach ($countries as $country) { $countryList[] = $country->Name . ($country->DoNotAllowSales ? ' (Sales not allowed)' : ''); } $html .= $this->createEditNode( 'Countries', implode(', ', $countryList) ); //users $memberList = ""; if ($members = $distributor->Members()) { if ($members->count()) { $memberList = implode(", ", $members->map("ID", "Email")->toArray()); } } $html .= $this->createEditNode( "Registered editors", $memberList ); $html .= $this->createEditNode( "Passwords?", ' ' . _t('Distributor.SINGULAR_NAME', 'Distributor').' can log in using the email(s) listed above. If they do not have a password they can request a <a href="/Security/lostpassword">password reset</a>. ' ); $html .= $this->closeTreeNode(); } } return $html; } /** * returns list of Country Fields * @return String */ public function AllowSalesTo() { $html = ""; $countries = EcommerceCountry::get() ->filter( array( "DoNotAllowSales" => 0, "Code" => $this->countryArray ) ) ->exclude(array("DistributorID" => 0)); if ($countries && $countries->count()) { foreach ($countries as $country) { //delivery options $deliveryOptionItems = PickUpOrDeliveryModifierOptions::get_all_as_country_array(); $deliveryOptions = ""; if ($deliveryOptionItems) { foreach ($deliveryOptionItems as $deliveryOptionCode => $countryCodes) { foreach ($countryCodes as $countryCode) { if ($countryCode == $country->Code) { $deliveryOptions .= $deliveryOptionCode.", "; } } } } //tax options $taxesObjects = GSTTaxModifierOptions::get() ->filter( array( "CountryCode" => $country->Code ) ); if ($taxesObjects && $taxesObjects->count()) { $taxes = implode(",", $taxesObjects->map("ID", "Name")->toArray()); } else { $taxes = ""; } $countrySpecificMessages = "tba"; //compile $data = array('T' => 'EcommerceCountry', 'I' => $country->ID); $distributorName = $country->Distributor()->Name; if (!$distributorName) { $distributorName = "<p class=\"message bad\">No ". _t('Distributor.SINGULAR_NAME', 'Distributor') ." has been assigned to this country.</p>"; } $html .= $this->createTreeNode($country->Code." - ".$country->Name, $country->Code, array($country)); $distributorTitlePlural = _t('Distributor.PLURAL_NAME', 'Distributor'); $distributorTitleSingluar = _t('Distributor.SINGULAR_NAME', 'Distributor'); $html .= $this->createEditNode($distributorTitleSingluar, $distributorName); $html .= $this->createEditNode("FAQ Content", "", $country->FAQContent, $data + array("F" => "FAQContent"), "textarea"); $html .= $this->createEditNode("Top Bar Message", "", $country->TopBarMessage, $data + array("F" => "TopBarMessage"), ""); $html .= $this->createEditNode("Country Specific Messages", $countrySpecificMessages); $html .= $this->createEditNode("Delivery Options", $deliveryOptions); $html .= $this->createEditNode("Taxes", $taxes); $paymentOptions = EcommercePayment::get_supported_methods(); $html .= $this->createEditNode("Payment Options", implode(',', array_keys($paymentOptions))); $html .= $this->closeTreeNode(); } } $countries = EcommerceCountry::get()->filter(array("DistributorID" => 0, "DoNotAllowSales" => 0)); if ($countries && $countries->count()) { $list = implode(", ", $countries->map("ID", "Code")->toArray()); $html .= $this->createEditNode("Countries without a ". _t('Distributor.SINGULAR_NAME', 'Distributor') ." that allow sales", $list); } $countries = EcommerceCountry::get()->filter(array("DistributorID" => 0, "DoNotAllowSales" => 1)); if ($countries && $countries->count()) { $list = implode(", ", $countries->map("ID", "Code")->toArray()); $html .= $this->createEditNode("Countries without a ". _t('Distributor.SINGULAR_NAME', 'Distributor') ." that do not allow sales", $list); } return $html; } /** * returns list of Product Fields * @return String */ public function Products() { $html = ""; $where = ""; $countryArray = array(); $products = Product::get() ->filter(array("AllowPurchase" => 1)) ->sort("FullSiteTreeSort", "ASC"); $defaultPriceText = ' (N.B. This is default for new variations ONLY - set actual prices under variations)'; if ($products && $products->count()) { foreach ($products as $product) { $withDefaultPrices = Permission::check('ADMIN') || (! $product->hasVariations()); $html .= $this->createTreeNode($product->FullName, "pricing", array($product)); //country exceptions if (Permission::check('ADMIN')) { $includedCountries = $product->IncludedCountries(); if ($includedCountries && $includedCountries->Count()) { $html .= $this->createEditNode( "Additional countries this product is sold ... ", implode(", ", $includedCountries->map("ID", "Code")->toArray()) ); } $excludedCountries = $product->ExcludedCountries(); if ($excludedCountries && $excludedCountries->Count()) { $html .= $this->createEditNode( "This product is not sold in ... ", implode(", ", $excludedCountries->map("ID", "Code")->toArray()) ); } //only show default price for ShopAdmin if ($withDefaultPrices) { $html .= $this->createEditNode( 'Default Price' . ($product->hasVariations() ? $defaultPriceText : ''), EcommercePayment::site_currency(), $product->Price, array( "T" => "Product", "F" => "Price", "I" => $product->ID ) ); } } //country prices $outstandingCountries = $this->countryArray; if ($withDefaultPrices) { $html .= $this->createTreeNode( 'Country Prices' . ($product->hasVariations() ? $defaultPriceText : ''), " pricing countryPrices" ); } $arrayOfProductCountryCurencyPrices = array(); $countriesWithProductPrices = array(); $countryPricesObjects = $product->AllCountryPricesForBuyable(); if ($countryPricesObjects->count()) { foreach ($countryPricesObjects as $countryPricesObject) { $arrayOfProductCountryCurencyPrices[$countryPricesObject->Currency.$countryPricesObject->Country] = $countryPricesObject->Currency.$countryPricesObject->Country; $countryObject = $countryPricesObject->CountryObject(); if (!$countryObject) { break; } $countryID = array_search($countryPricesObject->Country, $outstandingCountries); if (Permission::check('ADMIN') || $countryID !== false) { $data = array( "T" => "CountryPrice", "I" => $countryPricesObject->ID, "F" => "Price" ); $countryName = EcommerceCountry::find_title($countryPricesObject->Country); if ($withDefaultPrices) { $html .= $this->createEditNode( $countryPricesObject->Country . ' - '. $countryName, $countryPricesObject->Currency, $countryPricesObject->Price, $data, "input", array($countryObject), '[x]' ); } unset($outstandingCountries[$countryID]); } } } $addText = 'Add price to start selling'; foreach ($outstandingCountries as $countryCode) { if ($countryCode != EcommerceConfig::get('EcommerceCountry', 'default_country_code')) { $countryObject = EcommerceCountry::get()->filter(array("Code" => $countryCode))->first(); if (!$countryObject) { user_error("country not found"); } $currencyObject = $countryObject->EcommerceCurrency(); $data = array( "T" => "CountryPrice", "I" => array( 'Country' => $countryCode, 'Currency' => $currencyObject->Code, 'ObjectClass' => $product->ClassName, 'ObjectID' => $product->ID ), 'F' => 'Price' ); $countryName = EcommerceCountry::find_title($countryCode); if ($withDefaultPrices) { $html .= $this->createEditNode( $countryCode . ' - '. $countryName, $currencyObject->Code, $addText, $data, "input", array($countryObject), '[x]', 'add-node' ); } } } if ($withDefaultPrices) { $html .= $this->closeTreeNode(); } if ($product->hasVariations()) { $variations = $product->Variations(); if ($variations && $variations->count()) { $html .= $this->createTreeNode("Variations", "variations pricing"); $variations = $product->Variations(); foreach ($variations as $variation) { if ($variation->AllowPurchase) { $html .= $this->createTreeNode($variation->getTitle()); if (Permission::check('ADMIN')) { $html .= $this->createEditNode( "Default Price", EcommercePayment::site_currency(), $variation->Price, array( "T" => "ProductVariation", "F" => "Price", "I" => $variation->ID ) ); } $outstandingCountries = $this->countryArray; $countryPricesObjects = $variation->AllCountryPricesForBuyable(); $html .= $this->createTreeNode("Variation Country Prices", " pricing countryPrices variationCountryPrices"); if ($countryPricesObjects->count()) { $lowestPrice = 999999; foreach ($countryPricesObjects as $countryPricesObject) { $countryObject = $countryPricesObject->CountryObject(); if (!$countryObject) { break; } $countryID = array_search($countryPricesObject->Country, $outstandingCountries); if (Permission::check('ADMIN') || $countryID !== false) { $data = array( "T" => "CountryPrice", "I" => $countryPricesObject->ID, "F" => "Price" ); $countryName = EcommerceCountry::find_title($countryPricesObject->Country); $html .= $this->createEditNode( $countryPricesObject->Country . ' - '. $countryName, $countryPricesObject->Currency, $countryPricesObject->Price, $data, "input", array($countryObject), '[x]' ); if ($countryPricesObject->Price < $lowestPrice) { $lowestPrice = $countryPricesObject->Price; } unset($outstandingCountries[$countryID]); } } if ($lowestPrice > 0 && $lowestPrice < 999999) { if (!in_array($countryPricesObject->Currency.$countryPricesObject->Country, $arrayOfProductCountryCurencyPrices)) { $sql = ' INSERT INTO "CountryPrice" ("Created","LastEdited","Price","Country","Currency","ObjectClass","ObjectID") VALUES (NOW(), NOW(), \''.$lowestPrice.'\',\''.$countryPricesObject->Country.'\',\''.$countryPricesObject->Currency.'\',\''.$product->ClassName.'\','.$product->ID.') ON DUPLICATE KEY UPDATE "LastEdited" = VALUES("LastEdited"), "Price" = VALUES("Price") '; DB::alteration_message("adding product price for ".$product->Title." in ".$countryPricesObject->Country." because there are variation prices"); DB::query($sql); } } } foreach ($outstandingCountries as $countryCode) { if ($countryCode != EcommerceConfig::get('EcommerceCountry', 'default_country_code')) { $countryObject = EcommerceCountry::get()->filter(array("Code" =>$countryCode))->first(); if (!$countryObject) { user_error("country not found"); } $currency = $countryObject->EcommerceCurrency(); $data = array( "T" => "CountryPrice", "I" => array( 'Country' => $countryCode, 'Currency' => $currency->Code, 'ObjectClass' => $variation->ClassName, 'ObjectID' => $variation->ID ), 'F' => 'Price' ); $countryName = EcommerceCountry::find_title($countryCode); $html .= $this->createEditNode( $countryCode . ' - '. $countryName, $currency->Code, $addText, $data, "input", array($countryObject) ); } } $html .= $this->closeTreeNode(); $html .= $this->closeTreeNode(); } } $html .= $this->closeTreeNode(); } } $html .= $this->closeTreeNode(); } } else { $html .= $this->createEditNode("Products"); } return $html; } /** * returns list of Currencies with info * @return String */ public function Currencies() { $html = ""; $currencies = EcommerceCurrency::get(); foreach ($currencies as $currency) { $priceCount = CountryPrice::get()->filter(array("Currency" => $currency->Code))->count(); if ($priceCount) { $name = $currency->Code." ($priceCount price points)"; if ($currency->IsDefault()) { $name .= " [DEFAULT CURRENCY]"; } $html .= $this->createTreeNode($name, "currencies"); $html .= $this->createEditNode( 'Countries', "tba" ); $html .= $this->closeTreeNode(); } } //$html .= $this->createTreeNode("Currencies"); return $html; } /******************** * internal methods ********************/ /** * returns the opening of a list (<li>Title<ul>) * @param String $title - e.g. My items * @param String $classOrCountryCode -e.g. myCSSClass or NZ * @param Array list of objects used... * @return String */ private function createTreeNode($title, $classOrCountryCode = "", $objectArray = array()) { $class = ""; if (strlen($classOrCountryCode) == 2 && $img = $this->codeToFlag($classOrCountryCode)) { $title = $img.$title; $classOrCountryCode = ""; } elseif ($classOrCountryCode) { $class = " class=\"$classOrCountryCode\""; } $filterClass = ''; foreach ($objectArray as $object) { $filterClass .= ' '.$object->ClassName.$object->ID.' gp'.$object->ClassName; } return "<li class=\"$filterClass\"><strong>$title</strong><ul{$class}>"; } /** * returns the opening of a list (<li>Title<ul>) * @return String */ private function closeTreeNode() { return "</ul></li>"; } /** * returns the opening of a list (<li>Title<ul>) * @param String $label - e.g. My Price * @param String $nonEditText - e.g. USD * @param String $editText - e.g. 99.95 * @param Array $data - should include the following: "T", "I", "F" * @param String $fieldType -e.g. input, textarea, checkbox * @param DataList $objectArray -e.g. input, textarea, checkbox * @return String (<li>edit me</li>) */ private function createEditNode( $label, $nonEditText = "", $editText = "", $data = null, $fieldType = "input", $objectArray = null, $deleteText = '', $extraClassesString = '' ) { if (!$data) { $ddClass = "readonly"; $editTextNode = ""; } else { $ddClass = "editable"; $editTextNode = "<a href=\"#\" class=\"edit\">$editText</a>"; } if (strlen($label) == 2 && $img = $this->codeToFlag($label)) { $label = $img.$label; } //can be edited but there is no data if (($data && !$editText)) { $editText = "[NONE]"; ; } //can not be edited and there is no data elseif (!$data && !$editText && !$nonEditText) { $nonEditText = "[NONE]"; } $fieldTypeString = ""; if ($fieldType && $fieldType != "input") { $fieldTypeString = " data-$fieldType=\"1\""; } $nonEditTextNode = ""; if ($nonEditText) { $nonEditTextNode = "<div class=\"nonEditablePart\">$nonEditText</div>"; } if ($editTextNode) { $editTextNode = "<div class=\"editablePart\">$editTextNode</div>"; } if ($data) { foreach (array("T", "F", "I") as $key) { if (!isset($data[$key])) { user_error("data must contain T (table), F (field) and I (ID) value"); } } $data = " data-name=\"".Convert::raw2att(Convert::raw2json($data))."\""; } $filterClass = $extraClassesString; if ($objectArray) { foreach ($objectArray as $object) { $filterClass .= ' '.$object->ClassName.$object->ID.' gp'.$object->ClassName; } } $deleteLink = ''; if ($deleteText) { $deleteLink = '<a href="#" class="delete-record">'.$deleteText.'</a>'; } return " <li{$data}{$fieldTypeString} class=\"$filterClass \"> <dl> <dt>$label</dt> <dd class=\"$ddClass valueHolder\"> $nonEditTextNode $editTextNode $deleteLink </dd> </dl> </li>"; } private static $flag_cache = array(); /** * turn code into image flag * @param String $code * @return String html for flag */ private function codeToFlag($code) { if (isset(self::$flag_cache[$code])) { return self::$flag_cache[$code]; } $wwwLocation = "/themes/main/images/flags/".strtolower($code).".png"; $fileLocation = Director::baseFolder().$wwwLocation; if (file_exists($fileLocation)) { self::$flag_cache[$code] = "<img src=\"$wwwLocation\" alt=\"$code\" /> "; } else { self::$flag_cache[$code] = false; } return self::$flag_cache[$code]; } /** * turn code into image flag * @param String $table * @param Int $id * @return Boolean */ private function canEditThisObject($table, $id) { if (Permission::check('ADMIN')) { return true; } switch ($table) { case 'Distributor': if ($this->distributor->ID == $id) { return true; } return false; break; case 'EcommerceCountry': $obj = EcommerceCountry::get()->byID($id); return in_array($obj->Code, $this->countryArray); break; case 'CountryPrice': $obj = CountryPrice::get()->byID($id); return in_array($obj->Country, $this->countryArray); break; case 'Currency': return false; break; default: return false; } return false; } } |