Example #1
0
 /**
  * Constructor.
  *
  * @param string $name Name of the attribute
  * @param int $flags Flags for this attribute
  * @param bool $generate Generate password (boolean)
  * @param array $restrictions
  */
 public function __construct($name, $flags = 0, $generate = false, $restrictions = [])
 {
     $flags = $flags | self::AF_HIDE_SEARCH;
     $this->m_generate = $generate;
     parent::__construct($name, $flags);
     $this->setRestrictions($restrictions);
 }
Example #2
0
 public function addFlag($flag)
 {
     parent::addFlag($flag);
     if ($this->hasFlag(self::AF_DUMMY_SHOW_LABEL)) {
         $this->removeFlag(self::AF_BLANK_LABEL);
     }
 }
Example #3
0
 /**
  * Constructor.
  *
  * @param string $name fieldset name
  * @param int $flags flags
  * @param string $template template string
  */
 public function __construct($name, $flags = 0, $template)
 {
     $flags = $flags | self::AF_NO_SORT | self::AF_HIDE_SEARCH;
     parent::__construct($name, $flags);
     $this->setTemplate($template);
     $this->setLoadType(self::NOLOAD);
     $this->setStorageType(self::NOSTORE);
 }
Example #4
0
 /**
  * Constructor.
  *
  * Options can be an array using the following format:
  * array('option_a', 'option_b' => 'option_b_details')
  *
  * The options can either be specified as value (by not specifying a key)
  * or as key in which case you need to specify an attribute name as
  * value of another attribute which renders the detail selection for the
  * given option.
  *
  * @param string $name attribute name
  * @param int $flags
  * @param string $options can either be an array of values or a key/value
  *                        array in which case the key is used for the
  *                        translation and value is the value which is saved
  *                        in the database
  * @param array $details allows you to specify attributes that should be
  *                        used for the detail selection for certain options
  *                        the key should be the option value and the value
  *                        should be the attribute name
  */
 public function __construct($name, $flags = 0, $options, $details)
 {
     parent::__construct($name, $flags);
     $this->m_options = isset($options[0]) ? array_combine($options, $options) : $options;
     // Cast single detail attributes to arrays
     foreach ($details as $value => $detail) {
         $this->m_details[$value] = (array) $detail;
     }
 }
Example #5
0
 /**
  * Returns a displayable string for this value.
  *
  * @param array $record The record to display
  * @param string $mode The display mode ("view" for viewpages, or "list"
  *                       for displaying in recordlists, "edit" for
  *                       displaying in editscreens, "add" for displaying in
  *                       add screens. "csv" for csv files. Applications can
  *                       use additional modes.
  *
  * @return string
  */
 public function display($record, $mode)
 {
     if ($mode == 'csv') {
         return parent::display($record, $mode);
     }
     if (isset($record[$this->fieldName()]) && $record[$this->fieldName()] != '') {
         return '<a href="mailto:' . $record[$this->fieldName()] . '">' . $record[$this->fieldName()] . '</a>';
     }
     return '';
 }
Example #6
0
 /**
  * Constructor.
  *
  * @param string $name The name of the attribute
  * @param int $flags The flags of this attribute
  * @param string $parentAttrName
  * @return ProfileAttribute
  */
 public function __construct($name, $flags = 0, $parentAttrName = '')
 {
     $flags = $flags | self::AF_HIDE_SEARCH | self::AF_HIDE_LIST;
     parent::__construct($name, $flags);
     $this->m_parentAttrName = $parentAttrName;
     $this->m_accessField = Config::getGlobal('auth_accessfield');
     if (empty($this->m_accessField)) {
         $this->m_accessField = Config::getGlobal('auth_levelfield');
     }
 }
Example #7
0
 /**
  * Constructor.
  *
  * @param string $name The name of the attribute
  * @param int $flags The flags for this attribute
  * @param array $tabs The arrays looks like array("tabname1"=>("attribname1,"attribname2),"tabname1"=>(..),..)
  */
 public function __construct($name, $flags = 0, $tabs = [])
 {
     // A TabbedPane attribute should be display only in edit/view mode
     $flags = $flags | self::AF_HIDE_SEARCH | self::AF_HIDE_LIST | self::AF_HIDE_SELECT;
     foreach ($tabs as $tab => $attribs) {
         foreach ($attribs as $attrib) {
             $this->add($attrib, $tab);
         }
     }
     parent::__construct($name, $flags);
 }
