PageRenderTime 29ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/community/ZetaPrints/WebToPrint/Helper/PersonalizationForm.php

http://magento-w2p.googlecode.com/
PHP | 1195 lines | 874 code | 251 blank | 70 comment | 129 complexity | 5b5fbf8b56dc498e50ce29c42994dd87 MD5 | raw file
  1. <?php
  2. class ZetaPrints_WebToPrint_Helper_PersonalizationForm
  3. extends ZetaPrints_WebToPrint_Helper_Data
  4. implements ZetaPrints_Api {
  5. private function get_form_part_html ($form_part = null, $product, $params = array()) {
  6. //$template = Mage::getModel('webtoprint/template')->load($template_guid);
  7. //if (!$template->getId())
  8. // return false;
  9. if (! $xml = $this->getTemplateXmlForCurrentProduct())
  10. return;
  11. //if ($form_part === 'text-fields' || $form_part === 'image-fields')
  12. // $this->add_values_from_cache($xml);
  13. if ($form_part === 'image-fields'
  14. && Mage::registry('webtoprint-user-was-registered'))
  15. $this->add_user_images($xml);
  16. if ($form_part === 'page-size-table'
  17. && !isset($xml->Pages->Page[0]['WidthIn']))
  18. return false;
  19. $params = array_merge(
  20. $params,
  21. array('zetaprints-api-url'
  22. => Mage::getStoreConfig('webtoprint/settings/url') . '/' )
  23. );
  24. //Append translations to xml
  25. $locale_file = Mage::getBaseDir('locale') . DS
  26. . Mage::app()->getLocale()->getLocaleCode() .DS
  27. .'ZetaPrints_WebToPrint.csv';
  28. $custom_translations_file = Mage::getBaseDir('locale') . DS
  29. . Mage::app()->getLocale()->getLocaleCode() . DS
  30. . 'ZetaPrints_WebToPrintCustomTranslations.csv';
  31. if (file_exists($locale_file) || file_exists($custom_translations_file)) {
  32. $cache = Mage::getSingleton('core/cache');
  33. $out = $cache->load("XMLTranslation".Mage::app()->getLocale()->getLocaleCode());
  34. if (strlen($out) == 0) {
  35. $locale = @file_get_contents($locale_file)
  36. . @file_get_contents($custom_translations_file);
  37. preg_match_all('/"(.*?)","(.*?)"(:?\r|\n|$)/', $locale, $array, PREG_PATTERN_ORDER);
  38. if (is_array($array) && count($array[1]) > 0) {
  39. $out = '<trans>';
  40. foreach ($array[1] as $key => $value) {
  41. if (strlen($value) > 0 && strlen($array[2][$key]) > 0) {
  42. $out .= "<phrase key=\"".$value."\" value=\"".$array[2][$key]."\"/>";
  43. }
  44. }
  45. $out .= "</trans>";
  46. $cache->save($out,"XMLTranslation".Mage::app()->getLocale()->getLocaleCode(),array('TRANSLATE'));
  47. }
  48. }
  49. $doc = new DOMDocument();
  50. $doc->loadXML($out);
  51. $node = $doc->getElementsByTagName("trans")->item(0);
  52. $xml_dom = new DOMDocument();
  53. $xml_dom->loadXML($xml->asXML());
  54. $node = $xml_dom->importNode($node, true);
  55. $xml_dom->documentElement->appendChild($node);
  56. } else {
  57. $xml_dom = new DOMDocument();
  58. $xml_dom->loadXML($xml->asXML());
  59. }
  60. return zetaprints_get_html_from_xml($xml_dom, $form_part, $params);
  61. }
  62. public function add_values_from_cache ($xml) {
  63. $session = Mage::getSingleton('customer/session');
  64. $text_cache = $session->getTextFieldsCache();
  65. $image_cache = $session->getImageFieldsCache();
  66. if ($text_cache && is_array($text_cache))
  67. foreach ($xml->Fields->Field as $field) {
  68. $name = (string)$field['FieldName'];
  69. if (!isset($text_cache[$name]))
  70. continue;
  71. $field->addAttribute('Value', $text_cache[$name]);
  72. }
  73. if ($image_cache && is_array($image_cache))
  74. foreach ($xml->Images->Image as $image) {
  75. $name = (string)$image['Name'];
  76. if (!isset($image_cache[$name]))
  77. continue;
  78. $image->addAttribute('Value', $image_cache[$name]);
  79. }
  80. }
  81. public function is_personalization_step ($context) {
  82. return $context->getRequest()->getParam('personalization') == '1';
  83. }
  84. public function get_next_step_url ($context) {
  85. if (!$this->is_personalization_step($context)) {
  86. //Add personalization parameter to URL
  87. $params = array('personalization' => '1');
  88. //Check if the product page was requested with reorder parameter
  89. //then proxy the parameter to personalization step
  90. if ($this->_getRequest()->has('reorder'))
  91. $params['reorder'] = $this->_getRequest()->getParam('reorder');
  92. //Check if the product page was requested with for-item parameter
  93. //then proxy the parameter to personalization step and ignore last
  94. //visited page (need it to distinguish cross-sell product and already
  95. //personalized product)
  96. if ($this->_getRequest()->has('for-item'))
  97. $params['for-item'] = $this->_getRequest()->getParam('for-item');
  98. else
  99. //Check that the product page was opened from cart page (need for
  100. //automatic first preview update for cross-sell product)
  101. if (strpos(Mage::getSingleton('core/session')->getData('last_url'),
  102. 'checkout/cart') !== false)
  103. //Send update-first-preview query parameter to personalization step
  104. $params['update-first-preview'] = 1;
  105. //Print out url for the product
  106. echo $this->create_url_for_product($context->getProduct(), $params);
  107. return true;
  108. }
  109. else
  110. return false;
  111. }
  112. public function get_params_from_previous_step ($context) {
  113. if (!$this->is_personalization_step($context))
  114. return;
  115. foreach ($_POST as $key => $value) {
  116. if (is_array($value))
  117. foreach ($value as $option_key => $option_value)
  118. echo "<input type=\"hidden\" name=\"{$key}[{$option_key}]\" value=\"$option_value\" />";
  119. else
  120. echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
  121. }
  122. }
  123. public function get_product_image ($context, $product) {
  124. return false;
  125. }
  126. public function get_cart_image ($context, $width = 0, $height = 0) {
  127. $options = unserialize($context->getItem()->getOptionByCode('info_buyRequest')->getValue());
  128. if (!isset($options['zetaprints-previews'])
  129. || !$options['zetaprints-previews'])
  130. return false;
  131. $images = explode(',', $options['zetaprints-previews']);
  132. if (count($images) == 1)
  133. $message = $this->__('Click to enlarge image');
  134. else
  135. $message = $this->__('Click to see more images');
  136. $first_image = true;
  137. $group = 'group-' . mt_rand();
  138. foreach ($images as $image) {
  139. $href = $this->get_preview_url($image);
  140. $src = $this->get_thumbnail_url($image);
  141. if ($first_image) {
  142. echo "<a class=\"in-dialog product-image\" href=\"$href\" rel=\"{$group}\" title=\"{$message}\">";
  143. $first_image = false;
  144. } else
  145. echo "<a class=\"in-dialog product-image\" href=\"$href\" rel=\"{$group}\" style=\"display: none\">";
  146. $style = $width
  147. ? 'style="max-width: ' . $width . 'px;"'
  148. : 'style="max-width: 75px;"';
  149. echo '<img src="', $src, '" ', $style, ' />';
  150. echo "</a>";
  151. }
  152. //If item has low resolution link to PDF...
  153. if (isset($options['zetaprints-order-lowres-pdf'])) {
  154. $href = Mage::getStoreConfig('webtoprint/settings/url')
  155. . $options['zetaprints-order-lowres-pdf'];
  156. $title = $this->__('PDF Proof');
  157. //... show it
  158. echo "<br /><a class=\"zetaprints-lowres-pdf-link\" href=\"{$href}\">{$title}</a>";
  159. }
  160. ?>
  161. <script type="text/javascript">
  162. //<![CDATA[
  163. jQuery(document).ready(function($) {
  164. $('a.in-dialog').fancybox({
  165. 'opacity': true,
  166. 'overlayShow': false,
  167. 'transitionIn': 'elastic',
  168. 'changeSpeed': 200,
  169. 'speedIn': 500,
  170. 'speedOut' : 500,
  171. 'titleShow': false });
  172. });
  173. //]]>
  174. </script>
  175. <?php
  176. return true;
  177. }
  178. public function get_gallery_image ($context) {
  179. return false;
  180. }
  181. public function get_gallery_thumb ($context, $product, $_image) {
  182. return false;
  183. }
  184. public function get_preview_images ($context) {
  185. return false;
  186. }
  187. public function get_preview_image_sharing_link ($context = null) {
  188. $url = Mage::getModel('catalog/product_media_config')
  189. ->getTmpMediaUrl('previews/');
  190. if(substr($url, 0, 1) == '/') {
  191. $url = $this->_getRequest()->getScheme()
  192. . '://'
  193. . $_SERVER['SERVER_NAME']
  194. . $url;
  195. }
  196. ?>
  197. <span class="zetaprints-share-link empty">
  198. <a href="javascript:void(0)"><?php echo $this->__('Share preview'); ?></a>
  199. <input id="zetaprints-share-link-input" type="text" value="" />
  200. </span>
  201. <script type="text/javascript">
  202. //<![CDATA[
  203. var place_preview_image_sharing_link = true;
  204. var preview_image_sharing_link_template = '<?php echo $url; ?>';
  205. jQuery(document).ready(function($) {
  206. $('#zetaprints-share-link-input').focusout(function() {
  207. $(this).parent().removeClass('show');
  208. }).click(function () {
  209. $(this).select();
  210. }).select(function () {
  211. var guid = zp
  212. .template_details
  213. .pages[zp.current_page]['updated-preview-image'];
  214. $.ajax({
  215. url: zp.url.preview_download,
  216. type: 'POST',
  217. dataType: 'json',
  218. data: 'guid=' + guid,
  219. error: function (XMLHttpRequest, textStatus, errorThrown) {
  220. alert(preview_sharing_link_error_text + ': ' + textStatus);
  221. },
  222. success: function (data, textStatus) {
  223. //Check returned status'
  224. if (data != 'OK')
  225. alert(data);
  226. }
  227. });
  228. }).val('');
  229. $('span.zetaprints-share-link a').click(function () {
  230. var parent = $(this).parent();
  231. if (!$(parent).hasClass('empty')) {
  232. $(parent).addClass('show');
  233. $('#zetaprints-share-link-input').focus();
  234. }
  235. });
  236. });
  237. //]]>
  238. </script>
  239. <?php
  240. }
  241. public function get_preview_image ($context) {
  242. if (!$context->getProduct()->getSmallImage())
  243. return false;
  244. $img = '<img src="' . $context->helper('catalog/image')->init($context->getProduct(), 'small_image')->resize(265) . '" alt="'.$context->htmlEscape($context->getProduct()->getSmallImageLabel()).'" />';
  245. echo $context->helper('catalog/output')->productAttribute($context->getProduct(), $img, 'small_image');
  246. return true;
  247. }
  248. public function get_text_fields ($context) {
  249. $html = $this->get_form_part_html('text-fields', $context->getProduct());
  250. if ($html === false)
  251. return false;
  252. echo $html;
  253. return true;
  254. }
  255. public function get_image_fields ($context) {
  256. $params = array(
  257. 'ajax-loader-image-url'
  258. => Mage::getDesign()->getSkinUrl('images/spinner.gif'),
  259. 'user-image-edit-button'
  260. => Mage::getDesign()->getSkinUrl('images/image-edit/edit.png'),
  261. 'photothumbnail-url-height-100-template'
  262. => $this->get_photo_thumbnail_url('image-guid.image-ext', 0, 100),
  263. 'photothumbnail-url-template'
  264. => $this->get_photo_thumbnail_url('image-guid.image-ext'),
  265. 'show-image-field'
  266. => (bool) $this->getCustomOptions('fields/image@show-on-load=1')
  267. );
  268. $html = $this->get_form_part_html('image-fields', $context->getProduct(), $params);
  269. if ($html === false)
  270. return false;
  271. echo $html;
  272. return true;
  273. }
  274. private function add_user_images ($xml) {
  275. $url = Mage::getStoreConfig('webtoprint/settings/url');
  276. $key = Mage::getStoreConfig('webtoprint/settings/key');
  277. $user_credentials = $this->get_zetaprints_credentials();
  278. $data = array(
  279. 'ID' => $user_credentials['id'],
  280. 'Hash' => zetaprints_generate_user_password_hash($user_credentials['password']) );
  281. $images = zetaprints_get_user_images ($url, $key, $data);
  282. if ($images === null)
  283. return;
  284. foreach ($xml->Images->Image as $image_node)
  285. if (isset($image_node['AllowUpload']))
  286. foreach ($images as $image) {
  287. $user_image_node = $image_node->addChild('user-image');
  288. $user_image_node->addAttribute('guid', $image['guid']);
  289. if ($image['mime'] === 'image/jpeg' || $image['mime'] === 'image/jpg')
  290. $thumbnail_url = $this->get_photo_thumbnail_url($image['thumbnail'], 0, 100);
  291. else
  292. $thumbnail_url = $this->get_photo_thumbnail_url($image['thumbnail']);
  293. $user_image_node->addAttribute('thumbnail', $thumbnail_url);
  294. $user_image_node->addAttribute('mime', $image['mime']);
  295. $user_image_node->addAttribute('description', $image['description']);
  296. $user_image_node->addAttribute('edit-link',
  297. $this->_getUrl('web-to-print/image/',
  298. array('id' => $image['guid'], 'iframe' => 1) ));
  299. }
  300. }
  301. public function get_page_tabs ($context) {
  302. $html = $this->get_form_part_html('page-tabs', $context->getProduct());
  303. if ($html === false)
  304. return false;
  305. echo $html;
  306. return true;
  307. }
  308. public function get_preview_button ($context) {
  309. echo $context->getChildHtml('webtoprint_buttons');
  310. }
  311. public function get_next_page_button ($context) {
  312. return false;
  313. }
  314. public function prepare_gallery_images ($context, $check_for_personalization = false) {
  315. if (!$this->get_template_id($context->getProduct()))
  316. return false;
  317. if ($check_for_personalization && !$this->is_personalization_step($context))
  318. return false;
  319. $images = $context->getProduct()->getMediaGalleryImages();
  320. foreach ($images as $image)
  321. if(strpos(basename($image['path']), 'zetaprints_') === 0)
  322. $images->removeItemByKey($image->getId());
  323. //$images = $context->getProduct()->getMediaGallery('images');
  324. //foreach ($images as &$image)
  325. // if(strpos(basename($image['file']), 'zetaprints_') === 0)
  326. // $image['disabled'] = 1;
  327. //$context->getProduct()->setMediaGallery('images', $images);
  328. }
  329. public function get_js_css_includes ($context=null) {
  330. ?>
  331. <script type="text/javascript">
  332. //<![CDATA[
  333. alert('<?php echo __FUNCTION__; ?>() function has been deprecated. See release notes in http://code.google.com/p/magento-w2p/wiki/ReleaseNotes');
  334. //]]>
  335. </script>
  336. <?php
  337. return false;
  338. }
  339. public function get_admin_js_css_includes ($context = null) {
  340. ?>
  341. <script type="text/javascript">
  342. //<![CDATA[
  343. alert('<?php echo __FUNCTION__; ?>() function has been deprecated. See release notes in http://code.google.com/p/magento-w2p/wiki/ReleaseNotes');
  344. //]]>
  345. </script>
  346. <?php
  347. return false;
  348. }
  349. public function get_order_webtoprint_links ($context, $item = null) {
  350. $isAdmin = false;
  351. if (!$item) {
  352. $item = $context->getItem();
  353. $isAdmin = true;
  354. }
  355. $options = $item->getProductOptionByCode('info_buyRequest');
  356. //Check for ZetaPrints Template ID in item options
  357. //If it doesn't exist or product doesn't have web-to-print features then...
  358. if (!isset($options['zetaprints-TemplateID']))
  359. //... just return from the function.
  360. return;
  361. $isOrderComplete = isset($options['zetaprints-order-completed'])
  362. && $options['zetaprints-order-completed'];
  363. if ($isAdmin && !$isOrderComplete) {
  364. $url = Mage::helper('adminhtml')
  365. ->getUrl('web-to-print-admin/order/complete',
  366. array('item' => $item->getId()));
  367. $title = $this->__('Complete order on ZetaPrints');
  368. echo '<br />'
  369. . "<a id=\"zp-complete-order-link\" href=\"{$url}\">{$title}</a>";
  370. }
  371. if ($isAdmin && isset($options['zetaprints-previews'])
  372. && !$options['zetaprints-previews']) {
  373. $input = array();
  374. foreach ($options as $key => $value) {
  375. //Ignore key if it doesn't start with 'zetaprints-' prefix
  376. if (strpos($key, 'zetaprints-') !== 0)
  377. continue;
  378. //Remove prefix from the key
  379. $_key = substr($key, 11);
  380. if (!(strpos($_key, '_') === 0 || strpos($_key, '#') === 0
  381. || strpos($_key, '*') === 0))
  382. continue;
  383. if (strpos($_key, '#') === 0) {
  384. if (! $details = $context->getTemplateDetails()) {
  385. $details = $this
  386. ->getTemplateDetailsByGUID($options['zetaprints-TemplateID']);
  387. if ($details)
  388. $context->setTemplateDetails($details);
  389. }
  390. if ($details) {
  391. if (! $stockImages = $context->getStockImages()) {
  392. $stockImages = array();
  393. foreach ($details['pages'] as $page)
  394. foreach ($page['images'] as $imageField)
  395. if (isset($imageField['stock-images']))
  396. foreach ($imageField['stock-images'] as $image)
  397. if (!isset($stockImages[$image['guid']])) {
  398. $tokens = explode('.', $image['thumb']);
  399. $stockImages[$image['guid']]
  400. = array('thumb' => $image['thumb'],
  401. 'small-thumb'
  402. => $tokens[0] . '_0x100.' . $tokens[1] );
  403. }
  404. $context->setStockImages($stockImages);
  405. }
  406. if (isset($stockImages[$value])) {
  407. $url = Mage::getStoreConfig('webtoprint/settings/url')
  408. . 'photothumbs/'
  409. . $stockImages[$value]['thumb'];
  410. $small_url = Mage::getStoreConfig('webtoprint/settings/url')
  411. . 'photothumbs/'
  412. . $stockImages[$value]['small-thumb'];
  413. $value = "<a href=\"{$url}\" target=\"_blank\">" .
  414. "<image src=\"{$small_url}\" />" .
  415. "</a>";
  416. } else {
  417. if (! $userImages = $context->getUserImages()) {
  418. $customer = Mage::getModel('customer/customer')
  419. ->load($item->getOrder()->getCustomerId());
  420. $userImages = array();
  421. if ($customer->getId()) {
  422. $url = Mage::getStoreConfig('webtoprint/settings/url');
  423. $key = Mage::getStoreConfig('webtoprint/settings/key');
  424. $data = array(
  425. 'ID' => $customer->getZetaprintsUser(),
  426. 'Hash' => zetaprints_generate_user_password_hash(
  427. $customer->getZetaprintsPassword()) );
  428. $userImages = zetaprints_get_user_images($url, $key, $data);
  429. $context->setUserImages($userImages);
  430. }
  431. }
  432. if (isset($userImages[$value])) {
  433. $url = Mage::getStoreConfig('webtoprint/settings/url')
  434. . 'photothumbs/'
  435. . $userImages[$value]['thumbnail'];
  436. $tokens = explode('.', $userImages[$value]['thumbnail']);
  437. $small_url = Mage::getStoreConfig('webtoprint/settings/url')
  438. . 'photothumbs/'
  439. . $tokens[0] . '_0x100.' . $tokens[1];
  440. $value = "<a href=\"{$url}\" target=\"_blank\">" .
  441. "<image src=\"{$small_url}\" />" .
  442. "</a>";
  443. }
  444. }
  445. }
  446. if ($value === '#')
  447. $value = $this->__('Default');
  448. if ($value === '')
  449. $value = $this->__('Blank');
  450. } else
  451. $value = "<pre>{$value}</pre>";
  452. //Determine length of field prefix
  453. $prefix_length = 0;
  454. if (strpos($_key, '*') === 0)
  455. $prefix_length = 1;
  456. //Process field name (key), restore original symbols
  457. $_key = substr($_key, 0, $prefix_length)
  458. . str_replace( array('_', "\x0A"),
  459. array(' ', '.'),
  460. substr($_key, $prefix_length + 1) );
  461. //Add token to the array
  462. $input[$_key] = $value;
  463. }
  464. if (count($input)) {
  465. $product = Mage::getModel('catalog/product')->load($options['product']);
  466. if ($product->getId()) {
  467. $productUrl = $product->getProductUrl();
  468. $productName = $product->getName();
  469. }
  470. ?>
  471. <div style="display: none;">
  472. <div id ="zp-user-input-table">
  473. <?php if (isset($productUrl)): ?>
  474. <a href="<?php echo $productUrl; ?>">
  475. <?php echo $productName; ?>
  476. </a>
  477. <?php endif; ?>
  478. <table id ="zp-user-input-table">
  479. <thead>
  480. <tr>
  481. <th><?php echo $this->__('Name'); ?></th>
  482. <th><?php echo $this->__('Value'); ?></th>
  483. </tr>
  484. </thead>
  485. <tbody>
  486. <?php foreach ($input as $name => $value): ?>
  487. <tr>
  488. <td><?php echo $name; ?></td>
  489. <td><?php echo $value; ?></td>
  490. </tr>
  491. <?php endforeach ?>
  492. </tbody>
  493. </table>
  494. </div>
  495. </div>
  496. <br />
  497. <a id ="zp-user-input-link" href="#zp-user-input-table">
  498. <?php echo $this->__('Show customer\'s input data'); ?>
  499. </a>
  500. <?php
  501. }
  502. }
  503. //Get value of custom option which allows users download files
  504. //regardless of ZP template setting
  505. $is_user_allowed_download = Mage::helper('webtoprint')
  506. ->getCustomOptions('file-download/users@allow=1');
  507. //Check that downloading generated files is allowed for users
  508. if (!$isAdmin && !$is_user_allowed_download) {
  509. $template = Mage::getModel('webtoprint/template')
  510. ->load($options['zetaprints-TemplateID']);
  511. if (!$template->getId())
  512. return;
  513. try {
  514. $xml = new SimpleXMLElement($template->getXml());
  515. } catch (Exception $e) {
  516. Mage::log("Exception: {$e->getMessage()}");
  517. return;
  518. }
  519. if (!$xml)
  520. return;
  521. $template_details = zetaprints_parse_template_details($xml);
  522. if (!$template_details['download'])
  523. return;
  524. }
  525. $webtoprint_links = '<br />';
  526. $types = array('pdf', 'gif', 'png', 'jpeg');
  527. //If function called from admin template
  528. if ($isAdmin)
  529. //then add CDR file type to list of available types
  530. array_push($types, 'cdr');
  531. foreach ($types as $type)
  532. if (isset($options['zetaprints-file-'.$type])) {
  533. $title = strtoupper($type);
  534. $webtoprint_links .= "<a class=\"zetaprints-order-file-link {$type}\" href=\"{$options['zetaprints-file-'.$type]}\" target=\"_blank\">$title</a>&nbsp;";
  535. }
  536. //Check if the item is not null (it means the function was called from admin
  537. //interface) and ZetaPrints Order ID option is in the item then...
  538. if ($isAdmin && isset($options['zetaprints-order-id'])) {
  539. //... create URL to order details on web-to-print site
  540. $zp_order_url = Mage::getStoreConfig('webtoprint/settings/url')
  541. . '?page=order-details;OrderID='
  542. . $options['zetaprints-order-id'];
  543. //Display it on the page
  544. $webtoprint_links .=" <a target=\"_blank\" href=\"{$zp_order_url}\">ZP order</a>";
  545. }
  546. return $webtoprint_links;
  547. }
  548. public function get_order_preview_images ($context, $item = null) {
  549. if ($item)
  550. $options = $item->getProductOptionByCode('info_buyRequest');
  551. else
  552. $options = $context->getItem()->getProductOptionByCode('info_buyRequest');
  553. if (!(isset($options['zetaprints-previews'])
  554. || isset($options['zetaprints-downloaded-previews'])))
  555. return;
  556. $dynamicImaging = isset($options['zetaprints-dynamic-imaging'])
  557. ? $options['zetaprints-dynamic-imaging'] : false;
  558. $previews = $dynamicImaging ? $options['zetaprints-downloaded-previews']
  559. : explode(',', $options['zetaprints-previews']);
  560. $group = 'group-' . mt_rand();
  561. $url = Mage::getStoreConfig('webtoprint/settings/url');
  562. ?>
  563. <tr class="border zetaprints-previews">
  564. <td class="last" colspan="<?php echo $item ? 5 : 10; ?>">
  565. <div class="zetaprints-previews-box <?php if ($item) echo 'hidden'; ?>">
  566. <div class="title">
  567. <a class="show-title">+&nbsp;<span><?php echo $this->__('Show previews');?></span></a>
  568. <a class="hide-title">&minus;&nbsp;<span><?php echo $this->__('Hide previews');?></span></a>
  569. </div>
  570. <div class="content">
  571. <ul>
  572. <?php foreach ($previews as $preview): ?>
  573. <li>
  574. <?php if ($dynamicImaging): ?>
  575. <a href="<?php echo $preview; ?>" target="_blank">
  576. <?php echo $this->__('Download image');?>
  577. </a>
  578. <br />
  579. <a class="in-dialog zetaprints-dynamic-imaging"
  580. href="<?php echo $preview; ?>"
  581. target="_blank"
  582. rel="<?php echo $group; ?>">
  583. <img src="<?php echo $preview; ?>"
  584. title="<?php echo $this->__('Click to enlarge image'); ?>"/>
  585. </a>
  586. <?php else: ?>
  587. <a class="in-dialog" href="<?php echo $this->get_preview_url($preview); ?>" target="_blank" rel="<?php echo $group; ?>">
  588. <img src="<?php echo $this->get_thumbnail_url($preview); ?>" title="<?php echo $this->__('Click to enlarge image');?>"/>
  589. </a>
  590. <?php endif ?>
  591. </li>
  592. <?php endforeach ?>
  593. </ul>
  594. </div>
  595. </div>
  596. </td>
  597. </tr>
  598. <?php
  599. }
  600. public function getOrderPreviewImagesForEmail ($context, $item) {
  601. $options = $item->getProductOptionByCode('info_buyRequest');
  602. if (!(isset($options['zetaprints-previews'])
  603. || isset($options['zetaprints-downloaded-previews'])))
  604. return;
  605. $dynamicImaging = isset($options['zetaprints-dynamic-imaging'])
  606. ? $options['zetaprints-dynamic-imaging'] : false;
  607. $previews = $dynamicImaging ? $options['zetaprints-downloaded-previews']
  608. : explode(',', $options['zetaprints-previews']);
  609. ?>
  610. <tr>
  611. <td colspan="4"
  612. style=" border-bottom:2px solid #CCCCCC; padding:3px 9px;">
  613. <?php foreach ($previews as $preview): ?>
  614. <?php
  615. $url = $dynamicImaging ? $preview : $this->get_preview_url($preview);
  616. $thumb = $dynamicImaging ? $preview : $this->get_thumbnail_url($preview);
  617. ?>
  618. <a href="<?php echo $this->get_preview_url($preview); ?>"
  619. style="text-decoration: none"
  620. target="_blank">
  621. <img src="<?php echo $this->get_thumbnail_url($preview); ?>"
  622. title="<?php echo $this->__('Click to enlarge image');?>" />
  623. </a>
  624. <?php endforeach ?>
  625. </td>
  626. </tr>
  627. <?php
  628. }
  629. public function get_reorder_button ($context, $item) {
  630. $options = $item->getProductOptionByCode('info_buyRequest');
  631. //Check for ZetaPrints Order ID in item options
  632. //If it doesn't exist or product doesn't have web-to-print features then...
  633. if (!isset($options['zetaprints-order-id']))
  634. //... just return from the function.
  635. return;
  636. $product = Mage::getModel('catalog/product')->load($options['product']);
  637. if (!$product->getId())
  638. return;
  639. $url = $product->getUrlInStore(array('_query'
  640. => array('reorder' => $options['zetaprints-order-id'])));
  641. echo "<a class=\"zetaprints-reorder-item-link\" href=\"{$url}\">Reorder</a>";
  642. }
  643. public function get_js_for_order_preview_images ($context) {
  644. ?>
  645. <script type="text/javascript">
  646. //<![CDATA[
  647. jQuery(document).ready(function($) {
  648. var $boxes = $('div.zetaprints-previews-box');
  649. function set_width_for_boxes () {
  650. var width = $('#my-orders-table, table.order-tables')
  651. .find('tr.zetaprints-previews td')
  652. .width();
  653. if (width != 0) {
  654. $boxes
  655. .find('div.content')
  656. .width(width - 1)
  657. .end()
  658. .removeClass('hidden');
  659. } else
  660. setTimeout(set_width_for_boxes, 1000);
  661. }
  662. function set_width_for_ul () {
  663. if ($('a.in-dialog img:visible').length != 0)
  664. $boxes.each(function () {
  665. var width = 0;
  666. $(this).find('li').each(function () {
  667. width += $(this).outerWidth(true);
  668. });
  669. $(this).find('ul').width(width);
  670. });
  671. else
  672. setTimeout(set_width_for_ul, 1000);
  673. }
  674. $(window).load(function () {
  675. set_width_for_boxes();
  676. set_width_for_ul();
  677. });
  678. $boxes.find('a.show-title').each(function () {
  679. $(this).click(function () {
  680. $(this).parents('div.zetaprints-previews-box').removeClass('hide');
  681. });
  682. });
  683. $boxes.find('a.hide-title').each(function () {
  684. $(this).click(function () {
  685. $(this).parents('div.zetaprints-previews-box').addClass('hide');
  686. });
  687. });
  688. $('a.in-dialog').fancybox({
  689. 'opacity': true,
  690. 'overlayShow': false,
  691. 'transitionIn': 'elastic',
  692. 'changeSpeed': 200,
  693. 'speedIn': 500,
  694. 'speedOut' : 500,
  695. 'titleShow': false });
  696. $('#zp-user-input-link').fancybox();
  697. $('#zp-complete-order-link').click(function () {
  698. $('<div class="zp-overlay">' +
  699. '<div class="zp-overlay-spinner">' +
  700. '<div />' +
  701. '</div>' +
  702. '<span class="zp-overlay-text">' +
  703. '<?php echo $this->__('Completing order on ZetaPrints'); ?> &hellip;' +
  704. '</span>' +
  705. '</div>')
  706. .appendTo('body');
  707. });
  708. });
  709. //]]>
  710. </script>
  711. <?php
  712. }
  713. public function show_hide_all_order_previews ($context) {
  714. ?>
  715. <a href="#" class="all-order-previews">
  716. <span class="show-title"><?php echo $this->__('Show all order previews');?></span>
  717. <span class="hide-title"><?php echo $this->__('Hide all order previews');?></span>
  718. </a>
  719. <script type="text/javascript">
  720. //<![CDATA[
  721. jQuery(document).ready(function($) {
  722. $('a.all-order-previews').toggle(
  723. function () {
  724. $(this).addClass('hide-all');
  725. $('div.zetaprints-previews-box').addClass('hide');
  726. },
  727. function () {
  728. $(this).removeClass('hide-all');
  729. $('div.zetaprints-previews-box').removeClass('hide');
  730. }
  731. );
  732. });
  733. //]]>
  734. </script>
  735. <?php
  736. }
  737. public function getPageSizeTable ($context, $units = 'in') {
  738. $params = array(
  739. 'page-size-units' => $units,
  740. 'page-size-icon'
  741. => Mage::getDesign()->getSkinUrl('images/page-size-icon.png') );
  742. $result = $this->get_form_part_html('page-size-table',
  743. $context->getProduct(),
  744. $params );
  745. echo $result ? $result : '';
  746. }
  747. public function getDataSetTable ($context) {
  748. if (! $templateId = $this->get_template_id($context->getProduct()))
  749. return false;
  750. if (! $xml = Mage::registry('webtoprint-template-xml')) {
  751. $template = Mage::getModel('webtoprint/template')->loadById($templateId);
  752. if ($template->getId())
  753. try {
  754. $xml = new SimpleXMLElement($xml = $template->getXml());
  755. } catch (Exception $e) {
  756. Mage::log("Exception: {$e->getMessage()}");
  757. }
  758. }
  759. if (!$xml)
  760. return false;
  761. $templateDetails = zetaprints_parse_template_details($xml);
  762. $dataset = array();
  763. $fieldNames = array();
  764. foreach ($templateDetails['pages'] as $pageNumber => $page) {
  765. if (!isset($page['fields']))
  766. continue;
  767. $_dataset = array();
  768. foreach ($page['fields'] as $field)
  769. if (isset($field['dataset'])) {
  770. foreach ($field['dataset'] as $number => $data) {
  771. if (! isset($_dataset[$number]))
  772. $_dataset[$number] = array();
  773. $_dataset[$number][] = $data;
  774. }
  775. $fieldNames[] = $field['name'];
  776. }
  777. if (count($_dataset))
  778. $dataset[$pageNumber] = $_dataset;
  779. }
  780. if (!count($dataset))
  781. return;
  782. ?>
  783. <div class="zp-dataset-wrapper">
  784. <?php foreach ($dataset as $pageNumber => $_dataset): ?>
  785. <div id="zp-dataset-page-<?php echo $pageNumber; ?>" class="zp-dataset">
  786. <table id="zp-dataset-table-page-<?php echo $pageNumber; ?>" class="zp-dataset-table">
  787. <thead>
  788. <tr>
  789. <th></th>
  790. <?php
  791. if (isset($templateDetails['pages'][$pageNumber]['fields'])):
  792. $fields = $templateDetails['pages'][$pageNumber]['fields'];
  793. foreach ($fields as $field):
  794. if (isset($field['dataset'])):
  795. ?>
  796. <th><?php echo $this->__($field['name']); ?></th>
  797. <?php
  798. endif;
  799. endforeach;
  800. endif;
  801. ?>
  802. </tr>
  803. </thead>
  804. <tbody>
  805. <?php foreach ($_dataset as $set): ?>
  806. <tr>
  807. <td class="zp-dataset-checkbox"><input type="checkbox" name="test" /></td>
  808. <?php foreach ($set as $number => $data): ?>
  809. <td class="<?php echo $fieldNames[$number]; ?>">
  810. <?php foreach ($data['lines'] as $line => $text): ?>
  811. <p <?php if (!$line): ?>class="zp-dataset-first-line"<?php endif ?>><?php echo $text; ?></p>
  812. <?php endforeach ?>
  813. </td>
  814. <?php endforeach; ?>
  815. </tr>
  816. <?php endforeach; ?>
  817. </tbody>
  818. </table>
  819. <p class="zp-dataset-notice">
  820. <?php echo $this->__('* Click on a cell to insert the value or click on the first column to insert the entire row.'); ?>
  821. </p>
  822. </div>
  823. <?php endforeach; ?>
  824. </div>
  825. <?php $title = $this->__('Database look-up'); ?>
  826. <button id="zp-dataset-button" class="button hidden" title="<?php echo $title; ?>" type="button">
  827. <span><span><?php echo $title; ?></span></span>
  828. </button>
  829. <?php
  830. }
  831. /**
  832. * @deprecated Replaced with camelCased version
  833. */
  834. public function get_js ($context) {
  835. return $this->getJs($context);
  836. }
  837. public function getJs ($context) {
  838. $product = $context->getProduct();
  839. if (!$this->get_template_id($product))
  840. return false;
  841. if (!$details = $this->getTemplateDetailsForCurrentProduct())
  842. return false;
  843. $details['pages_number'] = count($details['pages']);
  844. $name = $product->getName();
  845. $previews = array();
  846. foreach ($details['pages'] as $page) {
  847. $guid = explode('preview/', $page['preview-image']);
  848. echo '<img src="', $this->get_preview_url($guid[1]), '" alt="Printable ',
  849. $name, '" class="zp-hidden" />';
  850. }
  851. $session = Mage::getSingleton('core/session');
  852. if ($session->hasData('zetaprints-previews')) {
  853. $userInput = unserialize($session->getData('zetaprints-user-input'));
  854. $session->unsetData('zetaprints-previews');
  855. }
  856. $request = $this->_getRequest();
  857. //Check if the product page is requested with 'for-item' parameter
  858. $hasForItem = $request->has('for-item');
  859. //Check if the product page is requested
  860. //with 'update-first-preview' parameter
  861. $hasUpdateFirstPreview = $request->getParam('update-first-preview') == '1';
  862. //Check if the product page is requested with 'reorder' parameter
  863. $hasReorder = strlen($request->getParam('reorder')) == 36;
  864. $lastUrl = $session->getData('last_url');
  865. //Check if the product page is opened from the shopping cart
  866. //to update first preview image for cross-sell products)
  867. $isFromShoppingCart = strpos($lastUrl, 'checkout/cart') !== false;
  868. $updateFirstPreview = $hasForItem
  869. || $hasReorder
  870. || $hasUpdateFirstPreview
  871. || $isFromShoppingCart
  872. || $product->getConfigureMode();
  873. $preserveFields = $product->getConfigureMode()
  874. || $hasReorder
  875. || $hasUpdateFirstPreview
  876. || $hasForItem;
  877. $preserveFields = !$preserveFields;
  878. $hasShapes = false;
  879. foreach ($details['pages'] as $page)
  880. if (isset($page['shapes'])) {
  881. $hasShapes = true;
  882. break;
  883. }
  884. $data = json_encode(array(
  885. 'template_details' => $details,
  886. 'is_personalization_step' => $this->is_personalization_step($context),
  887. 'update_first_preview_on_load' => $updateFirstPreview,
  888. 'preserve_fields' => $preserveFields,
  889. 'has_shapes' => $hasShapes,
  890. 'w2p_url' => Mage::getStoreConfig('webtoprint/settings/url'),
  891. 'options' => $this->getCustomOptions(),
  892. 'url' => array(
  893. 'preview' => $this->_getUrl('web-to-print/preview'),
  894. 'preview_download' => $this->_getUrl('web-to-print/preview/download'),
  895. 'upload' => $this->_getUrl('web-to-print/upload'),
  896. 'upload_by_url' => $this->_getUrl('web-to-print/upload/byurl'),
  897. 'image' => $this->_getUrl('web-to-print/image/update'),
  898. 'user-image-template'
  899. => $this->get_photo_thumbnail_url('image-guid.image-ext'),
  900. 'edit-image-template' => $this->get_image_editor_url('')
  901. )
  902. ));
  903. ?>
  904. <script type="text/javascript">
  905. //<![CDATA[
  906. // Global vars go here
  907. var image_imageName = ''; //currently edited template image
  908. var userImageThumbSelected = null; //user selected image to edit
  909. // Global vars end
  910. jQuery(document).ready(function($) {
  911. <?php
  912. if (isset($userInput) && is_array($userInput))
  913. foreach ($userInput as $key => $value)
  914. echo '$(\'[name="' . $key . '"]\').val(\'' . $value . '\');\n';
  915. ?>
  916. zp = <?php echo $data ?>;
  917. edit_button_text = "<?php echo $this->__('Edit');?>";
  918. delete_button_text = "<?php echo $this->__('Delete'); ?>";
  919. save_text = "<?php echo $this->__('Save');?>";
  920. saved_text = "<?php echo $this->__('Saved');?>";
  921. update_preview_button_text = "<?php echo $this->__('Update preview'); ?>";
  922. use_image_button_text = "<?php echo $this->__('Use image'); ?>";
  923. selected_image_button_text = "<?php echo $this->__('Selected image'); ?>";
  924. updating_preview_image_text = "<?php echo $this->__('Updating preview image'); ?>"
  925. cannot_update_preview = "<?php echo $this->__('Cannot update the preview. Try again.'); ?>";
  926. cannot_update_preview_second_time = "<?php echo $this->__('Cannot update the preview. Try again or add to cart as is and we will update it manually.'); ?>";
  927. preview_sharing_link_error_text = "<?php echo $this->__('Error was occurred while preparing preview image'); ?>";
  928. uploading_image_error_text = "<?php echo $this->__('Error was occurred while uploading image'); ?>";
  929. notice_to_update_preview_text = "<?php echo $this->__('Update preview first!'); ?>";
  930. notice_to_update_preview_text_for_multipage_template = "<?php echo $this->__('Update all previews first!'); ?>";
  931. click_to_close_text = "<?php echo $this->__('Click to close'); ?>";
  932. click_to_view_in_large_size = "<?php echo $this->__('Click to view in large size');?>";
  933. click_to_delete_text = "<?php echo $this->__('Click to delete'); ?>";
  934. click_to_edit_text = "<?php echo $this->__('Click to edit'); ?>";
  935. cant_delete_text = "<?php echo $this->__('Can\'t delete image'); ?>";
  936. delete_this_image_text = "<?php echo $this->__('Delete this image?'); ?>";
  937. personalization_form.apply(zp, [$]);
  938. });
  939. //]]>
  940. </script>
  941. <?php
  942. }
  943. }
  944. ?>