PDA

View Full Version : [PHP] HELP?


niko_lol
21-03-2008, 16:13
nell' URL scrivo: http://localhost/html/ada_1-71/

poi mi da questo errore:
Fatal error: Cannot redeclare Node::$order in /var/www/html/ada_1-71/include/node_classes.inc.php on line 59.
provo a cancellare la "var $order;" mi carica la pagina ma dopo mi da un' altro errore nell' index.php riga 83 cioè ":$data = getdate($course[3]);"

come posso risolvere? :help: :help: :help: :help: :help:

GRAZIE!

frax289
21-03-2008, 16:17
devi postare il file sennò non ci si riesce...se sei sicuro che funzioni come sono messe le register global?

niko_lol
21-03-2008, 16:23
file node_classes.inc.php******************
<?php
//
// +----------------------------------------------------------------------+
// | ADA version 1.7 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2004 Lynx |
// +----------------------------------------------------------------------+
// | |
// | NODE, EXERCISE, MEDIA, LINK CLASSES |
// | |
// | |
// | |
// | |
// | |
// +----------------------------------------------------------------------+
// | Authors: Stefano Penge <steve@lynxlab.com> |
// | Graffio<graffio@lynxlab.com> |
// +----------------------------------------------------------------------+
//
// $Id: NODE_classes.inc.php,v 1.0 2003/06/06
//
//
// Classes Structure:
// Node
// Exercise
// Resource
// Media
// Link


class Node
{
//media
var $text;
var $audio;
var $image = '';
var $video;
var $notes;
var $links;
var $media;

//user vars
var $author;
var $creation_date;
var $visited;
var $order;
var $level=1; // manca nelle tabelle ???!!!!
var $position;
var $icon;
var $copyright;
var $template_family;

//system vars

var $name;
var $type;
var $id;
var $parent_id;
var $order;
var $version;
var $bgcolor;
var $color;
var $correctness;
var $instance;

var $children;
var $full= 0; // the node exists?
var $error_msg;

var $open_vars = array('title','position','icon','text','audio','video','links');
var $logical_path = array();


function node($id_node){
//global $dh,$error,$debug;
//
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];

static $volte;
// constructor
$dataHa = $dh->get_node_info($id_node);
//mydebug(__LINE__,__FILE__,$dataHa);

if (AMA_DataHandler::isError($dataHa) || (!is_array($dataHa))){
$msg = $dataHa->getMessage();
if (!strstr ($msg, 'record was not found')) {
// header("Location: $error?err_msg=$msg");
// exit;
return $msg;
} else {
return $msg;
}
}


/* Se i nomi non sono gli stessi:
$this->author = $dataHa['author]'];
$this->position= $dataHa['position']; // the position (array: (x0, y0, x1, y1))
$this->name = $dataHa['nome'];
$this->title = $dataHa['title'];
$this->text = $dataHa['text'];
$this->type = $dataHa['type']; //the type of node
// (0 - Page, 1 - Group, 2 - Note, 3 - Multiple Answer, 4 - Free Answer, 5 - History separators (?))
$this->creation_date = $dataHa['creation_date']; // the date of creation of the node (the format is specified in ADA_DATE_FORMAT)
$this->parent_id = $dataHa['parent_id'];
$this->next_id = $dataHa['next_id'];
$this->previous_id = $dataHa['previous_id'];
$this->level = $dataHa['livello']; // the level at which the node is visible in the course (0 - 3)
$this->version = $dataHa['version']; //- version of the node (not used yet)
$this->contacts = $dataHa['contacts']; //- number of contacts that the node has received
$this->icon = $dataHa['icon'];
$this->color = $dataHa['color'];
$this->correctness = $dataHa['correctness']; // if the node is of type 3 or 4 (answers), give the correctness
// (0-10 or 0-100 or 0-whateverYouLike) of the answer, else it must be NULL
$this->copyright = $dataHa['copyright']; // - boolean (0, 1) if a copyright is held by the author on this node
*/
// mydebug(__LINE__,__FILE__,$dataHa);

if (!empty($dataHa['name'])){

foreach ($dataHa as $key=>$value){
$this->$key = $value;
}

$this->full = 1;
// Children
// mydebug(__LINE__,__FILE__,$this);
$childrenAr = $dh->get_node_children($id_node); // Array
// mydebug(__LINE__,__FILE__,$childrenAr);

if (AMA_DataHandler::isError($childrenAr) || (!is_array($childrenAr))){
$this->children = '';
} elseif (count($childrenAr)>0)
$this->children = $childrenAr;
// Links
$linksAr = $dh->get_node_links($id_node); // Array
if (AMA_DataHandler::isError($linksAr) || (!is_array($linksAr))){
$this->links = '';
} elseif (count($linksAr)>0)
$this->links = $linksAr;
// Media
$mediaAr = $dh->get_node_resources($id_node); // Array
if (AMA_DataHandler::isError($mediaAr) || (!is_array($mediaAr))){
$this->media = new AMA_Error(translateFN('Errore nei media'),translateFN('Errore nei media'));
} elseif (is_array($mediaAr))
$this->media = $mediaAr;


$this->id = $id_node;
// mydebug(__LINE__,__FILE__,$this);

}

}

function copy($new_id_node){
//global $dh,$error,$debug;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];
// duplicates a node

if ($new_id_node!=$this->id){
$dataHa = $dh->get_node_info($this->id);
//mydebug(__LINE__,__FILE__,$dataHa);
if (AMA_DataHandler::isError($dataHa) || (!is_array($dataHa))){
$msg = $dataHa->getMessage();
if (!strstr ($msg, 'record was not found')) {
header("Location: $error?err_msg=$msg");
exit;
} else {
return $msg;
}
}
$dataHa->node_id = $new_id_node;
$dh->add_node($dataHa); // Array
} else {
return translateFN("Un nodo con questo id è già presente");
}


}

function graph_indexFN($id_toc='',$depth=1,$user_level=1,$user_history=''){
// usata per la mappa grafica
//global $dh,$error;
//global $root_dir,$http_root_dir,$media_path;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$media_path = $GLOBALS['media_path'];
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];
if (empty($id_toc))
$id_toc = $this->id;
$course_icons_media_path = $root_dir.$media_path;

$base = new Node($id_toc); // da dove parte
$children = $base->children;
$type = $base->type;
// mydebug(__LINE__,__FILE__,$children);

$children_ha = array();
if (!empty($children) and ($type == 1)){
foreach ($children as $id_child) {
$linked_ha = array();
if (!empty($id_child)){
$child_dataHa = $dh->get_node_info($id_child);
// Vengono mostrati nella mappa solo i nodi di tipo pagina (0) e gruppo (1)
if (($child_dataHa['type'] == 0) or ($child_dataHa['type'] == 1)) {
//mydebug(__LINE__,__FILE__,$child_dataHa);
$linksAr = array();

$links_result = $dh->get_node_links($id_child); // Array
if (!is_object($links_result)) {
$linksAr = $links_result;

// filtro link
$ok_link = $this->get_filter_links_FN($linksAr,$user_level);
// fine filtro link
if (!empty($ok_link)) {
foreach ($ok_link as $link) {
$id_node_to = $link['id_node_to'];
$meaning_link = $link['meaning_link'];
$action_link = $link['action_link'];
array_push ($linked_ha, array ('id_node_to'=>$id_node_to,'meaning_link'=>$meaning_link,'action_link'=>$action_link));
}
}
}

if (file_exists($course_icons_media_path.$child_dataHa['icon'])) {
$icon_child = $course_icons_media_path.$child_dataHa['icon'];
} else {
$icon_child = $child_dataHa['icon'];
}
//mydebug(__LINE__,__FILE__,$course_icons_media_path.$child_dataHa['icon']);

$array_child = array('id_child'=>$id_child,
'name_child'=>$child_dataHa['name'],
'position_child'=>$child_dataHa['position'],
'type_child'=>$child_dataHa['type'],
'icon_child'=> $icon_child,
'level_child'=> $child_dataHa['level'],
'bgcolor_child'=>$child_dataHa['bgcolor'],
'color_child'=>$child_dataHa['color'],
'linked'=>$linked_ha);

array_push($children_ha, $array_child);
//mydebug(__LINE__,__FILE__,$array_child);
}
}
}
return $children_ha;
} else {
return translateFN("Nessuno");
}
}


