Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/myinfo/myinfo_operation.php
<?
defined( '_VALID_DA_' ) or die( 'Direct Access to this location is not allowed.' );

//*****************************************************************************
function Begin_Script($request){

	$content = "

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

	$sf = $request['sf'];
	$all = $request['all'];
	if (!isset($all))
		$all=0;

	$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=myinfo\" $current>"._CP_MYINFO_."</a></li>";

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

	return $content;

};

//*****************************************************************************
function End_Script(){
	$content = "";
	return $content;
};

/*****************************************************************************/
function Edit_Myinfo($request){

	global $module;
	global $module_path;

	$content = null;

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

	$obj_tempdb2array = new CTempDBArray();
	$obj_tempdb2engine = new CTempDBEngine();

	$userid = $_SESSION['uid'];

	$SQL = "SELECT * FROM users WHERE user_id=".intval($userid);
	$row = $obj_tempdbengine->GetRow($SQL);
	$active = $row['active'];
	if ($active)
		$active = " checked ";
	$username = $row['username'];
	$name_surname = $row['name_surname'];
	$email = $row['email'];
	$reg_date = $row['reg_date'];
	$last_login = $row['last_login'];

	$SQL = "SELECT * FROM user_groups ";
	$SQL .= "WHERE user_id='".intval($userid)."' ";
	$row = $obj_tempdbengine->GetRow($SQL);
	$groupid = $row['group_id'];
	
	$content = "
	<center>
	<form action='".basename($PHP_SELF)."?f=myinfo&sf=edit' method='post'>
	<input type=\"hidden\" name=\"operation\" value=\"save\" />
	<input type=\"hidden\" name=\"lastoperation\" value=\"update\" />
	<input type=\"hidden\" name=\"oldusername\" value=\"$username\" />
	<input type=\"hidden\" name=\"user\" value=\"$userid\" />
	<fieldset>
	<img style=\"float:right;\" src=\"./images/icon48/personel.png\" width=\"48\" height=\"48\" border=\"0\">
	<legend>"._CP_UA_FORM_USERS_INFORMATION_."</legend>
		<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
		<tr>
			<td><label for=\"active\">"._CP_UA_FORM_ACTIVE_."</label></td>
			<td><input type=\"checkbox\" name=\"active\" $active style=\"float:left;\" disabled/></td>
		</tr>
		<tr>
			<td><label for=\"newgroup\">"._CP_UA_FORM_GROUP_NAME_."</label></td>
			<td>
				<select name=\"newgroup\" style=\"float:left;\" disabled>";
				if ($groupid==0)
					$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				else
					$selected = "";
			
				$SQL2 = "SELECT * FROM groups";
				$obj_tempdb2array = $obj_tempdb2engine->GetRows($SQL2);
			
				//$content .= "<option value=\"0\" $selected>"._CMN_SELECT_AN_OPTION_."</option>";
				while( $row2 = $obj_tempdb2array->get() ){
						if ($groupid == $row2['group_id'])
							$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
						else
							$selected = "";
						$content .= "<option value=\"".$row2['group_id']."\" $selected>".$row2['group_name']."</option>";
				}
				$content .= "
				</select>
			</td>
		</tr>
		<tr>
			<td><label for=\"username\">"._CP_UA_FORM_USERNAME_."</label></td>
			<td><input type=\"text\" name=\"username\" value=\"$username\" style=\"float:left;\" maxlength=\"16\"/></td>
		</tr>
		<tr>
			<td><label for=\"name_surname\">"._CP_UA_FORM_NAME_SURNAME_."</label></td>
			<td><input type=\"text\" name=\"name_surname\" value=\"$name_surname\" style=\"float:left;\" maxlength=\"32\"/></td>
		</tr>
		<tr>
			<td><label for=\"email\">"._CP_UA_FORM_EMAIL_."</label></td>
			<td><input type=\"text\" name=\"email\" value=\"$email\" style=\"float:left;\" size=\"24\" maxlength=\"64\"/></td>
		</tr>
		<tr>
			<td><label for=\"password1\">"._CP_UA_FORM_PASSWORD_."</label></td>
			<td><input type=\"password\" name=\"password1\" style=\"float:left;\" size=\"8\" maxlength=\"16\"/></td>
		</tr>
		<tr>
			<td><label for=\"password2\">"._CP_UA_FORM_REPEAT_PASSWORD_."</label></td>
			<td><input type=\"password\" name=\"password2\" style=\"float:left;\" size=\"8\" maxlength=\"16\"/></td>
		</tr>

		<tr>
			<td><em>"._CP_UA_LIST_USERS_REGISTER_DATE_."</em></td>
			<td><em>$reg_date</em></td>
		</tr>

		<tr>
			<td><em>"._CP_UA_LIST_USERS_LAST_VISITED_."</em></td>
			<td><em>$last_login</em></td>
		</tr>

		<tr>
			<td colspan=\"2\" align=\"center\">
				<br>";
				$content .= "<input type=\"submit\" value=\""._CMN_UPDATE_."\" style=\"float:center;\"/>";
				$content .= go_back();
				$content .= "
			</td>
		</tr>
		</table>
		<br>
	</fieldset>
	</form>
	</center>";

	return $content;
}


