PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/image_view.php

http://candydolldb.googlecode.com/
PHP | 237 lines | 196 code | 38 blank | 3 comment | 29 complexity | af134dfe15bcae918f8ab62f306f586d MD5 | raw file
  1. <?php
  2. include('cd.php');
  3. $CurrentUser = Authentication::Authenticate();
  4. HTMLstuff::RefererRegister($_SERVER['REQUEST_URI']);
  5. $ModelID = Utils::SafeIntFromQS('model_id');
  6. $SetID = Utils::SafeIntFromQS('set_id');
  7. $ImageID = Utils::SafeIntFromQS('image_id');
  8. $TagsInDB = Tag::GetTags();
  9. $TagsThisImage = Tag2All::GetTag2Alls(new Tag2AllSearchParameters(
  10. FALSE, FALSE, FALSE,
  11. is_null($ModelID) ? FALSE : $ModelID, FALSE,
  12. is_null($SetID) ? FALSE : $SetID, FALSE,
  13. is_null($ImageID) ? FALSE : $ImageID, FALSE,
  14. FALSE, FALSE,
  15. FALSE, FALSE, FALSE, TRUE));
  16. if(!isset($ModelID))
  17. {
  18. header('location:index.php');
  19. exit;
  20. }
  21. if(!isset($SetID))
  22. {
  23. header('location:set.php?model_id='.$ModelID);
  24. exit;
  25. }
  26. $DeleteImage = (array_key_exists('cmd', $_GET) && $_GET['cmd'] && ($_GET['cmd'] == COMMAND_DELETE));
  27. $ReturnURL = sprintf('image.php?model_id=%1$d&set_id=%2$d', $ModelID, $SetID);
  28. $DisableControls =
  29. $DeleteImage ||
  30. (!$CurrentUser->hasPermission(RIGHT_IMAGE_EDIT) && !is_null($ImageID)) ||
  31. (!$CurrentUser->hasPermission(RIGHT_IMAGE_ADD) && is_null($ImageID));
  32. $DisableDefaultButton =
  33. (!$CurrentUser->hasPermission(RIGHT_IMAGE_DELETE) && !is_null($ImageID) && $DeleteImage) ||
  34. (!$CurrentUser->hasPermission(RIGHT_IMAGE_EDIT) && !is_null($ImageID) && !$DeleteImage) ||
  35. (!$CurrentUser->hasPermission(RIGHT_IMAGE_ADD) && is_null($ImageID));
  36. $DisableCacheDeleteButton =
  37. $DeleteImage ||
  38. is_null($ImageID) ||
  39. !$CurrentUser->hasPermission(RIGHT_CACHE_DELETE);
  40. /* @var $Image Image */
  41. /* @var $Set Set */
  42. /* @var $Model Model */
  43. if($ImageID != NULL)
  44. {
  45. $Images = Image::GetImages(new ImageSearchParameters(
  46. $ImageID,
  47. FALSE,
  48. is_null($SetID) ? FALSE : $SetID,
  49. FALSE,
  50. is_null($ModelID) ? FALSE : $ModelID));
  51. if($Images)
  52. { $Image = $Images[0]; }
  53. else
  54. {
  55. header('location:set.php?model_id='.$ModelID);
  56. exit;
  57. }
  58. $Set = $Image->getSet();
  59. $Model = $Set->getModel();
  60. }
  61. else
  62. {
  63. $Image = new Image(NULL, $lang->g('LabelNew'));
  64. $Set = Set::GetSets(new SetSearchParameters($SetID));
  65. if($Set)
  66. {
  67. $Set = $Set[0];
  68. $Model = $Set->getModel();
  69. $Image->setSet($Set);
  70. }
  71. else
  72. {
  73. header('location:index.php');
  74. exit;
  75. }
  76. }
  77. if(array_key_exists('hidAction', $_POST) && $_POST['hidAction'] == 'ImageView')
  78. {
  79. $Image->setFileName(Utils::NullIfEmpty($_POST['txtFilename']));
  80. $Image->setFileExtension(Utils::NullIfEmpty($_POST['txtFileExtension']));
  81. $Image->setFileSize(intval($_POST['txtFilesize']));
  82. $Image->setFileCheckSum(Utils::NullIfEmpty($_POST['txtFileChecksum']));
  83. $Image->setFileCRC32(Utils::NullIfEmpty($_POST['txtFileCRC32']));
  84. $Image->setImageWidth(abs(intval($_POST['txtImageWidth'])));
  85. $Image->setImageHeight(abs(intval($_POST['txtImageHeight'])));
  86. $tags = Tag::GetTagArray($_POST['txtTags']);
  87. if($Image->getImageWidth() == 0) { $Image->setImageHeight(0); }
  88. if($Image->getImageHeight() == 0) { $Image->setImageWidth(0); }
  89. if($Image->getID())
  90. {
  91. if($DeleteImage)
  92. {
  93. if(Image::Delete($Image, $CurrentUser))
  94. {
  95. header('location:'.$ReturnURL);
  96. exit;
  97. }
  98. }
  99. else
  100. {
  101. if(Image::Update($Image, $CurrentUser))
  102. {
  103. Tag2All::HandleTags($tags, $TagsThisImage, $TagsInDB, $CurrentUser, $ModelID, $SetID, $Image->getID(), NULL, TRUE);
  104. header('location:'.$ReturnURL);
  105. exit;
  106. }
  107. }
  108. }
  109. else
  110. {
  111. if(Image::Insert($Image, $CurrentUser))
  112. {
  113. Tag2All::HandleTags($tags, $TagsThisImage, $TagsInDB, $CurrentUser, $ModelID, $SetID, $Image->getID(), NULL, TRUE);
  114. header('location:'.$ReturnURL);
  115. exit;
  116. }
  117. }
  118. }
  119. echo HTMLstuff::HtmlHeader(sprintf('%1$s - %2$s - %3$s',
  120. $Model->GetShortName(TRUE),
  121. $lang->g('NavigationImages'),
  122. $Image->getFileName()
  123. ),
  124. $CurrentUser
  125. );
  126. if($ImageID)
  127. {
  128. $width = $Image->getImageWidthToppedOff(400, 600);
  129. $height = $Image->getImageHeightToppedOff(400, 600);
  130. echo HTMLstuff::ImageLoading(
  131. sprintf('download_image.php?image_id=%1$d&width=%2$d&height=%3$d&portrait_only=true', $ImageID, $width, $height),
  132. $width,
  133. $height,
  134. htmlentities($Model->GetFullName()),
  135. htmlentities($Model->GetFullName())
  136. );
  137. echo '<div class="PhotoContainer Loading"></div>';
  138. }
  139. ?>
  140. <h2><?php echo sprintf(
  141. '<a href="index.php">%7$s</a> - <a href="model_view.php?model_id=%1$d">%4$s</a> - <a href="set.php?model_id=%1$d">%8$s</a> - <a href="set_view.php?model_id=%1$d&amp;set_id=%2$d">%9$s %5$s</a> - <a href="image.php?model_id=%1$d&amp;set_id=%2$d">%10$s</a> - %6$s',
  142. $ModelID,
  143. $SetID,
  144. $ImageID,
  145. htmlentities($Model->GetShortName(TRUE)),
  146. htmlentities($Set->getName()),
  147. htmlentities($Image->getFileName()),
  148. $lang->g('NavigationHome'),
  149. $lang->g('NavigationSets'),
  150. $lang->g('NavigationSet'),
  151. $lang->g('NavigationImages')
  152. )?></h2>
  153. <form action="<?php echo htmlentities($_SERVER['REQUEST_URI'])?>" method="post">
  154. <fieldset>
  155. <input type="hidden" id="hidAction" name="hidAction" value="ImageView" />
  156. <div class="FormRow">
  157. <label for="txtFilename"><?php echo $lang->g('LabelFilename')?>: <em>*</em></label>
  158. <input type="text" id="txtFilename" name="txtFilename" maxlength="100" value="<?php echo $Image->getFileName()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  159. </div>
  160. <div class="FormRow">
  161. <label for="txtFileExtension"><?php echo $lang->g('LabelExtension')?>: <em>*</em></label>
  162. <input type="text" id="txtFileExtension" name="txtFileExtension" maxlength="10" value="<?php echo $Image->getFileExtension()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  163. </div>
  164. <div class="FormRow">
  165. <label for="txtFilesize"><?php echo $lang->g('LabelFilesize')?> (bytes): <em>*</em></label>
  166. <input type="text" id="txtFilesize" name="txtFilesize" maxlength="10" value="<?php echo $Image->getFileSize()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  167. </div>
  168. <div class="FormRow">
  169. <label for="txtFileChecksum"><?php echo $lang->g('LabelMD5Checksum')?>:</label>
  170. <input type="text" id="txtFileChecksum" name="txtFileChecksum" maxlength="32" value="<?php echo $Image->getFileCheckSum()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  171. </div>
  172. <div class="FormRow">
  173. <label for="txtFileCRC32">CRC32:</label>
  174. <input type="text" id="txtFileCRC32" name="txtFileCRC32" maxlength="8" value="<?php echo $Image->getFileCRC32()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  175. </div>
  176. <div class="FormRow">
  177. <label for="txtImageWidth"><?php echo $lang->g('LabelWidth')?> (pixels):</label>
  178. <input type="text" id="txtImageWidth" name="txtImageWidth" maxlength="10" value="<?php echo $Image->getImageWidth()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  179. </div>
  180. <div class="FormRow">
  181. <label for="txtImageHeight"><?php echo $lang->g('LabelHeight')?> (pixels):</label>
  182. <input type="text" id="txtImageHeight" name="txtImageHeight" maxlength="10" value="<?php echo $Image->getImageHeight()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  183. </div>
  184. <div class="FormRow">
  185. <label for="txtTags"><?php echo $lang->g('LabelTags')?> (CSV):</label>
  186. <input type="text" id="txtTags" name="txtTags" maxlength="400" class="TagsBox" value="<?php echo Tag2All::Tags2AllCSV($TagsThisImage)?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  187. </div>
  188. <div class="FormRow"><label>&nbsp;</label>
  189. <input type="submit" class="FormButton" value="<?php echo $DeleteImage ? $lang->g('ButtonDelete') : $lang->g('ButtonSave')?>"<?php echo HTMLstuff::DisabledStr($DisableDefaultButton)?> />
  190. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonCancel')?>" onclick="window.location='<?php echo htmlentities($ReturnURL)?>';" />
  191. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonClearCacheImage')?>" onclick="window.location='cacheimage_delete.php?image_id=<?php echo $ImageID ?>';"<?php echo HTMLstuff::DisabledStr($DisableCacheDeleteButton)?> />
  192. </div>
  193. <div class="Separator"></div>
  194. <?php echo HTMLstuff::Button('index.php')?>
  195. </fieldset>
  196. </form>
  197. <?php
  198. echo HTMLstuff::HtmlFooter($CurrentUser);
  199. ?>