';
$div .= ___('%s records on this page are selected. You can choose group operation in the select box below or %scancel%s',
''.$grid->getDataSource()->getFoundRows().'',
'', '') . PHP_EOL;
$div .= '
' . PHP_EOL;
$div .= '
' . PHP_EOL;
$div .= '' . PHP_EOL;
$output = substr_replace($output, $div, $start, 0);
$grid->_check_all_offer_added = true;
}
} Expandable.php 0000644 00000013413 15210162245 0007320 0 ustar 00 setGetFunction(array($this, 'expandableGet'));
parent::__construct($field, $title, $sortable, $align, $renderFunc, $width);
$this->isNeedExpand = array($this, '_defaultIsNeedExpand');
}
/**
*
* @param int $maxLength
* @return Am_Grid_Field_Expandable
*/
public function setMaxLength($maxLength)
{
$this->maxLength = (int) $maxLength;
return $this;
}
/**
* You can use variables like
* {user_id} and {getInvoiceId()} in the template
* it will be automatically fetched from record, escaped and substituted
*/
public function setAjax($url)
{
$this->isAjax = true;
$this->url = $url;
return $this;
}
/**
*
* @param string $placeholder
* @return Am_Grid_Field_Expandable
*/
public function setPlaceholder($placeholder)
{
$this->placeholder = $placeholder;
return $this;
}
public function render($obj, $controller)
{
$val = $this->get($obj, $controller, $this->field);
if (!$this->isNeedExpand($val, $obj)) {
return parent::render($obj, $controller);
} else {
$align_class = $this->align ? ' align_' . $this->align : null;
$placeholder = $this->getPlaceholder($val, $obj);
$data_class = ($this->isHtml ? ' isHtml' : '') .
($this->isAjax ? ' isAjax' : '') .
($this->isSafeHtml ? ' isSafeHtml' : '');
$data_val = $controller->escape($this->isAjax ? $this->parseUrl($this->url, $obj) : $val);
$id = "{$controller->getId()}-$this->field-{$controller->getDataSource()->getIdForRecord($obj)}";
$out = <<
$placeholder
CUT;
}
return $out;
}
function setIsNeedExpandFunction($func)
{
$this->isNeedExpand = $func;
return $this;
}
protected function isNeedExpand($val, $obj)
{
return call_user_func($this->isNeedExpand, $val, $obj, $this->field, $this);
}
function _defaultIsNeedExpand($val, $obj, $field, $fieldObj)
{
return $this->isAjax || mb_strlen($val) > $this->maxLength;
}
protected function parseUrl($url, $record)
{
$that = $this;
$ret = preg_replace_callback('|{(.+?)}|', function($matches) use ($that, $record) {
return $that->_pregReplace($matches, $record);
}, $url);
if ((strpos($ret, 'http')!==0) && ($ret[0] != '/'))
$ret = Am_Di::getInstance()->url($ret,null,false);
return $ret;
}
public function _pregReplace($matches, $record)
{
$var = $matches[1];
if ($var == 'THIS_URL') {
$ret = Am_Di::getInstance()->request->getRequestUri();
} elseif (preg_match('|^(.+)\(\)$|', $var, $regs)) {
$ret = call_user_func(array($record, $regs[1]));
} else {
$ret = $record->{$var};
}
return urlencode($ret);
}
/**
*
* @param string $val
* @return string html code of placeholder
*/
protected function getPlaceholder($val, $obj)
{
if (is_null($this->placeholder) || $this->placeholder == self::PLACEHOLDER_SELF_TRUNCATE_END) {
$placeholder = htmlentities(mb_substr($val, 0, $this->maxLength), null, 'UTF-8') . ( mb_strlen($val) > $this->maxLength ? '…' : '');
} elseif ($this->placeholder == self::PLACEHOLDER_SELF_TRUNCATE_BEGIN) {
$placeholder = ( mb_strlen($val) > $this->maxLength ? '…' : '') . htmlentities(mb_substr($val, -1 * $this->maxLength), null, 'UTF-8');
} elseif(is_callable($this->placeholder)) {
$placeholder = call_user_func($this->placeholder, $val, $obj);
} else {
$placeholder = htmlentities($this->placeholder, null, 'UTF-8');
}
return $placeholder;
}
public function expandableGet($obj, $controller, $field)
{
$val = $obj->{$field};
if (!$val) return $val;
// try unserialize
if (is_string($val)) {
if (($x = @unserialize($val)) !== false)
$val = $x;
}
switch (true)
{
case is_array($val) :
$out = '';
foreach ($val as $k => $v)
$out .= $k . ' = ' . ((is_array($v)) ? print_r($v, true) : (string) $v) . PHP_EOL;
return $out;
case is_object($val) :
return get_class($val) . "\n" . (string) $obj;
}
return $val;
}
public function setEscape($flag = null)
{
$ret = ! $this->isHtml;
if ($flag !== null) $this->isHtml = ! $flag;
return $ret;
}
public function setSafeHtml($flag)
{
$this->isSafeHtml = $flag;
return $this;
}
public function renderStatic()
{
$view = new Am_View;
$url = $view->escape($view->_scriptJs('htmlreg.js'));
return parent::renderStatic() .
' ';
}
}
Data.php 0000644 00000000706 15210162245 0006127 0 ustar 00 setGetFunction(array($this, '_get'));
}
public function _get(Am_Record_WithData $record, $fontroller, $field)
{
return $record->data()->get($field);
}
} Date.php 0000644 00000002071 15210162245 0006130 0 ustar 00 setFormatFunction(array($this, '_format'));
}
public function setFormatTime(){ $this->format = self::TIME; return $this;}
public function setFormatDatetime(){ $this->format = self::DATETIME; return $this;}
public function setFormatDate(){ $this->format = self::DATE; return $this;}
public function _format($d)
{
if (trim($d)=='') return '';
if ($d == Am_Period::MAX_SQL_DATE) return ___('Lifetime');
switch ($this->format)
{
case self::DATE:
return amDate($d);
case self::TIME:
return amTime($d);
default:
return amDatetime($d);
}
}
} Decorator/Link.php 0000644 00000001604 15210162245 0010073 0 ustar 00 target = $target;
}
function setTarget($target)
{
$this->target = $target;
}
public function render(&$out, $obj, $controller)
{
$url = $this->parseTpl($obj);
$target = $this->target ? " target=\"$this->target\"" : null;
$start = sprintf('',
htmlentities($url, ENT_QUOTES, 'UTF-8'),
$target
);
$stop = '';
$out = preg_replace('|()(.+)()|', '\1'.$start.'\2'.$stop.'\3', $out);
}
} Decorator/Tpl.php 0000644 00000002634 15210162245 0007741 0 ustar 00 setTpl($tpl);
}
/**
* You can use variables like
* {user_id} and {getInvoiceId()} in the template
* it will be automatically fetched from record, escaped and substituted
*/
function setTpl($tpl)
{
$this->tpl = $tpl;
}
protected function parseTpl($record)
{
$this->_record = $record;
$ret = preg_replace_callback('|{(.+?)}|', array($this, '_pregReplace'), $this->tpl);
unset($this->_record);
if ((strpos($ret, 'http')!==0) && ($ret[0] != '/')) {
$ret = Am_Di::getInstance()->url($ret, false);
}
return $ret;
}
public function _pregReplace($matches)
{
$var = $matches[1];
if ($var == 'THIS_URL') {
$ret = Am_Di::getInstance()->request->getRequestUri();
} elseif (preg_match('|^(.+)\(\)$|', $var, $regs)) {
$ret = call_user_func(array($this->_record, $regs[1]));
} else {
$ret = $this->_record->{$var};
}
return htmlentities(urlencode($ret), ENT_QUOTES, 'UTF-8');
}
public function render(&$out, $obj, $controller)
{
$content = $this->parseTpl($obj);
$out = preg_replace('|()(.+)()|', '\1'.$content.'\3', $out);
}
} Decorator/Abstract.php 0000644 00000000736 15210162245 0010746 0 ustar 00 field = $field;
}
function render(& $out, $obj, $controller) { }
function get(& $out, $obj, $controller, $field) { }
function renderTitle(& $out, $controller) { }
function renderStatic(& $out) { }
}
Decorator/Attrs.php 0000644 00000001341 15210162245 0010271 0 ustar 00 hAttrs = $hAttrs;
$this->dAttrs = $dAttrs;
}
public function render(&$out, $obj, $grid)
{
if ($this->dAttrs) {
$attrs = Am_Html::attrs($this->dAttrs);
$out = preg_replace('|()|', '\1 '.$attrs.'\2', $out);
}
}
function renderTitle(&$out, $grid)
{
if ($this->hAttrs) {
$attrs = Am_Html::attrs($this->hAttrs);
$out = preg_replace('|()|', '\1 '.$attrs.'\2', $out);
}
}
} Decorator/Shorten.php 0000644 00000001341 15210162245 0010616 0 ustar 00 len = $len;
parent::__construct();
}
public function render(&$out, $obj, $controller)
{
$out = preg_replace_callback('|()(.+)()|i', array($this, '_cb'), $out);
}
public function _cb($regs)
{
if (strlen($regs[2]) > $this->len)
{
$regs[2] = sprintf('%s',
htmlentities($regs[2], ENT_QUOTES, 'UTF-8'),
substr($regs[2], 0, $this->len) . '...');
}
$val = $regs[1] . $regs[2] . $regs[3];
return $val;
}
} Decorator/LiveSelect.php 0000644 00000003754 15210162245 0011245 0 ustar 00 action = $action;
parent::__construct();
}
public function render(&$out, $obj, $grid)
{
$options = $this->action->getOptions();
$wrap = $this->getWrapper($obj, $grid);
preg_match('{()(.*)()}is', $out, $match);
$out = $match[1] . ''. $wrap[0]
. ($match[2] ? $grid->escape($options[$match[2]]) : $grid->escape($this->action->getPlaceholder()))
. $wrap[1] . $match[3];
}
protected function divideUrlAndParams($url)
{
$ret = explode('?', $url, 2);
if (count($ret)<=1) return array($ret[0], null);
parse_str($ret[1], $params);
return array($ret[0], $params);
}
protected function getWrapper($obj, $grid)
{
$id = $this->action->getIdForRecord($obj);
$val = $obj->{$this->field->getFieldName()};
list($url, $params) = $this->divideUrlAndParams($this->action->getUrl($obj, $id));
$start = sprintf('',
$val ? '' : ' live-edit-placeholder',
$grid->getId() . '_' . $this->field->getFieldName() . '-' . $grid->escape($id),
$url,
$grid->escape(json_encode($params)),
$grid->escape($this->action->getPlaceholder()),
$grid->escape(json_encode($this->action->getOptions())),
$grid->escape(sprintf('', Am_Html::renderOptions($this->action->getOptions()))),
$grid->escape($val)
);
$stop = '';
return array($start, $stop);
}
} Decorator/LiveCheckbox.php 0000644 00000003342 15210162245 0011545 0 ustar 00 action = $action;
parent::__construct();
}
public function render(&$out, $obj, $grid)
{
$content = $this->getContent($obj, $grid);
preg_match('{()(.*)()}i', $out, $match);
$out = $match[1] . $content . $match[3];
}
protected function divideUrlAndParams($url)
{
$ret = explode('?', $url, 2);
if (count($ret) <= 1)
return array($ret[0], null);
parse_str($ret[1], $params);
return array($ret[0], $params);
}
protected function getContent($obj, Am_Grid_Editable $grid)
{
if (!$this->action->isAvailable($obj)) return;
$id = $this->action->getIdForRecord($obj);
$val = $obj->{$this->field->getFieldName()};
list($url, $params) = $this->divideUrlAndParams($this->action->getUrl($obj, $id));
$content = sprintf('',
$grid->escape($grid->getId() . '_' . $this->field->getFieldName() . '-' . $grid->escape($id)),
$grid->escape($url),
$id, $grid->escape(json_encode($params)),
$grid->escape($this->action->getValue()), $grid->escape($this->action->getEmptyValue()),
(($val == $this->action->getValue()) ? 'checked ' : ''));
return $content;
}
} Decorator/DetailGrid.php 0000644 00000004103 15210162245 0011203 0 ustar 00 title = $title;
$this->fnName = $fnName;
if (empty($this->fnName))
$this->fnName = 'dg_'. str_replace('.', '', microtime(true));
parent::__construct($tpl);
}
public function render(&$out, $obj, $controller)
{
$url = $this->parseTpl($obj);
$start = sprintf('',
$this->fnName, htmlentities($url, ENT_QUOTES, 'UTF-8')
);
$stop = '';
$out = preg_replace('|()(.+)()|', '\1'.$start.'\2'.$stop.'\3', $out);
}
public function renderStatic(&$out)
{
$title = json_encode($this->title);
$out .= <<
jQuery(document).on('click',".grid-detail-link", function(event){
var href = this.href;
var field = jQuery(this).data("field");
event.stopPropagation();
if (!jQuery(".grid-detail-dialog.grid-detail-field" + field).length)
jQuery("body").append("");
var div = jQuery(".grid-detail-dialog:first");
div.data('href', href);
jQuery(div).load(href,
function(){
if (!div.find('grid-wrap').length)
{
div.html("