From: <gbr...@us...> - 2003-05-24 20:34:44
|
Update of /cvsroot/phpwebsite-comm/modules/jobman/class In directory sc8-pr-cvs1:/tmp/cvs-serv29847/class Added Files: job.php Log Message: renaming... --- NEW FILE: job.php --- <?php /** * Job.php * Defines Job class for Job Manager module * * This class is an extension of the PHPWS_Item class defined in core/Item.php. * Its function is to create, edit, delete, and view one of the items in a list. * The class defines additional variables to the standard ones handled automatically * by PHPWS_Item, defines a constructor, edit(), delete(), and view() function, and * an action() switch that handles other procedures (here, a save() function) that * are needed. * * The listing of these items is handled by an extension of the PHPWS_Manager * class, defined in core/Manager.php. * * @version $Id: job.php,v 1.1 2003/05/24 20:34:41 gbrackett Exp $ * @author George Brackett <gbr...@NO...> * @package Job Manager */ class Job extends PHPWS_Item { /** * title of this job is stored in the item's Label field */ /** * status of this job -- full or part time * @var string */ var $_status = NULL; /** * hours of this job - a number, or 'flexible' etc. * @var string */ var $_hours = NULL; /** * date this job is available - an actual date, or 'ASAP' etc. * @var string */ var $_date_available = NULL; /** * contact for this job * @var string */ var $_contact = NULL; /** * description of this job * @var string */ var $_description = NULL; /** * qualifications for this job * @var string */ var $_qualifications = NULL; /** * Constructor for the job class * Sets all the job attributes * * @param int $job_id id of the job to be constructed; NULL if new job */ function Job($job_id = NULL) { /* point to the jobs data table */ $this->setTable("mod_jobman_jobs"); /* if the job exists, initialize its variables from the database */ if (isset($job_id)) { $error = $this->setId($job_id); /* setId returns a PHPWS_Error object */ if(PHPWS_Error::isError($error)) { $error->message('CNT_jobman'); /* report the error, if any */ } $this->init(); /* initialize variables */ } } /** * Edit a job object's data * * @author George Brackett <gbr...@NO...> */ function edit() { // Create a 'Back' button using EZform // Note: form action defaults to "index.php" $form = new EZform("JOB_BACK"); $form->add("BACK_BUTTON", "submit", $_SESSION["translate"]->it("Back")); $form->add("module", "hidden", "jobman"); $form->add("JOB_MAN_op", "hidden", "list"); $tags = array(); $tags = $form->getTemplate(); $content = $GLOBALS["core"]->processTemplate($tags, "jobman", "back.tpl"); // Set up the edit form $form = new EZform("JOB_EDIT"); $form->add("POSITION", "text", htmlspecialchars($this->getLabel())); $form->setSize("POSITION", 33); $form->setMaxSize("POSITION", 255); $form->setTab("POSITION", 1); $form->add("STATUS", "text", htmlspecialchars($this->_status)); $form->setSize("STATUS", 30); $form->setMaxSize("STATUS", 255); $form->setTab("STATUS", 2); $form->add("HOURS", "text", htmlspecialchars($this->_hours)); $form->setSize("HOURS", 30); $form->setMaxSize("HOURS", 255); $form->setTab("HOURS", 3); $form->add("DATE_AVAILABLE", "text", htmlspecialchars($this->_date_available)); $form->setSize("DATE_AVAILABLE", 33); $form->setMaxSize("DATE_AVAILABLE", 255); $form->setTab("DATE_AVAILABLE", 4); $form->add("CONTACT", "text", htmlspecialchars($this->_contact)); $form->setSize("CONTACT", 50); $form->setMaxSize("CONTACT", 255); $form->setTab("CONTACT", 5); // note do not need to convert special characters for a text area $form->add("DESCRIPTION", "textarea", $this->_description); $form->setTab("DESCRIPTION", 6); $form->add("QUALIFICATIONS", "textarea", $this->_qualifications); $form->setTab("QUALIFICATIONS", 7); $form->add("SUBMIT_BUTTON", "submit", $this->getId() ? $_SESSION["translate"]->it("Update") : $_SESSION["translate"]->it("Save")); $form->add("module", "hidden", "jobman"); $form->add("JOB_op", "hidden", "save"); $tags = array(); $tags = $form->getTemplate(); // include category selection menu, with help $tags["CATEGORY"] = $_SESSION['OBJ_fatcat']->showSelect($this->id, "multiple", 3, "jobman"); $tags["CATEGORY_HELP"] = $_SESSION['OBJ_help']->show_link("jobman", "jmCategory"); $tags["CATEGORY_LABEL"] = $_SESSION['translate']->it("Category"); // vary title for new and edited listings if ($this->getId()) { $tags["TITLE"] = $_SESSION["translate"]->it("Edit Position Listing"); } else { $tags["TITLE"] = $_SESSION["translate"]->it("Add Position Listing"); } /* include help links also, to display help for each field to be completed */ $tags["POSITION_LABEL"] = $_SESSION['translate']->it("Position"); $tags["POSITION_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmPosition"); $tags["STATUS_LABEL"] = $_SESSION['translate']->it("Status"); $tags["STATUS_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmStatus"); $tags["HOURS_LABEL"] = $_SESSION['translate']->it("Hours"); $tags["HOURS_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmHours"); $tags["DATE_AVAILABLE_LABEL"] = $_SESSION['translate']->it("Date Available"); $tags["DATE_AVAILABLE_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmDateAvailable"); $tags["CONTACT_LABEL"] = $_SESSION['translate']->it("Contact"); $tags["CONTACT_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmContact"); $tags["DESCRIPTION_LABEL"] = $_SESSION['translate']->it("Description"); $tags["DESCRIPTION_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmDescription"); $tags["QUALIFICATIONS_LABEL"] = $_SESSION['translate']->it("Qualifications"); $tags["QUALIFICATIONS_HELP"] = $_SESSION["OBJ_help"]->show_link("jobman", "jmQualifications"); $content .= $GLOBALS["core"]->processTemplate($tags, "jobman", "edit.tpl"); return $content; } //END function edit /** * Asks for confirmation and, getting it, deletes the current position listing * * @author George Brackett <gbr...@NO...> */ function delete() { if (isset($_REQUEST["YES_BUTTON"])) { // have confirmation; remove category listing while we know the id $_SESSION['OBJ_fatcat']->purge($this->getId(), "jobman"); // delete the current item $this->kill(); // function defined in core/item.php // tell 'em it's done $content = $this->_continueContent("Position listing deleted.", "list"); } elseif (isset($_REQUEST["NO_BUTTON"])) { /* tell user all is still okay */ $content = $this->_continueContent("Position listing NOT deleted.", "list"); } else { /* ask if the user is sure */ $form = new EZform("JOB_DELETE"); $form->add("YES_BUTTON", "submit", $_SESSION["translate"]->it("Yes")); $form->add("NO_BUTTON", "submit", $_SESSION["translate"]->it("No")); $form->add("module", "hidden", "jobman"); $form->add("JOB_MAN_op", "hidden", "delete"); // note must indicate with [] that the id variable is in an array $form->add("PHPWS_MAN_ITEMS[]", "hidden", $this->getId()); $tags = array(); $tags = $form->getTemplate(); $tags["MESSAGE"] = $_SESSION["translate"]->it("Delete this position listing?"); $tags["POSITION_LABEL"] = $_SESSION['translate']->it("Position"); $tags["STATUS_LABEL"] = $_SESSION['translate']->it("Status"); $tags["HOURS_LABEL"] = $_SESSION['translate']->it("Hours"); $tags["DATE_AVAILABLE_LABEL"] = $_SESSION['translate']->it("Date Available"); $tags["CONTACT_LABEL"] = $_SESSION['translate']->it("Contact"); $tags["DESCRIPTION_LABEL"] = $_SESSION['translate']->it("Description"); $tags["QUALIFICATIONS_LABEL"] = $_SESSION['translate']->it("Qualifications"); $tags["POSITION"] = $this->getLabel(); $tags["STATUS"] = $this->_status; $tags["HOURS"] = $this->_hours; $tags["DATE_AVAILABLE"] = $this->_date_available; $tags["CONTACT"] = $this->_contact; $tags["DESCRIPTION"] = $this->_description; $tags["QUALIFICATIONS"] = $this->_qualifications; $content .= $GLOBALS["core"]->processTemplate($tags, "jobman", "confirm.tpl"); } return $content; } //END function delete /** * Displays current position listing * * @author George Brackett <gbr...@NO...> */ function view() { $form = new EZform("JOB_VIEW"); $form->add("CONTINUE_BUTTON", "submit", $_SESSION["translate"]->it("Continue")); $form->add("module", "hidden", "jobman"); $form->add("JOB_MAN_op", "hidden", "list"); $tags = array(); $tags = $form->getTemplate(); $tags["POSITION_LABEL"] = $_SESSION['translate']->it("Position"); $tags["STATUS_LABEL"] = $_SESSION['translate']->it("Status"); $tags["HOURS_LABEL"] = $_SESSION['translate']->it("Hours"); $tags["DATE_AVAILABLE_LABEL"] = $_SESSION['translate']->it("Date Available"); $tags["CONTACT_LABEL"] = $_SESSION['translate']->it("Contact"); $tags["DESCRIPTION_LABEL"] = $_SESSION['translate']->it("Description"); $tags["QUALIFICATIONS_LABEL"] = $_SESSION['translate']->it("Qualifications"); $tags["POSITION"] = $this->getLabel(); $tags["STATUS"] = $this->_status; $tags["HOURS"] = $this->_hours; $tags["DATE_AVAILABLE"] = $this->_date_available; $tags["CONTACT"] = $this->_contact; $tags["DESCRIPTION"] = $this->_description; $tags["QUALIFICATIONS"] = $this->_qualifications; $content = $GLOBALS["core"]->processTemplate($tags, "jobman", "view.tpl"); return $content; } //END function functionname /** * Saves data for job object to database * * @author George Brackett <gbr...@NO...> */ function _save() { $newjob = ($this->getId() == NULL); $error = FALSE; // we MUST have a position title, since this is the label for the data entry; errors if not if (!isset($_REQUEST["POSITION"]) || (trim($_REQUEST["POSITION"]) == "")) { $message = "<br /><b>" . $_SESSION['translate']->it("Please enter a position title.") . "</b><hr>"; $_REQUEST["POSITION"] = $_SESSION['translate']->it("Error"); $error = TRUE; } // save the edited data in the database in either case // note that parseInput called this way allows the global set of HTML tags to be included $this->setLabel(PHPWS_Text::parseInput($_REQUEST["POSITION"])); $this->_status = PHPWS_Text::parseInput($_REQUEST["STATUS"]); $this->_hours = PHPWS_Text::parseInput($_REQUEST["HOURS"]); $this->_date_available = PHPWS_Text::parseInput($_REQUEST["DATE_AVAILABLE"]); $this->_contact = PHPWS_Text::parseInput($_REQUEST["CONTACT"]); $this->_description = PHPWS_Text::parseInput($_REQUEST["DESCRIPTION"]); $this->_qualifications = PHPWS_Text::parseInput($_REQUEST["QUALIFICATIONS"]); $this->commit(); // save the category $element_link = "index.php?module=jobman&JOB_MAN_op=sView&JOB_id=" . $this->getId(); $_SESSION['OBJ_fatcat']->saveSelect($this->getLabel(), $element_link, $this->getId()); if ($error) { $GLOBALS["CNT_jobman"]["title"] = "<span class=\"errortext\">" . $_SESSION['translate']->it("Error") . "</span>"; $content = $message . $this->edit(); } else { /// tell user data is saved or updated if ($newjob) { $content = $this->_continueContent("Position listing saved.", "list"); } else { $content = $this->_continueContent("Position listing updated.", "list"); } $GLOBALS["CNT_jobman"]["title"] = $_SESSION['translate']->it("Positions Available"); } // set content display $GLOBALS["CNT_jobman"]["content"] = $content; } //END function _save /** * Return content for a display with a message and a continue button * * @param string $message The string to display above the continue button, already translated * @param string $action The JOB_MAN_op action to perform when Continue is pressed * @author George Brackett <gbr...@NO...> */ function _continueContent($message, $action) { $form = new EZform("JOB_CONTINUE"); $form->add("module", "hidden", "jobman"); $form->add("JOB_MAN_op", "hidden", $action); $form->add("CONTINUE_BUTTON", "submit", $_SESSION["translate"]->it("Continue")); $tags = array(); $tags = $form->getTemplate(); $tags["MESSAGE"] = $_SESSION["translate"]->it($message); $content = $GLOBALS["core"]->processTemplate($tags, "jobman", "continue.tpl"); return $content; } //END function functionname /** * Perform actions on job object data (not object) * * @author George Brackett <gbr...@NO...> */ function action() { if (isset($_REQUEST["JOB_op"])) { switch($_REQUEST["JOB_op"]) { case "save": $this->_save(); break; } } /* if ($content != NULL) { */ /* /* set display variables */ /* $GLOBALS["CNT_jobman"]["content"] = $content; */ /* $GLOBALS["CNT_jobman"]["title"] = $_SESSION['translate']->it("Positions Available"); */ /* } */ }// END function action } ?> |