Example #1
0
 protected function runAction($action)
 {
     switch ($action) {
         case 'view':
             return !is_null($id = $this->fromGetOrPost()) && $this->actionView($id);
         case 'browse':
             $conditions = $this->default_conditions;
             // Merge all browsable fields for this privilege level
             $browsable = array();
             for ($n = $this->privilege; $n > TIP_PRIVILEGE_INVALID; --$n) {
                 if (array_key_exists($n, $this->browsable_fields)) {
                     $browsable = array_merge($browsable, $this->browsable_fields[$n]);
                 }
             }
             // Build a query for every GETS matching the $browsable array
             // and which has a corrispondence in the data structure
             $fields = $this->data->getFields();
             foreach ($browsable as $id) {
                 $get = $id == $this->browse_field ? 'id' : $id;
                 if (array_key_exists($get, $_GET) && !is_null($type = $this->data->getFieldType($id))) {
                     $conditions[$id] = TIP::getGet($get, $type);
                 }
             }
             // Global browsing is enabled only if there is the special
             // '__ALL__' id in the browsable fields
             if (empty($conditions) && !in_array('__ALL__', $browsable)) {
                 TIP::notifyError('denied');
                 return false;
             }
             isset($conditions) || ($conditions = '');
             return $this->actionBrowse($conditions);
         case 'search':
             return !is_null($pattern = $this->fromGetOrPost('id', 'string')) && $this->actionSearch($pattern);
     }
     return null;
 }
Example #2
0
 protected function runManagerAction($action)
 {
     switch ($action) {
         case 'phpinfo':
             ob_start();
             phpinfo();
             $this->content .= ob_get_clean();
             return true;
         case 'clear':
             if (is_null($dir = TIP::getGet('id', 'string'))) {
                 TIP::warning("GET not found ({$id})");
                 TIP::notifyError('noparams');
                 return false;
             }
             $dir = TIP::buildDataPath(urldecode($dir));
             TIP::removeDir($dir, false);
             TIP::notifyInfo('done');
             return true;
     }
     return null;
 }
Example #3
0
 /**
  * Perform a vote action
  *
  * Runs the 'vote_template' template to get a confirmation on the vote and
  * adds the vote if confirmed.
  *
  * @param  int  $id     The poll id
  * @param  int  $answer The answer id
  * @return bool         true on success or false on errors
  */
 protected function actionVote($id, $answer)
 {
     $expiration = @HTTP_Session2::get($this->id . '.expiration');
     $voting = @HTTP_Session2::get($this->id . '.voting');
     if ($voting && time() < $expiration) {
         TIP::notifyError('double');
         return false;
     }
     if (is_null($row =& $this->fromRow($id, false))) {
         return false;
     }
     if (is_null($answer_label = $this->getField('answer' . $answer))) {
         TIP::notifyError('wrongparams');
         $this->endView();
         return false;
     }
     if (@TIP::getGet('process', 'int') == 1) {
         if (!$voting) {
             TIP::notifyError('nocookies');
             $this->endView();
             return false;
         }
         $old_row = $row;
         ++$row['votes' . $answer];
         $this->_onDataRow($row);
         $this->data->updateRow($row, $old_row);
         HTTP_Session2::set($this->id . '.voting', false);
         HTTP_Session2::set($this->id . '.expiration', strtotime($this->expiration));
         $this->appendToPage($this->view_template);
     } else {
         HTTP_Session2::set($this->id . '.voting', true);
         $this->appendToPage($this->vote_template);
     }
     $this->endView();
     return true;
 }
