Example #1
0
function displayTranslation($id, $src)
{
    global $doc, $table;
    $src = e($src);
    $res = "\r\n        <div id='view'>\r\n        <div class='text'>{$src}</div>\r\n        <ol id='revisions'>";
    $qq = "\r\n        select t1.translation as translation, t1.revision as revision, t1.revert_to as revert_to, t1.comment as comment, t1.user_id as user_id, if(t1.user_id = 0, ip.id, u1.name) as name, unix_timestamp(t1.date) as _date\r\n        from {$table['translation']} t1 left join {$table['ip_data']} ip on t1.user_ip = ip.ip left join {$table['user']} u1 on t1.user_id = u1.id\r\n        where t1.source_id = ? order by t1.id desc;\r\n    ";
    $q = query($qq, $id);
    $i = 0;
    while ($row = $q->fetch(MYSQL_ASSOC)) {
        ++$i;
        $name = constructName($row['user_id'], $row['name']);
        $comment = $row['comment'] ? "<div class='comment'>" . f($row[comment]) . '</div>' : "";
        if ($row['revert_to'] == -1) {
            $revtype = 'Deleted';
            $text = '';
        } else {
            $text = "<div class='text'>" . f($row['translation']) . "</div>";
            if ($row['revert_to'] != 0) {
                $revtype = "Reverted to revision <a href='#{$row['revert_to']}'>{$row['revert_to']}</a>";
            } else {
                $revtype = "Submitted";
            }
        }
        $date = formatDate($row['_date']);
        if ($i > 1 && $row['revert_to'] != -1) {
            $revert = "\r\n                <div style='display: inline'>\r\n                <button class='revert'>Revert to this</button>\r\n                <form class='revertform' method='post' action='submit.php'>\r\n                <div class='fields'>\r\n                <label>Why do you want to revert the translation?<br>\r\n                <textarea name='comment'></textarea>\r\n                </label><br>\r\n                </div>\r\n                <input type='submit' value='Revert translation' />\r\n                <input type='hidden' name='src_id' value='{$id}' />\r\n                <input type='hidden' name='revert_to' value='{$row['revision']}' />\r\n                <input type='hidden' name='from' value='site' />\r\n                </form> \r\n                </div> \r\n            ";
        } else {
            $revert = "";
        }
        $res .= "\r\n            <a name='{$row['revision']}'></a>\r\n            <li value='{$row['revision']}'>\r\n            {$revtype} by {$name} on {$date}. {$revert}\r\n            {$text}\r\n            {$comment}\r\n            </li>\r\n        ";
        if ($i == 1) {
            $res .= "</ol>" . constructSubmitForm($id) . "<ol id='revisions'>";
        }
    }
    $res .= "</ol>";
    if ($i == 0) {
        $res .= constructSubmitForm($id);
    }
    $res .= "</div>";
    $res .= "\r\n        <script>\r\n        function toggleRevertForm(ev)\r\n        {\r\n            \$(this).parent().find('form.revertform').toggle();\r\n        }\r\n        \r\n        \$(function()\r\n        {\r\n            \$('button.revert').click(toggleRevertForm);\r\n        });\r\n        </script>\r\n    ";
    $doc->content = $res;
}
Example #2
0
 public function namelink()
 {
     return constructName($this->id, $this->id ? $this->name : $this->aid);
 }
