Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/structure/sortbypage_operation.php
<script language="JavaScript" src="./modules/structure/sort.js"></script>

<?
function SortByPage(){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_subpage = new CPage();
	$obj_subpagearray = new CPageArray();
	$obj_subpageengine = new CPageEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="sortby";

	$obj_pagearray = $obj_pageengine->GetParentPages(-1);
	$num_rows = $obj_pagearray->count();
	
	$obj_subpagearray = $obj_subpageengine->GetChildPagesCount(-1);
	$total_sub_pages = $obj_subpagearray->count();

	if ($num_rows!=0){
		$content = "
		<center>
		<form action='".basename($PHP_SELF)."?f=structure&sf=sortby' method='post'>
		<input type=\"hidden\" name=\"selecttype\" value=\"parent\" />
		<input type=\"hidden\" name=\"operation\" value=\"sortbypageselect\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/sort.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._CP_PA_SORT_BY_PAGE_."</legend>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
			<tr>
				<td align=\"left\"><strong>"._CP_PA_OBP_SORT_PARENT_PAGES_."</strong></td>
				<td align=\"center\"><input type=\"submit\" value=\""._CMN_CONTINUE_."\" /></td>
			</tr>
			</table>
		</fieldset>
		</form>
		</center>";
	}
	else{
		$content = "
		<div class=note>
			<h3>"._CMN_NOTE_."</h3>
			<p>";
			$content .= "<img src=\"./images/icon48/warning.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= _CP_NO_PAGE_FOUND_;
			$content .= "<br><br>";
			$content .= go_back();
			$content .= "
			</p>
		</div>
		";
	}



/*	<tr>
		<td><br></td>
		<td><br></td>
		<td><br></td>
	</tr>
	<tr>";
		if ($total_sub_pages!=0){
		$content .= "
		<form action='".basename($PHP_SELF)."?f=structure&sf=sortby' method='post'>
		<input type=\"hidden\" name=\"selecttype\" value=\"child\" />
		<input type=\"hidden\" name=\"operation\" value=\"sortbypageselect\" />
		<td align=\"left\">
			<strong>"._CP_PA_OBP_SORT_CHILD_PAGES_."</strong><br>
			<em>"._CP_PA_OBP_SELECT_PARENT_PAGE_."</em>
		</td>
		<td align=\"center\">
			<select name=\"pageid\">";
			while( $obj_page = $obj_pagearray->get() ){
				$thispageid = $obj_page->page_id;
//				$thisactive=$obj_page->active;
				$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
				$thisname = $obj_content->context;

				$obj_subpagearray = $obj_subpageengine->GetChildPages($thispageid, -1);
				$sub_num_rows = $obj_subpagearray->count();

				if ($sub_num_rows!=0){
					$content .= "<option value=\"$thispageid\">$thisname</option>";
				}
			}
			$content .= "
			</select>
		</td>
		<td align=\"center\">
			<input type=\"submit\" value=\""._CP_PA_OBP_SELECT_AND_CONTINUE_."\" />
		</td>";
		}
		$content .= "
	</tr>";

/*
	$header = _CONTROL_PANEL_."<br>";
	$header .= _CP_PAGE_ADMINISTRATION_._CMN_DASH_._CP_PA_ORDER_BY_PAGE_;

	$info = _CP_PA_OBP_MSG_;
*/

/*
	$content = "
	<center><h3>".$header."</h3></center>
	<i><ul>".$info."</ul></i>
	<center>
	<div id=\"formular\">
	<table width=\"90%\" cellpadding=\"2\" cellspacing=\"2\" border=\"1\">
	<tr>";
	if ($num_rows!=0){
	$content .= "
		<form action='".basename($PHP_SELF)."?f=structure&sf=sortby' method='post'>
		<input type=\"hidden\" name=\"selecttype\" value=\"parent\" />
		<input type=\"hidden\" name=\"operation\" value=\"sortbypageselect\" />
		<td align=\"left\"><strong>"._CP_PA_OBP_SORT_PARENT_PAGES_."</strong></td>
		<td align=\"center\">-</td>
		<td align=\"center\"><input type=\"submit\" value=\""._CMN_CONTINUE_."\" /></td>
		</form>
	</tr>
	<tr>";
		if ($total_sub_pages!=0){
		$content .= "
		<form action='".basename($PHP_SELF)."?f=structure&sf=sortby' method='post'>
		<input type=\"hidden\" name=\"selecttype\" value=\"child\" />
		<input type=\"hidden\" name=\"operation\" value=\"sortbypageselect\" />
		<td align=\"left\"><strong>"._CP_PA_OBP_SORT_CHILD_PAGES_."</strong></td>
		<td align=\"center\"><em>"._CP_PA_OBP_SELECT_PARENT_PAGE_."</em><br>
			<select name=\"pageid\">";
			while( $obj_page = $obj_pagearray->get() ){
				$thispageid = $obj_page->page_id;
//				$thisactive=$obj_page->active;
				$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
				$thisname = $obj_content->context;

				$obj_subpagearray = $obj_subpageengine->GetChildPages($thispageid, -1);
				$sub_num_rows = $obj_subpagearray->count();

				if ($sub_num_rows!=0){
					$content .= "<option value=\"$thispageid\">$thisname</option>";
				}
			}
			$content .= "
			</select>
		</td>
		<td align=\"center\">
			<input type=\"submit\" value=\""._CP_PA_OBP_SELECT_AND_CONTINUE_."\" />
		</td>";
		}
		$content .= "
	</tr>
	<tr>
		</form>";
	}
	else{
		$content .= "<td align=\"center\">"._CP_NO_PAGE_FOUND_."</td>";
	}
	$content .= "
	</tr>
	</table>
	</form>
	</div>
	</center>";
*/

	return $content;
}

