Ejemplo n.º 1
0
function common_projektneStrane()
{
    //debug mod aktivan
    global $userid, $user_nastavnik, $user_student, $conf_files_path, $user_siteadmin;
    $predmet = intval($_REQUEST['predmet']);
    $ag = intval($_REQUEST['ag']);
    $projekat = intval($_REQUEST['projekat']);
    $action = $_REQUEST['action'];
    //for project page only:
    $section = $_REQUEST['section'];
    $subaction = $_REQUEST['subaction'];
    $id = intval($_REQUEST['id']);
    //editing links, rss....
    if ($user_student && !$user_siteadmin) {
        $actualProject = getActualProjectForUserInPredmet($userid, $predmet, $ag);
        if ($actualProject[id] != $projekat) {
            //user is not in this project in this predmet...hijack attempt?
            zamgerlog("projektne strane: korisnik nije na projektu {$projekat} (pp{$predmet}, ag{$ag})", 3);
            zamgerlog2("nije na projektu", $projekat);
            return;
        }
    }
    $params = getPredmetParams($predmet, $ag);
    $project = getProject($projekat);
    $members = fetchProjectMembers($project[id]);
    if ($params[zakljucani_projekti] == 0) {
        zamgerlog("projektne strane: jos nisu otvorene! (pp{$predmet}, ag{$ag})", 3);
        zamgerlog2("svi projekti su jos otkljucani", $predmet, $ag);
        return;
    }
    if ($user_student && !$user_siteadmin) {
        $linkPrefix = "?sta=student/projekti&akcija=projektnastranica&projekat={$projekat}&predmet={$predmet}&ag={$ag}";
    } elseif ($user_nastavnik) {
        $linkPrefix = "?sta=nastavnik/projekti&akcija=projektna_stranica&projekat={$projekat}&predmet={$predmet}&ag={$ag}";
    } else {
        return;
    }
    ?>
  
     <h2><?php 
    echo filtered_output_string($project[naziv]);
    ?>
</h2>
     <div class="links">
            <ul class="clearfix">
            	<li><a href="<?php 
    echo $linkPrefix;
    ?>
">Početna strana</a></li>
            	<li><a href="<?php 
    echo $linkPrefix . "&section=info";
    ?>
">Informacije o projektu</a></li>
                <li><a href="<?php 
    echo $linkPrefix . "&section=links";
    ?>
">Korisni linkovi</a></li>
                <li><a href="<?php 
    echo $linkPrefix . "&section=rss";
    ?>
">RSS feedovi</a></li>
                <li><a href="<?php 
    echo $linkPrefix . "&section=bl";
    ?>
">Članci</a></li>
                <li><a href="<?php 
    echo $linkPrefix . "&section=file";
    ?>
">Fajlovi</a></li>
                <li class="last"><a href="<?php 
    echo $linkPrefix . "&section=bb";
    ?>
">Grupa za diskusiju</a></li>
            </ul>   
     </div>	
    <?php 
    if (!isset($section)) {
        //display project start page
        ?>
  	    <div id="mainWrapper" class="clearfix">
			<div id="leftBlocks">
                <div class="blockRow clearfix">
                     <div class="block" id="latestPosts">
                        <a class="blockTitle" href="<?php 
        echo $linkPrefix . "&section=bb";
        ?>
" title="Grupa za diskusiju">Najnoviji postovi</a>
                        <div class="items">
                        <?php 
        $latestPosts = fetchLatestPostsForProject($project[id], 4);
        foreach ($latestPosts as $post) {
            ?>
                            <div class="item">
                                <span class="date"><?php 
            echo date('d.m H:i  ', mysql2time($post[vrijeme]));
            ?>
</span>
                                <a href="<?php 
            echo $linkPrefix . "&section=bb&subaction=view&tid={$post['tema']}#p{$post['id']}";
            ?>
" title="<?php 
            echo $post['naslov'];
            ?>
" target="_blank"><?php 
            $maxLen = 100;
            $len = strlen($post[naslov]);
            echo filtered_output_string(substr($post['naslov'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</a>
                                <span class="author"> - <?php 
            echo filtered_output_string($post[osoba][prezime] . ' ' . $post[osoba][ime]);
            ?>
</span>
                                <div class="desc"><?php 
            $maxLen = 200;
            $len = strlen($post[tekst]);
            echo filtered_output_string(substr($post['tekst'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</div><!--desc-->
                            </div><!--item-->	
                        <?php 
        }
        ?>
                        
                        
                        </div><!--items-->
                    </div><!--block-->
                    
                    
                </div><!--blockRow-->
                
                <div class="blockRow clearfix">
                     <div class="block" id="latestArticles">
                        <a class="blockTitle" href="<?php 
        echo $linkPrefix . "&section=bl";
        ?>
" title="Članci">Najnoviji članci</a>
                        <div class="items">
                        <?php 
        $latestArticles = fetchArticlesForProject($project[id], 0, 4);
        foreach ($latestArticles as $article) {
            $author = getAuthorOfArticle($article[id]);
            ?>
                            <div class="item">
                                <span class="date"><?php 
            echo date('d.m H:i  ', mysql2time($article[vrijeme]));
            ?>
</span>
                                <a href="<?php 
            echo $linkPrefix . "&section=bl&subaction=view&id={$article['id']}";
            ?>
" title="<?php 
            echo $article['naslov'];
            ?>
" target="_blank"><?php 
            $maxLen = 100;
            $len = strlen($article[naslov]);
            echo filtered_output_string(substr($article['naslov'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</a>
                                <span class="author"> - <?php 
            echo filtered_output_string($author[prezime] . ' ' . $author[ime]);
            ?>
</span>
                                <div class="desc"><?php 
            $maxLen = 200;
            $len = strlen($article[tekst]);
            echo filtered_output_string(substr($article['tekst'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</div><!--desc-->
                            </div><!--item-->	
                        <?php 
        }
        ?>
                        
                        
                        </div><!--items-->
                    </div><!--block-->
                    
                    
                </div><!--blockRow-->

            </div><!--leftBlocks-->
            <div id="rightBlocks" class="clearfix">
            	<div class="blockRow">
                    <div class="block" id="latestLinks">
                        <a class="blockTitle" href="<?php 
        echo $linkPrefix . "&section=links";
        ?>
" title="Korisni linkovi">Korisni linkovi</a>
                        <div class="items">
                       
        <?php 
        //get latest entries
        $links = fetchLinksForProject($project[id], 0, 4);
        foreach ($links as $link) {
            $url = $link[url];
            $scheme = parse_url($url);
            $scheme = $scheme['scheme'];
            if ($scheme == '') {
                //only www part
                $url = 'http://' . $url;
            }
            $maxLen = 150;
            $len = strlen($link[naziv]);
            if ($len > $maxLen) {
                echo '...';
            }
            $author = getAuthorOfLink($link[id]);
            ?>
                            <div class="item">
                                <a href="<?php 
            echo $url;
            ?>
" title="<?php 
            echo $link['naziv'];
            ?>
" target="_blank"><?php 
            $maxLen = 35;
            $len = strlen($link[naziv]);
            echo filtered_output_string(substr($link['naziv'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</a>
                                <span class="author"> - <?php 
            echo filtered_output_string($author[prezime] . ' ' . $author[ime]);
            ?>
</span>
        <?php 
            if ($link[opis] != '') {
                ?>
                   
                                <div class="desc"><?php 
                $maxLen = 200;
                $len = strlen($link[opis]);
                echo filtered_output_string(substr($link['opis'], 0, $maxLen - 1));
                if ($len > $maxLen) {
                    echo '...';
                }
                ?>
</div><!--desc-->
        <?php 
            }
            ?>
                 
                            </div><!--item-->   		
        <?php 
        }
        //foreach
        ?>
     
                        </div><!--items-->   
                    </div><!--block--> 
				</div><!--blockRow-->            
            	<div class="blockRow">
                    <div class="block" id="latestRSS">
                        <a class="blockTitle" href="<?php 
        echo $linkPrefix . "&section=rss";
        ?>
" title="RSS feedovi">RSS feedovi</a>
                        <div class="items">
                       
        <?php 
        //get latest entries
        $links = fetchRSSForProject($project[id], 0, 4);
        foreach ($links as $link) {
            $url = $link[url];
            $scheme = parse_url($url);
            $scheme = $scheme['scheme'];
            if ($scheme == '') {
                //only www part
                $url = 'http://' . $url;
            }
            $maxLen = 150;
            $len = strlen($link[naziv]);
            if ($len > $maxLen) {
                echo '...';
            }
            $author = getAuthorOfRSS($link[id]);
            ?>
                            <div class="item">
                                <a href="<?php 
            echo $url;
            ?>
" title="<?php 
            echo $link['naziv'];
            ?>
" target="_blank"><?php 
            $maxLen = 35;
            $len = strlen($link[naziv]);
            echo filtered_output_string(substr($link['naziv'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</a>
                                <span class="author"> - <?php 
            echo filtered_output_string($author[prezime] . ' ' . $author[ime]);
            ?>
</span>
        <?php 
            if ($link[opis] != '') {
                ?>
                   
                                <div class="desc"><?php 
                $maxLen = 200;
                $len = strlen($link[opis]);
                echo filtered_output_string(substr($link['opis'], 0, $maxLen - 1));
                if ($len > $maxLen) {
                    echo '...';
                }
                ?>
</div><!--desc-->
        <?php 
            }
            ?>
                 
                            </div><!--item-->   		
        <?php 
        }
        //foreach
        ?>
     
                        </div><!--items-->   
                    </div><!--block-->
                </div><!--blockRow-->  
            	<div class="blockRow">
                    <div class="block" id="latestFiles">
                        <a class="blockTitle" href="<?php 
        echo $linkPrefix . "&section=file";
        ?>
" title="Fajlovi">Fajlovi</a>
                        <div class="items">
                       
        <?php 
        //get latest entries
        $files = fetchFilesForProjectLatestRevisions($project[id], 0, 4);
        foreach ($files as $file) {
            $author = getAuthorOfFile($file[id]);
            ?>
                            <div class="item">
                                <span class="date"><?php 
            echo date('d.m H:i  ', mysql2time($file[vrijeme]));
            ?>
</span>
                                <a href="<?php 
            echo "index.php?sta=common/attachment&tip=projekat&projekat={$projekat}&id={$file['id']}";
            ?>
" title="<?php 
            echo $file['filename'];
            ?>
" ><?php 
            $maxLen = 100;
            $len = strlen($file[filename]);
            echo filtered_output_string(substr($file['filename'], 0, $maxLen - 1));
            if ($len > $maxLen) {
                echo '...';
            }
            ?>
</a>
                                <span class="author"> - <?php 
            echo filtered_output_string($author[prezime] . ' ' . $author[ime]);
            ?>
</span>
                               
                            </div><!--item-->	
        <?php 
        }
        //foreach
        ?>
     
                        </div><!--items-->   
                    </div><!--block-->
                </div><!--blockRow-->            
                          
            </div><!--rightBlocks-->
        </div><!--mainWrapper-->    
    <?php 
    } else {
        if ($section == 'info') {
            // display project info
            ?>
    	<h2>Informacije o projektu</h2>

<table class="projekti" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <th width="200" align="left" valign="top" scope="row">Naziv</th>
    <td width="490" align="left" valign="top"><?php 
            echo filtered_output_string($project['naziv']);
            ?>
</td>
  </tr>
  <tr>
    <th width="200" align="left" valign="top" scope="row">Prijavljeni studenti</th>
    <td width="490" align="left" valign="top">
    	<?php 
            if (empty($members)) {
                echo 'Nema prijavljenih studenata.';
            } else {
                ?>
        <ul>
        <?php 
                foreach ($members as $member) {
                    ?>
        	<li><?php 
                    echo filtered_output_string($member[prezime] . ' ' . $member[ime] . ', ' . $member[brindexa]);
                    ?>
</li>
		<?php 
                }
                ?>
        </ul>	
		<?php 
            }
            ?>
    
    </td>
  </tr>
  <tr>
    <th width="200" align="left" valign="top" scope="row">Opis</th>
    <td width="490" align="left" valign="top"><?php 
            echo filtered_output_string($project['opis']);
            ?>
</td>
  </tr>
</table>
    
     
    <?php 
        } elseif ($section == 'links') {
            //links management
            $linkPrefix .= '&section=links';
            ?>
<h2>Korisni linkovi</h2>
 <div class="links" id="link">
    <ul class="clearfix">
        <li><a href="<?php 
            echo $linkPrefix;
            ?>
">Lista linkova</a></li>
        <li><a href="<?php 
            echo $linkPrefix . "&subaction=add";
            ?>
">Novi link</a></li>
    </ul>   
</div>	

    <?php 
            if (!isset($subaction)) {
                $rowsPerPage = 20;
                $pageNum = 1;
                if (isset($_REQUEST['page'])) {
                    $pageNum = $_REQUEST['page'];
                }
                // counting the offset
                $offset = ($pageNum - 1) * $rowsPerPage;
                //display links for this project, with links to edit and delete
                $links = fetchLinksForProject($project[id], $offset, $rowsPerPage);
                foreach ($links as $link) {
                    if (isUserAuthorOfLink($link[id], $userid)) {
                        ?>
<div class="links" id="link">
    <ul class="clearfix">
        <li><a href="<?php 
                        echo $linkPrefix . "&subaction=edit&id={$link['id']}";
                        ?>
">Uredi</a></li>
        <li><a href="<?php 
                        echo $linkPrefix . "&subaction=del&id={$link['id']}";
                        ?>
">Briši</a></li>
    </ul>   
</div>	
	<?php 
                    }
                    //if user is author of this item
                    ?>

<table class="linkovi" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <th width="200" align="left" valign="top" scope="row">URL</th>
    <td width="490" align="left" valign="top">
    <?php 
                    $url = $link[url];
                    $scheme = parse_url($url);
                    $scheme = $scheme['scheme'];
                    if ($scheme == '') {
                        //only www part
                        $url = 'http://' . $url;
                    }
                    ?>
<a href="<?php 
                    echo $url;
                    ?>
" title="<?php 
                    echo $link['naziv'];
                    ?>
" target="_blank"><?php 
                    echo filtered_output_string($link[naziv]);
                    ?>
</a>   
    </td>
  </tr>
 <?php 
                    if ($link['opis'] != '') {
                        ?>
  <tr>
    <th width="200" align="left" valign="top" scope="row">Opis</th>
    <td width="490" align="left" valign="top"><?php 
                        echo filtered_output_string($link['opis']);
                        ?>
</td>
  </tr>
  <?php 
                    }
                    //opis
                    ?>
</table>
    <?php 
                }
                //foreach link
                $numrows = getCountLinksForProject($project[id]);
                $maxPage = ceil($numrows / $rowsPerPage);
                $self = $linkPrefix;
                if ($maxPage > 0) {
                    echo "<span class=\"newsPages\">";
                    if ($pageNum > 1) {
                        $page = $pageNum - 1;
                        $prev = " <a href=\"{$self}&page={$page}\">[Prethodna]</a> ";
                        $first = " <a href=\"{$self}&page=1\">[Prva]</a> ";
                    }
                    if ($pageNum < $maxPage) {
                        $page = $pageNum + 1;
                        $next = " <a href=\"{$self}&page={$page}\">[Sljedeća]</a> ";
                        $last = " <a href=\"{$self}&page={$maxPage}\">[Zadnja]</a> ";
                    }
                    echo $first . $prev . " Strana <strong>{$pageNum}</strong> od ukupno <strong>{$maxPage}</strong> " . $next . $last;
                    echo "</span>";
                    //newsPages span
                }
            } else {
                if ($subaction == 'add') {
                    if (!isset($_REQUEST['submit'])) {
                        ?>
						 <h3>Novi link</h3>
				<?php 
                        print genform("POST", "addForm");
                        ?>
						
						<div id="formDiv">
							Polja sa * su obavezna. <br />
							
                            <div class="row">
								<span class="label">Naziv *</span>
								<span class="formw"><input name="naziv" type="text" id="naziv" size="70" /></span> 
							</div>
	
							<div class="row">
								<span class="label">URL *</span>
								<span class="formw"><input name="url" type="text" id="url" size="70" /></span> 
							</div>
							<div class="row">
								<span class="label">Opis</span>
								<span class="formw"><textarea name="opis" cols="60" rows="15" wrap="physical" id="opis"></textarea></span>
							</div> 
							
							<div class="row">	
								<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
							</div>
						
						</div><!--formDiv-->
						</form>
							
	<?php 
                    } else {
                        $errorText = formProcess_links('add');
                        if ($errorText == '') {
                            nicemessage('Novi link uspješno dodan.');
                            zamgerlog("dodao link na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("dodao link na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'edit') {
                    if (!isUserAuthorOfLink($id, $userid)) {
                        return;
                    }
                    //edit item
                    if (!isset($_REQUEST['submit'])) {
                        $entry = getLink($id);
                        ?>
					 <h3>Uredi link</h3>
				<?php 
                        print genform("POST", "editForm");
                        ?>
                	
					<div id="formDiv">
						Polja sa * su obavezna. <br />
						
						<div class="row">
							<span class="label">Naziv *</span>
							<span class="formw"><input name="naziv" type="text" id="naziv" size="70" value="<?php 
                        echo $entry['naziv'];
                        ?>
" /></span> 
						</div>

						<div class="row">
							<span class="label">URL *</span>
							<span class="formw"><input name="url" type="text" id="url" size="70" value="<?php 
                        echo $entry['url'];
                        ?>
" /></span> 
						</div>
						<div class="row">
							<span class="label">Opis</span>
							<span class="formw"><textarea name="opis" cols="60" rows="15" wrap="physical" id="opis"><?php 
                        echo $entry['opis'];
                        ?>
</textarea></span>
						</div> 
						
						<div class="row">	
							<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
						</div>
					
					</div><!--formDiv-->
					</form>
							
						
		<?php 
                    } else {
                        $errorText = formProcess_links('edit');
                        if ($errorText == '') {
                            nicemessage('Uspješno ste uredili link.');
                            zamgerlog("uredio link na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("uredio link na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            //an error occured trying to process the form
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'del') {
                    if (!isUserAuthorOfLink($id, $userid)) {
                        return;
                    }
                    //delete item
                    if (isset($id) && is_int($id) && $id > 0) {
                        if (!isset($_REQUEST['c'])) {
                            echo "Da li ste sigurni da zelite obrisati ovaj link?<br />";
                            echo '<a href="' . $linkPrefix . '&subaction=del&id=' . $id . '&c=true">Da</a> | <a href="' . $linkPrefix . '">Odustani</a>';
                        } else {
                            if ($_REQUEST['c'] == 'true') {
                                //delete the record
                                if (deleteLink($id)) {
                                    nicemessage('Uspješno ste obrisali link.');
                                    zamgerlog("obrisao link na projektu {$projekat} (pp{$predmet})", 2);
                                    zamgerlog2("obrisao link na projektu", $projekat);
                                    $link = $linkPrefix;
                                } else {
                                    niceerror('Doslo je do greske prilikom brisanja linka. Molimo kontaktirajte administratora.');
                                    $link = "javascript:history.back();";
                                }
                                nicemessage('<a href="' . $link . '">Povratak.</a>');
                            }
                        }
                        //else isset c get parameter
                    }
                    //id is okay
                }
                //subaction == del
            }
            //subaction set
        } elseif ($section == 'rss') {
            //links management
            $linkPrefix .= '&section=rss';
            ?>
<h2>RSS feedovi</h2>
 <div class="links clearfix" id="rss">
    <ul>
        <li><a href="<?php 
            echo $linkPrefix;
            ?>
">Lista RSS feedova</a></li>
        <li><a href="<?php 
            echo $linkPrefix . "&subaction=add";
            ?>
">Novi RSS feed</a></li>
    </ul>   
</div>	

    <?php 
            if (!isset($subaction)) {
                $rowsPerPage = 20;
                $pageNum = 1;
                if (isset($_REQUEST['page'])) {
                    $pageNum = $_REQUEST['page'];
                }
                // counting the offset
                $offset = ($pageNum - 1) * $rowsPerPage;
                //display links for this project, with links to edit and delete
                $feeds = fetchRSSForProject($project[id], $offset, $rowsPerPage);
                foreach ($feeds as $link) {
                    if (isUserAuthorOfRSS($link[id], $userid)) {
                        ?>
<div class="links clearfix" id="rss">
    <ul>
        <li><a href="<?php 
                        echo $linkPrefix . "&subaction=edit&id={$link['id']}";
                        ?>
">Uredi</a></li>
        <li><a href="<?php 
                        echo $linkPrefix . "&subaction=del&id={$link['id']}";
                        ?>
">Briši</a></li>
    </ul>   
</div>	
	<?php 
                    }
                    //if user is author of this item
                    ?>
<table class="rss" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <th width="200" align="left" valign="top" scope="row">URL</th>
    <td width="490" align="left" valign="top">
    <?php 
                    $url = $link[url];
                    $scheme = parse_url($url);
                    $scheme = $scheme['scheme'];
                    if ($scheme == '') {
                        //only www part
                        $url = 'http://' . $url;
                    }
                    ?>
<a href="<?php 
                    echo $url;
                    ?>
" title="<?php 
                    echo $link['naziv'];
                    ?>
" target="_blank"><?php 
                    echo filtered_output_string($link[naziv]);
                    ?>
</a>   
    </td>
  </tr>
 <?php 
                    if ($link['opis'] != '') {
                        ?>
  <tr>
    <th width="200" align="left" valign="top" scope="row">Opis</th>
    <td width="490" align="left" valign="top"><?php 
                        echo filtered_output_string($link['opis']);
                        ?>
</td>
  </tr>
 <?php 
                    }
                    //opis
                    ?>

 <tr>
 	<td colspan="2">
 	<?php 
                    global $conf_files_path;
                    //Ukljucimo koristenje globalne varijable koja pokazuje na privatni direktorij sa datotekama koji nije dostupan preko weba
                    $hashfromURL = hash("md5", $url);
                    $cachefile = "";
                    //Provjeri postojanost $conf_files_path/cache/rss direktorija
                    if (file_exists($conf_files_path . "/cache")) {
                        if (!file_exists($conf_files_path . "/cache/rss")) {
                            mkdir($conf_files_path . "/cache/rss");
                        }
                        $cachefile = $conf_files_path . "/cache/rss/" . $hashfromURL . ".html";
                    } else {
                        if (mkdir($conf_files_path . "/cache")) {
                            if (mkdir($conf_files_path . "/cache/rss/")) {
                                $cachefile = $conf_files_path . "/cache/rss/" . $hashfromURL . ".html";
                            }
                        }
                    }
                    $cachetime = 5 * 60;
                    //5 minuta TODO:Pri deployment-u povecati na sat-dva.
                    //Serviraj is kesha ako je mladji od $cachetime
                    if (file_exists($cachefile) && time() - filemtime($cachefile) < $cachetime) {
                        include $cachefile;
                        print "RSS ucitan iz kesha!";
                    } else {
                        //Ucitaj RSS ponovo
                        $XMLfilename = $url;
                        //Pocni dump buffera
                        ob_start();
                        include "lib/rss2html.php";
                        //HTML parsiran sadrzaj RSS-a
                        //Otvori kesh fajl za pisanje
                        $fp = fopen($cachefile, 'w');
                        //Sacuvaj sadrzaj izlaznog buffer-a u fajl
                        fwrite($fp, ob_get_contents());
                        //zatvori fajl
                        fclose($fp);
                        //Posalji izlaz na browser
                        ob_end_flush();
                        print "RSS osvjezen - feed ponovo ucitan!";
                    }
                    ?>
 	</td>
</tr>
 
</table>
    <?php 
                }
                //foreach link
                $numrows = getCountRSSForProject($project[id]);
                $maxPage = ceil($numrows / $rowsPerPage);
                $self = $linkPrefix;
                if ($maxPage > 0) {
                    echo "<span class=\"newsPages\">";
                    if ($pageNum > 1) {
                        $page = $pageNum - 1;
                        $prev = " <a href=\"{$self}&page={$page}\">[Prethodna]</a> ";
                        $first = " <a href=\"{$self}&page=1\">[Prva]</a> ";
                    }
                    if ($pageNum < $maxPage) {
                        $page = $pageNum + 1;
                        $next = " <a href=\"{$self}&page={$page}\">[Sljedeća]</a> ";
                        $last = " <a href=\"{$self}&page={$maxPage}\">[Zadnja]</a> ";
                    }
                    echo $first . $prev . " Strana <strong>{$pageNum}</strong> od ukupno <strong>{$maxPage}</strong> " . $next . $last;
                    echo "</span>";
                    //newsPages span
                }
            } else {
                if ($subaction == 'add') {
                    if (!isset($_REQUEST['submit'])) {
                        ?>
						 <h3>Novi RSS feed</h3>
				<?php 
                        print genform("POST", "addForm");
                        ?>
						
						<div id="formDiv">
							Polja sa * su obavezna. <br />
							
                            <div class="row">
								<span class="label">Naziv *</span>
								<span class="formw"><input name="naziv" type="text" id="naziv" size="70" /></span> 
							</div>
	
							<div class="row">
								<span class="label">URL *</span>
								<span class="formw"><input name="url" type="text" id="url" size="70" /></span> 
							</div>
							<div class="row">
								<span class="label">Opis</span>
								<span class="formw"><textarea name="opis" cols="60" rows="15" wrap="physical" id="opis"></textarea></span>
							</div> 
							
							<div class="row">	
								<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
							</div>
						
						</div><!--formDiv-->
						</form>
							
	<?php 
                    } else {
                        $errorText = formProcess_rss('add');
                        if ($errorText == '') {
                            nicemessage('Novi RSS feed uspješno dodan.');
                            zamgerlog("dodao novi rss feed na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("dodao rss feed na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'edit') {
                    if (!isUserAuthorOfRSS($id, $userid)) {
                        return;
                    }
                    //edit item
                    if (!isset($_REQUEST['submit'])) {
                        $entry = getRSS($id);
                        ?>
					 <h3>Uredi RSS feed</h3>
				<?php 
                        print genform("POST", "editForm");
                        ?>
                	
					<div id="formDiv">
						Polja sa * su obavezna. <br />
						
						<div class="row">
							<span class="label">Naziv *</span>
							<span class="formw"><input name="naziv" type="text" id="naziv" size="70" value="<?php 
                        echo $entry['naziv'];
                        ?>
" /></span> 
						</div>

						<div class="row">
							<span class="label">URL *</span>
							<span class="formw"><input name="url" type="text" id="url" size="70" value="<?php 
                        echo $entry['url'];
                        ?>
" /></span> 
						</div>
						<div class="row">
							<span class="label">Opis</span>
							<span class="formw"><textarea name="opis" cols="60" rows="15" wrap="physical" id="opis"><?php 
                        echo $entry['opis'];
                        ?>
</textarea></span>
						</div> 
						
						<div class="row">	
							<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
						</div>
					
					</div><!--formDiv-->
					</form>
							
						
		<?php 
                    } else {
                        $errorText = formProcess_rss('edit');
                        if ($errorText == '') {
                            nicemessage('Uspješno ste uredili RSS feed.');
                            zamgerlog("uredio rss feed na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("uredio rss feed na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            //an error occured trying to process the form
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'del') {
                    if (!isUserAuthorOfRSS($id, $userid)) {
                        return;
                    }
                    //delete item
                    if (isset($id) && is_int($id) && $id > 0) {
                        if (!isset($_REQUEST['c'])) {
                            echo "Da li ste sigurni da zelite obrisati ovaj RSS feed?<br />";
                            echo '<a href="' . $linkPrefix . '&subaction=del&id=' . $id . '&c=true">Da</a> | <a href="' . $linkPrefix . '">Odustani</a>';
                        } else {
                            if ($_REQUEST['c'] == 'true') {
                                //delete the record
                                if (deleteRSS($id)) {
                                    nicemessage('Uspješno ste obrisali RSS feed.');
                                    zamgerlog("obrisao rss feed na projektu {$projekat} (pp{$predmet})", 2);
                                    zamgerlog2("obrisao rss feed na projektu", $projekat);
                                    $link = $linkPrefix;
                                } else {
                                    niceerror('Doslo je do greske prilikom brisanja RSS feeda. Molimo kontaktirajte administratora.');
                                    $link = "javascript:history.back();";
                                }
                                nicemessage('<a href="' . $link . '">Povratak.</a>');
                            }
                        }
                        //else isset c get parameter
                    }
                    //id is okay
                }
                //subaction == del
            }
            //subaction set
        } elseif ($section == 'bl') {
            //links management
            $linkPrefix .= '&section=bl';
            ?>
<h2>Članci</h2>
 <div class="links clearfix" id="bl">
    <ul>
        <li><a href="<?php 
            echo $linkPrefix;
            ?>
">Lista članaka</a></li>
        <li><a href="<?php 
            echo $linkPrefix . "&subaction=add";
            ?>
">Novi članak</a></li>
    </ul>   
</div>	
    <?php 
            if (!isset($subaction)) {
                $rowsPerPage = 20;
                $pageNum = 1;
                if (isset($_REQUEST['page'])) {
                    $pageNum = $_REQUEST['page'];
                }
                // counting the offset
                $offset = ($pageNum - 1) * $rowsPerPage;
                $articles = fetchArticlesForProject($project[id], $offset, $rowsPerPage);
                foreach ($articles as $article) {
                    ?>
    
   <div class="article_summary clearfix">
   	<?php 
                    if (!empty($article[slika])) {
                        ?>
    	<div class="imgCont">
        	<a href="<?php 
                        echo "index.php?sta=common/articleImageDownload&projekat={$projekat}&predmet={$predmet}&ag={$ag}&a={$article['id']}&u={$article['osoba']}&i={$article['slika']}";
                        ?>
" target="_blank">
    			<img src="<?php 
                        echo "index.php?sta=common/articleImageDownload&projekat={$projekat}&predmet={$predmet}&ag={$ag}&a={$article['id']}&u={$article['osoba']}&i={$article['slika']}";
                        ?>
" />
        	</a>
        </div>
	<?php 
                    }
                    ?>
    	<div class="contentCont" <?php 
                    if (empty($article[slika])) {
                        echo 'style="margin-left: 0;"';
                    }
                    ?>
>
            <h1>
                <a href="<?php 
                    echo $linkPrefix . "&subaction=view&id={$article['id']}";
                    ?>
" 
                title="<?php 
                    echo $article['naslov'];
                    ?>
"><?php 
                    echo filtered_output_string($article['naslov']);
                    ?>
                </a>
            </h1>
            <div class="details">
        <?php 
                    $author = getAuthorOfArticle($article[id]);
                    ?>
                Autor: <?php 
                    echo filtered_output_string($author[ime] . ' ' . $author[prezime]);
                    ?>
<br />
                Datum: <?php 
                    echo date('d.m.Y', strtotime($article[vrijeme]));
                    ?>
            </div><!--details-->
   <?php 
                    if (isUserAuthorOfArticle($article[id], $userid) == true) {
                        ?>
	
            <div class="buttons">
                <a href="<?php 
                        echo $linkPrefix . "&subaction=edit&id={$article['id']}";
                        ?>
" title="Uredi ovaj članak">Uredi</a> | 
                <a href="<?php 
                        echo $linkPrefix . "&subaction=del&id={$article['id']}";
                        ?>
" title="Briši ovaj članak">Briši</a>
            </div><!--buttons-->	
	<?php 
                    }
                    ?>

<div class="text">
                                <?php 
                    $len = strlen($article[tekst]);
                    if (!empty($article[slika])) {
                        $maxLen = 400;
                    } else {
                        $maxLen = 800;
                    }
                    echo filtered_output_string(substr($article['tekst'], 0, $maxLen - 1));
                    if ($len > $maxLen) {
                        echo '...';
                    }
                    ?>
            </div><!--text-->
        </div><!--contentCont-->
   </div><!--article_summary--> 
    
    <?php 
                }
                //foreach article
                $numrows = getCountArticlesForProject($project[id]);
                $maxPage = ceil($numrows / $rowsPerPage);
                $self = $linkPrefix;
                if ($maxPage > 0) {
                    echo "<span class=\"newsPages\">";
                    if ($pageNum > 1) {
                        $page = $pageNum - 1;
                        $prev = " <a href=\"{$self}&page={$page}\">[Prethodna]</a> ";
                        $first = " <a href=\"{$self}&page=1\">[Prva]</a> ";
                    }
                    if ($pageNum < $maxPage) {
                        $page = $pageNum + 1;
                        $next = " <a href=\"{$self}&page={$page}\">[Sljedeća]</a> ";
                        $last = " <a href=\"{$self}&page={$maxPage}\">[Zadnja]</a> ";
                    }
                    echo $first . $prev . " Strana <strong>{$pageNum}</strong> od ukupno <strong>{$maxPage}</strong> " . $next . $last;
                    echo "</span>";
                    //newsPages span
                }
            } else {
                if ($subaction == 'view') {
                    $article = getArticle($id);
                    if (empty($article)) {
                        zamgerlog("projektne strane: nepostojeci clanak sa IDom {$id}, projekat {$projekat} (pp{$predmet}, ag{$ag})", 3);
                        zamgerlog2("nepostojeci clanak na projektu", $id, $projekat);
                        return;
                    }
                    ?>
		
	   <div class="article_full clearfix">
			<div class="contentCont clearfix">
				<h1>
					<a href="<?php 
                    echo $linkPrefix . "?subaction=view&id={$article['id']}";
                    ?>
" 
					title="<?php 
                    echo $article['naslov'];
                    ?>
"><?php 
                    echo filtered_output_string($article['naslov']);
                    ?>
					</a>
				</h1>
				<div class="details">
			<?php 
                    $author = getAuthorOfArticle($article[id]);
                    ?>
					Autor: <?php 
                    echo filtered_output_string($author[ime] . ' ' . $author[prezime]);
                    ?>
<br />
					Datum: <?php 
                    echo date('d.m.Y', strtotime($article[vrijeme]));
                    ?>
				</div><!--details-->
	   <?php 
                    if (isUserAuthorOfArticle($article[id], $userid) == true) {
                        ?>
	
				<div class="buttons">
					<a href="<?php 
                        echo $linkPrefix . "&subaction=edit&id={$article['id']}";
                        ?>
" title="Uredi ovaj članak">Uredi</a> | 
					<a href="<?php 
                        echo $linkPrefix . "&subaction=del&id={$article['id']}";
                        ?>
" title="Briši ovaj članak">Briši</a>
				</div><!--buttons-->	
		<?php 
                    }
                    ?>
		<?php 
                    if (!empty($article[slika])) {
                        ?>
			<div class="imgCont">
            	<a href="<?php 
                        echo "index.php?sta=common/articleImageDownload&projekat={$projekat}&predmet={$predmet}&ag={$ag}&a={$article['id']}&u={$article['osoba']}&i={$article['slika']}";
                        ?>
" target="_blank">
            		<img src="<?php 
                        echo "index.php?sta=common/articleImageDownload&projekat={$projekat}&predmet={$predmet}&ag={$ag}&a={$article['id']}&u={$article['osoba']}&i={$article['slika']}";
                        ?>
" />
                </a>     
            </div>
	  <?php 
                    }
                    ?>
				<div class="text"><?php 
                    echo filtered_output_string($article['tekst']);
                    ?>
</div><!--text-->
			</div><!--contentCont-->
	   </div><!--article_full--> 
       <a id="backLink" href="<?php 
                    echo $linkPrefix;
                    ?>
">Povratak na listu članaka</a>

		
		<?php 
                } elseif ($subaction == 'add') {
                    if (!isset($_REQUEST['submit'])) {
                        ?>
	
    		
				 <h3>Novi članak</h3>
				<?php 
                        print genform("POST", "addForm\" enctype=\"multipart/form-data\" ");
                        ?>
                
                <div id="formDiv">
                	Polja sa * su obavezna. <br />
                
                	<div class="row">
                        <span class="label">Naslov *</span>
                        <span class="formw"><input name="naslov" type="text" id="naslov" size="70" /></span> 
                  	</div>
                    <div class="row">
                        <span class="label">Tekst</span>
                        <span class="formw"><textarea name="tekst" cols="60" rows="15" wrap="physical" id="tekst"></textarea></span>
                   	</div> 
                   
                    <div class="row">
                        <span class="label">Slika</span>
                        <span class="formw">
                            <input name="image" type="file" id="image" size="60" />
                        </span><br /><br />
                        Dozvoljeni tipovi slike: jpg, jpeg, gif, png <br />
                    </div> 
                    
                    <div class="row">	
                      	<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
                    </div>
                
                </div><!--formDiv-->
               
                </form>
                
			
	<?php 
                    } else {
                        $errorText = formProcess_bl('add');
                        if ($errorText == '') {
                            nicemessage('Novi članak uspješno dodan.');
                            zamgerlog("dodao novi clanak na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("dodao clanak na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'edit') {
                    if (!isUserAuthorOfArticle($id, $userid)) {
                        return;
                    }
                    //edit item
                    if (!isset($_REQUEST['submit'])) {
                        $entry = getArticle($id);
                        ?>
				 <h3>Uredi članak</h3>
				<?php 
                        print genform("POST", "editForm\" enctype=\"multipart/form-data\" ");
                        ?>
				
				<div id="formDiv">
					Polja sa * su obavezna. <br />
				
					<div class="row">
						<span class="label">Naslov *</span>
						<span class="formw"><input name="naslov" type="text" id="naslov" size="70" value="<?php 
                        echo $entry['naslov'];
                        ?>
" /></span> 
					</div>
					<div class="row">
						<span class="label">Tekst</span>
						<span class="formw"><textarea name="tekst" cols="60" rows="15" wrap="physical" id="tekst"><?php 
                        echo $entry['tekst'];
                        ?>
</textarea></span>
					</div> 

<?php 
                        if ($entry['slika'] != '') {
                            //if the image exists, display it
                            ?>
				   <div class="row">
						<span class="label">Trenutna slika</span>
						<span class="formw"><img src="<?php 
                            echo "index.php?sta=common/articleImageDownload&projekat={$projekat}&predmet={$predmet}&ag={$ag}&a={$article['id']}&u={$entry['osoba']}&i={$entry['slika']}";
                            ?>
" />
						</span>
				   </div> 
				   
				   <div class="row">
						<span class="label">Briši sliku</span>
						<span class="formw"><input name="delete" type="checkbox" id="delete" value="delete" /></span>
				   </div> 
			   
<?php 
                        }
                        //if image is present
                        ?>
					<div class="row">
					  <span class="label"><?php 
                        if ($entry['slika'] != '') {
                            echo "ILI: Zamijeni sliku";
                        } else {
                            echo "Slika";
                        }
                        ?>
</span>
						<span class="formw">
							<input name="image" type="file" id="image" size="50" />
						</span><br /><br />
						Dozvoljeni tipovi slike: jpg, jpeg, gif, png <br />
					</div>                         
					
					<div class="row">	
						<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
					</div>
				
				</div><!--formDiv-->
				
				
				</form>
				
				
<?php 
                    } else {
                        $errorText = formProcess_bl('edit');
                        if ($errorText == '') {
                            nicemessage('Uspješno ste uredili članak.');
                            zamgerlog("uredio clanak na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("uredio clanak na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            //an error occured trying to process the form
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'del') {
                    //delete item
                    if (isset($id) && is_int($id) && $id > 0) {
                        if (isUserAuthorOfArticle($id, $userid) == false) {
                            return;
                        }
                        if (!isset($_REQUEST['c'])) {
                            echo "Da li ste sigurni da zelite obrisati ovaj članak? <br />";
                            echo '<a href="' . $linkPrefix . '&amp;subaction=del&amp;id=' . $id . '&amp;c=true">Da</a> | <a href="' . $linkPrefix . '">Odustani</a>';
                        } else {
                            if ($_REQUEST['c'] == 'true') {
                                //delete the record
                                if (deleteArticle($id)) {
                                    nicemessage('Uspješno ste obrisali članak.');
                                    zamgerlog("obrisao clanak na projektu {$projekat} (pp{$predmet})", 2);
                                    zamgerlog2("obrisao clanak na projektu", $projekat);
                                    $link = $linkPrefix;
                                } else {
                                    niceerror('Došlo je do greske prilikom brisanja članka. Molimo kontaktirajte administratora.');
                                    $link = "javascript:history.back();";
                                }
                                nicemessage('<a href="' . $link . '">Povratak.</a>');
                            }
                        }
                        //else isset c get parameter
                    }
                    //id is okay
                }
                //subaction == del
            }
            //subaction set
        } elseif ($section == 'file') {
            //files management
            $linkPrefix .= '&section=file';
            ?>
<h2>Fajlovi</h2>
 <div class="links clearfix" id="rss">
    <ul>
        <li><a href="<?php 
            echo $linkPrefix;
            ?>
">Lista fajlova</a></li>
        <li><a href="<?php 
            echo $linkPrefix . "&subaction=add";
            ?>
">Novi fajl</a></li>
    </ul>   
</div>	

    <?php 
            if (!isset($subaction)) {
                $rowsPerPage = 20;
                $pageNum = 1;
                if (isset($_REQUEST['page'])) {
                    $pageNum = $_REQUEST['page'];
                }
                // counting the offset
                $offset = ($pageNum - 1) * $rowsPerPage;
                //display files for this project, with links to edit and delete
                $files = fetchFilesForProjectAllRevisions($project[id], $offset, $rowsPerPage);
                ?>
<table class="files_table" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col" class="creation_date">Datum kreiranja</th>
    <th scope="col" class="author">Autor</th>
    <th scope="col" class="revision">Revizija</th>
    <th scope="col" class="name">Naziv</th>
    <th scope="col" class="filesize">Veličina</th>
    <th scope="col" class="options">Opcije</th>
  </tr>
	<?php 
                foreach ($files as $file) {
                    $lastRevisionId = 0;
                    $firstRevisionId = count($file) > 0 ? count($file) - 1 : 0;
                    $author = getAuthorOfFile($file[$lastRevisionId][id]);
                    ?>
				
    <tr>
    	<td class="creation_date"><?php 
                    echo date('d.m.Y H:i:s', mysql2time($file[$lastRevisionId][vrijeme]));
                    ?>
</td><!--vrijeme-->
    	<td class="author"><?php 
                    echo filtered_output_string($author['ime'] . ' ' . $author['prezime']);
                    ?>
</td><!--author-->
        <td class="revision">v<?php 
                    echo $file[$lastRevisionId][revizija];
                    ?>
</td><!--revizija-->
        <td class="filename"><?php 
                    if (count($file) > 1) {
                        ?>
		<a href="#" onclick="toggleFileRevisions('file_<?php 
                        echo $file[$lastRevisionId][id];
                        ?>
_revisions')"><?php 
                        echo filtered_output_string($file[$lastRevisionId][filename]);
                        ?>
</a>		
   	<?php 
                    } else {
                        ?>
    	<?php 
                        echo filtered_output_string($file[$lastRevisionId][filename]);
                        ?>
    <?php 
                    }
                    ?>
        </td><!--filename-->
        <td class="filesize"><?php 
                    $lokacijafajlova = "{$conf_files_path}/projekti/fajlovi/{$projekat}/" . $file[$lastRevisionId][osoba] . "/" . $file[$lastRevisionId][filename] . '/v' . $file[$lastRevisionId][revizija] . '/';
                    $filepath = $lokacijafajlova . $file[$lastRevisionId][filename];
                    $filesize = filesize($filepath);
                    echo nicesize($filesize);
                    ?>
        </td><!--filesize-->
        <td class="options">
			<a href="<?php 
                    echo 'index.php?sta=common/attachment' . "&tip=projekat&projekat={$projekat}&id=" . $file[$lastRevisionId][id];
                    ?>
">Snimi</a>        
	<?php 
                    if (isUserAuthorOfFile($file[$lastRevisionId][id], $userid)) {
                        ?>
           <a href="<?php 
                        echo $linkPrefix . "&subaction=edit&id=" . $file[$firstRevisionId]['id'];
                        ?>
">Uredi</a>
           <a href="<?php 
                        echo $linkPrefix . "&subaction=del&id=" . $file[$firstRevisionId]['id'];
                        ?>
">Briši</a>
	<?php 
                    }
                    //if user is author of this item
                    ?>
        </td><!--options-->
    </tr><!--file_leading-->
    <?php 
                    if (count($file) > 1) {
                        for ($i = 1; $i < count($file); $i++) {
                            $revision = $file[$i];
                            $author = getAuthorOfFile($revision[id]);
                            ?>
            <tr class="file_<?php 
                            echo $file[$lastRevisionId][id];
                            ?>
_revisions" style="display: none;" id="file_revisions">
                <td class="creation_date"><?php 
                            echo date('d.m.Y H:i:s', mysql2time($revision[vrijeme]));
                            ?>
</td><!--vrijeme-->
                <td class="author"><?php 
                            echo filtered_output_string($author['ime'] . ' ' . $author['prezime']);
                            ?>
</td><!--author-->
                <td class="revision">v<?php 
                            echo $revision[revizija];
                            ?>
</td><!--revizija-->
                <td class="filename"><?php 
                            echo filtered_output_string($revision[filename]);
                            ?>
</td><!--filename-->
                <td class="filesize"><?php 
                            $lokacijafajlova = "{$conf_files_path}/projekti/fajlovi/{$projekat}/" . $revision[osoba] . "/" . $revision[filename] . '/v' . $revision[revizija] . '/';
                            $filepath = $lokacijafajlova . $revision[filename];
                            $filesize = filesize($filepath);
                            echo nicesize($filesize);
                            ?>
                </td><!--filesize-->
                <td class="options">
                    <a href="<?php 
                            echo 'index.php?sta=common/attachment' . "&tip=projekat&projekat={$projekat}&id=" . $revision[id];
                            ?>
">Snimi</a>        
                </td><!--options-->
            </tr><!--file_revision-->	
    <?php 
                        }
                        //foreach revision
                    }
                    //if count files > 1
                }
                //foreach file
                ?>
    </table>
<!--files_table-->
<?php 
                $numrows = getCountFilesForProjectWithoutRevisions($project[id]);
                $maxPage = ceil($numrows / $rowsPerPage);
                $self = $linkPrefix;
                if ($maxPage > 0) {
                    echo "<span class=\"newsPages\">";
                    if ($pageNum > 1) {
                        $page = $pageNum - 1;
                        $prev = " <a href=\"{$self}&page={$page}\">[Prethodna]</a> ";
                        $first = " <a href=\"{$self}&page=1\">[Prva]</a> ";
                    }
                    if ($pageNum < $maxPage) {
                        $page = $pageNum + 1;
                        $next = " <a href=\"{$self}&page={$page}\">[Sljedeća]</a> ";
                        $last = " <a href=\"{$self}&page={$maxPage}\">[Zadnja]</a> ";
                    }
                    echo $first . $prev . " Strana <strong>{$pageNum}</strong> od ukupno <strong>{$maxPage}</strong> " . $next . $last;
                    echo "</span>";
                    //newsPages span
                }
                ?>
    <script type="text/javascript">
		function getElementsByClassName( strClassName, obj ) 
		{
			var ar = arguments[2] || new Array();
			var re = new RegExp("\\b" + strClassName + "\\b", "g");
		
			if ( re.test(obj.className) ) 
			{
				ar.push( obj );
			}
			for ( var i = 0; i < obj.childNodes.length; i++ )
				getElementsByClassName( strClassName, obj.childNodes[i], ar );
			
			return ar;
		}
		
		function toggleFileRevisions(divID)
		{
			 var aryClassElements = getElementsByClassName( divID, document.body );
			for ( var i = 0; i < aryClassElements.length; i++ ) 
			{
				if (aryClassElements[i].style.display == '')
					aryClassElements[i].style.display = 'none';
				else
					aryClassElements[i].style.display = '';	
			}
		}
	
	</script>
    <?php 
            } else {
                if ($subaction == 'add') {
                    if (!isset($_REQUEST['submit'])) {
                        ?>
						 <h3>Novi fajl</h3>
				<?php 
                        print genform("POST", "addForm\" enctype=\"multipart/form-data\" ");
                        ?>
						
						<div id="formDiv">
							Polja sa * su obavezna. <br />
							<b>Limit za upload je 20MB.</b> <br />
                            <div class="row">
                                <span class="label">Fajl *</span>
                                <span class="formw">
                                    <input name="filename" type="file" id="filename" size="60" />
                                    <input type="hidden" name="MAX_FILE_SIZE" value="20971520">
                                </span>
                            </div> 
                            
							<div class="row">	
								<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
							</div>
						
						</div><!--formDiv-->
						</form>
							
	<?php 
                    } else {
                        $errorText = formProcess_file('add');
                        if ($errorText == '') {
                            nicemessage('Novi fajl uspješno dodan.');
                            zamgerlog("dodao novi fajl na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("dodao fajl na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'edit') {
                    if (!isUserAuthorOfFile($id, $userid)) {
                        return;
                    }
                    if (!isThisFileFirstRevision($id)) {
                        return;
                    }
                    //edit item
                    if (!isset($_REQUEST['submit'])) {
                        $entry = getFileFirstRevision($id);
                        $lastRevisionEntry = getFileLastRevision($id);
                        ?>
					 <h3>Uredi fajl</h3>
				<?php 
                        print genform("POST", "editForm\" enctype=\"multipart/form-data\" ");
                        ?>
					
					<div id="formDiv">
						Polja sa * su obavezna. <br />
						<b>Limit za upload je 20MB.</b> <br />							
					   <div class="row">
							<span class="label">Trenutni fajl</span>
							<span class="formw"><a href="<?php 
                        echo 'index.php?sta=common/attachment' . "&tip=projekat&projekat={$projekat}&id=" . $lastRevisionEntry[id];
                        ?>
" >
								<?php 
                        echo filtered_output_string($lastRevisionEntry[filename]);
                        ?>
							</a>
							</span>
					   </div> 

						<div class="row">
						  <span class="label">Zamijeni fajl</span>
							<span class="formw">
								<input name="filename" type="file" id="filename" size="50" />
								<input type="hidden" name="MAX_FILE_SIZE" value="20971520">
							</span>
						</div>                         
						<div class="row">	
							<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
						</div>
					
					</div><!--formDiv-->
					</form>
	
		<?php 
                    } else {
                        $errorText = formProcess_file('edit');
                        if ($errorText == '') {
                            nicemessage('Uspješno ste uredili fajl.');
                            zamgerlog("uredio fajl na projektu {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("uredio fajl na projektu", $projekat);
                            $link = $linkPrefix;
                        } else {
                            //an error occured trying to process the form
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'del') {
                    if (!isUserAuthorOfFile($id, $userid)) {
                        return;
                    }
                    if (!isThisFileFirstRevision($id)) {
                        return;
                    }
                    //delete item
                    if (isset($id) && is_int($id) && $id > 0) {
                        if (!isset($_REQUEST['c'])) {
                            echo "Da li ste sigurni da zelite obrisati ovaj fajl? Obrisacete sve revizije fajla sa servera.<br />";
                            echo '<a href="' . $linkPrefix . '&subaction=del&id=' . $id . '&c=true">Da</a> | <a href="' . $linkPrefix . '">Odustani</a>';
                        } else {
                            if ($_REQUEST['c'] == 'true') {
                                //delete the record
                                if (deleteFile($id)) {
                                    nicemessage('Uspješno ste obrisali fajl.');
                                    zamgerlog("obrisao fajl na projektu {$projekat} (pp{$predmet})", 2);
                                    zamgerlog2("obrisao fajl na projektu", $projekat);
                                    $link = $linkPrefix;
                                } else {
                                    niceerror('Doslo je do greske prilikom brisanja fajla. Molimo kontaktirajte administratora.');
                                    $link = "javascript:history.back();";
                                }
                                nicemessage('<a href="' . $link . '">Povratak.</a>');
                            }
                        }
                        //else isset c get parameter
                    }
                    //id is okay
                }
                //subaction == del
            }
            //subaction set
        } elseif ($section == 'bb') {
            //links management
            $linkPrefix .= '&section=bb';
            ?>
<h2>Grupa za diskusiju</h2>
 <div class="links clearfix" id="bl">
    <ul>
        <li><a href="<?php 
            echo $linkPrefix;
            ?>
">Lista tema</a></li>
        <li><a href="<?php 
            echo $linkPrefix . "&subaction=add";
            ?>
">Nova tema</a></li>
    </ul>   
</div>	
    <?php 
            if (!isset($subaction)) {
                $rowsPerPage = 20;
                $pageNum = 1;
                if (isset($_REQUEST['page'])) {
                    $pageNum = $_REQUEST['page'];
                }
                // counting the offset
                $offset = ($pageNum - 1) * $rowsPerPage;
                $threads = fetchThreadsForProject($project[id], $offset, $rowsPerPage);
                $numrows = getCountThreadsForProject($project[id]);
                ?>
<div id="threadList">
	<div class="threadRow caption clearfix">
        <div class="threadInfo">
        	<div class="views">Pregleda</div><!--views-->
        	<div class="lastReply">Zadnji odgovor</div><!--lastReply-->
            <div class="replies">Odgovora</div><!--replies-->
        </div><!--threadInfo-->
    	<div class="title">Teme (<?php 
                echo $numrows;
                ?>
)</div><!--title-->		
    </div><!--threadRow caption-->
    <?php 
                foreach ($threads as $key => $thread) {
                    ?>
	<div class="threadRow clearfix<?php 
                    if ($key % 2) {
                        echo ' pattern';
                    }
                    ?>
">
        <div class="threadInfo">
        	<div class="views"><?php 
                    echo intval($thread[pregleda]);
                    ?>
</div><!--views-->
        	<div class="lastReply"><?php 
                    echo date('d.m.Y H:i:s', mysql2time($thread[zadnji_post][vrijeme]));
                    ?>
<br /><?php 
                    echo filtered_output_string($thread[zadnji_post][osoba][prezime] . ' ' . $thread[zadnji_post][osoba][ime]);
                    ?>
</div><!--lastReply-->
            <div class="replies"><?php 
                    echo intval($thread[broj_odgovora]);
                    ?>
</div><!--replies-->
        </div><!--threadInfo-->
    	<div class="title"><a href="<?php 
                    echo $linkPrefix . "&subaction=view&tid={$thread['id']}";
                    ?>
" title="<?php 
                    echo $thread['naslov'];
                    ?>
"><?php 
                    echo filtered_output_string($thread[naslov]);
                    ?>
</a></div><!--title-->
        <div class="author"><?php 
                    echo filtered_output_string($thread[prvi_post][osoba][prezime] . ' ' . $thread[prvi_post][osoba][ime]);
                    ?>
</div><!--author-->		
    </div><!--threadRow caption-->
    <?php 
                }
                //foreach thread
                ?>
</div><!--threadList-->
    <?php 
                $maxPage = ceil($numrows / $rowsPerPage);
                $self = $linkPrefix;
                if ($maxPage > 0) {
                    echo "<span class=\"newsPages\">";
                    if ($pageNum > 1) {
                        $page = $pageNum - 1;
                        $prev = " <a href=\"{$self}&page={$page}\">[Prethodna]</a> ";
                        $first = " <a href=\"{$self}&page=1\">[Prva]</a> ";
                    }
                    if ($pageNum < $maxPage) {
                        $page = $pageNum + 1;
                        $next = " <a href=\"{$self}&page={$page}\">[Sljedeća]</a> ";
                        $last = " <a href=\"{$self}&page={$maxPage}\">[Zadnja]</a> ";
                    }
                    echo $first . $prev . " Strana <strong>{$pageNum}</strong> od ukupno <strong>{$maxPage}</strong> " . $next . $last;
                    echo "</span>";
                    //newsPages span
                }
            } else {
                if ($subaction == 'view') {
                    $tid = intval($_REQUEST[tid]);
                    $thread = getThreadAndPosts($tid);
                    if (empty($thread)) {
                        zamgerlog("projektne strane: nepostojeci thread sa IDom {$id}, projekat {$projekat} (pp{$predmet}, ag{$ag})", 3);
                        zamgerlog2("nepostojeci thread na projektu", $id, $projekat);
                        return;
                    }
                    incrementThreadViewCount($thread[id]);
                    ?>
    <div id="fullThread">
    <?php 
                    foreach ($thread[posts] as $post) {
                        ?>
				
		<div class="post"><a name="p<?php 
                        echo $post[id];
                        ?>
">
        	<div id="post_<?php 
                        echo $post[id];
                        ?>
_header" class="header clearfix" onclick="toggleShowPost('post_<?php 
                        echo $post[id];
                        ?>
')">
                <div class="buttons">
                	<a href="<?php 
                        echo $linkPrefix . "&subaction=add&tid={$post['tema']}&id={$post['id']}";
                        ?>
" title="Odgovori na ovaj post">Odgovori</a>
    <?php 
                        if (isUserAuthorOfPost($post[id], $userid) == true) {
                            ?>
    				| <a href="<?php 
                            echo $linkPrefix . "&subaction=edit&tid={$post['tema']}&id={$post['id']}";
                            ?>
" title="Uredi vlastiti post">Uredi</a>
    				| <a href="<?php 
                            echo $linkPrefix . "&subaction=del&tid={$post['tema']}&id={$post['id']}";
                            ?>
" title="Obriši vlastiti post">Obriši</a>		
    <?php 
                        }
                        ?>
                </div>
                <div class="maininfo">
                	<div class="date"><?php 
                        echo date('d.m.Y H:i:s', mysql2time($post[vrijeme]));
                        ?>
</div>
                    <div class="author"><?php 
                        echo filtered_output_string($post[osoba][prezime] . ' ' . $post[osoba][ime]);
                        ?>
</div> - 
                    <div class="title"><?php 
                        echo filtered_output_string($post[naslov]);
                        ?>
</div>
                </div>
            </div><!--header-->
            <div class="text" id="post_<?php 
                        echo $post[id];
                        ?>
_text"><?php 
                        echo filtered_output_string($post[tekst]);
                        ?>
</div><!--text-->

        </div><!--post-->				
					
	<?php 
                    }
                    //foreach post
                    ?>
    
    
    </div><!--fullThread-->
        <script type="text/javascript">
		function toggleShowPost(divID)
		{
			header = document.getElementById(divID + '_header');
			text = document.getElementById(divID + '_text');
			if (text.style.display == 'block' || text.style.display == '')
			{
				text.style.display = 'none';
				header.style.backgroundColor = '#F5F5F5';
				header.style.color = 'black';
			}
			else
			{
				text.style.display = 'block';
				header.style.backgroundColor = '#EEEEEE';
			}	
				
		}
	
		</script>
	
    <?php 
                } elseif ($subaction == 'add') {
                    $threadID = intval($_REQUEST['tid']);
                    if ($threadID <= 0) {
                        $thread = false;
                    } else {
                        $thread = true;
                    }
                    if ($thread == true) {
                        $postInfo = getPostInfoForThread($threadID, $id);
                        $extendedThreadInfo = array();
                        getExtendedInfoForThread($threadID, $extendedThreadInfo);
                        if (empty($postInfo)) {
                            zamgerlog("projektne strane: odgovor na nepostojeci post {$id}, projekat {$projekat} (pp{$predmet})", 3);
                            zamgerlog2("odgovor na nepostojeci post na projektu", $id, $projekat);
                            return;
                        }
                    }
                    if (!isset($_REQUEST['submit'])) {
                        ?>
	
    		
				 <h3><?php 
                        if ($thread == true) {
                            echo 'Novi odgovor';
                        } else {
                            echo 'Nova tema';
                        }
                        ?>
</h3>
				<?php 
                        print genform("POST", "addForm");
                        ?>
                <?php 
                        if ($thread == true) {
                            ?>
 
					<input type="hidden" name="tid" value="<?php 
                            echo $threadID;
                            ?>
"  />
				<?php 
                        }
                        ?>
                <div id="formDiv">
                	Polja sa * su obavezna. <br />
                
                	<div class="row">
                        <span class="label">Naslov *</span>
                        <span class="formw"><input name="naslov" type="text" id="naslov" size="70" <?php 
                        if ($thread == true) {
                            ?>
 value="RE: <?php 
                            echo $extendedThreadInfo['naslov'];
                            ?>
"<?php 
                        }
                        ?>
/></span> 
                  	</div>
                    <div class="row">
                        <span class="label">Tekst *</span>
                        <span class="formw"><textarea name="tekst" cols="60" rows="15" wrap="physical" id="tekst"></textarea></span>
                   	</div> 
                                      
                    <div class="row">	
                      	<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
                    </div>
                
                </div><!--formDiv-->
               
                </form>
               
	<?php 
                    } else {
                        $errorText = formProcess_bb('add', $thread, $threadID);
                        if ($errorText == '') {
                            if ($thread == true) {
                                nicemessage('Novi odgovor uspješno dodan.');
                                zamgerlog("dodao novi odgovor na diskusiju ID {$threadID}, projekat {$projekat} (pp{$predmet})", 2);
                                zamgerlog2("dodao odgovor na diskusiju", $threadID, $projekat);
                            } else {
                                nicemessage('Nova tema uspješno dodana.');
                                zamgerlog("dodao novu temu na projektu {$projekat} (pp{$predmet})", 2);
                                zamgerlog2("dodao temu na projektu", $projekat);
                            }
                            if (!empty($_REQUEST[tid])) {
                                $link = $linkPrefix . "&subaction=view&tid={$_REQUEST['tid']}";
                            } else {
                                $link = $linkPrefix;
                            }
                        } else {
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'edit') {
                    //edit item
                    if (isUserAuthorOfPost($id, $userid) == false) {
                        zamgerlog("pokusava urediti post {$id} a nije autor, projekat {$projekat} (pp{$predmet})", 3);
                        zamgerlog2("pokusava urediti post a nije autor", $id, $projekat);
                        return;
                    }
                    $threadID = intval($_REQUEST[tid]);
                    if ($threadID <= 0) {
                        zamgerlog("pokusava urediti nepostojeci post {$id}, projekat {$projekat} (pp{$predmet})", 3);
                        zamgerlog2("pokusava urediti nepostojeci post", $id, $projekat);
                        return;
                    }
                    if (!isset($_REQUEST['submit'])) {
                        $entry = getPost($id);
                        if (empty($entry)) {
                            zamgerlog("pokusava urediti nepostojeci post {$id}, projekat {$projekat} (pp{$predmet})", 3);
                            zamgerlog2("pokusava urediti nepostojeci post", $id, $projekat);
                            return;
                        }
                        ?>
				 <h3>Uredi post</h3>
				<?php 
                        print genform("POST", "editForm");
                        ?>
				<div id="formDiv">
					Polja sa * su obavezna. <br />
				
					<div class="row">
						<span class="label">Naslov *</span>
						<span class="formw"><input name="naslov" type="text" id="naslov" size="70" value="<?php 
                        echo $entry['naslov'];
                        ?>
" /></span> 
					</div>
					<div class="row">
						<span class="label">Tekst *</span>
						<span class="formw"><textarea name="tekst" cols="60" rows="15" wrap="physical" id="tekst"><?php 
                        echo $entry['tekst'];
                        ?>
</textarea></span>
					</div> 
					
					<div class="row">	
						<span class="formw" style="margin-left:150px;"><input name="submit" type="submit" id="submit" value="Potvrdi"/></span>
					</div>
				
				</div><!--formDiv-->
				
				
				</form>
				
				
<?php 
                    } else {
                        $errorText = formProcess_bb('edit', $thread, $threadID);
                        if ($errorText == '') {
                            nicemessage('Uspješno ste uredili post.');
                            zamgerlog("uredio vlastiti BB post {$id}, projekat {$projekat} (pp{$predmet})", 2);
                            zamgerlog2("uredio vlastiti post", $id, $projekat);
                            $link = $linkPrefix . "&subaction=view&tid={$_REQUEST['tid']}";
                        } else {
                            //an error occured trying to process the form
                            niceerror($errorText);
                            $link = "javascript:history.back();";
                        }
                        nicemessage('<a href="' . $link . '">Povratak.</a>');
                    }
                    //submitted the form
                } elseif ($subaction == 'del') {
                    //delete item
                    if (isset($id) && is_int($id) && $id > 0) {
                        if (isUserAuthorOfPost($id, $userid) == false) {
                            zamgerlog("pokusava izbrisati post {$id} a nije autor, projekat {$projekat} (pp{$predmet})", 3);
                            zamgerlog2("pokusava izbrisati post a nije autor", $id, $projekat);
                            return;
                        }
                        $threadID = intval($_REQUEST[tid]);
                        if ($threadID <= 0) {
                            zamgerlog("pokusava izbrisati nepostojeci post {$id}, projekat {$projekat} (pp{$predmet})", 3);
                            zamgerlog2("pokusava izbrisati nepostojeci post", $id, $projekat);
                            return;
                        }
                        if (!isset($_REQUEST['c'])) {
                            echo "Da li ste sigurni da zelite obrisati ovaj post? <br />";
                            echo '<a href="' . $linkPrefix . '&amp;subaction=del&tid=' . $threadID . '&id=' . $id . '&amp;c=true">Da</a> | <a href="' . $linkPrefix . '">Odustani</a>';
                        } else {
                            if ($_REQUEST['c'] == 'true') {
                                //delete the record
                                if (deletePost($id)) {
                                    nicemessage('Uspješno ste obrisali post.');
                                    zamgerlog("obrisao post na projektu {$projekat} (pp{$predmet})", 2);
                                    zamgerlog2("obrisao post na projektu", $projekat);
                                    if (getCountPostsInThread($threadID) > 0) {
                                        $link = $linkPrefix . "&subaction=view&tid={$_REQUEST['tid']}";
                                    } else {
                                        $link = $linkPrefix;
                                    }
                                } else {
                                    niceerror('Došlo je do greske prilikom brisanja posta. Molimo kontaktirajte administratora.');
                                    $link = "javascript:history.back();";
                                }
                                nicemessage('<a href="' . $link . '">Povratak.</a>');
                            }
                        }
                        //else isset c get parameter
                    }
                    //id is okay
                }
                //subaction == del
            }
            //subaction set
        }
        //section == bb (forum)
    }
    //else - section is set
}
Ejemplo n.º 2
0
function db_grid($table)
{
    global $_lv_;
    global $__lv_cn, $__lv_ct, $__lv_cs, $__lv_showcreate;
    // Update database with submitted data
    db_submit();
    // Parse table columns from "show create" query
    __lv_parsetable($table);
    // Generate form header with hidden fields - this will be used for each row
    $form_header = genform("POST");
    $form_header .= '<input type="hidden" name="_lv_table" value="' . $table . '"> <input type="hidden" name="_lv_action" value="edit">' . "\n";
    // List tables - used to find foreign keys
    $q200 = myquery("show tables");
    while ($r200 = mysql_fetch_row($q200)) {
        $tables[] = $r200[0];
    }
    // Query database to get default form values
    $sql = "select * from {$table}";
    $n = 0;
    for ($i = 0; $i < count($__lv_cn); $i++) {
        $name = $__lv_cn[$i];
        // Get WHERE from $_lv_
        if (strlen($_lv_["where:{$name}"]) > 0) {
            if ($n > 0) {
                $sql .= " and ";
            } else {
                $sql .= " where ";
            }
            $sql .= "{$name}='" . my_escape($_lv_["where:{$name}"]) . "'";
            $n++;
        }
        // We are not interested in _lv_where...
    }
    // Get ORDER BY from $_lv_
    foreach ($_lv_ as $key => $value) {
        if ($key == "orderby") {
            $sql .= " order by " . $value;
            break;
        }
    }
    // Get LIMIT from $_lv_
    foreach ($_lv_ as $key => $value) {
        if ($key == "limit") {
            $sql .= " limit " . $value;
            break;
        }
    }
    // Display table header
    $result .= '<table border="0" cellspacing="0" cellpadding="3">' . "\n";
    $result .= '<tr bgcolor="#bbbbbb">' . "\n";
    for ($i = 0; $i < count($__lv_cn); $i++) {
        $name = $__lv_cn[$i];
        $type = $__lv_ct[$i];
        $label = strtoupper(substr($name, 0, 1)) . strtolower(substr($name, 1));
        $label = str_replace("_", " ", $label);
        if ($_lv_["label:{$name}"]) {
            $label = $_lv_["label:{$name}"];
        }
        // ID and fields given in WHERE are always hidden
        if ($name != "id" && !$_lv_["where:{$name}"]) {
            $result .= "<th>{$label}</th>\n";
        }
    }
    $result .= "<th>&nbsp;</th>\n";
    // Extra column for submit button
    $result .= "</tr>\n";
    // Table contents
    $q202 = myquery($sql);
    $color = 0;
    while ($r202 = mysql_fetch_assoc($q202)) {
        $result .= "{$form_header}\n";
        if ($color == 0) {
            $result .= "<tr>\n";
            $color = 1;
        } else {
            $result .= '<tr bgcolor="#efefef">' . "\n";
            $color = 0;
        }
        // Display form
        for ($i = 0; $i < count($__lv_cn); $i++) {
            $name = $__lv_cn[$i];
            $type = $__lv_ct[$i];
            $size = $__lv_cs[$i];
            if ($size > 15) {
                $size = 15;
            }
            // not practical to have size>15
            // ID and fields given in WHERE are always hidden
            if ($name == "id") {
                // FIXME: Value of 0 suggests that this is an autonumber field
                if (intval($r202[$name]) != 0) {
                    $result .= '<input type="hidden" name="_lv_where_id" value="' . $r202[$name] . '">' . "\n";
                    // We need to resubmit data for add
                    $result .= '<input type="hidden" name="_lv_column_id" value="' . $r202[$name] . '">' . "\n";
                }
            } else {
                if ($_lv_["where:{$name}"]) {
                    $result .= '<input type="hidden" name="_lv_where_' . $name . '" value="' . $_lv_["where:{$name}"] . '">' . "\n";
                    // We need to resubmit data for add
                    $result .= '<input type="hidden" name="_lv_column_' . $name . '" value="' . $_lv_["where:{$name}"] . '">' . "\n";
                    // find foreign keys
                } else {
                    if (in_array($name, $tables)) {
                        $result .= "<td>" . db_dropdown($name, $r202[$name]) . "</td>\n";
                        // db_dropdown will destroy __lv_c* ...
                        __lv_parsetable($table);
                        // Various column types
                    } else {
                        if ($type == "varchar") {
                            $result .= '<td><input type="text" name="_lv_column_' . $name . '" size="' . $size . '" value="' . $r202[$name] . '"></td>' . "\n";
                        } else {
                            if ($type == "text") {
                                $result .= '<td><textarea name="_lv_column_' . $name . '" rows="5" cols="20">' . $r202[$name] . '</textarea></td>' . "\n";
                            } else {
                                if ($type == "date") {
                                    // Parse date
                                    if ($r202[$name]) {
                                        $mytime = mysql2time($r202[$name]);
                                    } else {
                                        $mytime = time();
                                        // Set time to now
                                    }
                                    $d = date('d', $mytime);
                                    $m = date('m', $mytime);
                                    $Y = date('Y', $mytime);
                                    $result .= '<td>' . datectrl($d, $m, $Y, "_lv_column_{$name}" . "_") . "</td>\n";
                                } else {
                                    if ($type == "datetime") {
                                        // Parse date
                                        if ($r202[$name]) {
                                            $mytime = mysql2time($r202[$name]);
                                        } else {
                                            $mytime = time();
                                            // Set time to now
                                        }
                                        $d = date('d', $mytime);
                                        $m = date('m', $mytime);
                                        $Y = date('Y', $mytime);
                                        $h = date('H', $mytime);
                                        $mi = date('i', $mytime);
                                        $se = date('s', $mytime);
                                        $result .= '<td>' . datectrl($d, $m, $Y, "_lv_column_{$name}" . "_") . "\n";
                                        $result .= '<input type="text" size="2" name="_lv_column_' . $name . '_hour" value="' . $h . '">:';
                                        $result .= '<input type="text" size="2" name="_lv_column_' . $name . '_minute" value="' . $mi . '">:';
                                        $result .= '<input type="text" size="2" name="_lv_column_' . $name . '_second" value="' . $se . '"></td>' . "\n";
                                    } else {
                                        if ($type == "tinyint" && $size == "1") {
                                            // assume boolean
                                            $result .= '<td><input type="checkbox" name="_lv_column_' . $name . '"';
                                            if ($r202[$name] == "1") {
                                                $result .= ' CHECKED';
                                            }
                                            $result .= '></td>' . "\n";
                                        } else {
                                            if ($type == "int" || $type == "tinyint" || $type == "smallint" || $type == "bigint" || $type == "float" || $type == "double") {
                                                // classic numeric
                                                $result .= '<td><input type="text" name="_lv_column_' . $name . '" size="' . $size . '" value="' . $r202[$name] . '"></td>' . "\n";
                                            } else {
                                                $result .= "<td>Unknown type: '{$type}'</td>\n";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Row ends
        $result .= '<td>';
        if ($_lv_["enableedit"]) {
            $result .= '<a href="' . genuri() . '&_lv_nav_id=' . $r202["id"] . '">Izmijeni</a> ';
        }
        $result .= '<input type="submit" value=" Pošalji "><input type="submit" name="_lv_action_delete" value=" Obriši "></td>' . "\n";
        $result .= "</tr></form>";
    }
    $result .= "</table>\n";
    return $result;
}
Ejemplo n.º 3
0
function nastavnik_zadace()
{
    global $userid, $user_siteadmin, $conf_files_path;
    require "lib/manip.php";
    require "lib/autotest.php";
    global $mass_rezultat;
    // za masovni unos studenata u grupe
    global $_lv_;
    // radi autogenerisanih formi
    // Parametri potrebni za Moodle integraciju
    global $conf_moodle, $conf_moodle_url, $conf_moodle_db, $conf_moodle_prefix, $conf_moodle_reuse_connection, $conf_moodle_dbhost, $conf_moodle_dbuser, $conf_moodle_dbpass;
    global $__lv_connection, $conf_use_mysql_utf8;
    // Parametri
    $predmet = intval($_REQUEST['predmet']);
    $ag = intval($_REQUEST['ag']);
    // Naziv predmeta
    $q5 = myquery("select naziv from predmet where id={$predmet}");
    if (mysql_num_rows($q5) < 1) {
        biguglyerror("Nepoznat predmet");
        zamgerlog("ilegalan predmet {$predmet}", 3);
        //nivo 3: greska
        zamgerlog2("nepoznat predmet", $predmet);
        return;
    }
    $predmet_naziv = mysql_result($q5, 0, 0);
    // Da li korisnik ima pravo ući u modul?
    if (!$user_siteadmin) {
        $q10 = myquery("select nivo_pristupa from nastavnik_predmet where nastavnik={$userid} and predmet={$predmet} and akademska_godina={$ag}");
        if (mysql_num_rows($q10) < 1 || mysql_result($q10, 0, 0) == "asistent") {
            zamgerlog("nastavnik/ispiti privilegije (predmet pp{$predmet})", 3);
            zamgerlog2("nije nastavnik na predmetu", $predmet, $ag);
            biguglyerror("Nemate pravo pristupa ovoj opciji");
            return;
        }
    }
    // Dozvoljene ekstenzije
    $q13 = myquery("select naziv from ekstenzije");
    $dozvoljene_ekstenzije = array();
    while ($r13 = mysql_fetch_row($q13)) {
        array_push($dozvoljene_ekstenzije, $r13[0]);
    }
    // Da li predmet posjeduje komponente za zadaće?
    $q15 = myquery("select k.id, k.naziv from komponenta as k, tippredmeta_komponenta as tpk, akademska_godina_predmet as agp where agp.akademska_godina={$ag} and agp.predmet={$predmet} and agp.tippredmeta=tpk.tippredmeta and tpk.komponenta=k.id and k.tipkomponente=4");
    if (mysql_num_rows($q15) < 1) {
        zamgerlog("ne postoji komponenta za zadace na predmetu pp{$predmet} ag{$ag}", 3);
        zamgerlog2("ne postoji komponenta za zadace", $predmet, $ag);
        niceerror("U sistemu bodovanja za ovaj predmet nije definisana nijedna komponenta zadaće.");
        print "<p>Da biste nastavili, promijenite <a href=\"?sta=nastavnik/tip?predmet={$predmet}&ag={$ag}\">sistem bodovanja</a> za ovaj predmet.</p>\n";
        return;
    }
    if (mysql_num_rows($q15) > 1) {
        niceerror("U sistemu bodovanja za ovaj predmet je definisano više od jedne komponente za zadaće.");
        print "<p>Ovaj modul trenutno podržava samo jednu komponentu zadaća. Ako imate potrebu za rad sa više od jedne komponente zadaća istovremeno, kontaktirajte administratora Zamgera. U suprotnom, provjerite <a href=\"?sta=nastavnik/tip?predmet={$predmet}&ag={$ag}\">sistem bodovanja</a> za ovaj predmet za slučaj da je ova situacija posljedica greške.</p>\n";
        print "<p>Koristićemo komponentu označenu nazivom: <b>" . mysql_result($q15, 0, 1) . "</b></p>";
    }
    $komponenta_za_zadace = mysql_result($q15, 0, 0);
    ?>

<p>&nbsp;</p>

<p><h3><?php 
    echo $predmet_naziv;
    ?>
 - Zadaće</h3></p>

<?php 
    # Masovni unos zadaća
    if ($_POST['akcija'] == "massinput" && strlen($_POST['nazad']) < 1 && check_csrf_token()) {
        if ($_POST['fakatradi'] != 1) {
            $ispis = 1;
        } else {
            $ispis = 0;
        }
        // Provjera ostalih parametara
        $zadaca = intval($_REQUEST['_lv_column_zadaca']);
        $zadatak = intval($_REQUEST['zadatak']);
        $q20 = myquery("select naziv,zadataka,bodova,komponenta,predmet,akademska_godina from zadaca where id={$zadaca}");
        if (mysql_num_rows($q20) < 1) {
            zamgerlog("nepostojeca zadaca {$zadaca}", 3);
            // 3 = greška
            zamgerlog2("nepostojeca zadaca", $zadaca);
            niceerror("Morate najprije kreirati zadaću");
            print "\n<p>Koristite formular &quot;Kreiranje zadaće&quot; koji se nalazi na prethodnoj stranici. Ukoliko ne vidite nijednu zadaću na spisku &quot;Postojeće zadaće&quot;, koristite dugme Refresh vašeg web preglednika.</p>\n";
            return;
        }
        if (mysql_result($q20, 0, 1) < $zadatak) {
            zamgerlog("zadaca {$zadaca} nema {$zadatak} zadataka", 3);
            zamgerlog2("zadaca nema toliko zadataka", $zadaca, $zadatak);
            niceerror("Zadaća \"" . mysql_result($q20, 0, 0) . "\" nema {$zadatak} zadataka.");
            return;
        }
        $maxbodova = mysql_result($q20, 0, 2);
        $komponenta = mysql_result($q20, 0, 3);
        // Provjera spoofanja zadaće
        if ($predmet != mysql_result($q20, 0, 4) || $ag != mysql_result($q20, 0, 5)) {
            zamgerlog("zadaca z{$zadaca} nije u predmetu pp{$predmet}", 3);
            zamgerlog2("id zadace i predmeta se ne poklapaju", $zadaca, $predmet, $ag);
            niceerror("Pogresan ID zadace!");
            return;
        }
        if ($ispis) {
            ?>
Akcije koje će biti urađene:<br/><br/>
		<?php 
            echo genform("POST");
            ?>
		<input type="hidden" name="fakatradi" value="1">
		<input type="hidden" name="_lv_column_zadaca" value="<?php 
            echo $zadaca;
            ?>
">
		<table border="0" cellspacing="1" cellpadding="2">
		<!-- FIXME: prebaciti stilove u CSS? -->
		<thead>
		<tr bgcolor="#999999">
			<td><font style="font-family:DejaVu Sans,Verdana,Arial,sans-serif;font-size:11px;color:white;">Prezime</font></td>
			<td><font style="font-family:DejaVu Sans,Verdana,Arial,sans-serif;font-size:11px;color:white;">Ime</font></td>
			<td><font style="font-family:DejaVu Sans,Verdana,Arial,sans-serif;font-size:11px;color:white;">Bodovi / Komentar</font></td>
		</tr>
		</thead>
		<tbody>
		<?php 
        }
        $greska = mass_input($ispis);
        // Funkcija koja parsira podatke
        if (count($mass_rezultat) == 0) {
            niceerror("Niste unijeli ništa.");
            return;
        }
        foreach ($mass_rezultat['ime'] as $student => $ime) {
            $prezime = $mass_rezultat['prezime'][$student];
            $bodova = $mass_rezultat['podatak1'][$student];
            $bodova = str_replace(",", ".", $bodova);
            // Student neocijenjen (prazno mjesto za ocjenu)
            if (floatval($bodova) == 0 && strpos($bodova, "0") === FALSE) {
                if ($ispis) {
                    print "Student '{$prezime} {$ime}' - nema zadaću (nije unesen broj bodova {$bodova})<br/>";
                }
                continue;
            }
            // Bodovi moraju biti manji od maximalnih borova
            $bodova = floatval($bodova);
            if ($bodova > $maxbodova) {
                if ($ispis) {
                    print "-- Studenta '{$prezime} {$ime}' ima {$bodova} bodova što je više od maksimalnih {$maxbodova}<br/>";
                    //$greska=1;
                    continue;
                }
            }
            // Zaključak
            if ($ispis) {
                print "Student '{$prezime} {$ime}' - zadaća {$zadaca}, bodova {$bodova}<br/>";
            } else {
                // Odredjujemo zadnji filename
                $q25 = myquery("select filename from zadatak where zadaca={$zadaca} and redni_broj={$zadatak} and student={$student} order by id desc limit 1");
                if (mysql_num_rows($q25) > 0) {
                    $filename = mysql_result($q25, 0, 0);
                } else {
                    $filename = '';
                }
                $status_pregledana = 5;
                // status 5: pregledana
                $q30 = myquery("insert into zadatak set zadaca={$zadaca}, redni_broj={$zadatak}, student={$student}, status={$status_pregledana}, bodova={$bodova}, vrijeme=NOW(), filename='{$filename}', userid={$userid}");
                zamgerlog2("bodovanje zadace", $student, $zadaca, $zadatak, $bodova);
                // Treba nam ponudakursa za update komponente
                $q35 = myquery("select sp.predmet from student_predmet as sp, ponudakursa as pk where sp.student={$student} and sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag}");
                $ponudakursa = mysql_result($q35, 0, 0);
                update_komponente($student, $ponudakursa, $komponenta);
                // update statistike
            }
        }
        if ($ispis) {
            if ($greska == 0) {
                ?>
			</tbody></table>
			<p>Potvrdite upis ispita i bodova ili se vratite na prethodni ekran.</p>
			<p><input type="submit" name="nazad" value=" Nazad "> <input type="submit" value=" Potvrda"></p>
			</form>
			<?php 
            } else {
                ?>
			</tbody></table>
			<p>U unesenim podacima ima grešaka. Da li ste izabrali ispravan format ("Prezime[TAB]Ime" vs. "Prezime Ime")? Vratite se nazad kako biste ovo popravili.</p>
			<p><input type="submit" name="nazad" value=" Nazad "></p>
			</form>
			<?php 
            }
            return;
        } else {
            zamgerlog("masovno upisane zadaće na predmet pp{$predmet}, zadaća z{$zadaca}, zadatak {$zadatak}", 2);
            // 2 = edit
            ?>
		Bodovi iz zadaća su upisani.
		<script language="JavaScript">
		location.href='?sta=nastavnik/zadace&predmet=<?php 
            echo $predmet;
            ?>
&ag=<?php 
            echo $ag;
            ?>
';
		</script>
		<?php 
        }
    }
    // Akcija za kreiranje nove, promjenu postojeće ili brisanje zadaće
    if ($_POST['akcija'] == "edit" && $_POST['potvrdabrisanja'] != " Nazad " && check_csrf_token()) {
        $edit_zadaca = intval($_POST['zadaca']);
        // Prava pristupa
        if ($edit_zadaca > 0) {
            $q86 = myquery("select predmet, akademska_godina from zadaca where id={$edit_zadaca}");
            if (mysql_num_rows($q86) < 1) {
                niceerror("Nepostojeća zadaća sa IDom {$edit_zadaca}");
                zamgerlog("promjena nepostojece zadace {$edit_zadaca}", 3);
                zamgerlog2("nepostojeca zadaca", $edit_zadaca);
                return 0;
            }
            if (mysql_result($q86, 0, 0) != $predmet || mysql_result($q86, 0, 1) != $ag) {
                niceerror("Zadaća nije sa izabranog predmeta");
                zamgerlog("promjena zadace: zadaca {$edit_zadaca} nije sa predmeta pp{$predmet}", 3);
                zamgerlog2("id zadace i predmeta se ne poklapaju", $edit_zadaca, $predmet, $ag);
                return 0;
            }
        }
        // Brisanje postavke zadaće (a ne čitave zadaće!)
        if ($_POST['dugmeobrisi'] == "Obriši") {
            $q100 = myquery("select postavka_zadace from zadaca where id={$edit_zadaca}");
            $filepath = "{$conf_files_path}/zadace/{$predmet}-{$ag}/postavke/" . mysql_result($q100, 0, 0);
            unlink($filepath);
            $q110 = myquery("update zadaca set postavka_zadace='' where id={$edit_zadaca}");
            nicemessage("Postavka zadaće obrisana");
            print "<a href=\"?sta=nastavnik/zadace&predmet={$predmet}&ag={$ag}&_lv_nav_id={$edit_zadaca}\">Nazad</a>\n";
            zamgerlog("obrisana postavka zadace z{$edit_zadaca}", 2);
            zamgerlog2("obrisana postavka zadace", $edit_zadaca);
            return;
        }
        // Brisanje zadaće
        if ($_POST['brisanje'] == " Obriši ") {
            if ($edit_zadaca <= 0) {
                return;
            }
            // Ne bi se smjelo desiti
            $q86 = myquery("select predmet, akademska_godina from zadaca where id={$edit_zadaca}");
            if (mysql_num_rows($q86) < 1) {
                niceerror("Nepostojeća zadaća sa IDom {$edit_zadaca}");
                zamgerlog("brisanje nepostojece zadace {$edit_zadaca}", 3);
                zamgerlog2("nepostojeca zadaca", $edit_zadaca);
                return 0;
            }
            if (mysql_result($q86, 0, 0) != $predmet || mysql_result($q86, 0, 1) != $ag) {
                niceerror("Zadaća nije sa izabranog predmeta");
                zamgerlog("brisanje zadace: zadaca {$edit_zadaca} nije sa predmeta pp{$predmet}", 3);
                zamgerlog2("id zadace i predmeta se ne poklapaju", $edit_zadaca, $predmet, $ag);
                return 0;
            }
            if ($_POST['potvrdabrisanja'] == " Briši ") {
                // Brišemo srodne testove
                $q84 = myquery("delete from autotest_replace where zadaca={$edit_zadaca}");
                $q85 = myquery("delete from autotest_rezultat where autotest in (select id from autotest where zadaca={$edit_zadaca})");
                $q86 = myquery("delete from autotest where zadaca={$edit_zadaca}");
                // Brišemo zadaću
                $q87 = myquery("delete from zadatak where zadaca={$edit_zadaca}");
                $q88 = myquery("delete from zadaca where id={$edit_zadaca}");
                zamgerlog("obrisana zadaca {$edit_zadaca} sa predmeta pp{$predmet}", 4);
                zamgerlog2("obrisana zadaca", $edit_zadaca);
                nicemessage("Zadaća uspješno obrisana");
                ?>
			<script language="JavaScript">
			location.href='?sta=nastavnik/zadace&predmet=<?php 
                echo $predmet;
                ?>
&ag=<?php 
                echo $ag;
                ?>
';
			</script>
			<?php 
                return;
            } else {
                $q96 = myquery("select count(*) from zadatak where zadaca={$edit_zadaca}");
                $broj_zadataka = mysql_result($q96, 0, 0);
                $q97 = myquery("select count(*) from autotest where zadaca={$edit_zadaca}");
                $broj_testova = mysql_result($q97, 0, 0);
                print genform("POST");
                ?>
			Brisanjem zadaće obrisaćete i sve do sada unesene ocjene i poslane zadatke! Da li ste sigurni da to želite?<br>
			U pitanju je <b><?php 
                echo $broj_zadataka;
                ?>
</b> jedinstvenih slogova u bazi!<br><br>
			<?php 
                if ($broj_testova > 0) {
                    ?>
				Također ćete obrisati i <b><?php 
                    echo $broj_testova;
                    ?>
</b> testova.<br><br>
				<?php 
                }
                ?>
			<input type="submit" name="potvrdabrisanja" value=" Briši ">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" name="potvrdabrisanja" value=" Nazad ">
			<?php 
                return;
            }
        }
        // Kreiranje ili izmjena zadaće
        $naziv = trim(my_escape($_POST['naziv']));
        $zadataka = intval($_POST['zadataka']);
        $bodova = floatval(str_replace(",", ".", $_POST['bodova']));
        $dan = intval($_POST['day']);
        $mjesec = intval($_POST['month']);
        $godina = intval($_POST['year']);
        $sat = intval($_POST['sat']);
        $minuta = intval($_POST['minuta']);
        $sekunda = intval($_POST['sekunda']);
        if ($_POST['aktivna']) {
            $aktivna = 1;
        } else {
            $aktivna = 0;
        }
        if ($_POST['attachment']) {
            $attachment = 1;
        } else {
            $attachment = 0;
        }
        $programskijezik = intval($_POST['_lv_column_programskijezik']);
        if ($_POST['automatsko_testiranje']) {
            $automatsko_testiranje = 1;
        } else {
            $automatsko_testiranje = 0;
        }
        $postavka_file = $_FILES['postavka_zadace_file']['name'];
        if ($postavka_file != "") {
            if (!file_exists("{$conf_files_path}/zadace/{$predmet}-{$ag}/postavke")) {
                mkdir("{$conf_files_path}/zadace/{$predmet}-{$ag}/postavke", 0755, true);
            }
            copy($_FILES['postavka_zadace_file']['tmp_name'], "{$conf_files_path}/zadace/{$predmet}-{$ag}/postavke/{$postavka_file}");
            $sql_add_postavka_file = ", postavka_zadace = '{$postavka_file}'";
        } else {
            $sql_add_postavka_file = "";
        }
        if (intval($_POST['attachment']) == 1 && isset($_POST['dozvoljene_eks'])) {
            $ekstenzije = array_unique($_POST['dozvoljene_eks']);
            $dozvoljene_ekstenzije_selected = implode(',', $ekstenzije);
        } else {
            $dozvoljene_ekstenzije_selected = null;
        }
        // Provjera ispravnosti
        if (!preg_match("/\\w/", $naziv)) {
            niceerror("Naziv zadaće nije dobar.");
            return 0;
        }
        if ($zadataka <= 0 || $bodova < 0 || $zadataka > 100 || $bodova > 100) {
            niceerror("Broj zadataka ili broj bodova nije dobar");
            return 0;
        }
        if (!checkdate($mjesec, $dan, $godina)) {
            niceerror("Odabrani datum je nemoguć");
            return 0;
        }
        if ($sat < 0 || $sat > 24 || $minuta < 0 || $minuta > 60 || $sekunda < 0 || $sekunda > 60) {
            niceerror("Vrijeme nije dobro");
            return 0;
        }
        $mysqlvrijeme = time2mysql(mktime($sat, $minuta, $sekunda, $mjesec, $dan, $godina));
        // Provjera duplog imena zadace
        $q90 = myquery("select count(*) from zadaca where naziv like '{$naziv}' and predmet={$predmet} and akademska_godina={$ag} and id!={$edit_zadaca}");
        if (mysql_result($q90, 0, 0) > 0) {
            niceerror("Zadaća pod imenom '{$naziv}' već postoji! Izaberite neko drugo ime.");
            zamgerlog("zadaca sa nazivom '{$naziv}' vec postoji", 3);
            return 0;
        }
        // Kreiranje nove
        if ($edit_zadaca == 0) {
            // $komponenta_za_zadace određena na početku fajla
            $q92 = myquery("insert into zadaca set predmet={$predmet}, akademska_godina={$ag}, naziv='{$naziv}', zadataka={$zadataka}, bodova={$bodova}, rok='{$mysqlvrijeme}', aktivna={$aktivna}, attachment={$attachment}, programskijezik={$programskijezik}, automatsko_testiranje={$automatsko_testiranje}, dozvoljene_ekstenzije = '{$dozvoljene_ekstenzije_selected}', komponenta={$komponenta_za_zadace} {$sql_add_postavka_file}");
            $edit_zadaca = mysql_insert_id();
            if ($edit_zadaca == 0) {
                niceerror("Dodavanje zadaće nije uspjelo");
                zamgerlog("dodavanje zadace nije uspjelo pp{$predmet}, naziv '{$naziv}'", 3);
                zamgerlog2("dodavanje zadace nije uspjelo", $predmet, $zadataka, $bodova, $naziv);
            } else {
                nicemessage("Kreirana nova zadaća '{$naziv}'");
                zamgerlog("kreirana nova zadaca z{$edit_zadaca}", 2);
                zamgerlog2("kreirana nova zadaca", $edit_zadaca);
            }
            // Izmjena postojece zadace
        } else {
            // Ako se smanjuje broj zadataka, moraju se obrisati bodovi
            $q94 = myquery("select zadataka, komponenta from zadaca where id={$edit_zadaca}");
            $oldzadataka = mysql_result($q94, 0, 0);
            if ($zadataka < $oldzadataka) {
                // Prilikom brisanja svakog zadatka updatujemo komponentu studenta
                $komponenta = mysql_result($q94, 0, 1);
                $q96 = myquery("select id,student from zadatak where zadaca={$edit_zadaca} and redni_broj>{$zadataka} and redni_broj<={$oldzadataka} order by student");
                $oldstudent = 0;
                while ($r96 = mysql_fetch_row($q96)) {
                    $q97 = myquery("delete from zadatak where id={$r96['0']}");
                    if ($oldstudent != 0 && $oldstudent != $r96[1]) {
                        update_komponente($oldstudent, $predmet, $komponenta);
                    }
                    $oldstudent = $r96[1];
                }
                if ($oldstudent != 0) {
                    // log samo ako je bilo nesto
                    zamgerlog("Smanjen broj zadataka u zadaci z{$edit_zadaca}", 4);
                    zamgerlog2("smanjen broj zadataka u zadaci", $edit_zadaca);
                }
                // Brišemo i relevantne testove
                $q84 = myquery("delete from autotest_replace where zadaca={$edit_zadaca} and zadatak>{$zadataka}");
                $q85 = myquery("delete from autotest_rezultat where autotest in (select id from autotest where zadaca={$edit_zadaca} and zadatak>{$zadataka})");
                $q86 = myquery("delete from autotest where zadaca={$edit_zadaca} and zadatak>{$zadataka}");
            }
            $q94 = myquery("update zadaca set naziv='{$naziv}', zadataka={$zadataka}, bodova={$bodova}, rok='{$mysqlvrijeme}', aktivna={$aktivna}, attachment={$attachment}, programskijezik={$programskijezik}, automatsko_testiranje={$automatsko_testiranje}, dozvoljene_ekstenzije='{$dozvoljene_ekstenzije_selected}' {$sql_add_postavka_file} where id={$edit_zadaca}");
            nicemessage("Ažurirana zadaća '{$naziv}'");
            zamgerlog("azurirana zadaca z{$edit_zadaca}", 2);
            zamgerlog2("azurirana zadaca", $edit_zadaca);
        }
    }
    // Akcija: AUTOTESTOVI
    if ($_REQUEST['akcija'] == "autotestovi") {
        $zadaca = intval($_REQUEST['zadaca']);
        $backLink = "?sta=nastavnik/zadace&amp;predmet={$predmet}&amp;ag={$ag}";
        $linkPrefix = "{$backLink}&amp;zadaca={$zadaca}&amp;akcija=autotestovi";
        $backLink = "<a href=\"?{$backLink}&amp;_lv_nav_id={$zadaca}\">Nazad na popis zadaća</a>";
        // Provjera spoofinga zadaće
        $q10 = myquery("SELECT COUNT(*) FROM zadaca WHERE id={$zadaca} AND predmet={$predmet} AND akademska_godina={$ag}");
        if (mysql_result($q10, 0, 0) == 0) {
            nicemessage("Nepoznat ID zadaće {$zadaca}.");
            return;
        }
        autotest_admin($zadaca, $linkPrefix, $backLink);
        return;
    }
    // Spisak postojećih zadaća
    $_lv_["where:predmet"] = $predmet;
    $_lv_["where:akademska_godina"] = $ag;
    $_lv_["where:komponenta"] = $komponenta_za_zadace;
    // određena na početku fajla
    print "Postojeće zadaće:<br/>\n";
    print db_list("zadaca");
    // Kreiranje nove zadace ili izmjena postojeće
    $izabrana = intval($_REQUEST['_lv_nav_id']);
    if ($izabrana == 0) {
        $izabrana = intval($edit_zadaca);
    }
    if ($izabrana == 0) {
        ?>
<p><hr/></p>
	<p><b>Kreiranje zadaće</b><br/>
	<?php 
        $znaziv = $zaktivna = $zattachment = $zjezik = "";
        $zzadataka = 0;
        $zbodova = 0;
        $tmpvrijeme = time();
    } else {
        ?>
<p><hr/></p>
	<p><b>Izmjena zadaće</b></p>
	<?php 
        $q100 = myquery("select predmet, akademska_godina, naziv, zadataka, bodova, rok, aktivna, programskijezik, attachment, dozvoljene_ekstenzije, postavka_zadace, automatsko_testiranje from zadaca where id={$izabrana}");
        if ($predmet != mysql_result($q100, 0, 0) || $ag != mysql_result($q100, 0, 1)) {
            niceerror("Zadaća ne pripada vašem predmetu");
            zamgerlog("zadaca {$izabrana} ne pripada predmetu pp{$predmet}", 3);
            zamgerlog2("id zadace i predmeta se ne poklapaju", $izabrana, $predmet, $ag);
            return;
        }
        $znaziv = mysql_result($q100, 0, 2);
        $zzadataka = intval(mysql_result($q100, 0, 3));
        $zbodova = floatval(mysql_result($q100, 0, 4));
        $tmpvrijeme = mysql2time(mysql_result($q100, 0, 5));
        if (mysql_result($q100, 0, 6) == 1) {
            $zaktivna = "CHECKED";
        } else {
            $zaktivna = "";
        }
        $zjezik = mysql_result($q100, 0, 7);
        if (mysql_result($q100, 0, 8) == 1) {
            $zattachment = "CHECKED";
        } else {
            $zattachment = "";
        }
        $dozvoljene_ekstenzije_selected = mysql_result($q100, 0, 9);
        $postavka_zadace = mysql_result($q100, 0, 10);
        $automatsko_testiranje = mysql_result($q100, 0, 11);
    }
    $zdan = date('d', $tmpvrijeme);
    $zmjesec = date('m', $tmpvrijeme);
    $zgodina = date('Y', $tmpvrijeme);
    $zsat = date('H', $tmpvrijeme);
    $zminuta = date('i', $tmpvrijeme);
    $zsekunda = date('s', $tmpvrijeme);
    // JavaScript za provjeru validnosti forme
    ?>
<script language="JavaScript">
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;0
   
}

function provjera() {
//	var forma=document.getElementById("kreiranje_zadace");
	var naziv=document.getElementById("naziv");
	if (parseInt(naziv.value.length)<1) {
		alert("Niste unijeli naziv");
		naziv.style.border=1;
		naziv.style.backgroundColor="#FF9999";
		naziv.focus();
		return false;
	}
	var zadataka=document.getElementById("zadataka");
	if (!IsNumeric(zadataka.value)) {
		alert("Neispravan broj zadataka!");
		zadataka.style.border=1;
		zadataka.style.backgroundColor="#FF9999";
		zadataka.focus();
		return false;
	}
	if (parseInt(zadataka.value)<=0) {
		alert("Broj zadataka u zadaći mora biti veći od nule, npr. 1");
		zadataka.style.border=1;
		zadataka.style.backgroundColor="#FF9999";
		zadataka.focus();
		return false;
	}
	var bodova=document.getElementById("bodova");
	if (!IsNumeric(bodova.value)) {
		alert("Neispravan broj bodova!");
		bodova.style.border=1;
		bodova.style.backgroundColor="#FF9999";
		bodova.focus();
		return false;
	}
	if (parseFloat(bodova.value)<0) {
		alert("Broj bodova koje nosi zadaća mora biti veći ili jednak nuli, npr. 2 boda");
		bodova.style.border=1;
		bodova.style.backgroundColor="#FF9999";
		bodova.focus();
		return false;
	}
	
	return true;
}

function onemoguci_ekstenzije(chk) {
	var attachment = document.getElementById("attachment");
	var dozvoljene_ekstenzije = document.getElementById("dozvoljene_ekstenzije");
	var jezik = document.getElementById("_lv_column_programskijezik");

	if (attachment.checked) {
		dozvoljene_ekstenzije.style.display = '';
	} else {
		dozvoljene_ekstenzije.style.display = 'none';
		for (i = 0; i < chk.length; i++) chk[i].checked = false;
	}
}
</script>
<?php 
    // Forma za kreiranje zadaće
    unset($_REQUEST['aktivna']);
    unset($_REQUEST['attachment']);
    unset($_REQUEST['automatsko_testiranje']);
    print genform("POST", "kreiranje_zadace\" enctype=\"multipart/form-data\" onsubmit=\"return provjera();");
    ?>
<input type="hidden" name="akcija" value="edit">
<input type="hidden" name="zadaca" value="<?php 
    echo $izabrana;
    ?>
">
Naziv: <input type="text" name="naziv" id="naziv" size="30" value="<?php 
    echo $znaziv;
    ?>
"><br><br>

Broj zadataka: <input type="text" name="zadataka" id="zadataka" size="4" value="<?php 
    echo $zzadataka;
    ?>
">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Max. broj bodova: <input type="text" name="bodova" id="bodova" size="3" value="<?php 
    echo $zbodova;
    ?>
"><br><br>

Rok za slanje: <?php 
    echo datectrl($zdan, $zmjesec, $zgodina);
    ?>
&nbsp;&nbsp; <input type="text" name="sat" size="1" value="<?php 
    echo $zsat;
    ?>
"> <b>:</b> <input type="text" name="minuta" size="1" value="<?php 
    echo $zminuta;
    ?>
"> <b>:</b> <input type="text" name="sekunda" size="1" value="<?php 
    echo $zsekunda;
    ?>
"> <br><br>

<input type="checkbox" name="aktivna" <?php 
    echo $zaktivna;
    ?>
> Aktivna
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" value="1" id="attachment" onclick="onemoguci_ekstenzije(this.form.dozvoljene_eks)" name="attachment" <?php 
    echo $zattachment;
    ?>
> Slanje zadatka u formi attachmenta<br><br>

<span id="dozvoljene_ekstenzije" style="display:none" title="Oznacite željene ekstenzije">
Dozvoljene ekstenzije (Napomena: Ukoliko ne odaberete nijednu ekstenziju sve ekstenzije postaju dozvoljene): 
<?php 
    $dozvoljene_ekstenzije_selected = explode(',', $dozvoljene_ekstenzije_selected);
    foreach ($dozvoljene_ekstenzije as $doz_ext) {
        ?>
<input type="checkbox" name="dozvoljene_eks[]" <?php 
        if (in_array($doz_ext, $dozvoljene_ekstenzije_selected)) {
            echo 'checked="checked"';
        }
        ?>
 value="<?php 
        echo $doz_ext;
        ?>
" /> <?php 
        echo $doz_ext;
    }
    ?>
<br><br>
</span>

Programski jezik: <?php 
    echo db_dropdown("programskijezik", $zjezik);
    ?>
<br><br>

<?php 
    if ($zjezik != 0) {
        // Ako nije definisan programski jezik, nećemo ni nuditi automatsko testiranje... ?
        if ($automatsko_testiranje == 1) {
            $add_testiranje = "CHECKED";
        } else {
            $add_testiranje = "";
        }
        ?>
	<input type="checkbox" name="automatsko_testiranje" <?php 
        echo $add_testiranje;
        ?>
> Automatsko testiranje<br>
	<a href="?sta=nastavnik/zadace&predmet=<?php 
        echo $predmet;
        ?>
&ag=<?php 
        echo $ag;
        ?>
&zadaca=<?php 
        echo $izabrana;
        ?>
&akcija=autotestovi">Kliknite ovdje da definišete testove</a><br><br>
	<?php 
    }
    ?>

Postavka zadaće: 
<?php 
    if ($postavka_zadace == "") {
        ?>
<input type="file" name="postavka_zadace_file" size="45"><?php 
    } else {
        ?>
<a href="?sta=common/attachment&zadaca=<?php 
        echo $izabrana;
        ?>
&tip=postavka"><img src="images/16x16/preuzmi.png" width="16" height="16" border="0"> <?php 
        echo $postavka_zadace;
        ?>
</a>
	<input type="submit" name="dugmeobrisi" value="Obriši">
	<?php 
    }
    ?>
<br><br>

<input type="submit" value=" Pošalji "> <input type="reset" value=" Poništi ">
<?php 
    if ($izabrana > 0) {
        ?>
<input type="submit" name="brisanje" value=" Obriši "><?php 
    }
    echo "<script> onemoguci_ekstenzije('');</script>";
    ?>
</form>
<?php 
    /*
    $_lv_["label:programskijezik"] = "Programski jezik";
    $_lv_["label:zadataka"] = "Broj zadataka";
    $_lv_["label:bodova"] = "Max. broj bodova";
    $_lv_["label:attachment"] = "Slanje zadatka u formi attachmenta";
    $_lv_["label:rok"] = "Rok za slanje";
    $_lv_["hidden:vrijemeobjave"] = 1;
    print db_form("zadaca");*/
    // Formular za masovni unos zadaća
    $format = intval($_POST['format']);
    if (!$_POST['format']) {
        $q110 = myquery("select vrijednost from preference where korisnik={$userid} and preferenca='mass-input-format'");
        if (mysql_num_rows($q110) > 0) {
            $format = mysql_result($q110, 0, 0);
        } else {
            //default vrijednost
            $format = 0;
        }
    }
    $separator = intval($_POST['separator']);
    if (!$_POST['separator']) {
        $q120 = myquery("select vrijednost from preference where korisnik={$userid} and preferenca='mass-input-separator'");
        if (mysql_num_rows($q120) > 0) {
            $separator = mysql_result($q120, 0, 0);
        } else {
            //default vrijednost
            $separator = 0;
        }
    }
    $q130 = myquery("select count(*) from zadaca where predmet={$predmet} and akademska_godina={$ag}");
    if (mysql_result($q130, 0, 0) > 0) {
        ?>
<p><hr/></p>
<p><b>Masovni unos zadaća</b><br/>
<?php 
        print genform("POST");
        if (strlen($_POST['nazad']) > 1) {
            $izabrana = $_POST['_lv_column_zadaca'];
        } else {
            $izabrana = -1;
        }
        ?>
<input type="hidden" name="fakatradi" value="0">
<input type="hidden" name="akcija" value="massinput">
<input type="hidden" name="nazad" value="">
<input type="hidden" name="brpodataka" value="1">
<input type="hidden" name="duplikati" value="0">

Izaberite zadaću: <?php 
        echo db_dropdown("zadaca", $izabrana);
        ?>
Izaberite zadatak: <select name="zadatak"><?php 
        $q112 = myquery("select zadataka from zadaca where predmet={$predmet} and akademska_godina={$ag} order by zadataka desc limit 1");
        for ($i = 1; $i <= mysql_result($q112, 0, 0); $i++) {
            print "<option value=\"{$i}\">{$i}</option>\n";
        }
        ?>
</select><br/><br/>

<textarea name="massinput" cols="50" rows="10"><?php 
        if (strlen($_POST['nazad']) > 1) {
            print $_POST['massinput'];
        }
        ?>
</textarea><br/>
<br/>Format imena i prezimena: <select name="format" class="default">
<option value="0" <?php 
        if ($format == 0) {
            print "SELECTED";
        }
        ?>
>Prezime[TAB]Ime</option>
<option value="1" <?php 
        if ($format == 1) {
            print "SELECTED";
        }
        ?>
>Ime[TAB]Prezime</option>
<option value="2" <?php 
        if ($format == 2) {
            print "SELECTED";
        }
        ?>
>Prezime Ime</option>
<option value="3" <?php 
        if ($format == 3) {
            print "SELECTED";
        }
        ?>
>Ime Prezime</option></select>&nbsp;
Separator: <select name="separator" class="default">
<option value="0" <?php 
        if ($separator == 0) {
            print "SELECTED";
        }
        ?>
>Tab</option>
<option value="1" <?php 
        if ($separator == 1) {
            print "SELECTED";
        }
        ?>
>Zarez</option></select><br/><br/>
<input type="submit" value="  Dodaj  ">
</form></p>
<?php 
    } else {
        ?>
<p><hr/></p>
	<p><b>Masovni unos zadaća NIJE MOGUĆ</b><br/>
	Najprije kreirajte zadaću koristeći formular iznad</p>
	<?php 
    }
    /*
    // IMPORT ZADAĆA IZ MOODLA
    
    //Prikupljanje id-a moodle predmeta iz zamger baze radi poredjenja
    $q200 = myquery("SELECT moodle_id FROM moodle_predmet_id WHERE predmet='$predmet'");
    
    if ($conf_moodle && mysql_num_rows($q200)>0) {
    
    $id_predmeta_value = mysql_result($q200,0,0);
    
    
    // Ima li zadaća u Moodlu?
    
    $moodle_con = $__lv_connection;
    if (!$conf_moodle_reuse_connection) {
    	// Pravimo novu konekciju za moodle, kod iz dbconnect2() u libvedran
    	if (!($moodle_con = mysql_connect($conf_moodle_dbhost, $conf_moodle_dbuser, $conf_moodle_dbpass))) {
    		biguglyerror(mysql_error());
    		exit;
    	}
    	if (!mysql_select_db($conf_moodle_db, $moodle_con)) {
    		biguglyerror(mysql_error());
    		exit;
    	}
    	if ($conf_use_mysql_utf8) {
    		mysql_set_charset("utf8",$moodle_con);
    	}
    }
    $q300 = mysql_query("SELECT itemname
    	FROM $conf_moodle_db.$conf_moodle_prefix"."grade_items
    	WHERE itemmodule='assignment' AND itemtype='mod'", $moodle_con) or die ("Greska u upitu 300: " .mysql_error());
    
    
    // Ako nema, ne ispisujemo ništa
    if (mysql_num_rows($q300)<1) 
    	return;
    
    $za_value = mysql_fetch_array($q300);
    
    
    
    print genform("POST");
    ?>
    <p><hr/></p>
    <h4>Import svih zadaća iz Moodle-a</h4>
    <p>Klikom na import importuju se sve zadaće za sve studente</p>
    <p><br/><b>Napomena:</b> Sve zadaće moraju imati ista imena kao u Moodle-u!</p>
    <input type="hidden" name="akcija" value="import_svih">
    
    <?
    
    //Import svih zadaca
    if ($_POST['akcija'] == "import_svih" && check_csrf_token()) {
    	//Prikupljanje imena zadaca iz Zamger baze
    	$q210 = myquery("SELECT naziv
    		FROM zadaca
    		WHERE predmet='$predmet' AND akademska_godina='$ag'");
    	if (mysql_num_rows($q210)<1) {
    		niceerror("Nema zadaća u zamgeru");
    		zamgerlog("predmet pp$predmet ne sadrzi niti jednu zadacu u zamgeru",3);
    		return;
    	}
    
    	while ($r210 = mysql_fetch_array($q210)) {
    		//Prikupljanje podataka iz Moodle tabele
    		//Prikupljaju se id predmeta, ime zadace i JMBG svih studenata
    		//Posto se pri prikupljanju zadace porede po imenu trebaju imati isti naziv u Moodle-u kao i u Zamgeru
    		$q220 = mysql_query("SELECT c.id, gi.itemname, u.firstname, u.lastname
    			FROM $conf_moodle_db.$conf_moodle_prefix"."grade_grades gg, $conf_moodle_db.$conf_moodle_prefix"."user u, $conf_moodle_db.$conf_moodle_prefix"."grade_items gi, $conf_moodle_db.$conf_moodle_prefix"."course c
    			WHERE gi.itemname = '$r210[0]' AND c.id = '$id_predmeta_value' AND
    			gg.userid=u.id AND gg.itemid=gi.id AND gi.courseid=c.id", $moodle_con) or die ("Greska u upitu 220: " .mysql_error());
    		if (mysql_num_rows($q220)<1) {
    			niceerror("Nema podataka u Moodle-u");
    			zamgerlog("Nema podataka u Moodle-u za zadacu $r210[0]",3);
    			return;
    		}
    		//Ubacivanje podataka u zamger tabelu
    		while ($r220 = mysql_fetch_array($q220)) {
    			//$bodovi sadrzi vrijednost zadace iz $row1 za date vrijednosti (trenutni student, trenutna zadaca i trenutni predmet)
    			$q230 = mysql_query("SELECT gg.finalgrade
    				FROM $conf_moodle_db.$conf_moodle_prefix"."grade_grades gg, $conf_moodle_db.$conf_moodle_prefix"."user u, $conf_moodle_db.$conf_moodle_prefix"."grade_items gi, $conf_moodle_db.$conf_moodle_prefix"."course c
    				WHERE gi.itemname='$r220[1]' AND c.id='$r220[0]' AND u.firstname='$r220[2]' AND u.lastname='$r220[3]' AND
    				gg.userid=u.id AND gg.itemid=gi.id AND gi.courseid=c.id", $moodle_con) or die ("Greska u upitu 230: " .mysql_error());
    			if (mysql_num_rows($q230)<1) {
    				niceerror("Zadaća nema bodova u Moodle-u");
    				zamgerlog("Zadaca: $r210[0] nema bodova",3);
    				return;
    			}
    			$bodovi_value = mysql_fetch_array($q230);
    		
    			//zadaca_id sadrzi id zadace trenutne vrijednosti u $row1
    			$q240 = myquery("SELECT z.id
    				FROM zadaca z, moodle_predmet_id p
    				WHERE z.naziv='$r220[1]' AND p.moodle_id='$r220[0]' AND p.predmet=z.predmet");
    			if (mysql_num_rows($q240)<1) {
    				niceerror("Nema zadaća u zamgeru");
    				zamgerlog("Predmet $predmet ne sadrzi niti jednu zadacu u zamgeru",3);
    				return;
    			}
    			$zadaca_id_value = mysql_fetch_array($q240);
    		
    			//$student_id vraca id studenta koji se trenutno cita iz $row1
    			$q250 = myquery("SELECT id
    				FROM osoba
    				WHERE ime='$r220[2]' AND prezime='$r220[3]'");
    			if (mysql_num_rows($q250)<1) {
    				niceerror("Student ne postoji zamgeru");
    				zamgerlog("Student $r220[2] $r220[3] ne postoji u zamgeru",3);
    				return;
    			}
    			$student_id_value = mysql_fetch_array($q250);
    		
    			$q260 = "INSERT INTO zadatak (zadaca, redni_broj, student, status, bodova, vrijeme, userid)
    				VALUES ('$zadaca_id_value[0]', '1', '$student_id_value[0]', '5', '$bodovi_value[0]', 'SYSDATE()', '$userid')";
    		
    			myquery($q260);
    			//upit za dobijanje komponente za zadace
    			$q270 = myquery ("SELECT komponenta FROM zadaca WHERE id=$zadaca_id_value[0]");
    			if (mysql_num_rows($q270)<1) {
    				niceerror("Nema komponente");
    				zamgerlog("Nema komponenti u zamgeru",3);
    				return;
    			}
    			$komponenta_value = mysql_fetch_array($q270);
    			// Treba nam ponudakursa za update komponente
    			$q280 = myquery("SELECT sp.predmet
    				FROM student_predmet as sp, ponudakursa as pk
    				WHERE sp.student='$student_id_value[0]' and sp.predmet=pk.id and pk.predmet=$predmet and pk.akademska_godina='$ag'");
    			$pk_value = mysql_result($q280,0,0);
    			update_komponente($student_id_value[0],$pk_value,$komponenta_value[0]);
    		}
    	}
    
    	nicemessage("Import uspješan");
    	zamgerlog("zadace su importovane iz Moodle-a", 2);
    }
    ?>
    <table>
    <tr>
    	<td><input type="submit" name="sve_zadace" value="Import"><br/></td>
    </tr>
    </table>
    </form>
    
    <?
    
    
    // Import pojedinačnih zadaća iz Moodla
    
    print genform("POST");
    ?>
    <h4></br>Import zadaća iz Moodle-a sa advanced upload-a</h4>
    <input type="hidden" name="akcija" value="import_selected">
    <input type="hidden" name="moodle_zadace" value="<?=$za_value?>">
    
    <?
    if ($_POST['akcija'] == "import_selected" && check_csrf_token()) {
    	$q310 = mysql_query("SELECT u.firstname, u.lastname, gi.itemname, gi.grademax
    		FROM $conf_moodle_db.$conf_moodle_prefix"."grade_grades gg, $conf_moodle_db.$conf_moodle_prefix"."user u, $conf_moodle_db.$conf_moodle_prefix"."grade_items gi, $conf_moodle_db.$conf_moodle_prefix"."course c
    		WHERE gi.itemmodule='assignment' AND gi.itemtype='mod' AND c.id = '$id_predmeta_value' AND
    		gg.userid=u.id AND gg.itemid=gi.id AND gi.courseid=c.id", $moodle_con) or die ("Greska u upitu 310: " .mysql_error());
    	while ($r310 = mysql_fetch_array($q310)) {
    		
    		$q320 = mysql_query("SELECT gg.finalgrade
    			FROM $conf_moodle_db.$conf_moodle_prefix"."grade_grades gg, $conf_moodle_db.$conf_moodle_prefix"."user u, $conf_moodle_db.$conf_moodle_prefix"."grade_items gi, $conf_moodle_db.$conf_moodle_prefix"."course c
    			WHERE gi.itemmodule='assignment' AND c.id='$id_predmeta_value' AND u.firstname='$r310[0]' AND u.lastname='$r310[1]' AND
    			gg.userid=u.id AND gg.itemid=gi.id AND gi.courseid=c.id", $moodle_con) or die ("Greska u upitu 320: " .mysql_error());
    		if (mysql_num_rows($q320)<1) {
    			niceerror("Zadaća nema bodova u Moodle-u");
    			zamgerlog("Zadaca: $r310[2] nema bodova",3);
    			return;
    		}
    		$bodovi_value = mysql_fetch_array($q320);
    		
    		$q330 = myquery ("SELECT id FROM komponenta WHERE naziv='Zadace (ETF BSc)'");
    		if (mysql_num_rows($q330)<1) {
    			niceerror("Nema komponente");
    			zamgerlog("Nema komponenti u zamgeru",3);
    			return;
    		}
    		$komponenta_value = mysql_fetch_array($q330);
    		
    		$q340 = myquery("SELECT z.id
    			FROM zadaca z, moodle_predmet_id p
    			WHERE z.naziv='$za_value' AND p.moodle_id='$id_predmeta_value' AND p.predmet=z.predmet");
    		if (mysql_num_rows($q340)<1) {
    			$q350 = myquery ("INSERT INTO zadaca (naziv, predmet, akademska_godina, zadataka, bodova, rok, aktivna, programskijezik, attachment, komponenta, vrijemeobjave)
    				VALUES ('$row1[2]', '$predmet', '$ag', 1, '$r310[3]', 'SYSDATE()', 1, 0, 0, '$komponenta_value[0]', 'SYSDATE()')");
    			nicemessage("Kreirana nova zadaća '$naziv'");
    			zamgerlog("kreirana nova zadaca z$edit_zadaca prilikom importa iz Moodla", 2);
    
    			$q340 = myquery("SELECT z.id
    				FROM zadaca z, moodle_predmet_id p
    				WHERE z.naziv='$za_value' AND p.moodle_id='$id_predmeta_value' AND p.predmet=z.predmet");
    		}
    		$zadaca_id_value = mysql_fetch_array($q340);
    	
    		$q360 = myquery("SELECT id
    			FROM osoba
    			WHERE ime='$row1[0]' AND prezime='$row1[1]'");
    		if (mysql_num_rows($q360)<1) {
    			niceerror("Student ne postoji zamgeru");
    			zamgerlog("Student $row1[2] $row1[3] ne postoji u zamgeru",3);
    			return;
    		}
    		$student_id_value = mysql_fetch_array($q360);
    		
    		$q370 = "INSERT INTO zadatak (zadaca, redni_broj, student, status, bodova, vrijeme, userid)
    			VALUES ('$zadaca_id_value[0]', '1', '$student_id_value[0]', '5', '$bodovi_value[0]', 'SYSDATE()', '$userid')";
    	
    		myquery($q370);
    			
    			
    		$q380 = myquery("SELECT sp.predmet
    			FROM student_predmet as sp, ponudakursa as pk
    			WHERE sp.student='$student_id_value[0]' and sp.predmet=pk.id and pk.predmet=$predmet and pk.akademska_godina='$ag'");
    		$pk_value = mysql_result($q380,0,0);
    		update_komponente($student_id_value[0],$pk_value,$komponenta_value[0]);
    	}
    	nicemessage("Import uspješan");
    	zamgerlog("Zadace su importovane iz Moodle-a", 2);
    }
    ?>
    <table>
    <tr>
    	<td>Izaberite zadaću: <select name="moodle_zadaca"><?
    foreach ($za_value as $zaneki) {
    	print "<option value=\"$zaneki\">$zaneki</option>\n";
    }
    ?>
    </select></td></tr>
    <tr>
    	<td><input type="submit" name="advanced_zadace" value="Import"><br/></td>
    </tr>
    </table>
    </form>
    
    <?
    
    
    // Diskonektujemo moodle
    if (!$conf_moodle_reuse_connection) {
    	mysql_close($moodle_con);
    }
    
    
    }*/
}