function indexFN($id_toc='',$depth=1,$user_level=1,$user_history='',$user_type='3'){
// class function
// filtering nodes by level
// notes are shown only if created by users of this course
// AND of this instance
//global $dh,$error;
//global $sess_id_course,$sess_id_course_instance,$sess_id_user;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$sess_id_course = $GLOBALS['sess_id_course'];
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_user = $GLOBALS['sess_id_user'];


$visit_count = 0;
if (empty($id_toc)) $id_toc = $this->id;

$base = new Node($id_toc); // da dove parte
$children = $base->children;
//mydebug(__LINE__,__FILE__,$children);

if (!empty($children)){
$dataAr = array();
// $parent_link = array("<img name=gruppo alt=\"Questo gruppo\" src=\"img/_gruppo.gif\"> <a href=view.php?id_node=".$base->id.">".$base->name."</a>",
// $alt = translateFN("Questo gruppo");
// $parent_link = array("<img name=gruppo alt=\"$alt\" src=\"img/_gruppo.gif\">".$base->name);
$parent_link = array();
for ($k=1; $k<=$depth; $k++){
array_push($parent_link,"&nbsp;");
}
array_push($dataAr,$parent_link);
foreach ($children as $id_child) {
if (!empty($id_child)){
//$node_childObj = new Node($id_child);
//$children_link = array("&nbsp;","<img name=gruppo alt=\"nodo\" src=\"img/_nodo.gif\"> <a href=view.php?id_node=".$id_child.">".$node_childObj->name."</a>");
// se è troppo lento si può usare:
$ok = false;
$child_dataHa = $dh->get_node_info($id_child);
$node_type = $child_dataHa['type'];
switch ($node_type){
case ADA_LEAF_TYPE:
if ($child_dataHa['level']<=$user_level){
$alt = translateFN("Nodo inferiore");
$icon = "_nodo.gif";
switch ($user_type){
case AMA_TYPE_STUDENT:
default:
$visit_count = User::is_visited_by_userFN($id_child,$sess_id_course_instance,$sess_id_user);
break;
case AMA_TYPE_TUTOR:
// TOO SLOW !
$visit_count = User::is_visited_by_classFN($id_child,$sess_id_course_instance,$sess_id_course);
break;
case AMA_TYPE_AUTHOR:
$visit_count = User::is_visitedFN($id_child);
}
if ($visit_count<=0){
$children_link = array("<img name=\"nodo\" alt=\"$alt\" src=\"img/$icon\"> <b><a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a></b>");
} else {
$children_link = array("<img name=\"nodo\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a> ($visit_count)");
}
} else {
$alt = translateFN("Nodo non visitabile");
$icon = "_nododis.gif"; // _nododis.gif
$children_link = array("<img name=\"nodo\" alt=\"$alt\" src=\"img/$icon\"> ".$child_dataHa['name']);
}

break;
case ADA_GROUP_TYPE:
if ($child_dataHa['level']<=$user_level){
$alt = translateFN("Approfondimenti");
$icon = "_gruppo.gif";
switch ($user_type){
case AMA_TYPE_STUDENT:
default:
$visit_count = User::is_visited_by_userFN($id_child,$sess_id_course_instance,$sess_id_user);
break;
case AMA_TYPE_TUTOR:
// TOO SLOW !
// $visit_count = User::is_visited_by_classFN($id_child,$sess_id_course_instance,$sess_id_course);
//
break;
case AMA_TYPE_AUTHOR:
$visit_count = User::is_visitedFN($id_child);
}
if ($visit_count==0){
$children_link = array("<img name=\"gruppo\" alt=\"$alt\" src=\"img/$icon\"> <b><a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a></b>");
} else {
$children_link = array("<img name=\"gruppo\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a> ($visit_count)");
}
} else {
$alt = translateFN("Approfondimenti non visitabili");
$icon = "_gruppodis.gif"; // _gruppodis.gif
$children_link = array("<img name=\"gruppo\" alt=\"$alt\" src=\"img/$icon\"> ".$child_dataHa['name']);
}
break;
case ADA_NOTE_TYPE: // node added by users

/*
$autore = $child_dataHa['author'];

switch (VIEW_PRIVATE_NOTES_ONLY){
case 0: // every node added by student of this course are visible
$author_dataHa = $dh->get_subscription($autore, $sess_id_course_instance);
if (!DB::isError($author_dataHa)){
$alt = translateFN("Nota pubblica");
$icon = "_nota.gif";
$children_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a>");
}
break;
case 1: // only nodes added by this user are visible
if ($autore==$sess_id_user){
$alt = translateFN("Nota privata");
$icon = "_nota.gif";
$children_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a>");
}
default:
$ok = false;
$alt = translateFN("Nota non visitabile");
$icon = "_unknown.gif";
$children_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> ".$child_dataHa['name']);
}
*/
unset ($children_link);
break;
case ADA_STANDARD_EXERCISE_TYPE: // exercise
case 4: // exercise...
case 5: // exercise...
case 6: // exercise...
unset ($children_link);
break;
default:
$alt = translateFN("Nodo non visitabile");
$icon = "_unknown.gif";
$children_link = array("<img name=\"sconosciuto\" alt=\"$alt\" src=\"img/$icon\"> ".$child_dataHa['name']);

}
if (isset($children_link)){
for ($k=1; $k<=$depth; $k++){
array_unshift($children_link,"&nbsp;");
}
array_push($dataAr,$children_link);
}
}
}

$t = new Table();
$t->initTable('0','center','0','0','100%','blue','white','blue','white','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Indice dei nodi inferiori"));
$t->getTable();

return $t->data;
} else {
return translateFN("Nessuno")."<p>";
}

}

// Inizio funzioni wrapper per Main Index
// le funzioni vere appartengono alla classe Course
/* RIASSUNTO:
main_indexFN: mostra nodi e gruppi, per studente (no autore, tutor e admin)
explode_nodesFN : ricorsiva, chiamata per default e se $order=struct
explode_nodes_iterativeFN : iterativa, chiamata se $order=alfa

se hide_visits=1 mostrano anche le visite dello studente

class_indexFN: mostra nodi e gruppi,per tutor e autore (no studente e admin)
class_explode_nodesFN : ricorsiva, chiamata per default e se $order=struct
class_explode_nodes_iterativeFN : iterativa, chiamata se $order=alfa

se hide_visits=1 mostrano anche le visite della classe (tutor) o di tutti (autore)

forum_main_indexFN: mostra solo note, per studente, tutor (no admin e autore)
forum_explode_nodesFN : ricorsiva, chiamata se $order=struct
forum_explode_nodes_iterativeFN : iterativa, chiamata per default e se $order=chrono

*se hide_visits=1 mostrano anche le visite della classe (tutor)
*/

function main_indexFN($id_toc='',$depth=1,$user_level=1,$user_history='',$user_type=AMA_TYPE_STUDENT,$order='struct',$expand=0){
// this version is intended for studentes use only
$CourseObj = new Course($sess_id_course);
$index = $CourseObj->main_indexFN($id_toc,$depth,$user_level,$user_history,$user_type,$order,$expand);
return $index;
}


function class_main_indexFN($id_toc='',$depth=1,$id_profile,$order='struct',$expand=1){
// this version is intended for tutor or author use
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$CourseInstanceObj = new Course_instance($sess_id_course_instance);
$index = $CourseInstanceObj->class_main_indexFN($id_toc,$depth,$id_profile,$order,$expand);
return $index;

}


function forum_main_indexFN($id_toc='',$depth=1,$id_profile,$order='chrono',$id_student,$mode='standard'){
// this version is intended for tutor and studente use
// only notes are showed
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$CourseInstanceObj = new Course_instance($sess_id_course_instance);
$index = $CourseInstanceObj->forum_main_indexFN($id_toc,$depth,$id_profile,$order,$id_student,$mode);
return $index;
}

// Fine funzioni per Main Index

function get_all_childrenFN($depth,$user_level,$id_parent,$dataAr,$id_profile){
// recursive
//global $dh,$id_course,$sess_id_course_instance,$sess_id_course;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$sess_id_course = $GLOBALS['sess_id_course'];
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_user = $GLOBALS['sess_id_user'];

$depth++;
$childrenAr = $dh->get_node_children($id_parent);
if (!is_object($childrenAr)){ // it is an Error
$childnumber = 0;
foreach ($childrenAr as $id_child) {
if (!empty($id_child)){
$childnumber++;
$child_dataHa = $dh->get_node_info($id_child);
$node_type = $child_dataHa['type'];
$ok=false;
switch ($node_type){
case 0:
if ($child_dataHa['level']<=$user_level){
$alt = translateFN("Nodo inferiore");
$icon = "_nodo.gif";
$ok = true;
} else {
$alt = translateFN("Nodo non visitabile");
$icon = "_nododis.gif"; // _nododis.gif
$ok = false;
}

break;
case 1:
if ($child_dataHa['level']<=$user_level){
$alt = translateFN("Gruppo inferiore");
$icon = "_gruppo.gif";
$ok = true;
} else {
$alt = translateFN("Gruppo non visitabile");
$icon = "_gruppodis.gif"; // _gruppodis.gif
$ok = false;
}
break;
case 2: // node added by users
// notes doesn't have levels !
$autore = $child_dataHa['author'];

switch (VIEW_PRIVATE_NOTES_ONLY){
case 0: // every node added by student of this course are visible
$author_dataHa = $dh->get_subscription($autore, $sess_id_course_instance);
if (!DB::isError($author_dataHa)){
$alt = translateFN("Nota pubblica");
$icon = "_nota.gif";
$ok = true;
}
break;
case 1: // only nodes added by this user are visible
if ($autore==$sess_id_user){
$alt = translateFN("Nota privata");
$icon = "_nota.gif";
$ok = true;
}
default:
$ok = false;
$alt = translateFN("Nodo non visitabile");
$icon = "_unknown.gif";
}
break;
default:
$icon = "_nodo.gif";
$ok = true;
}
if ($ok){

switch ($id_profile){
case AMA_TYPE_STUDENT:
default:
$visit_count = $userObj-> is_visited_by_userFN($id_child,$sess_id_course_instance,$sess_id_user);
break;
case AMA_TYPE_TUTOR:
$visit_count = User::is_visited_by_classFN($id_child,$sess_id_course_instance,$sess_id_course);
break;
case AMA_TYPE_AUTHOR:
$visit_count = $userObj->is_visitedFN($id_child);
}


$dataAr[$depth][$childnumber ] = "<img name=\"nodo\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a>";
} else {
$dataAr[$depth][$childnumber ] = "<img name=\"nodo\" alt=\"$alt\" src=\"img/$icon\">".$child_dataHa['name'];
}
$dataAr[$depth][$childnumber ] = "<img name=gruppo alt=\"Nodo inferiore\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_child.">".$child_dataHa['name']."</a>";
Node::get_all_childrenFN($depth,$user_level,$id_child,$dataAr,$id_profile);
}
}
} else {
return FALSE;

}
}


function findPathFN($target="") {
// NON ricorsivamente tenta di risalire al nodo id X_0
//global $dh,$error,$sess_id_course, $self;

$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$sess_id_course = $GLOBALS['sess_id_course'];
$self = $GLOBALS['self'];


if (empty($target)) {
$target = $self;
}
$id_toc = $sess_id_course."_0";
$id_node = $this->id;
//$path = "<a href=view.php?id_node=$id_node>$name</a>";
if ($id_node==$id_toc){ // are we at main group level?
$path = '';
} else {

$name = $this->name;
$path = $name;
$id_parent = $this->parent_id;

while ($id_node!=$id_toc && (!empty($id_node))) {
// mydebug(__LINE__,__FILE__,array('parent'=>$id_parent,'node'=>$id_node));
$dataHa = $dh->get_node_info($id_parent);
$name = $dataHa['name'];
$id_node = $dataHa['parent_id'];
if ($id_parent!=$id_toc) {
if ($target == "map") {
$node_parentObj = new Node($id_node);
$parent_type = $node_parentObj->type;
if ($parent_type ==ADA_GROUP_TYPE) {
$path = "<a href=map.php?id_node=$id_parent>$name</a> > ".$path;
} else {
$path = "<a href=view.php?id_node=$id_parent>$name</a> > ".$path;
}
} else {
$path = "<a href=view.php?id_node=$id_parent>$name</a> > ".$path;
}
$id_parent = $id_node;
}
// mydebug(__LINE__,__FILE__,$path);
}

}

// we are at the first level
$dataHa = $dh->get_node_info($id_toc);
$tocname = $dataHa['name'];
if ($target == "map") {
$path = "<a href=map.php?id_node=$id_toc>$tocname</a> > ".$path;
} else {
$path = "<a href=view.php?id_node=$id_toc>$tocname</a> > ".$path;
}
return $path;

}


function get_filter_links_FN($linksAR,$user_level=1) {
// filtro sui link:
// verifica se i nodi linkati hanno livello<= a quello dell'utente
// torna un array associativo
$ok_link = array();
$data_Ar = array();
if (!empty($linksAR)) {
$linkAr = $linksAR;
foreach ($linkAr as $id_link){
$linkObj = new Link($id_link);
$id_linked_node = $linkObj->to_node_id;
$link_meaning = $linkObj->meaning;
$link_action = $linkObj->action;
$link_style = $linkObj->style;
$link_type = $linkObj->type;

// $node = $sess_id_course."_".$id_linked_node;
$node = $id_linked_node;
$tempNodeObj = new Node($node);
$linked_node_name = $tempNodeObj->name;
$linked_node_level = $tempNodeObj->level;
if (($linked_node_level<=$user_level) and (!empty($id_linked_node))) {
$ok_link = array('id_link'=>$id_link,'id_node_to'=>$id_linked_node,'meaning_link'=>$link_meaning,'type_link'=>$link_type,'action_link'=>$link_action);
//mydebug(__LINE__,__FILE__,$ok_link);
array_push($data_Ar,$ok_link);
// mydebug(__LINE__,__FILE__,$data_Ar);
}
}
return $data_Ar;
} else {
return "";
}
}


function filter_nodeFN($user_level,$user_history,$id_profile='3',$querystring=''){
/*
restituisce i dati visibili per l'utente in un array associativo

filtri attivi:
- media (in base al browser, dovrebbe farlo in base al profilo ,$id_profile)
- links (in base allo userlevel)
-

*/

if (!isset($id_profile))
$id_profile = AMA_TYPE_STUDENT;
$htmldataHa['text'] = $this->get_textFN($user_level,$querystring);
$htmldataHa['media'] = $this->get_mediaFN($user_level);
// prova
$htmldataHa['media'].= $this->get_user_mediaFN($user_level);
$htmldataHa['link'] = $this->get_linksFN($user_level,$id_profile);
$htmldataHa['exercises'] = $this->get_exercisesFN($user_level);
$htmldataHa['notes'] = $this->get_notesFN($user_level,$id_profile);


return $htmldataHa;

}


function get_textFN($user_level,$querystring){
// filtro sul testo
// verifica se il nodo ha livello<= a quello dell'utente
// sostituisce i link e i media di tipo img se IMG_VIEWING_MODE=2


//global $dh,$media_path,$root_dir,$http_root_dir;
//global $sess_id_course;
$dh = $GLOBALS['dh'];
$media_path = $GLOBALS['media_path'];
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];
$sess_id_course = $GLOBALS['sess_id_course'];

$level_filter = 1;
$link_filter = 1;
$extlink_filter = 1;
$media_filter = 1;
$query_filter = 1;

$parsing_text[] = $this->text;

if ($level_filter){
$node_level = $this->level;
if ($node_level>$user_level){
return translateFN("Il contenuto di questo nodo non è accessibile ad utenti di livello $user_level");
}
}

//media
/* type:
img= 0
audio = 1
video = 2
linkext = 3
*/

if ($media_filter){
// img
$unparsed_text = current($parsing_text);
$author = $this->author['username'];
$clause = "username = '$author'";
$field_list = array();
$res = $dh->find_authors_list($field_list,$clause);
if (AMA_DataHandler::isError($res)){
$msg = urlencode($res->getMessage());
header("Location: $error?err_msg=$msg");
}
if (sizeof($res)<1){
$author_dir = ""; //integrity error !
} else {
$author_dir = $res['0']['0'];
}



if (MEDIA_LOCAL_PATH){
$file_path = MEDIA_LOCAL_PATH . $media_path ;
$http_file_path = MEDIA_LOCAL_PATH . $media_path ;
} else {
$file_path = $root_dir . $media_path ;
$http_file_path = $http_root_dir . $media_path ;
}
/*
if (MEDIA_LOCAL_PATH){
$http_file_path = MEDIA_LOCAL_PATH . $media_path . $author_dir."/";
$file_path = MEDIA_LOCAL_PATH . $media_path . $author_dir."/";
} else {
$http_file_path = $http_root_dir . $media_path . $author_dir."/";
$file_path = $root_dir . $media_path . $author_dir."/";
}
*/

// echo "$http_root_dir $media_path $http_file_path <br>" ;

$img = "<MEDIA TYPE=\"0\" VALUE=\"([a-zA-Z0-9_ ]+).([a-zA-Z]{1,3})\">";
$is_img = eregi($img,$unparsed_text,$regs);
if ($is_img){
$img_file = $regs[1];
switch (IMG_VIEWING_MODE){
case 2:
// tag are replaced by fullsize img
$exploded_img = "<img src=\"$http_file_path\\1.\\2\" alt=\"\\1.\\2\">";
$parsing_text[] = eregi_replace($img,$exploded_img,$unparsed_text);
break;
case 1:
case 0:
default:
// tag are replaced by icons
$exploded_img = "<a href=\"$http_file_path\\1.\\2\"><img src=\"img/_img.gif\" border=\"0\" alt=\"\\1.\\2\"></a>";
$parsing_text[] = eregi_replace($img,$exploded_img,$unparsed_text);

}

}

// audio
$unparsed_text = end($parsing_text);
// $unparsed_text = current($parsing_text);
$audio= "<MEDIA TYPE=\"1\" VALUE=\"([a-zA-Z0-9_ ]+)\.([a-zA-Z0-9]{1,3})\">";
$is_audio = eregi($audio,$unparsed_text,$regs);
if ($is_audio){
$audio_file = $regs[1];
$exploded_audio = "<a href=\"$http_file_path\\1.\\2\" target=\"_blank\"><img src=\"img/_audio.gif\" border=\"0\" alt=\"\\1.\\2\"></a>";
$parsing_text[] = eregi_replace($audio,$exploded_audio,$unparsed_text);
}


// video
$unparsed_text = end($parsing_text);
$video= "<MEDIA TYPE=\"2\" VALUE=\"([a-zA-Z0-9_ ]+)\.([a-zA-Z]{1,3})\">";
$is_video = eregi($video,$unparsed_text,$regs);
if ($is_video){
$video_file = $regs[1];
$extension = $regs[2];
switch ($extension){
case "dcr": //shockwave
$exploded_video = "<object classid=\"clsid:166B1BCA-3F9C-11CF-8075-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,0,0,0\" width=\"400\" height=\"300\">
<param name=movie value=\"$http_file_path\\1.\\2\">
<embed src=\"$http_file_path\\1.\\2\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/\"width=\"400\" height=\"300\">
</embed>
</object>";
break;
case "swf": // flash
$exploded_video = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"400\" height=\"300\">
<param name=movie value=\"$http_file_path\\1.\\2\">
<param name=quality value=high>
<embed src=\"$http_file_path\\1.\\2\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"400\" height=\"300\">
</embed>
</object>";
break;
case "avi":
case "mpg":
default:
$exploded_video = "<a href=\"$http_file_path\\1.\\2\" target=\"_blank\"><img src=\"img/_video.gif\" border=\"0\" alt=\"\\1.\\2\"></a>";
}


$parsing_text[] = eregi_replace($video,$exploded_video,$unparsed_text);
}

}
// ext-link
if ($extlink_filter){
$unparsed_text = end($parsing_text);
$ext_link = "<MEDIA TYPE=\"3\" VALUE=\"([a-zA-Z0-9_~ ]+)\.([a-zA-Z]{1,4})\">"; // qualsiasi cosa...
$is_ext_link = eregi($ext_link,$unparsed_text,$regs);
if ($is_ext_link){
$file_name = $regs[0]; //echo $file_name;
if (stristr($file_name,"http:")) {
$exploded_ext_link = "<a href=\"$http_file_path\\1.\\2\" target=\"_blank\"><img src=\"img/_web.gif\" border=\"0\" alt=\"\\1.\\2\"></a>";

} else {
$exploded_ext_link = "<a href=\"$http_file_path\\1.\\2\" target=\"_blank\"><img src=\"img/_linkext.gif\" border=\"0\" alt=\"\\1.\\2\"></a>";
}
$parsing_text[] = eregi_replace($ext_link,$exploded_ext_link,$unparsed_text);

}
}

if ($link_filter){
//link : we have to filter these links !!!!
$unparsed_text = end($parsing_text);
$link= "<LINK TYPE=INTERNAL VALUE=\"([0-9]{1,4})\">";
$is_linked = eregi($link,$unparsed_text,$regs);
while ($is_linked){
$id_link = $regs[1];
if (!empty($id_link)){
$linked_node_id = $sess_id_course."_".$id_link;
$nodeObj = new Node($linked_node_id);
if ($nodeObj->full==1) {
$linked_node_level = $nodeObj->level;
$name = $nodeObj->name;
$link= "<LINK TYPE=INTERNAL VALUE=\"$id_link\">";
if ($linked_node_level<=$user_level){
$exploded_link = "<a href=view.php?id_node=".$linked_node_id."><img src=\"img/_linka.gif\" border=\"0\" alt=\"$name\"></a>";
$parsing_text[] = eregi_replace($link,$exploded_link,$unparsed_text);
} else {
$exploded_link = "<img src=\"img/_linkdis.gif\" border=\"0\" alt=\"$name\">";
$parsing_text[] = eregi_replace($link,$exploded_link,$unparsed_text);
}

} else {
$link= "<LINK TYPE=INTERNAL VALUE=\"$id_link\">";
$exploded_link = "<img src=\"img/_linkdis.gif\" border=\"0\" alt=\"$id_link\">";
$parsing_text[] = eregi_replace($link,$exploded_link,$unparsed_text);

}
}
$unparsed_text = end($parsing_text);
$link= "<LINK TYPE=INTERNAL VALUE=\"([0-9]{1,4})\">";
$is_linked = eregi($link,$unparsed_text,$regs);
}

}
if ($query_filter){
// query string (from search)
if (isset($querystring) && $querystring!="") {
$dim_query = substr_count ($querystring, " ");
$is_or_query = ($dim_query >= 1);
if (!$is_or_query){
$unparsed_text = end($parsing_text);
$stringa = split(' ',$unparsed_text);
$str_new = "";
for($k=0;$k<count($stringa);$k++) {
if (strtoUpper($querystring) == strtoUpper(strip_tags($stringa[$k]))) {
$str_new .= "<span style=\"background-color: #FFFF00;\">".$stringa[$k]."</span> ";
} else {
$str_new .= $stringa[$k]." ";
}
}
$parsing_text[] = $str_new;
}
}
}
return end($parsing_text);

// fine filtro testo
}

