function _uploads_CopyCategory(&$module, $orig_category_id, $dest_name, $dest_path, $dest_desc, $copyfiles, $edit_desc = true) { global $gCms; $config = $gCms->GetConfig(); // get the original category $orig_category = Uploads::load_category_by_id($orig_category_id); if (!$orig_category) { return $module->Lang('error_categorynotfound'); } $dest_category = $orig_category; if (empty($dest_name)) { return $module->Lang('error_missing_invalid', 'name'); } if (empty($dest_path)) { return $module->Lang('error_missing_invalid', 'path'); } $tmp = Uploads::getCategoryFromName($dest_name); if (is_array($tmp)) { return $module->Lang('error_categoryexists2', $dest_name); } $tmp2 = Uploads::category_path_in_use($dest_path); if ($tmp2) { return $module->Lang('error_pathinuse2', $dest_path); } $srcdir = cms_join_path($config['uploads_path'], $orig_category['upload_category_path']); $destdir = cms_join_path($config['uploads_path'], $dest_path); if (file_exists($destdir)) { return $module->Lang('error_fileexists', $destdir); } if (!file_exists($srcdir)) { return $module->Lang('error_filenotfound', $srcdir); } $dest_category['upload_category_name'] = $dest_name; $dest_category['upload_category_path'] = $dest_path; if ($edit_desc) { $dest_category['upload_category_description'] = $dest_desc; } global $gCms; $db =& $gCms->GetDb(); $catid = $db->GenID(cms_db_prefix() . "module_uploads_categories_seq"); $query = 'INSERT INTO ' . cms_db_prefix() . 'module_uploads_categories (upload_category_id,upload_category_name, upload_category_description,upload_category_path, upload_category_listable,upload_category_groups, upload_category_deletable) VALUES (?,?,?,?,?,?,?)'; $dbr = $db->Execute($query, array($catid, $dest_category['upload_category_name'], $dest_category['upload_category_description'], $dest_category['upload_category_path'], $dest_category['upload_category_listable'], $dest_category['upload_category_groups'], $dest_category['upload_category_deletable'])); if (!$dbr) { return $module->Lang('error_dberror'); } @mkdir($destdir, 0777, true); if (!file_exists($destdir)) { $query = 'DELETE FROM ' . cms_db_prefix() . 'module_uploads_categories WHERE upload_category_id = ?'; $db->Execute($query, array($catid)); return $module->Lang('error_cantcreatedirectory' . ': ' . $destdir); } if ($module->GetPreference('create_dummy_index_html')) { @touch($destdir . DIRECTORY_SEPARATOR . "index.html"); } // send an event $parms = array(); $parms['name'] = $dest_category['upload_category_name']; $parms['description'] = $dest_category['upload_category_description']; $parms['path'] = $dest_category['upload_category_path']; $parms['listable'] = $dest_category['upload_category_listable']; $parms['deletable'] = $dest_category['upload_category_deletable']; $module->SendEvent('OnCreateCategory', $parms); $error = array(); if ($copyfiles) { // now copy the files. $author = $_SESSION['cms_admin_username']; $now = $db->DbTimeSTamp(time()); $file_records = Uploads::get_category_file_list($orig_category_id); $iquery = 'INSERT INTO ' . cms_db_prefix() . "module_uploads\n (upload_id,upload_category_id,upload_name,\n upload_author,upload_summary,upload_description,\n upload_ip,upload_size,upload_date,\n upload_key,upload_thumbnail)\n VALUES(?,?,?,?,?,?,?,?,{$now},?,?)"; if (!is_array($file_records)) { break; } for ($i = 0; $i < count($file_records); $i++) { if (!empty($error)) { break; } $did_copy_thumb = false; $destthumb = ''; $onerec =& $file_records[$i]; // get the file path $srcfile = cms_join_path($srcdir, $onerec['upload_name']); $destfile = cms_join_path($destdir, $onerec['upload_name']); // copy the file copy($srcfile, $destfile); // check for a thumbnail $srcthumb = cms_join_path($srcdir, 'thumb_' . $onerec['upload_name']); $destthumb = cms_join_path($destdir, 'thumb_' . $onerec['upload_name']); if (file_exists($srcdir)) { // copy it $destthumb = cms_join_path($destdir, 'thumb_' . $onerec['upload_name']); copy($srcthumb, $destthumb); $did_copy_thumb = true; } // generate a new file id $file_id = $db->GenID(cms_db_prefix() . "module_uploads_seq"); // alter the record $onerec['upload_id'] = $file_id; $onerec['upload_category_id'] = $catid; $onerec['upload_author'] = $author; $onerec['upload_ip'] = null; // insert it. $dbr = $db->Execute($iquery, array($file_id, $onerec['upload_category_id'], $onerec['upload_name'], $onerec['upload_author'], $onerec['upload_summary'], $onerec['upload_description'], $onerec['upload_ip'], $onerec['upload_size'], $onerec['upload_key'], $onerec['upload_thumbnail'])); // on error delete files. if (!$dbr) { @unlink($destfile); @unlink($destthumb); if (!is_array($error)) { $error = array(); } $error[] = $module->Lang('error_dberror'); } } } // copy files if (!$error) { return $error; } return FALSE; }