$formLang = new sfc\Form(SSP_Path(), "noTable", "languageform"); $formLang->tplf = "testDatatypeLanguage.tpl"; $formLang->formSubmitVar = 'testLanguagechange'; $formLang->fe('select', 'language', 'Language', Protect::$tranlator->getLanguages()); $formLang->fep('deflt = ' . $session->lang); $formLang->fe('check', 'localError', 'Errors local to fields', array(0, 1)); $formLang->fep('deflt = ' . $errorLocal); if ($formLang->processForm($_POST)) { $session->lang = $formLang->getField('language'); if ($formLang->getField('localError') == 1) { $errorLocal = true; } else { $errorLocal = false; } session_write_close(); SSP_Divert(SSP_Path()); } else { $setLanguage = $formLang->create(); } $form = new sfc\Form("testcheckData.php", "TestSaveTable", "testdataform"); $form->tplf = "testCheckData_" . $session->lang . ".tpl"; $form->tda('lang', $session->lang); $form->tda('setLanguage', $setLanguage); if ($errorLocal) { $form->tda('localErrors', 1); } $form->errorsLocal = $errorLocal; $form->errorAutoFormDisplay = false; $form->fe("text", "textType", "Text input", ">"); $form->fe("text", "passwordType", "Password input", ">"); $form->fep("dataType=password");
* Routine: example1.php * Created: 23/03/2009 * Descrip: Basic for usage. * * Revision: a * Rev. Date 23/03/2009 * Descrip: Created. */ namespace w34u\ssp; // include libraries require "../../sspadmin/includeheader.php"; $mainTemplate = new Template("Main Template", "exampleMain.tpl"); // form definition // id name for the table is used for detection of submission and error messages $form = new sfc\Form(SSP_Path(true), "tableNameForSql", "idNameforTable"); $form->tpl = $mainTemplate; // main template to enclose the form, not required, form inserted into {content} $form->tplf = "example1.tpl"; // display template for the form $form->tda("miscTplData", "Some data for display on the form template, password is 'thingy'"); $form->fe("text", "firstElement", "First element, a text box"); $form->fep("required=true, dataType=text"); // element is required and is of data type text $form->fe("password", "pasword", "enter a password"); $form->fep("required=true, dataType=password, load=false"); $form->addHidden("hiddenStuff", "Some hidden stuff", "text"); // hidden field // check for submission if ($form->processForm($_POST)) { // check for error
$session = new Protect(); $dataCheck = new CheckData(); $formLang = new sfc\Form(SSP_Path(), "noTable", "languageform"); $formLang->tplf = "testDatatypeLanguage.tpl"; $formLang->formSubmitVar = 'testLanguagechange'; $formLang->fe('select', 'language', 'Language', Protect::$tranlator->getLanguages()); $formLang->fep('deflt = ' . $session->lang); $formLang->setParam('script', 'onChange="this.form.submit()"'); if ($formLang->processForm($_POST)) { $session->lang = $formLang->getField('language'); session_write_close(); SSP_Divert(SSP_Path()); } else { $setLanguage = $formLang->create(); } $form = new sfc\Form(SSP_Path(), "noTable", "testDatatype"); $form->tplf = "testDatatype.tpl"; $form->tda('lang', $session->lang); $form->tda('setLanguage', $setLanguage); $form->fe("text", "data", "Data to be checked"); $form->fep("dataType = gen"); $dataType = array("text" => "text " . $dataCheck->dataTypes["text"]->validChars, "password" => "password " . $dataCheck->dataTypes["password"]->validChars, "date" => "date " . $dataCheck->dataTypes["date"]->validChars, "time" => "time " . $dataCheck->dataTypes["time"]->validChars, "phone" => "phone " . $dataCheck->dataTypes["phone"]->validChars, "int" => "int " . $dataCheck->dataTypes["int"]->validChars, "real" => "real " . $dataCheck->dataTypes["real"]->validChars, "hex" => "hex " . $dataCheck->dataTypes["hex"]->validChars, "oct" => "oct " . $dataCheck->dataTypes["oct"]->validChars, "bin" => "bin " . $dataCheck->dataTypes["bin"]->validChars, "email" => "email " . $dataCheck->dataTypes["email"]->validChars, "emailchk" => "emailchk " . $dataCheck->dataTypes["email"]->validChars, "dom" => "dom " . $dataCheck->dataTypes["dom"]->validChars, "domchk" => "domchk " . $dataCheck->dataTypes["dom"]->validChars, "lable" => "lable " . $dataCheck->dataTypes["lable"]->validChars, "gen" => "general data, no checking at all!"); $form->fe("select", "dataType", "Data type to check against", $dataType); if ($form->processForm($_POST)) { if (!$form->error) { $error = $dataCheck->check($form->getField("dataType"), $form->getField("data")); $form->tda("errorNumber", $error); $form->tda("errorString", $dataCheck->errorMessage); echo $form->create(true); } } else {
/** * Start recovery of a users password */ public function startPasswordRecovery() { $form = new sfc\Form(SSP_Path(), "noTable", "startPasswordRecovery"); $form->tplf = "passwordrecover.tpl"; $form->tpl = $this->tpl(array("title" => "Password recovery")); $form->errorAutoFormDisplay = false; $form->tda("loginPath", $this->cfg->logonScript); $form->fe("text", "email", "Enter your registered email"); $form->fep("required=true,width=30, dataType=email"); $form->fe("submit", "submit", "Recover Password"); $form->fep("elClass=SSPFormButton"); if ($form->processForm($_POST)) { if (!$form->error) { // check for the email $fields = array("UserId", "UserEmail", "UserName", "UserPassword"); $where["UserEmail"] = SSP_encrypt(trim($form->getField("email"))); $row = $this->db->getf($this->cfg->userTable, $fields, $where, "SSP user admin: getting user info for password recovery"); if ($this->db->numRows()) { // found the email $rowMisc = $this->db->get($this->cfg->userMiscTable, array("UserId" => $row->UserId), "Getting user name for password recovery"); if ($this->cfg->passwordRecovery == 0 or $this->cfg->encryptPassword) { // use user change of password method // Generate user response token $token = SSP_ResponseToken($row->UserId, $this->cfg->recoverTime); // generate email if ($this->cfg->loginType == 1) { // Supply user name if used for login $content["UserName"] = $row["UserName"]; } $content["link"] = $this->cfg->newPassword; $content['token'] = $token; $content["adminEmail"] = $this->cfg->adminEmail; $email = new Email($this->cfg); $email->noReplyEmail($content, "emailpasswordrecovery0.tpl", $row->UserEmail, $rowMisc->FirstName . " " . $rowMisc->FamilyName); } else { // email all info to the user // generate email if ($this->cfg->loginType == 1) { // Supply user name if used for login $content["UserName"] = $row["UserName"]; } $content["UserPassword"] = $row["UserPassword"]; $content["adminEmail"] = $this->cfg->adminEmail; $email = new Email($this->cfg); $email->noReplyEmail($content, "emailpasswordrecovery1.tpl", $row->UserEmail, $rowMisc->FirstName . " " . $rowMisc->FamilyName); } $form->tda("sent"); $result = $form->create(); } else { // email not found $form->tda("error"); $result = $form->create(); } } else { $result = $form->create(true); } } else { // display form $result = $form->create(); } return $result; }
/** * Edit Miscellaneous data * @param bool $creating - creating a new user * @param bool $reDisplay - re-display after update * @return string/bool - edit screen or true on save and not re-display */ public function userMisc($creating = false, $reDisplay = false) { // Form elements $form = new sfc\Form(SSP_Path(), $this->cfg->userMiscTable, "userMisc"); $form->errorAutoFormDisplay = false; $mainContent = array(); if ($creating) { $mainContent["title"] = "Miscellaneous information"; } else { $mainContent["title"] = "Edit info"; } $form->tpl = $this->tpl($mainContent, $creating); if ($this->subTpl != "") { $form->tplf = $this->subTpl; } else { $form->tplf = "changemisc.tpl"; } $form->fe('text', "Title", "Title (Mr/Mrs/Mz/Dr/Prof.)"); $form->fep("width=10"); $form->fe('text', "FirstName", "First Name"); $form->fep("width=30,required=true"); $form->fe('text', "Initials", "Initials"); $form->fep("width=5"); $form->fe('text', "FamilyName", "Family Name", 30); $form->fep("width=30,required=true"); $form->fe('textarea', "Address", "Address"); $form->fep("width=30,lines=5"); $form->fe('text', "TownCity", "Town or City"); $form->fep("width=20"); $form->fe('text', "PostCode", "Post Code"); $form->fep("width=10, maxLength=10, maxChar=10"); $form->fe('text', "County", "County"); $form->fep("width=30"); if ($creating) { $form->fe("submit", "submit", "Next"); } else { $form->fe("submit", "submit", "Save"); } $return = ''; if ($form->processForm($_POST)) { if (!$form->error) { // update database $query = $form->querySave(true); $where = array("UserId" => $this->id); $this->db->update($this->cfg->userMiscTable, $form->saveFields, $where, "SSP user admin: Saving misc member data"); if ($reDisplay) { $form->tda("saved"); $return = $form->create(true); } else { $return = true; } } else { $return = $form->create(true); } } else { $query = $form->querySelect(); $where = array("UserId" => $this->id); $dataUpdate = $this->db->get($this->cfg->userMiscTable, $where, "SSP user admin: Getting User Misc data for update"); $form->data = get_object_vars($dataUpdate); $return = $form->create(true); } return $return; }
/** * keeps a rolling record of the history */ private function pageHistory() { $currentPage = SSP_Path(); // exit if in no history page specified for this instance if (count($this->config->noHistoryPages) > 0) { foreach ($this->config->noHistoryPages as $page) { if (strpos($currentPage, $page) !== false) { return; } } } // exit if in no history page specified foreach (self::$noHistoryOnPages as $page) { if (strpos($currentPage, $page) !== false) { return; } } // initialise SSP session save variables if not existing if (!isset($_SESSION["SSP_currentPage"])) { $_SESSION["SSP_currentPage"] = ""; $_SESSION["SSP_previousPage"] = ""; $_SESSION["SSP_thirdPage"] = ""; $_SESSION["SSP_userFault"] = ""; } // Get current page URL, and save last one. $_SESSION["SSP_thirdPage"] = $_SESSION["SSP_previousPage"]; $_SESSION["SSP_previousPage"] = $_SESSION["SSP_currentPage"]; // save current url to session vars. $_SESSION["SSP_currentPage"] = SSP_Path(true); }
function autoLogin($userTable) { // routine used in slave site to login remote user if (isset($_GET["remoteLoginToken"])) { $where = array("id" => $_GET["remoteLoginToken"], "userIp" => $_SERVER['REMOTE_ADDR']); $remoteLoginRecord = $this->db->get($this->sessionStatusTable, $where, "SSP Protect: gettting auto login record"); if ($remoteLoginRecord) { $where = array("UserName" => $remoteLoginRecord->userName); $userLoginInfo = $this->db->get($userTable, $where, "SSP Protect: getting user login information"); // create login record $login = new Logon($this, "", false, true); $login->logonCheck($userLoginInfo); session_write_close(); SSP_Divert(SSP_Path()); } } }
/** * creates a template for admin page displays * @param array $contentMain the pages content * @param string $tpl alternative template name * @param bool $createMenu create the main menu * @param bool $suppressLangSelect - suppress the language selection dropdown * @return Template main template */ function tpl($contentMain, $tpl = "", $createMenu = true, $suppressLangSelect = false) { // default to the main template if not other template not supplied if ($tpl != "") { $template = $tpl; } else { $template = $this->template; } // if the content suppied is just a string use it as the page title if (is_string($contentMain)) { $temp = $contentMain; $contentMain = array(); $contentMain["title"] = $temp; } // build the page title from the supplied segments if (count($this->pageTitleSegments)) { if ($this->session->isTranslate()) { foreach ($this->pageTitleSegments as $key => $titlePart) { $this->pageTitleSegments[$key] = $this->session->t($titlePart); } } $contentMain["title"] = $this->session->t($this->cfg->siteName) . $this->pageTitleSeperator . implode($this->pageTitleSeperator, $this->pageTitleSegments); } else { $contentMain["title"] = $this->session->t($this->cfg->siteName); } // add paths to various useful areas $contentMain["pathSite"] = $this->cfg->pathSite; $contentMain["pathAdmin"] = $this->cfg->adminDir; // create the language selection if ($this->cfg->translate and !$suppressLangSelect) { $formTemplate = array('<form action="{formAction}" method="post" id="languageSelectionform">', '{languageDropdown}', '{formHidden}', '</form>'); $form = new sfc\Form(SSP_Path(true), 'notable', 'languageSelect'); $form->translateDisable = true; $form->checkToken = false; $form->errorAutoFormDisplay = false; $form->formSubmitVar = 'languageSelectionformToken'; $form->tplf = new Template("", $formTemplate); $languages = $this->session->getLanguages(); $dropdownInformation = array(); foreach ($languages as $lang => $languageInfo) { $dropdownInformation[$lang] = array('text' => $languageInfo['description'], 'dir' => $languageInfo['dir'], 'class' => 'lang_' . $lang, 'style' => 'background-image: url(/sspadmin/images/flag_' . $lang . '.png);'); } $form->fe('select', 'languageDropdown', '', $dropdownInformation); $form->fep('deflt = ' . Protect::$tranlator->getLanguage()); $form->setParam('script', 'onChange="this.form.submit()"'); if ($form->processForm($_POST)) { if (!$form->error) { $this->session->lang = $form->getField('languageDropdown'); session_write_close(); //echo 'code '. $_SESSION['SSP_currentLanguageCode']; SSP_Divert(SSP_Path(true)); } } $contentMain['languageSelectForm'] = $form->create(); } if ($createMenu) { // generate main menu // highlight a main menu item if (isset($contentMain["mainSection"])) { $section = $contentMain["mainSection"]; } else { $section = ""; } $url = $_SERVER['REQUEST_URI']; $menu = new MenuGen(); $menu->add($this->cfg->adminDir . 'useradmin/info/' . $this->session->userId, $this->session->t("User Details"), strpos($url, "useradmin") !== false); $menu->add($this->cfg->adminDir . 'adminusercreation', $this->session->t("New User"), strpos($url, "adminusercreation") !== false); $menu->add($this->cfg->userLister, $this->session->t("List Users"), $url === "/sspadmin/" or $url === '/sspadmin/filterChange' or $url === '/sspadmin/filterNormal' or $url === '/sspadmin/filterAdminPending'); $menu->add($this->cfg->siteRoot, $this->session->t("Home")); $menu->add($this->cfg->logoffScript, $this->session->t("Log off")); $contentMain["mainMenu"] = $menu->cMenu(); } else { $contentMain["mainMenu"] = ""; } if (!isset($contentMain["menu"])) { $contentMain["menu"] = ""; } if ($this->cfg->enableSetup === true) { $contentMain['showDisableSetupText'] = true; } $tpl = new Template($contentMain, $template, false); return $tpl; }
/** * Delete a user * @param type $userId * @return string */ public function deleteUser($userId) { // check for valid user id, ie. hex $check = new \w34u\ssp\CheckData(); if ($check->check('hex', $userId) !== 0) { SSP_Divert($this->cfg->totalAdminScript); } // delete a user, not the current if (strcasecmp($userId, $this->session->userId) != 0) { if (isset($_POST["deleteUser"])) { $where = array("UserId" => $userId); $this->db->delete($this->cfg->userMiscTable, $where, "SSP Admin: deleting user misc data"); $this->db->delete($this->cfg->userTable, $where, "SSP Admin: deleting user login data"); SSP_Divert($this->cfg->totalAdminScript); } elseif (isset($_POST["preserveUser"])) { SSP_Divert($this->cfg->totalAdminScript); } else { // prompt to delete user $where = array("UserId" => $userId); $user = $this->db->get($this->cfg->userMiscTable, $where, "SSP Admin: Getting data to prompt for user delete"); if ($user) { $content = get_object_vars($user); $content["path"] = SSP_Path(); $page = new Template($content, "userListerDeletePrompt.tpl", false); $mainContent = array(); $mainContent["title"] = " - delete user " . $user->FirstName . " " . $user->FamilyName; $mainContent["content"] = $page->output(); $tpl = $this->tpl($mainContent); return $tpl->output(); } else { SSP_Divert($this->cfg->totalAdminScript); } } } }