Ejemplo n.º 1
0
 protected function runAction($action)
 {
     switch ($action) {
         case 'fatal':
             return TIP::notifyError('fatal');
     }
     return null;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
    /**
     * Get the html code for the whole PicasaWeb album
     *
     * Renders all the photo included by this album.
     *
     * @return string|false  The string to render or false on errors
     */
    public function toHtmlAlbum()
    {
        static $cnt = 1;
        if (is_null($view =& $this->startDataView())) {
            TIP::notifyError('select');
            return false;
        }
        $rows =& $view->getProperty('rows');
        $output = '';
        $max_width = 0;
        $max_height = 0;
        $options = array('max-width' => &$max_width, 'max-height' => &$max_height);
        foreach ($rows as $row) {
            $output .= '  <li>' . self::_renderRow($row, $options) . '</li>';
        }
        if (empty($output)) {
            return false;
        }
        $id = 'Album' . $cnt;
        ++$cnt;
        $output = <<<EOT
<div class="caption" style="float: right">
<ul id="{$id}">
{$output}
</ul>
<p class="caption-title"><a id="{$id}-prev" href="#">« PRECEDENTE</a> <a id="{$id}-next" href="#">SEGUENTE »</a></p>
</div>
<script type="text/javascript">
    jQuery(function() {
        jQuery('#{$id}').ulslide({
            width: {$max_width},
            height: {$max_height},
            bprev: '#{$id}-prev',
            bnext: '#{$id}-next',
            axis: 'x'
        });
    });
</script>
EOT;
        return $output;
    }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * Add a comments form
  *
  * Allows to show an inline form in the middle of a page.
  *
  * If the form is validated, the result is rendered in the page. Also, the
  * cancel button in the invalidated form is removed (it is not useful for
  * inline forms). $params must contain the id of the master row.
  */
 protected function tagAdd($params)
 {
     if ($this->privilege < TIP_PRIVILEGE_UNTRUSTED) {
         // Privilege level too low: return empty rendering result
         return '';
     } elseif (empty($params)) {
         // No param id specified
         TIP::notifyError('noparams');
         return null;
     }
     // Check for default options defined in configuration
     if (isset($this->form_options['tagadd'])) {
         $options = $this->form_options['tagadd'];
     } else {
         $options = array();
     }
     $options['defaults'][$this->browse_field] = (int) $params;
     TIP::arrayDefault($options, 'buttons', TIP_FORM_BUTTON_SUBMIT);
     TIP::arrayDefault($options, 'invalid_render', TIP_FORM_RENDER_HERE);
     TIP::arrayDefault($options, 'valid_render', TIP_FORM_RENDER_IN_PAGE);
     ob_start();
     if ($this->actionAdd(null, $options)) {
         return ob_get_clean();
     }
     ob_end_clean();
     return null;
 }
Ejemplo n.º 7
0
 private function _updateCount($id, $offset)
 {
     if (empty($this->count_field)) {
         return true;
     }
     // Global query (probably cached)
     if (is_null($view =& $this->startDataView())) {
         TIP::notifyError('select');
         return false;
     }
     $rows =& $view->getProperty('rows');
     $this->endView();
     if (!isset($rows[$id])) {
         TIP::warning("row not found ({$id})");
         TIP::notifyError('notfound');
         return false;
     }
     $old_row =& $rows[$id];
     $row[$this->count_field] = $old_row[$this->count_field] + $offset;
     if (!$this->data->updateRow($row, $old_row)) {
         TIP::notifyError('update');
         return false;
     }
     $old_row[$this->count_field] += $offset;
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Update the history on a master row deletion
  *
  * Updates the linked list by skipping the deleted history row
  * before deleting the row itsself.
  */
 public function _onMasterDelete(&$row, $old_row)
 {
     $master_data =& $this->master->getProperty('data');
     $id = $row[$master_data->getProperty('primary_key')];
     $engine =& $this->data->getProperty('engine');
     $query = $this->data->rowFilter($id);
     // Start the transaction here to avoid race conditions
     if (!$engine->startTransaction()) {
         // This error must be caught here to avoid the rollback
         return false;
     }
     // Get the current version row
     if (!($view =& $this->startDataView($query))) {
         $engine->endTransaction(false);
         return false;
     }
     $current_row = $view->current();
     $this->endView();
     if (empty($current_row)) {
         // No history found: return operation done (just in case...)
         return $engine->endTransaction(true);
     }
     // Get the previous version row
     $query = $this->data->filter($this->next_field, $id);
     if (!($view =& $this->startDataView($query))) {
         $engine->endTransaction(false);
         TIP::warning("no row to delete ({$id})");
         TIP::notifyError('notfound');
         return false;
     }
     $previous_row = $view->current();
     $this->endView();
     // Perform the operations
     $done = $this->data->deleteRow($id);
     if ($done && is_array($previous_row)) {
         // Update the next_field of previous_row
         $new_previous_row = $previous_row;
         $new_previous_row[$this->next_field] = $current_row[$this->next_field];
         $done = $this->data->updateRow($new_previous_row, $previous_row);
     }
     // Close the transaction
     $done = $engine->endTransaction($done) && $done;
     return $done;
 }
Ejemplo n.º 9
0
 /**
  * Called by the login form to validate user and password
  * @param  array      $row The data row
  * @return true|array      true on success or an associative array in the
  *                         form array(field => error_message)
  */
 public function _checkLogin($row)
 {
     $filter = $this->data->filter('user', $row['user']) . ' LIMIT 1';
     if (is_null($view =& $this->startDataView($filter))) {
         TIP::notifyError('select');
         return array('user' => TIP::getLocale('error.select', 'notify', null, false));
     }
     if (is_null($this->_row = $view->current())) {
         $this->endView();
         return array('user' => $this->getLocale('notfound'));
     }
     if ($this->_row['password'] != $row['password']) {
         $this->endView();
         $this->_row = null;
         return array('password' => $this->getLocale('wrongpassword'));
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Application errors
  *
  * Logs the specified warning message (for developement purpose only)
  * using the TIP_Logger instance, if present.
  *
  * The difference between warnings and errors is that errors generate a
  * notifyError() call while warnings don't.
  *
  * @param string $message A custom message
  */
 public static function error($message)
 {
     TIP::log('ERROR', $message);
     TIP::notifyError();
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 private function _getUser()
 {
     if (!array_key_exists('UID', $this->keys)) {
         if (!is_null($user = $this->fromGet('id')) && $this->privilege < TIP_PRIVILEGE_MANAGER && $user == TIP::getUserId()) {
             TIP::notifyError('denied');
             $user = null;
         }
         $this->keys['UID'] = $user;
     }
     return $this->keys['UID'];
 }