function get_linksFN($user_level,$id_profile){
//global $dh,$error,$debug;
//global $sess_id_course,$sess_id_course_instance,$sess_id_user;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];
$sess_id_course = $GLOBALS['sess_id_course'];
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_user = $GLOBALS['sess_id_user'];

// filtro sui link:
// verifica se i nodi linkati hanno livello<= a quello dell'utente

if (!empty($this->links)) {
$linkAr =$this->links;
// mydebug(__LINE__,__FILE__,$linkAr);
$dataAr = array();
foreach ($linkAr as $id_link){
$linkObj = new Link($id_link);
//$debug=1; mydebug(__LINE__,__FILE__,$linkObj);$debug=0;
$id_linked_node = $linkObj->to_node_id;
$link_meaning = translatefN("Tipo:").$linkObj->meaning;
$node = $id_linked_node;
$tempNodeObj = new Node($node);
//$debug=1; mydebug(__LINE__,__FILE__,$tempNodeObj);$debug=0;

if ($tempNodeObj->full==1) {
$linked_node_name = $tempNodeObj->name;
$linked_node_level = $tempNodeObj->level;
if ($linked_node_level<=$user_level){
switch ($id_profile){
case AMA_TYPE_STUDENT:
default:
$visit_count = User::is_visited_by_userFN($node,$sess_id_course_instance,$sess_id_user);
break;
case AMA_TYPE_TUTOR:
$visit_count = User::is_visited_by_classFN($node,$sess_id_course_instance,$sess_id_user);
break;
case AMA_TYPE_AUTHOR:
$visit_count = User::is_visitedFN($node);
}

if ($visit_count<=0){
$ok_link = array("<img src=\"img/_linka.gif\">","&nbsp;<b><a href=view.php?id_node=$node alt=\"$link_meaning\">$linked_node_name</a></b>");
} else {
$ok_link = array("<img src=\"img/_linka.gif\">","&nbsp;<a href=view.php?id_node=$node alt=\"$link_meaning\">$linked_node_name</a> ($visit_count)");
}
} else {
$ok_link = array("<img src=\"img/_linkdis.gif\">","&nbsp; ".$linked_node_name);
// $ok_link = array("<img src=\"templates/default/img/_linkdis.gif\">",$linked_node_name);
}
} else {
//$ok_link =array("&nbsp;","&nbsp;");
$ok_link =array("<img src=\"img/_linkdis.gif\" alt=\"$node\">",translateFN("nodo non trovato"));
}
array_push($dataAr,$ok_link);
}

$t = new Table();
$t->initTable('0','center','0','0','100%','blue','white','blue','white','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Indice dei nodi collegati"));
return $t->getTable();
} else {
return translateFN("Nessuno");
}
}
// fine filtro links

function get_exercisesFN($user_level){
//global $dh,$error;
//global $sess_id_user, $sess_id_course_instance;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_user = $GLOBALS['sess_id_user'];

// filtering exercises:
// have the exercises been already executed?
// HTML EMBEDDED VERSION
if (!empty($this->children)) {

$exerc_Ar =$this->children;
// mydebug(__LINE__,__FILE__,$exerc_Ar);
$dataAr = array();
foreach ($exerc_Ar as $id_exerc){
$temp = $dh->get_node_info($id_exerc);
$type = $temp['type'];
if ($type >= ADA_STANDARD_EXERCISE_TYPE) {
$exercise = $dh->get_node_info($id_exerc);
// mydebug(__LINE__,__FILE__,$exercObj);
$exerc_title = $exercise['name'];
$out_fields_ar = array('data_visita','ripetibile');
$history_exerc = $dh->find_ex_history_list($out_fields_ar,$sess_id_user, $sess_id_course_instance, $id_exerc);
if (is_array($history_exerc)){
$h_exerc = array_shift($history_exerc);
// global $debug; $debug = 1; mydebug(__LINE__,__FILE__,$h_exerc); $debug=0;
if (is_array($h_exerc))
$already_executed = !$h_exerc[2];
else
$already_executed = "";
} else {
$already_executed = "";
}


if (!$already_executed) { // not yet viewed or repeatable
$alt = translateFN("Esercizio");
$icon = "_exer.gif";
$ok = true;
} else {
$alt = translateFN("Esercizio già eseguito");
$icon = "_exerdis.gif"; // _gruppodis.gif
$ok = false;
}

if ($ok){
$exerc_ok = array("<img name=gruppo alt=\"$alt\" src=\"img/$icon\"> <a href=exercise.php?id_node=$id_exerc>$exerc_title</a>");
} else {
$exerc_ok = array("<img name=gruppo alt=\"$alt\" src=\"img/$icon\">$exerc_title");
}

array_push($dataAr,$exerc_ok);
}
}

$t = new Table();
$t->initTable('0','center','0','0','100%','','','','','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Indice degli esercizi collegati"));
return $t->getTable();
} else {
return translateFN("Nessuno")."<p>";
}
}
// fine filtro esercizi

function get_notesFN($user_level,$id_profile){
//global $dh,$error,$debug;
//global $sess_id_user, $sess_id_course_instance;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];
$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_user = $GLOBALS['sess_id_user'];

if (!empty($this->children)) {

$notes_Ar =$this->children;
$dataAr = array();
foreach ($notes_Ar as $id_note){
$nodeObj = new Node($id_note);
// $debug=1; mydebug(__LINE__,__FILE__,$nodeObj); $debug=0;
$type = $nodeObj->type;
$node_instance = $nodeObj->instance;
if ($type == 2) { // notes
$name = $nodeObj->name;
$level = $nodeObj->level;
$authorHa = $nodeObj->author;
$autore = $authorHa['id'];
// $debug=1; mydebug(__LINE__,__FILE__,$authorHa); $debug=0;
// $node_author = $authorHa['nome']." ". $authorHa['cognome'];
//echo "<p>";
if ($sess_id_course_instance == $node_instance){
switch (VIEW_PRIVATE_NOTES_ONLY){
case 0: // every node added by student or tutor of THIS course and of THIS instance are visible
$is_note_visibile = 0;
switch ($id_profile){
case AMA_TYPE_TUTOR:
$class_tutor_id = $dh->course_instance_tutor_get($sess_id_course_instance);
if (($class_tutor_id == $sess_id_user) &&
($autore == $sess_id_user )
){
$is_note_visibile = 1;
$alt = translateFN("Nota del tutor");
$node_author = translateFN(" del tutor");
$icon = "_nota_tutor.gif";
} else {
$author_dataHa = $dh->get_subscription($autore, $sess_id_course_instance);
if (!DB::isError($author_dataHa)){
$is_note_visibile = 1;
$alt = translateFN("Nota dello studente");
$node_author = translateFN("di")." ".$authorHa['username'];
$icon = "_nota.gif";
}
}
break;
case AMA_TYPE_AUTHOR:
$is_note_visibile = 0;
case AMA_TYPE_STUDENT:
$author_dataHa = $dh->get_subscription($autore, $sess_id_course_instance);
if (!DB::isError($author_dataHa)){
$is_note_visibile = 1;
$alt = translateFN("Nota dello studente");
$node_author = translateFN("di")." ".$authorHa['username'];
$icon = "_nota.gif";
}
}
if ($is_note_visibile){
$note_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_note.">$name</a> $node_author");
array_push($dataAr,$note_link);
}
break;
case 1: // only nodes added by this user and of THIS instance are visible
if ($autore==$sess_id_user)
{
$alt = translateFN("Nota privata");
$icon = "_nota.gif";
$note_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> <a href=view.php?id_node=".$id_note.">$name</a>");
array_push($dataAr,$note_link);

}
break;
default:
$alt = translateFN("Nota non visitabile");
$icon = "_unknown.gif";
$note_link = array("<img name=\"nota\" alt=\"$alt\" src=\"img/$icon\"> ".$node_data_Ha['name']);
array_push($dataAr,$note_link);
}

} else {
$is_note_visibile = 0;
}
}
}

$t = new Table();
$t->initTable('0','center','0','0','100%','white','','white','','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Indice delle note"));
return $t->getTable();
} else {
return translateFN("Nessuno")."<p>";
}
}
// fine filtro note

function get_mediaFN($user_level){
//global $HTTP_USER_AGENT;
//global $dh,$error, $media_path, $root_dir, $http_root_dir;
//global $sess_id_course;
//global $debug;
$HTTP_USER_AGENT = $GLOBALS['HTTP_USER_AGENT'];
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$media_path = $GLOBALS['media_path'];
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];
$sess_id_course = $GLOBALS['sess_id_course'];
$debug = $GLOBALS['debug'];


$node_level = $this->level;
if ($node_level<=$user_level){
$script = "";
// filtro sui media:
// dovrebbe verificare se nel profilo dell'utente si richiede una navigazione text-only, se il browser è abilitato etc
// per ora controlla solo se il browser supporta javascript
// qui va inserita la versione CD/WEB
$dataAr = array();
if (!empty($this->media) and !is_object($this->media)){
$browser = $HTTP_USER_AGENT;
$javascript_ok = check_javascriptFN($browser);
$mediaAr = $this->media;
$dataAr = array();
foreach ($mediaAr as $res_id) {
$mediaObj = new Media($res_id);
$media_name = $mediaObj->file_name;
$media_type = $mediaObj->media_type;
/*global $debug; $debug=1;
mydebug(__LINE__,__FILE__,$mediaObj);
$debug=0;
*/
$author = $this->author['username'];
if (empty($media_path)) {
$clause = "username = '$author'";
$field_list = array();
$res = $dh->find_authors_list($field_list,$clause);
if (AMA_DataHandler::isError($res)){
$msg = $res->getMessage();
// header("Location: $error?err_msg=$msg");
}
$author_dir = $res['0']['0'];
$media_path = "courses/media/".$author_dir."/";
} else {
//echo $media_path;
}

if (!empty($media_name)) {
if (($media_type<3) OR (!stristr($media_name,"http:")))
{ // 0,1,2 + files
if (MEDIA_LOCAL_PATH!=null){
$file_name = MEDIA_LOCAL_PATH . $media_path . $media_name;
$file_name_http = MEDIA_LOCAL_PATH . $media_path . $media_name;
} else {
$file_name = $root_dir . $media_path . $media_name;
$file_name_http = $http_root_dir . $media_path . $media_name;
}
} else { // http
$file_name = $media_name;
$file_name_http = $media_name;
}
// echo "$file_name $file_name_http<br>";
}
//if (!empty($media_name)) {
// $file_name = $root_dir . $media_path . $media_name;
// $file_name_http = $http_root_dir . $media_path . $media_name;

if (($media_type<3) AND (file_exists($file_name))){
// Controllo del tipo di media
switch ($media_type) {
case 0: //img

$size = GetImageSize($file_name);
$x = $size[0];
$y = $size[1];
$r = 10;
/*
$debug=1;
mydebug(__LINE__,__FILE__,$file_name);
mydebug(__LINE__,__FILE__,$size);
$debug=0;
*/

switch (IMG_VIEWING_MODE){ // it would be better to use a property instead
case 2: // full img in page, only icon here
if ($javascript_ok) {
$link_media= "<img src=\"img/_img.gif\"> <A HREF=\"#\" ONCLICK=\"newWindow('$file_name_http',$x,$y)\">$media_name</a>";
} else {
$link_media= "<img src=\"img/_img.gif\"> <a href=\"$file_name_http\" target=\"img_win\" >$media_name</a>";
}
break;
case 1: // icon in page, a reduced size preview here
if ($javascript_ok) {
$link_media= "<img src=\"include/resize.php?img=$file_name&ratio=$r\"> <A HREF=\"#\" ONCLICK=\"newWindow('$file_name_http',$x,$y)\">$media_name</a>";
} else {
$link_media= "<img src=\"include/resize.php?img=$file_name&ratio=$r\"> <a href=\"$file_name_http\" target=\"img_win\" >$media_name</a>";
}
break;
case 0: // icon in page, icon here
default:
if ($javascript_ok) {
$link_media= "<img src=\"img/_img.gif\"> <A HREF=\"#\" ONCLICK=\"newWindow('$file_name_http',$x,$y)\">$media_name</a>";
} else {
$link_media = "<img src=\"img/_img.gif\"> <a href=\"$file_name_http\" target=\"img_win\" >$media_name</a>";
//mydebug(__LINE__,__FILE__,$link_media);
}
}
break;
case 1:
$link_media = "<img src=\"img/_audio.gif\"> <a href=\"$file_name_http\">$media_name</a>";
break;
case 2:
$link_media = "<img src=\"img/_video.gif\"> <a href=\"$file_name_http\" target=\"img_win\" >$media_name</a>";
break;
}

} else {
if ($media_type == 3){
if (stristr($media_name,"http")) {
$link_media = "<img src=\"img/_web.gif\"> <a href=\"$file_name_http\" target=\"img_win\" >".wordwrap($media_name,20,"\n",1)."</a>";
} else {
$link_media = "<img src=\"img/_linkext.gif\"> <a href=\"$file_name_http\" target=\"img_win\" >$media_name</a>";
}
} else {
$link_media =$media_name.": ".translateFN("non riconosciuto");
}
}
$ok_media = array ('media'=>$link_media);

array_push($dataAr,$ok_media);

}
}



/*
*/
if (count($dataAr)) {
$t = new Table();
$t->initTable('0','center','2','0','100%','blue','white','blue','white','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Indice dei Media collegati"));
$t->getTable();
return $t->data;
} else {
return "";
}

} else {
return translateFN("Nessuno");
}
//}
// fine filtro media
}

/*
// filtro sulla history:
// verifica se il nodo è già stato visitato

$node_id = $this->id;
$user_historyAr = explode(',',$user_history);
// mydebug(__LINE__,__FILE__,$user_historyAr);
$visitato = in_array($node_id, $user_historyAr);
if ($visitato){
$quantevolteAr = array_count_values($user_historyAr);
$quantevolte = $quantevolteAr[$node_id];
$htmldataHa['text'] .= "<p>$quantevolte".translateFN("Questo nodo è stato già visitato $quantevolte volte.")."</p>";
} else {
$htmldataHa['text'] .= "<p>".translateFN("E' la prima volta che visiti questo nodo.")."</p>";
}



// fine filtro history
*/

function get_user_mediaFN($user_level){
// indexing files
$root_dir = $GLOBALS['root_dir'];
$http_root_dir = $GLOBALS['http_root_dir'];
$sess_id_course_instance = $_SESSION['sess_id_course_instance'];
$sess_id_course = $_SESSION['sess_id_course'];
$sess_id_node = $_SESSION['sess_id_node'];
$dh = $GLOBALS['dh'];


$course_ha = $dh->get_course($sess_id_course);
if (AMA_DataHandler::isError($course_ha)){ // not enrolled yet?
return "";
}
$author_id = $course_ha['id_autore'];
$elencofile = $this->read_user_dirFN("$root_dir/courses/media/$author_id");
if ($elencofile == NULL)//($stop<1)
return "";

$stop = count($elencofile);
$media = "<p><strong>".translateFN("Media inviati dalla classe")."</strong><br>";
$dataAr = array();

$lObj = new IList();
$lObj->initList('0','disc',1);

for ($i=0; $i<$stop; $i++){
$data = $elencofile[$i]['data'];
$complete_file_name = $elencofile[$i]['file'];
// rebuilding true file name
// rootdir + media path + author_id + filename + id_course_instance + user_id + node_id
// ex. 111_27_113_0_example.txt'
$filenameAr = explode('_',$complete_file_name);
$stop = count($filenameAr)-1;
$course_instance = $filenameAr[0];
$id_sender = $filenameAr[1];
$id_node = $filenameAr[2]."_".$filenameAr[3];
$filename = "";
for ($k = 4; $k<=$stop;$k++){
$filename .= $filenameAr[$k];
if ($k<$stop)
$filename .= "_";
}
$senderObj = read_user_from_DB($id_sender);
if ((is_object($senderObj)) OR (!empty($senderObj->error_msg))) {
$id_profile = $senderObj->tipo;
switch ($id_profile){
case AMA_TYPE_STUDENT:
case AMA_TYPE_AUTHOR:
case AMA_TYPE_TUTOR:
$user_name = $senderObj->username;
break;
default:
// errore
$sender_error = 1;
}
}

if ((!$sender_error) AND ($course_instance == $sess_id_course_instance)){
if (!isset($fid_node) OR ($fid_node == $sess_id_node))
array_push($dataAr,"<a href=\"$http_root_dir/user/index.php?module=download.php&amp;file=$complete_file_name\" target=_blank>$filename</a> <br> $user_name : $data");
}
}
$lObj->setList($dataAr);
$var = $lObj->getList();
$media.="$var</p>\n";
return $media;
}

// functions
function read_user_dirFN($dir){
$nomedata = array();
$elencofile = "";
$dirid = @opendir($dir);
if ($dirid){
$i = 0;
while (($file = readdir($dirid))!=false){
if (
(stristr($dir.$file,".txt")) OR
(stristr($dir.$file,".doc")) OR
(stristr($dir.$file,".xls")) OR
(stristr($dir.$file,".rtf")) OR
(stristr($dir.$file,".ppt")) OR
(stristr($dir.$file,".htm")) OR
(stristr($dir.$file,".pdf")) OR
(stristr($dir.$file,".jpg")) OR
(stristr($dir.$file,".gif"))

){
$elencofile[$i]['file'] = $dir."/".$file;
$filetime = date("d/m/y",filemtime($dir."/".$file));
$elencofile[$i]['data'] = $filetime;
$elencofile[$i]['file'] = $file;
$i++;
}
}
closedir ($dirid);
// va ordinato ora
if (is_array($elencofile)){
sort($elencofile);
reset($elencofile);
}
}
return $elencofile;
}





/* da implementare ancora: */

function is_allowedFN($command,$id_profile){
$dh = $GLOBALS['dh'];

// $dataHa = $dh->get_info($id_profile);


switch ($id_profile){
case AMA_TYPE_AUTHOR:
return TRUE;
break;
case AMA_TYPE_STUDENT:
case AMA_TYPE_TUTOR:
return FALSE;
break;
default:
return FALSE;
}


}


function edit($id_profile){
// va al form di modifica del nodo attuale se l'utente ha le permission giuste
$sess_id_node = $GLOBALS['sess_id_node'];
$id_node = $this->id;
if ($this->is_allowedFN('modify',$id_profile)){
header("Location: ../courses/edit_node.php?op=edit&id_node=$sess_id_node");
};
}

function delete($id_profile){
// elimina il nodo attuale se l'utente ha le permission giuste
$dh = $GLOBALS['dh'];
$id_node = $this->id;
if ($this->is_allowedFN('delete',$id_profile)){
header("Location: ../courses/edit_node.php?op=delete&id_node=$sess_id_node");
};

}

/* OTHER FUNCTIONS

function send($id_user){
//etc
}


function print($id_user){
//etc
}

function link($id_user){
// etc
}


function execute($id_user){
// esegue lo script associato al nodo attuale se l'utente ha le permission giuste
}


function annotate(){}

*/

} //end class node

class Exercise extends Node {

function get_exerciseFN($user_level=1,$user_history='',$id_node){

//global $dh,$error,$self;
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$self = $GLOBALS['self'];
$debug = $GLOBALS['debug'];

$dataAr = array();
$children = $this->children;
$node_dataHa = $dh->get_node_info($id_node);

// mydebug(__LINE__,__FILE__,$children);

$text = array($this->text);
array_push($dataAr,$text);

// $exercise_type = count($children); // 0: open, 1:single , >1:multiple choice
$exercise_type = $node_dataHa['type']; // 3 - Multiple Answer, 4 - Free Answer, 5 - Single answer with check, 6 - Cloze

$fields["add"][]="op";
$names["add"][]="";
$edittypes["add"][]="hidden";
$necessary["add"][]="";
$values["add"][]="answer";
$options["add"][]="";
$maxsize["add"][]="";

$fields["add"][]="exercise_type";
$names["add"][]="";
$edittypes["add"][]="hidden";
$necessary["add"][]="";
$values["add"][]=$exercise_type;
$options["add"][]="";
$maxsize["add"][]="";

switch ($exercise_type){
case 4:
// open type with manual feedback

$risp_desc = translateFN('Risposta:');

$fields["add"][]="useranswer";
$names["add"][]=$risp_desc; //translateFN('Risposta');
$edittypes["add"][]="textarea";
$necessary["add"][]="";
$values["add"][]="";
$options["add"][]="";
$maxsize["add"][]=400;

// input file
$fields["add"][]="file_up";
$names["add"][]="File allegato:";
$edittypes["add"][]="file";
$necessary["add"][]="";
$values["add"][]="";
$options["add"][]="";
$maxsize["add"][]=255;

// creazione del form
$form = MakeForm($fields,$names,$edittypes,$necessary,$values,$options,$maxsize,$self.".php?id_node=$id_node","add",false,true);
array_push($dataAr,array($form));
break;

case 5:
// open type with automatic feedback

$fields["add"][]="useranswer";
$names["add"][]=""; //translateFN('Risposta');
$edittypes["add"][]="textarea";
$necessary["add"][]="";
$values["add"][]="";
$options["add"][]="";
$maxsize["add"][]=400;

// creazione del form
$form = MakeForm($fields,$names,$edittypes,$necessary,$values,$options,$maxsize,$self.".php?id_node=$id_node","add",false,true);
array_push($dataAr,array($form));
break;

case 3:
// Multiple Answer
default:
// multiple choice type
$k=0;
if (is_array($children)) {
foreach ($children as $id_child) {
if (!empty($id_child)){
$k++;
//$node_childObj = new Node($id_child);
//$children_link = array("&nbsp;","<img name=gruppo alt=\"nodo\" src=\"img/_nodo.gif\"> <a href=view.php?id_node=".$id_child.">".$node_childObj->name."</a>");
$answ_dataHa = $dh->get_node_info($id_child);

$fields["add"][]="useranswer[]"; // name
$names["add"][]=$k." ".$answ_dataHa['name'].":"; // label
$edittypes["add"][]="radio";
$necessary["add"][]="";
$values["add"][]=$id_child.":";
$options["add"][]=$id_child.":";
$maxsize["add"][]=32;
// $answer = array(translateFN("Risposta n.").$k,"<a href=exercise.php?op=answer&choice=".$id_child.">".$answ_dataHa['name']."</a>");
// OPPURE $answer = array(translateFN("Risposta n.").$k,"<a href=exercise.php?op=answer&choice=".$id_child.">".$answ_dataHa['text']."</a>");
// array_push($dataAr,$answer);
}
}
$form = MakeForm($fields,$names,$edittypes,$necessary,$values,$options,$maxsize,$self.".php?id_node=$id_node","add",false,true);
array_push($dataAr,array($form));

}


}
$t = new Table();
$t->initTable('0','center','0','0','100%','','','','','0','0');
$t->setTable($dataAr,$caption="",$summary=translateFN("Esercizio:"));
$t->getTable();
return $t->data;

}

function get_surveyFN($user_level=1,$user_history='',$id_node){


$sess_id_course_instance = $GLOBALS['sess_id_course_instance'];
$sess_id_course = $GLOBALS['sess_id_course'];
$dh = $GLOBALS['dh'];
$dataAr = array();
$children = $this->children;
//$node_dataHa = $dh->get_node_info($id_node);

// mydebug(__LINE__,__FILE__,$children);

$textAr = array(
array('testo'=>$this->text)
);
$t = new Table();
$t->initTable('0','center','0','0','100%','','','','','0','0');
$t->setTable($textAr,$caption=translateFN("Esercizio:"),$summary=translateFN("Esercizio:"));
$t->getTable();
$text = $t->data;

// $exercise_type = count($children); // 0: open, 1:single , >1:multiple choice
$exercise_type = $node_dataHa['type']; //
switch ($exercise_type){
case 4:
case 5:
break;
case 3:
default:
if (is_array($children)) {
$visit_countAr = array(
array ('label'=>translateFN("Risposta"),'punteggio'=>translateFN("Punteggio"),'visits'=>translateFN("Corsisti"))
);

foreach ($children as $id_child) {
if (!empty($id_child)){
$k++;
$ans_dataHa = $dh->get_node_info($id_child);
$visits = User::exer_is_visited_by_classFN($id_child,$sess_id_course_instance,$sess_id_course);
$visit_countAr[] = array (
'label'=>"<a href=\"view.php?id_node=$id_child\">".$ans_dataHa['name']."</a>",
'punteggio'=>$ans_dataHa['correctness'],
'visits'=>$visits
);
}
}

}
}
$t = new Table();
$t->initTable('0','center','0','0','100%','','','','','0','0');
$t->setTable($visit_countAr,$caption=translateFN("Risposte:"),$summary=translateFN("Risposte:"));
$t->getTable();
$survey = $t->data;
return $text.$survey;
}

} //end class exercise


class Resource
{
var $id_resource;
var $full;
var $error_msg;

} //end class Resource

class Media extends Resource
{
var $file_name;
var $media_type;
var $media_copyright;

function media($res_id) {
//global $dh,$error;
// constructor
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];

$dataHa = $dh->get_risorsa_esterna_info($res_id);

if (AMA_DataHandler::isError($dataHa) || (!is_array($dataHa))){
$msg = $dataHa->getMessage();
if (!strstr ($msg, 'record not found')) {
header("Location: $error?err_msg=$msg");
exit;
} else {
$this->full = 1;
return $msg;
}
}


if (!empty($dataHa['nome_file'])){
$mediaHa = $dataHa;
$this->file_name = $mediaHa['nome_file'];
$this->media_type = $mediaHa['tipo'];
$this->media_copyright = $mediaHa['copyright'];

$this->full = 1;
} else {
$this->error_msg = translateFN("Nessuno");
}
}

}

