function process()
 {
     global $page_action, $specialID;
     if ($page_action == "INSERT") {
         $this->value = createClusterNode(value($this->table . "_" . $this->nameColumn, "", "Object") . $specialID, $this->value);
         DBO::process();
     }
 }
Example #2
0
/**
 * Import ClusterNode from XML
 * @param string XMLString
 */
function XmlImportClusterNode($xmlString)
{
    global $db;
    $xmlOptions = array(XML_OPTION_CASE_FOLDING => TRUE, XML_OPTION_SKIP_WHITE => TRUE);
    $xml =& new XPath(FALSE, $xmlOptions);
    $xml->importFromString($xmlString);
    $id = translateXmlGUID($xml->getAttributes('/NX:CLUSTERNODE[1]', 'ID'));
    $name = urldecode($xml->getAttributes('/NX:CLUSTERNODE[1]', 'NAME'));
    $clt = translateXmlGUID($xml->getAttributes('/NX:CLUSTERNODE[1]', 'CLUSTERTEMPLATE'));
    createClusterNode($name, $clt, $id);
    if ($xml->hasChildNodes('/NX:CLUSTERNODE[1]')) {
        $i = 1;
        while ($xml->getNode("/NX:CLUSTERNODE[1]/NX:CLUSTER[{$i}]")) {
            $child =& new XPath(FALSE, $xmlOptions);
            XmlImportCluster($xml->exportAsXml('/NX:CLUSTERNODE[1]/NX:CLUSTER[' . $i . ']', ''), $id, $clt);
            $i++;
        }
    }
}
Example #3
0
/**
 * Creates a cluster and a cluster-node for the given clt. returns the clnid.
 * Can only import dynamic content and dynamic clusters (GUIDs of Cluster_node!).
 * @param string name of the cluster
 * @param string GUID of Cluster template
 * @param string ID od Variation to use
 * @param string array with data to post to plugins, like array("Headline" => "Test Headline", ...)
 * @param string Username to use for create
 */
