Jump to content

Recommended Posts

Am having the following error here:

Fatal error: Using $this when not in object context in .....\pb_events.php on line 5

Any idea how to put $this in object context?

function DoEvents($this) {
global $_CONF, $_PAGE, $_TSM , $base;

$jpp = $this->vars->data["jpp"];

$cache["departments"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_departments]}");
$cache["locations"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_location]}");
$cache["names"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_names]}");
$cache["categories"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_categories]}");

//add the categories and the departments to the template
if (is_array($cache["categories"])) {
	$_TSM["CATEGORIES"] = $base->html->Table($this->templates["categories"], "Categories" , $cache["categories"]);
} else
	$_TSM["CATEGORIES"] = "";

if (is_array($cache["departments"])) {
	$_TSM["DEPARTMENTS"] = $base->html->Table($this->templates["departments"], "Departments" , $cache["departments"]);
} else
	$_TSM["DEPARTMENTS"] = "";


$_pb_used_vars = array("1" => "departments" , "locations" , "names" , "categories");
$_pb_used_keys = array("1" => "department" , "location" , "name" , "category");

//preprocess for assinging the correct id
foreach ($_pb_used_vars as $k => $v) {
	if (is_array($cache[$v])) {
		foreach ($cache[$v] as $key => $val) {
			$cache["_" . $v][$val[$_pb_used_keys[$k] . "_id" ]] = $val[$_pb_used_keys[$k] . "_title" ];
		}

		$cache[$v] = $cache["_" . $v];
		unset($cache["_" . $v]);
	}
}

$_GET["page"] = $_GET["page"] > 0 ? $_GET["page"] : 1;

$time = time();

switch ($_GET["sub"]) {
	case "details":
		$job = $this->db->QFetchArray("SELECT * FROM {$this->tables[job_list]} WHERE job_id = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

		//check if is a valid job
		if (is_array($job)) {

			//add the extra data
			$job["job_category_title"] = $cache["categories"][$job["job_category"]];
			$job["job_department_title"] = $cache["departments"][$job["job_department"]];
			$job["job_location_title"] = $cache["locations"][$job["job_location"]];
			$job["job_name_title"] = $cache["names"][$job["job_title"]];

			$job["referer"] = $_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"] : "list.php";
			$job["job_salary"] = number_format($job["job_salary"] , 2 );
			$job["details_link"] = $job["job_link"] ? $this->templates["details"]->blocks["Link"]->Replace($job) : "";

			return $this->templates["details"]->blocks["Main"]->Replace($job);

		} else {
			//redirect to error.php
			header("Location: error.php");
			exit;
		}			
	break;

	case "department":

		//check if is a valid department
		if ($cache["departments"][$_GET["id"]]) {

			$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE `job_department` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}' LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
			$count = $this->db->RowCount($this->tables["job_list"] , "WHERE `job_department` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

		} else {
			//redirect to error.php
			header("Location: error.php");
			exit;
		}

	break;

	case "category":

		//check if is a valid department
		if ($cache["categories"][$_GET["id"]]) {

			$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE `job_category` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
			$count = $this->db->RowCount($this->tables["job_list"] , "WHERE `job_category` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

		} else {
			//redirect to error.php
			header("Location: error.php");
			exit;
		}

	break;

	case "error":
		return $this->templates["error"]->output;
	break;

	case "search":
		if ($_GET["what"]) {
			//searching in cache
			if (is_array($cache["names"])) {
				foreach ($cache["names"] as $key => $val) {
					if (stristr($val , $_GET["what"])) {
						$found[] = $key;
					}						
				}

			}

			//ok search for the list of jobs
			$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE (job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}') AND (`job_description` LIKE '%{$_GET[what]}%' or `job_summary` LIKE '%{$_GET[what]}%' " . (is_array($found) ? " OR `job_title` in (" . implode("," , $found) . ")" : "" ) . " ) LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
			$count = $this->db->RowCount($this->tables["job_list"] , "WHERE (job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}') AND  (`job_description` LIKE '%{$_GET[what]}%' or `job_summary` LIKE '%{$_GET[what]}%' " . (is_array($found) ? " OR `job_title` in (" . implode("," , $found) . ")" : "") . ")");

			break;
		}

	default:
		$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}' LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
		$count = $this->db->RowCount($this->tables["job_list"] , "WHERE job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");
	break;		
}

$alternance = 1;

if (is_array($jobs)) {
	foreach ($jobs as $key => $val) {
		//add the extra data
		$jobs[$key]["job_category_title"] = $cache["categories"][$val["job_category"]];
		$jobs[$key]["job_department_title"] = $cache["departments"][$val["job_department"]];
		$jobs[$key]["job_location_title"] = $cache["locations"][$val["job_location"]];
		$jobs[$key]["job_name_title"] = $cache["names"][$val["job_title"]];

		//also add the alternance template
		$jobs[$key]["alternance"] = $this->templates["list"]->blocks["Alternance" . $alternance]->output;

		//switch
		$alternance = !$alternance;
	}		
}

//build a table with the results;

//well ok, now show the list with the templates

return $base->html->Table($this->templates["list"],"List",$jobs,true,$count,$jpp,$_GET["page"],$this->templates["paging"],array(
																																	"base" => in_array($_GET["sub"] , array ("department" , "category" , "search")) ? $_GET["sub"] . ".php" : "list.php" ,
																																	"extra" => $_GET["id"] ? "id=" . $_GET["id"] . "&" : "",
																																	"what" => $_GET["what"] ? "what=" . $_GET["what"] . "&" : ""

																																));

}

