Пример #1
0
 /**
  * Constructor.
  *
  * @param string $name Name of the field
  * @param int $flags Flags for this attribute.
  *
  * @return UpdatedByAttribute
  */
 public function __construct($name, $flags = 0)
 {
     $flags = $flags | self::AF_READONLY | self::AF_HIDE_ADD;
     parent::__construct($name, $flags, Config::getGlobal('auth_usernode'));
     $this->setForceInsert(true);
     $this->setForceUpdate(true);
 }
Пример #2
0
 /**
  * Convert an ATK generic datatype to a database specific type.
  *
  * @param string $generictype The datatype to convert.
  *
  * @return string
  */
 public function getType($generictype)
 {
     $config = Config::getGlobal('db_mysql_default_' . $generictype . '_columntype');
     if ($config) {
         return $config;
     }
     switch ($generictype) {
         case 'number':
             return 'INT';
         case 'decimal':
             return 'DECIMAL';
         case 'string':
             return 'VARCHAR';
         case 'date':
             return 'DATE';
         case 'text':
             return 'TEXT';
         case 'datetime':
             return 'DATETIME';
         case 'time':
             return 'TIME';
         case 'boolean':
             return 'NUMBER(1,0)';
             // size is added fixed. (because a boolean has no size of its own)
     }
     return '';
     // in case we have an unsupported type.
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param DataGrid $grid grid
  * @param array $options component options
  */
 public function __construct($grid, $options = array())
 {
     parent::__construct($grid, $options);
     $this->m_maxLinks = Config::getGlobal('pagelinks', 10);
     $this->m_goToFirstLast = Config::getGlobal('pagelinks_first_last', false);
     $this->m_goToPreviousNext = Config::getGlobal('pagelinks_previous_next', true);
 }
Пример #4
0
 /**
  * Static factory method for creating a new atkDDL instance. This static
  * method will determine the database type (mysql, oci, etc) and
  * instantiate the correct DDL class.
  *
  * @param string $database The database driver to use
  *
  * @return Ddl instance of db specific DDL driver
  */
 public static function create($database = null)
 {
     $db = Config::getGlobal('db');
     $database = $database === null ? $db['default']['driver'] : $database;
     $classname = __NAMESPACE__ . '\\' . $database . 'Ddl';
     return new $classname();
 }
Пример #5
0
 /**
  * constructor.
  */
 public function __construct()
 {
     // make sure we have apc available
     if (!(extension_loaded('apc') && ini_get('apc.enabled'))) {
         throw new Exception('The APC extension is not loaded or disabled');
     }
     $this->m_namespace = Config::getGlobal('cache_namespace', 'default');
 }
Пример #6
0
 /**
  * Return a piece of html code to edit the attribute.
  *
  * @param array $record Current record
  * @param string $fieldprefix The fieldprefix to put in front of the name
  *                            of any html form element for this attribute.
  * @param string $mode The mode we're in ('add' or 'edit')
  *
  * @return string piece of html code
  */
 public function edit($record, $fieldprefix, $mode)
 {
     $this->createDestination();
     $this->createLink();
     $result = '';
     $selectedPk = $this->getSelectedRecords($record);
     $recordset = $this->_getSelectableRecords($record, $mode);
     $total_records = count($recordset);
     if ($total_records > 0) {
         $page = Page::getInstance();
         $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkprofileattribute.js');
         if (!$this->hasFlag(self::AF_MANYBOOL_NO_TOOLBAR)) {
             $result .= '<div align="left">
                   [<a href="javascript:void(0)" onclick="profile_checkAll(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('check_all', 'atk') . '</a> <a href="javascript:void(0)" onclick="profile_checkNone(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('check_none', 'atk') . '</a> <a href="javascript:void(0)" onclick="profile_checkInvert(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('invert_selection', 'atk') . '</a>]</div>';
         }
         $result .= '<div>';
         for ($i = 0; $i < $total_records; ++$i) {
             $detailLink = '';
             $sel = '';
             $onchange = '';
             $inputId = $this->getHtmlId($fieldprefix) . '_' . $i;
             if (in_array($this->m_destInstance->primaryKey($recordset[$i]), $selectedPk)) {
                 $sel = 'checked';
                 if ($this->getShowDetailsLink() && !$this->m_linkInstance->hasFlag(Node::NF_NO_EDIT) && $this->m_linkInstance->allowed('edit')) {
                     $localPkAttr = $this->getOwnerInstance()->getAttribute($this->getOwnerInstance()->primaryKeyField());
                     $localValue = $localPkAttr->value2db($record);
                     $remotePkAttr = $this->getDestination()->getAttribute($this->getDestination()->primaryKeyField());
                     $remoteValue = $remotePkAttr->value2db($recordset[$i]);
                     $selector = $this->m_linkInstance->m_table . '.' . $this->getLocalKey() . '=' . $localValue . '' . ' AND ' . $this->m_linkInstance->m_table . '.' . $this->getRemoteKey() . "='" . $remoteValue . "'";
                     $detailLink = Tools::href(Tools::dispatch_url($this->m_link, 'edit', array('atkselector' => $selector)), '[' . Tools::atktext('edit', 'atk') . ']', SessionManager::SESSION_NESTED, true);
                 }
             }
             if (count($this->m_onchangecode)) {
                 $onchange = ' onChange="' . $inputId . '_onChange(this);"';
                 $this->_renderChangeHandler($fieldprefix, '_' . $i);
             }
             $value = $recordset[$i][$this->m_destInstance->primaryKeyField()];
             $css = $this->getCSSClassAttribute('atkcheckbox');
             $label = $this->m_destInstance->descriptor($recordset[$i]);
             $result .= '<div>';
             $result .= '  <input type="checkbox" id="' . $inputId . '" name="' . $this->getHtmlName($fieldprefix) . '[][' . $this->getRemoteKey() . ']" value="' . $value . '" ' . $css . ' ' . $sel . $onchange . ' />';
             $result .= '  <label for="' . $inputId . '">' . $label . '</label>';
             if ($detailLink != '') {
                 $result .= ' ' . $detailLink;
             }
             $result .= '</div>';
         }
         $result .= '</div>';
     } else {
         $nodename = $this->m_destInstance->m_type;
         $modulename = $this->m_destInstance->m_module;
         $result .= Tools::atktext('select_none', $modulename, $nodename) . ' ';
     }
     if ($this->hasFlag(self::AF_MANYBOOL_AUTOLINK) && $this->m_destInstance->allowed('add')) {
         $result .= Tools::href(Tools::dispatch_url($this->m_destination, 'add'), $this->getAddLabel(), SessionManager::SESSION_NESTED) . "\n";
     }
     return $result;
 }
Пример #7
0
 /**
  * Get the start of the form.
  *
  * @return string HTML The forms' start
  */
 public function getFormStart($record = null)
 {
     $sm = SessionManager::getInstance();
     $formstart = '<form name="entryform" id="entryform" action="' . Config::getGlobal('dispatcher') . '" method="get" onsubmit="return globalSubmit(this,false)">';
     $formstart .= $sm->formState(SessionManager::SESSION_NESTED);
     $formstart .= '<input type="hidden" name="atkselector" value="' . $this->getNode()->primaryKey($record) . '">';
     $formstart .= '<input type="hidden" class="atksubmitaction" />';
     return $formstart;
 }
Пример #8
0
 /**
  * Constructor.
  *
  * @return Zip
  */
 public function __construct()
 {
     $this->m_zipmode = Config::getGlobal('zipmode', 'auto');
     $this->m_zip_bin = Config::getGlobal('ziplocation', 'zip');
     $this->m_unzip_bin = Config::getGlobal('unziplocation', 'unzip');
     if (!$this->test()) {
         Tools::atkerror('atkZip: Error while testing');
     }
 }
Пример #9
0
 public function registerScriptsAndStyles($fieldprefix)
 {
     $htmlId = $this->getHtmlId($fieldprefix);
     $page = Page::getInstance();
     $base = Config::getGlobal('assets_url') . 'lib/bootstrap-switch/';
     $page->register_script($base . 'js/bootstrap-switch.min.js');
     $page->register_style($base . 'css/bootstrap3/bootstrap-switch.min.css');
     $opts = json_encode($this->switchOptions);
     $page->register_loadscript("\n            jQuery(function(\$){\n                \$('#{$htmlId}').bootstrapSwitch({$opts});\n            });");
 }
Пример #10
0
 public function registerScriptsAndStyles($fieldprefix)
 {
     $htmlId = $this->getHtmlId($fieldprefix) . '_group';
     $page = Page::getInstance();
     $base = Config::getGlobal('assets_url') . 'lib/bootstrap-colorpicker/dist/';
     $page->register_script($base . 'js/bootstrap-colorpicker.min.js');
     $page->register_style($base . 'css/bootstrap-colorpicker.min.css');
     $opts = json_encode($this->colorPickerOptions);
     $page->register_scriptcode("\n            jQuery(function(\$){\n                \$('#{$htmlId}').colorpicker({$opts});\n            });");
 }
Пример #11
0
 public function edit($record, $fieldprefix, $mode)
 {
     $page = $this->getOwnerInstance()->getPage();
     $id = $this->getHtmlId($fieldprefix);
     // register CKEditor main script
     $page->register_script(Config::getGlobal('assets_url') . 'lib/ckeditor/ckeditor.js');
     // activate CKEditor
     $options = json_encode($this->ckOptions);
     $page->register_loadscript("CKEDITOR.replace('{$id}', {$options});");
     return parent::edit($record, $fieldprefix, $mode);
 }
Пример #12
0
 /**
  * Register JavaScript code for the grid.
  */
 protected function registerScript()
 {
     if ($this->getGrid()->isUpdate()) {
         return;
     }
     $name = Json::encode($this->getGrid()->getName());
     $baseUrl = Json::encode($this->getGrid()->getBaseUrl());
     $embedded = $this->getGrid()->isEmbedded() ? 'true' : 'false';
     $this->getPage()->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkdatagrid.js');
     $this->getPage()->register_loadscript("\n      ATK.DataGrid.register({$name}, {$baseUrl}, {$embedded});\n    ");
 }
Пример #13
0
 /**
  * Get function for encryption.
  *
  * Gets a new instance of an encryption class with the type we passed
  * along
  *
  * @param string $type The type of encryption we want,
  *                     defaults to $config)_encryption_defaultmethod
  *
  * @return Encryption the node with which to encrypt or decrypt your data
  */
 public function getEncryption($type = '')
 {
     if ($type == '') {
         $type = Config::getGlobal('encryption_defaultmethod');
     }
     $encryptionclass = $type . 'Encryption';
     if (class_exists($encryptionclass)) {
         return new $encryptionclass();
     } else {
         return $this;
     }
 }
Пример #14
0
 /**
  * Returns the possible options.
  *
  * @param array $values possible limits
  *
  * @return array possible options
  */
 protected function getOptions($values)
 {
     $options = [];
     $limit = $this->getGrid()->getLimit();
     foreach ($values as $value) {
         $current = $value == $limit;
         $options[] = array('title' => $value, 'value' => $value, 'current' => $current);
     }
     //Add 'show all' option.
     //if ($this -> getOption('showAll', false))
     if (Config::getGlobal('enable_showall', false)) {
         $options[] = array('title' => $this->text('all'), 'value' => -1, 'current' => $limit == -1);
     }
     return $options;
 }
Пример #15
0
 /**
  * This method handles the storage of the action in the database.
  *
  * @param string $action The action being performed
  * @param array $record The record on which the action is performed
  */
 public function actionPerformed($action, $record)
 {
     $user = SecurityManager::atkGetUser();
     $userid = $user[Config::getGlobal('auth_userpk')];
     if ($userid == '') {
         $userid = 0;
     }
     // probably administrator
     $node = $this->m_node->atkNodeUri();
     $db = $this->m_node->getDb();
     $primarykey = $db->escapeSQL($this->m_node->primaryKey($record));
     $db->query('INSERT INTO atkeventlog (id, userid, stamp, node, action, primarykey)
                 VALUES(' . $db->nextid('atkeventlog') . ", {$userid}, " . $db->func_now() . ", '{$node}', '{$action}', '{$primarykey}')");
     $db->commit();
 }
Пример #16
0
 /**
  * Authenticate a user.
  *
  * @param string $user The login of the user to authenticate.
  * @param string $passwd The password of the user. Note: if the canMd5
  *                       function of an implementation returns true,
  *                       $passwd will be passed as an md5 string.
  *
  * @return int SecurityManager::AUTH_SUCCESS - Authentication succesful
  *             SecurityManager::AUTH_MISMATCH - Authentication failed, wrong
  *             user/password combination
  *             SecurityManager::AUTH_LOCKED - Account is locked, can not login
  *             with current username.
  *             SecurityManager::AUTH_ERROR - Authentication failed due to some
  *             error which cannot be solved by
  *             just trying again. If you return
  *             this value, you *must* also
  *             fill the m_fatalError variable.
  */
 public function validateUser($user, $passwd)
 {
     if ($user == '') {
         return SecurityManager::AUTH_UNVERIFIED;
     }
     // can't verify if we have no userid
     // if it's a virtual mail server add @<domain> to the username
     if (Config::getGlobal('auth_mail_login_type') == 'vmailmgr') {
         $user = $user . '@' . Config::getGlobal('auth_mail_suffix');
     }
     if (Config::getGlobal('auth_mail_server') == '') {
         $this->m_fatalError = Tools::atktext('auth_no_server');
         return SecurityManager::AUTH_ERROR;
     }
     $mailauth = @imap_open('{' . Config::getGlobal('auth_mail_server') . ':' . Config::getGlobal('auth_mail_port') . '}', $user, $passwd);
     // TODO/FIXME: return SecurityManager::AUTH_ERROR when connection fails..
     if ($mailauth == 0) {
         return SecurityManager::AUTH_MISMATCH;
     } else {
         imap_close($mailauth);
         return SecurityManager::AUTH_SUCCESS;
     }
 }
Пример #17
0
 public function edit($record, $fieldprefix, $mode)
 {
     $this->getOwnerInstance()->getPage()->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkradiodetailsattribute.js');
     $name = $this->getHtmlName($fieldprefix);
     $result = '<div class="atkradiodetailsattribute-selection">';
     foreach ($this->m_options as $label => $value) {
         $isSelected = $record[$this->fieldName()] == $value;
         $checked = $isSelected ? ' checked="checked"' : '';
         $attrNames = @$this->m_details[$value];
         if ($attrNames != null) {
             $url = Tools::partial_url($this->getOwnerInstance()->atkNodeUri(), $mode, 'attribute.' . $this->fieldName() . '.details', array('value' => $value, 'fieldprefix' => $fieldprefix));
             $onChange = "ATK.RadioDetailsAttribute.select(this, '{$url}');";
         } else {
             $onChange = 'ATK.RadioDetailsAttribute.select(this);';
         }
         $result .= '
     <input type="radio" class="atkradiodetailsattribute-option" name="' . $name . '" id="' . $name . '_' . $value . '" value="' . $value . '" onchange="' . $onChange . '"' . $checked . '/>
     <label for="' . $name . '_' . $value . '">' . $this->text($label) . '</label><br/>
   ';
         if ($attrNames != null) {
             $result .= '<div id="' . $name . '_' . $value . '_details" class="atkradiodetailsattribute-details">';
             if ($isSelected) {
                 foreach ($attrNames as $attrName) {
                     $attr = $this->getOwnerInstance()->getAttribute($attrName);
                     if (is_null($attr)) {
                         continue;
                     }
                     $result .= '<blockquote>' . $attr->edit($record, $fieldprefix, $mode) . '&nbsp;' . htmlentities($attr->getLabel($record, $mode)) . '</blockquote>';
                 }
             }
             $result .= '</div>';
         }
     }
     $result .= '</div>';
     return $result;
 }
Пример #18
0
 /**
  * Get the Smarty instance.
  *
  * @return \Smarty The one and only instance.
  */
 public static function getInstance()
 {
     static $s_smarty = null;
     if ($s_smarty == null) {
         Tools::atkdebug('Creating Smarty instance');
         $tplcompiledir = Config::getGlobal('tplcompiledir');
         if (!is_dir($tplcompiledir) && !mkdir($tplcompiledir, 0755, true)) {
             Tools::atkerror("Unable to create template compile directory: {$tplcompiledir}");
         }
         $tplcompiledir = realpath($tplcompiledir);
         $s_smarty = new Smarty();
         $s_smarty->setTemplateDir(Config::getGlobal('template_dir'));
         // name of directory for templates
         $s_smarty->autoload_filters = [];
         // indicates which filters will be auto-loaded
         $s_smarty->setCompileDir($tplcompiledir);
         // name of directory for compiled templates
         $s_smarty->setForceCompile(Config::getGlobal('tplforcecompile'));
         // force templates to compile every time,
         $s_smarty->addPluginsDir(__DIR__ . '/plugins');
         Tools::atkdebug('Instantiated new Smarty');
     }
     return $s_smarty;
 }
Пример #19
0
 /**
  * If the auto-select flag is set and only one record exists we immediately
  * return with the selected record.
  *
  * @param DataGrid $grid data grid
  *
  * @return bool auto-select active?
  */
 protected function autoSelectRecord($grid)
 {
     $node = $this->getNode();
     if (!$node->hasFlag(Node::NF_AUTOSELECT)) {
         return false;
     }
     $grid->loadRecords();
     if ($grid->getCount() != 1) {
         return false;
     }
     $sm = SessionManager::getInstance();
     if ($sm->atkLevel() > 0 && $grid->getPostvar('atkprevlevel', 0) > $sm->atkLevel()) {
         $backUrl = $sm->sessionUrl(Config::getGlobal('dispatcher') . '?atklevel=' . $sm->newLevel(SessionManager::SESSION_BACK));
         $node->redirect($backUrl);
     } else {
         $records = $grid->getRecords();
         // There's only one record and the autoselect flag is set, so we
         // automatically go to the target.
         $parser = new StringParser(rawurldecode(Tools::atkurldecode($grid->getPostvar('atktarget'))));
         // For backwardscompatibility reasons, we also support the '[pk]' var.
         $records[0]['pk'] = $node->primaryKey($records[0]);
         $target = $parser->parse($records[0], true);
         $node->redirect($sm->sessionUrl($target, SessionManager::SESSION_NESTED));
     }
     return true;
 }
Пример #20
0
 /**
  * This function renders the url that is used by
  * AdminHandler::getAddLink().
  *
  * @return string The url for the add link for the admin page
  */
 public function getAddUrl()
 {
     $atk = Atk::getInstance();
     $node = $atk->atkGetNode($this->invoke('getAddNodeType'));
     return Config::getGlobal('dispatcher') . '?atknodeuri=' . $node->atkNodeUri() . '&atkaction=add';
 }
Пример #21
0
 /**
  * Get TO_CHAR() equivalent for the current database.
  * Each database driver should override this method to perform vendor
  * specific conversion.
  *
  * @param string $fieldname The field to generate the to_char for.
  * @param string $format Format specifier. The format is compatible with
  *                          php's date() function (http://www.php.net/date)
  *                          The default is what's specified by
  *                          $config_date_to_char, or "Y-m-d" if not
  *                          set in the configuration.
  *
  * @return string Piece of sql query that converts a date field to char
  *                for the current database
  */
 public function func_datetochar($fieldname, $format = '')
 {
     if ($format == '') {
         $format = Config::getGlobal('date_to_char', 'Y-m-d');
     }
     return "DATE_FORMAT({$fieldname}, '" . $this->vendorDateFormat($format) . "')";
 }
Пример #22
0
 /**
  * Check if the system has multibyte support.
  *
  * @return bool
  */
 public static function hasMultiByteSupport()
 {
     if (self::$s_hasMultiByteSupport === null) {
         if (function_exists('mb_strlen') && Config::getGlobal('use_mbstring', true)) {
             mb_internal_encoding(self::atkGetCharset());
             self::$s_hasMultiByteSupport = true;
         } else {
             self::$s_hasMultiByteSupport = false;
         }
     }
     return self::$s_hasMultiByteSupport;
 }
Пример #23
0
 /**
  * Set the directory that the cache should be written in.
  */
 protected function setCachePath()
 {
     $this->m_path = $this->getCacheConfig('path', Config::getGlobal('atktempdir') . 'cache/') . $this->getFileSafeNamespace() . '/';
     FileAttribute::mkdir($this->m_path);
 }
Пример #24
0
 /**
  * Function returns a generic html form for editing a record.
  *
  * @param string $mode The edit mode ("add" or "edit").
  * @param array $record The record to edit.
  * @param array $forceList A key-value array used to preset certain
  *                             fields to a certain value.
  * @param array $suppressList An array of fields that will be hidden.
  * @param string $fieldprefix If set, each form element is prefixed with
  *                             the specified prefix (used in embedded
  *                             forms)
  * @param string $template The template to use for the edit form
  * @param bool $ignoreTab Ignore the tabs an attribute should be shown on.
  *
  * @return string the edit form as a string
  */
 public function editForm($mode = 'add', $record = null, $forceList = '', $suppressList = '', $fieldprefix = '', $template = '', $ignoreTab = false)
 {
     $node = $this->m_node;
     /* get data, transform into form, return */
     $data = $node->editArray($mode, $record, $forceList, $suppressList, $fieldprefix, $ignoreTab);
     // Format some things for use in tpl.
     /* check for errors and display them */
     $tab = $node->getActiveTab();
     $error_title = '';
     $pk_err_attrib = [];
     $tabs = $node->getTabs($node->m_action);
     // Handle errors
     $errors = [];
     if (count($data['error']) > 0) {
         $error_title = '<b>' . Tools::atktext('error_formdataerror') . '</b>';
         foreach ($data['error'] as $error) {
             if ($error['err'] == 'error_primarykey_exists') {
                 $pk_err_attrib[] = $error['attrib_name'];
             } else {
                 if (count($tabs) > 1 && $error['tab']) {
                     $tabLink = $this->getTabLink($node, $error);
                     $error_tab = ' (' . Tools::atktext('error_tab') . ' ' . $tabLink . ' )';
                 } else {
                     $tabLink = null;
                     $error_tab = '';
                 }
                 if (is_array($error['label'])) {
                     $label = implode(', ', $error['label']);
                 } else {
                     if (!empty($error['label'])) {
                         $label = $error['label'];
                     } else {
                         if (!is_array($error['attrib_name'])) {
                             $label = $node->text($error['attrib_name']);
                         } else {
                             $label = [];
                             foreach ($error['attrib_name'] as $attrib) {
                                 $label[] = $node->text($attrib);
                             }
                             $label = implode(', ', $label);
                         }
                     }
                 }
                 /* Error messages should be rendered in templates using message, label and the link to the tab. */
                 $err = array('message' => $error['msg'], 'tablink' => $tabLink, 'label' => $label);
                 /*
                  * @deprecated: For backwards compatibility, we still support the msg variable as well.
                  * Although the message, tablink variables should be used instead of msg and tab.
                  */
                 $err = array_merge($err, array('msg' => $error['msg'] . $error_tab));
                 $errors[] = $err;
             }
         }
         if (count($pk_err_attrib) > 0) {
             // Make primary key error message
             $pk_err_msg = '';
             for ($i = 0; $i < count($pk_err_attrib); ++$i) {
                 $pk_err_msg .= Tools::atktext($pk_err_attrib[$i], $node->m_module, $node->m_type);
                 if ($i + 1 < count($pk_err_attrib)) {
                     $pk_err_msg .= ', ';
                 }
             }
             $errors[] = array('label' => Tools::atktext('error_primarykey_exists'), 'message' => $pk_err_msg);
         }
     }
     /* display the edit fields */
     $fields = [];
     $errorFields = [];
     $attributes = [];
     for ($i = 0, $_i = count($data['fields']); $i < $_i; ++$i) {
         $field =& $data['fields'][$i];
         $tplfield = $this->createTplField($data['fields'], $i, $mode, $tab);
         $fields[] = $tplfield;
         // make field available in numeric array
         $params[isset($field['name']) ? $field['name'] : null] = $tplfield;
         // make field available in associative array
         $attributes[isset($field['name']) ? $field['name'] : null] = $tplfield;
         // make field available in associative array
         if (!empty($field['error'])) {
             $errorFields[] = $field['id'];
         }
     }
     $ui = $this->getUi();
     $page = $this->getPage();
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/formsubmit.js');
     // register fields that contain errornous values
     $page->register_scriptcode('var atkErrorFields = ' . Json::encode($errorFields) . ';');
     if (Config::getGlobal('lose_changes_warning', true)) {
         // If we are in the save or update action the user has added a nested record, has done
         // a selection using the select handler or generated an error, in either way we assume
         // the form has been changed, so we always warn the user when leaving the page.
         $isChanged = 'false';
         if (isset($record['atkerror']) && count($record['atkerror']) > 0 || isset($this->m_node->m_postvars['__atkunloadhelper']) && $this->m_node->m_postvars['__atkunloadhelper']) {
             $isChanged = 'true';
         }
         $unloadText = addslashes($this->m_node->text('lose_changes_warning'));
         $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkunloadhelper.js');
         $page->register_loadscript("new ATK.UnloadHelper('entryform', '{$unloadText}', {$isChanged});");
     }
     $result = '';
     foreach ($data['hide'] as $hidden) {
         $result .= $hidden;
     }
     $params['activeTab'] = $tab;
     $params['fields'] = $fields;
     // add all fields as a numeric array.
     $params['attributes'] = $attributes;
     // add all fields as an associative array
     $params['errortitle'] = $error_title;
     $params['errors'] = $errors;
     // Add the list of errors.
     Tools::atkdebug("Render editform - {$template}");
     if ($template) {
         $result .= $ui->render($template, $params);
     } else {
         $tabTpl = $this->_getTabTpl($node, $tabs, $mode, $record);
         $params['fieldspart'] = $this->_renderTabs($fields, $tabTpl);
         $result .= $ui->render('editform_common.tpl', $params);
     }
     return $result;
 }
Пример #25
0
 /**
  * This function returns password or false, if password can't be retrieve/recreate.
  *
  * @param string $username User for which the password should be regenerated
  *
  * @return mixed string with password or false
  */
 public function getPassword($username)
 {
     $configUser = Config::getGlobal('user');
     if (isset($configUser[$username]['password'])) {
         return $configUser[$username]['password'];
     }
     return false;
 }
Пример #26
0
 public function registerModule($moduleClass)
 {
     $reflection = new \ReflectionClass($moduleClass);
     $name = $reflection->getStaticPropertyValue('module');
     $this->g_modules[$name] = $moduleClass;
     if (!self::isModule($name)) {
         Tools::atkdebug("Constructing a new module - {$name}");
         $modClass = $this->g_modules[$name];
         /** @var Menu $menuClass */
         $menuClass = Config::getGlobal('menu');
         $menu = $menuClass::getInstance();
         /* @var \Sintattica\Atk\Core\Module $module */
         $module = new $modClass(static::$s_instance, $menu);
         $this->g_moduleRepository[$name] = $module;
         $module->register();
     }
 }
Пример #27
0
 /**
  * Apply posted (normal) search criteria to query.
  *
  * @param Query $query query object
  * @param array $attrsByLoadType attributes by load type
  */
 protected function _applyPostedSearchCriteriaToQuery(Query $query, array $attrsByLoadType)
 {
     $searchCriteria = Tools::atkArrayNvl($this->_getNode()->m_postvars, 'atksearch');
     if (!is_array($searchCriteria) || count($searchCriteria) == 0) {
         return;
     }
     foreach ($searchCriteria as $key => $value) {
         if ($value === null || $value === '' || $this->m_mode != 'admin' && $this->m_mode != 'export' && !array_key_exists($key, $attrsByLoadType[Attribute::ADDTOQUERY])) {
             continue;
         }
         $attr = $this->_getNode()->getAttribute($key);
         if (is_object($attr)) {
             if (is_array($value) && isset($value[$key]) && count($value) == 1) {
                 $value = $value[$key];
             }
             $searchMode = $this->_getNode()->getSearchMode();
             if (is_array($searchMode)) {
                 $searchMode = $searchMode[$key];
             }
             if ($searchMode == null) {
                 $searchMode = Config::getGlobal('search_defaultmode');
             }
             $attr->searchCondition($query, $this->_getNode()->getTable(), $value, $searchMode, '');
         } else {
             Tools::atkdebug("Using default search method for {$key}");
             //$condition = 'LOWER('.$this->_getNode()->getTable().'.'.$key.") LIKE LOWER('%".$this->_getDb()->escapeSQL($value, true)."%')";
             $condition = $this->_getNode()->getTable() . '.' . $key . " LIKE '%" . $this->_getDb()->escapeSQL($value, true) . "%'";
             $query->addSearchCondition($condition);
         }
     }
 }
Пример #28
0
 /**
  * Determine the export selections that should be displayed.
  *
  * @return array
  */
 protected function getExportSelections()
 {
     $where = ' nodetype = "' . $this->m_postvars['atknodeuri'] . '"';
     if ('none' !== strtolower(Config::getGlobal('authentication'))) {
         $user = SecurityManager::atkGetUser();
         if ('administrator' !== strtolower($user['name'])) {
             $where .= ' AND user_id IN( 0, ' . (int) $user[Config::getGlobal('auth_userpk')] . ' )';
         }
     }
     $db = Db::getInstance();
     return $db->getRows($query = 'SELECT id, name FROM atk_exportcriteria WHERE ' . $where . ' ORDER BY name');
 }
Пример #29
0
 /**
  * Get the base directory for writing
  * Will default to the atktmp dir.
  */
 public function getBasedir()
 {
     if (!$this->m_basedir) {
         $this->m_basedir = Config::getGlobal('atktempdir');
     }
     return $this->m_basedir;
 }
Пример #30
0
 /**
  * Handle the error.
  *
  * @param string $errorMessage
  * @param string $debugMessage
  */
 public function handle($errorMessage, $debugMessage)
 {
     $sessionManager = SessionManager::getInstance();
     $sessionData =& SessionManager::getSession();
     $txt_app_title = Tools::atktext('app_title');
     if ($this->params['mailto'] != '') {
         // only if enabled..
         $atk = Atk::getInstance();
         $subject = '[' . $_SERVER['SERVER_NAME'] . "] {$txt_app_title} error";
         $defaultfrom = sprintf('%s <%s@%s>', $txt_app_title, Config::getGlobal('identifier', 'atk'), $_SERVER['SERVER_NAME']);
         $from = Config::getGlobal('mail_sender', $defaultfrom);
         $body = "Hello,\n\nAn error seems to have occurred in the atk application named '{$txt_app_title}'.\n";
         $body .= "\nThe errormessage was:\n\n" . implode("\n", is_array($errorMessage) ? $errorMessage : array()) . "\n";
         $body .= "\nA detailed report follows:\n";
         $body .= "\nPHP Version: " . phpversion() . "\n\n";
         $body .= "\nDEBUGMESSAGES\n" . str_repeat('-', 70) . "\n";
         $lines = [];
         for ($i = 0, $_ = count($debugMessage); $i < $_; ++$i) {
             $lines[] = $this->_wordwrap(Tools::atk_html_entity_decode(preg_replace('(\\[<a.*</a>\\])', '', $debugMessage[$i])));
         }
         $body .= implode("\n", $lines);
         if (is_array($_GET)) {
             $body .= "\n\n_GET\n" . str_repeat('-', 70) . "\n";
             foreach ($_GET as $key => $value) {
                 $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
             }
         }
         if (function_exists('getallheaders')) {
             $request = getallheaders();
             if (count($request) > 0) {
                 $body .= "\n\nREQUEST INFORMATION\n" . str_repeat('-', 70) . "\n";
                 foreach ($request as $key => $value) {
                     $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
                 }
             }
         }
         if (is_array($_POST)) {
             $body .= "\n\n_POST\n" . str_repeat('-', 70) . "\n";
             foreach ($_POST as $key => $value) {
                 $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
             }
         }
         if (is_array($_COOKIE)) {
             $body .= "\n\n_COOKIE\n" . str_repeat('-', 70) . "\n";
             foreach ($_COOKIE as $key => $value) {
                 $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
             }
         }
         $body .= "\n\nATK CONFIGURATION\n" . str_repeat('-', 70) . "\n";
         foreach ($GLOBALS as $key => $value) {
             if (substr($key, 0, 7) == 'config_') {
                 $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
             }
         }
         $body .= "\n\nMODULE CONFIGURATION\n" . str_repeat('-', 70) . "\n";
         foreach ($atk->g_modules as $modname => $modpath) {
             $modexists = file_exists($modpath) ? ' (path exists)' : ' (PATH DOES NOT EXIST!)';
             $body .= $this->_wordwrap($modname . ':' . str_repeat(' ', max(1, 20 - strlen($modname))) . var_export($modpath, 1) . $modexists) . "\n";
         }
         $body .= "\n\nCurrent User:\n" . str_repeat('-', 70) . "\n";
         $user = SecurityManager::atkGetUser();
         if (is_array($user) && count($user)) {
             foreach ($user as $key => $value) {
                 $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
             }
         } else {
             $body .= "Not known\n";
         }
         if (is_object($sessionManager)) {
             $body .= "\n\nATK SESSION\n" . str_repeat('-', 70);
             $body .= "\nNamespace: " . $sessionManager->getNameSpace() . "\n";
             if (isset($sessionData[$sessionManager->getNameSpace()]['stack'])) {
                 $stack = $sessionData[$sessionManager->getNameSpace()]['stack'];
                 for ($i = 0; $i < count($stack); ++$i) {
                     $body .= "\nStack level {$i}:\n";
                     $item = isset($stack[$i]) ? $stack[$i] : null;
                     if (is_array($item)) {
                         foreach ($item as $key => $value) {
                             $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
                         }
                     }
                 }
             }
             if (isset($sessionData[$sessionManager->getNameSpace()]['globals'])) {
                 $ns_globals = $sessionData[$sessionManager->getNameSpace()]['globals'];
                 if (count($ns_globals) > 0) {
                     $body .= "\nNamespace globals:\n";
                     foreach ($ns_globals as $key => $value) {
                         $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
                     }
                 }
             }
             if (isset($sessionData['globals'])) {
                 $globals = $sessionData['globals'];
                 if (count($globals) > 0) {
                     $body .= "\nGlobals:\n";
                     foreach ($globals as $key => $value) {
                         $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
                     }
                 }
             }
         }
         $body .= "\n\nSERVER INFORMATION\n" . str_repeat('-', 70) . "\n";
         foreach ($_SERVER as $key => $value) {
             $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n";
         }
         //TODO: replace with some mailer object
         mail($this->params['mailto'], $subject, $body, "From: {$from}");
     }
 }