示例#1
0
 protected function postConstructor()
 {
     parent::postConstructor();
     // This must be called here (not in checkOptions()) to avoid
     // buildActionUri() call before application instantiation
     isset($this->fatal_uri) || ($this->fatal_uri = TIP::buildActionUri($this->id, 'fatal'));
     $this->keys['TITLE'] =& $this->title;
     $this->keys['DESCRIPTION'] =& $this->description;
     $this->keys['KEYWORDS'] =& $this->keywords;
     $this->keys['ROOT'] = TIP::getRoot();
     $this->keys['HOME'] = TIP::getHome();
     $this->keys['REFERER'] = '';
     // Set $_request
     $module = TIP::getGet('module', 'string');
     $action = TIP::getGet('action', 'string');
     if (!$action) {
         $module = TIP::getPost('module', 'string');
         $action = TIP::getPost('action', 'string');
     }
     $this->_request = array('uri' => @$_SERVER['REQUEST_URI'], 'module' => @strtolower($module), 'action' => @strtolower($action), 'id' => TIP::getGetOrPost('id', 'string'));
     $this->keys['REQUEST'] = $this->_request['uri'];
     $this->keys['MODULE'] = $this->_request['module'];
     $this->keys['ACTION'] = $this->_request['action'];
     // The ID global key will be assigned when the requested module
     // is loaded, so a type casting can be forced (because the id_type
     // of the module is known)
     $this->keys['ID'] = '';
     // Start the session
     TIP_AHAH || $this->_startSession();
 }