Link to comment
https://forums.phpfreaks.com/topic/227630-this/
Share on other sites

<?php
function DoEvents($this) {
global $_CONF , $_TSM;

$_TSM["MENU"] = "";

//checking if user is logged in
if (!$_SESSION["minibase"]["user"]) {

	if ($_SERVER["REQUEST_METHOD"] == "POST") {

		//autentificate
		$user = $this->db->QFetchArray("select * from {$this->tables[job_users]} where `user_login` = '{$_POST[user]}' AND `user_password` = '{$_POST[pass]}'");

		if (is_array($user)) {
			$_SESSION["minibase"]["user"] = 1;
			$_SESSION["minibase"]["raw"] = $user;

			//redirecing to viuw sites
			header("Location: $_CONF[default_location]");
			exit;
		} else
			return $this->templates["login"]->blocks["Login"]->output;

	} else
		return $this->templates["login"]->blocks["Login"]->output;
}
if ($_SESSION["minibase"]["raw"]["user_level"] == 0) {
	$_TSM["MENU"] = $this->templates["login"]->blocks["MenuAdmin"]->output;
} else {
	$_TSM["MENU"] = $this->templates["login"]->blocks["MenuUser"]->output;
}


switch ($_GET["sub"]) {
	case "logout":
		unset($_SESSION["minibase"]["user"]);
		header("Location: index.php");

		return $this->templates["login"]->EmptyVars();
	break;

	case "job_categories":
	case "job_departments":
	case "job_locations":
	case "job_names":
	case "job_users":
		if ($_SESSION["minibase"]["raw"]["user_level"] != 0 )
			return "Access Denied!";

		$data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables);
		return $data->DoEvents();
	break;

	case "job_list":

		if (!$_POST["job_date"]) {
			$_POST["job_date"] = time();
		}

		if (!$_POST["job_user"]) {
			$_POST["job_user"] = $_SESSION["minibase"]["raw"]["user_id"];
		}

		$data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables);
		return $data->DoEvents();
	break;

	case "job_settings":

		if ($_SESSION["minibase"]["raw"]["user_level"] != 0 )
			return "Access Denied!";

		$file = $_GET["sub"] . ".xml";

		$data = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->tables);

		if ($_GET["action"] == "store") {
			if (is_array($values = $data->Validate($_CONF["forms"]["adminpath"] . $file,$_POST))) {

				return $data->Show($_CONF["forms"]["adminpath"] . $file, $values);
			} else {

				$this->vars->SetAll($_POST);
				$this->vars->Save();

				header("location: index.php?mod=eshop&sub=" . $_GET["sub"]);
				exit;
			}

		}

		return $data->Show($_CONF["forms"]["adminpath"] . $file , array("values"=>$this->vars->data));

	break;

}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/227630-this/#findComment-1174091
Share on other sites

My problem was $this error and not support for that third party app.

 

Well be helpful at least and let me know how i can start learning OOP in PHP.

 

I did in C++ though, so i don't think it would be hard.

thanks in advance.

The $this error is OCCURING in your third party code, yes?

As for your second statement...Here's a fishing pole.

|

|

V

Link to comment
https://forums.phpfreaks.com/topic/227630-this/#findComment-1174141
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.