Example #8
0
 /**
  * Constructor.
  *
  * @param string $name Name of the attribute
  * @param int $flags Flags for this attribute
  * @param string $template Display/sort template.
  * @param array $searchFields Array with fields, in which search will be perform. If ommited, fields from $template will be used
  */
 public function __construct($name, $flags = 0, $template, $searchFields = [])
 {
     $flags = $flags | self::AF_HIDE_EDIT | self::AF_HIDE_ADD | self::AF_HIDE_VIEW;
     parent::__construct($name, $flags);
     // base class constructor
     $this->m_template = $template;
     $parser = new StringParser($template);
     $this->m_displayfields = $parser->getFields();
     if (!count($searchFields)) {
         $this->m_searchfields = $this->m_displayfields;
     } else {
         $this->m_searchfields = $searchFields;
     }
 }
Example #9
0
 /**
  * Constructor.
  *
  * @param string $name Name of the attribute
  * @param int $flags Flags for this attribute
  * @param string $text text field
  */
 public function __construct($name, $flags = 0, $text)
 {
     $flags = $flags | self::AF_HIDE_SEARCH | self::AF_NO_SORT;
     $this->m_text = $text;
     parent::__construct($name, $flags);
 }
Example #10
0
 /**
  * Fetch the metadata about this attrib from the table metadata, and
  * process it.
  *
  * @param array $metadata The table metadata from the table for this
  *                        attribute.
  */
 public function fetchMeta($metadata)
 {
     $this->m_dbfieldtype = isset($metadata[$this->fieldName()]['gentype']) ? $metadata[$this->fieldName()]['gentype'] : null;
     if ($this->m_dbfieldtype == 'string') {
         parent::fetchMeta($metadata);
     }
 }
Example #11
0
 /**
  * Creates a searchcondition for the field,
  * was once part of searchCondition, however,
  * searchcondition() also immediately adds the search condition.
  *
  * @param Query $query The query object where the search condition should be placed on
  * @param string $table The name of the table in which this attribute
  *                           is stored
  * @param mixed $value The value the user has entered in the searchbox
  * @param string $searchmode The searchmode to use. This can be any one
  *                           of the supported modes, as returned by this
  *                           attribute's getSearchModes() method.
  * @param string $fieldname
  *
  * @return string The searchcondition to use.
  */
 public function getSearchCondition(Query $query, $table, $value, $searchmode, $fieldname = '')
 {
     // When we get $value as a substring, we autocomplete the time
     // So 9 becomes 09:00:00 and 11:15 becomes 11:15:00
     if (!is_array($value)) {
         $retval = array('hours' => substr($value, 0, 2), 'minutes' => substr($value, 3, 2), 'seconds' => substr($value, 6, 2));
         if (!$retval['seconds']) {
             $retval['seconds'] = '00';
         }
         if (!$retval['minutes']) {
             $retval['minutes'] = '00';
         }
         if (strlen($retval['hours']) == 1) {
             $retval['hours'] = '0' . $retval['hours'];
         }
         if (strlen($retval['minutes']) == 1) {
             $retval['minutes'] = '0' . $retval['minutes'];
         }
         if (strlen($retval['seconds']) == 1) {
             $retval['seconds'] = '0' . $retval['seconds'];
         }
         $value = implode(':', $retval);
     }
     return parent::getSearchCondition($query, $table, $value, $searchmode);
 }
Example #12
0
 /**
  * Is this attribute hidden?
  *
  * @param Attribute $attribute
  *
  * @return bool Boolean to indicate if attribute is hidden or not
  */
 protected function isHidden(Attribute $attribute)
 {
     if ($attribute->hasFlag(Attribute::AF_HIDE)) {
         return true;
     }
     if ($attribute->hasFlag(Attribute::AF_HIDE_SELECT) && $this->m_node->m_action === 'select') {
         return true;
     }
     if ($attribute->hasFlag(Attribute::AF_HIDE_LIST) && ($this->m_node->m_action === 'export' || $this->m_mode === 'export')) {
         return true;
     }
     return false;
 }