class Link extends Resource
{

var $position;
var $type;
var $node_id;
var $author;
var $meaning;
var $creation_date;
var $to_node_id;
var $style;
var $action;


function link($id_link){
//global $dh,$error;
// constructor
$dh = $GLOBALS['dh'];
$error = $GLOBALS['error'];
$debug = $GLOBALS['debug'];

$dataHa = $dh->get_link_info($id_link);
if (AMA_DataHandler::isError($dataHa) || (!is_array($dataHa))){
$msg = $dataHa->getMessage();
if (!strstr ($msg, 'record not found')) {
header("Location: $error?err_msg=$msg");
exit;
} else {
$this->full = 1;
return $msg;
}
}



if (!empty($dataHa['id_nodo'])){
// foreach ($dataHa as $linkHa) {
$linkHa = $dataHa; //?? è uno solo???
$this->position = $linkHa['posizione'];
$this->author = $linkHa['autore'];
$this->node_id = $linkHa['id_nodo'];
$this->to_node_id = $linkHa['id_nodo_to'];
$this->type = $linkHa['tipo'];
$this->creation_date = $linkHa['data_creazione'];
$this->style = $linkHa['stile'];
$this->action = $linkHa['azione'];
$this->meaning = $linkHa['significato'];
// }

$this->full = 1;
} else {
$this->error_msg = translateFN("Nessuno");
}

}

}

