RID pole sätitud, palun säti omale RID või hoopis otsi abi spikrist.
Too spikker (sinu keelele spikrit nagunii pole).
Teised kasutajad on saanud lahenduseks ka: Err0771: Sellist vahendit polegi olemas
';
}
// CSS header for Crossword templates
private function crosswordCSSHeader(){
return '';
}
// View template for Crossword
private function crosswordViewTemplate(
$cwTitle,
$cwDescription,
$cwMainQuestion,
$cwHeader,
$cwBody,
$cwQuestionList,
$cwRowCount,
$cwColCount,
$assignmentID,
$rid){
$cwvt = <<
$cwTitle
$cwDescription
$cwMainQuestion
$cwQuestionList
EOD;
return $cwvt;
}
private function crosswordAnswerTemplate($title, $desc, $mainquestion, $cwHeader, $cwBody, $questions){
$cwat = <<
$title
$desc
$mainquestion
$questions
EOD;
return $cwat;
}
// Edit template for Crossword
private function crosswordEditTemplate(
$title,
$desc,
$keywords,
$cwHeader,
$cwBody,
$questions,
$mainquestion,
$cwCols,
$cwRows,
$cwSol
){
$cwvt = <<
EOD;
return $cwvt;
}
// array translator DB->array
function makeArray($data, $info=false){
$r = 0;
$c = 0;
$a = array();
$rows = split("\n", $data);
$r = count($rows);
foreach ($rows as $row){
$cols = split(",", $row);
$a[]=$cols;
}
$c = count($a[0]);
if ($info){
return array($a, $r, $c);
}
return $a;
}
// crossword header
function makeCrosswordHeader($col_count,
$solution_nr,
$editable=false
){
$ecwh="";
for($col_nr = 0; $col_nr < $col_count; $col_nr++){
$class = '';
$content = '';
if ($col_nr == $solution_nr){
$class = 'solution';
$content = '?';
}
if($editable){
$content = sprintf('%s.', ($col_nr+1));
}
$ecwht = '%s | ';
$ecwh .= sprintf($ecwht, $class, $content);
}
return $ecwh;
}
// crossword body
function makeCrosswordBody($row_count,
$col_count,
$solution_nr,
$data,
$answers=false,
$editable=false,
$disabled=false
){
$ecwb = '';
for($row_nr = 0; $row_nr < $row_count; $row_nr++){
$ecwb1 = '';
for($col_nr = 0; $col_nr < $col_count; $col_nr++){
$idd = sprintf('t%sc%s', $row_nr, $col_nr);
$class = '';
$datar = '';
$ddbb = '';
$ddaa = '';
if (count($data)>$row_nr){
if (count($data[$row_nr]>$col_nr)){
$ddbb = $data[$row_nr][$col_nr];
if ($answers){
$ddaa = $answers[$row_nr][$col_nr];
}
}
}
if ($col_nr == $solution_nr){
$class = 'solution';
}
if($editable){
$datar = $ddbb;
}
if($answers){
$datar = $ddaa;
}
$disableinput = '';
if($disabled){
$disableinput = 'disabled';
}
$input = '';
$input = sprintf($input, $datar, $idd, $idd, $idd, $disableinput);
if ($ddbb=='' && $editable==false){
$input = '';
}
$ecwbt1 = '%s | ';
$ecwb1 .= sprintf($ecwbt1, $class, $input);
}
$ecwbt = '%s. | %s
';
$ecwb .= sprintf($ecwbt, ($row_nr+1), $ecwb1);
}
return $ecwb;
}
// question list
function makeCrosswordQuestionList($questions, $ansok=false){
$al='';
$question_nr = 0;
foreach ($questions as $question){
$al.=''.$question.' ';
if ($ansok){
$ans_ti = 'Wrong';
$ans_st = 'color:red';
if ($question_nr%s',$ans_st,$ans_ti);
}
$al.='';
$question_nr++;
}
return $al;
}
// crosswordAnsOk
function crosswordAnswersOk($row_count,
$col_count,
$answers,
$data
){
$cwAnsOk = array();
for($row_nr = 0; $row_nr < $row_count; $row_nr++){
for($col_nr = 0; $col_nr < $col_count; $col_nr++){
if(strcasecmp($data[$row_nr][$col_nr],$answers[$row_nr][$col_nr])){
$cwAnsOk []= 0;
}else{
$cwAnsOk []= 1;
}
}
}
return $cwAnsOk;
}
// Crossword View Page
public function crosswordview() {
global $krihvel, $kdb;
$isresource = false;
if ( isset($_GET['rid'])){
$_SESSION['rid']=$_GET['rid'];
}
if ( isset($_SESSION['rid'])) {
$rid = $_SESSION['rid'];
$q_list = "title, description, keywords, mainQuestion, mainQuestionCol, questions, data";
$q_cond = sprintf("resourceID=%s AND type='%s'", $rid, "crossword");
$q = "SELECT %s from resources join crossword using(resourceID) where %s";
$q = sprintf($q, $q_list, $q_cond);
$ret = $kdb->query($q);
if ( isset($ret)) {
$row = mysql_fetch_array($ret);
if (count($row)>1){
$isresource=true;
}
}
}
if ($isresource){
$cwTitle = $row['title'];
$cwDescription = nl2br($row['description']);
$cwMainQuestion = $row['mainQuestion'];
$cwSolutionNr = $row['mainQuestionCol'];
$cwQuestions = split(",", $row['questions']);
$cwArray = $this->makeArray($row['data'], 1);
$cwData = $cwArray[0];
$cwRowCount = $cwArray[1];
$cwColCount = $cwArray[2];
$assignmentID = 1; //here is assgignment id
$msg = $this->crosswordViewTemplate(
$cwTitle,
$cwDescription,
$cwMainQuestion,
$this->makeCrosswordHeader($cwColCount, $cwSolutionNr, 0),
$this->makeCrosswordBody($cwRowCount, $cwColCount, $cwSolutionNr, $cwData, 0, 0, 0),
$this->makeCrosswordQuestionList($cwQuestions),
$cwRowCount,
$cwColCount,
$assignmentID,
$rid
);
}else{
$msg = $this->crosswordErrorMessage();
}
$cssHeader = $this->crosswordCSSHeader();
$krihvel->out("head", $cssHeader);
$krihvel->out("popup", $msg);
}
// Crossword Answer Page
public function crosswordanswer() {
global $krihvel, $kdb;
$isresource = false;
if ( isset($_GET['aid'])){
$aid=$_GET['aid'];
}else{
return 'kala';
}
if ( isset($_GET['rid'])){
$_SESSION['rid']=$_GET['rid'];
}
if ( isset($_SESSION['rid'])) {
$rid = $_SESSION['rid'];
$q_list = "title, description, keywords, mainQuestion, mainQuestionCol, questions, data";
$q_cond = sprintf("resourceID=%s AND type='%s'", $rid, "crossword");
$q = "SELECT %s from resources join crossword using(resourceID) where %s";
$q = sprintf($q, $q_list, $q_cond);
$ret = $kdb->query($q);
$qa_cond = sprintf("resourceID=%s AND answerID=%s", $rid, $aid);
$qa = sprintf("SELECT * from answers join crossword_answers using(answerID) where %s", $qa_cond);
$reta = $kdb->query($qa);
if ( isset($ret)) {
$row = mysql_fetch_array($ret);
$rowa = mysql_fetch_array($reta);
if (count($row)>1){
$isresource=true;
}
}
}
if ($isresource){
$cwTitle = $row['title'];
$cwDescription = nl2br($row['description']);
$cwMainQuestion = $row['mainQuestion'];
$cwSolutionNr = $row['mainQuestionCol'];
$cwQuestions = split(",", $row['questions']);
$cwArray = $this->makeArray($row['data'], 1);
$cwaData = $this->makeArray($rowa['data'], 0);
$cwData = $cwArray[0];
$cwRowCount = $cwArray[1];
$cwColCount = $cwArray[2];
$cwAnsOk = $this->crosswordAnswersOk($cwRowCount, $cwColCount, $cwaData, $cwData);
$msg = $this->crosswordAnswerTemplate(
$cwTitle,
$cwDescription,
$cwMainQuestion,
$this->makeCrosswordHeader($cwColCount, $cwSolutionNr, 0),
$this->makeCrosswordBody($cwRowCount, $cwColCount, $cwSolutionNr, $cwData, $cwaData, 0, 1),
$this->makeCrosswordQuestionList($cwQuestions, $cwAnsOk)
);
}else{
$msg = $this->crosswordErrorMessage();
}
$cssHeader = $this->crosswordCSSHeader();
$krihvel->out("head", $cssHeader);
$krihvel->out("popup", $msg);
}
function questionList($row_count, $questions){
$al='';
$question_nr = 0;
for($row_nr = 0; $row_nr < $row_count; $row_nr++){
$al.='';
}
return $al;
}
function getQuestion($questionNr, $questions){
if ($questionNrquery($q);
if ( isset($ret)) {
$row = mysql_fetch_array($ret);
if (count($row)>1){
$cwTitle = $row['title'];
$cwDescription = $row['description'];
$cwKeywords = $this->keywords_from_database($row['keywords']);
$cwMainQuestion = $row['mainQuestion'];
$cwSolutionNr = $row['mainQuestionCol'];
$cwQuestions = split(",", $row['questions']);
$cwArray = $this->makeArray($row['data'], 1);
$cwData = $cwArray[0];
$cwRowCount = $cwArray[1];
$cwColCount = $cwArray[2];
}
}
}
$msg=$this->crosswordEditTemplate(
$cwTitle,
$cwDescription,
$cwKeywords,
$this->makeCrosswordHeader($cwColCount, $cwSolutionNr, 1),
$this->makeCrosswordBody($cwRowCount, $cwColCount, $cwSolutionNr, $cwData, 0, 1, 0),
$this->questionList($cwRowCount, $cwQuestions),
$cwMainQuestion,
$cwRowCount,
$cwColCount,
$cwSolutionNr);
$cssHeader = sprintf('%s', $this->crosswordCSSHeader());
$krihvel->out("head", $cssHeader);
$krihvel->out("popup", $msg);
}
function keywords_to_database($keywords){
$kws_raw = split(",", $keywords);
$kws = ",";
foreach ($kws_raw as $kw_raw){
$kw = trim($kw_raw);
$kws .= sprintf("%s,", strtolower($kw));
}
return $kws;
}
function keywords_from_database($keywords){
$keywords = trim($keywords, ",");
$kws_raw = split(",", $keywords);
$kws = "";
foreach ($kws_raw as $kw){
$kws .= sprintf("%s, ", $kw);
}
$kws = substr_replace($kws, "", -2);
return $kws;
}
public function save_crossword(){
global $kdb, $user;
$type="crossword";
$title=$_POST['title'];
$desc=$_POST['desc'];
$keywords=$this->keywords_to_database($_POST['keywords']);
$user_id=$user->getId();
$creator=$user_id;
$created="";
$modified="0000-00-00";
$x=$_POST['x'];
$y=$_POST['y'];
$solution_col=$_POST['solution_col'];
$main_question=$_POST['mainquestion'];
$data="";
$cwt="";
$questions="";
for ($i=0;$i<$y;$i++){
$cwt="";
for ($j=0;$j<$x;$j++){
$cwt.=$_POST["t".$i."c".$j].',';
}
$data.=(substr_replace($cwt ,"",-1)).'\n';
$questions.=$_POST['q'.$i].',';
}
$data=(substr_replace($data ,"",-2));
$questions=(substr_replace($questions ,"",-1));
if (isset($_SESSION['rid']) && $_SESSION['rid']!=0){
$q = "UPDATE resources SET title='%s', description='%s', keywords='%s', modified='%s' WHERE resourceID=".$_SESSION['rid'];
$q = sprintf($q, $title, $desc, $keywords, $modified);
$kdb->query($q);
$q2 = "UPDATE crossword SET mainQuestion='%s', mainQuestionCol=%s, questions='%s', data='%s' WHERE resourceID=".$_SESSION['rid'];
$q2 = sprintf($q2, $main_question, $solution_col, $questions, $data);
$kdb->query($q2);
}else{
$q = "INSERT INTO resources (type, title, description, keywords, userID, modified) values ('%s', '%s', '%s', '%s', %s, '%s')";
$q = sprintf($q, $type, $title, $desc, $keywords, $creator, $modified);
$kdb->query($q);
$dbuid = mysql_insert_id();
$_SESSION['rid'] = $dbuid;
$q2 = "INSERT INTO crossword (resourceID, mainQuestion, mainQuestionCol, questions, data) values (%s, '%s', %s, '%s', '%s')";
$q2 = sprintf($q2, $dbuid, $main_question, $solution_col, $questions, $data);
$kdb->query($q2);
}
return 'crosswordview';
}
public function answer_crossword(){
global $kdb, $user;
$userID=$user->getId();
$y=$_POST['x'];
$x=$_POST['y'];
$assignmentID=$_POST['assignment'];
$resourceID= $_SESSION['rid'];
$data="";
$user_answers="";
$questions="";
for ($i=0;$i<$y;$i++){
$user_answers="";
for ($j=0;$j<$x;$j++){
$user_answer=$_POST["t".$i."c".$j];
$user_answers.=$user_answer.',';
}
$data.=(substr_replace($user_answers ,"",-1)).'\n';
}
$data=(substr_replace($data ,"",-2));
$q = sprintf("INSERT INTO answers (resourceID, assignmentID, userID) values (%s, %s, %s)", $resourceID, $assignmentID, $userID);
$kdb->query($q);
$dbuid = mysql_insert_id();
$q2 = "INSERT INTO crossword_answers (answerID, data) values (%s, '%s')";
$q2 = sprintf($q2, $dbuid, $data);
$kdb->query($q2);
return 'crosswordanswer';
}
/*
$q_cond = sprintf("resourceID='%s' AND type='%s' AND deleted=0", $rid, "crossword");
$q = sprintf("SELECT * from resources join crossword using(resourceID) where %s", $q_cond);
$ret = $kdb->query($q);
$row = mysql_fetch_array($ret);
$correct_data = $this->makeArray($row['data'], 0);
for ($i=0;$i<$y;$i++){
$cwt="";
for ($j=0;$j<$x;$j++){
$user_answer=$_POST["t".$i."c".$j];
$correct_answer=$correct_data[$i][$j];
$user_answers.=$user_answer.',';
*/
}
?>