PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/FormHelper.class.php

http://flumpshop.googlecode.com/
PHP | 94 lines | 80 code | 12 blank | 2 comment | 17 complexity | e2bacb5823322c97c87acfe532772185 MD5 | raw file
  1. <?php
  2. class FormHelper {
  3. function countrySelector($id = 'countrySelector',$supportedOnly = false) {
  4. global $config, $dbConn;
  5. if ($supportedOnly) {
  6. //Supported
  7. if ($config->isNode('cache','supportedCountrySelector')) {
  8. return str_replace('[[name]]',$id,$config->getNode('cache','supportedCountrySelector')); //Use cache if available
  9. } else {
  10. ob_start();
  11. $result = $dbConn->query("SELECT * FROM `country` WHERE supported=1 ORDER BY name ASC");
  12. echo '<select name="'.$id.'" id="'.$id.'" class="ui-widget-content required"><option value=""></option>';
  13. while ($row = $dbConn->fetch($result)) {
  14. echo '<option value="'.$row['iso'].'">'.$row['name'].'</option>';
  15. }
  16. echo '</select>';
  17. $return = ob_get_clean();
  18. $cache = str_replace($id,"[[name]]",$return);
  19. $config->setNode('cache','supportedCountrySelector',$cache);
  20. return $return;
  21. }
  22. } else {
  23. //All
  24. if ($config->isNode('cache','fullCountrySelector')) {
  25. return str_replace('[[name]]',$id,$config->getNode('cache','fullCountrySelector')); //Use cache if available
  26. } else {
  27. ob_start();
  28. $result = $dbConn->query("SELECT * FROM `country` ORDER BY name ASC");
  29. echo '<select name="'.$id.'" id="'.$id.'" class="ui-widget-content required" style="width: 150px;"><option value=""></option>';
  30. while ($row = $dbConn->fetch($result)) {
  31. if ($row['iso'] == $config->getNode('site','country')) {
  32. echo '<option value="'.$row['iso'].'" selected="selected">'.$row['name'].'</option>';
  33. } else
  34. echo '<option value="'.$row['iso'].'">'.$row['name'].'</option>';
  35. }
  36. echo '</select>';
  37. $return = ob_get_clean();
  38. $cache = str_replace($id,'[[name]]',$return);
  39. $config->setNode('cache','fullCountrySelector',$cache);
  40. return $return;
  41. }
  42. }
  43. }
  44. function orderStatusSelector($id) {
  45. global $config;
  46. if ($config->isNode('cache','orderStatusSelector')) {
  47. return str_replace('[[name]]',$id,$config->getNode('cache','orderStatusSelector')); //Use cache if available
  48. } else {
  49. ob_start();
  50. ?>
  51. <select name="<?php echo $id;?>" id="<?php echo $id;?>" class="ui-widget required">
  52. <option disabled="disabled"></option>
  53. <?php
  54. $orderStats = array_keys($config->getNodes('orderstatus'));
  55. foreach ($orderStats as $status) {
  56. if (!is_int($status)) continue;
  57. $array = $config->getNode('orderstatus',$status);
  58. echo "<option value='".$status."'>".$array['name']."</option>";
  59. }
  60. ?>
  61. </select>
  62. <?php
  63. $return = ob_get_clean();
  64. $cache = str_replace($id,'[[name]]',$return);
  65. $config->setNode('cache','orderStatusSelector',$cache);
  66. return $return;
  67. }
  68. }
  69. static function deliveryTierSelector($name,$current) {
  70. global $config;
  71. $i = 0;
  72. $reply = '<select class="ui-widget-content" name="'.$name.'" id="'.$name.'">';
  73. while ($config->isTree('deliveryTier'.$i)) {
  74. if ($i == $current) $append = ' selected="selected"'; else $append = '';
  75. $reply .= '<option value="'.$i.'"'.$append.'>'.$config->getNode('deliveryTier'.$i,'name').' (Â?'.$config->getNode('deliveryTier'.$i,'value').')</option>';
  76. $i++;
  77. }
  78. $reply .= '</select>';
  79. return $reply;
  80. }
  81. }
  82. ?>