__construct($id, $data); } public function __construct($id = NULL, $data = NULL){ $this->conn = db_connect(); $this->id = $id; if ($id == NULL){//New job if ($data == NULL){ error("Job: No data supplied."); }else { $this->registered = date("Y-m-d H:i:s"); $this->user_id_registered = getCurrentUser(); $this->published = date("Y-m-d H:i:s"); $this->position_id = (isset($data['positionid'])) ? $data['positionid'] : 0; } }else {//ID set, existing article if ($data != NULL){//Update existing article }else {//Retrieve data from backend for display or other actions $data = $this->_retrieveData(); if ($data == NULL){ notify("Stillingen du søkte er ikke tilgjengelig. Bruk skjemaet under om du vil rapportere problemet."); displayBugReportForm("job"); $this->id = NULL; } $this->jobcategory_title = $data['jobcategory_title']; $this->registered = $data['registered']; $this->user_id_registered = $data['user_id_registered']; $this->published = $data['published']; $this->position_id = (isset($data['position_id'])) ? $data['position_id'] : 0; } } //Common initializations $this->name = stripcslashes($data['name']); $this->text = stripcslashes($data['text']); $this->jobcategory_id = $data['jobcategory_id']; $this->contactInfo = $data['contactInfo']; $this->expires = $data['expires']; } public function store(){ $this->conn->autoCommit(false); if ($this->id == NULL){ $this->id = getNextId("din_job"); $sql = sprintf("INSERT INTO din_job (id, name, text, jobcategory_id, contactInfo, registered, user_id_registered, published, expires, position_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart($this->name), $this->conn->quoteSmart($this->text), $this->conn->quoteSmart($this->jobcategory_id), $this->conn->quoteSmart($this->contactInfo), $this->conn->quoteSmart($this->registered), $this->conn->quoteSmart($this->user_id_registered), $this->conn->quoteSmart($this->published), $this->conn->quoteSmart($this->expires), $this->conn->quoteSmart($this->position_id) ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ $GLOBALS['extraScriptParams']['jobid'] = $this->id; $sql = sprintf("INSERT INTO din_jobupdate VALUES (NULL, NOW(), %s, %s, %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart(getCurrentUser()), $this->conn->quoteSmart("Job registered.") ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ if ($this->conn->commit()){ notify("New job registered and stored."); }else { $this->conn->rollback(); error("New jobb: " . $result->toString()); } }else { $this->conn->rollback(); error("New job: " . $result->toString()); } }else { error("New job: " . $result->toString()); } }else { $sql = sprintf("UPDATE din_job SET name = %s, text = %s, jobcategory_id = %s, contactInfo = %s, expires = %s WHERE id = %s", $this->conn->quoteSmart($this->name), $this->conn->quoteSmart($this->text), $this->conn->quoteSmart($this->jobcategory_id), $this->conn->quoteSmart($this->contactInfo), $this->conn->quoteSmart($this->expires), $this->conn->quoteSmart($this->id) ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ $sql = sprintf("INSERT INTO din_jobupdate VALUES (NULL, NOW(), %s, %s, %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart(getCurrentUser()), $this->conn->quoteSmart("Job updated.") ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ if ($this->conn->commit()){ notify("Job updated."); }else { $this->conn->rollback(); error("Update job: " . $result->toString()); } }else { $this->conn->rollback(); error("Update job: " . $result->toString()); } }else { $this->conn->rollback(); error("Update job: " . $result->toString()); } } } public function _retrieveData(){ $sql = "SELECT j.*, jc.title AS jobcategory_title FROM din_job j, din_jobcategory jc WHERE j.id = $this->id AND j.jobcategory_id = jc.id"; $result =& $this->conn->query($sql); if (DB::isError($result) != true){ if ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)){ return $row; } }else { error("Jobs: " . $result->toString()); } } public function delete($id){ $conn = db_connect(); $sql = "DELETE FROM din_job WHERE id = $id LIMIT 1"; $result = $conn->query($sql); if (DB::isError($result) != true){ notify("Job deleted."); }else { error($result->toString()); } } public function display(){ if ($this->id == NULL){ return false; } $this->_markAsRead(); ?>
text); ?>
contactInfo); ?>