function SortByPageSelect($request){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_subpage = new CPage();
	$obj_subpagearray = new CPageArray();
	$obj_subpageengine = new CPageEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="sortby";

	$selecttype = $request['selecttype'];
	$pageid = $request['pageid'];

/*
	$header = _CONTROL_PANEL_."<br>";
	$header .= _CP_PAGE_ADMINISTRATION_._CMN_DASH_._CP_PA_SORT_BY_PAGE_;

	$info = _CP_PA_OBP_MSG_;
*/

	//Parent Pages
	if ($selecttype =="parent"){
		$obj_pagearray = $obj_pageengine->GetParentPages(-1);
		$num_rows = $obj_pagearray->count();
	}
	//Child Pages
	else{
		$obj_pagearray = $obj_pageengine->GetChildPages($pageid, -1);
		$num_rows = $obj_pagearray->count();
	}

	if ($num_rows!=0){

		$content = "
		<center>
		<form action='".basename($PHP_SELF)."?f=structure&sf=sortby' method=\"post\" onsubmit=\"selectall('sort');\">
		<input type=\"hidden\" name=\"selecttype\" value=\"parent\" />
		<input type=\"hidden\" name=\"operation\" value=\"sortbypagesave\" />
		<input type=\"hidden\" name=\"selecttype\" value=\"$selecttype\" />
		<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/sort.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._CP_PA_SORT_BY_PAGE_."</legend>
			"._CP_PA_OBP_MSG_."<br><br>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
			<tr>";
			if ($num_rows!=0){
				$content .= "
	
	
				<td valign=\"top\">
				<select name=\"sort[]\" size=\"$num_rows\" multiple=\"multiple\" id=\"sort\" onmousewheel=\"mousewheel(this);\" ondblclick=\"selectnone(this);\">";
					$id = 1;
					while( $obj_page = $obj_pagearray->get() ){
						$thispageid = $obj_page->page_id;
						$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
						$thisname = $obj_content->context;
						$content .= "<option value=\"$thispageid\"> $thisname </option>";
						$id++;
					}
					$content .= "
					</select>
				</td>
	
				<td>
					<input type=\"button\" value=\""._CP_PA_OBP_MOVE_UP_."\" onclick=\"up('sort');\" title=\""._CP_PA_OBP_MOVE_UP_."\" style=\"padding: 0; margin: 0; height: 22px;\" /><br>
					<input type=\"button\" value=\""._CP_PA_OBP_MOVE_DOWN_."\" onclick=\"down('sort');\" title=\""._CP_PA_OBP_MOVE_DOWN_."\" style=\"padding: 0; margin: 0; height: 22px;\" /><br>
				</td>
				<td>
					<input  type=\"submit\" value=\""._CMN_SAVE_."\">
				</td>
				</form>";
			}
			$content .= "
			</tr>
			</table>
		</fieldset>
		</form>
		</center>";
	}
	else{
		$content = "
		<div class=note>
			<h3>"._CMN_NOTE_."</h3>
			<p>";
			$content .= "<img src=\"./images/icon48/warning.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= _CP_NO_PAGE_FOUND_;
			$content .= "<br><br>";
			$content .= go_back();
			$content .= "
			</p>
		</div>
		";
	}


/*
	$content = "
	<center><h3>".$header."</h3></center>
	<i><ul>".$info."</ul></i>
	<center>
	<div id=\"formular\">
	<table width=\"75%\" cellpadding=\"2\" cellspacing=\"2\" border=\"1\">
	<tr align=\"center\">";
		//Parent Pages
		if ($selecttype =="parent"){
			$obj_pagearray = $obj_pageengine->GetParentPages(-1);
			$num_rows = $obj_pagearray->count();
		}
		//Child Pages
		else{
			$obj_pagearray = $obj_pageengine->GetChildPages($pageid, -1);
			$num_rows = $obj_pagearray->count();
		}

		if ($num_rows!=0){
			$content .= "

			<form action='".basename($PHP_SELF)."?f=structure&sf=sortby&operation=sortbypagesave&selecttype=$selecttype&pageid=$pageid' method=\"post\" onsubmit=\"selectall('sort');\">

			<td valign=\"top\" width=175>
			<select name=\"sort[]\" size=\"$num_rows\" multiple=\"multiple\" id=\"sort\" onmousewheel=\"mousewheel(this);\" ondblclick=\"selectnone(this);\">";
				$id = 1;
				while( $obj_page = $obj_pagearray->get() ){
					$thispageid = $obj_page->page_id;
					$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
					$thisname = $obj_content->context;
					$content .= "<option value=\"$thispageid\"> $thisname </option>";
					$id++;
				}
				$content .= "
				</select>
			</td>

			<td>
				<input type=\"button\" value=\""._CP_PA_OBP_MOVE_UP_."\" onclick=\"up('sort');\" title=\"Up\" style=\"padding: 0; margin: 0; height: 22px;\" /><br>
				<input type=\"button\" value=\""._CP_PA_OBP_MOVE_DOWN_."\" onclick=\"down('sort');\" title=\"Down\" style=\"padding: 0; margin: 0; height: 22px;\" /><br>
			</td>
			<td>
				<input  type=\"submit\" value=\""._CMN_CONTINUE_."\">
			</td>
			</form>";
		}
	$content .= "
	</tr>
	</table>
	</div>
	</center>";
*/

	return $content;
}