// end class Link

?>
*****************************

index.php***********************************

<?php

//
// +----------------------------------------------------------------------+
// | ADA version 1.7 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2004 Lynx |
// +----------------------------------------------------------------------+
// | |
// | I N D E X | |
// | |
// | |
// | |
// | |
// +----------------------------------------------------------------------+
// | Author: Stefano Penge <steve@lynxlab.com> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: index.php,v 1.7 2004/05/05
//

$debug=0;

/* 1
included modules and default values
*/

$ada_config_path = realpath(dirname(__FILE__));
include_once($ada_config_path.'/config_path.inc.php');

@session_destroy();
session_start();
session_register("sess_id_user");
session_register("sess_id_user_type");
session_register("sess_user_language");


include_once("$root_dir/browsing/include/includes.inc.php");
include_once("$root_dir/include/aut/login.inc.php");


// Configuration domain vs requested domain

$serv_temp = substr($http_root_dir,7);
$n = strpos($serv_temp,"/");
$server = substr($serv_temp,0,$n);
$real_server = $_SERVER['SERVER_ADDR'];
if ($real_server != $server){
//header("Location: $http_root_dir/index.php");
// Warning: this feature doesn't work if you have more installations of ADA at the same address
// echo "<!-- Config domain ($server) is different from requested domain ($real_server) -->\n";
}