Example #13
0
 /**
  * Constructor.
  *
  * @param string $name The name of the filter
  * @param int $flags The flags of the filter
  *
  * @return Filter
  */
 public function __construct($name, $flags = 0)
 {
     parent::__construct($name, $flags | Attribute::AF_HIDE | Attribute::AF_FORCE_LOAD);
 }
Example #14
0
 /**
  * Checks if the file has a valid filetype.
  *
  * Note that obligatory and unique fields are checked by the
  * atkNodeValidator, and not by the validate() method itself.
  *
  * @param array $record The record that holds the value for this
  *                       attribute. If an error occurs, the error will
  *                       be stored in the 'atkerror' field of the record.
  * @param string $mode The mode for which should be validated ("add" or
  *                       "update")
  */
 public function validate(&$record, $mode)
 {
     parent::validate($record, $mode);
     $this->isAllowedFileType($record);
     $error = $record[$this->fieldName()]['error'];
     if ($error > 0) {
         $error_text = $this->fetchFileErrorType($error);
         Tools::atkTriggerError($record, $this, $error_text, Tools::atktext($error_text, 'atk'));
     }
 }
Example #15
0
 /**
  * Returns a displayable string for this value, to be used in HTML pages.
  *
  * @param array $record The record that holds the value for this attribute
  * @param string $mode The display mode.
  *
  * @return string HTML String
  */
 public function display($record, $mode)
 {
     if ($this->m_ownerInstance->m_partial == 'attribute.' . $this->fieldName() . '.refresh') {
         $record[$this->fieldName()] = $this->load($this->m_ownerInstance->getDb(), $record, $mode);
     }
     return parent::display($record, $mode);
 }
Example #16
0
 /**
  * Check if a record has an empty value for this attribute.
  *
  * @param array $record The record that holds this attribute's value.
  *
  * @return bool
  */
 public function isEmpty($record)
 {
     return parent::isEmpty($record) || $record[$this->fieldName()] == 0;
 }
Example #17
0
 /**
  * Get the HTML label of the attribute.
  *
  * The difference with the label() method is that the label method always
  * returns the HTML label, while the getLabel() method is 'smart', by
  * taking the self::AF_NOLABEL and self::AF_BLANKLABEL flags into account.
  *
  * @param array $record The record holding the value for this attribute.
  * @param string $mode The mode ("add", "edit" or "view")
  *
  * @return string The HTML compatible label for this attribute, or an
  *                empty string if the label should be blank, or NULL if no
  *                label at all should be displayed.
  */
 public function getLabel($record = [], $mode = '')
 {
     if ($mode == 'view' && $this->hasFlag(self::AF_BLANK_LABEL | self::AF_BOOL_INLINE_LABEL)) {
         return $this->label();
     } else {
         return parent::getLabel($record);
     }
 }
Example #18
0
 /**
  * Constructor.
  *
  * Warning: very old versions of this attribute supported passing the
  * parameters in a different order: $name, $flags, $optionArray.
  * This order used to be supported even when the new order was
  * implemented, but it has now been removed. Keep this in mind
  * when upgrading from a very old ATK version (pre ATK4).
  *
  * @param string $name Name of the attribute
  * @param int $flags Flags for this attribute
  * @param array $optionArray Array with options
  * @param array $valueArray Array with values. If you don't use this parameter,
  *                            values are assumed to be the same as the options.
  */
 public function __construct($name, $flags = 0, $optionArray, $valueArray = null)
 {
     if (!is_array($valueArray) || count($valueArray) == 0) {
         $valueArray = $optionArray;
     }
     // If all values are numeric, we can use a numeric field to store the selected
     // value.
     $this->m_dbfieldtype = 'number';
     for ($i = 0, $_i = count($valueArray); $i < $_i && $this->m_dbfieldtype == 'number'; ++$i) {
         if (!is_numeric($valueArray[$i])) {
             $this->m_dbfieldtype = 'string';
         }
         // if one of the values is not a number, the fieldtype must be string, and
         // the loop is stopped.
     }
     // the max size we have is equal to the biggest value.
     $size = 0;
     for ($i = 0, $_i = count($valueArray); $i < $_i; ++$i) {
         $size = max($size, Tools::atk_strlen($valueArray[$i]));
     }
     if ($size > 0) {
         $this->setAttribSize($size);
     }
     parent::__construct($name, $flags);
     $this->setOptions($optionArray, $valueArray);
 }