Example #4
0
 private function _validate()
 {
     if ($this->action == TIP_FORM_ACTION_DELETE || $this->action == TIP_FORM_ACTION_CUSTOM) {
         // Special case: GET driven form
         $this->_form->freeze();
         return TIP::getGet('process', 'int') == 1;
     }
     // Add element and form rules
     isset($this->validator) && $this->_form->addFormRule($this->validator);
     foreach (array_keys($this->fields) as $id) {
         if ($this->_form->elementExists($id)) {
             $this->_addGuessedRules($id);
             $this->_addCustomRules($id);
         }
     }
     $stage_id = $this->id . '.stage';
     $last_stage = HTTP_Session2::get($stage_id);
     if (!$this->_form->isSubmitted() || isset($last_stage) && $last_stage < $this->_stage) {
         HTTP_Session2::set($stage_id, $this->_stage);
         $valid = false;
     } elseif (is_null($last_stage)) {
         // No last stage defined
         TIP::notifyError('double');
         $valid = null;
     } else {
         // Validation
         $this->_form->applyFilter('__ALL__', array('TIP', 'extendedTrim'));
         $valid = $this->_form->validate();
     }
     // Perform uploads (if needed)
     if (is_callable(array('HTML_QuickForm_attachment', 'doUploads'))) {
         HTML_QuickForm_attachment::doUploads($this->_form);
     }
     return $valid;
 }
Example #5
0
 /**
  * Get the value of a pair throught a "request" interface
  *
  * This method is usually used by the template engine interface methods
  * (the tag... functions) to access any pair information available
  * in the TIP system.
  *
  * A request can get the value of an item, a get, a post or a localized
  * text: the type of the request is obtained parsing the $request token.
  * Specify <code>item[...]</code> for items, <code>get[...]</code> for
  * gets, <code>post[...]</code> for posts and <code>locale[...]</code> for
  * localized text, specifying the id in place of the ellipsize.
  *
  * If no type is specified (that is, $request is directly an identifier),
  * the system will expand it in <code>item[...]</code>.
  * This means <code>getRequest('name')</code> is logically equivalent to
  * <code>getRequest('item[name]')</code>.
  *
  * @param string $request The item id
  * @return mixed|null The requested value or null if the request is invalid
  */
 protected function getRequest($request)
 {
     $open_brace = strpos($request, '[');
     if ($open_brace === false) {
         $type = 'item';
         $id = $request;
     } else {
         $close_brace = strrpos($request, ']');
         if ($close_brace === false || $close_brace < $open_brace) {
             return null;
         }
         $type = strtolower(trim(substr($request, 0, $open_brace)));
         $id = substr($request, $open_brace + 1, $close_brace - $open_brace - 1);
     }
     switch ($type) {
         case 'item':
             return $this->getItem($id);
         case 'get':
             return TIP::getGet($id, 'string');
         case 'post':
             return TIP::getPost($id, 'string');
         case 'locale':
             return $this->getLocale($id);
         case 'label':
             if (strpos('.', $id) > 0) {
                 return TIP::getLocale($id);
             } else {
                 return $this->getLocale('label.' . $id);
             }
     }
     return null;
 }
Example #6
0
 /**
  * Perform an add action
  *
  * Overrides the default add action, showing the conditions to accept
  * before registering a new user and performing the autologin (if needed).
  *
  * @param  mixed $id      The identifier of the row to duplicate
  * @param  array $options Options to pass to the form() call
  * @return bool           true on success or false on errors
  */
 protected function actionAdd($id = null, $options = array())
 {
     if (TIP::getGet('accept', 'int') == 1) {
         $this->appendToPage($this->conditions_template);
         return true;
     }
     // Merge the argument options with the configuration options, if found
     // The argument options have higher priority...
     if (@is_array($this->form_options['add'])) {
         $options = array_merge($this->form_options['add'], $options);
     }
     TIP::arrayDefault($options, 'on_process', array(&$this, '_onAdd'));
     $processed = $this->form(TIP_FORM_ACTION_ADD, $id, $options);
     if (is_null($processed)) {
         return false;
     } elseif (!$processed) {
         return true;
     }
     if (isset($this->keys['CID'])) {
         // User added by an administrator
         return true;
     }
     // User added anonymously: autologin
     if (!is_null($id = $this->data->getLastId()) && !is_null($filter = $this->data->rowFilter($id)) && !is_null($view = $this->startDataView($filter)) && !is_null($this->_row = $view->current())) {
         $this->login();
     }
     return true;
 }
Example #7
0
 protected function runAction($action)
 {
     switch ($action) {
         case 'browse':
             if (is_null($id = TIP::getGet('id', 'string'))) {
                 TIP::warning('GET not found (id)');
                 TIP::notifyError('noparams');
                 return false;
             }
             return $this->actionBrowse($id);
     }
     return null;
 }