$self = 'index';

$session_id_par = get_param_stringFN(); // data session passed as http GET parameters

$dh = new AMA_DataHandler(); // init ADA Middle API
$ymdhms = today_dateFN();

$ada_ver = ADA_VERSION;

/* 2.
finding all available courses
*/


$field_list_ar = array('nome','titolo','data_pubblicazione');
$clause = ''; // matching conditions: ...
$dataHa = $dh->find_courses_list($field_list_ar, $clause);

if (AMA_DataHandler::isError($dataHa)){
$msg = $dataHa->getMessage();
echo "<b>Error: $msg</b>";
// header("Location: $error?err_msg=$msg");
}
$course_dataHa = array();
foreach($dataHa as $course){
$id = $course[0];
$nome = $course[1];
$titolo = $course[2];
$data = getdate($course[3]);
$row = array(
translateFN('Nome')=>"<img src=\"img/title.gif\" border=0> $nome",
translateFN('Titolo')=>"<a href=info.php?$session_id_par"."id_course=$id> ".$titolo."</a>",
translateFN('Data')=>"<img src=\"img/flag.gif\" border=0> ".$data['mday']."/".$data['mon']."/".$data['year']
);
array_push($course_dataHa,$row);

}

$tObj = new Table();
//$tObj->initTable('1','center','0','1','100%','','','','',1,1);
$tObj->initTable('1','left','2','1','100%','','','','',1,1);
$caption = translateFN("Corsi attivi il $ymdhms");
$summary = translateFN("Elenco dei corsi attivi");
$tObj->setTable($course_dataHa,$caption,$summary);
$total_course_data = $tObj->getTable();


