<?php
/*
* Created on 26.03.2006 by *Camper*
*/
class FormScript extends Form{
function init(){
parent::init();
if($_GET['application_id'])$this->api->memorize('application_id', $_GET['application_id']);
if($_GET['ver'])$this->api->memorize('ver', $_GET['ver']);
$this
->addField('dropdown', 'type', 'Type of script')->setValueList(array('sql'=>'sql', 'php'=>'php'))
->addField('text', 'script', 'Script')->setProperty('cols', 80)->setProperty('rows', 20)
->setSource('script')
->addConditionFromGet('id')
;
if($_GET['id']!=''){
$this->addButton('Save')->submitForm($this)
//->ajaxFunc("alert('".$this->api->recall('application_id')."')")
//->redirect('Application', array('application_id'=>$_GET['id']))
->ajaxFunc($this->api->getScriptRenderFunc($this->api->recall('application_id')))
;
}else{
$this->addSubmit('Save');
}
}
private function getNumber(){
//TODO locks and so
$number = $this->api->db->getOne("select number+1 from script where version_id = ".$this->recall('ver')
." order by number desc");
if(!$number)$number = 0;
return $number;
}
function submitted(){
if(parent::submitted()){
if(!$this->loaded_from_db){
$this->dq->set('number', $this->getNumber());
$this->dq->set('application_id', $this->api->recall('application_id'));
$this->dq->set('version_id', $this->api->recall('ver'));
}else{
}
$this->update();
if($this->isClicked('Save'))$this->api->redirect('Application', array('application_id'=>
$this->api->recall('application_id')));
exit;
}
}
}
?>