Esempio n. 1
0
 public function flag()
 {
     $key = new Key($this->key_id);
     $key->flag();
 }
Esempio n. 2
0
 /**
  * Constructs a view of this form and returns it in a string.
  *
  * This function will construct a view of this form whether in edit mode
  * or submission mode and return it in a string for display.
  *
  * @param  boolean $edit Whether the view is in edit mode or not.
  * @return mixed   A templated string on success, or a FALSE on failure.
  * @access public
  */
 function view($edit = FALSE, $error = null)
 {
     if ($this->isHidden() && !$edit || !$this->isSaved() && !Current_User::allow('phatform', 'edit_forms')) {
         return dgettext('phatform', 'This form is not available for viewing at this time.');
     }
     $GLOBALS['CNT_phatform']['title'] = $this->getLabel();
     /* Do some basic checks if we're not in edit mode */
     if (!$edit) {
         /* If this form is not anonymous and the user is not logged in, print message and bail */
         if (($this->_editData || !$this->_anonymous) && !Current_User::isLogged()) {
             return dgettext('phatform', 'You must be logged in to view this form!');
         }
         /* If this form is not multi submit and the user has filled out this for before,
            print message and bail */
         if (!$this->_editData && !$this->_multiSubmit && $this->hasSubmission()) {
             return dgettext('phatform', 'You have already filled out this form!');
         }
         if (!Current_User::isDeity() && Current_User::allow('phatform', 'user_forms_only')) {
             if (Current_User::getUsername() != $this->getOwner()) {
                 return dgettext('phatform', 'You only have permission to edit your own forms!');
             }
         }
     }
     /* Assume the PHAT position :) */
     if (!isset($this->_position)) {
         $this->_position = 0;
     }
     /* Setup limit for loop */
     if ($this->_position + $this->_pageLimit > sizeof($this->_elements)) {
         $limit = $this->_position + (sizeof($this->_elements) - $this->_position);
     } else {
         $limit = $this->_position + $this->_pageLimit;
     }
     /* Begin view template array */
     if ($this->currentPage() == 1) {
         $viewTags['BLURB0'] = PHPWS_Text::parseOutput($this->_blurb0, ENCODE_PARSED_TEXT, false, true);
         if (!$this->_saved) {
             $viewTags['WARNING'] = dgettext('phatform', 'The form must be saved before it is available to the public.');
         }
     }
     $formTags = array();
     /* If this form has elements, loop and add them to the form template array */
     if (is_array($this->_elements) && sizeof($this->_elements) > 0) {
         for ($i = $this->_position; $i < $limit; $i++) {
             $sectionTags = array();
             $elementInfo = explode(':', $this->_elements[$i]);
             $this->element = new $elementInfo[0]($elementInfo[1]);
             /* If user can edit data, populate for element with it */
             if (!$edit && $this->_editData && is_array($this->_userData)) {
                 if (isset($this->_userData[$this->element->getLabel()]) && $this->isSerialized($this->_userData[$this->element->getLabel()])) {
                     $value = unserialize(stripslashes($this->_userData[$this->element->getLabel()]));
                     $this->element->setValue($value);
                 } else {
                     $this->element->setValue($this->_userData[$this->element->getLabel()]);
                 }
             }
             /* Setup color for alternating rows in the section template */
             if (isset($flag) && $flag) {
                 $flag = FALSE;
             } else {
                 $sectionTags['BGCOLOR'] = ' class="bgcolor1" ';
                 $flag = TRUE;
             }
             /* Get view of the current element */
             $sectionTags['ELEMENT'] = $this->element->view();
             if ($this->_showElementNumbers) {
                 $sectionTags['ELEMENT'] = $i + 1 . '. ' . $sectionTags['ELEMENT'];
             }
             /* If in edit mode, show the element editor for the current element */
             if ($edit) {
                 $sectionTags['ELEMENT_NAME'] = PHPWS_Text::parseOutput($this->element->getLabel(), ENCODE_PARSED_TEXT, false, true);
                 $sectionTags['ELEMENT_EDITOR'] = $this->_elementEditor($i);
             }
             if (!isset($formTags['ELEMENTS'])) {
                 $formTags['ELEMENTS'] = PHPWS_Template::processTemplate($sectionTags, 'phatform', 'form/section.tpl');
             } else {
                 $formTags['ELEMENTS'] .= PHPWS_Template::processTemplate($sectionTags, 'phatform', 'form/section.tpl');
             }
         }
         /* If we are on last page...show the submit button */
         if (!$edit) {
             if ($this->currentPage() == $this->numPages()) {
                 if ($this->_editData && $this->currentPage() > 1) {
                     $formTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_Back');
                 }
                 if (PHATFORM_CAPTCHA && $this->_anonymous && !Current_User::isLogged()) {
                     PHPWS_Core::initCoreClass('Captcha.php');
                     $formTags['CAPTCHA'] = Captcha::get();
                 }
                 $formTags['SUBMIT_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Finish'), 'PHAT_Submit');
             } else {
                 if ($this->_editData && $this->currentPage() > 1) {
                     $formTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_Back');
                 }
                 $formTags['NEXT_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Next'), 'PHAT_Next');
             }
         }
         /* Check if we're in edit mode and set the phat man accordingly */
         if ($edit) {
             $hiddens['PHAT_FORM_OP'] = 'EditAction';
         } else {
             $hiddens['PHAT_FORM_OP'] = 'Action';
         }
         /* Actually load hidden variables into the elements array */
         $hiddens['module'] = 'phatform';
         foreach ($hiddens as $key => $value) {
             $eles[] = PHPWS_Form::formHidden($key, $value);
         }
         $elements[] = implode("\n", $eles);
         $elements[0] .= PHPWS_Template::processTemplate($formTags, 'phatform', 'form/form.tpl');
         $viewTags['FORM'] = PHPWS_Form::makeForm('PHAT_Form', 'index.php', $elements);
     }
     /* Check to see if we should show page numbers or not */
     if ($this->_showPageNumbers) {
         $viewTags['PAGE_NUMBER'] = sprintf(dgettext('phatform', 'Page %1$s of %2$s'), $this->currentPage(), $this->numPages());
     }
     /* If in edit mode, display the toolbar */
     if ($edit) {
         $viewTags['TOOLBAR'] = $this->_toolbar();
     }
     $key = new Key($this->_key_id);
     $key->flag();
     if ($error) {
         $viewTags['WARNING'] = $error->getMessage();
     }
     return PHPWS_Template::processTemplate($viewTags, 'phatform', 'form/view.tpl');
 }
