/**
  * Output an edit form and process its input
  */
 function method_edit()
 {
     $this->foowd->track('smdoc_news->method_edit');
     include_once INPUT_DIR . 'input.form.php';
     include_once INPUT_DIR . 'input.textbox.php';
     include_once INPUT_DIR . 'input.textarea.php';
     $editForm = new input_form('editForm', NULL, 'POST', FORM_DEFAULT_SUBMIT, NULL);
     $editForm->addSubmitButton('preview', FORM_DEFAULT_PREVIEW);
     $editTitle = new input_textbox('editTitle', REGEX_TITLE, $this->title, 'Title', TRUE);
     $editForm->addObject($editTitle);
     $editCollision = new input_hiddenbox('editCollision', REGEX_DATETIME, time());
     $editForm->addObject($editCollision);
     $editSummary = new input_textarea('editSummary', NULL, $this->summary, 'Summary', 255);
     $editForm->addObject($editSummary);
     $editArea = new input_textarea('editArea', NULL, $this->body, 'Extended', 2048);
     $editForm->addObject($editArea);
     $this->addCategories($editForm);
     $this->foowd->template->assign_by_ref('form', $editForm);
     if ($editForm->submitted()) {
         // No versioning for news items.
         $this->set('summary', $editSummary->value);
         $result = $this->edit($editArea->value, FALSE, $editCollision->value);
         switch ($result) {
             case 1:
                 $_SESSION['ok'] = OBJECT_UPDATE_OK;
                 $url['classid'] = $this->classid;
                 $url['objectid'] = $this->objectid;
                 $this->save();
                 $this->foowd->loc_forward(getURI($url));
                 break;
             case 2:
                 $this->foowd->template->assign('failure', OBJECT_UPDATE_COLLISION);
                 break;
             default:
                 $this->foowd->template->assign('failure', OBJECT_UPDATE_FAILED);
                 break;
         }
     } elseif ($editForm->otherSubmitted('preview')) {
         $this->foowd->template->assign('preview', $this->processContent($editArea->value));
     }
     $this->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 an edit form and process its input
  */
 function method_edit()
 {
     $this->foowd->track('foowd_text_plain->method_edit');
     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.checkbox.php';
     $editForm = new input_form('editForm', NULL, 'POST', FORM_DEFAULT_SUBMIT, NULL);
     $editForm->addSubmitButton('preview', FORM_DEFAULT_PREVIEW);
     $editCollision = new input_hiddenbox('editCollision', REGEX_DATETIME, time());
     $editForm->addObject($editCollision);
     $editArea = new input_textarea('editArea', NULL, $this->body, NULL);
     $editForm->addObject($editArea);
     // If author is same as last author and not anonymous,
     // ask if they want to make a new version, or just save changes to existing version
     $noNewVersion = new input_checkbox('noNewVersion', $editForm, TRUE, _("Save this as the previous version?"));
     if (isset($this->foowd->user->objectid) && $this->updatorid == $this->foowd->user->objectid) {
         $editForm->addObject($noNewVersion);
     }
     $this->foowd->template->assign_by_ref('form', $editForm);
     if ($editForm->submitted()) {
         // Edit will increment version if requested ($newVersion->checked),
         // And will store revised body in the object if no edit collision
         $result = $this->edit($editArea->value, !$noNewVersion->checked, $editCollision->value);
         switch ($result) {
             case 1:
                 $_SESSION['ok'] = OBJECT_UPDATE_OK;
                 $url = getURI(array('classid' => $this->classid, 'objectid' => $this->objectid), FALSE);
                 $this->save();
                 $this->foowd->loc_forward($url);
                 break;
             case 2:
                 $this->foowd->template->assign('failure', OBJECT_UPDATE_COLLISION);
                 break;
             default:
                 $this->foowd->template->assign('failure', OBJECT_UPDATE_FAILED);
                 break;
         }
     } elseif ($editForm->otherSubmitted('preview')) {
         $this->foowd->template->assign('preview', $this->processContent($editArea->value));
     }
     $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();
 }
 /**
  * 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_workspace->class_create');
     include_once INPUT_DIR . 'input.querystring.php';
     include_once INPUT_DIR . 'input.form.php';
     include_once INPUT_DIR . 'input.textbox.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');
     $createDescription = new input_textbox('createDescription', '/^.{1,1024}$/', NULL, 'Description', FALSE);
     $createIcon = new input_textbox('createIcon');
     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, $createDescription->value, $createIcon->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($createDescription);
     $foowd->template->assign_by_ref('form', $createForm);
     $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();
 }
Beispiel #7
0
 /**
  * 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();
 }
Beispiel #8
0
 /**
  * Output a fetch password 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_lostPassword(&$foowd, $className)
 {
     $foowd->track('base_user->class_lostPassword');
     include_once INPUT_DIR . 'input.querystring.php';
     include_once INPUT_DIR . 'input.textbox.php';
     include_once INPUT_DIR . 'input.form.php';
     $usernameQuery = new input_querystring('username', REGEX_TITLE, NULL);
     $idQuery = new input_querystring('id', '/[a-z0-9]{32}/', NULL);
     $lostUsername = new input_textbox('lostUsername', REGEX_TITLE, $usernameQuery->value, _("Username") . ':');
     $lostForm = new input_form('lostForm', NULL, 'POST', _("Retrieve Password"), NULL);
     $result = call_user_func(array($className, 'fetchPassword'), &$foowd, $className, $lostUsername->value, $usernameQuery->value, $idQuery->value);
     switch ($result) {
         case 0:
             // done nothing, display form
             $lostForm->addObject($lostUsername);
             $foowd->template->assign_by_ref('form', $lostForm);
             break;
         case 1:
             // stage 1 complete
             $foowd->template->assign('stage1', TRUE);
             break;
         case 2:
             // could not send e-mail, technical problem
             $foowd->template->assign('failure', 2);
             $foowd->template->assign('webmaster', $foowd->webmaster_email);
             break;
         case 3:
             // could not send e-mail, user does not have an e-mail address listed
             $foowd->template->assign('failure', 3);
             $foowd->template->assign('username', htmlspecialchars($lostUsername->value));
             $foowd->template->assign('webmaster', $foowd->webmaster_email);
             break;
         case 4:
             // could not send e-mail, user does not exist
             $foowd->template->assign('failure', 4);
             $foowd->template->assign('username', htmlspecialchars($lostUsername->value));
             break;
         case 5:
             // stage 2 complete
             $foowd->template->assign('stage2', TRUE);
             $foowd->template->assign('class', $className);
             $foowd->template->assign('username', $lostUsername->value);
             break;
         case 6:
             // could not change password, technical problem
             $foowd->template->assign('failure', 6);
             $foowd->template->assign('webmaster', $foowd->webmaster_email);
             break;
         case 7:
             // could not change password, id does not match
             $foowd->template->assign('failure', 7);
             $foowd->template->assign('webmaster', $foowd->webmaster_email);
             $foowd->template->assign('class', $className);
             $foowd->template->assign('username', $usernameQuery->value);
             break;
         case 8:
             // could not change password, could not find user
             $foowd->template->assign('failure', 8);
             $foowd->template->assign('webmaster', $foowd->webmaster_email);
             break;
     }
     $foowd->track();
 }