function SortByPageSave($request){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_subpage = new CPage();
	$obj_subpagearray = new CPageArray();
	$obj_subpageengine = new CPageEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="sortby";

	$selecttype = $request['selecttype'];
	$pageid = $request['pageid'];
	$sort = $request['sort'];

	//echo "pageid:$pageid<br>";
	//echo "selecttype:$selecttype<br>";
	//print_r($sort);

		//Parent Pages
		if ($selecttype =="parent"){
			$obj_pagearray = $obj_pageengine->GetParentPages(-1);
			$num_rows = $obj_pagearray->count();
		}
		//Child Pages
		else{
			$obj_pagearray = $obj_pageengine->GetChildPages($pageid, -1);
			$num_rows = $obj_pagearray->count();
		}

		//var_dump($_POST["sort"]);

		if ($num_rows!=0){
			for ($i=0; $i<$num_rows; $i++){
				$obj_page = $obj_pageengine->GetPage($sort[$i]);
				$obj_page->order_id = $i;
				if ($obj_pageengine->UpdatePage($obj_page)){
					//echo "Update OK<br>";
				}
			}

			while( $obj_page = $obj_pagearray->get() ){
				$thispageid = $obj_page->page_id;
				$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
				$thisname = $obj_content->context;
			}
		}

/*
	$header = _CONTROL_PANEL_."<br>";
	$header .= _CP_PAGE_ADMINISTRATION_._CMN_DASH_._CP_PA_SORT_BY_PAGE_;

	$info = _CP_PA_OBP_COMPLETED_;
*/


	$content .= "
	<div class=note>
		<h3>"._CMN_NOTE_."</h3>
		<p>";
		if (!$failed){
			$content .= "<img src=\"./images/icon48/info.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= _CP_PA_OBP_COMPLETED_;
		}
		else{
			$content .= _CP_PA_OBP_ERROR_."
			<center>";
			$content .= "<img src=\"./images/icon48/warning.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= go_back();
		}
		$content .= "
		</p>
	</div>
	";

/*
	$content = "
	<center><h3>".$header."</h3></center>
	<i><ul>".$info."</ul></i>
	<center>
	<div id=\"formular\">
	<table width=\"50%\" cellpadding=\"2\" cellspacing=\"2\" border=\"1\">
	<tr>";

	$content .= "
	</tr>
	</table>
	</div>
	</center>";
*/
	return $content;
}

function SortByPage_Operation($request){
	$content = null;

	$operation = $request['operation'];

	switch ($operation){
	default:
//	case 'sortbypage':
//		$content = SortByPage();
//	break;
	case 'sortbypageselect':
		$content = SortByPageSelect($request);
	break;
	case 'sortbypagesave':
		$content = SortByPageSave($request);
	break;
	}

	return $content;
}


?>
Return current item: ChiCoMaS - Chilek CMS