Esempio n. 3
0
 /**
  * Displays the blog entry
  *
  * @param boolean edit       If true, show edit link
  * @param boolean summarized If true, this is a summarized entry
  */
 public function view($edit = true, $summarized = true)
 {
     if (!$this->id) {
         PHPWS_Core::errorPage(404);
     }
     $key = new Key($this->key_id);
     if (!$key->allowView() || !Blog_User::allowView()) {
         Current_User::requireLogin();
         return dgettext('blog', 'You do not have permission to view this entry.');
     }
     $template['TITLE'] = sprintf('<a href="%s" rel="bookmark">%s</a>', $this->getViewLink(true), $this->title);
     $template['TITLE_NO_LINK'] = $this->title;
     if ($this->publish_date > time()) {
         $template['UNPUBLISHED'] = dgettext('blog', 'Unpublished');
     } elseif ($this->expire_date && $this->expire_date < time()) {
         $template['UNPUBLISHED'] = dgettext('blog', 'Expired');
     }
     $template['LOCAL_DATE'] = $this->getPublishDate();
     $summary = $this->getSummary(true);
     $entry = $this->getEntry(true);
     if ($summarized) {
         if (empty($summary)) {
             $template['SUMMARY'] = PHPWS_Text::parseTag($entry);
         } else {
             if (!empty($entry)) {
                 $template['READ_MORE'] = PHPWS_Text::rewriteLink(Icon::get('chevron-circle-down') . '&nbsp;' . dgettext('blog', 'Read more'), 'blog', array('id' => $this->id), null, 'Read more of this entry', 'btn btn-default');
             }
             $template['SUMMARY'] = PHPWS_Text::parseTag($summary);
         }
     } else {
         $template['SUMMARY'] = PHPWS_Text::parseTag($summary);
         $template['ENTRY'] = PHPWS_Text::parseTag($entry);
     }
     $template['IMAGE'] = $this->getFile($this->thumbnail && $summarized);
     if ($edit && (Current_User::allow('blog', 'edit_blog', $this->id, 'entry') || Current_User::allow('blog', 'edit_blog') && $this->author_id == Current_User::getId())) {
         $vars['blog_id'] = $this->id;
         $vars['action'] = 'admin';
         $vars['command'] = 'edit';
         $template['EDIT_LINK'] = PHPWS_Text::secureLink(dgettext('blog', 'Edit'), 'blog', $vars);
         $template['EDIT_URI'] = PHPWS_Text::linkAddress('blog', $vars, true);
         if (!$summarized) {
             MiniAdmin::add('blog', array(PHPWS_Text::secureLink(dgettext('blog', 'Edit blog'), 'blog', $vars)));
         }
     }
     // Check setting for showing when the entry was posted
     if (PHPWS_Settings::get('blog', 'show_posted_by')) {
         $template['POSTED_BY'] = dgettext('blog', 'By');
         $template['AUTHOR'] = $this->author;
     }
     // Check settings for showing the author of the entry
     if (PHPWS_Settings::get('blog', 'show_posted_date')) {
         $template['PUBLISHED'] = dgettext('blog', 'Published');
         $template['POSTED_ON'] = dgettext('blog', 'Posted on');
         $template['PUBLISHED_DATE'] = $this->getPublishDateShort();
     }
     if ($summarized) {
         $view_tpl = 'view_list.tpl';
     } else {
         $template['COMMENT_SCRIPT'] = PHPWS_Settings::get('blog', 'comment_script');
         $key->flag();
         $view_tpl = 'view_full.tpl';
     }
     return PHPWS_Template::process($template, 'blog', $view_tpl);
 }