function view($id, $params) { global $my, $mainframe, $database, $option, $priTask, $subTask; global $WBG_CONFIG, $wbGalleryDB_cat; if (!$id) { $id = $params->get('id', 0); } // Load Image $row = new wbGalleryDB_img($database); $row->load($id); if (!$row->id) { echo "<script> alert('Image Not Found'); window.history.go(-1); </script>\n"; exit; } // Track Hit $row->hit(); // Load Category if ($row->cat_id != '0') { $cat = new wbGalleryDB_cat($database); $cat->load($row->cat_id); if (!$cat->id) { echo "<script> alert('Category Not Found'); window.history.go(-1); </script>\n"; exit; } if ($cat->access > $my->gid) { mosNotAuth(); exit; } } // Load Prev / Next $neighbors = $row->getNeighbors(); // Load Related Images $database->setQuery("\r\r\n SELECT i.*\r\r\n FROM #__wbgallery_img AS i\r\r\n WHERE i.cat_id = " . (int) $row->cat_id . "\r\r\n AND i.id != " . (int) $row->id . "\r\r\n AND i.published = 1\r\r\n ORDER BY i.hits DESC\r\r\n , i.ordering ASC\r\r\n LIMIT 0, " . $params->get('related_list_limit', $mainframe->getCfg('list_limit', 15)) . "\r\r\n "); $related = $database->loadObjectList(); echo $database->getErrorMsg(); wbGallery_img_html::view($row, $cat, $neighbors, $related, $params); }
function order($cid) { global $my, $mainframe, $database, $option, $priTask, $subTask; global $WBG_CONFIG, $wbGalleryDB_cat; $row = new wbGalleryDB_img($database); $conditions = array(); $first = mosGetParam($_POST, 'first', 0); $order = mosGetParam($_POST, 'order', array(0)); if (preg_match('/\\d+\\,\\d+/', $order)) { $order = split(',', $order); } if ($first > 0) { $row->load($first); $database->setQuery(' SELECT i.* FROM #__wbgallery_img AS i WHERE i.ordering < ' . $ordering . ' AND i.cat_id = ' . $row->cat_id); $database->loadObject($lowest_row); if ($lowest_row->id) { $ordering = $lowest_row->ordering + 1; } else { $ordering = 1; } $res = true; foreach ($order as $id) { $database->setQuery("\r\r\n UPDATE #__wbgallery_img AS i\r\r\n SET i.ordering='" . $ordering++ . "'\r\r\n WHERE i.id= {$id}\r\r\n "); if ($database->query() != 1) { $res = false; } } if ($res) { echo "Order Updated..."; } else { echo "Order Update Failed !!!"; } } else { for ($i = 0, $n = count($cid); $i < $n; $i++) { $row->load($cid[$i]); if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->store()) { echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n"; exit; } $condition = 'cat_id = ' . (int) $row->cat_id; $found = false; for ($j = 0, $k = count($conditions); $j < $k; $j++) { $cond = $conditions[$j]; if ($cond[1] == $condition) { $found = true; break; } } if (!$found) { $conditions[] = array($row->id, $condition); } } } for ($i = 0, $n = count($conditions); $i < $n; $i++) { $condition = $conditions[$i]; $row->load($condition[0]); $row->updateOrder($condition[1]); } mosRedirect('index2.php?option=' . $option . '&task=image'); } exit; }