/*****************************************************************************/
function Save_Myinfo($request){

	global $module;
	global $module_path;

	$content = null;

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

	$userid = $request['user'];
	$name_surname = $request['name_surname'];
	$username = $request['username'];
	$password1 = $request['password1'];
	$password2 = $request['password2'];
	$email = $request['email'];
	$lastoperation = $request['lastoperation'];
	$oldusername = $request['oldusername'];

	$my_validator = new validator();

	if (!(($my_validator->validate_fields("name_surname")) && ($my_validator->validate_fields("username")) && ($my_validator->validate_fields("email")))) {
		$failed = true;
	}
	else {
		if ($password1!=$password2)
			$password_failed = false;
		else
			if ($password1!="")
				$changepassword = true;

		$password = sha1($password1);

	
		if ($username==$oldusername)
			$sameusername = true;
	
		if ($lastoperation=="update"){
			$SQL  = "UPDATE users ";
			$SQL .= "SET ";
//			$SQL .= "active = '".$active."', ";
			$SQL .= "name_surname = '".ucwords($name_surname)."', ";
			if (!$sameusername)
				$SQL .= "username = '".strtolower($username)."', ";
			if ($changepassword)
				$SQL .= "password = '".$password."', ";
			$SQL .= "email = '".strtolower($email)."' ";
			$SQL .= "WHERE user_id=".intval($userid);

			if (!$obj_tempdbengine->ExecQuery($SQL))
				$content .= "<br>Update Error on ExecQuery<br>";

		}
		//$content .= $SQL;
	}


	$content .= "
	<div class=note>
		<h3>"._CMN_NOTE_."</h3>
		<p>";
		if (!$failed){
			if (!$samerecord){
				$content .= _CMN_SAVE_OK_;
				ReDirection(basename($PHP_SELF)."?f=myinfo");
			}
			else{
				$content .= _CP_UA_AU_SAME_RECORD_."<br><br>";
				$content .= go_back();
			}
		}
		else{
			$content .= _CMN_SAVE_FAILED_."<br><br>";
			$content .= go_back();
		}
		$content .= "
		</p>
	</div>
	";

	return $content;
}

	//*****************************************************************************
function Myinfo_Operation($request){

	global $module;
	global $module_path;
	global $process;

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

	$sf = $request['sf'];
	$operation = $request['operation'];

	$content = Begin_Script($request);

	switch ($operation){
	default:
	case 'edit':
		$content .= Edit_Myinfo($request);
	break;
	case 'save':
		$content .= Save_Myinfo($request);
	break;
	}
	$content .= End_Script();

	return $content;
}

?>
Return current item: ChiCoMaS - Chilek CMS