/* 3.
building login form
*/

$login_dataHa = array(
array(
'label'=>translateFN('Utente'),
'type'=>'text',
'name'=>'username',
'size'=>'20',
'maxlenght'=>'40'
),

array(
'label'=>translateFN('Password'),
'type'=>'password',
'name'=>'password',
'size'=>'20',
'maxlength'=>'40'
),

array(
'label'=>translateFN('Lingua'),
'type'=>'select',
'name'=>'user_language',
'value'=>array('italiano','english','fran�is','deutsch','espanol'),
'selected'=>$sess_user_language
),

array(
'label'=>'',
'type'=>'submit',
'name'=>'Submit',
'value'=>translateFN('Entra')
),
array(
'label'=>translateFN('Non sei un utente registrato?'),
'type'=>'submit',
'name'=>'Register',
'value'=>translateFN('Registrati')
)

);


$fObj = new Form();
$fObj->setForm($login_dataHa);
$login_form = $fObj->getForm();

/* 4.
Welcome message (from ext file)
*/

$newsfile = 'news_'.strtolower(substr($language,0,2)).'.txt';
$infofile = 'info_'.strtolower(substr($language,0,2)).'.txt';
$helpfile = 'hlp_'.strtolower(substr($language,0,2)).'.txt';

$infomsg = '';
$newsmsg = '';
$hlpmsg = '';

