예제 #1
0
파일: parser.php 프로젝트: bvy/cources
    }
    exit;
}
if ($fileType != 'text/plain') {
    echo 'Error: file is not a plain text';
    exit;
}
$upfile = __DIR__ . "\\upload\\" . $userFile;
if (is_uploaded_file($tmpFile)) {
    if (!move_uploaded_file($tmpFile, $upfile)) {
        echo 'File uploaded, but could not move to destination directory';
        exit;
    }
}
//call user function
$str = fileToString($upfile);
$arr = stringToArray($str);
usort($arr, "sortBySourceField");
echo "<table border=1>";
foreach ($arr as $key => $value) {
    foreach ($value as $key2 => $value2) {
        echo "<tr><td>{$key2}</td>";
        echo "<td>{$value2}</td>";
    }
}
echo "</table>";
//define user's functions
function fileToString($filePatch)
{
    $handle = fopen($filePatch, 'r');
    if (!$handle) {
예제 #2
0
function manageArticles()
{
    global $tbl_1d_article, $tbl_1d_pictures;
    global $SUBS, $PARAM, $MSG, $MONTHS, $MONTHS2;
    global $articleString, $articlePage, $articleCount, $articleWhere;
    //from session
    if ($PARAM['Delete'] == '1') {
        reset($PARAM);
        $Ar = '0';
        while (list($k, $v) = each($PARAM)) {
            if (ereg('^article_([0-9]+)$', $k, $R)) {
                $Ar .= ",{$R['1']}";
            }
        }
        if ($Ar == '0') {
            $SUBS['ERROR'] = $MSG[20008];
            $SUBS['ERROR'] = fileParse('_admin_error.htmlt');
        } else {
            //iztrij kartinki;
            $query = "SELECT\t{$tbl_1d_pictures}.ID,\n\t\t\t\t\t{$tbl_1d_pictures}.URL,\n\t\t\t\t\t{$tbl_1d_pictures}.RefType,\n\t\t\t\t\t\n\t\t\t\t\ta1.ID AS thumbID,\n\t\t\t\t\ta1.URL AS thumbURL\n\n\t\t\t\tFROM {$tbl_1d_article}\n\t\t\t\tLEFT JOIN {$tbl_1d_pictures}\n\t\t\t\t\tON (\t{$tbl_1d_pictures}.RefID = {$tbl_1d_article}.ID\n\t\t\t\t\t\tAND {$tbl_1d_pictures}.RefType = 'article'\n\t\t\t\t\t\t)\n\t\t\t\tLEFT JOIN {$tbl_1d_pictures} a1\n\t\t\t\t\tON a1.RefType = 'thumb'\n\t\t\t\t\t\tAND a1.RefID = {$tbl_1d_pictures}.ID\n\t\t\t\tWHERE {$tbl_1d_article}.ID IN ({$Ar})";
            $result = runQuery($query, 'manageArticles()', 'GET_PISTURES');
            $Pics = '0';
            while ($row = db_fetch_row($result)) {
                //del pic
                if (!@unlink(getAdmSetting('UPLOAD_DIR') . $row[1])) {
                    setLogAndStatus("Erasing", getAdmSetting('UPLOAD_DIR') . $row[1], 0, "manageArticles()", 'DEL_ARTICLES_PICS');
                }
                $Pics .= ",0{$row['0']}";
                //del thumb
                if (!@unlink(getAdmSetting('UPLOAD_DIR') . $row[4])) {
                    setLogAndStatus("Erasing", getAdmSetting('UPLOAD_DIR') . $row[4], 0, "manageArticles()", 'DEL_THUMB_PICS');
                }
                $Pics .= ",0{$row['3']}";
            }
            //iztriwane na kartinkite ot db
            $query = "DELETE FROM {$tbl_1d_pictures}\n\t\t\t\tWHERE ID IN ({$Pics}) ";
            $result = runQuery($query, 'manageArticles()', 'ERASE_PISTURES');
            //iztriwane na samiyat film
            $query = "DELETE FROM {$tbl_1d_article}\n\t\t\t\tWHERE ID IN ({$Ar}) ";
            $result = runQuery($query, 'manageArticles()', 'ERASE_ARTICLES');
            $SUBS['COMMAND'] = $PARAM['cmd'] . "&err=20093";
            printPage('_admin_done.htmlt');
            return;
        }
    }
    if ($PARAM['Add'] == 1) {
        //nowo zaglavie
        $PARAM['WHEN'] = 1 + strToTime($PARAM['Day1'] . ' ' . $MONTHS2[$PARAM['Month1']] . ' ' . $PARAM['Year1']);
        $query = "UPDATE {$tbl_1d_article} SET\n\t\t\t\tPriority = " . intval($PARAM['NO']) . ",\n\t\t\t\ttsWhen = " . dbQuote($PARAM['WHEN']) . ",\n\t\t\t\ttsLast = " . time() . "\n\t\t\t\tWHERE ID = " . dbQuote($PARAM['id']);
        $result = runQuery($query, 'manageArticles()', 'SAVE_WHEN_ARTICLE');
        $SUBS['COMMAND'] = $PARAM['cmd'] . "&err=20092&offs=" . $PARAM['offs'];
        printPage('_admin_done.htmlt');
        return;
    }
    //SESSION
    if (!session_is_registered('articleString')) {
        session_register('articleString');
    }
    if (!session_is_registered('articlePage')) {
        session_register('articlePage');
        $articlePage = getAdmSetting('RESULT_PER_PAGE');
    }
    if (!$articlePage) {
        $articlePage = getAdmSetting('RESULT_PER_PAGE');
    }
    //set perpage
    if ($PARAM['SearchPage'] && $PARAM['SearchPage'] > 0) {
        $articlePage = $PARAM['SearchPage'];
    }
    if (!session_is_registered('articleCount')) {
        session_register('articleCount');
    }
    if (!session_is_registered('articleWhere')) {
        session_register('articleWhere');
        $articleWhere = '1';
    }
    if ($PARAM['Show'] == 1) {
        $articleString = $PARAM['string'];
        $articleWhere = '1';
        $string = dbQuote("%{$articleString}%");
        $articleWhere .= " AND (({$tbl_1d_article}.Title LIKE {$string}) OR ({$tbl_1d_article}.Caption LIKE {$string})) ";
    }
    //prepare sort
    switch ($PARAM['sort']) {
        case 1:
            $articleSort = ' ASC ';
            $SUBS['SORT'] = 0;
            break;
        case 0:
            $articleSort = ' DESC ';
            $SUBS['SORT'] = 1;
            break;
        default:
            $articleSort = ' DESC ';
            $SUBS['SORT'] = 0;
    }
    //prepare order
    if (!$PARAM['orderby']) {
        $PARAM['orderby'] = '2';
    }
    switch ($PARAM['orderby']) {
        case 1:
            $articleOrder = "{$tbl_1d_article}.Title";
            break;
        case 2:
            $articleOrder = "{$tbl_1d_article}.tsWhen {$articleSort}, {$tbl_1d_article}.Priority ";
            $articleSort = ' ASC ';
            break;
        case 3:
            $articleOrder = "{$tbl_1d_article}.tsLast";
            break;
        default:
            $articleOrder = "{$tbl_1d_article}.ID";
            //case 0
    }
    //pokaji statii
    $articleSelect = "SELECT\t{$tbl_1d_article}.ID,\n\t\t\t{$tbl_1d_article}.Title,\n\t\t\t{$tbl_1d_article}.tsWhen,\n\t\t\t{$tbl_1d_article}.tsLast,\n\t\t\t{$tbl_1d_article}.Priority";
    $articleFrom = "FROM {$tbl_1d_article}";
    //get search count
    if (!$articleCount || $PARAM['Show'] == 1) {
        $query = "SELECT COUNT({$tbl_1d_article}.ID) {$articleFrom} WHERE {$articleWhere}";
        $result = runQuery($query, 'manageArticles()', 'GET_ARTIFLES_COUNT');
        if ($row = db_fetch_row($result)) {
            $articleCount = $row[0];
        } else {
            $articleCount = 0;
        }
    }
    if (!$PARAM['offs']) {
        $articleStart = 0;
    } else {
        $articleStart = $PARAM['offs'];
    }
    if ($PARAM['offs'] >= $articleCount) {
        $SUBS['ERROR'] = $MSG[20047];
        //out of search limits
        $SUBS['ERROR'] = fileParse('_admin_error.htmlt');
        $articleRows = 0;
        ////----[Mrasnika's] Edition 16.10.2002
        $no = 1;
    }
    //run query
    // if ($SUBS['ERROR'] == '')
    if ($no != 1) {
        $query = "{$articleSelect} {$articleFrom} WHERE {$articleWhere} {$articleGroupBy}\n\t\t\tORDER BY {$articleOrder} {$articleSort}\n\t\t\tLIMIT {$articleStart}, {$articlePage}";
        $result = runQuery($query, 'manageArticles()', 'DO_ARTICLES_SEARCH');
        $articleRows = db_num_rows($result);
    }
    if ($PARAM['Show'] == 1) {
        $SUBS['COMMAND'] = $PARAM['cmd'];
        printPage('_admin_done.htmlt');
        return;
    }
    $SUBS['SORTED'] = (1 + $SUBS['SORT']) % 2;
    $SUBS['ORDER'] = $PARAM['orderby'];
    $SUBS['PERPAGE'] = $articlePage;
    $SUBS['START'] = $articleStart;
    while ($row = db_fetch_row($result)) {
        $SUBS['CHECK'] = $row[0];
        $SUBS['ID2'] = sprintf('%04d', $row[0]);
        $SUBS['TITLE'] = htmlEncode($row[1]);
        $SUBS['KOGA'] = $row[2];
        $SUBS['SEDMICA'] = date('d ', $row[2]) . $MONTHS[intval(date('m', $row[2]))] . date(' Y', $row[2]);
        $SUBS['NOM'] = $row[4];
        $SUBS['LAST'] = $datata = date('d ', $row[3]) . $MONTHS[intval(date('m', $row[3]))] . date(' Y H:i:s', $row[3]);
        $SUBS['ARTICLES'] .= fileParse('_admin_manage_articles_row.htmlt');
        if ($PARAM['Add'] != 1 && $PARAM['id'] == $row[0]) {
            $PARAM['WHEN'] = $row[2];
            $PARAM['NO'] = $row[4];
            $SUBS['ARTICLE'] = $SUBS['TITLE'];
        }
    }
    //navigation
    $SUBS['TOTAL'] = $articleCount;
    $template = fileToString(getAdmSetting('TEMPLATES_DIR') . '/_admin_manage_article_navigation.htmlt');
    if ($articleRows != 0) {
        $SUBS['PAGE'] = 1 + $articleStart . ' - ' . ($articleStart + $articleRows);
    } else {
        $SUBS['PAGE'] = '0 - 0';
    }
    if ($articleStart != 0) {
        $SUBS['BUTTON'] = $MSG[20060];
        //first
        $SUBS['START'] = 0;
        $SUBS['FIRST'] = strParse($template);
    } else {
        $SUBS['FIRST'] = $MSG[20060];
    }
    if ($articleStart != 0) {
        $SUBS['BUTTON'] = $MSG[20063];
        //previous
        if (($SUBS['START'] = $articleStart - $articlePage) < 0) {
            $SUBS['START'] = 0;
        }
        $SUBS['PREV'] = strParse($template);
    } else {
        $SUBS['PREV'] = $MSG[20063];
    }
    if (($SUBS['START'] = $articleStart + $articlePage) < $articleCount) {
        $SUBS['BUTTON'] = $MSG[20062];
        //next
        $SUBS['NEXT'] = strParse($template);
    } else {
        $SUBS['NEXT'] = $MSG[20062];
    }
    if ($articleStart < ($SUBS['START'] = $articleCount - $articlePage)) {
        $SUBS['BUTTON'] = $MSG[20061];
        //last
        $SUBS['LAST'] = strParse($template);
    } else {
        $SUBS['LAST'] = $MSG[20061];
    }
    $SUBS['START'] = $articleStart;
    //nameri naj-starata statiya
    $query = "SELECT MIN(tsWhen) FROM {$tbl_1d_article}";
    $result = runQuery($query, 'manageArticles()', 'GET_OLDEST_WEEK');
    if ($row = db_fetch_row($result)) {
        $span = $row[0];
    }
    //compatibility
    if (!$PARAM['WHEN']) {
        //no date applied
        if (!$PARAM['Day1'] || !$PARAM['Month1'] || !$PARAM['Year1']) {
            $PARAM['WHEN'] = getNextWeek();
            $PARAM['Year1'] = date('Y', $PARAM['WHEN']);
            $PARAM['Month1'] = date('m', $PARAM['WHEN']);
            $PARAM['Day1'] = date('d', $PARAM['WHEN']);
        } else {
            $PARAM['WHEN'] = 1 + strToTime($PARAM['Day1'] . ' ' . $MONTHS2[$PARAM['Month1']] . ' ' . $PARAM['Year1']);
        }
    } else {
        //load date form
        $PARAM['Year1'] = date('Y', $PARAM['WHEN']);
        $PARAM['Month1'] = date('m', $PARAM['WHEN']);
        $PARAM['Day1'] = date('d', $PARAM['WHEN']);
    }
    if ($span > $PARAM['WHEN']) {
        //ima data, no e po-malka ot naj-starata programa
        $SUBS['COMMAND'] = $PARAM['cmd'] . "&WHERE=" . $PARAM['WHERE'] . "&WHEN={$span}&WEEK={$span}&PLACES=" . $PARAM['PLACES'];
        printPage('_admin_done.htmlt');
        return;
    }
    $Year2 = 1 + date('Y', max($PARAM['WHEN'], time()));
    $Year1 = date('Y', $span);
    for ($i = $Year1; $i <= $Year2; $i++) {
        if ($i == $PARAM['Year1']) {
            $SUBS['YEAR1'] .= "<OPTION value=\"{$i}\" selected>{$i}";
        } else {
            $SUBS['YEAR1'] .= "<OPTION value=\"{$i}\">{$i}";
        }
    }
    for ($i = 1; $i <= 12; $i++) {
        if ($i == $PARAM['Month1']) {
            $SUBS['MONTH1'] .= "<OPTION value=\"{$i}\" selected>" . $MONTHS[$i];
        } else {
            $SUBS['MONTH1'] .= "<OPTION value=\"{$i}\">" . $MONTHS[$i];
        }
    }
    for ($i = 1; $i <= 31; $i++) {
        if ($i == $PARAM['Day1']) {
            $SUBS['DAY1'] .= "<OPTION value=\"{$i}\" selected>" . sprintf('%02d', $i);
        } else {
            $SUBS['DAY1'] .= "<OPTION value=\"{$i}\">" . sprintf('%02d', $i);
        }
    }
    if (!($SUBS['WEEK'] = $PARAM['WEEK'])) {
        $SUBS['WEEK'] = $PARAM['WHEN'];
    }
    $SUBS['DISPLAYWEEK'] = displayWeek($SUBS['WEEK']);
    $SUBS['GO'] = $PARAM['WEEK'];
    $SUBS['ID'] = $PARAM['id'];
    $SUBS['NO'] = htmlEncode($PARAM['NO']);
    $SUBS['STRING'] = htmlEncode($articleString);
    if ($PARAM['err'] != '' && $SUBS['ERROR'] == '') {
        $SUBS['ERROR'] = $MSG[$PARAM['err']];
        $SUBS['ERROR'] = fileParse('_admin_error.htmlt');
    }
    printPage('_admin_manage_articles.htmlt');
}
예제 #3
0
function sentMail($mail)
{
    $mail = fileToString(getAdmSetting('EMAIL_TEMPLATES_DIR') . "/{$mail}");
    $mail = strParse($mail);
    eregi("To:([^\n]*)\n(From:[^\n]*)\nSubject:([^\n]*)\n[^[a-z0-9]]*(.*)", $mail, $R);
    $To = $R[1];
    $From = $R[2];
    $Subject = $R[3];
    $Msg = ltrim($R[4]);
    if (!@mail($To, $Subject, $Msg, $From)) {
        //SENT_MAIL
        setLogAndStatus("mail ({$To}, {$Subject}, {$Msg}, {$From})", 0, 'Mailing failed', 'sentMail()', 'SENT_MAIL');
        return 0;
    }
    return 1;
}