示例#2
0
 /**
  * Perform an add action
  *
  * Generates and executes a TIP_Form instance to add a new row.
  * The $id argument can be used to duplicate an existing row.
  * If left null, an empty row is used as default.
  *
  * If no $options are specified, the default behaviour is to render the
  * form in the page and to try to call actionView() on the result when the
  * form is validated.
  *
  * Notice also that $options['on_process'], if not specified, will be set
  * to the _onAdd() default callback.
  *
  * @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())
 {
     $primary_key = $this->data->getProperty('primary_key');
     // 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'));
     TIP::arrayDefault($options, 'follower', TIP::buildActionUri($this->id, 'view', '') . '{' . $primary_key . '}');
     $processed = $this->form(TIP_FORM_ACTION_ADD, $id, $options);
     if (is_null($processed)) {
         return false;
     } elseif (!$processed) {
         return true;
     }
     // Form validate: if 'valid_render' is set to nothing, try to
     // call actionView() on the newly appended row
     if (@$options['valid_render'] == TIP_FORM_RENDER_NOTHING) {
         return $this->actionView($this->data->getLastId());
     }
     return true;
 }
示例#3
0
 private function &_widgetLookup(&$field, $args)
 {
     $id = $field['id'];
     $label = $this->getLocale('label.' . $id);
     $info = TIP::getLocale('comment.' . $id, $this->locale_prefix);
     if (empty($args)) {
         // Try to get the lookup module from the $cfg array
         global $cfg;
         foreach ($cfg as $module_id => &$module_options) {
             if (@$module_options['master'] == $this->id && end($module_options['type']) == 'hierarchy') {
                 $lookup_id = $module_id;
                 break;
             }
         }
     } else {
         // Explicitely defined in the widget args
         $lookup_id = $args;
     }
     // On lookup module not found, build a default one
     // by appending '_hierarchy' to this module id
     isset($lookup_id) || ($lookup_id = $this->id . '_hierarchy');
     ++$this->_tabindex;
     $element =& $this->_addElement('text', $id, array('size' => 8, 'maxlength' => 8));
     $element->setInfo($info);
     if ($this->json) {
         // Add JSON params, if needed
         $params = array('sWidget' => 'lookup', 'sUriView' => TIP::buildActionUri($lookup_id, 'view'));
         if (!is_null(TIP::getOption($lookup_id, 'search_field'))) {
             // Enable search URI
             $params['sUriSearch'] = TIP::buildActionUri($lookup_id, 'search');
         }
         $element->setComment(json_encode($params));
         // Enable AHAH interactivity
         $element->setAttribute('class', 'ahah');
     }
     return $element;
 }
示例#4
0
 /**
  * Perform an add action
  *
  * Overrides the default add action, assuring the 'browse_field' has a
  * valid value.
  *
  * @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, $options = array())
 {
     // Merge the argument before the parent actionAdd(), so also
     // the defaults here defined can be overriden in configuration
     if (isset($this->form_options['add'])) {
         $options = array_merge($this->form_options['add'], $options);
     }
     // Check for the default value of 'browse_field' (the parent id)
     if (!isset($options['defaults'], $options['defaults'][$this->browse_field])) {
         // Try to get the parent id from GET or POST
         if (is_null($parent_id = $this->fromGetOrPost($this->browse_field))) {
             return false;
         }
         $options['defaults'][$this->browse_field] = $parent_id;
     } else {
         $parent_id = $options['defaults'][$this->browse_field];
     }
     TIP::arrayDefault($options, 'follower', TIP::buildActionUri($this->master, 'view', $parent_id));
     return parent::actionAdd($id, $options);
 }
示例#5
0
 /**
  * Perform an edit action
  *
  * Overrides the default edit action, merging master and child
  * fields to build an unique form. The class field is frozen.
  *
  * @param  mixed $id      The identifier of the row to edit
  * @param  array $options Options to pass to the form() call
  * @return bool           true on success or false on errors
  */
 protected function actionEdit($id, $options = array())
 {
     $primary_key = $this->data->getProperty('primary_key');
     // Merge the argument options with the configuration options, if found
     // The argument options have higher priority...
     if (@is_array($this->form_options['edit'])) {
         $options = array_merge($this->form_options['edit'], $options);
     }
     // Populate "defaults" with master and child values
     if (is_null($row = $this->fromRow($id))) {
         return false;
     } elseif (@is_array($options['defaults'])) {
         $options['defaults'] = array_merge($row, $options['defaults']);
     } else {
         $options['defaults'] =& $row;
     }
     $options['type'] = array('module', 'form');
     $options['master'] =& $this;
     TIP::arrayDefault($options, 'action', TIP_FORM_ACTION_EDIT);
     TIP::arrayDefault($options, 'on_process', array(&$this, '_onEdit'));
     TIP::arrayDefault($options, 'follower', TIP::buildActionUri($this->id, 'view', '') . '{' . $primary_key . '}');
     TIP::arrayDefault($options, 'readonly', array($this->class_field));
     $form =& TIP_Type::singleton($options);
     $valid = $form->validate();
     // On edit, the child form is chained-up also if $valid==false:
     // this module was already retrieved by fromRow()
     $child =& $this->_getChildModule();
     if ($child === false) {
         // Errors on child module
         return false;
     } elseif ($child) {
         // Child module found and valid: chain-up the child form
         $valid = $form->validateAlso($child);
     }
     if ($valid) {
         $form->process();
     }
     return $form->render($valid);
 }
示例#6
0
 /**
  * Build an action URI by modify the current action
  *
  * In this case, anything different from null will be applied to the
  * current action. The $args array will be merged to the current one.
  *
  * @param  string $module The module name
  * @param  string $action The action to perform
  * @param  string $id     The subject of the action
  * @param  array  $args   Optional additional query arguments
  * @return string         The constructed URI
  */
 public static function modifyActionUri($module, $action, $id = null, $args = null)
 {
     $gets = array();
     foreach ($_GET as $get => $value) {
         switch ($get) {
             case 'module':
                 is_null($module) && ($module = $value);
                 break;
             case 'action':
                 is_null($action) && ($action = $value);
                 break;
             case 'id':
                 is_null($id) && ($id = $value);
                 break;
             default:
                 $gets[$get] = $value;
         }
     }
     isset($args) && ($gets = array_merge($gets, $args));
     return TIP::buildActionUri($module, $action, $id, $args);
 }