PageRenderTime 61ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/src/index.php

https://github.com/jacadym/picman
PHP | 1076 lines | 1045 code | 29 blank | 2 comment | 40 complexity | 115ed70997f8b657293105df01342c9e MD5 | raw file
  1. <?php
  2. // -------------------------------------------------------------------------
  3. $PICMAN_CONF = 'picman.cfg';
  4. if (!is_file($PICMAN_CONF)) {
  5. echo "Not found CONF file ($PICMAN_CONF)!!!\n";
  6. exit;
  7. }
  8. include $PICMAN_CONF;
  9. global $PICMAN_INFO;
  10. // -------------------------------------------------------------------------
  11. function debug_info($level, $info, $message) {
  12. global $debug_level, $debug_file;
  13. static $init, $time, $uniq, $no = 1;
  14. if ($debug_level < $level || empty($debug_file)) {
  15. return;
  16. }
  17. if (!isset($init)) {
  18. $init = true;
  19. $uniq = uniqid('LOG_');
  20. $time = GetMicrotime();
  21. error_log(sprintf("\n\n%s :: %s :: %s\n", date('ymd H:i:s'), $uniq, $message), 3, $debug_file);
  22. return;
  23. }
  24. $newtime = GetMicrotime();
  25. error_log(
  26. sprintf("%s :: %s,%-2d :: %04.2f :: %8s :: %s\n", date('ymd H:i:s'), $uniq, $no++, ($newtime - $time), $info, $message),
  27. 3,
  28. $debug_file
  29. );
  30. $time = $newtime;
  31. }
  32. function GetMicrotime() {
  33. list ($usec, $sec) = explode(' ', microtime());
  34. return ((float)$usec + (float)$sec);
  35. }
  36. function LoadTemplateFile($filename) {
  37. $txt = '';
  38. if (is_file($filename)) {
  39. debug_info(4, 'LoadFile', $filename);
  40. $txt = join('', file($filename));
  41. } else {
  42. echo "ERROR!!! Not found file $filename!!!<BR>";
  43. }
  44. return $txt;
  45. }
  46. function UpdateTemplate($text, $options) {
  47. $txt = $text;
  48. if (is_array($options)) {
  49. foreach($options as $name => $value) {
  50. $txt = preg_replace("|%%$name%%|i", $value, $txt);
  51. }
  52. }
  53. return $txt;
  54. }
  55. function ParsePage() {
  56. global $PATH_INFO;
  57. $page = 'main.php';
  58. if (!empty($PATH_INFO)) {
  59. if (preg_match("|\/([^/]*?)\/|", $PATH_INFO, $regs)) {
  60. $PAGE_IN_PATH = $regs[1];
  61. if (is_file(PICMAN_INCLUDE . $PAGE_IN_PATH . '.php')) {
  62. $page = $PAGE_IN_PATH . '.php';
  63. }
  64. }
  65. }
  66. return $page;
  67. }
  68. function SetPageParams() {
  69. global $PATH_INFO, $page_id, $page_pg;
  70. $page_id = 0;
  71. $page_pg = 0;
  72. if (preg_match("|i(\d+)|i", $PATH_INFO, $regs)) $page_id = 0 + $regs[1];
  73. if (preg_match("|p(\d+)|i", $PATH_INFO, $regs)) $page_pg = 0 + $regs[1];
  74. }
  75. function GetDirForCollection($id_group) {
  76. $link = db_fetch_array(db_query("SELECT uid_col FROM {links} WHERE id = $id_group"));
  77. if ($link['uid_col']) {
  78. $group = db_fetch_array(db_query("SELECT * FROM {collections} WHERE uniqid = '".$link['uid_col']."'"));
  79. }
  80. else {
  81. $group = db_fetch_array(db_query("SELECT * FROM {collections} WHERE id = $id_group"));
  82. }
  83. $result = db_query("
  84. SELECT DISTINCT P.id AS id, P.catdir AS catdir, P.lnum AS plnum
  85. FROM {categories} P, {categories} C
  86. WHERE C.uniqid = '%s' AND C.lnum BETWEEN P.lnum AND P.rnum
  87. ORDER BY plnum",
  88. $group['uid_cat']
  89. );
  90. if (db_num_rows($result)) {
  91. $dirs = array();
  92. while ($level = db_fetch_array($result)) {
  93. $dirs[] = $level['catdir'];
  94. }
  95. $dirs[] = $group['coldir'];
  96. return preg_replace('/[\/]+/', '/', join('/', $dirs).'/');
  97. }
  98. }
  99. function GetDirForCat($id_obj, $id_group = 0) {
  100. static $dir = array();
  101. if ($id_group) {
  102. $group = db_fetch_array(db_query("SELECT * FROM {collections} WHERE id = $id_group"));
  103. $id_dir = 'G_'.$id_group;
  104. $sql = "
  105. SELECT DISTINCT P.id AS id, P.catdir AS catdir, P.lnum AS plnum
  106. FROM {categories} C, {categories} P
  107. WHERE C.uniqid = '".$group['uid_cat']."' AND C.lnum BETWEEN P.lnum AND P.rnum
  108. ORDER BY plnum
  109. ";
  110. }
  111. else {
  112. $id_dir = 'C_'.$id_obj;
  113. $sql = "
  114. SELECT DISTINCT P.id AS id, P.catdir AS catdir, P.lnum AS plnum
  115. FROM {categories} C, {categories} P
  116. WHERE C.id = $id_obj AND C.lnum BETWEEN P.lnum AND P.rnum
  117. ORDER BY plnum
  118. ";
  119. }
  120. if (!isset($dir[$id_dir])) {
  121. $result = db_query($sql);
  122. if (db_num_rows($result)) {
  123. $dirs = array();
  124. while ($level = db_fetch_array($result)) {
  125. $dirs[] = $level['catdir'];
  126. }
  127. $dir[$id_dir] = preg_replace('/[\/]+/', '/', join('/', $dirs).'/');
  128. }
  129. }
  130. return $dir[$id_dir];
  131. }
  132. function GetTopCatsForCat($id_obj) {
  133. $result = db_query("
  134. SELECT DISTINCT P.id AS id, P.name AS name, P.lnum AS plnum
  135. FROM {categories} P, {categories} C
  136. WHERE C.id = $id_obj AND C.lnum BETWEEN P.lnum AND P.rnum
  137. ORDER BY plnum
  138. ");
  139. $txt = '<a href="'.PICMAN_INDEX.'">Category</a> :: ';
  140. if (db_num_rows($result)) {
  141. $cat_arr = array();
  142. while ($cat = db_fetch_array($result)) {
  143. if ($cat['id'] == $id_obj) {
  144. $cat_arr[] = '<b>'.$cat['name'].'</b>';
  145. }
  146. else {
  147. $cat_arr[] = sprintf('<a href="'.PICMAN_MAIN."i%03dp%03d.html\">%s</a>", $cat['id'], 1, $cat['name']);
  148. }
  149. }
  150. if (PICMAN_ADMINISTRATION) {
  151. $cat_arr[] = sprintf('<a href="'.PICMAN_ADMIN_CAT."i%03dp%03d.html\">[::]</a>", $id_obj, 1);
  152. $cat_arr[] = sprintf('<a href="'.PICMAN_ADMIN_SEARCH."i%03dp%03d.html\">[??]</a>", $id_obj, 1);
  153. }
  154. $txt .= join(' / ', $cat_arr);
  155. }
  156. return $txt;
  157. }
  158. function GetTopCatsForCollection($id_obj, $display = 0) {
  159. $txt = '<a href="'.PICMAN_INDEX.'">Category</a> :: ';
  160. $link = db_fetch_array(db_query("SELECT uid_col FROM {links} WHERE id = $id_obj"));
  161. if ($link['uid_col']) {
  162. $group = db_fetch_array(db_query("SELECT * FROM {collections} WHERE uniqid = '".$link['uid_col']."'"));
  163. }
  164. else {
  165. $group = db_fetch_array(db_query("SELECT * FROM {collections} WHERE id = $id_obj"));
  166. }
  167. $result = db_query("
  168. SELECT DISTINCT P.id AS id, P.name AS name, P.lnum AS plnum
  169. FROM {categories} P, {categories} C
  170. WHERE C.uniqid = '%s' AND C.lnum >= P.lnum AND C.lnum <= P.rnum
  171. ORDER BY plnum",
  172. $group['uid_cat']
  173. );
  174. if (db_num_rows($result)) {
  175. $cat_arr = array();
  176. while ($cat = db_fetch_array($result)) {
  177. $cat_arr[] = sprintf('<a href="'.PICMAN_MAIN."i%03dp%03d.html\">%s</a>", $cat['id'], 1, $cat['name']);
  178. }
  179. if ($display) {
  180. $cat_arr[] = sprintf('<a href="'.PICMAN_COLLECTION."i%03d.html\">%s</a>", $id_obj, $group['name']);
  181. $cat_arr[] = sprintf('<a href="'.PICMAN_COLLECTION."i%03dp%03d.html\">Page %d</a>", $id_obj, $display, $display);
  182. }
  183. else {
  184. $cat_arr[] = '<b>'.$group['name'].'</b>';
  185. }
  186. $cat_arr[] = sprintf('<a href="'.PICMAN_SLIDESHOW."i%03dp%03d.html\">[!!]</a>", $id_obj, $display ? $display : 1);
  187. if (PICMAN_ADMINISTRATION) {
  188. $cat_arr[] = sprintf('<a href="'.PICMAN_ADMIN_COLLECTION."i%03dp%03d.html\">[::]</a>", $id_obj, 1);
  189. if ($display) {
  190. $cat_arr[] = sprintf('<a href="'.PICMAN_ADMIN_THUMB."i%03dp%03d.html\">[&lt;&gt;]</a>", $id_obj, $display);
  191. // } else {
  192. // $cat_arr[] = sprintf('<a href="'.PICMAN_ADMIN_LINK."i%03dp%03d.html\">[&lt;&gt;]</a>", $id_obj, 1);
  193. }
  194. }
  195. $txt .= join(' / ', $cat_arr);
  196. }
  197. return $txt;
  198. }
  199. function GetGrpContent($id_cat, $item_txt, $txt_pre, $txt_post, $txt_prerow, $txt_postrow) {
  200. global $PICMAN_INFO, $page_pg, $num_total_pages;
  201. if (!$id_cat) return array('', '');
  202. $pagesel = '';
  203. $group = db_fetch_array(db_query("SELECT colcols, colrows FROM {categories} WHERE id = $id_cat"));
  204. $perpage = $group['colcols'] * $group['colrows'];
  205. $ticodir = $PICMAN_INFO['dircat'];
  206. $result = db_query("
  207. SELECT DISTINCT
  208. G.id AS id, G.uniqid AS uniqid, G.name AS name, G.weight AS weight, G.quantity AS quantity, G.date_create AS dcreate,
  209. G.icoindex AS icoindex, G.coldir AS coldir, G.thumbsubdir AS thumbsubdir, G.thumbtemp AS thumbtemp, G.uid_cat AS uid_cat, 0 AS linkitem
  210. FROM {categories} C
  211. INNER JOIN {collections} G ON (C.uniqid = G.uid_cat)
  212. WHERE C.id = $id_cat
  213. UNION SELECT
  214. G.id AS id, G.uniqid AS uniqid, G.name AS name, L.weight AS weight, G.quantity AS quantity, G.date_create AS dcreate,
  215. G.icoindex AS icoindex, G.coldir AS coldir, G.thumbsubdir AS thumbsubdir, G.thumbtemp AS thumbtemp, G.uid_cat AS uid_cat, 1 AS linkitem
  216. FROM {categories} C
  217. INNER JOIN {links} L ON (C.uniqid = L.uid_cat)
  218. INNER JOIN {collections} G ON (L.uid_col = G.uniqid)
  219. WHERE C.id = $id_cat
  220. ORDER BY weight DESC, dcreate DESC, name
  221. ");
  222. $txt = '';
  223. if ($num = db_num_rows($result)) {
  224. $page = 1;
  225. $total = (int)($num / $perpage);
  226. if ($num % $perpage) $total++;
  227. if (isset($page_pg) && $page_pg > 1) {
  228. $page = $page_pg;
  229. if ($page > $total) $page = $total;
  230. }
  231. $startnum = (($page - 1) * $perpage);
  232. $maxnum = ($page < $total ? $perpage : $num - (($total - 1) * $perpage));
  233. $num_total_pages = $total;
  234. $txt .= $txt_pre;
  235. $pgnumtemp = '%02d';
  236. if ($total > 1) {
  237. $pages_arr = array();
  238. for ($p = 1; $p <= $total; $p++) {
  239. if ($p == $page_pg) {
  240. $pages_arr[] = sprintf("<B>$pgnumtemp</B>", $p);
  241. }
  242. else {
  243. $pages_arr[] = sprintf('<a href="'.PICMAN_MAIN."i%03dp%03d.html\">$pgnumtemp</a>", $id_cat, $p, $p);
  244. }
  245. }
  246. $pagesel = join(' || ', $pages_arr);
  247. }
  248. $arr_collections = array();
  249. $arr_links = array();
  250. db_seek($result, $startnum);
  251. for ($rec = $startnum; ($rec < $num) && ($rec < $startnum + $perpage); $rec++) {
  252. $grp_dir = '';
  253. $grp = db_fetch_array($result);
  254. if (!empty($grp['icoindex'])) {
  255. $grp_dir = "$ticodir/".$grp['coldir'];
  256. $icoarr = split(':', $grp['icoindex']);
  257. if ($icoarr[0] == 'T') {
  258. // Jako ikona będzie thumnbails
  259. $grp['icoindex'] = sprintf($grp['thumbsubdir']."/".$grp['thumbtemp'], $icoarr[1]);
  260. }
  261. if ($grp['linkitem']) $grp_dir = '';
  262. }
  263. $arr_collections[] = array(
  264. 'id' => $grp['id'],
  265. 'name' => $grp['name'],
  266. 'count' => $grp['quantity'],
  267. 'icon' => $grp['icoindex'],
  268. 'dir' => $grp_dir,
  269. 'uniqid' => $grp['uniqid'],
  270. 'date' => date('Y-m-d', strtotime($grp['dcreate'])),
  271. 'link' => $grp['linkitem']
  272. );
  273. $arr_links[$grp['uniqid']] = $grp['uid_cat'];
  274. }
  275. $links_output = array();
  276. $qid_links = db_query("
  277. SELECT DISTINCT C.id AS id, C.name AS name, L.uid_col AS uid_col FROM {links} L
  278. INNER JOIN {categories} C ON (C.uniqid = L.uid_cat)
  279. WHERE
  280. (L.uid_cat IN ('".join("','", array_unique(array_values($arr_links)))."') OR L.uid_col IN ('".join("','", array_unique(array_keys($arr_links)))."'))
  281. AND C.id != $id_cat
  282. UNION SELECT C.id AS id, C.name AS name, G.uniqid AS uid_col FROM {collections} G
  283. INNER JOIN {categories} C ON (C.uniqid = G.uid_cat)
  284. WHERE
  285. (G.uid_cat IN ('".join("','", array_unique(array_values($arr_links)))."') OR G.uniqid IN ('".join("','", array_unique(array_keys($arr_links)))."'))
  286. AND C.id != $id_cat
  287. ");
  288. if ($num_links = db_num_rows($qid_links)) {
  289. while ($pos = db_fetch_array($qid_links, $idx++)) {
  290. $links_output[$pos['uid_col']][$pos['id']] = $pos['name'];
  291. }
  292. }
  293. // echo '<pre>';
  294. // print_r($links_output);
  295. // echo '</pre>';
  296. $snum = 1;
  297. for ($r = 1; $r <= $group['colrows'] && $snum <= $maxnum; $r++) {
  298. $txt .= $txt_prerow;
  299. for ($c = 1; $c <= $group['colcols'] && $snum <= $maxnum; $c++) {
  300. $gr = $arr_collections[$snum - 1];
  301. $icon_thumb = ($gr['link'] ? GetDirForCollection($gr['id']).'/' : '');
  302. $icon_thumb .= $gr['dir'].'/'.$gr['icon'];
  303. echo "\n<!-- Pic[$snum] : $icon_thumb --- ".$gr['dir']." :: ".$gr['icon']." -->\n";
  304. $icon = preg_replace('/[\/]+/', '/',
  305. (is_file(PICMAN_IMAGE_DIR.$icon_thumb) ?
  306. PICMAN_IMAGE.$icon_thumb
  307. :
  308. DEFAULT_COLLECTION_ICON
  309. )
  310. );
  311. $others = '';
  312. if (isset($links_output[$gr['uniqid']])) {
  313. foreach($links_output[$gr['uniqid']] as $catid => $catname) {
  314. $others .= sprintf('<a href="%si%03dp%03d.html" title="%s">&raquo;</a> ', PICMAN_MAIN, $catid, 1, $catname);
  315. }
  316. }
  317. if (PICMAN_ADMINISTRATION == 1) {
  318. $others .= sprintf('<a href="%si%03dp%03d.html" title="%s">[::]</a> ', PICMAN_ADMIN_COLLECTION, $gr['id'], 1, $catname);
  319. }
  320. $txt .= UpdateTemplate($item_txt, array(
  321. 'href' => sprintf(PICMAN_COLLECTION."i%03d.html", $gr['id']),
  322. 'name' => $gr['name'],
  323. 'count' => ($gr['count'] ? $gr['count'] : ''),
  324. 'icon' => $icon,
  325. 'dateupdate' => $gr['date'],
  326. 'others' => $others
  327. ));
  328. $snum++;
  329. }
  330. $txt .= $txt_postrow;
  331. }
  332. $txt .= $txt_post;
  333. }
  334. return array($txt, $pagesel);
  335. }
  336. function GetCatContent($id_cat, $item_txt, $txt_pre, $txt_post, $txt_prerow, $txt_postrow) {
  337. $cat = db_fetch_array(db_query("SELECT catcols, catrows FROM {categories} WHERE id = $id_cat"));
  338. if ($cat['catcols'] == 0 || $cat['catrows'] == 0) {
  339. $cat['catcols'] = 1;
  340. $cat['catrows'] = 8;
  341. }
  342. $perpage = $cat['catcols'] * $cat['catrows'];
  343. /*
  344. (SELECT count(*) FROM {collections} G WHERE G.uid_cat = C.uniqid) AS grcount,
  345. (SELECT count(*) FROM {links} L WHERE L.uid_cat = C.uniqid) AS lncount,
  346. (SELECT max(G.date_create) FROM {collections} G WHERE G.uid_cat = C.uniqid) AS dcreate
  347. */
  348. $result = db_query("
  349. SELECT
  350. C.id AS id, C.name AS name, C.lnum AS lnum
  351. FROM {categories} C
  352. WHERE C.id_parent = $id_cat AND C.hidden = 0
  353. ORDER BY lnum
  354. ");
  355. $txt = '';
  356. if ($num = db_num_rows($result)) {
  357. $txt .= $txt_pre;
  358. for ($rec = 0; $rec < $num; $rec++) {
  359. $item = db_fetch_array($result);
  360. $count = $item['grcount'] + $item['lncount'];
  361. if (($rec % $cat['catcols']) == 0) {
  362. $txt .= $txt_prerow;
  363. }
  364. $txt .= UpdateTemplate($item_txt, array(
  365. 'href' => sprintf(PICMAN_MAIN."i%03dp%03d.html", $item['id'], 1),
  366. 'name' => $item['name'],
  367. 'count' => ($count ? $count : ''),
  368. 'date' => (!empty($item['dcreate']) ? date('Y-m-d', strtotime($item['dcreate'])) : '')
  369. ));
  370. if ((($rec % $cat['catcols']) == ($cat['catcols'] - 1)) || ($rec == $num - 1)) {
  371. $txt .= $txt_postrow;
  372. }
  373. }
  374. $txt .= $txt_post;
  375. }
  376. return $txt;
  377. }
  378. function FramedTable1() {
  379. return '<div class="frame">';
  380. }
  381. function FramedTable2() {
  382. return '</div>';
  383. }
  384. function AdminMenu() {
  385. global $page_id;
  386. return
  387. FramedTable1().
  388. '<table><TR>
  389. <TD CLASS="menu"> <a href="'.PICMAN_INDEX.'" CLASS="menu">Index</a> </TD>
  390. <TH CLASS="menu"> Category: </TH><TD CLASS="menu"> '.
  391. sprintf('<a href="'.PICMAN_ADMIN_CAT.'i%03dp%03d.html"', 0, $page_id).
  392. ' CLASS="menu">New</a>'.
  393. ' :: '.
  394. '<a href="" CLASS="menu">Modify</a> :: <a href="" CLASS="menu">Delete</a> </TD>
  395. <TH CLASS="menu"> Collection: </TH><TD CLASS="menu"> <a href="'.PICMAN_ADMIN_COLLECTION.'" CLASS="menu">New</a> :: <a href="" CLASS="menu">Modify</a> :: <a href="" CLASS="menu">Delete</a> </TD>
  396. <TH CLASS="menu"> Link: </TH><TD CLASS="menu"> <a href="'.PICMAN_ADMIN_LINK.'" CLASS="menu">New</a> :: <a href="" CLASS="menu">Delete</a> </TD>
  397. </TR></table>'.
  398. FramedTable2();
  399. }
  400. // ---- FORMULARZE ------------------------------------------------
  401. function FrmTxt($form_text) {
  402. return htmlspecialchars(stripslashes(trim($form_text)));
  403. }
  404. function FrmDb($form_text) {
  405. return preg_replace("/'/", "''", stripslashes(trim($form_text)));
  406. }
  407. function FormHidden($name, $default = '') {
  408. global $frm;
  409. return '<input type="hidden" id="form-'.$name.'" name="frm['.$name.']" value="'.(isset($frm[$name]) ? FrmTxt($frm[$name]) : $default).'">';
  410. }
  411. function FormInput($name, $size = 50, $default = '') {
  412. global $frm;
  413. return '<input type="text" id="form-'.$name.'" name="frm['.$name.']" size="'.$size.'" value="'.(isset($frm[$name]) ? FrmTxt($frm[$name]) : $default).'">';
  414. }
  415. function FormSelect($name, $options = array(), $hash = 1) {
  416. global $frm;
  417. if (count($options) == 0) return '';
  418. if ($hash == 1) {
  419. foreach ($options as $key => $val)
  420. $txt .= '<option value="'.$key.'"'.(isset($frm[$name]) && $frm[$name] == $key ? ' selected="selected"' : '').'> '.$val.'</option>';
  421. } else {
  422. foreach ($options as $key)
  423. $txt .= '<option value="'.$key.'"'.(isset($frm[$name]) && $frm[$name] == $key ? ' selected="selected"' : '').'> '.$key.'</option>';
  424. }
  425. return '<select id="form-'.$name.'" name="frm['.$name.']">'.$txt.'</select>';
  426. }
  427. function FormCheckbox($name) {
  428. global $frm;
  429. return '<input type="checkbox" id="form-'.$name.'" name="frm['.$name.']" value="1"'.(isset($frm[$name]) && $frm[$name] ? ' checked="checked"' : '').'> ';
  430. }
  431. function FormCheckarea($name) {
  432. global $frm;
  433. $temp = '<span><input type="checkbox" name="frm[%s][]" value="%s" %s /> %s</span> ';
  434. $opt = $frm['#'.$name];
  435. $val = $frm[$name];
  436. $txt = '';
  437. if (is_array($opt) && count($opt)) {
  438. foreach ($opt as $key => $label) {
  439. $txt .= sprintf($temp, $name, $key, ((is_array($val) ? in_array($key, $val) : ($val == $key)) ? 'checked="checked"' : ''), $label);
  440. }
  441. }
  442. return $txt;
  443. }
  444. function FormText($name, $cols = 50, $rows = 4) {
  445. global $frm;
  446. return '<textarea id="form-'.$name.'" name="frm['.$name.']" cols="'.$cols.'" rows="'.$rows.'" wrap="physical">'.FrmTxt($frm[$name]).'</textarea>';
  447. }
  448. function GetCategoryData($id) {
  449. global $frm;
  450. $result = db_query("SELECT * FROM categories WHERE id = $id");
  451. if (db_num_rows($result)) {
  452. $cat = db_fetch_array($result);
  453. $frm[uniqid] = $cat['uniqid'];
  454. $frm[parent] = $cat['id_parent'];
  455. $frm[datecr] = date('Y-m-d', strtotime($cat['date_create']));
  456. $frm[name] = $cat['name'];
  457. $frm[title] = $cat['title'];
  458. $frm[header] = $cat['header'];
  459. $frm[desc] = $cat['description'];
  460. $frm[dircat] = $cat['catdir'];
  461. $frm[dirtem] = $cat['template'];
  462. $sql_options = $cat['options'];
  463. $frm[catrow] = $cat['catrows'];
  464. $frm[catcol] = $cat['catcols'];
  465. $frm[grrow] = $cat['colrows'];
  466. $frm[grcol] = $cat['colcols'];
  467. if (!empty($cat['hidden']) && $cat['hidden']) $frm[cathid] = 1;
  468. }
  469. }
  470. function GetLinkData($id) {
  471. global $frm;
  472. $result = db_query("
  473. SELECT C.id AS cid, L.weight AS weight, G.id AS gid, G.name AS name
  474. FROM {links} L
  475. INNER JOIN {collections} G ON (L.uid_col = G.uniqid)
  476. INNER JOIN {categories} C ON (L.uid_cat = C.uniqid)
  477. WHERE L.id = $id
  478. ");
  479. if (db_num_rows($result)) {
  480. $link = db_fetch_array($result);
  481. $frm[parent] = $link['cid'];
  482. $frm[position] = $link['weight'];
  483. $frm[idgr] = $link['gid'];
  484. $frm[name] = $link['name'];
  485. }
  486. }
  487. function GetCollectionData($id) {
  488. global $frm;
  489. $result = db_query("
  490. SELECT
  491. G.uniqid AS uniqid, C.id AS cid, G.weight AS weight, G.date_create AS date_create,
  492. G.name AS name, G.title AS title, G.header AS header, G.description AS description,
  493. G.startnum AS startnum, G.quantity AS quantity, G.holes AS holes,
  494. G.coldir AS coldir, G.picsubdir AS picsubdir, G.thumbsubdir AS thumbsubdir,
  495. G.pictemp AS pictemp, G.thumbtemp AS thumbtemp, G.pgnumtemp AS pgnumtemp,
  496. G.imgindex AS imgindex, G.icoindex AS icoindex,
  497. G.rows AS rows, G.cols AS cols, G.options AS options
  498. FROM {collections} G
  499. INNER JOIN {categories} C ON (G.uid_cat = C.uniqid)
  500. WHERE G.id = $id
  501. ");
  502. if (db_num_rows($result)) {
  503. $cat = db_fetch_array($result);
  504. $frm[uniqid] = $cat['uniqid'];
  505. $frm[parent] = $cat['cid'];
  506. $frm[position] = $cat['weight'];
  507. $frm[datecr] = date('Y-m-d', strtotime($cat['date_create']));
  508. $frm[name] = $cat['name'];
  509. $frm[title] = $cat['title'];
  510. $frm[header] = $cat['header'];
  511. $frm[desc] = $cat['description'];
  512. $frm[first] = $cat['startnum'];
  513. $frm[quantity] = $cat['quantity'];
  514. $frm[holes] = $cat['holes'];
  515. $frm[dirgr] = $cat['coldir'];
  516. $frm[dirimg] = $cat['picsubdir'];
  517. $frm[dirth] = $cat['thumbsubdir'];
  518. $frm[tempimg] = $cat['pictemp'];
  519. $frm[tempth] = $cat['thumbtemp'];
  520. $frm[temppage] = $cat['pgnumtemp'];
  521. $frm[introimg] = $cat['imgindex'];
  522. $frm[thumbimg] = $cat['icoindex'];
  523. $frm[serrow] = $cat['rows'];
  524. $frm[sercol] = $cat['cols'];
  525. $sql_options = $cat['options'];
  526. $arr_options = split('\|', $sql_options);
  527. if (in_array('HOME', $arr_options)) $frm[intro] = 1;
  528. if (in_array('LP', $arr_options)) {
  529. $frm[options] = 'LP';
  530. } elseif (in_array('LI', $arr_options)) {
  531. $frm[options] = 'LI';
  532. }
  533. }
  534. }
  535. function GetTags($id = null) {
  536. $result = db_query("
  537. SELECT T.id AS id, T.name AS name, T.weight AS weight
  538. FROM {tags} T
  539. INNER JOIN {tag_collections} TC ON (TC.id_tag = T.id)
  540. INNER JOIN {collections} C ON (C.id = TC.id_col)
  541. ORDER BY T.weight DESC, T.name
  542. ");
  543. $tags = array();
  544. while ($tag = db_fetch_array($result)) {
  545. $tags[$tag['id']] = $tag['name'];
  546. }
  547. return $tags;
  548. }
  549. function SetCollectionTags($id, $name) {
  550. global $frm;
  551. $result = db_query("
  552. SELECT T.id AS id, T.name AS name
  553. FROM {tags} T
  554. INNER JOIN {tag_collections} TC ON (TC.id_tag = T.id)
  555. INNER JOIN {collections} C ON (C.id = TC.id_col)
  556. WHERE C.id = %d
  557. ", $id);
  558. while ($tag = db_fetch_array($result)) {
  559. $frm[$name][] = $tag['id'];
  560. }
  561. }
  562. // Type: 0 - category, 1 - group, 2 - link
  563. function GetCategoriesHierarchy($default = 0, $id = 0, $type = 1) {
  564. if ($default == 0 && $id == 0) {
  565. $result = db_query("
  566. SELECT id, name, lnum, rnum, hidden
  567. FROM categories
  568. WHERE NOT id IN (SELECT C.id FROM {categories} C, {categories} P WHERE P.hidden = 1 AND C.lnum BETWEEN P.lnum AND P.rnum)
  569. ORDER BY lnum
  570. ");
  571. }
  572. else {
  573. $result = db_query("
  574. SELECT C.id AS id, C.name AS name, C.lnum AS lnum, C.rnum AS rnum, C.hidden AS hidden
  575. FROM {categories} C, {categories} A".($type == 2 ? ", {categories} L" : '')."
  576. WHERE
  577. ".($id != 0 && $type == 0 ?
  578. "A.id = $id AND C.id != $id"
  579. :
  580. ($type == 2 ?
  581. "(L.id = $default AND A.id_parent = 0 AND A.lnum < L.lnum AND A.rnum > L.rnum)"
  582. :
  583. "A.id = $default"
  584. )
  585. )." AND (
  586. C.id_parent = 0
  587. OR C.id_parent = A.id_parent
  588. OR C.id IN (456,852,172,173,174,175,176,177,178,356,14108)
  589. OR (C.lnum <= A.lnum AND C.rnum >= A.rnum)
  590. ".($type == 1 || $type == 2 ? "OR (C.lnum BETWEEN A.lnum AND A.rnum)" : '')."
  591. )
  592. ORDER BY C.lnum
  593. ");
  594. }
  595. if ($num = db_num_rows($result)) {
  596. $tree = new TreeDraw();
  597. $tree->default = $default;
  598. $add_num = $default == 0 || $id == 0 ? 1 : 0;
  599. $max_num = 0;
  600. while ($cat = db_fetch_array($result)) {
  601. if ($cat['hidden']) $cat['name'] = '(*) '.$cat['name'];
  602. if ($cat['rnum'] > $max_num) $max_num = $cat['rnum'];
  603. $tree->AddNode($cat['lnum'] + $add_num, array($cat['rnum'] + $add_num, NTTREE_DOT, $cat['id'], $cat['name']));
  604. }
  605. if ($default == 0 || $id == 0) $tree->AddNode(1, array($max_num + 1, NTTREE_DOT, 0, ''));
  606. return $tree->GetOptions();
  607. }
  608. return '';
  609. }
  610. // -------------------------------------------------------------------------
  611. SetPageParams();
  612. $PICMAN_INFO = array (
  613. 'dircat' => GetDirForCat($page_id),
  614. 'dirgrp' => ''
  615. );
  616. include PICMAN_INCLUDE . ParsePage();
  617. // -------------------------------------------------------------------------
  618. db_close();
  619. class TreeDraw {
  620. var $content;
  621. /*
  622. * Czy ma rysować kropkę-root
  623. */
  624. var $draw_root;
  625. /*
  626. * For draw:
  627. * array ( lnum => array (rnum, image, auth, text, subnodes), ... )
  628. * For options:
  629. * array ( lnum => array (rnum, image, id, text, subnodes), ... )
  630. */
  631. var $nodes;
  632. var $max_rnum;
  633. /*
  634. * Wartość domyślna dla options
  635. */
  636. var $default;
  637. // czy posiada jakiś potomków
  638. // -> dla poprawnego rysowania subnodes
  639. var $has_children;
  640. /*
  641. * Like nodes but set by DrawNodes
  642. */
  643. var $subnode;
  644. var $images;
  645. var $image_align;
  646. /**
  647. * function TreeDraw
  648. *
  649. * @param integer $nodes
  650. * @return integer
  651. */
  652. function TreeDraw($nodes = "") {
  653. $this->ClearData();
  654. if (is_array($nodes)) {
  655. $this->nodes = $nodes;
  656. }
  657. }
  658. /**
  659. * function ClearData
  660. *
  661. * @return integer
  662. */
  663. function ClearData() {
  664. $this->content = '';
  665. $this->draw_root = 1;
  666. $this->nodes = array ();
  667. $this->max_rnum = 0;
  668. $this->default = 0;
  669. $this->has_children = 0;
  670. $this->subnode = 0;
  671. $this->images = array (
  672. NTTREE_DOT => NTWEB_IMAGE.'tree_dot.gif',
  673. NTTREE_FILE => NTWEB_IMAGE.'tree_file.gif',
  674. NTTREE_DIR => NTWEB_IMAGE.'tree_dir.gif',
  675. NTTREE_TEAM => NTWEB_IMAGE.'tree_team.gif',
  676. NTTREE_PROJ => NTWEB_IMAGE.'tree_proj.gif',
  677. NTTREE_COLLECTION => NTWEB_IMAGE.'tree_file.gif',
  678. NTTREE_USER => NTWEB_IMAGE.'tree_user.gif',
  679. NTTREE_BOOKUSER => NTWEB_IMAGE.'tree_bookuser.gif',
  680. NTTREE_DELUSER => NTWEB_IMAGE.'tree_deluser.gif',
  681. );
  682. $this->image_align = 'absmiddle';
  683. }
  684. /**
  685. * function AddNode
  686. *
  687. * @param integer $lnum
  688. * @param integer $date
  689. * @return integer
  690. */
  691. function AddNode($lnum, $date) {
  692. if (is_array($date)) {
  693. $this->nodes[$lnum] = $date;
  694. if ($date[0] > $this->max_rnum) $this->max_rnum = $date[0];
  695. return 1;
  696. }
  697. return 0;
  698. }
  699. /**
  700. * function GetOptions
  701. *
  702. * @return integer
  703. */
  704. function GetOptions() {
  705. // Czy jest ustawione max_rnum, jeżeli nie to wyszukanie
  706. if (!$this->max_rnum) {
  707. foreach ($this->nodes as $lnum => $date) {
  708. $rnum = $date[0];
  709. if ($rnum > $this->max_rnum) {
  710. $this->max_rnum = $rnum;
  711. }
  712. }
  713. }
  714. $lnum = 1;
  715. while ($lnum < $this->max_rnum) {
  716. $rnum = $this->GetNodesOption($lnum);
  717. if ($rnum) $lnum = $rnum;
  718. $lnum++;
  719. }
  720. return $this->content;
  721. }
  722. /**
  723. * function GetNodesOption
  724. *
  725. * @param integer $lnum
  726. * @param integer $level
  727. * @return integer
  728. */
  729. function GetNodesOption($lnum = 1, $level = 0) {
  730. if (!isset($this->nodes[$lnum])) return 0;
  731. $rnum = $this->nodes[$lnum][0];
  732. $id = $this->nodes[$lnum][2];
  733. $text = $this->nodes[$lnum][3];
  734. $children = ($rnum - $lnum - 1) / 2;
  735. $this->content .=
  736. '<option value="'.$id.'"'.
  737. (($this->default && $this->default == $id) ? " SELECTED> " : "> ");
  738. if ($level) {
  739. for ($sp = 1; $sp <= $level; $sp++) {
  740. $this->content .= '--';
  741. }
  742. }
  743. $this->content .= " $text</option>";
  744. if ($children) {
  745. $child_rnum = 0;
  746. // Posiada potomków -> wywołanie rekurencyjne
  747. while ($lnum < $rnum) {
  748. $child_lnum = $lnum + 1;
  749. if (isset($this->nodes[$child_lnum])) {
  750. $child_rnum = $this->GetNodesOption($child_lnum, $level + 1);
  751. $lnum = $child_rnum - 1;
  752. }
  753. $lnum++;
  754. }
  755. }
  756. return $rnum;
  757. }
  758. /**
  759. * function Draw
  760. *
  761. * @return integer
  762. */
  763. function Draw() {
  764. // Czy jest ustaione max_rnum, jeżeli nie to wyszukanie
  765. if (!$this->max_rnum) {
  766. foreach ($this->nodes as $lnum => $date) {
  767. $rnum = $date[0];
  768. if ($rnum > $this->max_rnum) {
  769. $this->max_rnum = $rnum;
  770. }
  771. }
  772. }
  773. $lnum = 1;
  774. while ($lnum < $this->max_rnum) {
  775. $rnum = $this->DrawNodes($lnum);
  776. if ($rnum) $lnum = $rnum;
  777. $lnum++;
  778. }
  779. return $this->content;
  780. }
  781. /**
  782. * function DrawNodes
  783. *
  784. * @param integer $lnum
  785. * @param integer $parent_rnum
  786. * @param integer $before
  787. * @return integer
  788. */
  789. function DrawNodes($lnum = 1, $parent_rnum = 0, $before = array () ) {
  790. if (!isset($this->nodes[$lnum])) return 0;
  791. $rnum = $this->nodes[$lnum][0];
  792. $image = $this->nodes[$lnum][1];
  793. $auth_img = $this->nodes[$lnum][2];
  794. $text = $this->nodes[$lnum][3];
  795. $num = count($before);
  796. $children = ($rnum - $lnum - 1) / 2;
  797. $this->subnode = 0;
  798. $this->has_children = $children;
  799. // Jeżeli jest na szczycie
  800. if ($num == 0) {
  801. $this->DrawBefore(array("dot"));
  802. $before = array("space");
  803. }
  804. elseif ($rnum + 1 == $parent_rnum) {
  805. if ($before[$num - 1] == "middle") {
  806. $before[$num - 1] = "end";
  807. $this->DrawBefore($before);
  808. $before[$num - 1] = "space";
  809. }
  810. }
  811. else {
  812. $this->DrawBefore($before);
  813. $before[$num - 1] = "line";
  814. }
  815. $before[] = "middle";
  816. // Narysowanie ilustracji i tekstu
  817. $this->DrawImage($image);
  818. $this->DrawAuthImage($auth_img);
  819. $this->content .= " $text</nobr><br clear=\"ALL\">\n";
  820. // Jeżeli są jakieś inne elementy podczepione
  821. if (is_array($this->nodes[$lnum][4])) {
  822. $this->subnode = $this->nodes[$lnum][4];
  823. $this->DrawSubNodes(1, 0, $before);
  824. }
  825. if ($children) {
  826. $child_rnum = 0;
  827. // Posiada potomków -> wywołanie rekurencyjne
  828. while ($lnum < $rnum) {
  829. $child_lnum = $lnum + 1;
  830. if (isset($this->nodes[$child_lnum])) {
  831. $child_rnum = $this->DrawNodes($child_lnum, $rnum, $before);
  832. $lnum = $child_rnum - 1;
  833. }
  834. $lnum++;
  835. }
  836. // Występują jeszcze jakieś elementy (ale brak do nich uprawnień)
  837. if ($child_rnum + 1 != $rnum) {
  838. $num = count($before);
  839. if ($before[$num - 1] == "middle") {
  840. $before[$num - 1] = "end";
  841. }
  842. $before[] = "dots";
  843. $this->DrawBefore($before);
  844. $this->content .= "</nobr><br clear=\"ALL\">\n";
  845. }
  846. }
  847. return $rnum;
  848. }
  849. /**
  850. * Wyświetlenie wszystkich potomków wyświetlenie tych o numerach od 1 do
  851. * rnum
  852. *
  853. * @param integer $lnum
  854. * @param integer $parent_rnum
  855. * @param integer $before
  856. * @param integer $level
  857. * @return integer
  858. */
  859. function DrawSubNodes($lnum = 1, $parent_rnum = 0, $before = array (), $level = 0 ) {
  860. if (!$this->subnode || !isset($this->subnode[$lnum])) return 0;
  861. $rnum = $this->subnode[$lnum][0];
  862. $image = $this->subnode[$lnum][1];
  863. $auth_img = $this->subnode[$lnum][2];
  864. $text = $this->subnode[$lnum][3];
  865. $num = count($before);
  866. $children = ($rnum - $lnum - 1) / 2;
  867. // Jeżeli jest na szczycie
  868. if ($parent_rnum == 0) {
  869. // Brak wyświetlenia pierwszego - głównego
  870. }
  871. elseif ($rnum + 1 == $parent_rnum) {
  872. if ($before[$num - 1] == "middle") {
  873. if ($level == 1 && $this->has_children) {
  874. $this->DrawBefore($before);
  875. $before[$num - 1] = "line";
  876. }
  877. else {
  878. $before[$num - 1] = "end";
  879. $this->DrawBefore($before);
  880. $before[$num - 1] = "space";
  881. }
  882. $before[] = "middle";
  883. }
  884. }
  885. else {
  886. $this->DrawBefore($before);
  887. $before[$num - 1] = "line";
  888. $before[] = "middle";
  889. }
  890. // Narysowanie ilustracji i tekstu
  891. if ($parent_rnum) {
  892. $this->DrawImage($image);
  893. $this->DrawAuthImage($auth_img);
  894. $this->content .= " $text</nobr><br clear=\"ALL\">\n";
  895. }
  896. if ($children) {
  897. // Posiada potomków -> wywołanie rekurencyjne
  898. while ($lnum < $rnum) {
  899. $child_lnum = $lnum + 1;
  900. if (isset($this->subnode[$child_lnum])) {
  901. $child_rnum = $this->DrawSubNodes($child_lnum, $rnum, $before, $level + 1);
  902. $lnum = $child_rnum - 1;
  903. }
  904. $lnum++;
  905. }
  906. }
  907. return $rnum;
  908. }
  909. /**
  910. * function DrawBefore
  911. *
  912. * @param integer $before
  913. * @return integer
  914. */
  915. function DrawBefore($before = array () ) {
  916. $this->content .= "<nobr>";
  917. foreach ($before as $item) {
  918. switch ($item) {
  919. case "dot" :
  920. if ($this->draw_root)
  921. $this->content .= '<img src="'.$this->images[NTTREE_DOT].'" width=18 height=18 hspace=0 vspace=0 border=0 align="'.$this->image_align.'" alt="">';
  922. break;
  923. case "line" :
  924. case "middle":
  925. case "end" :
  926. case "dots" :
  927. case "space" :
  928. $this->content .= '<img src="'.NTWEB_IMAGE."tree_$item".'.gif" width=18 height=18 hspace=0 vspace=0 border=0 align="'.$this->image_align.'" alt="">';
  929. break;
  930. }
  931. }
  932. }
  933. /**
  934. * function DrawAuthImage
  935. *
  936. * @param integer $idx
  937. * @return integer
  938. */
  939. function DrawAuthImage($idx) {
  940. $images = array (
  941. 1 => 'auth_private',
  942. 2 => 'auth_authorize',
  943. 3 => 'auth_team'
  944. );
  945. if ($idx) {
  946. // Narysowanie odpowiednich ikon
  947. $this->content .= '<img src="'.NTWEB_IMAGE.$images[$idx].'.gif" width=18 height=18 hspace=0 vspace=0 border=0 align="'.$this->image_align.'" alt="">';
  948. }
  949. }
  950. /**
  951. * function DrawImage
  952. *
  953. * @param integer $idx
  954. * @return integer
  955. */
  956. function DrawImage($idx) {
  957. if ($idx >= 1 && $idx <= NTTREE_DELUSER) {
  958. $this->content .= '<img src="'.$this->images[$idx].'" width=18 height=18 hspace=0 vspace=0 border=0 align="'.$this->image_align.'" alt="">';
  959. }
  960. }
  961. }
  962. ?>