Location: PHPKode > projects > PodAdmin - Web-based podcast management > podadmin-0.5.1/itunes-categories.php
<?php
// indicate which categories should be checked
print "checkedCats = new Array();\n";
if ($_POST['itunes_categories']) {
	foreach ($_POST['itunes_categories'] as $checkedCat) {
		$checkedCat = str_replace(" ","_",$checkedCat);
		print "checkedCats['$checkedCat'] = 1;\n";
		} // close foreach
	} // close if
?>

// function to count the number of selected categories, iTunes only allows 3
function countCats(lastChecked) {
  // if they are unchecking, don't even bother
  if (!lastChecked.checked) return;
  
  // otherwise, see how many categories they have checked, and if they
  // already have three, throw an alert and uncheck the one they just
  // tried to add.
  el = document.configform['itunes_categories[]'];
  counter = 0;
  for (i=0;i<el.length;i++) {
    if (el[i].checked) counter++;
    }
  if (counter > 3) {
    alert('iTunes only allows up to three categories.  Uncheck other categories first.');
	lastChecked.checked = false;
	}
  }


function addSubCat(parentfolderObject, itemLabel) {
  var newObj;
  var itemValue;
  
  newObj = insDoc(parentfolderObject, gLnk("R", itemLabel, "javascript:parent.op()"));

  // if the cat and subcat are the same, then this is a top level cat only, don't
  // store the value in the cat/subcat format.
  if (parentfolderObject.desc == itemLabel) {
  	itemValue = itemLabel;
	}
  else {
    itemValue = parentfolderObject.desc + "/" + itemLabel;
	}

  itemValue = itemValue.replace(/ /g,'_');
  
  //if (itemValue.match(/Fitness/)) {alert(itemValue);}
  
  // had strange problem with spaces in the value... until I get it figured out, just replace
  // them with underscores
  newObj.prependHTML = "<td valign=middle><input type=checkbox name='itunes_categories[]' value=" + 
  	itemValue + " onclick='countCats(this)'" + ifChecked(itemValue) + "></td>";
 
  }

function ifChecked(value) {
  if (checkedCats[value]) return " checked";
  else return " ";
  }

USETEXTLINKS = 0  
STARTALLOPEN = 0
HIGHLIGHT = 0
PRESERVESTATE = 1

// NOTE:  If you are going to set USEICONS = 1, then you will want to edit the gif 
// files and remove the white space on the right
USEICONS = 0
ICONPATH = "resources/Treeview/"

// In this case we want the whole tree to be built, even those branches that are 
// closed. The reason is that otherwise some form elements might not be built at 
// all before the user presses the "Get Values" button.
BUILDALL = 1

foldersTree = gFld("Choose up to three categories:", "");

foldersTree.treeID = "checkboxTree";
Arts = insFld(foldersTree, gFld("Arts"));
addSubCat(Arts, "Design");
addSubCat(Arts, "Fashion & Beauty");
addSubCat(Arts, "Food");
addSubCat(Arts, "Literature");
addSubCat(Arts, "Performing Arts");
addSubCat(Arts, "Visual Arts");

Business = insFld(foldersTree, gFld("Business"));
addSubCat(Business, "Business News");
addSubCat(Business, "Careers");
addSubCat(Business, "Investing");
addSubCat(Business, "Management & Marketing");
addSubCat(Business, "Shopping");

Comedy = insFld(foldersTree, gFld("Comedy"));
addSubCat(Comedy, "Comedy");

Education = insFld(foldersTree, gFld("Education"));
addSubCat(Education, "Education Technology");
addSubCat(Education, "Higher Education");
addSubCat(Education, "K-12");
addSubCat(Education, "Language Courses");
addSubCat(Education, "Training");

Government = insFld(foldersTree, gFld("Government & Organizations"));
addSubCat(Government, "Local");
addSubCat(Government, "National");
addSubCat(Government, "Non-Profit");
addSubCat(Government, "Regional");

Health = insFld(foldersTree, gFld("Health"));
addSubCat(Health, "Alternative Health");
addSubCat(Health, "Fitness & Nutrition");
addSubCat(Health, "Self-Help");
addSubCat(Health, "Sexuality");

Kids = insFld(foldersTree, gFld("Kids & Family"));
addSubCat(Kids, "Kids & Family");

Music = insFld(foldersTree, gFld("Music"));
addSubCat(Music, "Music");

News = insFld(foldersTree, gFld("News & Politics"));
addSubCat(News, "News & Politics");

Religion = insFld(foldersTree, gFld("Religion & Spirituality"));
addSubCat(Religion, "Buddhism");
addSubCat(Religion, "Christianity");
addSubCat(Religion, "Hinduism");
addSubCat(Religion, "Islam");
addSubCat(Religion, "Judaism");
addSubCat(Religion, "Other");
addSubCat(Religion, "Spirituality");

Science = insFld(foldersTree, gFld("Science & Medicine"));
addSubCat(Science, "Medicine");
addSubCat(Science, "Natural Sciences");
addSubCat(Science, "Social Sciences");

Society = insFld(foldersTree, gFld("Society & Culture"));
addSubCat(Society, "History");
addSubCat(Society, "Personal Journals");
addSubCat(Society, "Philosophy");
addSubCat(Society, "Places & Travel");

Sports = insFld(foldersTree, gFld("Sports & Recreation"));
addSubCat(Sports, "Amateur");
addSubCat(Sports, "College & High School");
addSubCat(Sports, "Outdoor");
addSubCat(Sports, "Professional");

Technology = insFld(foldersTree, gFld("Technology"));
addSubCat(Technology, "Gadgets");
addSubCat(Technology, "Tech News");
addSubCat(Technology, "Podcasting");
addSubCat(Technology, "Software How-To");

TV = insFld(foldersTree, gFld("TV & Film"));
addSubCat(TV, "TV & Film");
Return current item: PodAdmin - Web-based podcast management