/** * Creates the client side validation from form fields * which is generated at the header of each page */ function javascript() { $code = ''; $fields = $this->form->Fields(); foreach($fields as $field){ //if the field type has some special specific specification for validation of itself $valid = $field->jsValidation(); if($valid){ $code .= $valid; } } if(is_array($this->required)){ foreach($this->required as $field) { if(is_array($field) && isset($field['js'])){ $code .= $field['js'] . "\n"; }else if($fields->dataFieldByName($field)) { $code .= " require('$field');\n"; //Tabs for output tabbing :-) } } }else{ USER_ERROR("CustomRequiredFields::requiredfields is not set / not an array",E_USER_WARNING); } return $code; }
function CanEditShareIcons() { if (class_exists('DataObjectSorterDOD')) { $obj = singleton('ShareThisDataObject'); if ($obj->hasExtension('DataObjectSorterDOD')) { return true; } else { USER_ERROR('You have installed DataObjectSorterDOD, but you have not extended ShareThisDataObject with DataObjectSorterDOD, see sharethis/_config.php for more information.', E_USER_NOTICE); } } else { USER_ERROR('You need to install the DataObjectSorter module (see sharethis/README or sharethis/_config.php for more information)', E_USER_NOTICE); } }
function FlashObjectData() { if (!class_exists("FlashObject")) { USER_ERROR("You have not installed the flash module, please see README for more information", E_USER_WARNING); } $file = self::get_youtube_embed_url() . $this->YouTubeVideoCode . "?"; $array = self::get_player_options(); foreach ($array as $key => $value) { $file .= "&" . urlencode($key) . "=" . urlencode($value); } FlashObject::set_use_dynamic_insert(false); $obj = new FlashObject(); return $obj->CreateFlashObject($Title = $this->Title, $FlashFileDivID = "YouTubeVideo" . $this->URLSegment, $FlashFilename = $file, $AlternativeContent = '', $Width = self::get_player_width(), $Height = self::get_player_height(), $FlashVersion = '9.0.0', $ParamArray = self::get_player_options()); }
/** * Allows you to set groups based on a CheckboxSetField * * Pass the form element from your post data directly to this method, and * it will update the groups and add and remove the member as appropriate. * * On the form setup: * * <code> * $fields->push( * new CheckboxSetField( * "NewsletterSubscriptions", * "Receive email notification of events in ", * $sourceitems = DataObject::get("NewsletterType")->toDropDownMap("GroupID","Title"), * $selectedgroups = $member->Groups()->Map("ID","ID") * ) * ); * </code> * * On the form handler: * * <code> * $groups = $member->Groups(); * $checkboxfield = $form->Fields()->fieldByName("NewsletterSubscriptions"); * $groups->setByCheckboxSetField($checkboxfield); * </code> * * @param CheckboxSetField $checkboxsetfield The CheckboxSetField (with * data) from your form. */ function setByCheckboxSetField(CheckboxSetField $checkboxsetfield) { // Get the values from the formfield. $values = $checkboxsetfield->Value(); $sourceItems = $checkboxsetfield->getSource(); if ($sourceItems) { // If (some) values are present, add and remove as necessary. if ($values) { // update the groups based on the selections foreach ($sourceItems as $k => $item) { if (in_array($k, $values)) { $add[] = $k; } else { $remove[] = $k; } } // else we should be removing all from the necessary groups. } else { $remove = array_keys($sourceItems); } if ($add) { $this->addManyByGroupID($add); } if ($remove) { $this->RemoveManyByGroupID($remove); } } else { USER_ERROR("Member::setByCheckboxSetField() - No source items could be found for checkboxsetfield " . $checkboxsetfield->Name(), E_USER_WARNING); } }
/** * Generate a resized copy of this image with the given width & height. * Use in templates with $ResizedImage. */ function generateResizedImage($gd, $width, $height) { if (is_numeric($gd) || !$gd) { USER_ERROR("Image::generateFormattedImage - generateResizedImage is being called by legacy code or gd is not set.", E_USER_WARNING); } else { return $gd->resize($width, $height); } }
/** * Get all {@link FormField} instances necessary for a single row, * respecting the casting set in {@link $fieldTypes}. * Doesn't populate with any data. Optionally performs a readonly * transformation if {@link $IsReadonly} is set, or the current user * doesn't have edit permissions. * * @return FieldList */ function FieldSetForRow() { $fieldset = new FieldList(); if($this->fieldTypes){ foreach($this->fieldTypes as $key => $fieldType) { if(isset($fieldType->class) && is_subclass_of($fieldType, 'FormField')) { // using clone, otherwise we would just add stuff to the same field-instance $field = clone $fieldType; } elseif(strpos($fieldType, '(') === false) { $field = new $fieldType($key); } else { $fieldName = $key; $fieldTitle = ""; $field = eval("return new $fieldType;"); } if($this->IsReadOnly || !$this->Can('edit')) { $field = $field->performReadonlyTransformation(); } $fieldset->push($field); } }else{ USER_ERROR("TableField::FieldSetForRow() - Fieldtypes were not specified",E_USER_WARNING); } return $fieldset; }
/** * confirm payment... * @param HTTP_Request (SS_HTTPRequest) */ public function paid($request) { $timeStamp = $request->param("ID"); if ($timeStamp) { //find payment $payment = AuthorizeDotNetPayment::get()->byID(intval($_POST["x_invoice_num"])); if ($payment) { $payment->ValuesReceived = Convert::raw2sql(serialize($_POST)); //already completed? if ($payment->Status != "Incomplete") { return $payment->redirectToOrder(); } //get amount ... if (isset($_REQUEST["x_amount"])) { $amount = $_REQUEST["x_amount"]; } else { $amount = "0.00"; } //check if it is authorize.net response $checkHash = AuthorizeDotNetPayment::create_fingerprint($payment->ID, trim($timeStamp), $amount); if ($payment->Hash == $checkHash) { $payment->Hash = ""; //now we know it is legit, lets see the response... $responseCode = $_POST["x_response_code"]; if ($responseCode == self::$response_approved) { $payment->Status = 'Success'; } elseif ($responseCode == self::$response_held) { $payment->Status = 'Pending'; } else { $payment->Status = 'Failure'; } } else { $payment->Status = 'Failure'; } $payment->write(); return $payment->redirectToOrder(); } else { USER_ERROR("PAYMENT COULD NOT BE FOUND ", E_USER_WARNING); } } else { USER_ERROR("URL IS MISSING TIMESTAMP OF TRANSACTION", E_USER_WARNING); } }
/** * Generate an image on the specified format. It will save the image * at the location specified by cacheFilename(). The image will be generated * using the specific 'generate' method for the specified format. * @param string $format Name of the format to generate. * @param string $arg1 Argument to pass to the generate method. * @param string $arg2 A second argument to pass to the generate method. */ public function generateTransparentFormattedImage($format, $arg1 = null, $arg2 = null) { $cacheFile = $this->owner->cacheTransparentFilename($format, $arg1, $arg2); $backend = Injector::inst()->createWithArgs(Image::get_backend(), array(Director::baseFolder() . "/" . $this->owner->Filename)); if ($backend->hasImageResource()) { $generateFunc = "generate{$format}"; if ($this->owner->hasMethod($generateFunc)) { $backend = $this->owner->{$generateFunc}($backend, $arg1, $arg2); if ($backend) { $backend->writeTo(Director::baseFolder() . "/" . $cacheFile); } } else { USER_ERROR("Image::generateTransparentFormattedImage - Image {$format} function not found.", E_USER_WARNING); } } }
/** * Get the Order object to modify, check security that it's the object you want to modify based * off Worldpay confirmation, update the Order object to show complete and Payment object to show * that it was received. Finally, send a receipt to the buyer to show these details. */ function paid() { // Check if callback password is the same, otherwise fail if ($_REQUEST['callbackPW'] == WorldpayPayment::$callback_password) { $paymentID = $_REQUEST['MC_paymentID']; if (is_numeric($paymentID)) { if ($payment = DataObject::get_by_id('WorldpayPayment', $paymentID)) { if ($_REQUEST['transStatus'] == "Y") { $payment->Status = 'Success'; } else { $payment->Status = 'Failure'; } $payment->write(); $payment->redirectToOrder(); } else { USER_ERROR("CheckoutPage::OrderConfirmed - There is no Payment object for this order object (Order ID " . $orderID . ")", E_USER_WARNING); } } else { USER_ERROR('CheckoutPage::OrderConfirmed - Order ID is NOT numeric', E_USER_WARNING); } } else { USER_ERROR("CheckoutPage::OrderConfirmed - Order error - password failed", E_USER_WARNING); } return; }
function dodataobjectsort() { if (!class_exists("DataObjectSorterDOD")) { USER_ERROR("you have not installed the dataobjectsorter module - either hide the sort option OR install it: http://sunny.svnrepository.com/svn/sunny-side-up-general/dataobjectsorter"); } else { $this->extend("dodataobjectsort"); } }
function paid() { $this->extend("DpsPxPayPayment_Handler_completion_start"); $commsObject = new DpsPxPayComs(); $response = $commsObject->processRequestAndReturnResultsAsObject(); if ($payment = DpsPxPayPayment::get()->byID($response->getMerchantReference())) { if (1 == $response->getSuccess()) { $payment->Status = 'Success'; } else { $payment->Status = 'Failure'; } if ($DpsTxnRef = $response->getDpsTxnRef()) { $payment->TxnRef = $DpsTxnRef; } if ($ResponseText = $response->getResponseText()) { $payment->Message = $ResponseText; } $payment->write(); $payment->redirectToOrder(); } else { USER_ERROR("could not find payment with matching ID", E_USER_WARNING); } return; }
<?php trigger_error('this is a mistake'); USER_ERROR('this is another mistake', E_USER_NOTICE);
function paid() { $commsObject = new DpsPxPayComs(); $response = $commsObject->processRequestAndReturnResultsAsObject(); if ($payment = DpsPxPayStoredPayment::get()->byID($response->getMerchantReference())) { if ($payment->Status != 'Success') { if (1 == $response->getSuccess()) { $payment->Status = 'Success'; if ($response->DpsBillingId) { $existingCard = DpsPxPayStoredCard::get()->filter(array("BillingID" => $response->DpsBillingId))->First(); if ($existingCard == false) { $storedCard = new DpsPxPayStoredCard(); $storedCard->BillingID = $response->DpsBillingId; $storedCard->CardName = $response->CardName; $storedCard->CardHolder = $response->CardHolderName; $storedCard->CardNumber = $response->CardNumber; $storedCard->MemberID = $payment->Order()->MemberID; $storedCard->write(); } } } else { $payment->Status = 'Failure'; } if ($DpsTxnRef = $response->getDpsTxnRef()) { $payment->TxnRef = $DpsTxnRef; } if ($ResponseText = $response->getResponseText()) { $payment->Message = $ResponseText; } $payment->write(); } $payment->redirectToOrder(); } else { USER_ERROR("could not find payment with matching ID", E_USER_WARNING); } return; }
/** * creates order from repeatorder for a specific day. * IF it does not already exists. * */ protected function createOrderFromRepeatOrder($orderDateInteger) { if ($order = DataObject::get_one("Order", "\"OrderDateInteger\" = '" . $orderDateInteger . "' AND \"RepeatOrderID\" = " . $this->ID)) { //do nothing } else { $order = new Order(); $order->OrderDate = date("Y-m-d", $orderDateInteger); $order->OrderDateInteger = $orderDateInteger; $order->RepeatOrderID = $this->ID; $order->MemberID = $this->MemberID; $order->CustomerOrderNote = "Created as part of a repeating order."; $order->write(); if ($this->OrderItems()) { foreach ($this->OrderItems() as $repeatOrderOrderItem) { $product = DataObject::get_by_id('Product', $repeatOrderOrderItem->ProductID); if ($product) { //START CHECK AVAILABILITY if (class_exists("ProductStockCalculatedQuantity")) { $numberAvailable = ProductStockCalculatedQuantity::get_quantity_by_product_id($product->ID); if ($numberAvailable < $repeatOrderOrderItem->Quantity) { $alternatives = $repeatOrderOrderItem->AlternativesPerProduct(); $product = null; if ($dos) { foreach ($alternatives as $alternative) { $stillLookingForAlternative = true; $numberAvailable = ProductStockCalculatedQuantity::get_quantity_by_product_id($alternative->ID); if ($numberAvailable > $repeatOrderOrderItem->Quantity && $stillLookingForAlternative) { $stillLookingForAlternative = false; $product = $alternative; } } } } } //END CHECK AVAILABILITY if ($product) { $newProductOrderItem = new Product_OrderItem(); $newProductOrderItem->addBuyableToOrderItem($product, $repeatOrderOrderItem->Quantity); $newProductOrderItem->OrderID = $order->ID; $newProductOrderItem->write(); } } else { USER_ERROR("Product does not exist", E_USER_WARNING); } } } else { USER_ERROR("There are no order items", E_USER_WARNING); } //FINALISE!!! $order->write(); $order->tryToFinaliseOrder(); } }