Pridanie nového skriptu






Späť na index

add.php:

<?php
require('prepend.inc.php');

class 
AddScript extends QForm {
  
// deklaracia QControls
  
protected $txtName;
  protected 
$txtCode;
  protected 
$lstCategory;
  protected 
$btnSave;
    
  public function 
Form_Create() {
    
// inicializacia QControls
    
$this->txtName = new QTextBox($this'name');
    
$this->txtCode = new QTextBox($this'code');
    
$this->txtCode->TextMode QTextMode::MultiLine;
    
$this->txtCode->Width 600;
    
$this->txtCode->Height 300;
    
$this->txtCode->CrossScripting QCrossScripting::Allow;
    
    
$this->lstCategory = new QListBox($this);
    
$objCategoryArray Category::LoadAll();
    if(
$objCategoryArray) foreach($objCategoryArray as $objCategory) {
      
$this->lstCategory->AddItem($objCategory->Name$objCategory);
    }
    
    
$this->btnSave = new QButton($this);
    
$this->btnSave->Text QApplication::Translate('Pridaj skript!');
    
// tlacidlu $this->btnSave pridame akciu, ktora sa zavola
    // pri kliknuti na tlacidlo
    
$this->btnSave->AddAction(new QClickEvent(), new QServerAction('Add'));
    
// kliknutie na tlacitko bude najprv vyzadovat validaciu udajov
    // a metoda Add() sa zavola len vtedy ak Form_Validate() vrati true 
    
$this->btnSave->CausesValidation true;
  }
  
  protected function 
Add() {
    
$objScript = new Script();
    
$objScript->Name $this->txtName->Text;
    
$objScript->Code $this->txtCode->Text;
    
    
$objScript->CategoryId $this->lstCategory->SelectedValue->Id;
    
$objScript->Save();
    
QApplication::Redirect('index.php');
  }
  
  
// jednoducha validacia zadanych udajov
  
protected function Form_Validate() {
    
$error false;
    if(
strlen($this->txtName->Text) < 5) {
      
$this->txtName->Warning QApplication::Translate('Príliš krátky názov !');
      
$error true;
    }
    if(
strlen($this->txtCode->Text) < 10) {
      
$this->txtCode->Warning QApplication::Translate('Príliš krátky kód !');
      
$error true;
    }
    
    if(
$error) return false;
    return 
true;
  }
}

AddScript::Run('AddScript''add.tpl.php');
?>

add.tpl.php:

<html>
<head>
<link rel="stylesheet" href="style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=<?= QApplication::$EncodingType?>"/>
<title>QForms ukážka pre seminár o PHP frameworkoch</title></head>
<body>
<h1><? _t('Pridanie nového skriptu'); ?></h1>
<? $this->RenderBegin(); ?>
<label for="name"><? _t('Názov'); ?>:</label>
<br />
<? $this->txtName->RenderWithError(); ?>
<br />
<label for="code"><? _t('Kód'); ?>:</label>
<br />
<? $this->txtCode->RenderWithError(); ?>
<br />
<label for="listbox"><? _t('Vyber kategóriu'); ?>:</label> <? $this->lstCategory->Render(); ?>
<br /> 
<? $this->btnSave->Render(); ?>
<? $this
->RenderEnd(); ?>
<a href="index.php"><? _t('Späť na index'); ?></a>
<hr>
<p class="bold">add.php:</p>
<? highlight_file('add.php'); ?>
<p class="bold">add.tpl.php:</p>
<? highlight_file('add.tpl.php'); ?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1055484-1";
urchinTracker();
</script>
</body>
</html>