Example #3
0
function showLastSubmits()
{
    global $table, $search;
    $by = (int) get($_GET, 'by');
    $aby = (int) get($_GET, 'aby');
    $res = "";
    if ($search) {
        $head = "<h2>Search results</h2>";
    } else {
        if ($by || $aby) {
            $head = "<h2>User submissions</h2>";
        }
    }
    $res = "";
    $max_id = (int) queryGetString("select max(id) from {$table['translation']}");
    $skip = (int) get($_GET, 'skip');
    if ($skip < 0) {
        $skip = 0;
    }
    $perpage = (int) get($_GET, 'perpage');
    if ($perpage <= 0 || $perpage > 100) {
        $perpage = 20;
    }
    $to = $max_id - $skip;
    $from = $to - $perpage * 2;
    $qq = "select t1.id as id, t1.source_id as source_id, t2.source as source, t1.translation as translation, t1.revision as revision, t1.revert_to as revert_to, t1.comment as comment, t1.user_id as user_id, if(t1.user_id = 0, ip.id, u1.name) as name, unix_timestamp(t1.date) as _date\r\n           from {$table['translation']} t1 left join {$table['ip_data']} ip on t1.user_ip = ip.ip left join {$table['user']} u1 on t1.user_id = u1.id inner join {$table['source']} t2 on t1.source_id = t2.id";
    $num_rows = $max_id;
    if ($search) {
        $q = query("{$qq} where t2.source like ? order by t1.id desc limit {$perpage}", $search);
    } else {
        if ($by || $aby) {
            if ($aby) {
                $num_rows = (int) queryGetString("select count(*) from {$table['translation']} t1, {$table['ip_data']} ip where ip.id = ? and t1.user_id = 0 and t1.user_ip = ip.ip", $aby);
                $q = query("{$qq} where t1.user_id = 0 and ip.id = ? order by t1.id desc limit {$skip}, {$perpage}", $aby);
            } else {
                $num_rows = (int) queryGetString("select count(*) from {$table['translation']} where user_id = ?", $by);
                $q = query("{$qq} where t1.user_id = ? order by t1.id desc limit {$skip}, {$perpage}", $by);
            }
        } else {
            $q = query("{$qq} where t1.id > {$from} and t1.id <= {$to} order by t1.id desc limit {$perpage}");
            if ($q->num_rows < $perpage && $to - $perpage >= 0) {
                $q->free();
                $q = query("{$qq} where t1.id > {$from} order by t1.id desc limit {$perpage}");
            }
        }
    }
    if (!$search && $num_rows > 0) {
        $res .= "<p>Pages: ";
        $pages_num = (int) (($num_rows + $perpage - 1) / $perpage);
        $ct = 0;
        for ($i = 0; $i < $pages_num; ++$i) {
            $num = $i + 1;
            if ($skip >= $ct && $skip < $ct + $perpage) {
                $num = "<b>{$num}</b>";
            }
            $link = "<a href='index.php?{$qs}skip={$ct}&perpage={$perpage}'>{$num}</a>";
            $res .= $link . ' ';
            $ct += $perpage;
        }
        $res .= '</p>';
    }
    $res .= "<table id='submissions'>";
    $i = 0;
    while ($row = $q->fetch(MYSQL_ASSOC)) {
        $comment = "<span class='comment'>" . e($row['comment']) . "</span>";
        if ($row['revert_to']) {
            if ($row['revert_to'] == '-1') {
                $comment = "Deleted. {$comment}";
            } else {
                $comment = "Reverted to revision {$row['revert_to']}. {$comment}";
            }
        }
        $name = constructName($row['user_id'], $row['name']);
        $cl = $i++ % 2 ? 'c2' : 'c1';
        $res .= "<tr class='{$cl}'>";
        $res .= "<td><a href='index.php?p=view&id={$row['source_id']}'>" . e($row['source']) . "</a></td>";
        $res .= "<td>" . e($row['translation']) . "</td>";
        $res .= "<td>{$comment}</td>";
        $res .= "<td>{$name}</td>";
        $res .= "<td>{$row['revision']}</td>";
        $res .= "<td>" . formatDate($row['_date']) . "</td>";
        $res .= "</tr>";
    }
    $res .= "</table>";
    if (!$search) {
        if ($num_rows > 0) {
            $res .= "<p>Pages: ";
            $pages_num = (int) (($num_rows + $perpage - 1) / $perpage);
            $ct = 0;
            for ($i = 0; $i < $pages_num; ++$i) {
                $num = $i + 1;
                if ($skip >= $ct && $skip < $ct + $perpage) {
                    $num = "<b>{$num}</b>";
                }
                $link = "<a href='index.php?{$qs}skip={$ct}&perpage={$perpage}'>{$num}</a>";
                $res .= $link . ' ';
                $ct += $perpage;
            }
            $res .= '</p>';
        }
    } else {
        if ($q->num_rows == 0) {
            return $head . submitForm();
        }
    }
    return $head . $res;
}
Example #4
0
function getNameUniversal($row, $order, $hcard = null)
{
    global $text, $admtext, $tngconfig, $nonames;
    //$nonames = showNames($row);
    $lastname = trim($row['lnprefix'] . " " . $row['lastname']);
    if ($tngconfig['ucsurnames']) {
        $lastname = tng_strtoupper($lastname);
    }
    if ($hcard) {
        $lastname = "<span class=\"family-name\">" . $lastname . "</span>";
    }
    $title = $row['title'] && $row['title'] == $row['prefix'] ? $row['title'] : trim($row['title'] . " " . $row['prefix']);
    if (($row['allow_living'] || !$nonames) && ($row['allow_private'] || !$tngconfig['nnpriv'])) {
        $firstname = $hcard ? "<span class=\"given-name\">" . $row['firstname'] . "</span>" : $row['firstname'];
        $firstname = trim($title . " " . $firstname);
        $namestr = constructName($firstname, $lastname, $row['suffix'], $order);
    } elseif ($row['living'] && !$row['allow_living'] && $nonames == 1) {
        $namestr = $text['living'];
    } elseif ($row['private'] && !$row['allow_private'] && $tngconfig['nnpriv'] == 1) {
        $namestr = $admtext['text_private'];
    } else {
        //initials
        $firstname = $hcard ? "<span class=\"given-name\">" . initials($row['firstname']) . "</span>" : initials($row['firstname']);
        $firstname = trim($title . " " . $firstname);
        $namestr = constructName($firstname, $lastname, $row['suffix'], $order);
    }
    if ($hcard) {
        $namestr = "<span class=\"n\">{$namestr}</span>";
    }
    return $namestr;
}