function save($redirect = true) { global $my, $mainframe, $database, $option, $priTask, $subTask; global $WBG_CONFIG, $wbGalleryDB_cat, $wbGallery_eng; // ==============================v======================================== // Category Record $row = new wbGalleryDB_cat($database); $row->bind($_POST); if (!$row->id) { $row->ordering = 999999999; } if ($row->parent_id == $row->id) { $row->parent_id = 0; } // clean title if (!$row->title) { $row->title = $row->name; } $allowed = "/[^a-z0-9\\040\\.\\-\\_]/i"; // Letters, Digits, Hyphen, Underscore $row->title = preg_replace($allowed, ' ', strtolower($row->title)); $row->title = preg_replace('/\\_+/', '_', preg_replace('/\\s+/', '_', $row->title)); // remove file if specified if (mosGetParam($_POST, '_delFile', null) == 'true') { $row->file = null; } $row->published = intval(mosGetParam($_REQUEST, 'published', 0)); if (!$row->check()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } $row->updateOrder("parent_id = '" . $row->parent_id . "'"); // ==============================v======================================== // Category Image File if (!empty($_FILES['img']['tmp_name'])) { if ($row->file) { $wbGallery_eng->remove($row->file); } echo "Updating Category Image <br/>"; $known_images = array('image/pjpeg', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif'); if (!in_array($_FILES['img']['type'], $known_images)) { echo "<script> alert('Image type: " . $_FILES['img']['type'] . " is an unknown type');\r\n document.location.href='index2.php?option=" . $option . "&task=category.edit&id=" . $row->id . "'; </script>\n"; exit; } $imgData = $wbGallery_eng->add($_FILES['img']['tmp_name'], $_FILES['img']['name'], $_FILES['img']['type'], $row, false); if ($imgData->file) { $row->file = $imgData->file; if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } } else { echo "<script> alert('Failed to Store Category Image');\r\n document.location.href='index2.php?option=" . $option . "&task=category.edit&id=" . $row->id . "'; </script>\n"; exit; } } // ==============================v======================================== if ($redirect) { switch ($subTask) { case 'save': mosRedirect('index2.php?option=' . $option . '&task=category&parent_id=' . $row->parent_id, 'Changes to category saved'); break; case 'apply': mosRedirect('index2.php?option=' . $option . '&task=category.edit&id=' . $row->id . '&hidemainmenu=1', 'Changes to category saved'); break; } } else { return $row->id; } }