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

/set_view.php

http://candydolldb.googlecode.com/
PHP | 297 lines | 244 code | 48 blank | 5 comment | 59 complexity | 3db5505466d654ffeb57bca03b6c921b 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. $TagsInDB = Tag::GetTags();
  8. $TagsThisSet = Tag2All::GetTag2Alls(new Tag2AllSearchParameters(
  9. FALSE, FALSE, FALSE,
  10. $ModelID, FALSE,
  11. $SetID, FALSE,
  12. FALSE, FALSE,
  13. FALSE, FALSE,
  14. FALSE, FALSE, TRUE, TRUE));
  15. if(!isset($ModelID))
  16. {
  17. header('location:index.php');
  18. exit;
  19. }
  20. $NoErrorDuringPostback = TRUE;
  21. $DeleteSet = (array_key_exists('cmd', $_GET) && $_GET['cmd'] && ($_GET['cmd'] == COMMAND_DELETE));
  22. $DisableControls =
  23. $DeleteSet ||
  24. (!$CurrentUser->hasPermission(RIGHT_SET_EDIT) && !is_null($SetID)) ||
  25. (!$CurrentUser->hasPermission(RIGHT_SET_ADD) && is_null($SetID));
  26. $DisableDefaultButton =
  27. (!$CurrentUser->hasPermission(RIGHT_SET_DELETE) && !is_null($SetID) && $DeleteSet) ||
  28. (!$CurrentUser->hasPermission(RIGHT_SET_EDIT) && !is_null($SetID) && !$DeleteSet) ||
  29. (!$CurrentUser->hasPermission(RIGHT_SET_ADD) && is_null($SetID));
  30. $DisableCacheDeleteButton =
  31. $DeleteSet ||
  32. is_null($SetID) ||
  33. !$CurrentUser->hasPermission(RIGHT_CACHE_DELETE);
  34. $ReturnURL = sprintf('set.php?model_id=%1$d', $ModelID);
  35. $DatesThisSet = array();
  36. /* @var $Set Set */
  37. /* @var $Model Model */
  38. if($SetID != NULL)
  39. {
  40. $Sets = Set::GetSets(new SetSearchParameters($SetID, FALSE, $ModelID));
  41. if($Sets)
  42. { $Set = $Sets[0]; }
  43. else
  44. {
  45. header('location:index.php');
  46. exit;
  47. }
  48. $Model = $Set->getModel();
  49. $DatesThisSet = Date::GetDates(new DateSearchParameters(FALSE, FALSE, $Set->getID()));
  50. }
  51. else
  52. {
  53. $Set = new Set(NULL, $lang->g('New'));
  54. $Model = Model::GetModels(new ModelSearchParameters($ModelID));
  55. if($Model) { $Model = $Model[0]; }
  56. else
  57. {
  58. header('location:index.php');
  59. exit;
  60. }
  61. $Set->setModel($Model);
  62. }
  63. $DatesThisSet[] = new Date(NULL, DATE_KIND_UNKNOWN, -1,
  64. $Set->getID(), $Set->getPrefix(), $Set->getName(), $Set->getContainsWhat(),
  65. $Model->getID(), $Model->getFirstName(), $Model->getLastName());
  66. if(array_key_exists('hidAction', $_POST) && $_POST['hidAction'] == 'SetView')
  67. {
  68. $Set->setPrefix(Utils::NullIfEmpty($_POST['txtPrefix']));
  69. $Set->setName(Utils::NullIfEmpty($_POST['txtName']));
  70. $tags = Tag::GetTagArray($_POST['txtTags']);
  71. if(array_key_exists('radContains', $_POST) && $_POST['radContains'])
  72. { $Set->setContainsWhat(intval($_POST['radContains'])); }
  73. if($Set->getID())
  74. {
  75. if($DeleteSet)
  76. {
  77. if($CurrentUser->hasPermission(RIGHT_SET_DELETE) && Set::Delete($Set, $CurrentUser))
  78. {
  79. $CacheImages = CacheImage::GetCacheImages(new CacheImageSearchParameters(FALSE, FALSE, $Model->getID()));
  80. CacheImage::DeleteMulti($CacheImages, $CurrentUser);
  81. header('location:'.$ReturnURL);
  82. exit;
  83. }
  84. }
  85. else if($CurrentUser->hasPermission(RIGHT_SET_EDIT))
  86. {
  87. $NoErrorDuringPostback = Set::Update($Set, $CurrentUser);
  88. if($NoErrorDuringPostback){
  89. Tag2All::HandleTags($tags, $TagsThisSet, $TagsInDB, $CurrentUser, $ModelID, $Set->getID(), NULL, NULL);
  90. }
  91. }
  92. }
  93. else if($CurrentUser->hasPermission(RIGHT_SET_ADD))
  94. {
  95. if(($NoErrorDuringPostback = Set::Insert($Set, $CurrentUser)))
  96. {
  97. $CacheImages = CacheImage::GetCacheImages(new CacheImageSearchParameters(FALSE, FALSE, $Model->getID()));
  98. CacheImage::DeleteMulti($CacheImages, $CurrentUser);
  99. Tag2All::HandleTags($tags, $TagsThisSet, $TagsInDB, $CurrentUser, $ModelID, $Set->getID(), NULL, NULL);
  100. }
  101. }
  102. $Set->setDatesPic(
  103. HTMLstuff::DatesFromPOST($_POST, $Set, DATE_KIND_IMAGE)
  104. );
  105. $Set->setDatesVid(
  106. HTMLstuff::DatesFromPOST($_POST, $Set, DATE_KIND_VIDEO)
  107. );
  108. /* @var $Date Date */
  109. /* @var $dateInDb Date */
  110. foreach ($Set->getDatesPic() as $Date)
  111. {
  112. if($Date->getID())
  113. {
  114. if($Date->getTimeStamp() == -1)
  115. { Date::Delete($Date, $CurrentUser); }
  116. else
  117. { Date::Update($Date, $CurrentUser); }
  118. }
  119. else if($Date->getTimeStamp() > 0)
  120. {
  121. Date::Insert($Date, $CurrentUser);
  122. }
  123. }
  124. foreach ($Set->getDatesVid() as $Date)
  125. {
  126. if($Date->getID())
  127. {
  128. if($Date->getTimeStamp() == -1)
  129. { Date::Delete($Date, $CurrentUser); }
  130. else
  131. { Date::Update($Date, $CurrentUser); }
  132. }
  133. else if($Date->getTimeStamp() > 0)
  134. {
  135. Date::Insert($Date, $CurrentUser);
  136. }
  137. }
  138. if($NoErrorDuringPostback)
  139. {
  140. header('location:'.$ReturnURL);
  141. exit;
  142. }
  143. }
  144. echo HTMLstuff::HtmlHeader(sprintf('%1$s - %2$s - %3$s',
  145. $Model->GetShortName(TRUE),
  146. $lang->g('NavigationSets'),
  147. $Set->getName()
  148. ),
  149. $CurrentUser
  150. );
  151. if($SetID)
  152. {
  153. echo HTMLstuff::ImageLoading(
  154. sprintf('download_image.php?set_id=%1$d&width=400&height=600&portrait_only=true', $SetID),
  155. 400,
  156. 600,
  157. htmlentities($Model->GetFullName()),
  158. htmlentities($Model->GetFullName())
  159. );
  160. echo '<div class="PhotoContainer Loading"></div>';
  161. }
  162. ?>
  163. <h2><?php echo sprintf(
  164. '<a href="index.php">%5$s</a> - <a href="model_view.php?model_id=%1$d">%3$s</a> - <a href="set.php?model_id=%1$d">%6$s</a> - %7$s %4$s',
  165. $ModelID,
  166. $SetID,
  167. htmlentities($Model->GetShortName(TRUE)),
  168. htmlentities($Set->getName()),
  169. $lang->g('NavigationHome'),
  170. $lang->g('NavigationSets'),
  171. $lang->g('NavigationSet')
  172. )?></h2>
  173. <form action="<?php echo htmlentities($_SERVER['REQUEST_URI'])?>" method="post">
  174. <fieldset>
  175. <input type="hidden" id="hidAction" name="hidAction" value="SetView" />
  176. <div class="FormRow">
  177. <label for="txtPrefix"><?php echo $lang->g('LabelPrefix')?>:</label>
  178. <input type="text" id="txtPrefix" name="txtPrefix" maxlength="100" value="<?php echo $Set->getPrefix()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  179. </div>
  180. <div class="FormRow">
  181. <label for="txtName"><?php echo $lang->g('LabelName')?>: <em>*</em></label>
  182. <input type="text" id="txtName" name="txtName" maxlength="100" value="<?php echo $Set->getName()?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  183. </div>
  184. <div class="FormRow">
  185. <label><?php echo $lang->g('LabelContains')?>: </label>
  186. <input type="radio" id="radImages" name="radContains" value="<?php echo SET_CONTENT_IMAGE?>"<?php echo ($Set->getContainsWhat() & SET_CONTENT_IMAGE) > 0 ? ' checked="checked"' : NULL?><?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  187. <label for="radImages" class="Radio"><?php echo $lang->g('NavigationImages')?></label>
  188. <input type="radio" id="radVideos" name="radContains" value="<?php echo SET_CONTENT_VIDEO?>"<?php echo ($Set->getContainsWhat() & SET_CONTENT_VIDEO) > 0 ? ' checked="checked"' : NULL?><?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  189. <label for="radVideos" class="Radio"><?php echo $lang->g('NavigationVideos')?></label>
  190. <input type="radio" id="radBoth" name="radContains" value="<?php echo (SET_CONTENT_IMAGE + SET_CONTENT_VIDEO)?>"<?php echo (($Set->getContainsWhat() & SET_CONTENT_IMAGE) > 0 && ($Set->getContainsWhat() & SET_CONTENT_VIDEO) > 0) ? ' checked="checked"' : NULL?><?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  191. <label for="radBoth" class="Radio"><?php echo $lang->g('LabelBoth')?></label>
  192. </div>
  193. <?php
  194. /* @var $Date Date */
  195. foreach ($DatesThisSet as $Date)
  196. {
  197. if($Date->getDateKind() == DATE_KIND_IMAGE || $Date->getDateKind() == DATE_KIND_UNKNOWN)
  198. {
  199. if(!$DeleteSet || $Date->getTimeStamp() > 0)
  200. {
  201. echo HTMLstuff::DateFormField(
  202. $Date->getID(),
  203. Date::FormatDates(array($Date), 'Y-m-d'),
  204. DATE_KIND_IMAGE,
  205. $DisableControls
  206. );
  207. }
  208. }
  209. }
  210. foreach ($DatesThisSet as $Date)
  211. {
  212. if($Date->getDateKind() == DATE_KIND_VIDEO || $Date->getDateKind() == DATE_KIND_UNKNOWN)
  213. {
  214. if(!$DeleteSet || $Date->getTimeStamp() > 0)
  215. {
  216. echo HTMLstuff::DateFormField(
  217. $Date->getID(),
  218. Date::FormatDates(array($Date), 'Y-m-d'),
  219. DATE_KIND_VIDEO,
  220. $DisableControls
  221. );
  222. }
  223. }
  224. }
  225. ?>
  226. <div class="FormRow">
  227. <label for="txtTags"><?php echo $lang->g('LabelTags')?> (CSV):</label>
  228. <input type="text" id="txtTags" name="txtTags" maxlength="400" class="TagsBox" value="<?php echo Tag2All::Tags2AllCSV($TagsThisSet)?>"<?php echo HTMLstuff::DisabledStr($DisableControls)?> />
  229. </div>
  230. <div class="FormRow">
  231. <label>&nbsp;</label>
  232. <input type="submit" class="FormButton" value="<?php echo $DeleteSet ? $lang->g('ButtonDelete') : $lang->g('ButtonSave')?>"<?php echo HTMLstuff::DisabledStr($DisableDefaultButton)?> />
  233. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonCancel')?>" onclick="window.location='<?php echo $ReturnURL?>';" />
  234. <input type="button" class="FormButton" value="<?php echo $lang->g('ButtonClearCacheImage')?>" onclick="window.location='cacheimage_delete.php?set_id=<?php echo $SetID ?>';"<?php echo HTMLstuff::DisabledStr($DisableCacheDeleteButton)?> />
  235. </div>
  236. <div class="Separator"></div>
  237. <?php
  238. if($Set && ($Set->getContainsWhat() & SET_CONTENT_IMAGE) > 0)
  239. { echo HTMLstuff::Button(sprintf('image.php?model_id=%1$d&amp;set_id=%2$d', $ModelID, $SetID), $lang->g('NavigationImages')); }
  240. if($Set && ($Set->getContainsWhat() & SET_CONTENT_VIDEO) > 0)
  241. { echo HTMLstuff::Button(sprintf('video.php?model_id=%1$d&amp;set_id=%2$d', $ModelID, $SetID), $lang->g('NavigationVideos')); }
  242. ?>
  243. <?php echo HTMLstuff::Button(sprintf('set.php?model_id=%1$d', $ModelID), $lang->g('NavigationSets'))?>
  244. <?php echo HTMLstuff::Button('index.php')?>
  245. </fieldset>
  246. </form>
  247. <?php
  248. echo HTMLstuff::HtmlFooter($CurrentUser);
  249. ?>