/** * Stores data for new categories */ function save_category($edit = 0) { global $xoopsDB, $xoopsModuleConfig, $xoopsModule; $q = 'images.php?action=' . ($edit ? 'editcat' : 'newcat'); foreach ($_POST as $k => $v) { if ($k == 'action' || $k == 'XOOPS_TOKEN_REQUEST') { continue; } if (is_array($v)) { $q .= '&' . RMFunctions::urlencode_array($v, $k); } else { $q .= '&' . $k . '=' . urlencode($v); } } extract($_POST); if ($edit) { if ($id <= 0) { redirectMsg('images.php?action=showcats', __('Specify a valid category id', 'rmcommon'), 1); die; } $cat = new RMImageCategory($id); if ($cat->isNew()) { redirectMsg('images.php?action=showcats', __('Specified category does not exists!', 'rmcommon'), 1); die; } } else { $cat = new RMImageCategory(); } if ($name == '') { redirectMsg($q, __('Please specify a category name', 'rmcommon'), 1); die; } if (empty($read)) { $read = array(0); } if (empty($write)) { $write = array(0); } // Check if resize data is correct $schecked = array(); foreach ($sizes as $size) { if (trim($size['name']) == '') { continue; } if ($size['type'] != 'none' && $size['width'] <= 0 && $size['height'] <= 0) { continue; } $schecked[] = $size; } if (empty($schecked)) { redirectMsg($q, __('You must create one size for this category at least!', 'rmcommon'), 1); die; } // Check if there are a category with same name $num = RMFunctions::get_num_records('rmc_img_cats', "name='{$name}'" . ($edit ? " AND id_cat<>'" . $cat->id() . "'" : '')); if ($num > 0) { redirectMsg($q, __('There is already a category with the same name!', 'rmcommon'), 1); die; } $cat->setVar('name', $name); $cat->setVar('status', $status); $cat->setVar('groups', array('write' => $write, 'read' => $read)); $cat->setVar('sizes', $schecked); $cat->setVar('filesize', $filesize <= 0 ? '50' : $filesize); $cat->setVar('sizeunit', $sizeunit <= 0 ? '1024' : $sizeunit); if ($cat->save()) { redirectMsg('images.php?action=showcats', __($edit ? 'Category updated successfully!' : 'Category saved successfully!', 'rmcommon'), 0); } else { redirectMsg($q, __('There were some erros while trying to save this category.', 'rmcommon') . '<br />' . $cat->errors(), 1); } }