예제 #1
0
function display_page_content()
{
    $accnt_id = requestIdParam();
    $account = Paypal_Config::FindById($accnt_id);
    ?>

<script type="text/javascript">
	$().ready(function() {
		$("#edit_paypal").validate({
			rules: {
					email: { required: true, email: true }
				},
			messages: {
					email: "Please enter a valid email address"
				}
		});
	});
</script>

<form id="edit_paypal" method="POST">

	<h1>Edit Account "<?php 
    echo $account->account_name;
    ?>
"</h1>
	
	<p class="announce">There is one PayPal account associated with <a href="<?php 
    echo BASEHREF;
    ?>
admin/list_products">products</a> on your site. To change the email associated with products and your PayPal account, edit it here. If you need more than one account &ndash; say, for different types of products &ndash; then let us know, and we can add that functionality.</p>
	<p>&nbsp;</p>
	
	<p><label for="email">Email:</label>
	<?php 
    textField("email", $account->email, "required: true");
    ?>
</p>
	
	<p><label for="email">Success URL:</label>
	<?php 
    textField("success_url", $account->success_url);
    ?>
<br />
	<span class="hint">Optional address to send people to when they successfully complete a checkout</span></p>
	
	<p><label for="email">Cancel URL:</label>
	<?php 
    textField("cancel_url", $account->cancel_url);
    ?>
<br />
	<span class="hint">Optional address to send people to when they decline or cancel a checkout</span></p>
		
	<input type="submit" class="submitbutton" name="submit" value="Save" />
</form>
<?php 
}
예제 #2
0
function initialize_page()
{
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Add Product" or $post_action == "Add and Return to List") {
        $product = MyActiveRecord::Create('Product');
        $product->display_name = $_POST['display_name'];
        $product->name = slug($_POST['display_name']);
        $product->price = $_POST['price'];
        if (isset($_POST['product_description'])) {
            $product->description = $_POST['product_description'];
        }
        $product->id = null;
        $product->save();
        $product = Product::FindByName($product->name);
        $account = Paypal_Config::FindById($_POST['accountId']);
        $account->setLink($product->id, 'product');
        // now check if a thumbnail was uploaded
        if (is_uploaded_file($_FILES["image"]["tmp_name"])) {
            $mimeType = $_FILES["image"]["type"];
            $fileType = "";
            switch ($mimeType) {
                case "image/gif":
                    $mimeName = "GIF Image";
                    $fileType = "gif";
                    break;
                case "image/jpeg":
                    $mimeName = "JPEG Image";
                    $fileType = "jpg";
                    break;
                case "image/png":
                    $mimeName = "PNG Image";
                    $fileType = "png";
                    break;
                case "image/x-MS-bmp":
                    $mimeName = "Windows Bitmap";
                    $fileType = "bmp";
                    break;
                default:
                    $mimeName = "Unknown image type";
            }
            // Open the uploaded file
            // MAIN IMAGE
            resizeToMaxDimension($_FILES["image"]["tmp_name"], PRODUCT_IMAGE_MAXWIDTH, "jpg");
            // Open the uploaded file
            $file = fopen($_FILES["image"]["tmp_name"], "r");
            $filesize = filesize($_FILES["image"]["tmp_name"]);
            // Read in the uploaded file
            $imageContents = fread($file, $filesize);
            // Escape special characters in the file
            $imageContents = AddSlashes($imageContents);
            // THUMBNAIL
            resizeToMaxDimension($_FILES["image"]["tmp_name"], PRODUCTTHUMB_IMAGE_MAXWIDTH, "jpg");
            // Open the uploaded file
            $file = fopen($_FILES["image"]["tmp_name"], "r");
            $filesize = filesize($_FILES["image"]["tmp_name"]);
            // Read in the uploaded file
            $thumbContents = fread($file, $filesize);
            // Escape special characters in the file
            $thumbContents = AddSlashes($thumbContents);
            $updateQuery = "UPDATE product SET thumbnail = \"{$thumbContents}\", image = \"{$imageContents}\", mime_type = \"{$mimeName}\" WHERE id = {$product->id}";
            $result = mysql_Query($updateQuery, MyActiveRecord::Connection());
        }
        setFlash("<h3>Product Added</h3>");
        if ($post_action == "Add and Return to List") {
            redirect("admin/list_products");
        }
    }
}