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

/src/inc/admcol.php

https://github.com/jacadym/picman
PHP | 344 lines | 309 code | 29 blank | 6 comment | 30 complexity | 6bf1842dac6e72abb1e643bbfe09b46e MD5 | raw file
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Administrator :: Collections</TITLE>
  4. <STYLE TYPE="text/css"><!--
  5. body {
  6. font-family: arial,helvetica,sans-serif;
  7. font-size: 10pt;
  8. }
  9. a {
  10. font-family: arial,helvetica,sans-serif;
  11. text-decoration: none;
  12. }
  13. a.menu {
  14. font-weight: bold;
  15. color: #6699cc;
  16. font-size: 8pt;
  17. }
  18. td {
  19. font-size: 10pt;
  20. }
  21. th {
  22. font-size: 14pt;
  23. font-weight: bold;
  24. color: #000000;
  25. text-align: left;
  26. }
  27. td.menu, th.menu {
  28. font-size: 10pt;
  29. text-align: left;
  30. color: #000000;
  31. }
  32. div.frame {
  33. background: white;
  34. border: solid 1px black;
  35. width: 700px;
  36. }
  37. div.thumbnails {
  38. overflow-x: auto !important;
  39. padding: 10px 8px;
  40. white-space: nowrap;
  41. }
  42. div.thumbnails img {
  43. padding: 0 2px;
  44. cursor: pointer;
  45. }
  46. img.thumb-sel {
  47. border: solid 2px red;
  48. padding: 4px !important;
  49. margin: 0 2px;
  50. }
  51. td span {
  52. white-space: nowrap;
  53. }
  54. //--></STYLE>
  55. <script type="text/javascript" language="javascript">
  56. function selImg(num) {
  57. document.getElementById('form-thumbimg').value = 'T:' + num;
  58. var children = document.body.getElementsByTagName('img');
  59. for (var i = 0, length = children.length; i < length; i++) {
  60. child = children[i];
  61. child.className = 'thumb-img';
  62. }
  63. document.getElementById('img-' + num).className = 'thumb-sel';
  64. }
  65. </script>
  66. </HEAD>
  67. <BODY BGCOLOR="silver">
  68. <DIV ALIGN=center>
  69. <?php
  70. echo AdminMenu();
  71. if (isset($frm[action])) {
  72. switch (strtolower($frm[action])) {
  73. case 'mod' :
  74. // Ustalenie opcji
  75. $arr_opt = array();
  76. if (isset($frm[intro])) $arr_opt[] = 'HOME';
  77. if (isset($frm[options]) && !empty($frm[options])) $arr_opt[] = $frm[options];
  78. if (isset($frm[addbr]) && !empty($frm[desc])) {
  79. $out = '';
  80. foreach(split("\n", trim($frm[desc])) as $line) $out .= trim($line)."<BR>\n";
  81. $frm[desc] = $out;
  82. }
  83. if ($page_id) {
  84. // Sprawdzanie tagów
  85. $tags = GetTags();
  86. $tagids = array();
  87. if (isset($frm['tags']) && count($frm['tags'])) {
  88. $tagids = $frm['tags'];
  89. }
  90. if (!empty($frm['newtags'])) {
  91. foreach (split(',', $frm['newtags']) as $_tag) {
  92. $tag = strtolower(trim($_tag));
  93. if (!in_array($tag, $tags)) {
  94. $id = db_next_id('seq_tag');
  95. db_query("INSERT INTO {tags} (id, name) VALUES (%d, '%s')", $id, $tag);
  96. $tags[$id] = $tag;
  97. array_push($tagids, $id);
  98. }
  99. }
  100. }
  101. db_query("DELETE FROM {tag_collections} WHERE id_col = %d", $page_id);
  102. if (count($tagids)) {
  103. db_query("INSERT INTO {tag_collections} (id_tag,id_col) SELECT id, %d FROM {tags} WHERE id IN (%s)",
  104. $page_id, join(',', $tagids)
  105. );
  106. }
  107. $cat = db_fetch_array(db_query("SELECT uniqid FROM {categories} WHERE id = %d", $frm['parent']));
  108. $result = db_query("
  109. UPDATE {collections} SET
  110. uid_cat = '%s',
  111. uniqid = '%s',
  112. weight = %d,
  113. date_create = '%s',
  114. name = '%s',
  115. title = '%s',
  116. header = '%s',
  117. description = '%s',
  118. startnum = %d,
  119. quantity = %d,
  120. holes = '%s',
  121. coldir = '%s',
  122. picsubdir = '%s',
  123. thumbsubdir = '%s',
  124. pictemp = '%s',
  125. thumbtemp = '%s',
  126. pgnumtemp = '%s',
  127. imgindex = '%s',
  128. icoindex = '%s',
  129. rows = %d,
  130. cols = %d,
  131. options = '%s'
  132. WHERE id = %d",
  133. $cat['uniqid'],
  134. FrmDb($frm['uniqid']),
  135. $frm['position'],
  136. $frm['datecr'],
  137. FrmDb($frm['name']),
  138. FrmDb($frm['title']),
  139. FrmDb($frm['header']),
  140. FrmDb($frm['desc']),
  141. $frm['first'],
  142. $frm['quantity'],
  143. FrmDb($frm['holes']),
  144. FrmDb($frm['dirgr']),
  145. FrmDb($frm['dirimg']),
  146. FrmDb($frm['dirth']),
  147. FrmDb($frm['tempimg']),
  148. FrmDb($frm['tempth']),
  149. FrmDb($frm['temppage']),
  150. FrmDb($frm['introimg']),
  151. FrmDb($frm['thumbimg']),
  152. $frm['serrow'],
  153. $frm['sercol'],
  154. join('|',$arr_opt),
  155. $page_id
  156. );
  157. echo
  158. FramedTable1().
  159. '<BR> &nbsp; OK! Modify Collection "'.$frm[name].'" &nbsp; <BR><BR>'.
  160. FramedTable2();
  161. }
  162. else {
  163. // Tworzenie nowej grupy
  164. $result = db_query(
  165. "INSERT INTO {collections} ( ".
  166. "uid_cat,uniqid,".
  167. "weight,date_create,".
  168. "name,title,header,description,".
  169. "startnum,quantity,holes,".
  170. "coldir,picsubdir,thumbsubdir,".
  171. "pictemp,thumbtemp,pgnumtemp,".
  172. "imgindex,icoindex,".
  173. "rows,cols,options".
  174. ") SELECT
  175. C.uniqid, '".FrmDb($frm[uniqid])."',
  176. $frm[position], '".$frm[datecr]."',
  177. '".FrmDb($frm[name])."', '".FrmDb($frm[title])."', '".FrmDb($frm[header])."', '".FrmDb($frm[desc])."',
  178. $frm[first], $frm[quantity], '".FrmDb($frm[holes])."',
  179. '".FrmDb($frm[dirgr])."', '".FrmDb($frm[dirimg])."', '".FrmDb($frm[dirth])."',
  180. '".FrmDb($frm[tempimg])."', '".FrmDb($frm[tempth])."', '".FrmDb($frm[temppage])."',
  181. '".FrmDb($frm[introimg])."', '".FrmDb($frm[thumbimg])."',
  182. $frm[serrow], $frm[sercol], '".join('|',$arr_opt)."'
  183. FROM {categories} C
  184. WHERE C.id = $frm[parent]"
  185. );
  186. echo
  187. FramedTable1().
  188. '<BR> &nbsp; OK! Created new collection "'.$frm[name].'" &nbsp; <BR><BR>'.
  189. FramedTable2();
  190. }
  191. break;
  192. case 'del' :
  193. echo
  194. FramedTable1().
  195. '<BR> &nbsp; Sorry! But delete is not ready yet! &nbsp; <BR><BR>'.
  196. FramedTable2();
  197. break;
  198. default:
  199. echo
  200. FramedTable1().
  201. '<BR> &nbsp; Sorry! But incorrect action "'.$frm[action].'" &nbsp; <BR><BR>'.
  202. FramedTable2();
  203. break;
  204. }
  205. }
  206. else {
  207. DisplayCollectionForm();
  208. }
  209. function DisplayCollectionForm() {
  210. global $page_id, $frm;
  211. // Wartości domyślne
  212. if (!isset($frm)) $frm = array('sercol' => 5, 'serrow' => 4, 'datecr' => date('Y-m-d'));
  213. if ($page_id) {
  214. GetCollectionData($page_id);
  215. }
  216. $hier_cat = GetCategoriesHierarchy($frm[parent], $page_id, 1);
  217. // Odczytanie tagów
  218. $frm['#tags'] = GetTags();
  219. SetCollectionTags($page_id, 'tags');
  220. echo
  221. FramedTable1().
  222. '<FORM METHOD="POST">'.
  223. '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>'.
  224. '<TR><TH> Collection </TH><TD></TD></TR>'.
  225. '<TR><TD></TD><TD ALIGN=right> '.
  226. FormSelect('action', array('mod' => 'Modify', 'del' => 'Delete')).
  227. ' <INPUT TYPE="submit" VALUE=" Send "> '.
  228. '</TD></TR>'.
  229. '<TR><TD> Category: </TD><TD> '.
  230. '<SELECT NAME="frm[parent]">'.$hier_cat.'</SELECT>'.
  231. ' Position '.
  232. FormInput('position', 4, 1).
  233. ' </TD></TR>'.
  234. '<TR><TD> Uniqid & Date: </TD><TD> '.FormInput('uniqid').' '.FormInput('datecr',12).' </TD></TR>'.
  235. '<TR><TD> Name: </TD><TD> '.FormInput('name').' </TD></TR>'.
  236. '<TR><TD> Title: </TD><TD> '.FormInput('title').' </TD></TR>'.
  237. '<TR><TD> Header: </TD><TD> '.FormInput('header').' </TD></TR>'.
  238. '<TR><TD> Description: </TD><TD> '. FormText('desc', 80, 5).'<BR>'.FormCheckbox('addbr').' Auto add "break line" </TD></TR>'.
  239. '<TR><TD COLSPAN=2><HR></TD></TR>'.
  240. '<TR><TD> Tags: </TD><TD> '.FormCheckarea('tags').' </TD></TR>'.
  241. '<TR><TD> New tags: </TD><TD> '.FormText('newtags', 80, 2).' </TD></TR>'.
  242. '<TR><TD COLSPAN=2><HR></TD></TR>'.
  243. '<TR><TD> Series: </TD><TD> '.
  244. FormSelect('sercol', range(1, 10), 0).
  245. ' x '.
  246. FormSelect('serrow', range(1, 10), 0).
  247. ' (columns x rows) '.
  248. '</TD></TR>'.
  249. '<TR><TD> Images: </TD><TD> First number '.FormInput('first', 4, 1).' Quantity '.FormInput('quantity', 4, 1).' </TD></TR>'.
  250. '<TR><TD> Number holes: </TD><TD> '.FormText('holes', 60, 2).' </TD></TR>'.
  251. '<TR><TD COLSPAN=2><HR></TD></TR>'.
  252. '<TR><TD> Collection directory: </TD><TD> '.FormInput('dirgr').' </TD></TR>'.
  253. '<TR><TD> Image directory: </TD><TD> '.FormInput('dirimg').' </TD></TR>'.
  254. '<TR><TD> Thumbnails directory: </TD><TD> '.FormInput('dirth').' </TD></TR>'.
  255. '<TR><TD COLSPAN=2><HR></TD></TR>'.
  256. '<TR><TD> Pages template: </TD><TD> '.FormInput('temppage', 50, '%02d').' </TD></TR>'.
  257. '<TR><TD> Images template: </TD><TD> '.FormInput('tempimg').' </TD></TR>'.
  258. '<TR><TD> Thumbnails template: </TD><TD> '.FormInput('tempth').' </TD></TR>'.
  259. '<TR><TD COLSPAN=2><HR></TD></TR>'.
  260. '<TR><TD> Options: </TD><TD> Links to '.
  261. FormSelect('options', array('' => 'None', 'LP' => 'Page', 'LI' => 'Image')).
  262. ' '.
  263. FormCheckbox('intro').
  264. ' Exist intro page '.
  265. '</TD></TR>'.
  266. '<TR><TD> Image on intro page: </TD><TD> '.FormInput('introimg').' </TD></TR>'.
  267. '<TR><TD> Thumbnail for group: </TD><TD> '.FormInput('thumbimg').' </TD></TR>'.
  268. '</TABLE>'.
  269. '</FORM>'.
  270. FramedTable2();
  271. if ($page_id) {
  272. DisplayThumbForm($page_id);
  273. }
  274. }
  275. function DisplayThumbForm($group_id) {
  276. $item = db_fetch_array(db_query("SELECT * FROM {collections} WHERE id = $group_id"));
  277. $imgdir = GetDirForCollection($group_id);
  278. $icondir = preg_replace('/[\/]+/', '/', PICMAN_IMAGE."$imgdir/".$item['thumbsubdir']."/");
  279. $content = '';
  280. $picholes = array();
  281. if (!empty($item['holes'])) {
  282. foreach(split(',', $item['holes']) as $range) {
  283. list($range_from, $range_to) = split('-', $range);
  284. if (isset($range_to) && $range_to) {
  285. for ($i = $range_from; $i <= $range_to; $i++) {
  286. $picholes[] = $i;
  287. }
  288. }
  289. else {
  290. $picholes[] = $range_from;
  291. }
  292. }
  293. }
  294. $ico = split(':', $item['icoindex']);
  295. $img_add = $item['startnum'] - 1;
  296. $mov_holes = 0;
  297. for ($inum = 1; $inum <= $item['quantity']; $inum++) {
  298. if (count($picholes)) while (in_array($inum + $img_add, $picholes)) $img_add++;
  299. $content .= sprintf('<img id="img-%d" src="%s" class="%s" onClick="selImg(\'%d\')" />',
  300. $inum,
  301. $icondir . sprintf($item['thumbtemp'], $inum + $img_add),
  302. (($ico[0] == 'T') && ($ico[1] == $inum)) ? 'thumb-sel' : 'thumb-img',
  303. $inum
  304. );
  305. }
  306. echo
  307. FramedTable1().
  308. '<div class="thumbnails">'.
  309. $content.
  310. '</div>'.
  311. FramedTable2();
  312. }
  313. ?>
  314. </DIV>
  315. </BODY></HTML>