作者:sintattic
项目:at
/**
* Copies a record, based on parameters passed in the url.
*/
public function nodeCopy()
{
Tools::atkdebug('CopyHandler::nodeCopy()');
$recordset = $this->m_node->select($this->m_postvars['atkselector'])->mode('copy')->getAllRows();
$db = $this->m_node->getDb();
if (count($recordset) > 0) {
// allowed to copy record?
if (!$this->allowed($recordset[0])) {
$this->renderAccessDeniedPage();
return;
}
if (!$this->m_node->copyDb($recordset[0])) {
Tools::atkdebug('node::action_copy() -> Error');
$db->rollback();
$location = $this->m_node->feedbackUrl('save', self::ACTION_FAILED, $recordset[0], $db->getErrorMsg());
Tools::atkdebug('node::action_copy() -> Redirect');
$this->m_node->redirect($location);
} else {
$db->commit();
$this->notify('copy', $recordset[0]);
$this->clearCache();
}
}
$this->m_node->redirect();
}
作者:sintattic
项目:at
/**
* Register change handler.
*
* @param string $mode
* @param string $prefix
*/
protected function registerChangeHandler($mode, $prefix)
{
$mode = $mode == 'add' ? 'add' : 'edit';
$url = addslashes(Tools::partial_url($this->m_shuttle->m_ownerInstance->atkNodeUri(), $mode, 'attribute.' . $this->m_shuttle->getHtmlId($prefix) . '.filter', array('atkfieldprefix' => $prefix)));
$page = $this->m_shuttle->m_ownerInstance->getPage();
$page->register_scriptcode('function ' . $this->getChangeHandlerName($prefix) . "(el)\n {\n shuttle_refresh('" . $url . "', '" . $this->m_shuttle->getHtmlId($prefix) . '[cselected][][' . $this->m_shuttle->getRemoteKey() . ']' . "', '" . $prefix . $this->m_shuttle->fieldName() . "[section]', '" . $this->m_section . "')\n }\n");
}
作者:sintattic
项目:at
/**
* function to get multilanguage strings.
*
* This is actually a wrapper for ATK's Tools::atktext() method, for
* use in templates.
*
* @author Ivo Jansch <ivo@achievo.org>
*
* Example: {atktext id="users.userinfo.description"}
* {atktext id="userinfo.description" module="users"}
* {atktext id="description" module="users" node="userinfo"}
*/
function smarty_function_atktext($params, $smarty)
{
if (!isset($params['id'])) {
$params['id'] = $params[0];
}
switch (substr_count($params['id'], '.')) {
case 1:
list($module, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, isset($params['node']) ? $params['node'] : '');
break;
case 2:
list($module, $node, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, $node);
break;
default:
$str = Tools::atktext($params['id'], Tools::atkArrayNvl($params, 'module', ''), Tools::atkArrayNvl($params, 'node', ''), Tools::atkArrayNvl($params, 'lng', ''));
}
if (isset($params['filter'])) {
$fn = $params['filter'];
$str = $fn($str);
}
// parse the rest of the params in the string
$parser = new StringParser($str);
return $parser->parse($params);
}
作者:sintattic
项目:at
/**
* Function for embedding a date control in html.
*
* @author Peter C. Verhage <peter@ibuildings.nl>
*/
function smarty_function_atkdatefield($params, $smarty)
{
$name = isset($params['name']) ? $params['name'] : 'date';
$format = isset($params['format']) ? $params['format'] : Tools::atktext('date_format_edit', 'atk', '', '', '', true);
$mandatory = isset($params['mandatory']) && $params['mandatory'] || isset($params['obligatory']) && $params['obligatory'];
$noweekday = isset($params['noweekday']) && $params['noweekday'];
$calendar = isset($params['calendar']) && $params['calendar'];
$time = isset($params['time']) ? $params['time'] : ($mandatory ? mktime() : null);
$min = isset($params['min']) ? $params['min'] : 0;
$max = isset($params['max']) ? $params['max'] : 0;
if (is_array($time)) {
$date = $time;
} else {
if ($time == null) {
$date = null;
} else {
if (is_numeric($time)) {
$date = getdate($time);
$date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
} else {
if (preg_match('/([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})/', $time, $matches)) {
$date = array('day' => (int) $matches[1], 'month' => (int) $matches[2], 'year' => $matches[3]);
} else {
$date = getdate(strtotime($time));
$date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
}
}
}
}
$attr = new DateAttribute($name, $format, '', $min, $max, ($noweekday ? DateAttribute::AF_DATE_EDIT_NO_DAY : 0) | ($mandatory ? Attribute::AF_OBLIGATORY : 0) | ($calendar ? 0 : DateAttribute::AF_DATE_NO_CALENDAR));
$html = $attr->edit(array($name => $date), '', '');
return $html;
}
作者:sintattic
项目:at
/**
* Translates a menuitem with the menu_ prefix, or if not found without.
*
* @param string $menuitem Menuitem to translate
* @param string $modname Module to which the menuitem belongs
*
* @return string Translation of the given menuitem
*/
public function getMenuTranslation($menuitem, $modname = 'atk')
{
$s = Tools::atktext("menu_{$menuitem}", $modname, '', '', '', true);
if (!$s) {
$s = Tools::atktext($menuitem, $modname);
}
return $s;
}
作者:sintattic
项目:at
/**
* get a singleton instance of the Ui class.
*
* @return Ui
*/
public static function getInstance()
{
static $s_instance = null;
if ($s_instance == null) {
Tools::atkdebug('Creating a new Ui instance');
$s_instance = new self();
}
return $s_instance;
}
作者:sintattic
项目:at
/**
* Converts the given node flags to recordlist flags where possible.
*
* @param int $flags
* @static
*
* @return int
*/
public function convertFlags($flags)
{
$result = Tools::hasFlag($flags, Node::NF_MRA) ? self::RL_MRA : 0;
$result |= Tools::hasFlag($flags, Node::NF_MRPA) ? self::RL_MRPA : 0;
$result |= Tools::hasFlag($flags, Node::NF_NO_SEARCH) ? self::RL_NO_SEARCH : 0;
$result |= Tools::hasFlag($flags, Node::NF_NO_EXTENDED_SEARCH) ? self::RL_NO_EXTENDED_SEARCH : 0;
$result |= Tools::hasFlag($flags, Node::NF_EXT_SORT) ? self::RL_EXT_SORT : 0;
return $result;
}
作者:sintattic
项目:at
/**
* Notify the listener of any action on a record.
*
* This method is called by the framework for each action called on a
* node. Depending on the actionfilter passed in the constructor, the
* call is forwarded to the actionPerformed($action, $record) method.
*
* @param string $trigger The trigger being performed
* @param array $record The record on which the trigger is performed
* @param string $mode The mode (add/update)
*
* @return bool Result of operation.
*/
public function notify($trigger, &$record, $mode = null)
{
if (method_exists($this, $trigger)) {
Tools::atkdebug('Call listener ' . get_class($this) . " for trigger {$trigger} on " . $this->m_node->atkNodeUri() . ' (' . $this->m_node->primaryKey($record) . ')');
return $this->{$trigger}($record, $mode);
} else {
return true;
}
}
作者:sintattic
项目:at
/**
* Constructor.
*
* @param string $name The name of the attribute
* @param int $flags The flags for this attribute
* @param string $text The text to display
*/
public function __construct($name, $flags = 0, $text = '')
{
// A Dummy attrikbute should not be searchable and sortable
$flags |= self::AF_HIDE_SEARCH | self::AF_NO_SORT;
// Add the self::AF_BLANKLABEL flag unless the self::AF_DUMMY_SHOW_LABEL flag wasn't present
if (!Tools::hasFlag($flags, self::AF_DUMMY_SHOW_LABEL)) {
$flags |= self::AF_BLANKLABEL;
}
parent::__construct($name, $flags);
// base class constructor
$this->m_text = $text;
}
作者:sintattic
项目:at
/**
* Constructor.
*
* @param string $name Name of the attribute
* @param int $flags Flags for this attribute
* @param string $currencysymbol The symbol which is printed in front of the value.
* @param int $decimals The number of decimals (default 2)
* @param string $decimalseparator The separator which is printed for the decimals.
* @param string $thousandsseparator The separator which is printed for the thousands.
*/
public function __construct($name, $flags = 0, $currencysymbol = '', $decimals = 2, $decimalseparator = '', $thousandsseparator = '')
{
parent::__construct($name, $flags, $decimals);
$this->setAttribSize(10);
if ($currencysymbol == '') {
$currencysymbol = Tools::atktext('currencysymbol', 'atk', '', '', '', true);
}
$this->m_currencysymbol = $currencysymbol;
$this->m_decimalseparator = $decimalseparator != '' ? $decimalseparator : '.';
$this->m_thousandsseparator = $thousandsseparator != '' ? $thousandsseparator : ',';
$this->setUseThousandsSeparator(true);
}
作者:sintattic
项目:at
/**
* Get the selected record from.
*
* @return array the record to be copied
*/
protected function getCopyRecord()
{
$selector = $this->m_postvars['atkselector'];
$recordset = $this->m_node->select($selector)->mode('copy')->getAllRows();
if (count($recordset) > 0) {
return $recordset[0];
} else {
Tools::atkdebug("Geen records gevonden met selector: {$selector}");
$this->m_node->redirect();
}
return;
}
作者:sintattic
项目:at
/**
* Converts an ip (in number or string format) to a long number.
*
* The supplied ip must be a valid ip. If the given ip is not
* valid, then atkerror will be called.
*
* @static This function may be used statically
*
* @param mixed $ip String or long numeric IP address.
*
* @return bool True if the ip is valid, False if not.
*/
public static function ipLongFormat($ip)
{
if (!self::ipValidate($ip)) {
Tools::atkdebug('IpUtils::ipLongFormat() Invalid ip given');
return;
}
if (is_numeric($ip)) {
return $ip;
}
$array = explode('.', $ip);
return $array[3] + 256 * $array[2] + 256 * 256 * $array[1] + 256 * 256 * 256 * $array[0];
}
作者:sintattic
项目:at
/**
* Replace the bind parameters in the parsed query with their escaped values.
*
* @param array $params parameters
*
* @return string query
*/
protected function _bindParams($params)
{
$query = $this->_getParsedQuery();
Tools::atkdebug('Binding parameters for query: ' . $this->_getParsedQuery());
foreach (array_values($this->_getBindPositions()) as $i => $param) {
Tools::atkdebug("Bind param {$i}: " . ($params[$param] === null ? 'NULL' : $params[$param]));
}
foreach (array_reverse($this->_getBindPositions(), true) as $position => $param) {
$query = substr($query, 0, $position) . ($params[$param] === null ? 'NULL' : "'" . $this->getDb()->escapeSQL($params[$param]) . "'") . substr($query, $position + 1);
}
return $query;
}
作者:sintattic
项目:at
/**
* Export data to a download file.
*
* BROWSER BUG:
* IE has problems with the use of attachment; needs atachment (someone at MS can't spell) or none.
* however ns under version 6 accepts this also.
* NS 6+ has problems with the absense of attachment; and the misspelling of attachment;
* at present ie 5 on mac gives wrong filename and NS 6+ gives wrong filename.
*
* @todo Currently supports only csv/excel mimetypes.
*
* @param string $data The content
* @param string $fileName Filename for the download
* @param string $type The type (csv / excel / xml)
* @param string $ext Extension of the file
* @param string $compression Compression method (bzip / gzip)
*/
public function export($data, $fileName, $type, $ext = '', $compression = '')
{
ob_end_clean();
if ($compression == 'bzip') {
$mime_type = 'application/x-bzip';
$ext = 'bz2';
} elseif ($compression == 'gzip') {
$mime_type = 'application/x-gzip';
$ext = 'gz';
} elseif ($type == 'csv') {
$mime_type = 'text/x-csv';
$ext = 'csv';
} elseif ($type == 'excel') {
$mime_type = 'application/octet-stream';
$ext = 'xls';
} elseif ($type == 'xml') {
$mime_type = 'text/xml';
$ext = 'xml';
} else {
$mime_type = 'application/octet-stream';
}
header('Content-Type: ' . $mime_type);
header('Content-Disposition: filename="' . $fileName . '.' . $ext . '"');
// Fix for downloading (Office) documents using an SSL connection in
// combination with MSIE.
if (($_SERVER['SERVER_PORT'] == '443' || Tools::atkArrayNvl($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') && preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) {
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
header('Expires: 0');
// 1. as a bzipped file
if ($compression == 'bzip') {
if (@function_exists('bzcompress')) {
echo bzcompress($data);
}
} else {
if ($compression == 'gzip') {
if (@function_exists('gzencode')) {
// without the optional parameter level because it bug
echo gzencode($data);
}
} else {
if ($type == 'csv' || $type == 'excel') {
// in order to output UTF-8 content that Excel both on Windows and OS X will be able to successfully read
echo mb_convert_encoding($data, 'Windows-1252', 'UTF-8');
}
}
}
flush();
exit;
}
作者:sintattic
项目:at
/**
* Implements the {atkmessages} plugin for use in templates.
*
* The {atkmessages} tag does not output anything. Instead, it loads
* the messages into the template variable {$atkmessages}, which is
* an array of elements, each with a single message.
*
* <b>Example:</b>
* <code>
* {atkmessages}
*
* {foreach from=$atkmessages item=message}
* {$message.message}<br>
* {/foreach}
* </code>
*
* @author Patrick van der Velden <patrick@ibuildings.nl>
*/
function smarty_function_atkmessages($params, $smarty)
{
$sessionManager = SessionManager::getInstance();
if (is_object($sessionManager)) {
$msgs = MessageQueue::getMessages();
$smarty->assign('atkmessages', $msgs);
if (empty($msgs)) {
Tools::atkdebug('No messages in MessageQueue');
}
return '';
}
return '';
}
作者:sintattic
项目:at
/**
* The decryption method for decrypting data with the bajus algorithm.
*
* @param mixed $input the data we want to encrypt
* @param mixed $key the key we want to encrypt the data with
*
* @return mixed the encrypted data
*/
public function decrypt($input, $key)
{
$input = $this->addbackslashes($input);
$keys = $this->getKeys($key);
$key = openssl_get_privatekey($keys['private']);
if ($key) {
Tools::atkerror('OpenSSLEncryption::decrypt << not a valid key passed');
} else {
echo "decrypt for: input:{$input}, decrypted: {$decrypted}, key: {$key}";
openssl_private_decrypt($input, $decrypted, $key);
}
return $decrypted;
}
作者:sintattic
项目:at
public function search($record, $extended = false, $fieldprefix = '', DataGrid $grid = null)
{
$this->createDestination();
if ($this->m_destinationFilter != '') {
$sp = new StringParser($this->m_destinationFilter);
$this->m_destInstance->addFilter($sp->parse($record));
}
$recordset = $this->m_destInstance->select()->includes(Tools::atk_array_merge($this->m_destInstance->descriptorFields(), $this->m_destInstance->m_primaryKey))->getAllRows();
$result = '<select class="form-control" name="atksearch[' . $this->fieldName() . ']">';
$result .= '<option value="">' . Tools::atktext('search_all', 'atk');
$result .= $this->createdd($recordset);
$result .= '</select>';
return $result;
}
作者:sintattic
项目:at
/**
* Bind statement parameters.
*
* @param array $params parameters
*/
private function _bindParams($params)
{
if (count($params) == 0) {
return;
}
$i = 0;
$args = [];
$args[] = str_repeat('s', count($this->_getBindPositions()));
foreach ($this->_getBindPositions() as $param) {
Tools::atkdebug("Bind param {$i}: " . ($params[$param] === null ? 'NULL' : $params[$param]));
$args[] =& $params[$param];
++$i;
}
call_user_func_array(array($this->m_stmt, 'bind_param'), $args);
}
作者:sintattic
项目:at
/**
* Validates email address through regular expression and dns check.
*
* @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"
*/
public function validate(&$record, $mode)
{
$email = $record[$this->fieldName()];
//first check complete string
if (!self::validateAddressSyntax($email)) {
Tools::triggerError($record, $this, 'error_invalid_email');
} else {
if ($this->m_dnsSearch) {
//now check if domain exists, searches DNS for MX records
list(, $domain) = explode('@', $email, 2);
if (!self::validateAddressDomain($domain, false)) {
Tools::triggerError($record, $this->fieldName(), 'error_unkown_domain', Tools::atktext('error_unkown_domain') . ' ' . $domain);
}
}
}
}
作者:sintattic
项目:at
/**
* The method returns a complete html page containing the feedback info.
*
* @param string $action The action for which feedback is provided
* @param int $actionstatus The status of the action for which feedback is
* provided
* @param string $message An optional message to display in addition to the
* default feedback information message.
*
* @return string The feedback page as an html String.
*/
public function feedbackPage($action, $actionstatus, $message = '')
{
$node = $this->m_node;
$ui = $this->getUi();
$params['content'] = '<br>' . Tools::atktext('feedback_' . $action . '_' . Tools::atkActionStatus($actionstatus), $node->m_module, $node->m_type);
if ($message) {
$params['content'] .= ' <br>' . $message;
}
$sm = SessionManager::getInstance();
if ($sm->atkLevel() > 0) {
$params['formstart'] = '<form method="get">' . $sm->formState(SessionManager::SESSION_BACK);
$params['buttons'][] = '<input type="submit" class="btn btn-default btn_cancel" value="<< ' . Tools::atktext('back') . '">';
$params['formend'] = '</form>';
}
$output = $ui->renderAction($action, $params);
return $ui->renderBox(array('title' => $node->actionTitle($action), 'content' => $output));
}