Example #19
0
 /**
  * Checks if the value is a valid IP address.
  *
  * @param array $record The record that holds the value for this
  *                       attribute. If an error occurs, the error will
  *                       be stored in the 'atkerror' field of the record.
  * @param string $mode The mode for which should be validated ("add" or
  *                       "update")
  */
 public function validate(&$record, $mode)
 {
     // Check for valid ip string
     $strvalue = Tools::atkArrayNvl($record, $this->fieldName(), '');
     if ($strvalue != '' && $strvalue != '...') {
         if ($this->hasFlag(self::AF_IP_ALLOW_WILDCARDS) && !$this->hasFlag(self::AF_IP_STORENUMERIC)) {
             $strvalue = str_replace('*', '0', $strvalue);
         }
         $num = '(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])';
         if (preg_match("/^{$num}\\.{$num}\\.{$num}\\.{$num}\$/", $strvalue, $matches) <= 0) {
             Tools::triggerError($record, $this->fieldName(), 'error_not_a_valid_ip');
         }
     }
     parent::validate($record, $mode);
 }
Example #20
0
 /**
  * Add an Attribute (or one of its derivatives) to the node.
  *
  * @param Attribute $attribute The attribute you want to add
  * @param mixed $sections The sections/tab(s) on which the attribute should be
  *                             displayed. Can be a tabname (String) or a list of
  *                             tabs (array) or "*" if the attribute should be
  *                             displayed on all tabs.
  * @param int $order The order at which the attribute should be displayed.
  *                             If ommitted, this defaults to 100 for the first
  *                             attribute, and 100 more for each next attribute that
  *                             is added.
  *
  * @return Attribute the attribute just added
  */
 public function add($attribute, $sections = null, $order = 0)
 {
     $tabs = null;
     $column = null;
     $attribute->m_owner = $this->m_type;
     if (!$this->atkReadOptimizer()) {
         $this->resolveSectionsTabsOrder($sections, $tabs, $column, $order);
         // check for parent fieldname (treeview)
         if ($attribute->hasFlag($attribute::AF_PARENT)) {
             $this->m_parent = $attribute->fieldName();
         }
         // check for cascading delete flag
         if ($attribute->hasFlag($attribute::AF_CASCADE_DELETE)) {
             $this->m_cascadingAttribs[] = $attribute->fieldName();
         }
         if ($attribute->hasFlag($attribute::AF_HIDE_LIST) && !$attribute->hasFlag($attribute::AF_PRIMARY)) {
             if (!in_array($attribute->fieldName(), $this->m_listExcludes)) {
                 $this->m_listExcludes[] = $attribute->fieldName();
             }
         }
         if ($attribute->hasFlag($attribute::AF_HIDE_VIEW) && !$attribute->hasFlag($attribute::AF_PRIMARY)) {
             if (!in_array($attribute->fieldName(), $this->m_viewExcludes)) {
                 $this->m_viewExcludes[] = $attribute->fieldName();
             }
         }
     } else {
         // when the read optimizer is enabled there is no active tab
         // we circument this by putting all attributes on all tabs
         if ($sections !== null && is_int($sections)) {
             $order = $sections;
         }
         $tabs = '*';
         $sections = '*';
         $column = $this->getDefaultColumn();
     }
     // NOTE: THIS SHOULD WORK. BUT, since add() is called from inside the $this
     // constructor, m_ownerInstance ends up being a copy of $this, rather than
     // a reference. Don't ask me why, it has something to do with the way PHP
     // handles the constructor.
     // To work around this, we reassign the this pointer to the attributes as
     // soon as possible AFTER the constructor. (the dispatcher function)
     $attribute->setOwnerInstance($this);
     if ($attribute->hasFlag(Attribute::AF_PRIMARY)) {
         if (!in_array($attribute->fieldName(), $this->m_primaryKey)) {
             $this->m_primaryKey[] = $attribute->fieldName();
         }
     }
     $attribute->init();
     $exist = false;
     if (isset($this->m_attribList[$attribute->fieldName()]) && is_object($this->m_attribList[$attribute->fieldName()])) {
         $exist = true;
         // if order is set, overwrite it with new order, last order will count
         if ($order != 0) {
             $this->m_attribIndexList[$this->m_attribList[$attribute->fieldName()]->m_index]['order'] = $order;
         }
         $attribute->m_index = $this->m_attribList[$attribute->fieldName()]->m_index;
     }
     if (!$exist) {
         if ($order == 0) {
             $this->m_attribOrder += 100;
             $order = $this->m_attribOrder;
         }
         if (!$this->atkReadOptimizer()) {
             // add new tab(s) to the tab list ("*" isn't a tab!)
             if ($tabs != '*') {
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_ADD)) {
                     $this->m_tabList['add'] = isset($this->m_tabList['add']) ? Tools::atk_array_merge($this->m_tabList['add'], $tabs) : $tabs;
                 }
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_EDIT)) {
                     $this->m_tabList['edit'] = isset($this->m_tabList['edit']) ? Tools::atk_array_merge($this->m_tabList['edit'], $tabs) : $tabs;
                 }
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_VIEW)) {
                     $this->m_tabList['view'] = isset($this->m_tabList['view']) ? Tools::atk_array_merge($this->m_tabList['view'], $tabs) : $tabs;
                 }
             }
             if ($sections != '*') {
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_ADD)) {
                     $this->m_sectionList['add'] = isset($this->m_sectionList['add']) ? Tools::atk_array_merge($this->m_sectionList['add'], $sections) : $sections;
                 }
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_EDIT)) {
                     $this->m_sectionList['edit'] = isset($this->m_sectionList['edit']) ? Tools::atk_array_merge($this->m_sectionList['edit'], $sections) : $sections;
                 }
                 if (!$attribute->hasFlag(Attribute::AF_HIDE_VIEW)) {
                     $this->m_sectionList['view'] = isset($this->m_sectionList['view']) ? Tools::atk_array_merge($this->m_sectionList['view'], $sections) : $sections;
                 }
             }
         }
         $attribute->m_order = $order;
         $this->m_attribIndexList[] = array('name' => $attribute->fieldName(), 'tabs' => $tabs, 'sections' => $sections, 'order' => $attribute->m_order);
         $attribute->m_index = max(array_keys($this->m_attribIndexList));
         // might contain gaps
         $attribute->setTabs($tabs);
         $attribute->setSections($sections);
         $this->m_attributeTabs[$attribute->fieldName()] = $tabs;
     }
     // Order the tablist
     $this->m_attribList[$attribute->fieldName()] = $attribute;
     $attribute->setTabs($this->m_attributeTabs[$attribute->fieldName()]);
     $attribute->setSections($this->m_attribIndexList[$attribute->m_index]['sections']);
     $attribute->setColumn($column);
     return $attribute;
 }
