PageRenderTime 31ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/download_multi.php

http://candydolldb.googlecode.com/
PHP | 156 lines | 121 code | 31 blank | 4 comment | 9 complexity | ae79deb1651a0dc1249c76cd5c5d1884 MD5 | raw file
  1. <?php
  2. include('cd.php');
  3. ini_set('max_execution_time', '3600');
  4. $CurrentUser = Authentication::Authenticate();
  5. if(!$CurrentUser->hasPermission(RIGHT_EXPORT_ZIP_MULTI))
  6. {
  7. $e = new Error(RIGHTS_ERR_USERNOTALLOWED);
  8. Error::AddError($e);
  9. HTMLstuff::RefererRedirect();
  10. }
  11. HTMLstuff::RefererRegister($_SERVER['REQUEST_URI']);
  12. $Models = NULL;
  13. $ModelsOptions = NULL;
  14. $SetsOptions = NULL;
  15. $ImagesOptions = NULL;
  16. $ButtonText = $lang->g('ButtonNext');
  17. $Models = Model::GetModels();
  18. $UseSubfoldersInDownload = array_key_exists('chkSubfolders', $_POST) && isset($_POST['chkSubfolders']);
  19. if(array_key_exists('hidAction', $_POST) && $_POST['hidAction'] == 'DownloadMulti')
  20. {
  21. $ModelsOptions = NULL;
  22. $SetsOptions = NULL;
  23. $SelectedModelIDs = array_key_exists('selModels', $_POST) ? Utils::SafeInts($_POST['selModels']) : array();
  24. /* @var $Model Model */
  25. foreach ($Models as $Model)
  26. {
  27. $ModelsOptions .= sprintf("<option value=\"%1\$d\"%3\$s>%2\$s</option>",
  28. $Model->getID(),
  29. htmlentities($Model->GetFullName()),
  30. in_array($Model->getID(), $SelectedModelIDs) ? ' selected="selected"' : NULL
  31. );
  32. }
  33. if($SelectedModelIDs)
  34. {
  35. $Sets = Set::GetSets(new SetSearchParameters(FALSE, FALSE, FALSE, $SelectedModelIDs));
  36. $SelectedSetIDs = array_key_exists('selSets', $_POST) ? Utils::SafeInts($_POST['selSets']) : array();
  37. /* @var $Set Set */
  38. foreach ($Sets as $Set)
  39. {
  40. $SetsOptions .= sprintf("<option value=\"%1\$d\"%5\$s>%2\$s - %3\$s%4\$s</option>",
  41. $Set->getID(),
  42. htmlentities($Set->getModel()->GetFullName()),
  43. htmlentities($Set->getPrefix()),
  44. htmlentities($Set->getName()),
  45. in_array($Set->getID(), $SelectedSetIDs) ? ' selected="selected"' : NULL
  46. );
  47. }
  48. if($SelectedSetIDs)
  49. {
  50. $Images = Image::GetImages(new ImageSearchParameters(FALSE, FALSE, FALSE, $SelectedSetIDs));
  51. $SelectedImageIDs = array_key_exists('selImages', $_POST) ? Utils::SafeInts($_POST['selImages']) : array();
  52. $ButtonText = $lang->g('ButtonDownload');
  53. /* @var $Image Image */
  54. foreach ($Images as $Image)
  55. {
  56. if(!in_array($Image->getSet()->getModel()->getID(), $SelectedModelIDs))
  57. { continue; }
  58. $ImagesOptions .= sprintf("<option value=\"%1\$d\"%7\$s>%2\$s - %5\$s.%6\$s</option>",
  59. $Image->getID(),
  60. htmlentities($Image->getSet()->getModel()->GetFullName()),
  61. htmlentities($Image->getSet()->getPrefix()),
  62. htmlentities($Image->getSet()->getName()),
  63. htmlentities($Image->getFileName()),
  64. htmlentities($Image->getFileExtension()),
  65. in_array($Image->getID(), $SelectedImageIDs) ? ' selected="selected"' : NULL
  66. );
  67. }
  68. if($SelectedImageIDs)
  69. {
  70. header(
  71. sprintf('location:download_zip.php?image_ids=%1$s&usesub=%2$s',
  72. join(',', $SelectedImageIDs),
  73. $UseSubfoldersInDownload ? 'true' : 'false'
  74. )
  75. );
  76. exit;
  77. }
  78. }
  79. }
  80. }
  81. else
  82. {
  83. /* @var $Model Model */
  84. foreach ($Models as $Model){
  85. $ModelsOptions .= sprintf("<option value=\"%1\$d\">%2\$s</option>",
  86. $Model->getID(),
  87. htmlentities($Model->GetFullName())
  88. );
  89. }
  90. }
  91. echo HTMLstuff::HtmlHeader('Download', $CurrentUser);
  92. ?>
  93. <h2><?php echo sprintf('<a href="index.php">%1$s</a> - %2$s', $lang->g('NavigationHome'), $lang->g('NavigationMultiDownload'))?></h2>
  94. <form action="<?php echo htmlentities($_SERVER['REQUEST_URI'])?>" method="post">
  95. <fieldset>
  96. <input type="hidden" id="hidAction" name="hidAction" value="DownloadMulti" />
  97. <select id="selModels" name="selModels[]" multiple="multiple" style="width:200px;height:400px;float:left;">
  98. <?php echo $ModelsOptions?>
  99. </select>
  100. <select id="selSets" name="selSets[]" multiple="multiple" style="width:250px;height:400px;float:left;margin-left:20px;">
  101. <?php echo ($SetsOptions ? $SetsOptions : '<option value=""></option>')?>
  102. </select>
  103. <select id="selImages" name="selImages[]" multiple="multiple" style="width:450px;height:400px;float:left;margin-left:20px;">
  104. <?php echo ($ImagesOptions ? $ImagesOptions : '<option value=""></option>')?>
  105. </select>
  106. <div class="Clear"></div>
  107. <ol>
  108. <li><?php echo $lang->g('LabelMultiDownloadStep1')?></li>
  109. <li><?php echo $lang->g('LabelMultiDownloadStep2')?></li>
  110. <li><?php echo $lang->g('LabelMultiDownloadStep3')?></li>
  111. </ol>
  112. <div class="FormRow">
  113. <label style="width:auto;" for="chkSubfolders"><?php echo $lang->g('LabelMultiDownloadUseSubfolders')?></label>&nbsp;<input type="checkbox" id="chkSubfolders" name="chkSubfolders"<?php echo HTMLstuff::CheckedStr($UseSubfoldersInDownload)?> />
  114. </div>
  115. <div class="Clear Separator"></div>
  116. <div class="FormRow">
  117. <input type="submit" class="FormButton" value="<?php echo $ButtonText?>" />
  118. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonReset')?>" onclick="window.location='download_multi.php';" />
  119. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonCancel')?>" onclick="window.location='index.php';" />
  120. </div>
  121. </fieldset>
  122. </form>
  123. <?php
  124. echo HTMLstuff::HtmlFooter($CurrentUser);
  125. ?>