function createCluster2($name, $clt, $variationId, $data, $createUser = "******")
{
    $name = makeCopyName("cluster_node", "NAME", parseSQL($name), "CLT_ID = {$clt}");
    if (!is_numeric($clt)) {
        exit;
    }
    if (!is_numeric($variationId)) {
        exit;
    }
    $clnid = createClusterNode($name, $clt);
    $clid = createCluster($clnid, $variationId, $createUser);
    $datarows = array_keys($data);
    for ($i = 0; $i < count($datarows); $i++) {
        $type = getDBCell("cluster_template_items", "CLTITYPE_ID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
        $clti = getDBCell("cluster_template_items", "CLTI_ID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
        $clcid = getDBCell("cluster_content", "CLCID", "CLID={$clid} AND CLTI_ID = {$clti}");
        if ($type == 2) {
            $pgType = strtoupper(getDBCell("modules", "MODULE_NAME", "MODULE_ID = " . getDBCell("cluster_template_items", "FKID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')")));
            $moduleId = getDBCell("cluster_template_items", "FKID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
            if ($pgType == "TEXT" || $pgType == "LABEL") {
                $data[$datarows[$i]] = urlencode($data[$datarows[$i]]);
            }
            $xml = '<NX:CONTENT TYPE="' . $pgType . '">' . $data[$datarows[$i]] . '</NX:CONTENT>';
            $pgn = createPGNRef($moduleId, $clcid);
            $pgn->import($xml);
        } else {
            if ($type == 4) {
                if (is_numeric($data[$datarows[$i]])) {
                    $sql = "UPDATE cluster_content SET FKID=" . $data[$datarows[$i]] . " WHERE CLCID = {$clcid}";
                    global $db;
                    $query = new query($db, $sql);
                    $query->free();
                }
            }
        }
    }
    return $clnid;
}
			$handler = new ActionHandler("INSERT");
			$handler->addFncAction("syncClusterVariations");
			$form->registerActionHandler($handler);

			$page->add($form);
			// edit the properties of an object.
			$handled = true;

		} else if ($action != "foo" && ($action != "0"  || $view != "0")) {
			if ($action == "") $action = value("acstate");	

			if ($action == "createCluster") {
				$id = value("id");

				$clnid = createClusterNode(value("cluster_node_NAME".$id), $clt);
    		    $variations = createDBCArray("variations", "VARIATION_ID");
                for ($varX=0; $varX < count($variations); $varX++) {
                        $clid = createCluster($clnid, $variations[$varX], $auth->userName);
                }

	   		    $sql = "UPDATE cluster_content SET FKID = '$clnid' WHERE CLCID = '$id';";
				$query = new query($db, $sql);
				$query->getrow();
				
				// Trying to set action to Edit All, but it obviously doesn't work.
				$action = value("acstate");
			}
					
			$handled = true;
			$page_action = "UPDATE";
	/**
	 * 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);	  
	}
	/**
	 * Draw the input boxes needed for editing the contents in the envelope.
	 * @param integer id of cluster_content.CLCID
	 */
	function getSingleEdit($id) {
		global $specialID, $lang, $c, $sid, $aclf, $db, $lang;
        global $forceLoadFromDB, $auth;

       $clt = getDBCell("cluster_template_items", "FKID", "CLTI_ID = ".$this->clti);

       if ($this->saction == "createCluster" && $id == value("id")) {
                $name = parseSQL(value("cluster_node_NAME".$id));
                if ($name=="0") $name = "Cluster";
                $name = makeCopyName("cluster_node", "NAME", $name, "1", "", false);
                $clnid = createClusterNode($name, $clt);
                $variations = createDBCArray("variations", "VARIATION_ID");
                for ($varX=0; $varX < count($variations); $varX++) {
                        $clid = createCluster($clnid, $variations[$varX], $auth->userName);
                }

                $sql = "UPDATE cluster_content SET FKID = $clnid WHERE CLCID = $id";
                $query = new query($db, $sql);
                $query->free();
                $forceLoadFromDB = "yes";
        }

        if ($this->editState && $this->editor) {
            $chclbox = new Container(4);
				$compoundEnvelope = new Container(3);
				$compoundContainer = new Container(3);

                $specialID = $id;
                $cpselector = new CPCLSelector($lang->get("select_cl"), "cluster_content", "FKID", "CLCID=$id", getModuleFromCLC($id), "", "");
                $cpselector->additionalAttribute = "onchange=\" if ( !confirm('".$lang->get("confirm_unsaved_changes_linkedcluster", "Note: When changing the linked cluster, any changes you apply on the currently linked cluster will be lost. If you want to save these canges, save your work first and change the linked cluster then. Proceed ?")."') ) { for(i=0; i<document.form1.cluster_content_FKID$specialID.length; i++)  if(document.form1.cluster_content_FKID$specialID.options[i].defaultSelected == true) document.form1.cluster_content_FKID$specialID.options[i].selected=true; }\"";
                $variation = variation();
                // force save in dbo.
                //$clnid = getDBCell("cluster_content", "FKID", "CLCID = ".$id);
                if (!isset($clnid)) {
                    $clnid = $cpselector->value;
                } else {
                    $cpselector->value = $clnid;
                }
                $clid = getClusterFromNode($clnid, $variation);
                $chclbox->add( $cpselector );
                $forceLoadFromDB = "no";


                if ($clnid != "" && $clnid != "0") {
				    $clid = getClusterFromNode($clnid, $variation);
                    $name = getDBCell("cluster_node", "NAME", "CLNID = $clnid");
                }
                
				$infoboxid = $id;
				$chclboxid = $id;

				$table = '<table width="100% border="0" cellpadding="0" cellspacing="0"><tr><td>';
				$table.= $lang->get("cllink", "This box is linked to ")."&nbsp; <b>".$name."</b>";
				$table.= '</td><td align="right">';
				// Add-Button
				$ShowInfoButton = new LinkButtonInline("toggle_info_".$infoboxid, "show info", "box", "button", "toggle('showinfo_".$infoboxid."')");
				$CHCLButton = new LinkButtonInline("toggle_chcl_".$chclboxid, "change cluster", "box", "button", "toggle('chcl_".$chclboxid."')");
				$table.= $ShowInfoButton->draw()."&nbsp;".$CHCLButton->draw();
				$table.= '</td></tr></table>';
				
				$this->add(new Label("lbl", $table, "headbox", 2));

				if (getDBCell("cluster_content", "FKID", "CLCID = ".$id) != $clnid)
					$forceLoadFromDB = "yes";
	

			    $chclbox->add(new Cell("spacer", "standardlight", 1));
			    $chclbox->add(new Label("lbl", "or create a new instance called", "standardlight"));
			    $chclbox->add(new Input("cluster_node_NAME$id", "", "standardlight", 32));
			    $chclbox->add(new SingleHidden("clt", ""));
			    $chclbox->add(new SingleHidden("id", ""));
			    $chclbox->add(new LinkButtonInCell("neueInstanz", "Create Instance", "standardlight navelement", "button", "javascript:if (confirm('".$lang->get("confirm_unsaved_changes")."')) { document.form1.saction.value='createCluster';document.form1.id.value='$id';document.form1.clt.value='$clt';document.form1.submit(); };", "form1", 1));

			    $sql = "SELECT * FROM variations WHERE 1";
			    $variations = new query($db, $sql);
			    while ($variations->getrow()) {
				    $chclbox->add(new Hidden("cluster_variations_VARIATION_ID_".$variations->field("VARIATION_ID"), "1"));
			    }

			    $specialID = "";
                $compoundContainer->add(new IDWrapper("chcl_".$chclboxid, $chclbox, "embedded", ' style="display:'.(($clid == 0) ? "" : "none" ).';" ', 3));

                if ($clid != "0" && $clid != "") {
        			// GET CONTENT OF THE CLUSTER
    				// set variables that will contain the content later to null.
    				$clusters = null;
    				$plugins = null;
    				$types = null;

    				// get the structure of the content.
    				$sql = "SELECT CLTI_ID, CLTITYPE_ID FROM cluster_template_items WHERE CLT_ID = $clt AND FKID!=0 ORDER BY POSITION";

    				$query = new query($db, $sql);

    				while ($query->getrow()) {
    					$cltitype = $query->field("CLTITYPE_ID");

    					$ni = count($plugins);
    					$plugins[$ni] = $query->field("CLTI_ID");
    					$types[$ni] = $cltitype;
    				}

    				$query->free();

    				// we don't want to draw an additional back link in clusters-editor
    				// if (! $sitepage && ! $isArticle) {
    				//	$compoundContainer->add(new LinkLabel("link1", $lang->get("back_to_cv", "Back to cluster overview"), "modules/cluster/clusterbrowser.php?sid=$sid&clt=$clt", "_self", "informationheader", 2));
    				// }

    				$infobox = new Container(3);

    				// draw some cluster-information.
    				$infobox->add(new Subtitle("", $lang->get("cluster_information", "Information about this record"), 3));
    				$infobox->add(new ClusterInformation($clid));

    				$compoundContainer->add(new IDWrapper("showinfo_".$infoboxid, $infobox, "embedded", ' style="display:none;" ', 3));
    				// draw plugin preview.

    				$len = count($plugins);
    				if ($clid) {
    					for ($i = 0; $i < $len; $i++) {

                            if ($types[$i] == 2)
    							$compoundContainer->add(new ContentEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 4)
    							$compoundContainer->add(new ClusterEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 5)
    							$compoundContainer->add(new LibraryEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 6)
    							$compoundContainer->add(new CompoundClusterEnvelope($plugins[$i], $clid, true));

    				        if ($types[$i] == 8)
    				          $compoundContainer->add(new ChannelEnvelope($plugins[$i], $clid, true));
    					}
    					if ($isArticle || $action == $lang->get("edit_all") || ($action == $lang->get("save")) || $action == $lang->get("save_back")) {
    				       	$compoundContainer->add(new NonDisplayedValue("cluster_variations", "LAST_CHANGED", "CLID = ".$clid, "(NOW()+0)", "NUMBER"));
    						$compoundContainer->add(new NonDisplayedValue("cluster_variations", "LAST_USER", "CLID = ".$clid, $auth->userName, "TEXT"));
    					}
    				}
                }
                $compoundEnvelope->add(new IDWrapper("compoundEnvelope_$id", $compoundContainer, "embedded sub", '', 3));
                $this->add(new IDWrapper("compoundCluster_$id", $compoundEnvelope, "boxed", '', 3));

		} else {
			$name = "&lt;" . $lang->get("not_selected", "No item selected yet."). "&gt;";
			$myfk = getDBCell("cluster_content", "FKID", "CLCID = " . $id);
			if ($myfk != 0 && $myfk != "") {
				$clt = getDBCell("cluster_node", "CLT_ID", "CLNID = " . $myfk);
				$cltname = getDBCell("cluster_templates", "NAME", "CLT_ID = ".$clt);
				$cat = getDBCell("cluster_templates", "CATEGORY_ID", "CLT_ID = " . $clt);
				$name = "<br><b>" . $lang->get("cli"). "</b> " .$cltname."/".getDBCell("cluster_node", "NAME", "CLNID = " . $myfk);
				$buttons = "<br><a href=\"" . $c["docroot"] . "modules/cluster/clusterbrowser.php?sid=$sid&action=editobject&go=update&oid=$myfk&pnode=$cat&clt=$clt\" class=\"box\">".$lang->get("goto_cl", "Goto Cluster")."</a>";
				if ($aclf->checkAccessToFunction("B_PREVIEW_PAGE")) $buttons .= drawSpacer(10, 1). "<a href=\"#\" onClick=\"window.open('" . $c["docroot"] . "modules/cluster/previewcpcl.php?sid=$sid&oid=$myfk', 'cppreview', 'width=400,height=400,location=no,menubar=no,toolbar=no');return false;\"  class=\"box\">".$lang->get("preview")."</a>";
			}
			$this->add(new Label("lbl", $name, "", 1));
			$this->add(new AlignedLabel('lbl', $buttons, 'right', '', 1));
		}

	}