switch ($modx->event->name) {
case 'OnManagerLoginFormPrerender': /* if you want to add custom scripts, css, etc, register them here */
$results = $modx->query("SELECT * FROM modx_context WHERE modx_context.key NOT IN ('mgr')");
$numItems = $modx->getCount('modContext', array('key:NOT IN' => array('mgr')));
$i = 0;
while ($r = $results->fetch(PDO::FETCH_ASSOC)){
if(++$i === $numItems){
$listContext .= "['" . $r['key'] . "', '" . $r['name'] . "']"; // NO comma at the end of the array.
}else{
$listContext .= "['" . $r['key'] . "', '" . $r['name'] . "'],";
}
}
// Define the model for website
$script = "<script type='text/javascript'>
Ext.onReady(function() {
/* disable shadows for the combo-list globally, saves a few dom nodes as it's not used anyways */
Ext.form.ComboBox.prototype.shadow = false;
/* replaces the default img tag for the combo trigger with a div to make the use of iconfonts with :before possible */
Ext.override(Ext.form.TriggerField, {
// this is the exact method from the source code, just the triggerConfig is modified to not use an img tag
// We cannot override the prototype Ext.form.TriggerField.prototype.triggerConfig because we loose the option to add a custom triggerClass
onRender: function(ct, position){
this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
this.trigger = this.wrap.createChild(this.triggerConfig ||
{tag: 'div', cls: 'x-form-trigger ' + (this.triggerClass || '')});
this.initTrigger();
if(!this.width){
this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
}
this.resizeEl = this.positionEl = this.wrap;
}
});
Ext.namespace('Ext.websitedata');
Ext.websitedata.websites = [" . $listContext . "];
// simple array store
var store = new Ext.data.ArrayStore({
fields: ['context', 'name'],
data : Ext.websitedata.websites // from namespace data
});
var combo = new Ext.form.ComboBox({
store: store,
displayField:'name',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText:'Select a website...',
selectOnFocus:true,
hiddenName: 'cntxwebsite',
valueField: 'context',
applyTo: 'local-websites'
});
});
</script>";
$modx->event->output($script);
break;
case 'OnManagerLoginFormRender':
$fields = '<div class="x-form-item login-form-item" style="padding-top: 17px;">
<label for="local-websites">Website</label>
<input type="text" id="local-websites" value="" readonly="" style="width: 368px;"/>
</div>';
$modx->event->output($fields);
break;
case 'OnManagerLogin':
$profile = $user->getOne('Profile');
$modx->log(modX::LOG_LEVEL_ERROR, "You have logged in with: " . $_POST['cntxwebsite'] . " Your user name is: " . $_POST['username'] . " Session contexts: " . print_r($user->toArray()));
$results = $modx->query("SELECT * FROM modx_context WHERE modx_context.key NOT IN ('" . $_POST['cntxwebsite'] . "','mgr')");
while ($r = $results->fetch(PDO::FETCH_ASSOC)){
$resource = $modx->getObject('modResource',array('context_key' => $r['key']));
$user->removeSessionContext($r['key']);
}
/*$script = '<script type="text/javascript">
var tree = null;
Ext.onReady(function() {
var tree = Ext.getCmp("modx-resource-tree");
if (tree && tree.rendered) {
tree.refresh();
}
});
</script>';*/
break;
}