Example #21
0
 /**
  * Check if the currently logged-in user has the right to view, edit etc.
  * an attribute of a node.
  *
  * @param SecurityManager $securityMgr the security manager
  * @param Attribute $attr attribute reference
  * @param string $mode mode (add, edit, view etc.)
  * @param array $record record data
  *
  * @return bool true if access is granted, false if not.
  */
 public function attribAllowed($securityMgr, $attr, $mode, $record = null)
 {
     $node = $attr->m_ownerInstance->atkNodeUri();
     $attribute = $attr->fieldName();
     // security disabled or user is superuser? (may do anything)
     if ($securityMgr->m_scheme == 'none' || !Config::getGlobal('security_attributes') || $securityMgr->hasLevel(-1) || strtolower($securityMgr->m_user['name']) == 'administrator') {
         $allowed = true;
     } else {
         if ($securityMgr->hasLevel(-2) || strtolower($securityMgr->m_user['name']) == 'guest') {
             $allowed = false;
         } else {
             // all other situations
             $required = $this->getAttribEntity($node, $attribute, $mode);
             if ($required == -1) {
                 // No access restrictions found..
                 $allowed = true;
             } else {
                 if ($securityMgr->m_scheme == 'level') {
                     $allowed = $securityMgr->m_user['level'] >= $required;
                 } else {
                     if ($securityMgr->m_scheme == 'group') {
                         $level = is_array($securityMgr->m_user['level']) ? $securityMgr->m_user['level'] : [$securityMgr->m_user['level']];
                         $required = is_array($required) ? $required : [$required];
                         $allowed = array_intersect($level, $required) ? true : false;
                         if (Config::getGlobal('reverse_attributeaccess_logic', false)) {
                             $allowed = !$allowed;
                         }
                     } else {
                         // unknown scheme??
                         $allowed = false;
                     }
                 }
             }
         }
     }
     return $allowed;
 }
