/** * Output an object creation form and process its input. * * @static * @param smdoc $foowd Reference to the foowd environment object. * @param string className The name of the class. */ function class_create(&$foowd, $className) { $foowd->track('foowd_text_plain->class_create'); include_once INPUT_DIR . 'input.querystring.php'; include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.textbox.php'; include_once INPUT_DIR . 'input.textarea.php'; $queryTitle = new input_querystring('title', REGEX_TITLE, NULL); $createForm = new input_form('createForm', NULL, SQ_POST, _("Create"), NULL); $createTitle = new input_textbox('createTitle', REGEX_TITLE, $queryTitle->value, 'Object Title'); $createBody = new input_textarea('createBody'); if ($createForm->submitted() && $createTitle->wasSet && $createTitle->wasValid && $createTitle->value != '') { // Ensure unique title $oid = NULL; if (!$foowd->database->isTitleUnique($createTitle->value, $foowd->user->workspaceid, $oid, NULL, FALSE)) { $result = 1; } else { $object =& new $className($foowd, $createTitle->value, $createBody->value); if ($object->objectid != 0 && $object->save($foowd)) { $result = 0; } else { $result = 2; } // error } } else { $result = -1; } switch ($result) { case 0: $_SESSION['ok'] = OBJECT_CREATE_OK; $uri_arr['classid'] = $object->classid; $uri_arr['objectid'] = $object->objectid; $foowd->loc_forward(getURI($uri_arr, FALSE)); exit; case 1: $foowd->template->assign('failure', OBJECT_DUPLICATE_TITLE); $createTitle->wasValid = FALSE; break; case 2: $foowd->template->assign('failure', OBJECT_CREATE_FAILED); break; default: $foowd->template->assign('failure', FORM_FILL_FIELDS); } $createForm->addObject($createTitle); $createForm->addObject($createBody); $foowd->template->assign_by_ref('form', $createForm); $foowd->track(); }
/** * Output an edit form and process its input * @global array Specifies default list of categories */ function class_create(&$foowd, $className) { global $NEWS_CATEGORIES; $foowd->track('smdoc_news->class_create'); include_once INPUT_DIR . 'input.querystring.php'; include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.textbox.php'; include_once INPUT_DIR . 'input.textarea.php'; include_once INPUT_DIR . 'input.dropdown.php'; $queryTitle = new input_querystring('title', REGEX_TITLE, NULL); $createForm = new input_form('createForm', NULL, SQ_POST, _("Create"), NULL); $createTitle = new input_textbox('createTitle', REGEX_TITLE, $queryTitle->value, 'Title', TRUE); $createBody = new input_textarea('createBody', NULL, '', 'Extended', 2048); $createSummary = new input_textarea('createSummary', NULL, '', 'Summary', 255); $category = new input_dropdown('createCategory', NULL, $NEWS_CATEGORIES, 'Category', TRUE); $result = 0; if ($createForm->submitted() && $createTitle->wasSet && $createTitle->wasValid && $createSummary->wasSet && $createSummary->wasValid && $createTitle->value != '') { $object =& new $className($foowd, $createTitle->value, $createSummary->value, $createBody->value, $category->value); if ($object->objectid != 0 && $object->save($foowd)) { $result = 1; } else { $result = 2; } // error } switch ($result) { case 1: $_SESSION['ok'] = OBJECT_CREATE_OK; $uri_arr['classid'] = $object->classid; $uri_arr['objectid'] = $object->objectid; $foowd->loc_forward(getURI($uri_arr, FALSE)); exit; case 2: $foowd->template->assign('failure', OBJECT_CREATE_FAILED); break; default: $foowd->template->assign('failure', FORM_FILL_FIELDS); } $createForm->addObject($createTitle); $createForm->addObject($createSummary); $createForm->addObject($createBody); $createForm->addObject($category); $foowd->template->assign_by_ref('form', $createForm); $foowd->track(); }
/** * Display the import workspace form and process its input. */ function method_import() { $this->foowd->track('foowd_workspace->method_import'); include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.file.php'; $importForm = new input_form('importForm', NULL, SQ_POST, _("Import"), NULL); $importFile = new input_file('importFile', _("Import file") . ':', NULL, getConstOrDefault('INPUT_FILE_SIZE_MAX', 2097152)); if ($importForm->submitted()) { $result = $this->import($importFile); if ($result == 0) { $this->foowd->template->assign('success', TRUE); $this->foowd->template->assign('objectid', $this->objectid); $this->foowd->template->assign('classid', $this->classid); } else { $this->foowd->template->assign('success', FALSE); $this->foowd->template->assign('error', $result); } } else { $importForm->addObject($importFile); $this->foowd->template->assign_by_ref('form', $importForm); } $this->foowd->track(); }
/** * Output a list of all known short names * * Values set in template: * + shortlist - below * + addForm - Form for adding a new shortname * + deleteForm - Form for deleting shortnames * * Sample contents of $t['shortlist']: * <pre> * array ( * shortname => array ( * 'objectid' => 8894324, * 'classid' => 9321833, * 'title' => 'Some page title', * 'name_delete' => checkbox for deletion of shortname * ) * ) * </pre> * * @static * @param smdoc $foowd Reference to the foowd environment object. * @param string $className The name of the class. */ function class_list(&$foowd, $className) { $foowd->track('smdoc_name_lookup->class_list'); include_once INPUT_DIR . 'input.textbox.php'; include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.checkbox.php'; $shortList = array(); $lookup =& smdoc_name_lookup::getInstance($foowd); /* * Create form for clearing short names */ $deleteForm = new input_form('deleteForm', NULL, SQ_POST, _("Delete Short Names")); if (!empty($lookup->shortNames)) { foreach ($lookup->shortNames as $idx => $value) { if (is_string($idx)) { $elem = $value; $deleteBox = new input_checkbox($idx, $deleteForm, FALSE, 'Delete'); if ($deleteForm->submitted() && $deleteBox->checked) { $lookup->deleteShortName($idx); unset($elem); } else { // Add box to form and array $deleteForm->addObject($deleteBox); $elem['name_delete'] =& $deleteForm->objects[$idx]; } if (isset($elem)) { $shortList[$idx] = $elem; } } } } $foowd->template->assign_by_ref('deleteForm', $deleteForm); $foowd->template->assign('shortList', $shortList); $foowd->track(); }
/** * Edit members of particular group * * Values set in template: * + memberlist - below * + groupname - name of group being modified * + deleteForm - Form for deleting members * * Sample contents of $t['memberlist']: * <pre> * array ( * 0 => array ( * 'title' => 'Username' * 'objectid' => 1287432 * 'member_delete' => checkbox for deletion from group * ) * ) * </pre> * * @static * @global array Specifies table information for user persistance. * @param smdoc $foowd Reference to the foowd environment object. * @param string className The name of the class. */ function class_edit(&$foowd, $className) { $foowd->track('smdoc_group->class_edit'); include_once INPUT_DIR . 'input.querystring.php'; include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.checkbox.php'; $id_q = new input_querystring('id', REGEX_TITLE, NULL); if (empty($id_q->value)) { $_SESSION['error'] = OBJECT_NOT_FOUND; $foowd->loc_forward(getURI(NULL, FALSE)); exit; } $group = $id_q->value; global $GROUP_USER_SOURCE; global $USER_SOURCE; /* * Set up combined source for JOIN query */ $source['table'] = $USER_SOURCE['table'] . ', ' . $GROUP_USER_SOURCE['table']; $source['table_create'] = NULL; // Select objectid, and title from the user table $index[] = $USER_SOURCE['table'] . '.objectid AS objectid'; $index[] = $USER_SOURCE['table'] . '.title AS title'; // Select only those records that match the current group $where[$GROUP_USER_SOURCE['table'] . '.title'] = $group; // and that match object id's between the user table and the group table $where['match']['index'] = $GROUP_USER_SOURCE['table'] . '.objectid'; $where['match']['op'] = '='; $where['match']['field'] = $USER_SOURCE['table'] . '.objectid'; // order by user title $order = $USER_SOURCE['table'] . '.title'; // Fetch users belonging to specified group, order by user name, // no limit, only fetch array, and don't bother with workspaces. $members =& $foowd->getObjList($index, $source, $where, $order, NULL, FALSE, FALSE); $deleteForm = new input_form('memberDeleteForm', NULL, SQ_POST, _("Delete Group Member")); if (!empty($members)) { foreach ($members as $idx => $userArray) { $deleteBox = new input_checkbox($userArray['objectid'], $deleteForm, FALSE, 'Delete'); if ($deleteForm->submitted() && $deleteBox->checked) { $foowd->groups->removeUser($userArray['objectid'], $group); $user =& $foowd->getObj(array('objectid' => $userArray['objectid'], 'classid' => USER_CLASS_ID)); if ($user) { $user->removeFromGroup($group); } unset($members[$idx]); } else { // Add box to form and array $deleteForm->addObject($deleteBox); $members[$idx]['member_delete'] =& $deleteForm->objects[$userArray['objectid']]; } } } $foowd->template->assign_by_ref('memberlist', $members); $foowd->template->assign_by_ref('deleteForm', $deleteForm); $foowd->template->assign('groupname', $foowd->groups->getDisplayName($group)); $foowd->track(); }
/** * Output the object clone form and handle its input. * * @access protected */ function method_clone() { $this->foowd->track('foowd_object->method_clone'); include_once INPUT_DIR . 'input.form.php'; include_once INPUT_DIR . 'input.textbox.php'; include_once INPUT_DIR . 'input.dropdown.php'; include_once INPUT_DIR . 'input.checkbox.php'; $cloneForm = new input_form('cloneForm', NULL, SQ_POST); $cloneTitle = new input_textbox('cloneTitle', REGEX_TITLE, $this->title, 'Clone Title'); $cloneObjectId = new input_checkbox('cloneId', $cloneForm, FALSE, 'New Object Translation'); $cloneWorkspace = new input_dropdown('workspaceDropdown', NULL, $this->getWorkspaceList()); $newWorkspace = $cloneWorkspace->value; if ($cloneForm->submitted()) { $rc = $this->clone($cloneTitle->value, $newWorkspace, $cloneObjectId->checked); switch ($rc) { case 1: $_SESSION['ok'] = OBJECT_CREATE_OK; $uri_arr['objectid'] = $this->objectid; $uri_arr['classid'] = $this->classid; $this->foowd->loc_forward(getURI($uri_arr, FALSE)); exit; case -1: $this->foowd->template->assign('failure', OBJECT_DUPLICATE_TITLE); $cloneTitle->wasValid = 0; break; case -3: $this->foowd->template->assign('failure', OBJECT_DUPLICATE_TITLE); default: case -2: $this->foowd->template->assign('failure', OBJECT_CREATE_FAILED); break; } } $cloneForm->addObject($cloneTitle); $cloneForm->addObject($cloneWorkspace); $cloneForm->addObject($cloneObjectId); $this->foowd->template->assign_by_ref('form', $cloneForm); $this->foowd->track(); }
/** * Output a login form and process its input. * * @static * @param smdoc $foowd Reference to the foowd environment object. * @param string className The name of the class. */ function class_login(&$foowd, $className) { $foowd->track('base_user->class_login'); include_once INPUT_DIR . 'input.textbox.php'; include_once INPUT_DIR . 'input.form.php'; $usernameQuery = new input_querystring('username', REGEX_TITLE, ''); $loginUsername = new input_textbox('loginUsername', REGEX_TITLE, $usernameQuery->value, 'Username'); $loginPassword = new input_passwordbox('loginPassword', REGEX_PASSWORD, NULL, 'Password'); $loginForm = new input_form('loginForm', NULL, SQ_POST, _("Log In"), NULL); $loginForm->addObject($loginUsername); $loginForm->addObject($loginPassword); if ($loginForm->submitted()) { $result = call_user_func(array($className, 'login'), $foowd, $loginUsername->value, $loginPassword->value); } else { $result = -1; } switch ($result) { case 0: case 5: $_SESSION['ok'] = $result == 0 ? USER_LOGIN_OK : USER_LOGIN_PREV; $uri_arr['objectid'] = $foowd->user->objectid; $uri_arr['classid'] = USER_CLASS_ID; $url = getURI($uri_arr, FALSE); $foowd->loc_forward($url); exit; case -1: $foowd->template->assign('failure', FORM_FILL_FIELDS); break; case 2: case 3: $foowd->template->assign('failure', _("User or password is incorrect.")); break; } $foowd->template->assign_by_ref('form', $loginForm); $foowd->track(); }