Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/db_tag_processor.php
Show First 20 Lines • Show All 2590 Lines • ▼ Show 20 Line(s) | |||||
if ( substr($button_title, 0, 1) == '+' ) { | if ( substr($button_title, 0, 1) == '+' ) { | ||||
$button_title = substr($button_title, 1); | $button_title = substr($button_title, 1); | ||||
} | } | ||||
else { | else { | ||||
$button_title = $this->Application->Phrase($button_title, false, true); | $button_title = $this->Application->Phrase($button_title, false, true); | ||||
} | } | ||||
if ( !isset($params['pass']) ) { | |||||
$params['pass'] = 'm,' . $item_prefix; | |||||
} | |||||
$edit_prefix = $item_prefix; | |||||
list($parent_prefix, $parent_id) = $this->getParentPrefixAndId($object); | |||||
if ( $parent_prefix !== false ) { | |||||
$edit_prefix = $parent_prefix; | |||||
$params[$parent_prefix . '_id'] = $parent_id; | |||||
$params['pass'] = $parent_prefix . ',' . $params['pass']; | |||||
} | |||||
$icon_url = $this->Application->BaseURL() . 'core/admin_templates/img/top_frame/icons/' . $button_icon; | $icon_url = $this->Application->BaseURL() . 'core/admin_templates/img/top_frame/icons/' . $button_icon; | ||||
$button_onclick = '$form_name = ' . json_encode($form_name) . '; std_edit_item(' . json_encode($item_prefix) . ', ' . json_encode($template) . '); return false;'; | |||||
if ( !isset($params['temp_mode']) || (isset($params['temp_mode']) && $params['temp_mode']) ) { | |||||
$edit_function = 'std_edit_item'; | |||||
} | |||||
else { | |||||
$edit_function = 'std_edit_temp_item'; | |||||
} | |||||
$button_onclick = '$form_name = ' . json_encode($form_name) . '; ' . $edit_function . '(' . json_encode($edit_prefix) . ', ' . json_encode($template) . '); return false;'; | |||||
$button_code = '<button | $button_code = '<button | ||||
style="background-image: url(' . $icon_url . ');" | style="background-image: url(' . $icon_url . ');" | ||||
onclick="' . kUtil::escape($button_onclick, kUtil::ESCAPE_HTML) . '" | onclick="' . kUtil::escape($button_onclick, kUtil::ESCAPE_HTML) . '" | ||||
class="cms-btn-new ' . $button_class . '">' . | class="cms-btn-new ' . $button_class . '">' . | ||||
kUtil::escape($button_title, kUtil::ESCAPE_HTML) . ' | kUtil::escape($button_title, kUtil::ESCAPE_HTML) . ' | ||||
</button>'; | </button>'; | ||||
if ( !isset($params['pass']) ) { | |||||
$params['pass'] = 'm,' . $item_prefix; | |||||
} | |||||
$params['m_opener'] = 'd'; | $params['m_opener'] = 'd'; | ||||
$params[$item_prefix . '_id'] = $object->GetID(); | $params[$item_prefix . '_id'] = $object->GetID(); | ||||
if ( !isset($params['temp_mode']) || (isset($params['temp_mode']) && $params['temp_mode']) ) { | |||||
$params[$item_prefix . '_mode'] = 't'; | |||||
$params[$item_prefix . '_event'] = 'OnEdit'; | |||||
} | |||||
$params['front'] = 1; // to make opener stack work properly | $params['front'] = 1; // to make opener stack work properly | ||||
$params['__NO_REWRITE__'] = 1; // since admin link | $params['__NO_REWRITE__'] = 1; // since admin link | ||||
unset($params['button_icon'], $params['button_class'], $params['button_title'], $params['template'], $params['item_prefix'], $params['temp_mode']); | unset($params['button_icon'], $params['button_class'], $params['button_title'], $params['template'], $params['item_prefix'], $params['temp_mode']); | ||||
// link from Front-End to Admin, don't remove "index.php" | // link from Front-End to Admin, don't remove "index.php" | ||||
$form_name_escaped = kUtil::escape($form_name, kUtil::ESCAPE_HTML); | $form_name_escaped = kUtil::escape($form_name, kUtil::ESCAPE_HTML); | ||||
$edit_url = kUtil::escape($this->Application->HREF($template, ADMIN_DIRECTORY, $params, 'index.php'), kUtil::ESCAPE_HTML); | $edit_url = kUtil::escape($this->Application->HREF($template, ADMIN_DIRECTORY, $params, 'index.php'), kUtil::ESCAPE_HTML); | ||||
$edit_form = '<form method="POST" style="display: inline; margin: 0px" name="' . $form_name_escaped . '" id="' . $form_name_escaped . '" action="' . $edit_url . '"></form>'; | $edit_form = '<form method="POST" style="display: inline; margin: 0px" name="' . $form_name_escaped . '" id="' . $form_name_escaped . '" action="' . $edit_url . '"></form>'; | ||||
if ( isset($params['forms_later']) && $params['forms_later'] ) { | if ( isset($params['forms_later']) && $params['forms_later'] ) { | ||||
$all_forms = $this->Application->GetVar('all_forms'); | $all_forms = $this->Application->GetVar('all_forms'); | ||||
$this->Application->SetVar('all_forms', $all_forms . $edit_form); | $this->Application->SetVar('all_forms', $all_forms . $edit_form); | ||||
} | } | ||||
else { | else { | ||||
$button_code .= $edit_form; | $button_code .= $edit_form; | ||||
} | } | ||||
return $button_code; | return $button_code; | ||||
} | } | ||||
/** | /** | ||||
* Returns parent record ID. | |||||
* | |||||
* @param kDBBase $object Object. | |||||
* | |||||
* @return array | |||||
*/ | |||||
protected function getParentPrefixAndId(kDBBase $object) | |||||
{ | |||||
static $parent_mapping = array(); | |||||
$parent_prefix = $this->Application->getUnitOption($object->Prefix, 'ParentPrefix'); | |||||
if ( $parent_prefix === false ) { | |||||
return array(false, null); | |||||
} | |||||
$foreign_key = $this->Application->getUnitOption($object->Prefix, 'ForeignKey'); | |||||
$foreign_key = is_array($foreign_key) ? $foreign_key[$parent_prefix] : $foreign_key; | |||||
$parent_table_key = $this->Application->getUnitOption($object->Prefix, 'ParentTableKey'); | |||||
$parent_table_key = is_array($parent_table_key) ? $parent_table_key[$parent_prefix] : $parent_table_key; | |||||
$parent_id_field = $this->Application->getUnitOption($parent_prefix, 'IDField'); | |||||
$parent_id = $object->GetDBField($foreign_key); | |||||
if ( $parent_table_key != $parent_id_field ) { | |||||
$cache_key = $object->getPrefixSpecial(); | |||||
if ( !isset($parent_mapping[$cache_key]) ) { | |||||
$foreign_key_values = array_unique($object->GetCol($foreign_key)); | |||||
$sql = 'SELECT ' . $parent_id_field . ', ' . $parent_table_key . ' | |||||
FROM ' . $this->Application->getUnitOption($parent_prefix, 'TableName') . ' | |||||
WHERE ' . $parent_table_key . ' IN (' . implode(',', $foreign_key_values) . ')'; | |||||
$parent_mapping[$cache_key] = $this->Conn->GetCol($sql, $parent_table_key); | |||||
} | |||||
// Parent record was deleted, but child record is still referencing it. | |||||
if ( !isset($parent_mapping[$cache_key][$parent_id]) ) { | |||||
return array(false, null); | |||||
} | |||||
$parent_id = $parent_mapping[$cache_key][$parent_id]; | |||||
} | |||||
return array($parent_prefix, $parent_id); | |||||
} | |||||
/** | |||||
* Calls OnNew event from template, when no other event submitted | * Calls OnNew event from template, when no other event submitted | ||||
* | * | ||||
* @param Array $params | * @param Array $params | ||||
*/ | */ | ||||
function PresetFormFields($params) | function PresetFormFields($params) | ||||
{ | { | ||||
$prefix = $this->getPrefixSpecial(); | $prefix = $this->getPrefixSpecial(); | ||||
if ( !$this->Application->GetVar($prefix . '_event') ) { | if ( !$this->Application->GetVar($prefix . '_event') ) { | ||||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |