1. Page 1
Quiz component for Joomla
How to use the component:
- open the Joomla site in one browser
- log in as an administrator
- install the component from Administrator Panel
- open the component frontend page
- the first post is a link post
- click on link to edit your first quiz
Download
http://24secunde.com/joomla/media/com_componentamea.zip
2. Page 2
Press Register (Inregistreaza) and the quiz is ready.
The syntax for Questions and Answers must follow the rules:
<intrebare/>
SUA ? - the question is the first after the tag
Washington - the GOOD answer is always the first
New YORK
Los Angeles
<intrebare/>
Canada ?
Ottawa
Montreal
Toronto
Vancouver
<intrebare/>
France ?
Paris
Marseille
Nice
Strasbourg
You can use HTML code in questions or in answers. You CAN’T use
newline “n” in questions or answers. The newline is used to break the
quiz in questions and answers and is reserved. The newline is the last
escape character in every row. Usually, you push ENTER to introduce a
newline.
The quiz will look like this image:
Download
http://24secunde.com/joomla/media/com_componentamea.zip
8. Page 8
<intrebare/>
Care este capitala Romaniei?
Bucuresti
Budapesta
Sofia
<intrebare/>
Care este capitala Turciei?
Ankara
Istanbul
Atena
</textarea>
File admin.componentamea.php:
<?php
// nu permite accesul direct la acest fisier
defined('_JEXEC') or die('<center>Restricted access.</center>');
?>
<?php
$task=JRequest::getVar('task',null)."";
if(!isset($task) || trim($task)=="")
JRequest::setVar('task','admin_test');
$task=JRequest::getVar('task',null)."";
if($task=="admin_test") include_once("admin.principal.php");
if($task=="publish") include_once("admin.publish.php");
if($task=="unpublish") include_once("admin.unpublish.php");
if($task=="edit") include_once("admin.edit.php");
if($task=="apply") include_once("admin.edit.php");
if($task=="cancel") include_once("admin.edit.php");
if($task=="rezult_test") include_once("admin.rezultate.php");
if($task=="remove") include_once("admin.remove.php");
?>
File admin.edit.php:
<?php
// nu permite accesul direct la acest fisier
defined('_JEXEC') or die('<center>Restricted access.</center>');
?>
<?php
$cid = JRequest::getVar( 'cid', array(0));
$id=$cid[0];
// obtinem o refeinta la clasa JUser
$user =& JFactory::getUser();
// obtinem o referinta la baza de date
$db =& JFactory::getDBO();
if($task== "apply")
{
$titlu_test=JRequest::getVar('titlu_test','');
Download
http://24secunde.com/joomla/media/com_componentamea.zip
19. Page 19
?>
<?php
print('<div style="clear:both;"></div>');
$url_partaj=JURI::base()."index.php?option=com_componentamea%26task=x
ml_feed%26format=feed";
jimport('joomla.utilities.date');
$date1 = new JDate();
$date1=$date1->toFormat('%d-%m-%Y %H:%M:%S EET');
print('<div style="background-color:#e1e1e1; padding:3px 3px 3px 3px;
margin-bottom:5px; font-weight:bold">');
print('<div style="float:left;">Ora vizitei: '.$date1.'</div>');
print('<div style="float:right;background-color:#e1e1e1; padding:0px
0px 1px 0px;">');
print('<a
href="'.JURI::base().'index.php?option=com_componentamea&task=xml_fee
d&format=feed" title="RSS"><img
src="components/com_hello/imagini/rss.gif" alt="RSS"></a>');
print('<a href="http://add.my.yahoo.com/rss?url='.$url_partaj.'"
title="Yahoo"><img src="components/com_hello/imagini/yahoo.gif"
alt="Yahoo"></a>');
print('<a href="http://fusion.google.com/add?feedurl='.$url_partaj.'"
title="Google"><img src="components/com_hello/imagini/google.gif"
alt="Google"></a>');
print('<a
href="http://www.netvibes.com/subscribe.php?url='.$url_partaj.'"
title="Netvibes"><img src="components/com_hello/imagini/netvibes.gif"
alt="Netvibes"></a>');
print('</div>');
print('.</div>');
print('<div style="clear:both;"></div>');
$tip_user="Super Administrator";
// setam titlul ce apare in browser
$document =& JFactory::getDocument();
$document->setTitle("Teste de cunoastere");
// setam parametrii pentru bara de navigatie
$limit = 20;
$limitstart = JRequest::getVar('limitstart',0);
$limitstart = 0 + intval($limitstart);
$total = 0; //numarul total de articole
// obtinem o refeinta la clasa JUser
$user =& JFactory::getUser();
// obtinem o referinta la baza de date
$db =& JFactory::getDBO();
// avem interogari diferite pentru un user obisnuit si un
administrator
// administratorul poate sa aiba acces la toate inregistrarile, si la
cele marcate ca nepublicate
// interogarea urmatoare va intoarce numarul total de teste din baza
de date; informatia este necesara pentru bara de navigatie
if($user->usertype==$tip_user)
$query="SELECT count(*) FROM `jos_cunoastere_test` WHERE 1 ";
else
Download
http://24secunde.com/joomla/media/com_componentamea.zip
20. Page 20
$query="SELECT count(*) FROM `jos_cunoastere_test` WHERE
`published`=1 ";
$result = $db->setQuery($query);
$total=$db->loadResult();
if($user->usertype=="Super Administrator")
$query="SELECT `id` , `nume_test` , `descriere_test` FROM
`jos_cunoastere_test` WHERE 1 ORDER BY `id` DESC LIMIT
".$limitstart." , ".$limit."";
else
$query="SELECT `id` , `nume_test` , `descriere_test` FROM
`jos_cunoastere_test` WHERE `published`=1 ORDER BY `id` DESC LIMIT
".$limitstart." , ".$limit."";
$result = $db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{
print('<a
href="index.php?option=com_componentamea&task=view_test&id='.$row-
>id.'" style="text-decoration:none; cursor: pointer; " title="'.$row-
>nume_test.'"><h3>'.$row->nume_test.'</h3></a>');
print(stripslashes($row->descriere_test));
print("<br/>"); print("<br/>");
}
jimport('joomla.html.pagination');
$_pagination = new JPagination($total, $limitstart, $limit);
?>
<div style="clear:both"></div>
<div class="pagenav" style="text-align:center; margin-top:10px; ">
<?php print($_pagination->getPagesLinks()); ?>
<br/>
<?php print($_pagination->getPagesCounter()); ?>
</div>
File publica.php
<?php
defined("_JEXEC") or exit("Restricted access");
?>
<?php
$user =& JFactory::getUser();
if($user->usertype!="Super Administrator") $mainframe-
>redirect('index.php');
?>
<?php
$id=JRequest::getVar('id',0);
$id=$id+0;
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
$table_test = JTable::getInstance('cunoastere_test', 'Table');
$table_test->load($id);
$table_test->set('published',1);
Download
http://24secunde.com/joomla/media/com_componentamea.zip
35. Page 35
The folder tables
File index.html
Ooops! Nu e chiar ceea ce cauti!
File cunoastere_intrebari.php
<?php
class Tablecunoastere_intrebari extends JTable
{
/*
CREATE TABLE `jos_cunoastere_intrebari`
(
Download
http://24secunde.com/joomla/media/com_componentamea.zip
36. Page 36
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_test` INT NOT NULL,
`nume_intrebare` TEXT NOT NULL
);
*/
// cream variabile pentru fiecare camp din tabel si dam fiecarei
valori o valoare implicita
var $id = null;
var $id_test=NULL;
var $nume_intrebare=NULL;
// functia constructor are ca parametru o referinta la baza de date
function __construct( &$db )
{
parent::__construct('#__cunoastere_intrebari', 'id', $db);
}
// validarea datelor daca este cazul
function check()
{
if(!$this->id_test)
{
$this->setError(JText::_('Eroare - lipseste campul
ID din tabela TEST.'));
return false;
}
if(!$this->nume_intrebare)
{
$this->setError(JText::_('Eroare - intrebarea nu
poate fi vida.'));
return false;
}
return true;
}
}
?>
File cunoastere_raspunsuri.php
<?php
class Tablecunoastere_raspunsuri extends JTable
{
/*
CREATE TABLE `jos_cunoastere_raspunsuri`
(
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_intrebari` INT NOT NULL,
`nume_raspuns` TEXT NOT NULL
);
*/
// cream variabile pentru fiecare camp din tabel si dam fiecarei
valori o valoare implicita
Download
http://24secunde.com/joomla/media/com_componentamea.zip
37. Page 37
var $id = null;
var $id_intrebari=NULL;
var $nume_raspuns=NULL;
// functia constructor are ca parametru o referinta la baza de date
function __construct( &$db )
{
parent::__construct('#__cunoastere_raspunsuri', 'id', $db);
}
// validarea datelor daca este cazul;
function check()
{
if(!$this->id_intrebari)
{
$this->setError(JText::_('Eroare - lipseste campul
ID din tabela INTREBARI.'));
return false;
}
if(!$this->nume_raspuns)
{
$this->setError(JText::_('Eroare - testul nu are
definit un raspuns.'));
return false;
}
return true;
}
}
?>
File cunoastere_test.php
<?php
class Tablecunoastere_test extends JTable
{
/*
CREATE TABLE `jos_cunoastere_test` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`nume_test` TEXT NOT NULL ,
`descriere_test` TEXT NOT NULL ,
`published` TINYINT( 1 ) NOT NULL DEFAULT 0
);
*/
// cream variabile pentru fiecare camp din tabel si dam fiecarei
valori o valoare implicita
var $id = null;
var $nume_test=NULL;
var $descriere_test=NULL;
var $published = 0;
// functia constructor are ca parametru o referinta la baza de date
function __construct( &$db )
{
Download
http://24secunde.com/joomla/media/com_componentamea.zip
38. Page 38
parent::__construct('#__cunoastere_test', 'id', $db);
}
// validarea datelor daca este cazul; verificam ca testul sa aiba un
titlu si o descriere
function check()
{
if(!$this->nume_test)
{
$this->setError(JText::_('Eroare - testul nu are
definit un titlu.'));
return false;
}
if(!$this->descriere_test)
{
$this->setError(JText::_('Eroare - testul nu are
definita o descriere.'));
return false;
}
return true;
}
}
?>
File cunoastere_user.php
<?php
class Tablecunoastere_user extends JTable
{
/*
CREATE TABLE `jos_cunoastere_user`
(
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_test` INT NOT NULL,
`user` VARCHAR(255) NOT NULL,
`punctaj` INT NOT NULL DEFAULT 0
);
*/
// cream variabile pentru fiecare camp din tabel si dam fiecarei
valori o valoare implicita
var $id = null;
var $id_test=NULL;
var $user=NULL;
var $punctaj = 0;
// functia constructor are ca parametru o referinta la baza de date
function __construct( &$db )
{
parent::__construct('#__cunoastere_user', 'id', $db);
}
// validarea datelor daca este cazul;
function check()
Download
http://24secunde.com/joomla/media/com_componentamea.zip
39. Page 39
{
if(!$this->id_test)
{
$this->setError(JText::_('Eroare - lipseste campul
ID din tabela TEST.'));
return false;
}
if(!$this->user)
{
$this->setError(JText::_('Eroare - testul nu are
definit un USER.'));
return false;
}
return true;
}
}
?>
Download
http://24secunde.com/joomla/media/com_componentamea.zip