Example #22
0
 /**
  * Validate attribute value.
  *
  * @param Attribute $p_attrib pointer to the attribute
  * @param array $record record
  */
 public function validateAttributeValue($p_attrib, &$record)
 {
     if (!$p_attrib->isEmpty($record)) {
         $funcname = $p_attrib->m_name . '_validate';
         if (method_exists($this->m_nodeObj, $funcname)) {
             $this->m_nodeObj->{$funcname}($record, $this->m_mode);
         } else {
             $p_attrib->validate($record, $this->m_mode);
         }
     }
 }
Example #23
0
 /**
  * Validates absolute, relative and anchor URL through regular expression.
  *
  * @param array $record Record that contains value to be validated.
  *                           Errors are saved in this record, in the 'atkerror'
  *                           field.
  * @param string $mode Validation mode. Can be either "add" or "update"
  * @param bool $show_error fire a triggerError when validation fails
  */
 public function validateUrl(&$record, $mode, $show_error = false)
 {
     $result = false;
     $absolute_result = true;
     $anchor_result = true;
     $absolute_anchor_result = true;
     $relative_result = true;
     $base_url_regex = "(ft|htt)ps?:\\/\\/[a-zA-Z0-9\\.\\-\\_]+\\.[a-zA-Z]{2,4}";
     $relative_url_regex = "[a-zA-Z0-9\\.\\-\\_\\/?&=%]";
     $relative_url_regex_with_anchor = "[a-zA-Z0-9\\.\\-\\_\\/?&=%#]";
     /*
      * Validate URL, check if format is absolute (external URL's) and has no anchor
      *
      * Example: http://www2-dev.test_url.com
      * or:      ftp://www2-dev.test_url.com/index.php?/feeds/index.rss2
      */
     if (($this->m_accepts_url_flag & self::ABSOLUTE) == self::ABSOLUTE) {
         $absolute_result = preg_match('/^' . $base_url_regex . $relative_url_regex . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $absolute_result;
     }
     /*
      * Validate URL, check if format is a valid anchor
      *
      * Example: #internal_bookmark
      */
     if (($this->m_accepts_url_flag & self::ANCHOR) == self::ANCHOR) {
         $anchor_result = preg_match('/^#' . $relative_url_regex . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $anchor_result;
     }
     /*
      * Validate URL, check if format is absolute (external URL's) and has (optional) anchor
      *
      * Example: http://www2-dev.test_url.com
      * or:      ftp://www2-dev.test_url.com/index.php?/feeds/index.rss2
      * or:      https://www2-dev.test_url.com/index.php?/history.html#bookmark
      */
     if (($this->m_accepts_url_flag & self::ABSOLUTE) == self::ABSOLUTE && ($this->m_accepts_url_flag & self::ANCHOR) == self::ANCHOR) {
         $absolute_anchor_result = preg_match('/^' . $base_url_regex . $relative_url_regex_with_anchor . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $absolute_anchor_result;
     }
     /*
      * Validate URL, check if format is relative
      *
      * Example: /mysite/guestbook/index.html
      */
     if (($this->m_accepts_url_flag & self::RELATIVE) == self::RELATIVE) {
         $relative_result = preg_match('/^' . $relative_url_regex_with_anchor . '+$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $relative_result;
     }
     /*
      * If an error occured, show applicable message(s)
      */
     if (!$result && $show_error) {
         // if result of all validations is false, display error-messages
         if ($absolute_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_absolute_no_anchor_url', Tools::atktext('invalid_absolute_no_anchor_url'));
         }
         if ($anchor_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_url_anchor', Tools::atktext('invalid_url_anchor'));
         }
         if ($absolute_anchor_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_absolute_url', Tools::atktext('invalid_absolute_url'));
         }
         if ($relative_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_relative_url', Tools::atktext('invalid_relative_url'));
         }
     }
     if (!$result) {
         parent::validate($record, $mode);
     }
 }
Example #24
0
 /**
  * Constructor.
  *
  * @param string $name The name of the relation.
  * @param int $flags Flags for the relation
  * @param string $destination The destination node (in module.name notation)
  */
 public function __construct($name, $flags = 0, $destination)
 {
     parent::__construct($name, $flags);
     $this->m_destination = $destination;
 }
Example #25
0
 public function edit($record, $fieldprefix, $mode)
 {
     // There are 2 possibilities. Either we are going to search,
     // in which case we show a searchbox.
     // Or, a search has already been performed but multiple
     // matches have been found and an atkerror was set.
     // In this case, we show the selects.
     $select = false;
     if (isset($record['atkerror'])) {
         foreach ($record['atkerror'] as $error) {
             if ($error['attrib_name'] === $this->fieldName()) {
                 $select = true;
             }
         }
     }
     if ($select && $this->createSearchNodeInstance()) {
         $res = '';
         $notempty = false;
         // First lets get the results, which were lost during the redirect
         $this->m_matches = $this->getMatches($record[$this->fieldName()]);
         // Second check if we actually found anything
         if ($this->m_matches) {
             foreach ($this->m_matches as $match) {
                 if (!empty($match)) {
                     $notempty = true;
                     continue;
                 }
             }
             if (!$notempty) {
                 return Tools::atktext('no_results_found');
             }
         }
         if ($this->m_mode == 'multiselect' && count($this->m_matches) > 1) {
             $optionArray = $valueArray = [];
             foreach ($this->m_matches as $keyword => $matches) {
                 for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                     $optionArray[] = $this->m_searchnodeInstance->descriptor($matches[$i]);
                     $valueArray[] = $this->m_searchnodeInstance->primaryKey($matches[$i]);
                 }
             }
             $attrib = new MultiSelectAttribute($this->m_name, $optionArray, $valueArray, 1, self::AF_NO_LABEL | MultiSelectAttribute::AF_CHECK_ALL | MultiSelectAttribute::AF_LINKS_BOTTOM);
             $res .= $attrib->edit($record, $fieldprefix, $mode);
         } else {
             if ($this->m_mode == 'select' || $this->m_mode == 'multiselect' && count($this->m_matches) == 1) {
                 // Select one record from all matches.
                 $res .= '<SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">';
                 $res .= '<OPTION VALUE="">' . Tools::atktext('select_none');
                 $selects = [];
                 foreach ($this->m_matches as $keyword => $matches) {
                     for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                         $item = '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]);
                         if (!in_array($item, $selects)) {
                             $selects[] = $item;
                         }
                     }
                     $res .= implode("\n", $selects);
                 }
                 $res .= '</SELECT>';
             } else {
                 if ($this->m_mode == 'selectperkeyword') {
                     // Select one record per keyword.
                     $res = '<table border="0">';
                     foreach ($this->m_matches as $keyword => $matches) {
                         if (count($matches) > 0) {
                             $res .= '<tr><td>\'' . $keyword . '\': </td><td><SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">';
                             $res .= '<OPTION VALUE="">' . Tools::atktext('select_none');
                             for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                                 $res .= '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]);
                             }
                             $res .= '</SELECT></td></tr>';
                         }
                     }
                     $res .= '</table>';
                 }
             }
         }
         return $res;
     } else {
         $record = '';
         // clear the record so we always start with an empty
         // searchbox.
         return parent::edit($record, $fieldprefix, $mode);
     }
 }
Example #26
0
 /**
  * Returns a piece of html code that can be used in a form to search values.
  * Searching is disabled for the date attribute, we only return a space.
  *
  * @param array $record array with 3 fields (year, month, day)
  * @param bool $extended if set to false, a simple search input is
  *                            returned for use in the searchbar of the
  *                            recordlist. If set to true, a more extended
  *                            search may be returned for the 'extended'
  *                            search page. The Attribute does not
  *                            make a difference for $extended is true, but
  *                            derived attributes may reimplement this.
  * @param string $fieldprefix The fieldprefix of this attribute's HTML element.
  * @param DataGrid $grid
  *
  * @return string piece of HTML code
  */
 public function search($record, $extended = false, $fieldprefix = '', DataGrid $grid = null)
 {
     if (!$extended) {
         // plain text search, check if we didn't come from extended search (then current value is an array)
         if (isset($record[$this->fieldName()]) && is_array($record[$this->fieldName()])) {
             // TODO try to set the value
             $record[$this->fieldName()] = null;
         }
         $maxSize = $this->m_maxsize;
         $this->m_maxsize = 25;
         // temporary increase max size to allow from/to dates
         $result = parent::search($record, $extended, $fieldprefix);
         $this->m_maxsize = $maxSize;
         return $result;
     }
     // Set default values to null.
     if (!isset($record[$this->fieldName()]) || empty($record[$this->fieldName()])) {
         $record[$this->fieldName()] = null;
     }
     $id = $this->getHtmlId($fieldprefix);
     $name = $this->getSearchFieldName($fieldprefix);
     $rec = isset($record[$this->fieldName()]['from']) ? array($this->fieldName() => $record[$this->fieldName()]['from']) : $record;
     $res = $this->draw($rec, $id . '_from', $name, 'atksearch_AE_' . $fieldprefix, '_AE_from', 'search');
     $rec = isset($record[$this->fieldName()]['to']) ? array($this->fieldName() => $record[$this->fieldName()]['to']) : $record;
     $res .= '&nbsp;' . Tools::atktext('until') . ': ' . $this->draw($rec, $id . '_to', $name, 'atksearch_AE_' . $fieldprefix, '_AE_to', 'search');
     return $res;
 }
Example #27
0
 public function __construct($name, $flags = 0, $colorPickerOptions = [])
 {
     $this->colorPickerOptions = $colorPickerOptions;
     parent::__construct($name, $flags);
 }
Example #28
0
 /**
  * Constructor.
  *
  * <b>Example:</b>
  *        $this->add(new atkFormatAttribute("license", "AAA/##/##",
  *                                                        self::AF_OBLIGATORY));
  *
  * @todo Support for other types of input, upper/lowercase support,
  *       escape possibility for using literal *'s.
  *       Also, variable length parts would be nice.
  *       Finally, there should be an option if 'AA' accepts 'z' or only
  *       'zz'
  *
  * @param string $name Name of the attribute (unique within a node, and
  *                       corresponds to a field in the database.
  * @param int $flags Flags for the attribute.
  * @param string $format The format specifier. Each character defines
  *                       what type of input is expected.
  *                       Currently supported format characters:
  *                       * - Accept any character
  *                       # - Accept letter or digit
  *                       A - Accept a letter from the alphabet
  *                       9 - Accept a digit
  *                       Any other char is seen as a literal and displayed
  *                       literally as non-editable chars in the editor.
  */
 public function __construct($name, $flags = 0, $format)
 {
     $this->m_format = $format;
     parent::__construct($name, $flags);
     $this->setAttribSize(strlen($format));
 }
Example #29
0
 /**
  * Is attribute load required?
  *
  * @param Attribute $attr attribute
  *
  * @return bool load required?
  */
 protected function _isAttributeLoadRequired($attr)
 {
     $attrName = $attr->fieldName();
     return !$this->m_ignorePrimaryKey && in_array($attrName, $this->_getNode()->m_primaryKey) || !$this->m_ignoreForceLoad && $attr->hasFlag(Attribute::AF_FORCE_LOAD) || ($this->m_includes != null && in_array($attrName, $this->m_includes) || $this->m_excludes != null && !in_array($attrName, $this->m_excludes)) || $this->m_excludes == null && $this->m_includes == null;
 }
Example #30
0
 function display($record = "", $mode = '')
 {
     if ($this->getSearchType() == "number") {
         $attr = new NumberAttribute($this->fieldName());
         return $attr->display($record, $mode);
     } else {
         if ($this->getSearchType() == "date") {
             $attr = new DateAttribute($this->fieldName());
             $record[$this->fieldName()] = $attr->db2value($record);
             return $attr->display($record, $mode);
         }
     }
     return parent::display($record, $mode);
 }