// $newsfile = $root_dir."/".$newsfile; txt files in ADA root directory
$newsfile = $root_dir."/user/".$newsfile; // txt files in ADA user directory
if ($fid = @fopen($newsfile,'r')){
while (!feof($fid))
$newsmsg .= fread($fid,4096);
fclose($fid);
} else {
$newsmsg = translateFN("File info non trovato");
}


// $helpfile = $root_dir."/".$helpfile; txt files in ADA root directory
$helpfile = $root_dir."/user/".$helpfile; // txt files in ADA user directory
if ($fid = @fopen($helpfile,'r')){
while (!feof($fid))
$hlpmsg .= fread($fid,4096);
fclose($fid);
} else {
$hlpmsg = translateFN("File help non trovato");
}
/* 5.
building HTML page
*/

$banner = include ("$root_dir/include/banner.inc.php");

if (isset($err_msg)){
$message = $err_msg;
} else {
$message = translateFN("Powered by ADA - Ver.").$ada_ver;
}

$menu = "<a href=\"info.php\">".translateFN("elenco corsi")."</a><br>";
$menu .= "<a href=\"browsing/registration.php\">".translateFN("registrazione")."</a><br>";

$home = "<a href=\"index.php\">".translateFN("home")."</a>";

$title=PORTAL_NAME.">".translateFN("Login");

// Controllo per compatibilita' con vecchie versioni di php
// fino alla 4.1 esclusa non esiste l'array $_POST



if (isset($_POST)) {
if (in_array("Submit",array_keys($_POST)))
$Submit = $_POST['Submit'];
if (in_array("username",array_keys($_POST)))
$username = $_POST['username'];
if (in_array("password",array_keys($_POST)))
$password = $_POST['password'];
if (in_array("user_language",array_keys($_POST))){
$sess_user_language = $_POST['user_language'];

}

}



if(isset($Submit)){

// data check 1: have been all the fields fulfilled ?
if (empty($username) || empty($password) ){
$message = translateFN("Username e/o password sono obbligatori. Riprovare.");
$field_data = array('form'=>$login_form,
'message'=>$message,
'course_list'=>$total_course_data
);
$login_err = $message;
} else {
$login_err = login($username,$password);
//mydebug(__LINE__,__FILE__,$login_err);
}

// data check 2: are login data valid?

if (!empty($login_err)){
// $message = translateFN("Username e/o password non validi. Errore: $login_err.");
$message = translateFN("Username e/o password non validi. Riprovare.");
$field_data = array('form'=>$login_form,
'message'=>$message,
'course_list'=>$total_course_data
);
} else {
// ok: redirect
switch ($sess_id_user_type){

case AMA_TYPE_AUTHOR:
header("Location: courses/menu.php");
exit;

case AMA_TYPE_ADMIN:
header("Location: admin/menu.php");
exit;

case AMA_TYPE_STUDENT:
header("Location: browsing/student.php");
exit;

case AMA_TYPE_TUTOR:
header("Location: tutor/tutor.php");
exit;

default:

$message = translateFN("Utente di tipo sconosciuto:"). $sess_id_user_type;
$field_data = array('form'=>$login_form,
'message'=>$message,
'course_list'=>$total_course_data
);

//header("Location: $error?err_msg=$msg");
//exit;

}

}



} elseif (isset($Register)){

// new user

header("Location: $http_root_dir/browsing/registration.php");
exit;

} else {

// first time
$field_data = array(
'banner'=>$banner,
'home'=>$home,
'text'=>$newsmsg,
'help'=>$hlpmsg,
'menu'=>$menu,
'form'=>"<p align=right>".$login_form."</p>",
'message'=>$message,
'course_list'=>$total_course_data
);
}


/* 5.
building data for browser
*/

if (!isset($family))
$family = ADA_TEMPLATE_FAMILY; // default


$id_profile = AMA_TYPE_STUDENT; // default
$layoutObj = read_layout_from_DB($id_profile,$family,"","");
$layout_CSS = $layoutObj->CSS_filename;
$layout_template = $layoutObj->template;

$htmlObj = new HTML($layout_template,$layout_CSS,"","","");

//$htmlObj-> verify_templateFN($dataHa);
$htmlObj->fillin_templateFN($field_data);

$imgpath = (dirname($layout_template));
$htmlObj-> resetImgSrcFN($imgpath);
$htmlObj->apply_CSSFN();
$htmlObj->session_id_par = '';



/* 6.
sending all the stuff to the browser
*/

$htmlObj->outputFN('page');

?>
*****************************************

frax289
21-03-2008, 16:28
usare un tag PHP no è? [ PHP ][/ PHP ]

frax289
21-03-2008, 16:30
il problema cmq è tuo, non dello script....cosa hai installato sul pc? prova xampp

niko_lol
21-03-2008, 16:34
questo è un software che va installa to via web,si chiama ADA, quindi ho dovuto montare un server apache, ho seguito le istruzioni per l'installazione, non mi trovava il file DB.php, l' ho scaricato ora ok. ma poi l'errore che ti ho detto prima. ho installato apache, mysql e php.

xampp cos'è un gui di sviluppo php?

frax289
22-03-2008, 11:13
beh prima di tutto è meglio che ti compri un buon manuale di php, xampp è un tutto incluso: apache+mysql+phpmyadmin e tanto altro...vai a cercarlo, scaricalo, installalo e esegui su quello ada :) vedrai;)