Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/content/content_operation.php
<?
//*****************************************************************************
function Create_Tab_Menu($request){

	global $module;
	global $module_path;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$sf = $request['sf'];

	$content = "
	<div id=\"navcontainer\">
	<ul id=\"navlist\">";

	$current = "id=\"current\"";
	$active = "id=\"active\"";


	$content .= "<li><a href=\"".basename($PHP_SELF)."?mode=admin\">"._CONTROL_PANEL_."</a></li>";

	$content .= "<li $active><a href=\"".basename($PHP_SELF)."?f=content\" $current>"._CP_CONTENT_ADMINISTRATION_."</a></li>";

	$content .= "
	</ul>
	</div>";

	return $content;

};

//*****************************************************************************
function RecursivePageSelect($pageid, $recursivecount){
	$content = null;

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

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


	$obj_pagearray = $obj_pageengine->GetChildPages($pageid, -1);
	$num_rows = $obj_pagearray->count();

	if ($num_rows!=0){
		$recursivecount++;
		for ( $counter = 1; $counter <= $recursivecount; $counter++)
			$braket = $braket."|--";

		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;
			if ($thisactive==0)
				$activepage="style=\"background-color:gray;color:white\"";
			else
				$activepage="";

			$content .= "<option value=\"$thispageid\" $activepage>";
			$content .= "$braket";
			$content .= "$thisname</option>";;
			$content .= RecursivePageSelect($thispageid, $recursivecount);
		}
	}
	else{
		$content = null;
		$recursivecount--;
		$braket = null;
	}

	return $content;
}

//*****************************************************************************
function SelectPage(){
	$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_pagetype = new CPageType();
	$obj_pagetypearray = new CPageTypeArray();
	$obj_pagetypeengine = new CPageTypeEngine();

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

	$obj_language = new CLanguage();
	$obj_languagearray = new CLanguageArray();
	$obj_languageengine = new CLanguageEngine();

	global $recursivecount;

	if (!isset($f)) $f="content";
	if (!isset($sf)) $sf="";

	$recursivecount = 0;
	$obj_pagearray = $obj_pageengine->GetPagesByPageType(1);
	$num_rows = $obj_pagearray->count();

	if ($num_rows!=0){
	
		$content = "
		<center>
		<form action='".basename($PHP_SELF)."?f=content&sf=edit' method='post'>
		<input type=\"hidden\" name=\"operation\" value=\"editcontent\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/contents.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._CP_CA_SELECT_PAGE_."</legend>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">";
			$obj_languagearray = $obj_languageengine->GetLanguages(1);
			$num_langs = $obj_languagearray->count();
			if ($num_langs!=0){
				$content .= "
				<tr>
				<td align=\"left\">"._CP_CA_SELECT_LANGUAGE_."</td>
				<td align=\"left\">
					<select name=\"languageid\">";
					while( $obj_language = $obj_languagearray->get() ){
						$thislanguageid = $obj_language->language_id;
						$thisname = $obj_language->language;
						$thislang = $obj_language->lang;
		
						if ($_SESSION['lang']==$thislang)
							$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
						else
							$selected="";
						$content .= "<option value=\"$thislanguageid\" $selected>$thisname</option>";
					}
					$content .= "
					</select>
				</td>
				</tr>";
			}
		
			$content .= "
			<tr>
				<td align=\"left\">"._CP_CA_SELECT_PAGE_."</td>
				<td align=\"left\">
					<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;
						if ($thisactive==0)
							$activepage="style=\"background-color:gray;color:white\"";
						else
							$activepage="";

						if ($_SESSION['active_page'] == $thispageid)
							$selected = "selected";
						else
							$selected = "";

						$content .= "<option value=\"$thispageid\" $activepage $selected>$thisname</option>";

						$recursivecount = 0;
						$content .= RecursivePageSelect($thispageid, $recursivecount);
					}
					$content .= "
					</select>
				</td>
			</tr>
			<tr>
				<td colspan=\"2\" align=\"center\">
					<br>";
					$content .= "<input type=\"submit\" value=\""._CP_CA_EDIT_CONTENT_."\" style=\"float:center;\"/>";
					$content .= go_back();
					$content .= "
				</td>
			</tr>
			</table>
			<br>
		</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>
		";

		$_SESSION['active_page'] = "";
	}

	return $content;
}

