function syncLanguages() {
	  global $db, $auth;
	  $variations = createDBCArray('variations', 'VARIATION_ID');
	  // enable languages in all templates
	  $spms = createDBCArray('sitepage_master', 'SPM_ID', 'VERSION=0');
	  for ($i=0; $i<count($spms); $i++) {
		for ($j=0; $j<count($variations); $j++) {
		  $check = getDBCell("sitepage_variations", "VARIATION_ID", "SPM_ID=".$spms[$i]." AND VARIATION_ID=".$variations[$j]);		  
		  if ($check=="") {		    
		  	$update = new query($db, 'INSERT INTO sitepage_variations (SPM_ID, VARIATION_ID) VALUES ('.$spms[$i].','.$variations[$j].')');
		  }	
		}
	  }
	  
	  // enable languages for all contents
	  $cids = createDBCArray("content", "CID", "VERSION=0");
	  for ($i=0; $i<count($cids); $i++) {
	  	$module = getDBCell("content", "MODULE_ID", "CID=".$cids[$i]);
	    for ($j=0; $j<count($variations); $j++) {
	      $check = getDBCell("content_variations", "VARIATION_ID", "CID=".$cids[$i]." AND VARIATION_ID=".$variations[$j]);
	      if ($check=="") {
		      $fk = nextGUID();
	  		  $sql = "INSERT INTO content_variations (CID, VARIATION_ID, FK_ID, DELETED) VALUES ( $cids[$i], $variations[$j], $fk, 0)";
              $PGNRef = createPGNRef($module, $fk);
              $PGNRef->sync();
              $update = new query($db, $sql);
	      }
	    }	  
	  }

	  // enable languages for all clusters
	  $clnids = createDBCArray('cluster_node', 'CLNID', 'VERSION=0 AND DELETED=0');
	  for ($i=0; $i<count($clnids); $i++) {
	  	for ($j=0; $j<count($variations); $j++) {
	  	  $check = getDBCell("cluster_variations", 'VARIATION_ID', 'CLNID='.$clnids[$i].' AND VARIATION_ID='.$variations[$j]);
	  	  if ($check=="") {
			$fk = nextGUID();
			$sql = "INSERT INTO cluster_variations (CLNID, VARIATION_ID, CLID, DELETED,CREATED_AT, CREATE_USER ) VALUES ( $clnids[$i], $variations[$j], $fk, 0, NOW()+0, '".$auth->userName."')";
	  	  	$update = new query($db, $sql);
	  	  	syncCluster($fk);
	  	  }
	  	}	  	
	  }
	  
	  // enable languages for all menutexts
	  $spids = createDBCArray("sitepage", "SPID", "VERSION=0 AND DELETED=0");
	  for ($i=0; $i<count($spids); $i++) {
	    for ($j=0; $j<count($variations); $j++) {
	      $check = getDBCell("sitepage_names", "VARIATION_ID", "VARIATION_ID= $variations[$j] AND SPID=$spids[$i]");
	      if ($check =="") {
	      	$update = new query($db, 'INSERT INTO sitepage_names (SPID,VARIATION_ID,NAME,HELP,DELETED,VERSION) VALUES ('.$spids[$i].','.$variations[$j].',"","",0,0)');
	      }		      
	    }	
	  }	  	  	  
	}	
	function syncClids() {
	   global $db, $form;
	   $counter = 0;
	   $sql = "SELECT cv.CLID FROM cluster_variations cv, cluster_node cn WHERE cv.DELETED=0 AND cv.CLNID=cn.CLNID AND cn.VERSION=0";	
	   $query = new query($db, $sql);
	   while ($query->getrow()) {
	     syncCluster($query->field("CLID"));	
	     $counter++;
	   }	
	   //$form->addToTopText("<br/>".$lang->get("num_cl_sync", "Number of cluster who were synchronized").": ".$counter);
	}
		/**
		 * Delete one item out of the list
		 */
		function deleteItem() {
			global $db;
			$deleted = false;
			for ($i = 0; $i < count($this->members); $i++) {
				if ($this->eid == $this->members[$i][1]) {
					$sql = "DELETE FROM cluster_content WHERE CLCID = $this->eid";
					$query = new query($db, $sql);
					$query->free();
					if ($this->membersCount > 1) sortTableRows("cluster_content", "CLCID", "POSITION", "CLTI_ID = $this->clti AND CLID = $this->cl");
					$deleted = true;
                    $this->deleteReferencedItem($this->eid);
				}
			}
			if ($deleted) {
				syncCluster ($this->cl);
				$this->members = $this->getItemData();					
			}
		}
    $toolbar = new Buttonbar("Toolbar");
    $toolbar->selectBoxDescr = true;
    $toolbar->setTranslationSelector(createNameValueArrayEx("variations", "NAME", "VARIATION_ID", "VARIATION_ID <>" . variation()), translation());
    if (!$isArticle) {
        $toolbar->setVariationSelector(populateVariations($clnid, variation()), variation());
    }
    $clusterPanel->add($toolbar);
}
// PANELS
// Edit-Content Panel.
// include needed sources
includePGNISources();
//Plugin Sources.
$clid = getClusterFromNode($clnid, $variation);
if ($view == $pos_clusterPanel) {
    syncCluster($clid);
}
$clusterPanel->add(new Hidden("view", $view));
$clusterPanel->add(new Hidden("oid", value("oid", "NUMERIC")));
if (!$clusterEditState || $isArticle) {
    $clusterPanel->add(new ActionField("panel_cluster"));
}
if ($action == $lang->get("edit_all") || $action == $lang->get("save")) {
    $clusterPanel->add(new Hidden("processing", "yes"));
}
// start processing of content-items
// GET CONTENT OF THE CLUSTER
// set variables that will contain the content later to null.
$clusters = null;
$plugins = null;
$types = null;
	/**
	 * Checks, whether the cluster already exists and creates it, if not.
	 */	 
	function checkIfCLNExists() {
	  global $db;
	  
	  // Check, if Clusternode exists.
	  if ($this->value == "0" || $this->value == "") {
	    // The Cluster in the variation will be created now.
	    $this->clnid = createClusterNode($this->clustername, $this->cltid);	  	
	    	// update the new clnid immediately to the database	  	
	  	$sql = "UPDATE $this->table SET $this->column=$this->clnid WHERE $this->row_identifier";	  	
	  	$query = new query($db, $sql);
	  	$query->free();
	  
	  }	else {
	  	// the cluster node already exists.
	  	$this->clnid = $this->value;
	  }
	  
	  // check, if clustervariation exists.
	  $clid = getDBCell("cluster_variations", "CLID", "CLNID=$this->clnid AND VARIATION_ID=$this->variation");
	  if ($clid == "") {
	  	// Cluster-Variation does not exists yet.
	  	$this->clid = createCluster($this->clnid, $this->variation);
	  } else {
	  	$this->clid = $clid;
	  }
	  
	  // sync the cluster variation
	  syncCluster($this->clid);	  
	  
	  // ensure correct CLT-ID
	  $this->cltid = getDBCell("cluster_node", "CLT_ID", "CLNID=".$this->clnid);	  
	}
/**
 * Create a cluster 
 * @param integer GUID of the Cluster-Node
 * @param integer GUID of the Variation
 * @param string Username which shall be inserted for create-user
 */
function createCluster($clnid, $variationId, $createUser = "******")
{
    global $db;
    $clid = nextGUID();
    $sql = "INSERT INTO cluster_variations (CLNID, VARIATION_ID, CLID, DELETED,CREATED_AT, CREATE_USER, LAST_CHANGED, LAST_USER ) VALUES ( {$clnid}, {$variationId}, {$clid}, 0, NOW()+0, '" . $createUser . "', NOW()+0, '" . $createUser . "')";
    $query = new query($db, $sql);
    $query->free();
    syncCluster($clid);
    return $clid;
}