/**
		 * Prepare and declare wui for overview
		 */
		function prepare_overview() {
			global $lang, $db, $sid, $specialID;

			// initializing
			$doc = doc();
			$oid = value("oid", "NUMERIC");

			if ($this->membersCount > $this->mincard && $this->developer)
				$this->deleteable = true;

			// process moving up and moving down....
			if ($this->saction == "up" && ($this->editor || $this->developer)) {
				$this->move("UP");
			} else if ($this->saction == "down" && ($this->editor || $this->developer)) {
				$this->move("DOWN");
			}

			// process adding of items...
			if (($this->saction == "addci_".$this->clti) && ($this->editor || $this->developer)) {
				$this->createItems();		
			} 
			
			// process delete ...
			if ($this->saction == "delete" && value("back") != $lang->get("no") && ($this->editor || $this->developer)) {
				$this->deleteItem();
			} 

			if ((($this->action == "editsingle" || (value("status") == "editsingle" && $this->action != $lang->get("back"))) && $this->editor) && ! $this->forceEditAll) {
				for ($i = 0; $i < count($this->members); $i++) {
					if ($this->eid == $this->members[$i][1]) {
						$this->add(new Hidden("status", "editsingle"));
						$this->add(new Hidden("eid", $this->eid));
						$this->add(new Hidden("processing", "yes"));
						$this->getSingleEdit($this->members[$i][1]);
					}
				}
			} else {
				// draw the main view of the content-envelope
				if ($this->membersCount == 1 && $this->maxcard == 1 && $this->mincard == 1) {
					$labeltext = "<b>" . $this->name . "</b>";
					// Draw the title bar 

					$container = new HtmlContainer('box', 'headbox',2);
					// Edit-Button

					if ($this->editor && ! $this->editState) {
					    $menuLabel = crLink($lang->get("edit"), $doc . "?sid=$sid&oid=$oid&action=editsingle&eid=" . $this->members[0][1], "box");
					} else {
						$menuLabel = '&nbsp;';						
					}					
					$table = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
					$table.= '<tr><td>'.$labeltext.'</td>';
					$table.= '<td align="right"><b>'.$menuLabel.'</b></td></tr>';
					$table.= '</table>';					
					$container->add($table);					
					$this->add($container);
					$this->add(new Cell('', '', 2, 10, 10));
					$this->getSingleEdit($this->members[0][1]);
					
				// processing of lists.	
				} else {
					$labeltext = '<b>'.$this->name.'</b>';
					$container2 = new HtmlContainer('box', 'headbox',2);
					if ($this->mincard != 1 || $this->maxcard != 1) {
						$labeltext .= " &nbsp;($this->mincard - $this->maxcard)";
					}

					$menuLabel = "";

					// Add-Button
					if ($this->membersCount < $this->maxcard) {
						$toggleButton = new LinkButtonInline("toggle_create_".$this->clti, $lang->get("create_instances", "Create Instances"), "box", "button", "toggle('crinst_".$this->clti."')");
						$menuLabel .= $toggleButton->draw();
					}
									
					$table = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
					$table.= '<tr><td>'.$labeltext.'</td>';
					$table.= '<td align="right"><b>'.$menuLabel.'</b></td></tr>';
					$table.= '</table>';					
					$container2->add($table);					
					$this->add($container2);															
									
					// Add Toggle-Field
					$container = new Container(3);
					$container->add(new Label("lbl", $lang->get("number_of_instances", "Please specify how many instances you want to create"), "standardlight", 3));
					$container->add(new Input("number_of_instances".$this->clti, "1", "standardlight", 2, "", 100));

					
					if ($this->editState) {
						$createInstancesJS = "javascript:if (confirm('".$lang->get("confirm_unsaved_changes", "Note: Unsaved changes will be lost if you proceed. If you have already edited something, you may cancel now and save your work. Proceed ?")."')) { document.form1.saction.value='addci_".$this->clti."';document.form1.submit(); };";
					} else {
						$createInstancesJS = "javascript:document.form1.saction.value='addci_".$this->clti."';document.form1.submit();";
					}

					$container->add(new ButtonInCell("create_".$this->clti, $lang->get("create_instances", "Create instances"), "standardlight navelement", "button", $createInstancesJS));
					$this->add(new IDWrapper("crinst_".$this->clti, $container, "embedded", ' style="display:none;" ', 3));	
					$this->add(new Cell('clc', '', 2,10,10));					
					// draw list content
					$container0 = array();
					for ($i = 0; $i < $this->membersCount; $i++) {
						$labeltext = $this->name . '&nbsp;&nbsp;'.($i + 1) . "/" . $this->maxcard . "&nbsp;" . $this->members[$i][0] . "";

						// Draw one instance
						$table = '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
						$table.= '<tr><td width="200">'.$labeltext.'</td>';
						$table.= '<td align="right">';					
											

						$menuLabel = "";
						// Edit-Button
						if ($this->editState) {
							$menuLabel = crLink($lang->get("up"), "javascript:confirmAction('".$lang->get("confirm_unsaved_changes")."', '".$doc."?sid=$sid&oid=$oid&saction=up&eid=".$this->members[$i][1]."');", "box");
							$menuLabel .= "&nbsp;".crLink($lang->get("down"), "javascript:confirmAction('".$lang->get("confirm_unsaved_changes")."', '".$doc . "?sid=$sid&oid=$oid&saction=down&eid=" . $this->members[$i][1]."');", "box");

							$menuLabel .= "&nbsp;&nbsp" . crLink($lang->get("delete"), "javascript:if (confirm('".$lang->get("confirm_unsaved_changes")."')) { confirmAction('".$lang->get("confirm_delete", "Do you really want to delete this item?")."', '". $doc . "?sid=$sid&oid=$oid&saction=delete&eid=" . $this->members[$i][1]."') } ;", "box");
						} else {
							$menuLabel = crLink($lang->get("up"), $doc . "?sid=$sid&oid=$oid&saction=up&eid=" . $this->members[$i][1], "box");
							$menuLabel .= "&nbsp;".crLink($lang->get("down"), $doc . "?sid=$sid&oid=$oid&saction=down&eid=" . $this->members[$i][1], "box");	
							$menuLabel .= "&nbsp;&nbsp" . crLink($lang->get("delete"), "javascript:confirmAction('".$lang->get("confirm_delete", "Do you really want to delete this item?")."', '". $doc . "?sid=$sid&oid=$oid&saction=delete&eid=" . $this->members[$i][1]."');", "box");
						}
						
						if ($this->editor && !$this->editState)
							$menuLabel .= "&nbsp;".crLink($lang->get("edit"), $doc . "?sid=$sid&oid=$oid&action=editsingle&eid=" . $this->members[$i][1], "box");

						$table.= $menuLabel;				
						$table.= '</td></tr></table>';
						$container0[$i] = new HTMLContainer('subbox', 'headbox2', 2);
						$container0[$i]->add($table);
						$this->add($container0[$i]);
						$this->getSingleEdit($this->members[$i][1]);
						$this->add(new Cell('clc', '', 2, 10,10));
					}
				}
			}
		}
 /**
  * query the rows from the database
  */
 function getRows()
 {
     global $db, $c, $sid, $lang, $auth;
     $result = array();
     $order = "ca.TITLE";
     if ($this->order == "NAME") {
         $order = "ca.TITLE";
     } else {
         if ($this->order == "CATEGORY") {
             $order = "ca.CH_CAT_ID";
         } else {
             if ($this->order == "EDITED") {
                 $order = "cv.LAST_CHANGED";
             } else {
                 if ($this->order == "CREATED") {
                     $order = "cv.CREATED_AT";
                 } else {
                     if ($this->order == "POSITION") {
                         $order = "ca.POSITION";
                     }
                 }
             }
         }
     }
     $order .= " " . $this->orderdir;
     // $sql_articles = "Select ca.*, cv.LAST_USER, cv.CREATED_AT, cv.LAST_CHANGED FROM channel_articles ca, cluster_variations cv ".$this->getFilterJoin()." WHERE ca.CHID = ".$this->channelId." AND ca.ARTICLE_ID = cv.CLNID AND cv.VARIATION_ID = ".variation()." AND ca.VERSION=0 " . $this->getFilterSQL() . " ORDER BY $order LIMIT ".(($this->page - 1) * $this->recordsPerPage).",".$this->recordsPerPage;
     $sql_articles = "SELECT DISTINCT ca.* FROM channel_articles ca, cluster_variations cv " . $this->getFilterJoin() . " WHERE ca.ARTICLE_ID = cv.CLNID AND ca.CHID = " . $this->channelId . " AND ca.VERSION = 0 " . $this->getFilterSQL() . " ORDER BY {$order} LIMIT " . ($this->page - 1) * $this->recordsPerPage . "," . $this->recordsPerPage;
     // echo $sql_articles;
     $query = new query($db, $sql_articles);
     while ($query->getrow()) {
         $tmp = array();
         $varexists = true;
         $article_id = $query->field("ARTICLE_ID");
         $cvdatasql = "SELECT * FROM cluster_variations WHERE CLNID = " . $article_id . " AND VARIATION_ID=" . variation();
         $cvdata = new query($db, $cvdatasql);
         $cvdata->getrow();
         if ($cvdata->count() < 1) {
             $varexists = false;
         }
         array_push($tmp, $query->field("ARTICLE_ID"));
         $clid = getDBCell("cluster_variations", "CLID", "CLNID = " . $query->field("ARTICLE_ID") . " AND VARIATION_ID = " . variation());
         $live = isClusterLive($clid);
         if ($varexists) {
             if ($live) {
                 array_push($tmp, drawImage("green.gif", $lang->get("article_is_live", "Article is live")));
             } else {
                 array_push($tmp, drawImage("red.gif", $lang->get("article_is_expired", "Article is expired")));
             }
         } else {
             array_push($tmp, drawImage("gray.gif", $lang->get("article_variation_missing", "Variation of this article does not exist yet")));
         }
         array_push($tmp, $query->field("POSITION"));
         array_push($tmp, '<b>' . $query->field("TITLE") . '</b>');
         array_push($tmp, $this->categories[$query->field("CH_CAT_ID")]);
         array_push($tmp, formatDBTimestamp($cvdata->field("LAST_CHANGED")));
         $buttons = "&nbsp;" . crLink(drawImage('up.gif'), $c["docroot"] . "modules/channels/overview.php?sid={$sid}&action=up&article=" . $query->field("ARTICLE_ID"), "navelement");
         $buttons .= "&nbsp;" . crLink(drawImage('down.gif'), $c["docroot"] . "modules/channels/overview.php?sid={$sid}&action=down&article=" . $query->field("ARTICLE_ID"), "navelement");
         $buttons .= "&nbsp;";
         if ($auth->checkAccessToFunction("CHANNEL_DELETE")) {
             $buttons .= "&nbsp;" . crLink($lang->get("delete"), "javascript:confirmAction('" . $lang->get("del_article") . "', '" . $c["docroot"] . "modules/channels/overview.php?sid={$sid}&action=deletearticle&article=" . $query->field("ARTICLE_ID") . "');", "navelement");
         }
         if ($auth->checkAccessToFunction("CHANNEL_LAUNCH")) {
             $buttons .= "&nbsp;" . crLink($lang->get("launch", "Launch"), $c["docroot"] . "modules/channels/overview.php?sid={$sid}&action=launcharticle&article=" . $query->field("ARTICLE_ID"), "navelement");
             $buttons .= "&nbsp;" . crLink($lang->get("expire", "Expire"), $c["docroot"] . "modules/channels/overview.php?sid={$sid}&action=expirearticle&article=" . $query->field("ARTICLE_ID"), "navelement");
         }
         array_push($tmp, $buttons);
         array_push($result, $tmp);
     }
     return $result;
 }