function EditContent($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_pagetype = new CPageType();
	$obj_pagetypearray = new CPageTypeArray();
	$obj_pagetypeengine = new CPageTypeEngine();

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

	$obj_language = new CLanguage();
	$obj_languagearray = new CLanguageArray();
	$obj_languageengine = new CLanguageEngine();

	if (!isset($f)) $f="content";
	if (!isset($sf)) $sf="editcontent";

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

	$_SESSION['active_page'] = $pageid;

	$obj_language = $obj_languageengine->FindLanguage($languageid);
	$lang = $obj_language->lang;
	$language = $obj_language->language;

	$obj_content = $obj_contentengine->GetContent($lang, $pageid, "name");
	$name = $obj_content->context;

	$obj_content = $obj_contentengine->GetContent($lang, $pageid, "content");
	$editcontent = $obj_content->context;

	$header = _CONTROL_PANEL_."<br>";
	$header .= _CP_CONTENT_ADMINISTRATION_._CMN_DASH_._CP_CA_EDIT_CONTENT_;

?>
<!-- TinyMCE -->
<script language="javascript" type="text/javascript" src="./jscripts/tiny_mce/tiny_mce.js"></script>
<!--script language="javascript" type="text/javascript" src="./jscripts/tiny_mce/tiny_mce_gzip.php"></script-->
<script language="javascript" type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,ibrowser",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen,ibrowser",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		content_css : "example_full.css",
	    plugin_insertdate_dateFormat : "%Y-%m-%d",
	    plugin_insertdate_timeFormat : "%H:%M:%S",
		extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		external_link_list_url : "example_link_list.js",
		external_image_list_url : "example_image_list.js",
		flash_external_list_url : "example_flash_list.js",
		file_browser_callback : "fileBrowserCallBack",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		language : "<?=$_SESSION['lang']?>"
	});

function fileBrowserCallBack(field_name, url, type, win) {

	// Do custom browser logic
	var connector = "../../../../modules/content/file_browser.php?fbtype=" + type;

	// Insert new URL, this would normaly be done in a popup
	// win.document.forms[0].elements[field_name].value = "someurl.htm";

	window.open(connector, 'win', 'width=640,height=480,scrollbars=yes,status=yes,location=no,resizable=yes', 1);
}
</script>
<!-- /TinyMCE -->


<?
	$content .= "<center>"._CMN_USE_FIREFOX_."</center>";
	$content .= "
	<form method=\"post\" action=\"".basename($PHP_SELF)."?f=content&sf=edit\">
		<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />
		<input type=\"hidden\" name=\"languageid\" value=\"$languageid\" />
		<input type=\"hidden\" name=\"operation\" value=\"savecontent\" />
		<textarea id=\"elm1\" name=\"elm1\" rows=\"25\" cols=\"80\" style=\"width: 100%\">
			".$editcontent."
		</textarea>
		<br />
		<input type=\"submit\" name=\"save\" value=\""._CMN_SAVE_."\" />
	</form>
	";


	return $content;
}

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

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

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

	$obj_language = new CLanguage();
	$obj_languagearray = new CLanguageArray();
	$obj_languageengine = new CLanguageEngine();

	if (!isset($f)) $f="content";
	if (!isset($sf)) $sf="";

	$pageid = $request['pageid'];
	$languageid = $request['languageid'];
	$editcontent = $request['editcontent'];

	$elm1 = $request['elm1'];
	$editcontent = $elm1;

	$obj_language = $obj_languageengine->FindLanguage($languageid);
	$lang = $obj_language->lang;
	$language = $obj_language->language;

	$obj_content = $obj_contentengine->GetContent($lang, $pageid, "content");
	$obj_content->context = $editcontent;
	$obj_content->page_id = $pageid;

	//Hit Counter for User mode
	$hitcounter = $obj_content->hit_counter;
	$hitcounter++;
	$obj_content->hit_counter = $hitcounter;

	if (!$obj_contentengine->UpdateContent($lang, $obj_content, "content"))
		echo "Update Error on Content Engine<br>";

	ReDirection(basename($PHP_SELF)."?f=content&sf=edit&operation=editcontent&pageid=".$pageid."&languageid=".$languageid."");

	return $content;
}


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

	$operation = $request['operation'];

	$content = Create_Tab_Menu($request);

	switch ($operation){
	default:
	case 'selectpage':
		$content .= SelectPage();
	break;
	case 'editcontent':
		$content .= EditContent($request);
	break;
	case 'savecontent':
		$content .= SaveContent($request);
	break;
	}

	return $content;
}
?>
Return current item: ChiCoMaS - Chilek CMS